Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Feb 20, 2024
1 parent d32c3e6 commit 05848c2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
12 changes: 6 additions & 6 deletions api/src/main/java/kr/toxicity/inventory/api/gui/GuiExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('/','.')))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object InventoryManager: FrameworkManager {
cursor,
current,
e
), holder.animation)
), holder)
}
}, PLUGIN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!");
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
yEquation = "10sin(t/10 * pi) - 10"
)
@InventoryText(
scale = 24,
multiplier = 0.5,
y = -10,
asset = "test.ttf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 05848c2

Please sign in to comment.