unify owner and timestamp creation

This commit is contained in:
hyperdefined
2025-07-23 10:53:22 -04:00
parent 70ed50ce9e
commit 27a89fd67c
9 changed files with 191 additions and 204 deletions

View File

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

View File

@@ -92,8 +92,6 @@ public class CreativeEvent implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
}
PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -111,28 +109,21 @@ public class CreativeEvent implements Listener {
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.originType, PersistentDataType.INTEGER, 6);
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);
lore.add(creationDate);
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.originType, PersistentDataType.INTEGER, 6);
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
lore.add(itemOwner);
meta.lore(lore);
}

View File

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

View File

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

View File

@@ -114,8 +114,6 @@ public class PlayerFish implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
}
PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -131,28 +129,21 @@ public class PlayerFish implements Listener {
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.originType, PersistentDataType.INTEGER, 5);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
lore.add(creationDate);
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.originType, PersistentDataType.INTEGER, 5);
Component newLine = toolStats.configTools.formatLore("fished.caught-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
lore.add(itemOwner);
meta.lore(lore);
}

View File

@@ -131,8 +131,6 @@ public class VillagerTrade implements Listener {
if (toolStats.config.getBoolean("normalize-time-creation")) {
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
timeCreated = finalDate.getTime();
} else {
finalDate = new Date(timeCreated);
}
PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -148,28 +146,22 @@ public class VillagerTrade implements Listener {
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.originType, PersistentDataType.INTEGER, 3);
String date = toolStats.numberFormat.formatDate(finalDate);
Component newLine = toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(newLine);
lore.add(creationDate);
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.originType, PersistentDataType.INTEGER, 3);
Component newLine = toolStats.configTools.formatLore("traded.traded-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(newLine);
lore.add(itemOwner);
meta.lore(lore);
}