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

Axolotl Playing Dead #7361

Open
wants to merge 3 commits into
base: dev/feature
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java
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.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.LivingEntity;

@Name("Is Playing Dead")
@Description("Checks to see if an axolotl is playing dead.")
@Examples({
"if last spawned axolotl is playing dead:",
"\tmake last spawned axolotl stop playing dead"
})
@Since("INSERT VERSION")
public class CondIsPlayingDead extends PropertyCondition<LivingEntity> {

static {
PropertyCondition.register(CondIsPlayingDead.class, PropertyType.BE, "playing dead", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
return (entity instanceof Axolotl axolotl) ? axolotl.isPlayingDead() : false;
}

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

}
55 changes: 55 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffPlayingDead.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.Axolotl;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Play Dead")
@Description("Make an axolotl start or stop playing dead.")
@Examples("make last spawned axolotl play dead")
@Since("INSERT VERSION")
public class EffPlayingDead extends Effect {

static {
Skript.registerEffect(EffPlayingDead.class,
"make %livingentities% (start playing|play) dead",
"force %livingentities% to (start playing|play) dead",
"make %livingentities% (stop playing|not play) dead",
"force %livingentities% to (stop playing|not play) dead");
}

private Expression<LivingEntity> entities;
private boolean playDead;

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

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Axolotl axolotl)
axolotl.setPlayingDead(playDead);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + entities.toString(event, debug) + (playDead ? " start" : " stop") + " playing dead";
}

}
9 changes: 9 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffPlayingDead.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "playing dead":
# Combines: EffPlayingDead and CondPlayingDead
spawn an axolotl at test-location:
set {_entity} to entity
make {_entity} start playing dead
assert {_entity} is playing dead with "Axolotl should be playing dead"
make {_entity} stop playing dead
assert {_entity} is not playing dead with "Axolotl should not be playing dead"
clear entity within {_entity}
Loading