diff --git a/src/main/java/io/github/apickledwalrus/skriptgui/SkriptTypes.java b/src/main/java/io/github/apickledwalrus/skriptgui/SkriptTypes.java index 8f14801..4e888e5 100644 --- a/src/main/java/io/github/apickledwalrus/skriptgui/SkriptTypes.java +++ b/src/main/java/io/github/apickledwalrus/skriptgui/SkriptTypes.java @@ -17,48 +17,46 @@ public class SkriptTypes { public static void register() { Classes.registerClass(new ClassInfo<>(GUI.class, "guiinventory") - .user("gui inventor(y|ies)?") - .name("GUI") - .description("Represents a skript-gui GUI") - .examples("See the GUI creation section.") - .since("1.0") - .parser(new Parser() { - - @Override - public boolean canParse(ParseContext ctx) { - return false; - } - - @Override - public String toString(GUI gui, int flags) { - return gui.getInventory().getType().getDefaultTitle().toLowerCase() - + " gui named " + gui.getName() - + " with " + gui.getInventory().getSize() / 9 + " rows" - + " and shape " + gui.getRawShape(); - } - - @Override - public String toVariableNameString(GUI gui) { - return toString(gui, 0); - } - - @Override - public String getVariableNamePattern() { - return ".+"; - } - - }) + .user("gui inventor(y|ies)?") + .name("GUI") + .description("Represents a skript-gui GUI") + .examples("See the GUI creation section.") + .since("1.0") + .parser(new Parser() { + @Override + public boolean canParse(ParseContext ctx) { + return false; + } + + @Override + public String toString(GUI gui, int flags) { + return gui.getInventory().getType().getDefaultTitle().toLowerCase() + + " gui named " + gui.getName() + + " with " + gui.getInventory().getSize() / 9 + " rows" + + " and shape " + gui.getRawShape(); + } + + @Override + public String toVariableNameString(GUI gui) { + return toString(gui, 0); + } + + @Override + public String getVariableNamePattern() { + return ".+"; + } + }) ); - EnumUtils slotTypes = new EnumUtils<>(SlotType.class, "slot types"); - Classes.registerClass(new ClassInfo<>(SlotType.class, "slottype") + if (Classes.getExactClassInfo(SlotType.class) == null) { + EnumUtils slotTypes = new EnumUtils<>(SlotType.class, "slot types"); + Classes.registerClass(new ClassInfo<>(SlotType.class, "slottype") .user("slot types?") .name("Slot Types") .description("Represents the slot type in an Inventory Click Event.") .examples(slotTypes.getAllNames()) .since("1.0.0") .parser(new Parser() { - @Override public boolean canParse(ParseContext ctx) { return true; @@ -69,24 +67,25 @@ public boolean canParse(ParseContext ctx) { public SlotType parse(String expr, ParseContext context) { return slotTypes.parse(expr); } - + @Override public String toString(SlotType type, int flags) { return slotTypes.toString(type, flags); } - + @Override public String toVariableNameString(SlotType type) { return "slottype:" + type.name(); } - + @Override public String getVariableNamePattern() { return "\\S+"; } - }) - .serializer(new EnumSerializer<>(SlotType.class))); + .serializer(new EnumSerializer<>(SlotType.class) + )); + } } diff --git a/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecCreateGUI.java b/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecCreateGUI.java index 9ae13b3..397bfe8 100644 --- a/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecCreateGUI.java +++ b/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecCreateGUI.java @@ -29,7 +29,7 @@ public class SecCreateGUI extends EffectSection { static { Skript.registerCondition(SecCreateGUI.class, - "create [a] [new] gui [[with id] %-string%] with %inventory% [(1¦and (moveable|stealable) items)] [and shape %-strings%]", + "create [a] [new] gui [[with id] %-string%] with %inventory% [(1¦(and|with) (moveable|stealable) items)] [(and|with) shape %-strings%]", "(change|edit) [gui] %guiinventory%" ); } diff --git a/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecMakeGUI.java b/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecMakeGUI.java index e870375..b5542c7 100644 --- a/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecMakeGUI.java +++ b/src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecMakeGUI.java @@ -43,7 +43,7 @@ public class SecMakeGUI extends EffectSection { public static SecMakeGUI lastInstance = null; - private Expression slots; // Can be number or a string + private Expression slots; // Can be number or a string private Expression item; private int pattern; @@ -63,7 +63,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean kleenean if (matchedPattern < 2) item = (Expression) exprs[matchedPattern]; if (matchedPattern == 1 || matchedPattern == 3) - slots = exprs[0].getConvertedExpression(Object.class); + slots = (Expression) exprs[0]; if (hasSection()) loadSection("gui effect", false, InventoryClickEvent.class); diff --git a/src/main/java/io/github/apickledwalrus/skriptgui/gui/GUI.java b/src/main/java/io/github/apickledwalrus/skriptgui/gui/GUI.java index c714f8d..5ca48c3 100644 --- a/src/main/java/io/github/apickledwalrus/skriptgui/gui/GUI.java +++ b/src/main/java/io/github/apickledwalrus/skriptgui/gui/GUI.java @@ -457,9 +457,10 @@ public Consumer getSlot(int slot) { * @return The slot's {@link Consumer}, or {@link GUI#NULL_CONSUMER} if it does not have one. * @see GUI#getSlot(int) */ - @Nullable public Consumer getSlot(char ch) { - return ch > 0 ? slots.get(ch) : NULL_CONSUMER; + if (ch > 0 && slots.containsKey(ch)) + return slots.get(ch); + return NULL_CONSUMER; } public GUIListener getListener() { @@ -468,6 +469,8 @@ public GUIListener getListener() { @Override public void onClick(InventoryClickEvent e, int slot) { Consumer run = getSlot(slot); + // Cancel the event if this GUI slot runs something + // If it doesn't, check whether items are stealable in this GUI e.setCancelled(run != NULL_CONSUMER || !getStealable()); if (run != null && slot == e.getSlot() && guiInventory.equals(e.getClickedInventory())) { run.accept(e); @@ -486,7 +489,7 @@ public void onClose(InventoryCloseEvent e) { SkriptGUI.getGUIManager().setGUIEvent(e, GUI.this); try { getOnClose().accept(e); - } catch (Exception ex){ + } catch (Exception ex) { Skript.exception(ex, "An error occurred while closing a GUI. If you are unsure why this occured, please report the error on the skript-gui GitHub."); } } @@ -494,8 +497,10 @@ public void onClose(InventoryCloseEvent e) { @Override public void onDrag(InventoryDragEvent e, int slot) { - if (getSlot(slot) != null) - e.setCancelled(!getStealable()); + Consumer run = getSlot(slot); + // Cancel the event if this GUI slot runs something + // If it doesn't, check whether items are stealable in this GUI + e.setCancelled(run != NULL_CONSUMER || !getStealable()); } }; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dfef657..3110598 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: skript-gui main: io.github.apickledwalrus.skriptgui.SkriptGUI -version: 1.0.0-BETA-2 +version: 1.0.0 authors: [APickledWalrus, Tuke_Nuke] description: Enables the easy creation of advanced and organized GUIs with Skript. website: https://github.com/APickledWalrus/skript-gui