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 18 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
47 changes: 47 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,47 @@
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 From A Mob Spawner")
@Description("Check if an entity was spawned from a mob spawner.")
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"send whether target is from a mob spawner"
})
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@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%('s | is| are) from [a] [mob] spawner",
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
"%entities% (isn't|aren't|is not|are not) from [a] [mob] spawner");
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(matchedPattern == 1);
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,49 @@
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("Check if an entity's custom name is visible.")
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"send true if target's custom name is visible"
})
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@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();

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

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

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

33 changes: 33 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,33 @@
package ch.njol.skript.conditions;

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 org.bukkit.entity.Entity;

@Name("Is Ticking")
@Description("Check if an entity is ticking.")
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"send true if target is ticking"
})
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
public class CondIsTicking extends PropertyCondition<Entity> {

static {
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

42 changes: 42 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,42 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
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;

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<?>[] expr, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved
showCustomName = parseResult.hasTag("show");
entities = (Expression<Entity>) expr[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);
}

}
42 changes: 42 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprFireDamageDelay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ch.njol.skript.expressions;

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.expressions.base.SimplePropertyExpression;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Timespan.TimePeriod;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.Nullable;

@Name("Fire Damage Delay")
@Description("Returns the amount of time before an entity begins getting damaged by fire.")
@Examples({
"send target's fire damage delay"
})
@Since("INSERT VERSION")
public class ExprFireDamageDelay extends SimplePropertyExpression<Entity, Timespan> {
Nuutrai marked this conversation as resolved.
Show resolved Hide resolved

static {
register(ExprFireDamageDelay.class, Timespan.class, "fire damage delay", "entities");
}

@Override
@Nullable
public Timespan convert(Entity entity) {
return new Timespan(TimePeriod.TICK, entity.getMaxFireTicks());
}

@Override
public Class<? extends Timespan> getReturnType() {
return Timespan.class;
}

@Override
protected String getPropertyName() {
return "fire damage delay";
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
13 changes: 13 additions & 0 deletions src/test/skript/tests/syntaxes/conditions/CondIsTicking.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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