From 9a3756f3d0e90380f0ded792fb5354c671f7c9dd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Dec 2020 17:09:19 +0100 Subject: [PATCH] Extraced Inventory API Changes from BungeeSchemGUI --- .../bungeecore/commands/BauCommand.java | 8 +++-- .../bungeecore/comms/PacketIdManager.java | 1 - .../comms/packets/InventoryPacket.java | 2 +- .../bungeecore/inventory/SWInventory.java | 29 ++++++++----------- .../steamwar/bungeecore/inventory/SWItem.java | 21 +++++--------- .../bungeecore/inventory/SWListInv.java | 10 +++---- .../steamwar/messages/BungeeCore.properties | 7 ++++- 7 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 3385650..8f39327 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -239,9 +239,11 @@ public class BauCommand { } private static void delete(ProxiedPlayer p, String[] command){ - SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?"); - inventory.addItem(new SWItem(8, "§cAbbrechen", 1), click -> inventory.close()); - inventory.addItem(new SWItem(0, "§aLöschen", 10), click -> { + SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p)); + inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click -> + inventory.close() + ); + inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> { if(bau15(p, command, 2)){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId()); diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java index b2c3300..ae86d70 100644 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ b/src/de/steamwar/bungeecore/comms/PacketIdManager.java @@ -20,7 +20,6 @@ package de.steamwar.bungeecore.comms; public class PacketIdManager { - private PacketIdManager(){} //0x0(X) Standalone Packets public static final byte PING_PACKET = 0x01; diff --git a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java index 4a37d1c..f9a6195 100644 --- a/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java +++ b/src/de/steamwar/bungeecore/comms/packets/InventoryPacket.java @@ -68,7 +68,7 @@ public class InventoryPacket extends BungeePacket { JsonArray array = new JsonArray(); for (int i = 0; i < size; i++) { if(items.get(i) != null) - array.add(items.get(i).writeToString()); + array.add(items.get(i).writeToString(i)); } object.add("items", array); byteArrayDataOutput.writeUTF(object.toString()); diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index 1f3d166..31cb89e 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -25,7 +25,9 @@ import de.steamwar.bungeecore.comms.packets.InventoryPacket; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class SWInventory { @@ -46,33 +48,26 @@ public class SWInventory { next = false; } - public void addItem(SWItem item) { - itemMap.put(item.getPosition(), item); - } - - public void addItem(SWItem item, InvCallback callback) { - item.setCallback(callback); - itemMap.put(item.getPosition(), item); - } - - public void addItem(int position, SWItem item) { - itemMap.put(position, item); - } - public void addItem(int pos, SWItem item, InvCallback callback) { + addItem(pos, item, new ArrayList<>(), callback); + } + + public void addItem(int pos, SWItem item, List lore, InvCallback callback) { item.setCallback(callback); + item.setLore(lore); + itemMap.put(pos, item); + } + + public void addItem(int pos, SWItem item) { itemMap.put(pos, item); } public void addItem(int pos, SWItem item, String name, InvCallback callback) { + item.setName(name); item.setCallback(callback); itemMap.put(pos, item); } - public void removeItem(SWItem item) { - itemMap.remove(item.getPosition()); - } - public void removeItem(int position) { itemMap.remove(position); } diff --git a/src/de/steamwar/bungeecore/inventory/SWItem.java b/src/de/steamwar/bungeecore/inventory/SWItem.java index aadd2d9..41f6ea1 100644 --- a/src/de/steamwar/bungeecore/inventory/SWItem.java +++ b/src/de/steamwar/bungeecore/inventory/SWItem.java @@ -29,29 +29,26 @@ public class SWItem { private String material, title, skullOwner; private boolean enchanted, hideAttributes; - private int position; private List lore; private InvCallback callback; private int color; - public SWItem(String material, int position, String title) { + public SWItem(String material, String title) { this.material = material.toUpperCase(); lore = new ArrayList<>(); - this.position = position; this.title = title; color = 0; } - public SWItem(int position, String title, int color) { + public SWItem(String title, int color) { this.material = "DYE"; lore = new ArrayList<>(); - this.position = position; this.title = title; this.color = color; } public static SWItem getSkull(String skullOwner) { - SWItem item = new SWItem("SKULL", 1, skullOwner); + SWItem item = new SWItem("SKULL", skullOwner); item.setSkullOwner(skullOwner); return item; } @@ -100,10 +97,6 @@ public class SWItem { this.hideAttributes = hideAttributes; } - public int getPosition() { - return position; - } - public void setName(String name) { title = name; } @@ -112,7 +105,7 @@ public class SWItem { this.lore.add(lore); } - public JsonObject writeToString() { + public JsonObject writeToString(int position) { JsonObject object = new JsonObject(); object.addProperty("material", material); object.addProperty("position", position); @@ -152,8 +145,10 @@ public class SWItem { return false; if(!item.skullOwner.equals(skullOwner)) return false; - if(item.position != position) - return false; return true; } + + public void setLore(List lore) { + this.lore = lore; + } } diff --git a/src/de/steamwar/bungeecore/inventory/SWListInv.java b/src/de/steamwar/bungeecore/inventory/SWListInv.java index 639e953..bd43730 100644 --- a/src/de/steamwar/bungeecore/inventory/SWListInv.java +++ b/src/de/steamwar/bungeecore/inventory/SWListInv.java @@ -43,19 +43,19 @@ public class SWListInv extends SWInventory { setCallback(-999, (InvCallback.ClickType click) -> close()); if(elements.size() > 54){ if(page != 0) - addItem(45, new SWItem(45, "§eSeite zurück", 10), (InvCallback.ClickType click) -> { + addItem(45, new SWItem("§eSeite zurück", 10), (InvCallback.ClickType click) -> { page--; open(); }); else - addItem(45, new SWItem(45, "§7Seite zurück", 8), (InvCallback.ClickType click) -> {}); + addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {}); if(page < elements.size()/45) - addItem(53, new SWItem( 53, "§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> { + addItem(53, new SWItem("§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> { page++; open(); }); else - addItem(53, new SWItem(53, "§eSeite vor", 8), (InvCallback.ClickType click) -> {}); + addItem(53, new SWItem("§eSeite vor", 8), (InvCallback.ClickType click) -> {}); } int ipageLimit = elements.size() - page*45; @@ -119,7 +119,7 @@ public class SWListInv extends SWInventory { m = "CAULDRON_ITEM"; else m = s.getSchemItem(); - SWItem item = new SWItem(m, 0, "§e" + s.getSchemName()); + SWItem item = new SWItem(m, "§e" + s.getSchemName()); schemList.add(new SWListEntry<>(item, s)); } return schemList; diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 14172c9..90a26cf 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -108,4 +108,9 @@ IGNORE_MESSAGE=§7Du ignorierst nun §e{0}§8. #PollresultCommand POLLRESULT_NOPOLL=§cDerzeit läuft keine Umfrage. POLLRESULT_HEADER=§eEs haben {0} abgestimmt auf die Frage: §7{1} -POLLRESULT_LIST=§e{0}§8: §7{1} \ No newline at end of file +POLLRESULT_LIST=§e{0}§8: §7{1} + +#BauCommand +BAU_DELETE_GUI_NAME=§eWirklich Welt löschen? +BAU_DELETE_GUI_CANCEL=§cAbbrechen +BAU_DELETE_GUI_DELETE=§aLöschen \ No newline at end of file -- 2.39.2