diff --git a/src/main/java/lol/hyper/toolstats/ToolStats.java b/src/main/java/lol/hyper/toolstats/ToolStats.java index b8b7fa2..f977b2e 100644 --- a/src/main/java/lol/hyper/toolstats/ToolStats.java +++ b/src/main/java/lol/hyper/toolstats/ToolStats.java @@ -34,6 +34,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.logging.Logger; @@ -60,9 +61,8 @@ public final class ToolStats extends JavaPlugin { public final NamespacedKey newElytra = new NamespacedKey(this, "new"); public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH); - public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00"); - public final DecimalFormat commaFormat = new DecimalFormat("#,###"); - + public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault())); + public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault())); public BlocksMined blocksMined; public ChunkPopulate chunkPopulate; public CraftItem craftItem; @@ -121,6 +121,8 @@ public final class ToolStats extends JavaPlugin { new Metrics(this, 14110); Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates); + + logger.info("Locale: " + Locale.getDefault()); } public void loadConfig() { @@ -264,7 +266,7 @@ public final class ToolStats extends JavaPlugin { } public BukkitAudiences getAdventure() { - if(this.adventure == null) { + if (this.adventure == null) { throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); } return this.adventure; diff --git a/src/main/java/lol/hyper/toolstats/events/BlocksMined.java b/src/main/java/lol/hyper/toolstats/events/BlocksMined.java index 6e40127..11b7bf4 100644 --- a/src/main/java/lol/hyper/toolstats/events/BlocksMined.java +++ b/src/main/java/lol/hyper/toolstats/events/BlocksMined.java @@ -73,7 +73,7 @@ public class BlocksMined implements Listener { } // read the current stats from the item // if they don't exist, then start from 0 - Integer blocksMined = 0; + Integer blocksMined; PersistentDataContainer container = meta.getPersistentDataContainer(); if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) { blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER); @@ -98,6 +98,7 @@ public class BlocksMined implements Listener { } List lore; + String newLine = configLoreRaw.replace("{blocks}", toolStats.thousandsFormat.format(blocksMined)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -106,18 +107,18 @@ public class BlocksMined implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(configLore)) { hasLore = true; - lore.set(x, configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined))); + lore.add(newLine); } // do we add the lore based on the config? if (toolStats.checkConfig(playerTool, "blocks-mined")) { diff --git a/src/main/java/lol/hyper/toolstats/events/EntityDamage.java b/src/main/java/lol/hyper/toolstats/events/EntityDamage.java index 7d934fe..8a8d3d4 100644 --- a/src/main/java/lol/hyper/toolstats/events/EntityDamage.java +++ b/src/main/java/lol/hyper/toolstats/events/EntityDamage.java @@ -219,7 +219,7 @@ public class EntityDamage implements Listener { toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats."); return null; } - Integer playerKills = null; + Integer playerKills; PersistentDataContainer container = meta.getPersistentDataContainer(); if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) { playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER); @@ -243,6 +243,7 @@ public class EntityDamage implements Listener { } List lore; + String newLine = playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -251,18 +252,18 @@ public class EntityDamage implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(playerKillsLore)) { hasLore = true; - lore.set(x, playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills))); + lore.add(newLine); } // do we add the lore based on the config? if (toolStats.checkConfig(itemStack, "player-kills")) { @@ -285,7 +286,7 @@ public class EntityDamage implements Listener { toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats."); return null; } - Integer mobKills = null; + Integer mobKills; PersistentDataContainer container = meta.getPersistentDataContainer(); if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) { mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER); @@ -310,6 +311,7 @@ public class EntityDamage implements Listener { } List lore; + String newLine = mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -318,18 +320,18 @@ public class EntityDamage implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(mobKillsLore)) { hasLore = true; - lore.set(x, mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills))); + lore.add(newLine); } // do we add the lore based on the config? if (toolStats.checkConfig(itemStack, "mob-kills")) { @@ -376,6 +378,7 @@ public class EntityDamage implements Listener { } List lore; + String newLine = damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -384,18 +387,18 @@ public class EntityDamage implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(damageTakenLore)) { hasLore = true; - lore.set(x, damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken))); + lore.add(newLine); } if (toolStats.config.getBoolean("enabled.armor-damage")) { meta.setLore(lore); diff --git a/src/main/java/lol/hyper/toolstats/events/PlayerFish.java b/src/main/java/lol/hyper/toolstats/events/PlayerFish.java index 62bfee0..b33ef71 100644 --- a/src/main/java/lol/hyper/toolstats/events/PlayerFish.java +++ b/src/main/java/lol/hyper/toolstats/events/PlayerFish.java @@ -20,7 +20,6 @@ package lol.hyper.toolstats.events; import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.tools.ItemChecker; import lol.hyper.toolstats.tools.UUIDDataType; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.Item; @@ -37,7 +36,6 @@ import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.ListIterator; public class PlayerFish implements Listener { @@ -63,7 +61,6 @@ public class PlayerFish implements Listener { } // make sure the player is holding a fishing rod ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot()); - int heldItemSlot = player.getInventory().getHeldItemSlot(); if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.FISHING_ROD) { return; } @@ -86,7 +83,6 @@ public class PlayerFish implements Listener { /** * Update a fishing rod's fish count. * @param fishingRod The fishing rod to update. - * @return A new fishing rod with update counts. */ private void updateFishCount(ItemStack fishingRod) { ItemMeta meta = fishingRod.getItemMeta(); @@ -119,6 +115,7 @@ public class PlayerFish implements Listener { } List lore; + String newLine = fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -127,18 +124,18 @@ public class PlayerFish implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(fishCaughtLore)) { hasLore = true; - lore.set(x, fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught))); + lore.add(newLine); } /* diff --git a/src/main/java/lol/hyper/toolstats/events/SheepShear.java b/src/main/java/lol/hyper/toolstats/events/SheepShear.java index b986f67..cdeb24d 100644 --- a/src/main/java/lol/hyper/toolstats/events/SheepShear.java +++ b/src/main/java/lol/hyper/toolstats/events/SheepShear.java @@ -110,6 +110,7 @@ public class SheepShear implements Listener { } List lore; + String newLine = sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)); if (meta.hasLore()) { lore = meta.getLore(); boolean hasLore = false; @@ -118,18 +119,18 @@ public class SheepShear implements Listener { for (int x = 0; x < lore.size(); x++) { if (lore.get(x).contains(sheepShearedLore)) { hasLore = true; - lore.set(x, sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared))); + lore.set(x, newLine); break; } } // if the item has lore but doesn't have the tag, add it if (!hasLore) { - lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared))); + lore.add(newLine); } } else { // if the item has no lore, create a new list and add the string lore = new ArrayList<>(); - lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared))); + lore.add(newLine); } if (toolStats.config.getBoolean("enabled.sheep-sheared")) { meta.setLore(lore);