mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-22 19:11:23 +00:00
more work
This commit is contained in:
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -47,8 +48,6 @@ public class InventoryOpen implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getPlayer();
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
@@ -68,7 +67,7 @@ public class InventoryOpen implements Listener {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta newMeta = getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
||||
ItemMeta newMeta = toolStats.itemLore.getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
|
||||
if (newMeta == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -78,66 +77,11 @@ public class InventoryOpen implements Listener {
|
||||
itemStack.setItemMeta(newMeta);
|
||||
}
|
||||
};
|
||||
toolStats.scheduleEntity(runnable, player, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine an item's origin based on lore.
|
||||
*
|
||||
* @param itemMeta The item's meta.
|
||||
* @param elytra If they item is an elytra.
|
||||
* @return The new item meta with the new origin tag. Returns null if origin cannot be determined.
|
||||
*/
|
||||
private ItemMeta getOrigin(ItemMeta itemMeta, boolean elytra) {
|
||||
List<String> lore;
|
||||
if (!itemMeta.hasLore()) {
|
||||
return null;
|
||||
}
|
||||
lore = itemMeta.getLore();
|
||||
Integer origin = null;
|
||||
|
||||
for (String line : lore) {
|
||||
// this is the worst code I have ever written
|
||||
String createdBy = toolStats.getLoreFromConfig("created.created-by", false);
|
||||
String createdOn = toolStats.getLoreFromConfig("created.created-on", false);
|
||||
String caughtBy = toolStats.getLoreFromConfig("fished.caught-by", false);
|
||||
String lootedBy = toolStats.getLoreFromConfig("looted.looted-by", false);
|
||||
String foundBy = toolStats.getLoreFromConfig("looted.found-by", false);
|
||||
String tradedBy = toolStats.getLoreFromConfig("traded.traded-by", false);
|
||||
|
||||
if (createdBy != null && line.contains(createdBy)) {
|
||||
origin = 0;
|
||||
}
|
||||
if (createdOn != null && line.contains(createdOn)) {
|
||||
origin = 0;
|
||||
}
|
||||
if (caughtBy != null && line.contains(caughtBy)) {
|
||||
origin = 5;
|
||||
}
|
||||
if (lootedBy != null && line.contains(lootedBy)) {
|
||||
origin = 2;
|
||||
}
|
||||
// because the config changed, "found-by" was being used for ALL looted items
|
||||
// this includes elytras, so we have to check for this mistake
|
||||
if (foundBy != null && line.contains(foundBy)) {
|
||||
if (elytra) {
|
||||
origin = 4;
|
||||
} else {
|
||||
origin = 5;
|
||||
}
|
||||
}
|
||||
if (tradedBy != null && line.contains(tradedBy)) {
|
||||
origin = 3;
|
||||
Location location = inventory.getLocation();
|
||||
// only run for actual inventories
|
||||
if (location != null) {
|
||||
toolStats.scheduleRegion(runnable, location.getWorld(), location.getChunk(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (origin == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, origin);
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user