From 2b75ea094d32232a0afc4fab9555a89d3a5b0fa3 Mon Sep 17 00:00:00 2001 From: hyperdefined Date: Sun, 9 Oct 2022 16:51:26 -0400 Subject: [PATCH] maybe not do this? --- .../hyper/toolstats/events/BlocksMined.java | 23 +++++------ .../hyper/toolstats/events/PlayerFish.java | 40 ++++++++++++------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/main/java/lol/hyper/toolstats/events/BlocksMined.java b/src/main/java/lol/hyper/toolstats/events/BlocksMined.java index 39fd537..6e40127 100644 --- a/src/main/java/lol/hyper/toolstats/events/BlocksMined.java +++ b/src/main/java/lol/hyper/toolstats/events/BlocksMined.java @@ -62,18 +62,14 @@ public class BlocksMined implements Listener { return; } // if it's an item we want, update the stats - ItemStack newTool = updateBlocksMined(heldItem); - if (newTool != null) { - player.getInventory().setItem(heldItemSlot, newTool); - } + updateBlocksMined(heldItem); } - private ItemStack updateBlocksMined(ItemStack originalTool) { - ItemStack newTool = originalTool.clone(); - ItemMeta meta = newTool.getItemMeta(); + private void updateBlocksMined(ItemStack playerTool) { + ItemMeta meta = playerTool.getItemMeta(); if (meta == null) { - toolStats.logger.warning(originalTool + " does NOT have any meta! Unable to update stats."); - return null; + toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats."); + return; } // read the current stats from the item // if they don't exist, then start from 0 @@ -87,7 +83,7 @@ public class BlocksMined implements Listener { if (blocksMined == null) { blocksMined = 0; - toolStats.logger.warning(originalTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen."); + toolStats.logger.warning(playerTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen."); } blocksMined++; @@ -98,7 +94,7 @@ public class BlocksMined implements Listener { if (configLore == null || configLoreRaw == null) { toolStats.logger.warning("There is no lore message for messages.blocks-mined!"); - return null; + return; } List lore; @@ -124,10 +120,9 @@ public class BlocksMined implements Listener { lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined))); } // do we add the lore based on the config? - if (toolStats.checkConfig(newTool, "blocks-mined")) { + if (toolStats.checkConfig(playerTool, "blocks-mined")) { meta.setLore(lore); } - newTool.setItemMeta(meta); - return newTool; + playerTool.setItemMeta(meta); } } diff --git a/src/main/java/lol/hyper/toolstats/events/PlayerFish.java b/src/main/java/lol/hyper/toolstats/events/PlayerFish.java index 6759b91..62bfee0 100644 --- a/src/main/java/lol/hyper/toolstats/events/PlayerFish.java +++ b/src/main/java/lol/hyper/toolstats/events/PlayerFish.java @@ -20,6 +20,7 @@ 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; @@ -36,6 +37,7 @@ 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 { @@ -45,7 +47,7 @@ public class PlayerFish implements Listener { this.toolStats = toolStats; } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGH) public void onFish(PlayerFishEvent event) { if (event.isCancelled()) { return; @@ -66,10 +68,7 @@ public class PlayerFish implements Listener { return; } // update the fishing rod to the new one - ItemStack newRod = updateFishCount(heldItem); - if (newRod != null) { - player.getInventory().setItem(heldItemSlot, newRod); - } + updateFishCount(heldItem); // check if the player caught an item if (event.getCaught() == null) { return; @@ -86,15 +85,14 @@ public class PlayerFish implements Listener { /** * Update a fishing rod's fish count. - * @param originalRod The fishing rod to update. + * @param fishingRod The fishing rod to update. * @return A new fishing rod with update counts. */ - private ItemStack updateFishCount(ItemStack originalRod) { - ItemStack newRod = originalRod.clone(); - ItemMeta meta = newRod.getItemMeta(); + private void updateFishCount(ItemStack fishingRod) { + ItemMeta meta = fishingRod.getItemMeta(); if (meta == null) { - toolStats.logger.warning(originalRod + " does NOT have any meta! Unable to update stats."); - return null; + toolStats.logger.warning(fishingRod + " does NOT have any meta! Unable to update stats."); + return; } Integer fishCaught; PersistentDataContainer container = meta.getPersistentDataContainer(); @@ -106,7 +104,7 @@ public class PlayerFish implements Listener { if (fishCaught == null) { fishCaught = 0; - toolStats.logger.warning(originalRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen."); + toolStats.logger.warning(fishingRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen."); } fishCaught++; @@ -117,7 +115,7 @@ public class PlayerFish implements Listener { if (fishCaughtLore == null || fishCaughtLoreRaw == null) { toolStats.logger.warning("There is no lore message for messages.fish-caught!"); - return null; + return; } List lore; @@ -142,11 +140,23 @@ public class PlayerFish implements Listener { lore = new ArrayList<>(); lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught))); } + + /* + if (Bukkit.getPluginManager().isPluginEnabled("EvenMoreFish")) { + ListIterator iterator = lore.listIterator(); + while (iterator.hasNext()) { + String line = iterator.next(); + toolStats.logger.info(line); + if (line.equalsIgnoreCase("§f")) { + iterator.remove(); + } + } + }*/ + if (toolStats.config.getBoolean("enabled.fish-caught")) { meta.setLore(lore); } - newRod.setItemMeta(meta); - return newRod; + fishingRod.setItemMeta(meta); } /**