This commit is contained in:
mfnalex 2018-08-12 18:26:25 +02:00
parent 82f8df253a
commit 0b08f2a49c
3 changed files with 31 additions and 4 deletions

View File

@ -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

View File

@ -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])) {

View File

@ -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<String, JeffChestSortPlayerSetting> PerPlayerSettings = new HashMap<String, JeffChestSortPlayerSetting>();
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());
}
}