mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
maybe not do this?
This commit is contained in:
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> 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<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")) {
|
||||
meta.setLore(lore);
|
||||
}
|
||||
newRod.setItemMeta(meta);
|
||||
return newRod;
|
||||
fishingRod.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user