Compare commits

..

5 Commits

Author SHA1 Message Date
hyperdefined
c0d79fd740 Update pom.xml 2025-07-23 12:31:06 -04:00
hyperdefined
b056972d30 swap order of anvil checking to account 2025-07-23 12:30:46 -04:00
hyperdefined
525df4bcf6 use the new GLIDER DataComponent 2025-07-23 12:19:40 -04:00
hyperdefined
86cbdd58ff new purge command 2025-07-23 11:29:20 -04:00
hyperdefined
27a89fd67c unify owner and timestamp creation 2025-07-23 10:53:22 -04:00
14 changed files with 445 additions and 381 deletions

View File

@@ -23,7 +23,7 @@
<groupId>lol.hyper</groupId> <groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId> <artifactId>toolstats</artifactId>
<version>1.9.8</version> <version>1.9.9</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ToolStats</name> <name>ToolStats</name>

View File

@@ -155,6 +155,37 @@ public class CommandToolStats implements TabExecutor {
sender.sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN)); sender.sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN));
return true; return true;
} }
case "purge": {
if (!sender.hasPermission("toolstats.purge")) {
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
return true;
}
if (args.length == 2 && args[1].equalsIgnoreCase("confirm")) {
if (!sender.hasPermission("toolstats.purge.confirm")) {
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}
Player player = (Player) sender;
ItemStack heldItem = player.getInventory().getItemInMainHand();
if (!toolStats.itemChecker.isValidItem(heldItem.getType())) {
sender.sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
return true;
}
ItemStack purgedItem = toolStats.itemLore.removeAll(heldItem, true);
player.getInventory().setItemInMainHand(purgedItem);
sender.sendMessage(Component.text("The item was purged!", NamedTextColor.GREEN));
return true;
}
sender.sendMessage(Component.text("This will purge ALL ToolStats data from this item.", NamedTextColor.GREEN));
sender.sendMessage(Component.text("This includes all stats, ownership, and creation time.", NamedTextColor.GREEN));
sender.sendMessage(Component.text("THIS CANNOT BE UNDONE!", NamedTextColor.GREEN));
sender.sendMessage(Component.text("Type /toolstats purge confirm to confirm this.", NamedTextColor.GREEN));
return true;
}
case "givetokens": { case "givetokens": {
if (!sender.hasPermission("toolstats.givetokens")) { if (!sender.hasPermission("toolstats.givetokens")) {
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED)); sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
@@ -233,38 +264,6 @@ public class CommandToolStats implements TabExecutor {
origin = -1; origin = -1;
} }
// hard code elytras
if (finalItem.getType() == Material.ELYTRA) {
Long flightTime = null;
Long timeCreated = null;
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
}
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
}
if (flightTime != null) {
if (toolStats.config.getBoolean("enabled.flight-time")) {
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
Component line = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
lore.add(line);
}
}
if (timeCreated != null) {
Component timeCreatedLine = toolStats.configTools.formatLore("looted.found-by", "{player}", player.getName());
Component playerOwnerLine = toolStats.configTools.formatLore("looted.found-on", "{date}", toolStats.numberFormat.formatDate(new Date(timeCreated)));
lore.add(timeCreatedLine);
lore.add(playerOwnerLine);
}
finalMeta.lore(lore);
finalItem.setItemMeta(finalMeta);
int slot = player.getInventory().getHeldItemSlot();
player.getInventory().setItem(slot, finalItem);
}
if (container.has(toolStats.droppedBy, PersistentDataType.STRING)) { if (container.has(toolStats.droppedBy, PersistentDataType.STRING)) {
if (toolStats.config.getBoolean("enabled.dropped-by")) { if (toolStats.config.getBoolean("enabled.dropped-by")) {
if (container.has(toolStats.droppedBy)) { if (container.has(toolStats.droppedBy)) {
@@ -293,82 +292,30 @@ public class CommandToolStats implements TabExecutor {
container.set(toolStats.itemOwner, new UUIDDataType(), player.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), player.getUniqueId());
} }
// show how the item was created based on the previous lore // add the ownership lore
switch (origin) { Component ownerLore = toolStats.itemLore.formatOwner(ownerName, origin, original);
case 0: { if (ownerLore != null) {
if (toolStats.configTools.checkConfig(original.getType(), "crafted-by")) { lore.add(ownerLore);
lore.add(toolStats.configTools.formatLore("crafted.crafted-by", "{player}", ownerName));
}
break;
}
case 2: {
if (toolStats.configTools.checkConfig(original.getType(), "looted-by")) {
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
}
break;
}
case 3: {
if (toolStats.configTools.checkConfig(original.getType(), "traded-by")) {
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
}
break;
}
case 5: {
if (toolStats.configTools.checkConfig(original.getType(), "fished-by")) {
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
}
break;
}
case 6: {
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-by")) {
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
}
break;
}
} }
} }
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) { if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG); Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
if (time != null) { if (time != null) {
String date = toolStats.numberFormat.formatDate(new Date(time)); // add the creation time lore
// show how when the item was created based on the previous lore Component creationTimeLore = toolStats.itemLore.formatCreationTime(time, origin, original);
switch (origin) { if (creationTimeLore != null) {
case 0: { lore.add(creationTimeLore);
if (toolStats.configTools.checkConfig(original.getType(), "crafted-on")) {
lore.add(toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date));
} }
break;
} }
case 1: {
if (toolStats.config.getBoolean("enabled.dropped-on")) {
lore.add(toolStats.configTools.formatLore("dropped-on", "{date}", date));
}
break;
}
case 2: {
if (toolStats.configTools.checkConfig(original.getType(), "looted-on")) {
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
}
break;
}
case 3: {
if (toolStats.configTools.checkConfig(original.getType(), "traded-on")) {
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
}
break;
}
case 5: {
if (toolStats.configTools.checkConfig(original.getType(), "fished-on")) {
lore.add(toolStats.configTools.formatLore("fished.caught-on", "{date}", date));
}
break;
}
case 6: {
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-on")) {
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date));
}
break;
} }
if (toolStats.config.getBoolean("enabled.flight-time")) {
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
if (flightTime != null) {
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
Component line = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
lore.add(line);
} }
} }
} }
@@ -1076,12 +1023,18 @@ public class CommandToolStats implements TabExecutor {
if (sender.hasPermission("toolstats.remove")) { if (sender.hasPermission("toolstats.remove")) {
suggestions.add("remove"); suggestions.add("remove");
} }
if (sender.hasPermission("toolstats.purge")) {
suggestions.add("purge");
}
return suggestions.isEmpty() ? null : suggestions; return suggestions.isEmpty() ? null : suggestions;
} }
if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) { if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) {
return Collections.singletonList("confirm"); return Collections.singletonList("confirm");
} }
if (args.length == 2 && args[0].equalsIgnoreCase("purge") && sender.hasPermission("toolstats.purge.confirm")) {
return Collections.singletonList("confirm");
}
if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) { if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) {
// yes I am lazy // yes I am lazy
return toolStats.tokenData.getTokenTypes().stream() return toolStats.tokenData.getTokenTypes().stream()

View File

@@ -90,7 +90,9 @@ public class AnvilEvent implements Listener {
} }
if (tokenType.equalsIgnoreCase("remove")) { if (tokenType.equalsIgnoreCase("remove")) {
remove(event, clone); ItemStack removedStats = toolStats.itemLore.removeAll(clone, false);
event.setResult(removedStats);
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
return; return;
} }
@@ -129,6 +131,10 @@ public class AnvilEvent implements Listener {
} }
return; return;
} }
if (toolStats.itemChecker.canGlide(clone)) {
addToken(event, tokenType, "flight-time", clone);
return;
}
if (toolStats.itemChecker.isArmor(firstSlotMaterial)) { if (toolStats.itemChecker.isArmor(firstSlotMaterial)) {
addToken(event, tokenType, "damage-taken", clone); addToken(event, tokenType, "damage-taken", clone);
return; return;
@@ -167,10 +173,6 @@ public class AnvilEvent implements Listener {
} }
return; return;
} }
if (firstSlotMaterial == Material.ELYTRA) {
addToken(event, tokenType, "flight-time", clone);
return;
}
if (firstSlotMaterial == Material.FISHING_ROD) { if (firstSlotMaterial == Material.FISHING_ROD) {
addToken(event, tokenType, "fish-caught", clone); addToken(event, tokenType, "fish-caught", clone);
} }
@@ -394,155 +396,4 @@ public class AnvilEvent implements Listener {
event.setResult(finalItem); event.setResult(finalItem);
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset")); event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
} }
/**
* Remove all stats from an item.
*
* @param event The PrepareAnvilEvent event.
* @param inputItem The input item to remove stats from.
*/
private void remove(PrepareAnvilEvent event, ItemStack inputItem) {
ItemStack finalItem = inputItem.clone();
ItemMeta meta = finalItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();
// remove the applied tokens
if (container.has(toolStats.tokenApplied)) {
container.remove(toolStats.tokenApplied);
}
if (container.has(toolStats.playerKills)) {
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (playerKills == null) {
return;
}
container.remove(toolStats.playerKills);
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
Component lineToRemove = toolStats.configTools.formatLore("kills.player", "{kills}", playerKillsFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.mobKills)) {
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
if (mobKills == null) {
return;
}
container.remove(toolStats.mobKills);
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
Component lineToRemove = toolStats.configTools.formatLore("kills.mob", "{kills}", mobKillsFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.blocksMined)) {
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
if (blocksMined == null) {
return;
}
container.remove(toolStats.blocksMined);
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", blocksMinedFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.cropsHarvested)) {
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (cropsHarvested == null) {
return;
}
container.remove(toolStats.cropsHarvested);
String cropsHarvestedFormatted = toolStats.numberFormat.formatInt(cropsHarvested);
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", cropsHarvestedFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.fishCaught)) {
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
if (fishCaught == null) {
return;
}
container.remove(toolStats.fishCaught);
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", fishCaughtFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.sheepSheared)) {
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
if (sheepSheared == null) {
return;
}
container.remove(toolStats.sheepSheared);
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
Component lineToRemove = toolStats.configTools.formatLore("sheep.sheared", "{sheep}", sheepShearedFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.armorDamage)) {
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
if (armorDamage == null) {
return;
}
container.remove(toolStats.armorDamage);
String armorDamageFormatted = toolStats.numberFormat.formatDouble(armorDamage);
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", armorDamageFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.damageDone)) {
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
if (damageDone == null) {
return;
}
container.remove(toolStats.damageDone);
String damageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", damageDoneFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.arrowsShot)) {
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
if (arrowsShot == null) {
return;
}
container.remove(toolStats.arrowsShot);
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", arrowsShotFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.flightTime)) {
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
if (flightTime == null) {
return;
}
container.remove(toolStats.flightTime);
String flightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", flightTimeFormatted);
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
event.setResult(finalItem);
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
}
} }

