diff --git a/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIDisplay.java b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIDisplay.java index 1545f99f3b..fb798d0668 100644 --- a/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIDisplay.java +++ b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIDisplay.java @@ -1,5 +1,6 @@ package me.hsgamer.hscore.bukkit.gui; +import me.hsgamer.hscore.bukkit.gui.object.BukkitInventorySize; import me.hsgamer.hscore.bukkit.gui.object.BukkitItem; import me.hsgamer.hscore.minecraft.gui.InventoryGUIDisplay; import me.hsgamer.hscore.minecraft.gui.object.InventorySize; @@ -34,7 +35,7 @@ public BukkitGUIDisplay(UUID uuid, BukkitGUIHolder holder) { @Override protected void initInventory() { this.inventory = holder.getInventoryFunction().apply(this); - this.inventorySize = BukkitGUIUtils.getInventorySize(inventory); + this.inventorySize = new BukkitInventorySize(inventory); } @Override diff --git a/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIUtils.java b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIUtils.java index 1f84cdf710..03e7ced6cf 100644 --- a/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIUtils.java +++ b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/BukkitGUIUtils.java @@ -2,7 +2,6 @@ import me.hsgamer.hscore.bukkit.gui.event.BukkitClickEvent; import me.hsgamer.hscore.bukkit.gui.event.BukkitDragEvent; -import me.hsgamer.hscore.minecraft.gui.object.InventorySize; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; @@ -117,36 +116,4 @@ public static Function getInventoryFunctionFromTitl : Bukkit.createInventory(display, type, title); }; } - - /** - * Get the inventory size from the inventory - * - * @param inventory the inventory - * - * @return the inventory size - */ - public static InventorySize getInventorySize(Inventory inventory) { - return new InventorySize() { - @Override - public int getSize() { - return inventory.getSize(); - } - - @Override - public int getSlotPerRow() { - switch (inventory.getType()) { - case CHEST: - case ENDER_CHEST: - case SHULKER_BOX: - return 9; - case DISPENSER: - case DROPPER: - case HOPPER: - return 3; - default: - return getSize(); - } - } - }; - } } diff --git a/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/object/BukkitInventorySize.java b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/object/BukkitInventorySize.java new file mode 100644 index 0000000000..efa086e6d0 --- /dev/null +++ b/bukkit/bukkit-gui/src/main/java/me/hsgamer/hscore/bukkit/gui/object/BukkitInventorySize.java @@ -0,0 +1,41 @@ +package me.hsgamer.hscore.bukkit.gui.object; + +import me.hsgamer.hscore.minecraft.gui.object.InventorySize; +import org.bukkit.inventory.Inventory; + +/** + * The {@link InventorySize} of {@link Inventory} + */ +public class BukkitInventorySize implements InventorySize { + private final Inventory inventory; + + /** + * Create a new instance + * + * @param inventory the inventory + */ + public BukkitInventorySize(Inventory inventory) { + this.inventory = inventory; + } + + @Override + public int getSize() { + return inventory.getSize(); + } + + @Override + public int getSlotPerRow() { + switch (inventory.getType()) { + case CHEST: + case ENDER_CHEST: + case SHULKER_BOX: + return 9; + case DISPENSER: + case DROPPER: + case HOPPER: + return 3; + default: + return getSize(); + } + } +} diff --git a/minecraft/minecraft-gui/src/main/java/me/hsgamer/hscore/minecraft/gui/object/InventorySize.java b/minecraft/minecraft-gui/src/main/java/me/hsgamer/hscore/minecraft/gui/object/InventorySize.java index f7840898de..46ab331cd2 100644 --- a/minecraft/minecraft-gui/src/main/java/me/hsgamer/hscore/minecraft/gui/object/InventorySize.java +++ b/minecraft/minecraft-gui/src/main/java/me/hsgamer/hscore/minecraft/gui/object/InventorySize.java @@ -20,7 +20,7 @@ public interface InventorySize { * @return the slot per row */ default int getSlotPerRow() { - return 9; + return getSize(); } /** diff --git a/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/MinestomGUIDisplay.java b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/MinestomGUIDisplay.java index c5a3c34da2..b28f6f0956 100644 --- a/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/MinestomGUIDisplay.java +++ b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/MinestomGUIDisplay.java @@ -4,6 +4,7 @@ import me.hsgamer.hscore.minecraft.gui.object.InventorySize; import me.hsgamer.hscore.minecraft.gui.object.Item; import me.hsgamer.hscore.minestom.gui.inventory.DelegatingInventory; +import me.hsgamer.hscore.minestom.gui.object.MinestomInventorySize; import me.hsgamer.hscore.minestom.gui.object.MinestomItem; import net.minestom.server.MinecraftServer; import net.minestom.server.entity.Player; @@ -34,17 +35,7 @@ public MinestomGUIDisplay(@NotNull UUID uuid, @NotNull MinestomGUIHolder holder) protected void initInventory() { this.inventory = new DelegatingInventory(holder.getInventoryType(), holder.getTitleFunction().apply(uuid), this); this.inventory.init(); - this.inventorySize = new InventorySize() { - @Override - public int getSize() { - return inventory.getSize(); - } - - @Override - public int getSlotPerRow() { - return inventory.getSlotPerRow(); - } - }; + this.inventorySize = new MinestomInventorySize(inventory); } @Override diff --git a/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/inventory/DelegatingInventory.java b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/inventory/DelegatingInventory.java index bceaa81fb0..3f6c3ac211 100644 --- a/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/inventory/DelegatingInventory.java +++ b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/inventory/DelegatingInventory.java @@ -78,23 +78,4 @@ public EventNode getEventNode() { public MinestomGUIDisplay getDisplay() { return display; } - - /** - * Get the slot per row of the inventory - * - * @return the slot per row - */ - public int getSlotPerRow() { - switch (getInventoryType()) { - case CHEST_1_ROW, CHEST_2_ROW, CHEST_3_ROW, CHEST_4_ROW, CHEST_5_ROW, CHEST_6_ROW, SHULKER_BOX -> { - return 9; - } - case WINDOW_3X3, CRAFTER_3X3 -> { - return 3; - } - default -> { - return getSize(); - } - } - } } diff --git a/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/object/MinestomInventorySize.java b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/object/MinestomInventorySize.java new file mode 100644 index 0000000000..32557af721 --- /dev/null +++ b/minestom/minestom-gui/src/main/java/me/hsgamer/hscore/minestom/gui/object/MinestomInventorySize.java @@ -0,0 +1,40 @@ +package me.hsgamer.hscore.minestom.gui.object; + +import me.hsgamer.hscore.minecraft.gui.object.InventorySize; +import net.minestom.server.inventory.Inventory; + +/** + * The {@link InventorySize} of {@link Inventory} + */ +public class MinestomInventorySize implements InventorySize { + private final Inventory inventory; + + /** + * Create a new instance + * + * @param inventory the inventory + */ + public MinestomInventorySize(Inventory inventory) { + this.inventory = inventory; + } + + @Override + public int getSize() { + return inventory.getSize(); + } + + @Override + public int getSlotPerRow() { + switch (inventory.getInventoryType()) { + case CHEST_1_ROW, CHEST_2_ROW, CHEST_3_ROW, CHEST_4_ROW, CHEST_5_ROW, CHEST_6_ROW, SHULKER_BOX -> { + return 9; + } + case WINDOW_3X3, CRAFTER_3X3 -> { + return 3; + } + default -> { + return getSize(); + } + } + } +}