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

Adding entity expressions & conditions #7088

Merged
merged 33 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a0c36ca
Added CondIsTicking
Nuutrai Sep 16, 2024
fb6c7e8
I didn't make this, this just showed up ¯\_(ツ)_/¯
Nuutrai Sep 16, 2024
7ab23a3
Lots of additions
Nuutrai Sep 18, 2024
1815d07
Forgot this
Nuutrai Sep 18, 2024
892de1c
Removed licenses, fixed periods
Nuutrai Sep 18, 2024
b2c1b02
Suggested changed + a test
Nuutrai Sep 18, 2024
133aef7
Updated syntax for ExprMaxFireTicks
Nuutrai Sep 18, 2024
ccd4746
Apply suggestions
Nuutrai Sep 18, 2024
39e243c
Changes + fixes
Nuutrai Sep 18, 2024
afdf135
Apply suggestions
Nuutrai Sep 19, 2024
f48be0a
Updated test to add show custom name
Nuutrai Sep 19, 2024
ad7f264
Added CondIsTicking test
Nuutrai Sep 19, 2024
18d1908
Merge remote-tracking branch 'origin/feature/entity' into feature/entity
Nuutrai Sep 19, 2024
1f75322
Merge branch 'dev/feature' into feature/entity
Nuutrai Sep 19, 2024
75abb8a
Fixed basically redundant test
Nuutrai Sep 19, 2024
1d25680
Merge remote-tracking branch 'origin/feature/entity' into feature/entity
Nuutrai Sep 19, 2024
8124c44
Apply suggested changes
Nuutrai Sep 19, 2024
f31a06d
Renamed ExprFireDamageDelay
Nuutrai Sep 19, 2024
95cda33
Suggested changes
Nuutrai Sep 20, 2024
4297596
Apply suggestions
Nuutrai Sep 21, 2024
3407f76
Merge branch 'dev/feature' into feature/entity
Nuutrai Sep 21, 2024
951f73b
Merge branch 'dev/feature' into feature/entity
Nuutrai Sep 22, 2024
cd68607
Apply suggestions
Nuutrai Sep 24, 2024
6d26ae2
Merge branch 'dev/feature' into feature/entity
Nuutrai Sep 24, 2024
907c7a8
Apply suggestions
Nuutrai Sep 29, 2024
3ad2fe2
Merge branch 'dev/feature' into feature/entity
Nuutrai Oct 1, 2024
b0a3207
Merge branch 'dev/feature' into feature/entity
Nuutrai Oct 3, 2024
eb5f1c9
Merge branch 'dev/feature' into feature/entity
sovdeeth Oct 3, 2024
7ea8ec4
Merge branch 'dev/feature' into feature/entity
sovdeeth Oct 13, 2024
d4523e4
Merge branch 'dev/feature' into feature/entity
Nuutrai Oct 20, 2024
c8af23d
Merge branch 'dev/feature' into feature/entity
Nuutrai Nov 12, 2024
d0cfec6
Merge branch 'dev/feature' into feature/entity
Moderocky Nov 30, 2024
25eab59
Merge branch 'dev/feature' into feature/entity
sovdeeth Dec 15, 2024
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
45 changes: 45 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondFromMobSpawner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;

@Name("Is From A Mob Spawner")
@Description("Checks if an entity was spawned from a mob spawner.")
@Examples("send whether target is from a mob spawner")
@RequiredPlugins("PaperMC")
@Since("INSERT VERSION")
public class CondFromMobSpawner extends PropertyCondition<Entity> {
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

static {
if (Skript.methodExists(Entity.class, "fromMobSpawner"))
Skript.registerCondition(CondFromMobSpawner.class,
"%entities% (is|are) from a [mob] spawner",
"%entities% (isn't|aren't|is not|are not) from a [mob] spawner",
"%entities% (was|were) spawned (from|by) a [mob] spawner",
"%entities% (wasn't|weren't|was not|were not) spawned (from|by) a [mob] spawner");
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(matchedPattern == 1 || matchedPattern == 3);
setExpr((Expression<Entity>) exprs[0]);
return true;
}

@Override
public boolean check(Entity entity) {
return entity.fromMobSpawner();
}

@Override
protected String getPropertyName() {
return "from a mob spawner";
}

}
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;

