From 0b08f2a49ccd2ad51566635947ae31381dc7e1cb Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Sun, 12 Aug 2018 18:26:25 +0200 Subject: [PATCH] . --- plugin.yml | 4 ++-- .../JeffChestSort/JeffChestSortListener.java | 21 +++++++++++++++++-- .../JeffChestSort/JeffChestSortPlugin.java | 10 +++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugin.yml b/plugin.yml index 2db5ac7..4a01fa8 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,11 +1,11 @@ main: de.jeffclan.JeffChestSort.JeffChestSortPlugin name: ChestSort -version: 1.3.4 +version: 1.3.5 api-version: 1.13 description: Allows automatic chest sorting author: mfnalex website: www.jeff-media.de -prefix: [ChestSort] +prefix: ChestSort commands: chestsort: description: Toggle automatic chest sorting diff --git a/src/de/jeffclan/JeffChestSort/JeffChestSortListener.java b/src/de/jeffclan/JeffChestSort/JeffChestSortListener.java index c815ee7..470f5df 100644 --- a/src/de/jeffclan/JeffChestSort/JeffChestSortListener.java +++ b/src/de/jeffclan/JeffChestSort/JeffChestSortListener.java @@ -28,6 +28,11 @@ public class JeffChestSortListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + + if(event.getPlayer().getName().equalsIgnoreCase("mfnalex")) { + plugin.debug=true; + } + UUID uniqueId = event.getPlayer().getUniqueId(); if (!plugin.PerPlayerSettings.containsKey(uniqueId.toString())) { @@ -106,6 +111,16 @@ public class JeffChestSortListener implements Listener { } } } + + /* + * Alright, what the f**k is going on here? Well... + * + * First of all, we get the inventory's contents in a nice ItemStack-array. + * Altering this array does NOT change the inventory! We just use it to + * generate a sorted list of our items including a string (which happens + * to be the item's type) and a unique identifier, so that we will not + * confuse two items with the same name but different attributes. + */ Inventory inv = event.getInventory(); ItemStack[] items = inv.getContents(); @@ -115,7 +130,7 @@ public class JeffChestSortListener implements Listener { int i = 0; for (ItemStack item : items) { if (item != null) { - itemList[i] = item.getType().name() + "," + String.valueOf(item.hashCode()); + itemList[i] = plugin.getSortableString(item); i++; } } @@ -141,7 +156,9 @@ public class JeffChestSortListener implements Listener { // put everything back in the inventory for (String s : shortenedArray) { - // System.out.println(s); + if (plugin.debug) { + System.out.println(s); + } for (ItemStack item : items) { if (item != null && s != null) { if (item.hashCode() == Integer.parseInt(s.split(",")[1])) { diff --git a/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java index 5e9a569..db3b9ef 100644 --- a/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java +++ b/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java @@ -6,11 +6,13 @@ import java.util.HashMap; import java.util.Map; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; public class JeffChestSortPlugin extends JavaPlugin { + boolean debug = false; Map PerPlayerSettings = new HashMap(); JeffChestSortMessages msg; @@ -40,5 +42,13 @@ public class JeffChestSortPlugin extends JavaPlugin { if (!playerDataFolder.exists()) playerDataFolder.mkdir(); } + + String getSortableString(ItemStack item) { + return item.getType().name() + /*+ "," + + (10000-item.getDurability())*/ + + "," + + String.valueOf(item.hashCode()); + } }