1919
2020import lol .hyper .toolstats .ToolStats ;
2121import lol .hyper .toolstats .tools .UUIDDataType ;
22- import org .bukkit .Bukkit ;
23- import org .bukkit .Location ;
22+ import org .bukkit .entity .Player ;
2423import org .bukkit .event .EventHandler ;
2524import org .bukkit .event .Listener ;
2625import org .bukkit .event .inventory .InventoryOpenEvent ;
@@ -47,7 +46,7 @@ public void onOpen(InventoryOpenEvent event) {
4746 }
4847
4948 Inventory inventory = event .getInventory ();
50- Location location = event . getInventory (). getLocation ();
49+ Player player = ( Player ) event . getPlayer ();
5150 for (ItemStack itemStack : inventory ) {
5251 if (itemStack == null ) {
5352 continue ;
@@ -75,31 +74,35 @@ public void onOpen(InventoryOpenEvent event) {
7574 }
7675 }
7776
78- // generate a hash if the item doesn't have one (if it's enabled in the config)
77+ // generate a hash if the item doesn't have one (and enabled)
78+ // if hashes are disabled and the item has one, remove it.
7979 if (toolStats .config .getBoolean ("generate-hash-for-items" )) {
8080 if (!container .has (toolStats .hash , PersistentDataType .STRING )) {
81- // make sure the item has an owner
82- if (!container .has (toolStats .itemOwner , new UUIDDataType ())) {
83- continue ;
81+ UUID owner = null ;
82+ // get the current owner if there is one.
83+ if (container .has (toolStats .itemOwner , new UUIDDataType ())) {
84+ owner = container .get (toolStats .itemOwner , new UUIDDataType ());
8485 }
85- UUID owner = container . get ( toolStats . itemOwner , new UUIDDataType ());
86+ // if there is no owner, use the player holding it
8687 if (owner == null ) {
87- continue ;
88+ owner = player . getUniqueId () ;
8889 }
8990 Long timestamp = container .get (toolStats .timeCreated , PersistentDataType .LONG );
9091 if (timestamp == null ) {
91- continue ;
92+ // if there is no time created, use now
93+ timestamp = System .currentTimeMillis ();
9294 }
9395 String hash = toolStats .hashMaker .makeHash (itemStack .getType (), owner , timestamp );
9496 container .set (toolStats .hash , PersistentDataType .STRING , hash );
97+ itemStack .setItemMeta (itemMeta );
98+ }
99+ } else {
100+ // if hashes are disabled but the item has one, remove it.
101+ if (container .has (toolStats .hash , PersistentDataType .STRING )) {
102+ container .remove (toolStats .hash );
103+ itemStack .setItemMeta (itemMeta );
95104 }
96105 }
97- ItemMeta clone = itemMeta .clone ();
98- if (location != null ) {
99- Bukkit .getRegionScheduler ().runDelayed (toolStats , location , scheduledTask -> itemStack .setItemMeta (clone ), 1 );
100- }
101-
102-
103106 }
104107 }
105108}
0 commit comments