Skip to content

Strider Support #7748

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

Merged
merged 7 commits into from
Jun 3, 2025
Merged
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
@@ -0,0 +1,34 @@
package ch.njol.skript.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Strider;

@Name("Strider Is Shivering")
@Description("Whether a strider is shivering.")
@Example("""
if last spawned strider is shivering:
make last spawned strider stop shivering
""")
@Since("INSERT VERSION")
public class CondStriderIsShivering extends PropertyCondition<LivingEntity> {

static {
register(CondStriderIsShivering.class, "shivering", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return entity instanceof Strider strider && strider.isShivering();
}

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

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

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
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.skript.lang.SyntaxStringBuilder;
import ch.njol.util.Kleenean;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Strider;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Strider Shivering")
@Description("Make a strider start/stop shivering.")
@Example("""
if last spawned strider is shivering:
make last spawned strider stop shivering
""")
@Since("INSERT VERSION")
public class EffStriderShivering extends Effect {

static {
Skript.registerEffect(EffStriderShivering.class,
"make %livingentities% start shivering",
"force %livingentities% to start shivering",
"make %livingentities% stop shivering",
"force %livingentities% to stop shivering");
}

private Expression<LivingEntity> entities;
private boolean start;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
entities = (Expression<LivingEntity>) exprs[0];
start = matchedPattern <= 1;
return true;
}

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Strider strider) {
strider.setShivering(start);
}
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
builder.append("make", entities);
if (start) {
builder.append("start");
} else {
builder.append("stop");
}
builder.append("shivering");
return builder.toString();
}
}
85 changes: 85 additions & 0 deletions src/main/java/ch/njol/skript/entity/StriderData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ch.njol.skript.entity;

import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Strider;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class StriderData extends EntityData<Strider> {

static {
register(StriderData.class, "strider", Strider.class, 1,
"warm strider", "strider", "shivering strider");
}

private Kleenean shivering = Kleenean.UNKNOWN;

public StriderData() {}

public StriderData(Kleenean shivering) {
this.shivering = shivering;
}

@Override
protected boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
shivering = Kleenean.get(matchedPattern - 1);
return true;
}

@Override
protected boolean init(@Nullable Class<? extends Strider> entityClass, @Nullable Strider entity) {
shivering = Kleenean.get(entity == null ? 0 : (entity.isShivering() ? 1 : -1));
return true;
}

@Override
public void set(Strider entity) {
entity.setShivering(shivering.isTrue());
}

@Override
protected boolean match(Strider entity) {
return shivering.isUnknown() || (this.shivering.isTrue() == entity.isShivering());
}

@Override
public boolean isSupertypeOf(EntityData<?> entityData) {
return entityData instanceof StriderData striderData
&& (this.shivering.isUnknown() || striderData.shivering.is(shivering).isTrue());
}

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

@Override
public EntityData<? super Strider> getSuperType() {
return new StriderData(shivering);
}

@Override
protected int hashCode_i() {
return Objects.hash(shivering);
}

@Override
protected boolean equals_i(EntityData<?> entityData) {
return entityData instanceof StriderData striderData
&& striderData.shivering == this.shivering;
}

@Override
public String toString(int flags) {
StringBuilder builder = new StringBuilder();
switch (shivering) {
case TRUE -> builder.append("shivering ");
case FALSE -> builder.append("warm ");
};
return builder.append("strider").toString();
}

}
6 changes: 6 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,12 @@ entities:
strider:
name: strider¦s
pattern: <age> strider(|1¦s)|(4¦)strider (kid(|1¦s)|child(|1¦ren))
warm strider:
name: warm strider¦s
pattern: <age> warm strider(|1¦s)|(4¦)warm strider (kid(|1¦s)|child(|1¦ren))
shivering strider:
name: shivering strider¦s, cold strider¦s
pattern: <age> (cold|shivering) strider(|1¦s)|(4¦)(cold|shivering) strider (kid(|1¦s)|child(|1¦ren))
#1.16.2 entity
piglin brute:
name: piglin brute¦s
Expand Down
31 changes: 31 additions & 0 deletions src/test/skript/tests/misc/striderdata.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local function easySpawn(type:entitytype) :: entity:
spawn {_type} at test location
delete spawned entity
return spawned entity

test "StriderData - Strider Entity Data":
set {_normal_strider} to easySpawn(strider)
assert {_normal_strider} is not shivering with "The strider spawned using 'strider' should not be shivering"

set {_warm_strider} to easySpawn(warm strider)
assert {_warm_strider} is not shivering with "The strider spawned using 'warm strider' should not be shivering"

set {_shivering_strider} to easySpawn(shivering strider)
assert {_shivering_strider} is shivering with "The strider spawned using 'shivering strider' wasn't shivering"


test "StriderData - Strider Entity Data Comparison":
set {_normal_strider} to easySpawn(strider)
assert {_normal_strider} is a strider
assert {_normal_strider} is a warm strider # Striders should always be warm for one tick after spawning
assert {_normal_strider} is not a cold strider

set {_warm_strider} to easySpawn(warm strider)
assert {_warm_strider} is a strider
assert {_warm_strider} is a warm strider # Striders should always be warm for one tick after spawning
assert {_warm_strider} is not a cold strider

set {_shivering_strider} to easySpawn(shivering strider)
assert {_shivering_strider} is a strider
assert {_shivering_strider} is not a warm strider
assert {_shivering_strider} is a cold strider
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test "strider shivering":
spawn a strider at test-location:
set {_entity} to entity
make {_entity} start shivering
assert {_entity} is shivering with "Strider should be shivering"
make {_entity} stop shivering
assert {_entity} is not shivering with "Strider should not be shivering"
clear entity within {_entity}