-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented Item Loss Chance * Removed debug stuff * Use Map#compute * whoops * changed datatype of time from long to LocalDateTime * Refactored, used early return pattern, changed from hashmap to arraylist and removed TableManager#save * Removed unused imports
- Loading branch information
Showing
6 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/iridium/iridiumskyblock/database/LostItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.iridium.iridiumskyblock.database; | ||
|
||
import com.iridium.iridiumcore.utils.ItemStackUtils; | ||
import com.iridium.iridiumteams.database.DatabaseObject; | ||
import com.j256.ormlite.field.DataType; | ||
import com.j256.ormlite.field.DatabaseField; | ||
import com.j256.ormlite.table.DatabaseTable; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.UUID; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@DatabaseTable(tableName = "lost_items") | ||
public class LostItems extends DatabaseObject { | ||
@DatabaseField(columnName = "id", generatedId = true, canBeNull = false, unique = true) | ||
private int id; | ||
|
||
@DatabaseField(columnName = "uuid", canBeNull = false) | ||
private @NotNull UUID uuid; | ||
|
||
@DatabaseField(columnName = "time") | ||
private LocalDateTime time; | ||
|
||
@DatabaseField(columnName = "items", dataType = DataType.SERIALIZABLE) | ||
private String[] items; | ||
|
||
public void setItems(ItemStack[] items) { | ||
this.items = Arrays.stream(items) | ||
.map(ItemStackUtils::serialize) | ||
.toArray(String[]::new); | ||
} | ||
|
||
public ItemStack[] getItems() { | ||
return Arrays.stream(items) | ||
.map(ItemStackUtils::deserialize) | ||
.toArray(ItemStack[]::new); | ||
} | ||
|
||
public LostItems(@NotNull UUID uuid, ItemStack[] items) { | ||
this.uuid = uuid; | ||
this.time = LocalDateTime.now(); | ||
setItems(items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/iridium/iridiumskyblock/managers/tablemanagers/LostItemsTableManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.iridium.iridiumskyblock.managers.tablemanagers; | ||
|
||
import com.iridium.iridiumskyblock.database.LostItems; | ||
import com.j256.ormlite.support.ConnectionSource; | ||
|
||
import java.sql.SQLException; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class LostItemsTableManager extends TableManager<LostItems, Integer> { | ||
public LostItemsTableManager(ConnectionSource connectionSource, Class<LostItems> clazz, Comparator<LostItems> comparator) throws SQLException { | ||
super(connectionSource, clazz, comparator); | ||
sort(); | ||
} | ||
|
||
public void sort() { | ||
getEntries().sort(Comparator.comparing(LostItems::getUuid)); | ||
} | ||
|
||
public List<LostItems> getLostItems(UUID uuid) { | ||
return getEntries().stream() | ||
.filter(item -> item.getUuid().equals(uuid)) | ||
.sorted(Comparator.comparing(LostItems::getTime).reversed()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |