more config changes

* fixed typo on config updater
* handle missing config messages a lot better
* only try to update lore if it's enabled, don't try then check if it's enabled
This commit is contained in:
hyperdefined
2023-10-21 18:52:58 -04:00
parent 59bfdf69ca
commit 700e7bca2c
13 changed files with 131 additions and 89 deletions

View File

@@ -25,7 +25,6 @@ import lol.hyper.toolstats.tools.*;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;

View File

@@ -107,11 +107,10 @@ public class BlocksMined implements Listener {
blocksMined++; blocksMined++;
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined); container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) { if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) {
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
meta.setLore(newLore); meta.setLore(newLore);
} }
playerTool.setItemMeta(meta); playerTool.setItemMeta(meta);
@@ -144,11 +143,10 @@ public class BlocksMined implements Listener {
cropsMined++; cropsMined++;
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined); container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined);
String cropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{crops}", cropsMinedFormatted, "crops-harvested");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) { if (toolStats.checkConfig(playerTool.getType(), "blocks-mined")) {
String cropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{crops}", cropsMinedFormatted, "crops-harvested");
meta.setLore(newLore); meta.setLore(newLore);
} }
playerTool.setItemMeta(meta); playerTool.setItemMeta(meta);

View File

@@ -113,18 +113,6 @@ public class CraftItem implements Listener {
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 0); container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
if (createdOnRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
return null;
}
if (createdByRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
return null;
}
List<String> lore; List<String> lore;
// get the current lore the item // get the current lore the item
if (meta.hasLore()) { if (meta.hasLore()) {
@@ -134,12 +122,23 @@ public class CraftItem implements Listener {
} }
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(itemStack.getType(), "created-date")) { if (toolStats.checkConfig(itemStack.getType(), "created-date")) {
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
if (createdOnRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
return null;
}
lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate))); lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate)));
meta.setLore(lore);
} }
if (toolStats.checkConfig(itemStack.getType(), "created-by")) { if (toolStats.checkConfig(itemStack.getType(), "created-by")) {
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
if (createdByRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
return null;
}
lore.add(createdByRaw.replace("{player}", owner.getName())); lore.add(createdByRaw.replace("{player}", owner.getName()));
meta.setLore(lore);
} }
meta.setLore(lore);
newItem.setItemMeta(meta); newItem.setItemMeta(meta);
return newItem; return newItem;
} }

View File

@@ -97,10 +97,9 @@ public class CreativeEvent implements Listener {
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 6); container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
if (toolStats.checkConfig(newSpawnedItem.getType(), "spawned-in")) { if (toolStats.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
meta.setLore(newLore); meta.setLore(newLore);
} }

View File

@@ -244,11 +244,10 @@ public class EntityDamage implements Listener {
playerKills++; playerKills++;
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills); container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(itemStack.getType(), "player-kills")) { if (toolStats.checkConfig(itemStack.getType(), "player-kills")) {
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
meta.setLore(newLore); meta.setLore(newLore);
} }
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
@@ -279,11 +278,10 @@ public class EntityDamage implements Listener {
mobKills++; mobKills++;
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills); container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(itemStack.getType(), "mob-kills")) { if (toolStats.checkConfig(itemStack.getType(), "mob-kills")) {
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
meta.setLore(newLore); meta.setLore(newLore);
} }
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
@@ -316,10 +314,9 @@ public class EntityDamage implements Listener {
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken); container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
container.set(toolStats.armorDamageInt, PersistentDataType.INTEGER, damageTaken.intValue()); container.set(toolStats.armorDamageInt, PersistentDataType.INTEGER, damageTaken.intValue());
String damageTakenFormatted = toolStats.numberFormat.formatDouble(damageTaken);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{damage}", damageTakenFormatted, "damage-taken");
if (toolStats.config.getBoolean("enabled.armor-damage")) { if (toolStats.config.getBoolean("enabled.armor-damage")) {
String damageTakenFormatted = toolStats.numberFormat.formatDouble(damageTaken);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{damage}", damageTakenFormatted, "damage-taken");
meta.setLore(newLore); meta.setLore(newLore);
} }
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
@@ -351,11 +348,10 @@ public class EntityDamage implements Listener {
mobKills++; mobKills++;
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills); container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(newTrident.getType(), "mob-kills")) { if (toolStats.checkConfig(newTrident.getType(), "mob-kills")) {
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
meta.setLore(newLore); meta.setLore(newLore);
} }
newTrident.setItemMeta(meta); newTrident.setItemMeta(meta);
@@ -388,11 +384,10 @@ public class EntityDamage implements Listener {
playerKills++; playerKills++;
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills); container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(newTrident.getType(), "player-kills")) { if (toolStats.checkConfig(newTrident.getType(), "player-kills")) {
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
meta.setLore(newLore); meta.setLore(newLore);
} }
newTrident.setItemMeta(meta); newTrident.setItemMeta(meta);

View File

@@ -85,9 +85,8 @@ public class EntityDeath implements Listener {
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(toolStats.originType, PersistentDataType.INTEGER, 1); container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{name}", mob, "dropped-by");
if (toolStats.config.getBoolean("enabled.dropped-by")) { if (toolStats.config.getBoolean("enabled.dropped-by")) {
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{name}", mob, "dropped-by");
meta.setLore(newLore); meta.setLore(newLore);
} }
newItem.setItemMeta(meta); newItem.setItemMeta(meta);

View File

@@ -116,10 +116,9 @@ public class GenerateLoot implements Listener {
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 2); container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
if (toolStats.checkConfig(newItem.getType(), "looted-tag")) { if (toolStats.checkConfig(newItem.getType(), "looted-tag")) {
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
meta.setLore(newLore); meta.setLore(newLore);
} }
newItem.setItemMeta(meta); newItem.setItemMeta(meta);

View File

@@ -101,10 +101,9 @@ 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);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
if (toolStats.config.getBoolean("enabled.elytra-tag")) { if (toolStats.config.getBoolean("enabled.elytra-tag")) {
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
meta.setLore(newLore); meta.setLore(newLore);
} }
finalItem.setItemMeta(meta); finalItem.setItemMeta(meta);

View File

@@ -124,10 +124,9 @@ public class PlayerFish implements Listener {
fishCaught++; fishCaught++;
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught); container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught);
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{fish}", fishCaughtFormatted, "fished.fish-caught");
if (toolStats.config.getBoolean("enabled.fish-caught")) { if (toolStats.config.getBoolean("enabled.fish-caught")) {
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{fish}", fishCaughtFormatted, "fished.fish-caught");
meta.setLore(newLore); meta.setLore(newLore);
} }
fishingRod.setItemMeta(meta); fishingRod.setItemMeta(meta);
@@ -161,10 +160,9 @@ public class PlayerFish implements Listener {
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 5); container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
if (toolStats.checkConfig(newItem.getType(), "fished-tag")) { if (toolStats.checkConfig(newItem.getType(), "fished-tag")) {
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
meta.setLore(newLore); meta.setLore(newLore);
} }
newItem.setItemMeta(meta); newItem.setItemMeta(meta);

View File

@@ -117,10 +117,9 @@ public class SheepShear implements Listener {
sheepSheared++; sheepSheared++;
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared); container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared);
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{sheep}", sheepShearedFormatted, "sheep-sheared");
if (toolStats.config.getBoolean("enabled.sheep-sheared")) { if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{sheep}", sheepShearedFormatted, "sheep-sheared");
meta.setLore(newLore); meta.setLore(newLore);
} }
newShears.setItemMeta(meta); newShears.setItemMeta(meta);

View File

@@ -115,10 +115,9 @@ public class VillagerTrade implements Listener {
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId()); container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 3); container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
if (toolStats.checkConfig(newItem.getType(), "traded-tag")) { if (toolStats.checkConfig(newItem.getType(), "traded-tag")) {
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
meta.setLore(newLore); meta.setLore(newLore);
} }
newItem.setItemMeta(meta); newItem.setItemMeta(meta);

View File

