From 8bbbc39d186e0ed468dcc85b9c79eb71318f54fc Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Sat, 22 Jul 2023 21:52:55 +0200 Subject: [PATCH] Add size debug command --- .../Minepacks/Bukkit/Backpack.java | 2 +- .../Bukkit/Command/DebugCommand.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java index 8e87a04..2a2939d 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java @@ -125,7 +125,7 @@ public class Backpack implements at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack return Bukkit.getServer().getPlayer(ownerId); } - private void checkResize() + public void checkResize() { Player owner = Bukkit.getServer().getPlayer(this.ownerId); if(owner != null) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/DebugCommand.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/DebugCommand.java index 9074d0a..8e3d41f 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/DebugCommand.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Command/DebugCommand.java @@ -25,6 +25,7 @@ import at.pcgamingfreaks.Message.MessageClickEvent; import at.pcgamingfreaks.Message.MessageColor; import at.pcgamingfreaks.Message.MessageFormat; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksCommand; +import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack; import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks; import at.pcgamingfreaks.Minepacks.Bukkit.Permissions; @@ -153,6 +154,47 @@ public class DebugCommand extends MinepacksCommand } commandSender.sendMessage("###############################"); } + else if (args.length == 2 && args[0].equals("size")) + { + Player player = Bukkit.getServer().getPlayer(args[1]); + if (player == null) + { + commandSender.sendMessage("Player " + args[1] + " is offline."); + return; + } + Backpack bp = Minepacks.getInstance().getBackpackCachedOnly(player); + int bpSize = -1, bpInvSize = -1, sizeShouldBe = Minepacks.getInstance().getBackpackPermSize(player); + String actualSize = "backpack not loaded", actualSizeInventory = "backpack not loaded"; + if (bp != null) + { + bpSize = bp.getSize(); + bpInvSize = bp.getInventory().getSize(); + actualSize = String.valueOf(bpSize); + actualSizeInventory = String.valueOf(bpInvSize); + } + commandSender.sendMessage("### Backpack size for " + player.getName() + " ###"); + commandSender.sendMessage("Size: " + actualSize); + commandSender.sendMessage("Inventory Size: " + actualSizeInventory); + commandSender.sendMessage("Should be: " + sizeShouldBe); + if (bpSize != sizeShouldBe) + { + commandSender.sendMessage("Size missmatch detected, attempt resize ..."); + ((at.pcgamingfreaks.Minepacks.Bukkit.Backpack) bp).checkResize(); + if (bp.getSize() != sizeShouldBe) + { + commandSender.sendMessage("Failed to resize backpack."); + } + else + { + commandSender.sendMessage("Resized backpack successfully."); + } + } + if (bp != null && bp.getSize() != bp.getInventory().getSize()) + { + commandSender.sendMessage("Inventory size does not match backpack size!"); + } + commandSender.sendMessage("###############################"); + } else debugSystem(commandSender); }