@Name("Is Custom Name Visible")
@Description("Checks if an entity's custom name is visible.")
@Examples("send true if target's custom name is visible")
@Since("INSERT VERSION")
public class CondIsCustomNameVisible extends PropertyCondition<Entity> {

static {
Skript.registerCondition(CondIsCustomNameVisible.class,
"%entities%'[s] custom name[s] (is|are) visible",
"%entities%'[s] custom name[s] (isn't|is not|are not|aren't) visible",
"custom name of %entities% (is|are) visible",
"custom name of %entities% (isn't|is not|are not|aren't) visible");
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(matchedPattern == 1 || matchedPattern == 3);
setExpr((Expression<Entity>) exprs[0]);
return true;
}

@Override
public boolean check(Entity entity) {
return entity.isCustomNameVisible();
}

@Override
protected String getPropertyName() {
return "custom name";
}

}
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

31 changes: 31 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsTicking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import org.bukkit.entity.Entity;

@Name("Is Ticking")
@Description("Checks if an entity is ticking.")
@Examples("send true if target is ticking")
@RequiredPlugins("PaperMC")
@Since("INSERT VERSION")
public class CondIsTicking extends PropertyCondition<Entity> {

static {
if (Skript.methodExists(Entity.class, "isTicking"))
register(CondIsTicking.class, "ticking", "entities");
}

@Override
public boolean check(Entity entity) {
return entity.isTicking();
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
protected String getPropertyName() {
return "ticking";
}

}
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

53 changes: 53 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffCustomName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
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;

@Name("Toggle Custom Name Visibility")
@Description("Toggles the custom name visibility of an entity.")
@Examples({
"show the custom name of event-entity",
"hide target's display name"
})
@Since("INSERT VERSION")
public class EffCustomName extends Effect {
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

static {
Skript.registerEffect(EffCustomName.class,
"(:show|hide) [the] (custom|display)[ ]name of %entities%",
"(:show|hide) %entities%'[s] (custom|display)[ ]name");
}

private boolean showCustomName;
private Expression<Entity> entities;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
showCustomName = parseResult.hasTag("show");
entities = (Expression<Entity>) exprs[0];
return true;
}

@Override
protected void execute(Event event) {
for (Entity entity : entities.getArray(event)) {
entity.setCustomNameVisible(showCustomName);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return showCustomName ? "show" : "hide" + " the custom name of " + entities.toString(event, debug);
}

}
30 changes: 25 additions & 5 deletions src/main/java/ch/njol/skript/expressions/ExprFireTicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,52 @@
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Timespan.TimePeriod;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Entity Fire Burn Duration")
@Description("How much time an entity will be burning for.")
@Examples({"send \"You will stop burning in %fire time of player%\""})
@Since("2.7")
@Examples({
"send \"You will stop burning in %fire time of player%\"",
"send the max burn time of target"
})
@Since("2.7, INSERT VERSION (maximum)")
public class ExprFireTicks extends SimplePropertyExpression<Entity, Timespan> {
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

static {
register(ExprFireTicks.class, Timespan.class, "(burn[ing]|fire) (time|duration)", "entities");
register(ExprFireTicks.class, Timespan.class, "[:max[imum]] (burn[ing]|fire) (time|duration)", "entities");
}

private boolean max;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
max = (parseResult.hasTag("max"));
return true;
}

@Override
@Nullable
public Timespan convert(Entity entity) {
return Timespan.fromTicks(Math.max(entity.getFireTicks(), 0));
return new Timespan(TimePeriod.TICK, (max ? entity.getMaxFireTicks() : Math.max(entity.getFireTicks(), 0)));
}

@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
return (mode != ChangeMode.REMOVE_ALL) ? CollectionUtils.array(Timespan.class) : null;
if (max)
return null;
return switch (mode) {
case ADD, SET, RESET, DELETE, REMOVE -> CollectionUtils.array(Timespan.class);
default -> null;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test "custom name visibility":
spawn an adult zombie at (spawn of world "world"):
set {_z} to entity

assert {_z}'s custom name isn't visible with "A zombie shouldn't be spawned with a visible display name"

set {_z}'s display name to "aaa"

assert {_z}'s custom name is visible with "Setting an entity's display name sets the visibility to true"

hide {_z}'s custom name

assert {_z}'s custom name isn't visible with "New effect should hide the custom name"

show {_z}'s custom name

assert {_z}'s custom name is visible with "New effect should show the custom name"

delete entity within {_z}
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

14 changes: 14 additions & 0 deletions src/test/skript/tests/syntaxes/conditions/CondIsTicking.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test "is entity ticking":

spawn an adult zombie at location(512, 1, 512):
add entity to {_z::*}

spawn an adult zombie at (spawn of world "world"):
add entity to {_z::*}

assert {_z::1} isn't ticking with "Chunk isn't loaded, therefore should not tick"

assert {_z::2} is ticking with "Chunk is loaded, therefore should tick"

delete entities within {_z::*}
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

Loading