-
Notifications
You must be signed in to change notification settings - Fork 16
Fixed some bugs and added QoL features #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
APickledWalrus
merged 10 commits into
APickledWalrus:dev/1.4.0
from
MissingReports:master
Jan 17, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04e0807
Added `slot changed` section
MissingReports e54f10b
Fixed some edge cases to change the GUI without calling the on change…
MissingReports 7550096
Update src/main/java/io/github/apickledwalrus/skriptgui/elements/sect…
MissingReports 5c14eef
Update src/main/java/io/github/apickledwalrus/skriptgui/gui/events/GU…
MissingReports b1fb0d8
Changed the code abit
MissingReports eddc9ae
Update src/main/java/io/github/apickledwalrus/skriptgui/gui/events/GU…
MissingReports 1e7373e
Patched a bug to trigger on change without changing the slot
MissingReports 44b4f5c
Merge remote-tracking branch 'origin/master'
MissingReports 3290e0f
Merge branch 'dev/1.4.0' into master
APickledWalrus 3ac8c23
Fix spacing
APickledWalrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecSlotChange.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.github.apickledwalrus.skriptgui.elements.sections; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.config.SectionNode; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.Section; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.Trigger; | ||
import ch.njol.skript.lang.TriggerItem; | ||
import ch.njol.skript.variables.Variables; | ||
import ch.njol.util.Kleenean; | ||
import io.github.apickledwalrus.skriptgui.SkriptGUI; | ||
import io.github.apickledwalrus.skriptgui.gui.GUI; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import java.util.List; | ||
|
||
@Name("GUI Slot Change") | ||
@Description("Sections that will run when a gui slot is changed. This section is optional.") | ||
@Examples({ | ||
"create a gui with virtual chest inventory with 3 rows named \"My GUI\"", | ||
"\trun when slot 12 changes:", | ||
"\t\tsend \"You changed slot 12!\" to player", | ||
"\trun on slot 14 changed:", | ||
"\t\tcancel event" | ||
}) | ||
@Since("1.3") | ||
public class SecSlotChange extends Section { | ||
|
||
static { | ||
Skript.registerSection(SecSlotChange.class, | ||
"run when [gui] slot[s] %integers% change[s]", | ||
"run when [gui] slot[s] %integers% [(are|is)] [being] changed", | ||
"run on change of [gui] slot[s] %integers%" | ||
); | ||
} | ||
|
||
@SuppressWarnings("NotNullFieldNotInitialized") | ||
private Trigger trigger; | ||
private Expression<Integer> guiSlots; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems) { | ||
if (!getParser().isCurrentSection(SecCreateGUI.class)) { | ||
Skript.error("You can't listen for changes of a slot outside of a GUI creation or editing section."); | ||
return false; | ||
} | ||
|
||
trigger = loadCode(sectionNode, "inventory click", InventoryClickEvent.class); | ||
|
||
guiSlots = (Expression<Integer>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public TriggerItem walk(Event e) { | ||
GUI gui = SkriptGUI.getGUIManager().getGUI(e); | ||
if (gui == null) | ||
return walk(e, false); | ||
|
||
Integer[] slots = guiSlots.getAll(e); | ||
|
||
for (Integer slot : slots) { | ||
if (slot >= 0 && slot + 1 <= gui.getInventory().getSize()) { | ||
Object variables = Variables.copyLocalVariables(e); | ||
GUI.SlotData slotData = gui.getSlotData(gui.convert(slot)); | ||
if (variables != null && slotData != null) { | ||
slotData.setRunOnChange(event -> { | ||
Variables.setLocalVariables(event, variables); | ||
trigger.execute(event); | ||
}); | ||
} else if (slotData != null) { | ||
slotData.setRunOnChange(trigger::execute); | ||
} | ||
} | ||
} | ||
|
||
// We don't want to execute this section | ||
return walk(e, false); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return "run on change of slot " + guiSlots.toString(e, debug); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.