maybe not do this?

This commit is contained in:
hyperdefined
2022-10-09 16:51:26 -04:00
parent bc8496fad4
commit 2b75ea094d
2 changed files with 34 additions and 29 deletions

View File

@@ -62,18 +62,14 @@ public class BlocksMined implements Listener {
return; return;
} }
// if it's an item we want, update the stats // if it's an item we want, update the stats
ItemStack newTool = updateBlocksMined(heldItem); updateBlocksMined(heldItem);
if (newTool != null) {
player.getInventory().setItem(heldItemSlot, newTool);
}
} }
private ItemStack updateBlocksMined(ItemStack originalTool) { private void updateBlocksMined(ItemStack playerTool) {
ItemStack newTool = originalTool.clone(); ItemMeta meta = playerTool.getItemMeta();
ItemMeta meta = newTool.getItemMeta();
if (meta == null) { if (meta == null) {
toolStats.logger.warning(originalTool + " does NOT have any meta! Unable to update stats."); toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats.");
return null; return;
} }
// read the current stats from the item // read the current stats from the item
// if they don't exist, then start from 0 // if they don't exist, then start from 0
@@ -87,7 +83,7 @@ public class BlocksMined implements Listener {
if (blocksMined == null) { if (blocksMined == null) {
blocksMined = 0; 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++; blocksMined++;
@@ -98,7 +94,7 @@ public class BlocksMined implements Listener {
if (configLore == null || configLoreRaw == null) { if (configLore == null || configLoreRaw == null) {
toolStats.logger.warning("There is no lore message for messages.blocks-mined!"); toolStats.logger.warning("There is no lore message for messages.blocks-mined!");
return null; return;
} }
List<String> lore; List<String> lore;
@@ -124,10 +120,9 @@ public class BlocksMined implements Listener {
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined))); lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
} }
// do we add the lore based on the config? // do we add the lore based on the config?
if (toolStats.checkConfig(newTool, "blocks-mined")) { if (toolStats.checkConfig(playerTool, "blocks-mined")) {
meta.setLore(lore); meta.setLore(lore);
} }
newTool.setItemMeta(meta); playerTool.setItemMeta(meta);
return newTool;
} }
} }

View File

@@ -20,6 +20,7 @@ package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.ItemChecker; import lol.hyper.toolstats.tools.ItemChecker;
import lol.hyper.toolstats.tools.UUIDDataType; import lol.hyper.toolstats.tools.UUIDDataType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@@ -36,6 +37,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ListIterator;
public class PlayerFish implements Listener { public class PlayerFish implements Listener {
@@ -45,7 +47,7 @@ public class PlayerFish implements Listener {
this.toolStats = toolStats; this.toolStats = toolStats;
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGH)
public void onFish(PlayerFishEvent event) { public void onFish(PlayerFishEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
@@ -66,10 +68,7 @@ public class PlayerFish implements Listener {
return; return;
} }
// update the fishing rod to the new one // update the fishing rod to the new one
ItemStack newRod = updateFishCount(heldItem); updateFishCount(heldItem);
if (newRod != null) {
player.getInventory().setItem(heldItemSlot, newRod);
}
// check if the player caught an item // check if the player caught an item
if (event.getCaught() == null) { if (event.getCaught() == null) {
return; return;
@@ -86,15 +85,14 @@ public class PlayerFish implements Listener {
/** /**
* Update a fishing rod's fish count. * 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. * @return A new fishing rod with update counts.
*/ */
private ItemStack updateFishCount(ItemStack originalRod) { private void updateFishCount(ItemStack fishingRod) {
ItemStack newRod = originalRod.clone(); ItemMeta meta = fishingRod.getItemMeta();
ItemMeta meta = newRod.getItemMeta();
if (meta == null) { if (meta == null) {
toolStats.logger.warning(originalRod + " does NOT have any meta! Unable to update stats."); toolStats.logger.warning(fishingRod + " does NOT have any meta! Unable to update stats.");
return null; return;
} }
Integer fishCaught; Integer fishCaught;
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -106,7 +104,7 @@ public class PlayerFish implements Listener {
if (fishCaught == null) { if (fishCaught == null) {
fishCaught = 0; 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++; fishCaught++;
@@ -117,7 +115,7 @@ public class PlayerFish implements Listener {
if (fishCaughtLore == null || fishCaughtLoreRaw == null) { if (fishCaughtLore == null || fishCaughtLoreRaw == null) {
toolStats.logger.warning("There is no lore message for messages.fish-caught!"); toolStats.logger.warning("There is no lore message for messages.fish-caught!");
return null; return;
} }
List<String> lore; List<String> lore;
@@ -142,11 +140,23 @@ public class PlayerFish implements Listener {
lore = new ArrayList<>(); lore = new ArrayList<>();
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught))); lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
} }
/*
if (Bukkit.getPluginManager().isPluginEnabled("EvenMoreFish")) {
ListIterator<String> 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")) { if (toolStats.config.getBoolean("enabled.fish-caught")) {
meta.setLore(lore); meta.setLore(lore);
} }
newRod.setItemMeta(meta); fishingRod.setItemMeta(meta);
return newRod;
} }
/** /**