Skip to content

Commit 2b75ea0

Browse files
committed
maybe not do this?
1 parent bc8496f commit 2b75ea0

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/main/java/lol/hyper/toolstats/events/BlocksMined.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,14 @@ public void onBreak(BlockBreakEvent event) {
6262
return;
6363
}
6464
// if it's an item we want, update the stats
65-
ItemStack newTool = updateBlocksMined(heldItem);
66-
if (newTool != null) {
67-
player.getInventory().setItem(heldItemSlot, newTool);
68-
}
65+
updateBlocksMined(heldItem);
6966
}
7067

71-
private ItemStack updateBlocksMined(ItemStack originalTool) {
72-
ItemStack newTool = originalTool.clone();
73-
ItemMeta meta = newTool.getItemMeta();
68+
private void updateBlocksMined(ItemStack playerTool) {
69+
ItemMeta meta = playerTool.getItemMeta();
7470
if (meta == null) {
75-
toolStats.logger.warning(originalTool + " does NOT have any meta! Unable to update stats.");
76-
return null;
71+
toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats.");
72+
return;
7773
}
7874
// read the current stats from the item
7975
// if they don't exist, then start from 0
@@ -87,7 +83,7 @@ private ItemStack updateBlocksMined(ItemStack originalTool) {
8783

8884
if (blocksMined == null) {
8985
blocksMined = 0;
90-
toolStats.logger.warning(originalTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
86+
toolStats.logger.warning(playerTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
9187
}
9288

9389
blocksMined++;
@@ -98,7 +94,7 @@ private ItemStack updateBlocksMined(ItemStack originalTool) {
9894

9995
if (configLore == null || configLoreRaw == null) {
10096
toolStats.logger.warning("There is no lore message for messages.blocks-mined!");
101-
return null;
97+
return;
10298
}
10399

104100
List<String> lore;
@@ -124,10 +120,9 @@ private ItemStack updateBlocksMined(ItemStack originalTool) {
124120
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
125121
}
126122
// do we add the lore based on the config?
127-
if (toolStats.checkConfig(newTool, "blocks-mined")) {
123+
if (toolStats.checkConfig(playerTool, "blocks-mined")) {
128124
meta.setLore(lore);
129125
}
130-
newTool.setItemMeta(meta);
131-
return newTool;
126+
playerTool.setItemMeta(meta);
132127
}
133128
}

src/main/java/lol/hyper/toolstats/events/PlayerFish.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lol.hyper.toolstats.ToolStats;
2121
import lol.hyper.toolstats.tools.ItemChecker;
2222
import lol.hyper.toolstats.tools.UUIDDataType;
23+
import org.bukkit.Bukkit;
2324
import org.bukkit.GameMode;
2425
import org.bukkit.Material;
2526
import org.bukkit.entity.Item;
@@ -36,6 +37,7 @@
3637
import java.util.ArrayList;
3738
import java.util.Date;
3839
import java.util.List;
40+
import java.util.ListIterator;
3941

4042
public class PlayerFish implements Listener {
4143

@@ -45,7 +47,7 @@ public PlayerFish(ToolStats toolStats) {
4547
this.toolStats = toolStats;
4648
}
4749

48-
@EventHandler(priority = EventPriority.HIGHEST)
50+
@EventHandler(priority = EventPriority.HIGH)
4951
public void onFish(PlayerFishEvent event) {
5052
if (event.isCancelled()) {
5153
return;
@@ -66,10 +68,7 @@ public void onFish(PlayerFishEvent event) {
6668
return;
6769
}
6870
// update the fishing rod to the new one
69-
ItemStack newRod = updateFishCount(heldItem);
70-
if (newRod != null) {
71-
player.getInventory().setItem(heldItemSlot, newRod);
72-
}
71+
updateFishCount(heldItem);
7372
// check if the player caught an item
7473
if (event.getCaught() == null) {
7574
return;
@@ -86,15 +85,14 @@ public void onFish(PlayerFishEvent event) {
8685

8786
/**
8887
* Update a fishing rod's fish count.
89-
* @param originalRod The fishing rod to update.
88+
* @param fishingRod The fishing rod to update.
9089
* @return A new fishing rod with update counts.
9190
*/
92-
private ItemStack updateFishCount(ItemStack originalRod) {
93-
ItemStack newRod = originalRod.clone();
94-
ItemMeta meta = newRod.getItemMeta();
91+
private void updateFishCount(ItemStack fishingRod) {
92+
ItemMeta meta = fishingRod.getItemMeta();
9593
if (meta == null) {
96-
toolStats.logger.warning(originalRod + " does NOT have any meta! Unable to update stats.");
97-
return null;
94+
toolStats.logger.warning(fishingRod + " does NOT have any meta! Unable to update stats.");
95+
return;
9896
}
9997
Integer fishCaught;
10098
PersistentDataContainer container = meta.getPersistentDataContainer();
@@ -106,7 +104,7 @@ private ItemStack updateFishCount(ItemStack originalRod) {
106104

107105
if (fishCaught == null) {
108106
fishCaught = 0;
109-
toolStats.logger.warning(originalRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
107+
toolStats.logger.warning(fishingRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
110108
}
111109

112110
fishCaught++;
@@ -117,7 +115,7 @@ private ItemStack updateFishCount(ItemStack originalRod) {
117115

118116
if (fishCaughtLore == null || fishCaughtLoreRaw == null) {
119117
toolStats.logger.warning("There is no lore message for messages.fish-caught!");
120-
return null;
118+
return;
121119
}
122120

123121
List<String> lore;
@@ -142,11 +140,23 @@ private ItemStack updateFishCount(ItemStack originalRod) {
142140
lore = new ArrayList<>();
143141
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
144142
}
143+
144+
/*
145+
if (Bukkit.getPluginManager().isPluginEnabled("EvenMoreFish")) {
146+
ListIterator<String> iterator = lore.listIterator();
147+
while (iterator.hasNext()) {
148+
String line = iterator.next();
149+
toolStats.logger.info(line);
150+
if (line.equalsIgnoreCase("§f")) {
151+
iterator.remove();
152+
}
153+
}
154+
}*/
155+
145156
if (toolStats.config.getBoolean("enabled.fish-caught")) {
146157
meta.setLore(lore);
147158
}
148-
newRod.setItemMeta(meta);
149-
return newRod;
159+
fishingRod.setItemMeta(meta);
150160
}
151161

152162
/**

0 commit comments

Comments
 (0)