Skip to content

Commit

Permalink
1.0.0 Release
Browse files Browse the repository at this point in the history
- Fixed issue with SlotType being already registered (potentially by another addon?), leading to the plugin failing to load
- Fixed an issue where a null return on getSlot would incorrectly set the inventory click event as cancelled (this caused the stealable items feature to not act as intended)
- Made some changes to the way InventoryDragEvent is cancelled
- Small syntax changes to SecCreateGUI (non-breaking)
  • Loading branch information
APickledWalrus committed Jul 1, 2020
1 parent d25bb42 commit 06cd205
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
77 changes: 38 additions & 39 deletions src/main/java/io/github/apickledwalrus/skriptgui/SkriptTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GUI>() {

@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<GUI>() {
@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<SlotType> slotTypes = new EnumUtils<>(SlotType.class, "slot types");
Classes.registerClass(new ClassInfo<>(SlotType.class, "slottype")
if (Classes.getExactClassInfo(SlotType.class) == null) {
EnumUtils<SlotType> 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<SlotType>() {

@Override
public boolean canParse(ParseContext ctx) {
return true;
Expand All @@ -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)
));
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> slots; // Can be number or a string
private Expression<ItemType> item;

private int pattern;
Expand All @@ -63,7 +63,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean kleenean
if (matchedPattern < 2)
item = (Expression<ItemType>) exprs[matchedPattern];
if (matchedPattern == 1 || matchedPattern == 3)
slots = exprs[0].getConvertedExpression(Object.class);
slots = (Expression<Object>) exprs[0];

if (hasSection())
loadSection("gui effect", false, InventoryClickEvent.class);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/io/github/apickledwalrus/skriptgui/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,10 @@ public Consumer<InventoryClickEvent> 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<InventoryClickEvent> 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() {
Expand All @@ -468,6 +469,8 @@ public GUIListener getListener() {
@Override
public void onClick(InventoryClickEvent e, int slot) {
Consumer<InventoryClickEvent> 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);
Expand All @@ -486,16 +489,18 @@ 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.");
}
}
}

@Override
public void onDrag(InventoryDragEvent e, int slot) {
if (getSlot(slot) != null)
e.setCancelled(!getStealable());
Consumer<InventoryClickEvent> 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());
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 06cd205

Please sign in to comment.