From 9eee6a6f23ddff7c0f153d43a591966462dd0b03 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Sep 2020 11:48:38 +0200 Subject: [PATCH 1/5] Moved Item --- src/de/steamwar/bungeecore/commands/BauCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 043ddfb..03be9c9 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -230,7 +230,7 @@ public class BauCommand { private static void delete(ProxiedPlayer p, String[] command){ SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?"); inventory.addItem(8, new SWItem(8, "§cAbbrechen", 1), click -> inventory.close()); - inventory.addItem(1, new SWItem(1, "§aLöchen", 10), click -> { + inventory.addItem(1, new SWItem(0, "§aLöschen", 10), click -> { if(bau15(p, command, 2)){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId()); From 96bc29b105074e0cea36832c2f039526ed40b1b8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Sep 2020 11:50:29 +0200 Subject: [PATCH 2/5] Moved Item --- src/de/steamwar/bungeecore/commands/BauCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 03be9c9..e5bc49a 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -230,7 +230,7 @@ public class BauCommand { private static void delete(ProxiedPlayer p, String[] command){ SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?"); inventory.addItem(8, new SWItem(8, "§cAbbrechen", 1), click -> inventory.close()); - inventory.addItem(1, new SWItem(0, "§aLöschen", 10), click -> { + inventory.addItem(0, new SWItem(0, "§aLöschen", 10), click -> { if(bau15(p, command, 2)){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId()); From 29d7cf081991a755e69883d412d43d86a61843f2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Sep 2020 12:44:31 +0200 Subject: [PATCH 3/5] Refactored Some Code --- src/de/steamwar/bungeecore/commands/BauCommand.java | 4 ++-- .../comms/handlers/InventoryCallbackHandler.java | 9 +++++++++ .../bungeecore/comms/packets/CloseInventoryPacket.java | 8 +++----- src/de/steamwar/bungeecore/inventory/SWInventory.java | 7 ++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index e5bc49a..b433f72 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -229,8 +229,8 @@ public class BauCommand { private static void delete(ProxiedPlayer p, String[] command){ SWInventory inventory = new SWInventory(p, 9, "§eWirklich Welt löschen?"); - inventory.addItem(8, new SWItem(8, "§cAbbrechen", 1), click -> inventory.close()); - inventory.addItem(0, new SWItem(0, "§aLöschen", 10), click -> { + inventory.addItem(new SWItem(8, "§cAbbrechen", 1), click -> inventory.close()); + inventory.addItem(new SWItem(0, "§aLöschen", 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/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java index e39b668..385a6bd 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java @@ -20,10 +20,13 @@ package de.steamwar.bungeecore.comms.handlers; import com.google.common.io.ByteArrayDataInput; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.comms.SpigotHandler; +import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket; import de.steamwar.bungeecore.inventory.InvCallback; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ProxyServer; import java.util.HashMap; import java.util.Map; @@ -36,6 +39,12 @@ public class InventoryCallbackHandler implements SpigotHandler { public void handle(ByteArrayDataInput byteArrayDataInput) { SteamwarUser owner = SteamwarUser.get(byteArrayDataInput.readInt()); CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF()); + if(!inventoryHashMap.containsKey(owner.getId())) { + BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§eAuf grund eines neuladens ist dein Inventar verloren gegangen."); + if(type == CallbackType.CLICK) { + new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid())); + } + } if(type == CallbackType.CLICK) { int pos = byteArrayDataInput.readInt(); InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(byteArrayDataInput.readUTF()); diff --git a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java b/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java index 974661a..0445c10 100644 --- a/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java +++ b/src/de/steamwar/bungeecore/comms/packets/CloseInventoryPacket.java @@ -22,24 +22,22 @@ package de.steamwar.bungeecore.comms.packets; import com.google.common.io.ByteArrayDataOutput; import de.steamwar.bungeecore.comms.BungeePacket; import de.steamwar.bungeecore.comms.PacketIdManager; -import de.steamwar.bungeecore.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class CloseInventoryPacket extends BungeePacket { - final ProxiedPlayer player; + final int player; @Override public int getId() { return PacketIdManager.INVENTORY_CLOSE_PACKET; } - public CloseInventoryPacket(ProxiedPlayer player) { + public CloseInventoryPacket(int player) { this.player = player; } @Override public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeInt(SteamwarUser.get(player).getId()); + byteArrayDataOutput.writeInt(player); } } diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index 6a308cf..1f3d166 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -50,6 +50,11 @@ public class SWInventory { 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); } @@ -116,7 +121,7 @@ public class SWInventory { } public void close() { - new CloseInventoryPacket(player).send(player); + new CloseInventoryPacket(SteamwarUser.get(player).getId()).send(player); } public void setClose(InvCallback close) { From 8f0549b6dd698ddc8c14137fcc72560496cd5a15 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Sep 2020 12:45:04 +0200 Subject: [PATCH 4/5] Forgot Return --- .../bungeecore/comms/handlers/InventoryCallbackHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java index 385a6bd..802695e 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java @@ -44,6 +44,7 @@ public class InventoryCallbackHandler implements SpigotHandler { if(type == CallbackType.CLICK) { new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid())); } + return; } if(type == CallbackType.CLICK) { int pos = byteArrayDataInput.readInt(); From 4f44d9b393fe14b6b6a6199b0ac08ca084203c26 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Sep 2020 20:44:13 +0200 Subject: [PATCH 5/5] Changed Message --- .../bungeecore/comms/handlers/InventoryCallbackHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java index 802695e..07d37b7 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/InventoryCallbackHandler.java @@ -40,7 +40,7 @@ public class InventoryCallbackHandler implements SpigotHandler { SteamwarUser owner = SteamwarUser.get(byteArrayDataInput.readInt()); CallbackType type = CallbackType.valueOf(byteArrayDataInput.readUTF()); if(!inventoryHashMap.containsKey(owner.getId())) { - BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§eAuf grund eines neuladens ist dein Inventar verloren gegangen."); + BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden."); if(type == CallbackType.CLICK) { new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid())); }