@@ -61,9 +61,9 @@ public class ConfigUpdater {
toolStats.logger.info("Adding enabled.spawned-in.bow to config.yml."); toolStats.logger.info("Adding enabled.spawned-in.bow to config.yml.");
toolStats.config.set("enabled.spawned-in.armor", true); toolStats.config.set("enabled.spawned-in.armor", true);
toolStats.logger.info("Adding enabled.spawned-in.armor to config.yml."); toolStats.logger.info("Adding enabled.spawned-in.armor to config.yml.");
toolStats.config.set("messages.spawned.spawned-by", "&7Spawned in by: &8{player}"); toolStats.config.set("messages.spawned-in.spawned-by", "&7Spawned in by: &8{player}");
toolStats.logger.info("Adding messages.spawned-in.spawned-by to config.yml."); toolStats.logger.info("Adding messages.spawned-in.spawned-by to config.yml.");
toolStats.config.set("messages.spawned.spawned-on", "&7Spawned on: &8{date}"); toolStats.config.set("messages.spawned-in.spawned-on", "&7Spawned on: &8{date}");
toolStats.logger.info("Adding messages.spawned-in.spawned-on to config.yml."); toolStats.logger.info("Adding messages.spawned-in.spawned-on to config.yml.");
toolStats.config.set("generate-hash-for-items", true); toolStats.config.set("generate-hash-for-items", true);
toolStats.logger.info("Adding generate-hash-for-items to config.yml."); toolStats.logger.info("Adding generate-hash-for-items to config.yml.");

View File

@@ -34,7 +34,7 @@ public class ItemLore {
} }
/** /**
* Adds new lore to an item. * Adds/updates lore for an item.
* *
* @param placeholder The placeholder from the config. ex: {kills} * @param placeholder The placeholder from the config. ex: {kills}
* @param placeholderValue The value to replace the placeholder. * @param placeholderValue The value to replace the placeholder.
@@ -80,7 +80,7 @@ public class ItemLore {
} }
/** /**
* Adds new ownership tag to an item. * Adds new ownership to an item.
* *
* @param itemMeta The item meta. * @param itemMeta The item meta.
* @param playerName The new owner of item. * @param playerName The new owner of item.
@@ -88,49 +88,108 @@ public class ItemLore {
* @return The item's new lore. * @return The item's new lore.
*/ */
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) { public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
String dateCreated = null; String dateCreatedLore;
String itemOwner = null; String itemOwnerLore;
Integer origin = null; Integer origin = null;
PersistentDataContainer container = itemMeta.getPersistentDataContainer(); PersistentDataContainer container = itemMeta.getPersistentDataContainer();
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) { if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
origin = container.get(toolStats.originType, PersistentDataType.INTEGER); origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
} }
// if the origin is broken, don't try to set the lore
if (origin == null) { if (origin == null) {
origin = -1; toolStats.logger.info("Unable to determine origin for item " + itemMeta.getAsString());
toolStats.logger.info("This IS a bug, please report this to the GitHub.");
return itemMeta.getLore();
} }
// set the lore based on the origin
switch (origin) { switch (origin) {
case 2: { case 2: {
dateCreated = toolStats.getLoreFromConfig("looted.looted-on", true); dateCreatedLore = toolStats.getLoreFromConfig("looted.looted-on", true);
itemOwner = toolStats.getLoreFromConfig("looted.looted-by", true); itemOwnerLore = toolStats.getLoreFromConfig("looted.looted-by", true);
if (dateCreatedLore == null) {
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
if (itemOwnerLore == null) {
toolStats.logger.warning("messages.looted.looted-by is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
break; break;
} }
case 3: { case 3: {
dateCreated = toolStats.getLoreFromConfig("traded.traded-on", true); dateCreatedLore = toolStats.getLoreFromConfig("traded.traded-on", true);
itemOwner = toolStats.getLoreFromConfig("traded.traded-by", true); itemOwnerLore = toolStats.getLoreFromConfig("traded.traded-by", true);
if (dateCreatedLore == null) {
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
if (itemOwnerLore == null) {
toolStats.logger.warning("messages.traded.traded-by is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
break; break;
} }
case 4: { case 4: {
dateCreated = toolStats.getLoreFromConfig("looted.found-on", true); dateCreatedLore = toolStats.getLoreFromConfig("looted.found-on", true);
itemOwner = toolStats.getLoreFromConfig("looted.found-by", true); itemOwnerLore = toolStats.getLoreFromConfig("looted.found-by", true);
if (dateCreatedLore == null) {
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
if (itemOwnerLore == null) {
toolStats.logger.warning("messages.looted.found-by is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
break; break;
} }
case 5: { case 5: {
dateCreated = toolStats.getLoreFromConfig("fished.caught-on", true); dateCreatedLore = toolStats.getLoreFromConfig("fished.caught-on", true);
itemOwner = toolStats.getLoreFromConfig("fished.caught-by", true); itemOwnerLore = toolStats.getLoreFromConfig("fished.caught-by", true);
if (dateCreatedLore == null) {
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
if (itemOwnerLore == null) {
toolStats.logger.warning("messages.fished.caught-by is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
break; break;
} }
case 6: { case 6: {
dateCreated = toolStats.getLoreFromConfig("spawned-in.spawned-on", true); dateCreatedLore = toolStats.getLoreFromConfig("spawned-in.spawned-on", true);
itemOwner = toolStats.getLoreFromConfig("spawned-in.spawned-by", true); itemOwnerLore = toolStats.getLoreFromConfig("spawned-in.spawned-by", true);
if (dateCreatedLore == null) {
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
if (itemOwnerLore == null) {
toolStats.logger.warning("messages.spawned-in.spawned-by is not set in your config!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
break; break;
} }
} default: {
toolStats.logger.warning("Origin " + origin + " was found. Data was modified OR something REALLY broke.");
if (dateCreated == null || itemOwner == null) { toolStats.logger.warning(itemMeta.getAsString());
toolStats.logger.info("Unable to determine origin of item for " + itemMeta); return itemMeta.getLore();
return itemMeta.getLore(); }
} }
List<String> newLore; List<String> newLore;
@@ -140,8 +199,8 @@ public class ItemLore {
newLore = new ArrayList<>(); newLore = new ArrayList<>();
} }
newLore.add(dateCreated.replace("{date}", formattedDate)); newLore.add(dateCreatedLore.replace("{date}", formattedDate));
newLore.add(itemOwner.replace("{player}", playerName)); newLore.add(itemOwnerLore.replace("{player}", playerName));
return newLore; return newLore;
} }
@@ -160,15 +219,15 @@ public class ItemLore {
lore = itemMeta.getLore(); lore = itemMeta.getLore();
Integer origin = null; Integer origin = null;
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);
for (String line : lore) { for (String line : lore) {
// this is the worst code I have ever written // 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)) { if (createdBy != null && line.contains(createdBy)) {
origin = 0; origin = 0;
} }