2121import lol .hyper .toolstats .UUIDDataType ;
2222import org .bukkit .*;
2323import org .bukkit .command .Command ;
24- import org .bukkit .command .CommandExecutor ;
2524import org .bukkit .command .CommandSender ;
2625import org .bukkit .command .TabExecutor ;
2726import org .bukkit .entity .Player ;
@@ -88,11 +87,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
8887 return true ;
8988 }
9089
91- private ItemStack fixItemLore (ItemStack original , Player player ) {
90+ /**
91+ * Fixes lore on a given item. This will wipe all lore and reapply our custom ones.
92+ * @param original The item we are fixing.
93+ * @param player The player running the command.
94+ */
95+ private void fixItemLore (ItemStack original , Player player ) {
9296 ItemStack finalItem = original .clone ();
9397 ItemMeta finalMeta = finalItem .getItemMeta ();
9498 if (finalMeta == null ) {
95- return null ;
99+ return ;
96100 }
97101 PersistentDataContainer container = finalMeta .getPersistentDataContainer ();
98102 List <String > lore = new ArrayList <>();
@@ -101,10 +105,14 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
101105 String lootedByLore = toolStats .getLoreFromConfig ("looted.found-by" , false );
102106 String tradedByLore = toolStats .getLoreFromConfig ("traded.traded-by" , false );
103107
108+ // make sure the config messages are not null
104109 if (caughtByLore == null || lootedByLore == null || tradedByLore == null ) {
105- return null ;
110+ return ;
106111 }
107112
113+ // determine how the item was originally created
114+ // this doesn't get saved, so we just rely on the lore
115+ // if there isn't a tag, default to crafted
108116 String type = "DEFAULT" ;
109117 if (finalMeta .hasLore ()) {
110118 if (finalMeta .getLore () != null ) {
@@ -124,6 +132,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
124132 if (toolStats .checkConfig (original , "created-by" )) {
125133 if (container .has (toolStats .genericOwner , new UUIDDataType ())) {
126134 container .set (toolStats .genericOwner , new UUIDDataType (), player .getUniqueId ());
135+ // show how the item was created based on the previous lore
127136 switch (type ) {
128137 case "DEFAULT" : {
129138 lore .add (toolStats .getLoreFromConfig ("created.created-by" , true ).replace ("{player}" , player .getName ()));
@@ -148,8 +157,9 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
148157 if (container .has (toolStats .timeCreated , PersistentDataType .LONG )) {
149158 Long time = container .get (toolStats .timeCreated , PersistentDataType .LONG );
150159 if (time == null ) {
151- return null ;
160+ return ;
152161 }
162+ // show how when the item was created based on the previous lore
153163 switch (type ) {
154164 case "DEFAULT" : {
155165 lore .add (toolStats .getLoreFromConfig ("created.created-by" , true ).replace ("{date}" , format .format (new Date (time ))));
@@ -174,7 +184,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
174184 if (container .has (toolStats .swordPlayerKills , PersistentDataType .INTEGER )) {
175185 Integer kills = container .get (toolStats .swordPlayerKills , PersistentDataType .INTEGER );
176186 if (kills == null ) {
177- return null ;
187+ return ;
178188 }
179189 lore .add (toolStats .getLoreFromConfig ("kills.player" , true ).replace ("{kills}" , Integer .toString (kills )));
180190 }
@@ -183,7 +193,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
183193 if (container .has (toolStats .swordMobKills , PersistentDataType .INTEGER )) {
184194 Integer kills = container .get (toolStats .swordMobKills , PersistentDataType .INTEGER );
185195 if (kills == null ) {
186- return null ;
196+ return ;
187197 }
188198 lore .add (toolStats .getLoreFromConfig ("kills.mob" , true ).replace ("{kills}" , Integer .toString (kills )));
189199 }
@@ -192,7 +202,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
192202 if (container .has (toolStats .genericMined , PersistentDataType .INTEGER )) {
193203 Integer blocksMined = container .get (toolStats .genericMined , PersistentDataType .INTEGER );
194204 if (blocksMined == null ) {
195- return null ;
205+ return ;
196206 }
197207 lore .add (toolStats .getLoreFromConfig ("blocks-mined" , true ).replace ("{blocks}" , Integer .toString (blocksMined )));
198208 }
@@ -201,7 +211,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
201211 if (container .has (toolStats .fishingRodCaught , PersistentDataType .INTEGER )) {
202212 Integer fish = container .get (toolStats .fishingRodCaught , PersistentDataType .INTEGER );
203213 if (fish == null ) {
204- return null ;
214+ return ;
205215 }
206216 lore .add (toolStats .getLoreFromConfig ("fished.fish-caught" , true ).replace ("{fish}" , Integer .toString (fish )));
207217 }
@@ -210,7 +220,7 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
210220 if (container .has (toolStats .shearsSheared , PersistentDataType .INTEGER )) {
211221 Integer sheep = container .get (toolStats .shearsSheared , PersistentDataType .INTEGER );
212222 if (sheep == null ) {
213- return null ;
223+ return ;
214224 }
215225 lore .add (toolStats .getLoreFromConfig ("sheep-sheared" , true ).replace ("{sheep}" , Integer .toString (sheep )));
216226 }
@@ -219,14 +229,13 @@ private ItemStack fixItemLore(ItemStack original, Player player) {
219229 if (container .has (toolStats .armorDamage , PersistentDataType .INTEGER )) {
220230 Integer damage = container .get (toolStats .armorDamage , PersistentDataType .INTEGER );
221231 if (damage == null ) {
222- return null ;
232+ return ;
223233 }
224234 lore .add (toolStats .getLoreFromConfig ("damage-taken" , true ).replace ("{damage}" , Integer .toString (damage )));
225235 }
226236 }
227237 finalMeta .setLore (lore );
228238 finalItem .setItemMeta (finalMeta );
229- return finalItem ;
230239 }
231240
232241 @ Nullable
0 commit comments