-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make event parsing more reliable (#5900)
* Make event parsing more reliable * Switch to parse marks * Requested Changes Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> * Switch to parse tags --------- Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Co-authored-by: Moderocky <admin@moderocky.com> Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
- Loading branch information
1 parent
90d211a
commit fccb68e
Showing
6 changed files
with
140 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
117 changes: 117 additions & 0 deletions
117
src/main/java/ch/njol/skript/structures/StructEvent.java
This file contains 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,117 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.structures; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.NoDoc; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.parser.ParserInstance; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.EventPriority; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.skriptlang.skript.lang.entry.EntryContainer; | ||
import org.skriptlang.skript.lang.structure.Structure; | ||
|
||
import java.util.Locale; | ||
|
||
@NoDoc | ||
public class StructEvent extends Structure { | ||
|
||
static { | ||
Skript.registerStructure(StructEvent.class, | ||
"[on] <.+> [with priority (:(lowest|low|normal|high|highest|monitor))]"); | ||
} | ||
|
||
private SkriptEvent event; | ||
|
||
@Override | ||
@SuppressWarnings("ConstantConditions") | ||
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult, EntryContainer entryContainer) { | ||
String expr = parseResult.regexes.get(0).group(); | ||
if (!parseResult.tags.isEmpty()) | ||
getParser().getData(EventData.class).priority = EventPriority.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH)); | ||
event = SkriptEvent.parse(expr, entryContainer.getSource(), null); | ||
return event != null; | ||
} | ||
|
||
@Override | ||
public boolean preLoad() { | ||
getParser().setCurrentStructure(event); | ||
return event.preLoad(); | ||
} | ||
|
||
@Override | ||
public boolean load() { | ||
getParser().setCurrentStructure(event); | ||
return event.load(); | ||
} | ||
|
||
@Override | ||
public boolean postLoad() { | ||
getParser().setCurrentStructure(event); | ||
return event.postLoad(); | ||
} | ||
|
||
@Override | ||
public void unload() { | ||
event.unload(); | ||
} | ||
|
||
@Override | ||
public void postUnload() { | ||
event.postUnload(); | ||
} | ||
|
||
@Override | ||
public Priority getPriority() { | ||
return event.getPriority(); | ||
} | ||
|
||
public SkriptEvent getSkriptEvent() { | ||
return event; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return this.event.toString(event, debug); | ||
} | ||
|
||
static { | ||
ParserInstance.registerData(EventData.class, EventData::new); | ||
} | ||
|
||
public static class EventData extends ParserInstance.Data { | ||
|
||
@Nullable | ||
private EventPriority priority; | ||
|
||
public EventData(ParserInstance parserInstance) { | ||
super(parserInstance); | ||
} | ||
|
||
@Nullable | ||
public EventPriority getPriority() { | ||
return priority; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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