From 05848c2ee9ff3ed54c701c44d60fcade5cceb226 Mon Sep 17 00:00:00 2001 From: toxicity Date: Tue, 20 Feb 2024 13:07:22 +0900 Subject: [PATCH] bug fix --- .../kr/toxicity/inventory/api/gui/GuiExecutor.java | 12 ++++++------ .../kr/toxicity/inventory/api/gui/GuiHolder.java | 4 +++- .../kr/toxicity/inventory/InventoryFrameworkImpl.kt | 8 +++++++- .../kr/toxicity/inventory/gui/GuiBuilderImpl.kt | 4 ++-- .../toxicity/inventory/manager/InventoryManager.kt | 2 +- .../toxicity/inventory/example/InventoryExample.java | 10 +++++----- .../kr/toxicity/inventory/example/TestAsset.java | 1 - .../kr/toxicity/inventory/example/TestAsset2.java | 3 +-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/api/src/main/java/kr/toxicity/inventory/api/gui/GuiExecutor.java b/api/src/main/java/kr/toxicity/inventory/api/gui/GuiExecutor.java index ba5b860..8ff3ad6 100644 --- a/api/src/main/java/kr/toxicity/inventory/api/gui/GuiExecutor.java +++ b/api/src/main/java/kr/toxicity/inventory/api/gui/GuiExecutor.java @@ -6,21 +6,21 @@ public interface GuiExecutor { GuiExecutor EMPTY = new GuiExecutor() { @Override - public void init(@NotNull Player player, @NotNull GuiAnimation animation) { + public void init(@NotNull Player player, @NotNull GuiHolder holder) { } @Override - public void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiAnimation animation) { + public void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiHolder holder) { } @Override - public void end(@NotNull Player player, @NotNull GuiAnimation animation) { + public void end(@NotNull Player player, @NotNull GuiHolder holder) { } }; - void init(@NotNull Player player, @NotNull GuiAnimation animation); - void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiAnimation animation); - void end(@NotNull Player player, @NotNull GuiAnimation animation); + void init(@NotNull Player player, @NotNull GuiHolder holder); + void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiHolder holder); + void end(@NotNull Player player, @NotNull GuiHolder holder); } diff --git a/api/src/main/java/kr/toxicity/inventory/api/gui/GuiHolder.java b/api/src/main/java/kr/toxicity/inventory/api/gui/GuiHolder.java index 6291b21..3196519 100644 --- a/api/src/main/java/kr/toxicity/inventory/api/gui/GuiHolder.java +++ b/api/src/main/java/kr/toxicity/inventory/api/gui/GuiHolder.java @@ -30,7 +30,9 @@ public Inventory getInventory() { } public void setInventory(@NotNull Component component) { - this.inventory = Bukkit.createInventory(this, this.inventory.getSize(), component); + var newInventory = Bukkit.createInventory(this, this.inventory.getSize(), component); + newInventory.setContents(this.inventory.getContents()); + this.inventory = newInventory; } public void setCancelled(boolean cancelled) { diff --git a/dist/src/main/kotlin/kr/toxicity/inventory/InventoryFrameworkImpl.kt b/dist/src/main/kotlin/kr/toxicity/inventory/InventoryFrameworkImpl.kt index 5f6aa30..886d8b0 100644 --- a/dist/src/main/kotlin/kr/toxicity/inventory/InventoryFrameworkImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/inventory/InventoryFrameworkImpl.kt @@ -49,8 +49,14 @@ class InventoryFrameworkImpl: InventoryFramework() { JarFile(getFile[plugin] as File).use { jar -> jar.entries().asIterator().forEach { entry -> if (!entry.isDirectory && entry.name.endsWith("class")) { + fun addClass(clazz: Class<*>) { + classes.add(clazz) + clazz.classes.forEach { subClass -> + addClass(subClass) + } + } runCatching { - classes.add(Class.forName(entry.name.substringBeforeLast(".").replace('/','.'))) + addClass(Class.forName(entry.name.substringBeforeLast(".").replace('/','.'))) } } } diff --git a/dist/src/main/kotlin/kr/toxicity/inventory/gui/GuiBuilderImpl.kt b/dist/src/main/kotlin/kr/toxicity/inventory/gui/GuiBuilderImpl.kt index 8150ac5..8718d02 100644 --- a/dist/src/main/kotlin/kr/toxicity/inventory/gui/GuiBuilderImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/inventory/gui/GuiBuilderImpl.kt @@ -83,7 +83,7 @@ class GuiBuilderImpl: GuiBuilder { if (oldHolder is GuiHolder) { holder.parent = oldHolder } - holder.executor.init(player, holder.animation) + holder.executor.init(player, holder) player.openInventory(holder.inventory) GuiTask { if (!holder.isCancelled && player.openInventory.topInventory.holder === holder) { @@ -100,7 +100,7 @@ class GuiBuilderImpl: GuiBuilder { false } else { player.closeInventory() - holder.executor.end(player, holder.animation) + holder.executor.end(player, holder) holder.parent?.let { parent -> PLUGIN.taskLater(1) { parent.gui.open(player) diff --git a/dist/src/main/kotlin/kr/toxicity/inventory/manager/InventoryManager.kt b/dist/src/main/kotlin/kr/toxicity/inventory/manager/InventoryManager.kt index 29ef93b..cc7a140 100644 --- a/dist/src/main/kotlin/kr/toxicity/inventory/manager/InventoryManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/inventory/manager/InventoryManager.kt @@ -43,7 +43,7 @@ object InventoryManager: FrameworkManager { cursor, current, e - ), holder.animation) + ), holder) } }, PLUGIN) } diff --git a/example/src/main/java/kr/toxicity/inventory/example/InventoryExample.java b/example/src/main/java/kr/toxicity/inventory/example/InventoryExample.java index cfd5056..6b7281d 100644 --- a/example/src/main/java/kr/toxicity/inventory/example/InventoryExample.java +++ b/example/src/main/java/kr/toxicity/inventory/example/InventoryExample.java @@ -3,8 +3,8 @@ import kr.toxicity.inventory.api.InventoryFramework; import kr.toxicity.inventory.api.annotation.InventoryPlugin; import kr.toxicity.inventory.api.gui.ClickData; -import kr.toxicity.inventory.api.gui.GuiAnimation; import kr.toxicity.inventory.api.gui.GuiExecutor; +import kr.toxicity.inventory.api.gui.GuiHolder; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -22,21 +22,21 @@ public void onEnable() { .append(new TestAsset2()) .setExecutor(new GuiExecutor() { @Override - public void init(@NotNull Player player, @NotNull GuiAnimation animation) { + public void init(@NotNull Player player, @NotNull GuiHolder holder) { player.sendMessage("Hello world!"); } @Override - public void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiAnimation animation) { + public void click(@NotNull Player player, @NotNull ClickData data, @NotNull GuiHolder holder) { player.sendMessage("The clicked slot is " + data.clickedSlot() + "!"); data.setCancelled(true); if (data.clickedSlot() == 0) { - animation.toggle(TestAsset.class); + holder.getAnimation().toggle(TestAsset.class); } } @Override - public void end(@NotNull Player player, @NotNull GuiAnimation animation) { + public void end(@NotNull Player player, @NotNull GuiHolder holder) { player.sendMessage("Ended!"); } }) diff --git a/example/src/main/java/kr/toxicity/inventory/example/TestAsset.java b/example/src/main/java/kr/toxicity/inventory/example/TestAsset.java index e3f603d..649a37d 100644 --- a/example/src/main/java/kr/toxicity/inventory/example/TestAsset.java +++ b/example/src/main/java/kr/toxicity/inventory/example/TestAsset.java @@ -20,7 +20,6 @@ yEquation = "10sin(t/10 * pi) - 10" ) @InventoryText( - scale = 24, multiplier = 0.5, y = -10, asset = "test.ttf" diff --git a/example/src/main/java/kr/toxicity/inventory/example/TestAsset2.java b/example/src/main/java/kr/toxicity/inventory/example/TestAsset2.java index 5b60a9a..41e799b 100644 --- a/example/src/main/java/kr/toxicity/inventory/example/TestAsset2.java +++ b/example/src/main/java/kr/toxicity/inventory/example/TestAsset2.java @@ -7,9 +7,8 @@ import org.jetbrains.annotations.NotNull; @InventoryText( - scale = 24, multiplier = 0.5, - y = -30, + y = -20, asset = "test.ttf" ) public class TestAsset2 implements GuiAsset, GuiText {