Config option to toggle disabling flight / speed on world change (#2546)

Closes #2141.

This PR adds the option to toggle whether or not EssentialsX should handle disabling player flight / speed when they switch to a new world, in case server administrators are handling that via a third party plugin.
This commit is contained in:
mink 2020-04-23 11:13:19 -04:00 committed by GitHub
parent 40fb496052
commit 2bd6ebd2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 19 deletions

View File

@ -581,27 +581,31 @@ public class EssentialsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerChangedWorldFlyReset(final PlayerChangedWorldEvent event) {
final User user = ess.getUser(event.getPlayer());
if (user.getBase().getGameMode() != GameMode.CREATIVE
// COMPAT: String compare for 1.7.10
&& !user.getBase().getGameMode().name().equals("SPECTATOR")
&& !user.isAuthorized("essentials.fly")) {
user.getBase().setFallDistance(0f);
user.getBase().setAllowFlight(false);
}
if (!user.isAuthorized("essentials.speed")) {
user.getBase().setFlySpeed(0.1f);
user.getBase().setWalkSpeed(0.2f);
} else {
if (user.getBase().getFlySpeed() > ess.getSettings().getMaxFlySpeed() && !user.isAuthorized("essentials.speed.bypass")) {
user.getBase().setFlySpeed((float) ess.getSettings().getMaxFlySpeed());
} else {
user.getBase().setFlySpeed(user.getBase().getFlySpeed() * 0.99999f);
}
if (user.getBase().getWalkSpeed() > ess.getSettings().getMaxWalkSpeed() && !user.isAuthorized("essentials.speed.bypass")) {
user.getBase().setWalkSpeed((float) ess.getSettings().getMaxWalkSpeed());
if (ess.getSettings().isWorldChangeFlyResetEnabled()) {
if (user.getBase().getGameMode() != GameMode.CREATIVE
// COMPAT: String compare for 1.7.10
&& !user.getBase().getGameMode().name().equals("SPECTATOR")
&& !user.isAuthorized("essentials.fly")) {
user.getBase().setFallDistance(0f);
user.getBase().setAllowFlight(false);
}
}
if (ess.getSettings().isWorldChangeSpeedResetEnabled()) {
if (!user.isAuthorized("essentials.speed")) {
user.getBase().setFlySpeed(0.1f);
user.getBase().setWalkSpeed(0.2f);
} else {
user.getBase().setWalkSpeed(user.getBase().getWalkSpeed() * 0.99999f);
if (user.getBase().getFlySpeed() > ess.getSettings().getMaxFlySpeed() && !user.isAuthorized("essentials.speed.bypass")) {
user.getBase().setFlySpeed((float) ess.getSettings().getMaxFlySpeed());
} else {
user.getBase().setFlySpeed(user.getBase().getFlySpeed() * 0.99999f);
}
if (user.getBase().getWalkSpeed() > ess.getSettings().getMaxWalkSpeed() && !user.isAuthorized("essentials.speed.bypass")) {
user.getBase().setWalkSpeed((float) ess.getSettings().getMaxWalkSpeed());
}
}
}
}

View File

@ -294,6 +294,10 @@ public interface ISettings extends IConf {
boolean isCommandCooldownsEnabled();
boolean isWorldChangeFlyResetEnabled();
boolean isWorldChangeSpeedResetEnabled();
long getCommandCooldownMs(String label);
Entry<Pattern, Long> getCommandCooldownEntry(String label);

View File

@ -1498,6 +1498,16 @@ public class Settings implements net.ess3.api.ISettings {
return config.getBoolean("allow-direct-hat", true);
}
@Override
public boolean isWorldChangeFlyResetEnabled() {
return config.getBoolean("world-change-fly-reset", true);
}
@Override
public boolean isWorldChangeSpeedResetEnabled() {
return config.getBoolean("world-change-speed-reset", true);
}
private List<String> defaultEnabledConfirmCommands;
private List<String> _getDefaultEnabledConfirmCommands() {

View File

@ -196,6 +196,18 @@ socialspy-commands:
# If so, they will be differentiated from those sent by normal players.
socialspy-listen-muted-players: true
# The following settings listen for when a player changes worlds.
# If you use another plugin to control speed and flight, you should change these to false.
# When a player changes world, should EssentialsX reset their flight?
# This will disable flight if the player does not have essentials.fly.
world-change-fly-reset: true
# When a player changes world, should we reset their speed according to their permissions?
# This resets the player's speed to the default if they don't have essentials.speed.
# If the player doesn't have essentials.speed.bypass, this resets their speed to the maximum specified above.
world-change-speed-reset: true
# Mute Commands
# These commands will be disabled when a player is muted.
# Use '*' to disable every command.