View File

@@ -125,8 +125,6 @@ public class CraftItem implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -145,29 +143,20 @@ public class CraftItem implements Listener {
} }
// if creation date is enabled, add it // if creation date is enabled, add it
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-on")) { Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 0, newItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
container.set(toolStats.originType, PersistentDataType.INTEGER, 0); container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
lore.add(creationDate);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }
// if creation owner is enabled, add it // if ownership is enabled, add it
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-by")) { Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 0, newItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 0); container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
lore.add(itemOwner);
Component newLine = toolStats.configTools.formatLore("crafted.crafted-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }

View File

@@ -92,8 +92,6 @@ public class CreativeEvent implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -111,28 +109,21 @@ public class CreativeEvent implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
} }
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-on")) { // if creation date is enabled, add it
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 6, newSpawnedItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
container.set(toolStats.originType, PersistentDataType.INTEGER, 6); container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
lore.add(creationDate);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-by")) { // if ownership is enabled, add it
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 6, newSpawnedItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 6); container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
lore.add(itemOwner);
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }

View File

@@ -18,6 +18,7 @@
package lol.hyper.toolstats.events; package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -91,8 +92,6 @@ public class EntityDeath implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -108,12 +107,13 @@ public class EntityDeath implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
} }
if (toolStats.config.getBoolean("enabled.dropped-on")) { // if creation date is enabled, add it
container.set(toolStats.originType, PersistentDataType.INTEGER, 1); Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 1, newItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
String date = toolStats.numberFormat.formatDate(finalDate); container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
Component droppedOn = toolStats.configTools.formatLore("dropped-on", "{date}", date); lore.add(creationDate);
lore.add(droppedOn); meta.lore(lore);
} }
if (toolStats.config.getBoolean("enabled.dropped-by")) { if (toolStats.config.getBoolean("enabled.dropped-by")) {

View File

@@ -104,8 +104,6 @@ public class GenerateLoot implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -121,28 +119,21 @@ public class GenerateLoot implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-on")) { // if creation date is enabled, add it
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
container.set(toolStats.originType, PersistentDataType.INTEGER, 2); container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
lore.add(creationDate);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("looted.looted-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-by")) { // if ownership is enabled, add it
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 2); container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
lore.add(itemOwner);
Component newLine = toolStats.configTools.formatLore("looted.looted-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }

View File

@@ -95,8 +95,6 @@ public class PickupItem implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -123,12 +121,22 @@ public class PickupItem implements Listener {
container.set(toolStats.originType, PersistentDataType.INTEGER, 4); container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
container.remove(toolStats.newElytra); container.remove(toolStats.newElytra);
String formattedDate = toolStats.numberFormat.formatDate(finalDate); Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 4, finalItem);
Component dateCreatedLore = toolStats.configTools.formatLore("looted.found-on", "{date}", formattedDate); if (creationDate != null) {
Component itemOwnerLore = toolStats.configTools.formatLore("looted.found-by", "{player}", owner.getName()); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
lore.add(dateCreatedLore); container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
lore.add(itemOwnerLore); lore.add(creationDate);
meta.lore(lore); meta.lore(lore);
}
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 4, finalItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
lore.add(itemOwner);
meta.lore(lore);
}
finalItem.setItemMeta(meta); finalItem.setItemMeta(meta);
return finalItem; return finalItem;
} }

