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 7 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 dashing.")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"if last spawned camel is dashing:",
"\tkill last spawned camel"
})
@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
65 changes: 65 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,65 @@
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.",
"If the player is not moving when this effect is used, they will be put in sprint mode for a tick and then stops (Causes FOV change). "
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
+ "Using it a second time, without the player manually sprinting in between, causes the player to stay in sprint mode, with some quirks.",
" - Particles may not be produced under the player's feet.",
" - The player will not exit the sprinting state if they stop moving.",
" - Restrictions like low hunger will not prevent the player from sprinting",
" - The player pressing shift will stop them sprinting, and pressing sprint will re-assert normal sprinting behavior",
"Using this effect two or more consecutive times on a stationary player produces undefined behavior and should not be relied on."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is so unreliable, should it even be featured in Skript? seems like all this would do is create bug reports for stuff we cant fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already got the go ahead from Sovde. He was the one to help note down all the stuff that happens and even rewrote the description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was about the difference between dashing and sprinting though, or was this done in dms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok if we have the quirks documented but it's a fair point, some other opinions would be welcome

})
@Examples({
"make player start sprinting",
"force player to start sprinting"
})
@Since("INSERT VERSION")
public class EffSprinting extends Effect {

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

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

}
Loading