Skip to content

Commit

Permalink
Register placeholder pattern for custom syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Pikachu920 committed Jan 14, 2025
1 parent 9ec3526 commit c2d9a2b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public String toString(Event e, boolean debug) {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
SkriptParser.ParseResult parseResult) {
// prevent the user from using the placeholder pattern we register in order to satisfy the registration requirements
if (matchedPattern == 1) {
return false;
}

which = StructCustomCondition.lookup(SkriptUtil.getCurrentScript(), matchedPattern);

if (which == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class StructCustomCondition extends CustomSyntaxStructure<ConditionSyntax
static final Map<ConditionSyntaxInfo, Boolean> parseSectionLoaded = new HashMap<>();

static {
Skript.registerCondition(CustomCondition.class);
Skript.registerCondition(CustomCondition.class, "this is here because at least one pattern is required");
Optional<SyntaxInfo<? extends Condition>> info = SkriptMirror.getAddonInstance().syntaxRegistry().syntaxes(SyntaxRegistry.CONDITION).stream()
.filter(i -> i.type() == CustomCondition.class)
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public String toString(Event e, boolean debug) {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
SkriptParser.ParseResult parseResult) {
// prevent the user from using the placeholder pattern we register in order to satisfy the registration requirements
if (matchedPattern == 1) {
return false;
}

which = StructCustomEffect.lookup(SkriptUtil.getCurrentScript(), matchedPattern);

if (which == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class StructCustomEffect extends CustomSyntaxStructure<EffectSyntaxInfo>
static final Map<EffectSyntaxInfo, Boolean> parseSectionLoaded = new HashMap<>();

static {
Skript.registerEffect(CustomEffect.class);
Skript.registerEffect(CustomEffect.class, "this is here because at least one pattern is required");
Optional<SyntaxInfo<? extends Effect>> info = SkriptMirror.getAddonInstance().syntaxRegistry().syntaxes(SyntaxRegistry.EFFECT).stream()
.filter(i -> i.type() == CustomEffect.class)
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class CustomEvent extends SkriptEvent {

@Override
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) {
// prevent the user from using the placeholder pattern we register in order to satisfy the registration requirements
if (matchedPattern == 1) {
return false;
}

which = StructCustomEvent.lookup(SkriptUtil.getCurrentScript(), matchedPattern);

if (which == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean canCreateWith(String node) {
static final Map<EventSyntaxInfo, Boolean> parseSectionLoaded = new HashMap<>();

static {
Skript.registerEvent("custom event", CustomEvent.class, BukkitCustomEvent.class);
Skript.registerEvent("custom event", CustomEvent.class, BukkitCustomEvent.class, "this is here because at least one pattern is required");
Optional<BukkitSyntaxInfos.Event<?>> info = SkriptMirror.getAddonInstance().syntaxRegistry().syntaxes(BukkitRegistryKeys.EVENT).stream()
.filter(i -> i.type() == CustomEvent.class)
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
SkriptParser.ParseResult parseResult) {
// prevent the user from using the placeholder pattern we register in order to satisfy the registration requirements
if (matchedPattern == 1) {
return false;
}

which = StructCustomExpression.lookup(SkriptUtil.getCurrentScript(), matchedPattern);

if (which == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected Class<?> getValue(String value) {

static {
// noinspection unchecked
Skript.registerExpression(CustomExpression.class, Object.class, ExpressionType.PATTERN_MATCHES_EVERYTHING);
Skript.registerExpression(CustomExpression.class, Object.class, ExpressionType.PATTERN_MATCHES_EVERYTHING, "this is here because at least one pattern is required");
Optional<SyntaxInfo<?>> info = SkriptMirror.getAddonInstance().syntaxRegistry().elements().stream()
.filter(i -> Expression.class.isAssignableFrom(i.type()))
.filter(i -> i.type() == CustomExpression.class)
Expand Down

0 comments on commit c2d9a2b

Please sign in to comment.