Skip to content

Commit

Permalink
Seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism committed Jan 2, 2025
1 parent c26b1e1 commit 1cf58cd
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 38 deletions.
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.")
@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";
}

}
22 changes: 7 additions & 15 deletions src/main/java/ch/njol/skript/conditions/CondIsSprinting.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package ch.njol.skript.conditions;

import org.bukkit.entity.Camel;
import org.bukkit.entity.LivingEntity;
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;

@Name("Is Sprinting")
@Description("Checks whether a player or camel is sprinting.")
@Description("Checks whether a player is sprinting.")
@Examples("player is not sprinting")
@Since("1.4.4, INSERT VERSION (camels)")
public class CondIsSprinting extends PropertyCondition<LivingEntity> {
@Since("1.4.4")
public class CondIsSprinting extends PropertyCondition<Player> {

static {
register(CondIsSprinting.class, "sprinting", "livingentities");
register(CondIsSprinting.class, "sprinting", "players");
}

@Override
public boolean check(LivingEntity entity) {
if (entity instanceof Player player) {
return player.isSprinting();
} else if (entity instanceof Camel camel) {
return camel.isDashing();
}
return false;
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."
})
@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");
}

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";
}

}
24 changes: 9 additions & 15 deletions src/main/java/ch/njol/skript/effects/EffSprinting.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
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.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Sprint")
@Description("Make a player or camel start or stop sprinting.")
@Name("Sprinting")
@Description("Make a player start or stop sprinting.")
@Examples({
"make player start sprinting",
"make last spawned camel sprint"
Expand All @@ -26,35 +24,31 @@ public class EffSprinting extends Effect {

static {
Skript.registerEffect(EffSprinting.class,
"make %livingentities% (start sprinting|sprint)",
"make %livingentities% (stop sprinting|not sprint)");
"make %players% (start sprinting|sprint)",
"make %players% (stop sprinting|not sprint)");
}

private Expression<LivingEntity> entities;
private Expression<Player> players;
private boolean sprint;

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

@Override
protected void execute(Event event) {
for (LivingEntity entity : entities.getArray(event)) {
if (entity instanceof Player player) {
player.setSprinting(sprint);
} else if (entity instanceof Camel camel) {
camel.setDashing(sprint);
}
for (Player player : players.getArray(event)) {
player.setSprinting(sprint);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + entities.toString(event, debug) + (sprint ? " start" : " stop") + " sprinting";
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.
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}
8 changes: 0 additions & 8 deletions src/test/skript/tests/syntaxes/effects/EffSprinting.sk

This file was deleted.

0 comments on commit 1cf58cd

Please sign in to comment.