View File

@@ -114,8 +114,6 @@ public class PlayerFish implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -131,28 +129,21 @@ public class PlayerFish implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-on")) { // if creation date is enabled, add it
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 5, newItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
container.set(toolStats.originType, PersistentDataType.INTEGER, 5); container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
lore.add(creationDate);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-by")) { // if ownership is enabled, add it
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 5, newItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 5); container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
lore.add(itemOwner);
Component newLine = toolStats.configTools.formatLore("fished.caught-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }

View File

@@ -53,15 +53,23 @@ public class PlayerMove implements Listener {
// player is not flying // player is not flying
if (playerStartFlight.containsKey(player)) { if (playerStartFlight.containsKey(player)) {
PlayerInventory inventory = player.getInventory(); PlayerInventory inventory = player.getInventory();
ItemStack chest = inventory.getChestplate(); // copy their current armor
// make sure the player is wearing an elytra ItemStack[] armor = inventory.getArmorContents().clone();
if (chest != null && chest.getType() == Material.ELYTRA) { for (ItemStack armorPiece : armor) {
// skip missing slots
if (armorPiece == null) {
continue;
}
// if the armor piece can glide, track the flight time
if (toolStats.itemChecker.canGlide(armorPiece)) {
long duration = (System.currentTimeMillis() - playerStartFlight.get(player)); long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
ItemMeta newItem = toolStats.itemLore.updateFlightTime(chest, duration); ItemMeta newMeta = toolStats.itemLore.updateFlightTime(armorPiece, duration);
if (newItem != null) { if (newMeta != null) {
inventory.getChestplate().setItemMeta(newItem); armorPiece.setItemMeta(newMeta);
} }
} }
}
inventory.setArmorContents(armor);
playerStartFlight.remove(player); playerStartFlight.remove(player);
} }
} }

