From 6614ca6345e0e77b1601b7b6f82d1e62c50d414a Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 24 Nov 2024 01:47:19 +0100 Subject: [PATCH] :fire: Listen once section are now disabled --- .../elements/sections/once/SecListenOnce.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/info/itsthesky/disky/elements/sections/once/SecListenOnce.java b/src/main/java/info/itsthesky/disky/elements/sections/once/SecListenOnce.java index c145a8f..810e2a9 100644 --- a/src/main/java/info/itsthesky/disky/elements/sections/once/SecListenOnce.java +++ b/src/main/java/info/itsthesky/disky/elements/sections/once/SecListenOnce.java @@ -7,6 +7,7 @@ import ch.njol.skript.util.Timespan; import ch.njol.skript.variables.Variables; import ch.njol.util.Kleenean; +import ch.njol.util.coll.iterator.ConsumingIterator; import info.itsthesky.disky.DiSky; import info.itsthesky.disky.api.events.DiSkyEvent; import info.itsthesky.disky.api.events.SimpleDiSkyEvent; @@ -16,10 +17,10 @@ import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.structure.Structure; +import org.skriptlang.skript.lang.structure.StructureInfo; import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletionException; import java.util.concurrent.TimeoutException; @@ -50,7 +51,12 @@ public class SecListenOnce extends Section { @Override public boolean init(Expression[] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult, @NotNull SectionNode sectionNode, @NotNull List list) { - DiSky.debug("Starting to parse listen once section ..."); + if (true) { + Skript.warning("The 'listen once' section is currently unavailable in Skript 2.9.1 and +. It'll come back once a fix from SkriptLang has been made about parsing an event."); + return false; + } + + //DiSky.debug("Starting to parse listen once section ..."); if (!(expressions[0] instanceof VariableString)) { Skript.error("The event name in a listen once section must be a literal string!"); return false; @@ -58,8 +64,23 @@ public boolean init(Expression[] expressions, int i, @NotNull Kleenean kleene currentEvents = getParser().getCurrentEvents(); final String rawEvent = ((VariableString) expressions[0]).toString().replace("\"", ""); - final Object result = SkriptParser.parseStatic(rawEvent, Skript.getEvents().iterator(), ParseContext.EVENT, "Cannot parse the given event: " + rawEvent); - // DiSky.debug("debug 2: " + rawEvent + " / " + result + " / " + (result != null ? result.getClass().getSimpleName() : "null")); + final var events = new ConsumingIterator<>(Skript.getEvents().stream() + .filter(e -> DiSkyEvent.class.isAssignableFrom(e.elementClass)) + .iterator(), event -> { + final Structure.StructureData structureData = getParser().getData(Structure.StructureData.class); + + try { + final var field = structureData.getClass().getDeclaredField("structureInfo"); + final var structInfo = new StructureInfo(event.patterns, event.elementClass, event.originClassPath, event.entryValidator); + field.setAccessible(true); + field.set(structureData, structInfo); + } catch (Exception e) { + e.printStackTrace(); + } + }); + + final Object result = SkriptParser.parseStatic(rawEvent, events, + ParseContext.EVENT, "Cannot parse the given event: " + rawEvent); if (!(result instanceof SkriptEvent)) return false; final SkriptEvent skriptEvent = (SkriptEvent) result;