Skip to content

Commit

Permalink
walk_speed/fly_speed mechs: valid range check
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 16, 2023
1 parent 15632dc commit 17cef98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Expand Up @@ -2891,7 +2891,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Returns an interaction entity's last attack interaction, if any.
// The returned map contains:
// - 'player' (PlayerTag): the player who interacted
// - 'duration' (DurationTag): the amount of time since the interaction. Note that this value is calculated, and may become inaccurate if the interaction entity changes worlds or the server lags.
// - 'duration' (DurationTag): the amount of time since the interaction. Note that this is a delta time (same limitations as <@link event delta time>), and may become inaccurate if the interaction entity changes worlds.
// - 'raw_game_time' (ElementTag(Number)): the raw game time the interaction occurred at, used to calculate the time above.
// -->
registerSpawnedOnlyTag(MapTag.class, "last_attack", (attribute, object) -> {
Expand All @@ -2909,7 +2909,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Returns an interaction entity's last right click interaction, if any.
// The returned map contains:
// - 'player' (PlayerTag): the player who interacted
// - 'duration' (DurationTag): the amount of time since the interaction. Note that this value is calculated, and may become inaccurate if the interaction entity changes worlds or the server lags.
// - 'duration' (DurationTag): the amount of time since the interaction. Note that this is a delta time (same limitations as <@link event delta time>), and may become inaccurate if the interaction entity changes worlds.
// - 'raw_game_time' (ElementTag(Number)): the raw game time the interaction occurred at, used to calculate the time above.
// -->
registerSpawnedOnlyTag(MapTag.class, "last_interaction", (attribute, object) -> {
Expand Down
Expand Up @@ -579,15 +579,6 @@ public void setLevel(int level) {
}
}

public void setFlySpeed(float speed) {
if (isOnline()) {
getPlayerEntity().setFlySpeed(speed);
}
else {
getNBTEditor().setFlySpeed(speed);
}
}

public void setGameMode(GameMode mode) {
if (isOnline()) {
getPlayerEntity().setGameMode(mode);
Expand Down Expand Up @@ -3098,7 +3089,17 @@ public void adjust(Mechanism mechanism) {
// <PlayerTag.fly_speed>
// -->
if (mechanism.matches("fly_speed") && mechanism.requireFloat()) {
setFlySpeed(mechanism.getValue().asFloat());
float val = mechanism.getValue().asFloat();
if (val < -1 || val > 1) {
mechanism.echoError("Invalid speed specified. Must be between -1 and 1.");
return;
}
if (isOnline()) {
getPlayerEntity().setFlySpeed(val);
}
else {
getNBTEditor().setFlySpeed(val);
}
}

// <--[mechanism]
Expand Down Expand Up @@ -3247,11 +3248,16 @@ public void adjust(Mechanism mechanism) {
// <PlayerTag.walk_speed>
// -->
if (mechanism.matches("walk_speed") && mechanism.requireFloat()) {
float val = mechanism.getValue().asFloat();
if (val < -1 || val > 1) {
mechanism.echoError("Invalid speed specified. Must be between -1 and 1.");
return;
}
if (isOnline()) {
getPlayerEntity().setWalkSpeed(mechanism.getValue().asFloat());
getPlayerEntity().setWalkSpeed(val);
}
else {
getNBTEditor().setWalkSpeed(mechanism.getValue().asFloat());
getNBTEditor().setWalkSpeed(val);
}
}

Expand Down

0 comments on commit 17cef98

Please sign in to comment.