-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples for the experimental features. (#7444)
* Clean up existing example issues. * Fix some issues with queues. * Add an example structure. * Fix the old tests. * Add example scripts for the experimental features. * Fix toString. * Apply suggestions from code review * Change text type. * Fix spacing. * Change node names. * Fix issues from merge. * Update src/main/resources/scripts/-examples/experimental features/for loops.sk Co-authored-by: Patrick Miller <[email protected]> * Fix some more merge errors. --------- Co-authored-by: Patrick Miller <[email protected]>
- Loading branch information
1 parent
c9ae203
commit 1fab937
Showing
21 changed files
with
882 additions
and
276 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
74 changes: 74 additions & 0 deletions
74
src/main/java/ch/njol/skript/structures/StructExample.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,74 @@ | ||
package ch.njol.skript.structures; | ||
|
||
import ch.njol.skript.ScriptLoader; | ||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.config.SectionNode; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.function.FunctionEvent; | ||
import ch.njol.skript.lang.parser.ParserInstance; | ||
import ch.njol.skript.registrations.Feature; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.skriptlang.skript.lang.entry.EntryContainer; | ||
import org.skriptlang.skript.lang.structure.Structure; | ||
|
||
@NoDoc | ||
@Name("Example") | ||
@Description({ | ||
"Examples are structures that are parsed, but will never be run.", | ||
"They are used as miniature tutorials for demonstrating code snippets in the example files.", | ||
"Scripts containing an example are seen as 'examples' by the parser and may have special safety restrictions." | ||
}) | ||
@Examples({""" | ||
example: | ||
broadcast "hello world" | ||
# this is never run""" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class StructExample extends Structure { | ||
|
||
public static final Priority PRIORITY = new Priority(550); | ||
|
||
static { | ||
Skript.registerStructure(StructExample.class, | ||
"example" | ||
); | ||
} | ||
|
||
private SectionNode source; | ||
|
||
@Override | ||
public boolean init(Literal<?>[] literals, int matchedPattern, ParseResult parseResult, | ||
@Nullable EntryContainer entryContainer) { | ||
if (!this.getParser().hasExperiment(Feature.EXAMPLES)) | ||
return false; | ||
assert entryContainer != null; // cannot be null for non-simple structures | ||
this.source = entryContainer.getSource(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean load() { | ||
ParserInstance parser = this.getParser(); | ||
// This acts like a 'function' except without some of the features (e.g. returns) | ||
// The code is parsed and loaded, but then discarded since it will never be run | ||
// This allows things like parse problems and errors to be detected. | ||
parser.setCurrentEvent("example", FunctionEvent.class); | ||
ScriptLoader.loadItems(source); | ||
parser.deleteCurrentEvent(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public Priority getPriority() { | ||
return PRIORITY; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "example"; | ||
} | ||
|
||
} |
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
Oops, something went wrong.