View File

@@ -131,8 +131,6 @@ public class VillagerTrade implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) { if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated); finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime(); timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -148,28 +146,22 @@ public class VillagerTrade implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-on")) {
// if creation date is enabled, add it
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 3, newItem);
if (creationDate != null) {
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated); container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
container.set(toolStats.originType, PersistentDataType.INTEGER, 3); container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
lore.add(creationDate);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-by")) { // if ownership is enabled, add it
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 3, newItem);
if (itemOwner != null) {
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 3); container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
lore.add(itemOwner);
Component newLine = toolStats.configTools.formatLore("traded.traded-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
meta.lore(lore); meta.lore(lore);
} }

View File

@@ -17,6 +17,8 @@
package lol.hyper.toolstats.tools; package lol.hyper.toolstats.tools;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.DataComponentTypes;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@@ -116,6 +118,22 @@ public class ItemChecker {
return mineItems.contains(itemType); return mineItems.contains(itemType);
} }
/**
* In newer versions of Minecraft, you can make items glide, which works
* like an Elytra.
*
* @param itemStack The item to check.
* @return True/false if the item can glide like an Elytra.
*/
public boolean canGlide(ItemStack itemStack) {
// if it's an elytra, we are good
if (itemStack.getType() == Material.ELYTRA) {
return true;
}
// otherwise if it has the GLIDER data
return itemStack.hasData(DataComponentTypes.GLIDER);
}
/** /**
* Check a given item for a target token. * Check a given item for a target token.
* *

View File

@@ -19,15 +19,17 @@ package lol.hyper.toolstats.tools;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
public class ItemLore { public class ItemLore {
@@ -97,6 +99,9 @@ public class ItemLore {
* @return The lore with the line removed. * @return The lore with the line removed.
*/ */
public List<Component> removeLore(List<Component> inputLore, Component toRemove) { public List<Component> removeLore(List<Component> inputLore, Component toRemove) {
if (inputLore == null) {
return Collections.emptyList();
}
List<Component> newLore = new ArrayList<>(inputLore); List<Component> newLore = new ArrayList<>(inputLore);
newLore.removeIf(line -> PlainTextComponentSerializer.plainText().serialize(line).equals(PlainTextComponentSerializer.plainText().serialize(toRemove))); newLore.removeIf(line -> PlainTextComponentSerializer.plainText().serialize(line).equals(PlainTextComponentSerializer.plainText().serialize(toRemove)));
return newLore; return newLore;
@@ -196,7 +201,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -295,7 +300,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -393,7 +398,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -491,7 +496,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -597,7 +602,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -703,7 +708,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -819,7 +824,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -917,7 +922,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -1017,7 +1022,7 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
@@ -1115,8 +1120,269 @@ public class ItemLore {
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {
return null; return null;
} }
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine); List<Component> newLore = updateItemLore(meta, oldLine, newLine);
meta.lore(newLore); meta.lore(newLore);
return meta; return meta;
} }
/**
* Format the item owner lore.
*
* @param playerName The player's name who owns the items.
* @param origin The origin type.
* @param item The item.
* @return A component with the lore.
*/
public Component formatOwner(String playerName, int origin, ItemStack item) {
switch (origin) {
case 0: {
if (toolStats.configTools.checkConfig(item.getType(), "crafted-by")) {
return toolStats.configTools.formatLore("crafted.crafted-by", "{player}", playerName);
}
break;
}
case 2: {
if (toolStats.configTools.checkConfig(item.getType(), "looted-by")) {
return toolStats.configTools.formatLore("looted.looted-by", "{player}", playerName);
}
break;
}
case 3: {
if (toolStats.configTools.checkConfig(item.getType(), "traded-by")) {
return toolStats.configTools.formatLore("traded.traded-by", "{player}", playerName);
}
break;
}
case 4: {
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
return toolStats.configTools.formatLore("looted.found-by", "{player}", playerName);
}
break;
}
case 5: {
if (toolStats.configTools.checkConfig(item.getType(), "fished-by")) {
return toolStats.configTools.formatLore("fished.caught-by", "{player}", playerName);
}
break;
}
case 6: {
if (toolStats.configTools.checkConfig(item.getType(), "spawned-in-by")) {
return toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", playerName);
}
break;
}
}
return null;
}
/**
* Format the item creation time.
*
* @param creationDate When the item was created.
* @param origin The origin type.
* @param item The item.
* @return A component with the lore.
*/
public Component formatCreationTime(long creationDate, int origin, ItemStack item) {
String date = toolStats.numberFormat.formatDate(new Date(creationDate));
switch (origin) {
case 0: {
if (toolStats.configTools.checkConfig(item.getType(), "crafted-on")) {
return toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date);
}
break;
}
case 1: {
if (toolStats.config.getBoolean("enabled.dropped-on")) {
return toolStats.configTools.formatLore("dropped-on", "{date}", date);
}
break;
}
case 2: {
if (toolStats.configTools.checkConfig(item.getType(), "looted-on")) {
return toolStats.configTools.formatLore("looted.looted-on", "{date}", date);
}
break;
}
case 3: {
if (toolStats.configTools.checkConfig(item.getType(), "traded-on")) {
return toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
}
break;
}
case 4: {
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
return toolStats.configTools.formatLore("looted.found-on", "{date}", date);
}
break;
}
case 5: {
if (toolStats.configTools.checkConfig(item.getType(), "fished-on")) {
return toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
}
break;
}
case 6: {
if (toolStats.configTools.checkConfig(item.getType(), "spawned-in-on")) {
return toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date);
}
break;
}
}
return null;
}
/**
* Remove all stats, ownership, and creation time from an item.
*
* @param inputItem The input item to remove stats from.
* @param removeMeta Remove ownership and creation time?
*/
public ItemStack removeAll(ItemStack inputItem, boolean removeMeta) {
ItemStack finalItem = inputItem.clone();
ItemMeta meta = finalItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();
// remove the applied tokens
if (container.has(toolStats.tokenApplied)) {
container.remove(toolStats.tokenApplied);
}
if (container.has(toolStats.playerKills)) {
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (playerKills != null) {
container.remove(toolStats.playerKills);
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
Component lineToRemove = toolStats.configTools.formatLore("kills.player", "{kills}", playerKillsFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.mobKills)) {
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
if (mobKills != null) {
container.remove(toolStats.mobKills);
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
Component lineToRemove = toolStats.configTools.formatLore("kills.mob", "{kills}", mobKillsFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.blocksMined)) {
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
if (blocksMined != null) {
container.remove(toolStats.blocksMined);
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", blocksMinedFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.cropsHarvested)) {
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (cropsHarvested != null) {
container.remove(toolStats.cropsHarvested);
String cropsHarvestedFormatted = toolStats.numberFormat.formatInt(cropsHarvested);
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", cropsHarvestedFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.fishCaught)) {
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
if (fishCaught != null) {
container.remove(toolStats.fishCaught);
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", fishCaughtFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.sheepSheared)) {
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
if (sheepSheared != null) {
container.remove(toolStats.sheepSheared);
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
Component lineToRemove = toolStats.configTools.formatLore("sheep.sheared", "{sheep}", sheepShearedFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.armorDamage)) {
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
if (armorDamage != null) {
container.remove(toolStats.armorDamage);
String armorDamageFormatted = toolStats.numberFormat.formatDouble(armorDamage);
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", armorDamageFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.damageDone)) {
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
if (damageDone != null) {
container.remove(toolStats.damageDone);
String damageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", damageDoneFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.arrowsShot)) {
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
if (arrowsShot != null) {
container.remove(toolStats.arrowsShot);
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", arrowsShotFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (container.has(toolStats.flightTime)) {
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
if (flightTime != null) {
container.remove(toolStats.flightTime);
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
meta.lore(removeLore(meta.lore(), lineToRemove));
finalItem.setItemMeta(meta);
}
}
if (removeMeta) {
Integer origin = null;
if (container.has(toolStats.originType)) {
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
}
if (container.has(toolStats.timeCreated)) {
Long timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
if (timeCreated != null && origin != null) {
container.remove(toolStats.timeCreated);
Component timeCreatedLore = formatCreationTime(timeCreated, origin, finalItem);
meta.lore(removeLore(meta.lore(), timeCreatedLore));
}
}
if (container.has(toolStats.itemOwner)) {
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
if (owner != null && origin != null) {
container.remove(toolStats.itemOwner);
String ownerName = Bukkit.getOfflinePlayer(owner).getName();
if (ownerName != null) {
Component ownerLore = formatOwner(ownerName, origin, finalItem);
meta.lore(removeLore(meta.lore(), ownerLore));
}
}
}
if (origin != null) {
container.remove(toolStats.originType);
}
finalItem.setItemMeta(meta);
}
return finalItem;
}
} }

View File

@@ -23,6 +23,12 @@ permissions:
toolstats.reset.confirm: toolstats.reset.confirm:
description: Allows the usage of /toolstats reset confirm. description: Allows the usage of /toolstats reset confirm.
default: true default: true
toolstats.purge:
description: Allows the usage of /toolstats purge.
default: true
toolstats.purge.confirm:
description: Allows the usage of /toolstats purge confirm.
default: true
toolstats.givetokens: toolstats.givetokens:
description: Allows the usage of /toolstats givetoken. description: Allows the usage of /toolstats givetoken.
default: op default: op