Skip to content
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

Syntax Simplification #7636

Draft
wants to merge 7 commits into
base: dev/feature
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Alphanumeric")
@Description({"Checks if the given string is alphanumeric."})
Expand Down Expand Up @@ -42,7 +43,13 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
public boolean check(Event e) {
return isNegated() ^ strings.check(e, StringUtils::isAlphanumeric);
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
strings = simplifyChild(strings, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return strings.toString(e, debug) + " is" + (isNegated() ? "n't" : "") + " alphanumeric";
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.World;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Do Respawn Anchors Work")
@Description("Checks whether or not respawn anchors work in a world.")
Expand Down Expand Up @@ -42,6 +43,12 @@ public boolean check(Event event) {
return worlds.check(event, World::isRespawnAnchorWorks, isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
worlds = simplifyChild(worlds, step, source);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "respawn anchors " + (isNegated() ? " do" : " don't") + " work in " + worlds.toString(event, debug);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/conditions/CondCanHold.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -72,7 +73,14 @@ public boolean check(Event e) {
t -> t.getItem().addTo(buf));
}, isNegated());
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
invis = simplifyChild(invis, step, source);
items = simplifyChild(items, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyType.CAN, e, debug, invis,
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondCanSee.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Can See")
@Description("Checks whether the given players can see the provided entities.")
Expand Down Expand Up @@ -61,6 +62,13 @@ public boolean check(Event event) {
), isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
viewers = simplifyChild(viewers, step, source);
entities = simplifyChild(entities, step, source);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return PropertyCondition.toString(this, PropertyType.CAN, event, debug, viewers,
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/ch/njol/skript/conditions/CondChance.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -49,7 +50,13 @@ public boolean check(final Event e) {
return false;
return Math.random() < (percent ? n.doubleValue() / 100 : n.doubleValue());
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
chance = simplifyChild(chance, step, source);
return this;
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "chance of " + chance.toString(e, debug) + (percent ? "%" : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Can See Messages")
@Description("Checks whether a player can see specific message types in chat.")
Expand Down Expand Up @@ -68,6 +69,12 @@ public boolean check(Event event) {
};
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
player = simplifyChild(player, step, source);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return switch (pattern) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import ch.njol.skript.util.Patterns;
import ch.njol.skript.util.Utils;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;
import org.skriptlang.skript.lang.util.Cyclical;

import java.util.function.Predicate;
Expand Down Expand Up @@ -404,6 +405,14 @@ private boolean compareLists(Event event) {
return shouldMatch;
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
first = simplifyChild(first, step, source);
second = simplifyChild(second, step, source);
third = simplifyChild(third, step, source);
return this;
}

@Override
public String toString(final @Nullable Event event, final boolean debug) {
String s;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondContains.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.inventory.ItemStack;
import org.skriptlang.skript.lang.converter.Converters;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

import java.util.Arrays;
import java.util.Objects;
Expand Down Expand Up @@ -156,6 +157,13 @@ public boolean check(Event event) {
};
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
containers = simplifyChild(containers, step, source);
items = simplifyChild(items, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return containers.toString(e, debug) + (isNegated() ? " doesn't contain " : " contains ") + items.toString(e, debug);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/ch/njol/skript/conditions/CondDamageCause.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -63,7 +64,13 @@ public boolean check(final Event e) {
other -> cause == other,
isNegated());
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
expected = simplifyChild(expected, step, source);
return this;
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "damage was" + (isNegated() ? " not" : "") + " caused by " + expected.toString(e, debug);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/conditions/CondDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ch.njol.skript.util.Date;
import ch.njol.skript.util.Timespan;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -58,7 +59,14 @@ public boolean check(final Event e) {
timespan -> now - date.getTime() >= timespan.getAs(Timespan.TimePeriod.MILLISECOND)
), isNegated());
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
date = simplifyChild(date, step, source);
delta = simplifyChild(delta, step, source);
return this;
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return date.toString(e, debug) + " was " + (isNegated() ? "less" : "more") + " than " + delta.toString(e, debug) + " ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Has Item Cooldown")
@Description("Check whether a cooldown is active on the specified material for a specific player.")
Expand Down Expand Up @@ -53,7 +54,14 @@ public boolean check(Event event) {
)
);
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
players = simplifyChild(players, step, source);
itemtypes = simplifyChild(itemtypes, step, source);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return PropertyCondition.toString(this, PropertyType.HAVE, event, debug, players,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Has Line of Sight")
@Description("Checks whether living entities have an unobstructed line of sight to other entities or locations.")
Expand Down Expand Up @@ -56,6 +57,13 @@ public boolean check(Event event) {
}, isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
viewers = simplifyChild(viewers, step, source);
targets = simplifyChild(targets, step, source);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return viewers.toString(event, debug) + " has" + (isNegated() ? " no" : "") + " line of sight to " + targets.toString(event,debug);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondHasMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.event.Event;
import org.bukkit.metadata.Metadatable;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Has Metadata")
@Description("Checks whether a metadata holder has a metadata tag.")
Expand Down Expand Up @@ -49,6 +50,13 @@ public boolean check(Event e) {
), isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
holders = simplifyChild(holders, step, source);
values = simplifyChild(values, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyType.HAVE, e, debug, holders,
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondHasPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Has Potion")
@Description("Checks whether the given living entities have specific potion effects.")
Expand Down Expand Up @@ -52,6 +53,13 @@ public boolean check(Event e) {
), isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
livingEntities = simplifyChild(livingEntities, step, source);
potionEffects = simplifyChild(potionEffects, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyType.HAVE, e, debug, livingEntities,
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/ch/njol/skript/conditions/CondHasScoreboardTag.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package ch.njol.skript.conditions;

import java.util.Arrays;
import java.util.List;

import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
import ch.njol.skript.doc.Description;
Expand All @@ -18,6 +10,13 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.simplification.Simplifiable;

import java.util.Arrays;
import java.util.List;

@Name("Has Scoreboard Tag")
@Description("Checks whether the given entities has the given <a href='expressions.html#ExprScoreboardTags'>scoreboard tags</a>.")
Expand Down Expand Up @@ -50,7 +49,14 @@ public boolean check(Event e) {
entity -> entity.getScoreboardTags().containsAll(tagsList),
isNegated());
}


@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
entities = simplifyChild(entities, step, source);
tags = simplifyChild(tags, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return PropertyCondition.toString(this, PropertyType.HAVE, e, debug, entities,
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIncendiary.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
import org.skriptlang.skript.lang.simplification.Simplifiable;

@Name("Is Incendiary")
@Description("Checks if an entity will create fire when it explodes. This condition is also usable in an explosion prime event.")
Expand Down Expand Up @@ -63,6 +64,12 @@ public boolean check(Event e) {
return entities.check(e, entity -> entity instanceof Explosive && ((Explosive) entity).isIncendiary(), isNegated());
}

@Override
public Condition simplify(Step step, @Nullable Simplifiable<?> source) {
entities = simplifyChild(entities, step, source);
return this;
}

@Override
public String toString(@Nullable Event e, boolean debug) {
if (isEvent)
Expand Down
Loading