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

Make Player Sprint + Camel Is Dashing #7365

Open
wants to merge 5 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsDashing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.Camel;
import org.bukkit.entity.LivingEntity;

@Name("Camel Is Dashing")
@Description("Checks whether a camel is sprinting.")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"if last spawned camel is not dashing:",
"\tmake last spawned camel start dashing"
})
@Since("INSERT VERSION")
public class CondIsDashing extends PropertyCondition<LivingEntity> {

static {
register(CondIsDashing.class, "dashing", "livingentities");
}

@Override
public boolean check(LivingEntity entity) {
if (entity instanceof Camel camel)
return camel.isDashing();
return false;
}

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

}
10 changes: 3 additions & 7 deletions src/main/java/ch/njol/skript/conditions/CondIsSprinting.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package ch.njol.skript.conditions;

import org.bukkit.entity.Player;

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.Player;

/**
* @author Peter Güttinger
*/
@Name("Is Sprinting")
@Description("Checks whether a player is sprinting.")
@Examples("player is not sprinting")
Expand All @@ -22,8 +18,8 @@ public class CondIsSprinting extends PropertyCondition<Player> {
}

@Override
public boolean check(final Player p) {
return p.isSprinting();
public boolean check(Player player) {
return player.isSprinting();
}

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

@Name("Camel Dashing")
@Description({
"Make a camel start or stop dashing.",
"Dashing is a temporary speed burst, a dash lasts for 0.35 seconds."
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
})
@Examples({
"make last spawned camel start dashing",
"make last spawned camel stop dashing",
})
@Since("INSERT VERSION")
public class EffDashing extends Effect {

static {
Skript.registerEffect(EffDashing.class,
"make %livingentities% (start dashing|dash)",
"make %livingentities% stop dashing");
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

private Expression<LivingEntity> entities;
private boolean dash;

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

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Camel camel)
camel.setDashing(dash);
}
}

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

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

@Name("Sprinting")
@Description("Make a player start or stop sprinting.")
@Examples({
"make player start sprinting",
"make last spawned camel sprint"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
})
@Since("INSERT VERSION")
public class EffSprinting extends Effect {

static {
Skript.registerEffect(EffSprinting.class,
"make %players% (start sprinting|sprint)",
"make %players% (stop sprinting|not sprint)");
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

private Expression<Player> players;
private boolean sprint;

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

@Override
protected void execute(Event event) {
for (Player player : players.getArray(event)) {
player.setSprinting(sprint);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + players.toString(event, debug) + (sprint ? " start" : " stop") + " sprinting";
}

}
9 changes: 9 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffDashing.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "camel dashing" when running minecraft "1.20":
# Test fails on 1.19.4, effect does work.
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
spawn a camel at test-location:
set {_entity} to entity
make {_entity} start dashing
assert {_entity} is dashing with "Camel should be dashing"
make {_entity} stop dashing
assert {_entity} is not dashing with "Camel should not be dashing"
clear entity within {_entity}
Loading