#1036 Add restoration options for Limbo allowFlight / fly speed / walk speed
- Introduce options to define how allow flight, fly & walk speed should be restored from LimboPlayer - Create consistency tests for line length in SectionComments methods and to ensure that all SettingsHolder classes are part of the returned ConfigurationData
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Possible types to restore the "allow flight" property
|
||||
* from LimboPlayer to Bukkit Player.
|
||||
*/
|
||||
public enum AllowFlightRestoreType {
|
||||
|
||||
/** Set value from LimboPlayer to Player. */
|
||||
RESTORE(LimboPlayer::isCanFly),
|
||||
|
||||
/** Always set flight enabled to true. */
|
||||
ENABLE(l -> true),
|
||||
|
||||
/** Always set flight enabled to false. */
|
||||
DISABLE(l -> false);
|
||||
|
||||
private final Function<LimboPlayer, Boolean> valueGetter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param valueGetter function with which the value to set on the player can be retrieved
|
||||
*/
|
||||
AllowFlightRestoreType(Function<LimboPlayer, Boolean> valueGetter) {
|
||||
this.valueGetter = valueGetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the "allow flight" property from the LimboPlayer to the Player.
|
||||
* This method behaves differently for each restoration type.
|
||||
*
|
||||
* @param player the player to modify
|
||||
* @param limbo the limbo player to read from
|
||||
*/
|
||||
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
||||
player.setAllowFlight(valueGetter.apply(limbo));
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,10 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_ALLOW_FLIGHT;
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_FLY_SPEED;
|
||||
import static fr.xephi.authme.settings.properties.LimboSettings.RESTORE_WALK_SPEED;
|
||||
|
||||
/**
|
||||
* Service for managing players that are in "limbo," a temporary state players are
|
||||
* put in which have joined but not yet logged in yet.
|
||||
@@ -53,18 +57,9 @@ public class LimboService {
|
||||
ConsoleLogger.debug("No LimboPlayer found for `{0}` - cannot restore", lowerName);
|
||||
} else {
|
||||
player.setOp(limbo.isOperator());
|
||||
player.setAllowFlight(limbo.isCanFly());
|
||||
float walkSpeed = limbo.getWalkSpeed();
|
||||
float flySpeed = limbo.getFlySpeed();
|
||||
// Reset the speed value if it was 0
|
||||
if (walkSpeed < 0.01f) {
|
||||
walkSpeed = LimboPlayer.DEFAULT_WALK_SPEED;
|
||||
}
|
||||
if (flySpeed < 0.01f) {
|
||||
flySpeed = LimboPlayer.DEFAULT_FLY_SPEED;
|
||||
}
|
||||
player.setWalkSpeed(walkSpeed);
|
||||
player.setFlySpeed(flySpeed);
|
||||
settings.getProperty(RESTORE_ALLOW_FLIGHT).restoreAllowFlight(player, limbo);
|
||||
settings.getProperty(RESTORE_FLY_SPEED).restoreFlySpeed(player, limbo);
|
||||
settings.getProperty(RESTORE_WALK_SPEED).restoreWalkSpeed(player, limbo);
|
||||
limbo.clearTasks();
|
||||
ConsoleLogger.debug("Restored LimboPlayer stats for `{0}`", lowerName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Possible types to restore the walk and fly speed from LimboPlayer
|
||||
* back to Bukkit Player.
|
||||
*/
|
||||
public enum WalkFlySpeedRestoreType {
|
||||
|
||||
/** Restores from LimboPlayer to Player. */
|
||||
RESTORE {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
player.setFlySpeed(limbo.getFlySpeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
player.setWalkSpeed(limbo.getWalkSpeed());
|
||||
}
|
||||
},
|
||||
|
||||
/** Restores from LimboPlayer, using the default speed if the speed on LimboPlayer is 0. */
|
||||
RESTORE_NO_ZERO {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
float limboFlySpeed = limbo.getFlySpeed();
|
||||
player.setFlySpeed(limboFlySpeed > 0.01f ? limboFlySpeed : LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
float limboWalkSpeed = limbo.getWalkSpeed();
|
||||
player.setWalkSpeed(limboWalkSpeed > 0.01f ? limboWalkSpeed : LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
}
|
||||
},
|
||||
|
||||
/** Uses the max speed of Player (current speed) and the LimboPlayer. */
|
||||
MAX_RESTORE {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
player.setFlySpeed(Math.max(player.getFlySpeed(), limbo.getFlySpeed()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
player.setWalkSpeed(Math.max(player.getWalkSpeed(), limbo.getWalkSpeed()));
|
||||
}
|
||||
},
|
||||
|
||||
/** Always sets the default speed to the player. */
|
||||
DEFAULT {
|
||||
@Override
|
||||
public void restoreFlySpeed(Player player, LimboPlayer limbo) {
|
||||
player.setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreWalkSpeed(Player player, LimboPlayer limbo) {
|
||||
player.setWalkSpeed(LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Restores the fly speed from Limbo to Player according to the restoration type.
|
||||
*
|
||||
* @param player the player to modify
|
||||
* @param limbo the limbo player to read from
|
||||
*/
|
||||
public abstract void restoreFlySpeed(Player player, LimboPlayer limbo);
|
||||
|
||||
/**
|
||||
* Restores the walk speed from Limbo to Player according to the restoration type.
|
||||
*
|
||||
* @param player the player to modify
|
||||
* @param limbo the limbo player to read from
|
||||
*/
|
||||
public abstract void restoreWalkSpeed(Player player, LimboPlayer limbo);
|
||||
|
||||
}
|
||||
@@ -20,9 +20,9 @@ public final class AuthMeSettingsRetriever {
|
||||
*/
|
||||
public static ConfigurationData buildConfigurationData() {
|
||||
return ConfigurationDataBuilder.collectData(
|
||||
DatabaseSettings.class, ConverterSettings.class, PluginSettings.class,
|
||||
RestrictionSettings.class, EmailSettings.class, HooksSettings.class,
|
||||
ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class,
|
||||
RegistrationSettings.class, BackupSettings.class);
|
||||
DatabaseSettings.class, PluginSettings.class, RestrictionSettings.class,
|
||||
EmailSettings.class, HooksSettings.class, ProtectionSettings.class,
|
||||
PurgeSettings.class, SecuritySettings.class, RegistrationSettings.class,
|
||||
LimboSettings.class, BackupSettings.class, ConverterSettings.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package fr.xephi.authme.settings.properties;
|
||||
|
||||
import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SectionComments;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import fr.xephi.authme.data.limbo.AllowFlightRestoreType;
|
||||
import fr.xephi.authme.data.limbo.WalkFlySpeedRestoreType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
/**
|
||||
* Settings for the LimboPlayer feature.
|
||||
*/
|
||||
public final class LimboSettings implements SettingsHolder {
|
||||
|
||||
@Comment({
|
||||
"Whether the player is allowed to fly: RESTORE, ENABLE, DISABLE.",
|
||||
"RESTORE sets back the old property from the player."
|
||||
})
|
||||
public static final Property<AllowFlightRestoreType> RESTORE_ALLOW_FLIGHT =
|
||||
newProperty(AllowFlightRestoreType.class, "limbo.restoreAllowFlight", AllowFlightRestoreType.RESTORE);
|
||||
|
||||
@Comment({
|
||||
"Restore fly speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.",
|
||||
"RESTORE: restore the speed the player had;",
|
||||
"DEFAULT: always set to default speed;",
|
||||
"MAX_RESTORE: take the maximum of the player's current speed and the previous one",
|
||||
"RESTORE_NO_ZERO: Like 'restore' but sets speed to default if the player's speed was 0"
|
||||
})
|
||||
public static final Property<WalkFlySpeedRestoreType> RESTORE_FLY_SPEED =
|
||||
newProperty(WalkFlySpeedRestoreType.class, "limbo.restoreFlySpeed", WalkFlySpeedRestoreType.MAX_RESTORE);
|
||||
|
||||
@Comment({
|
||||
"Restore walk speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.",
|
||||
"See above for a description of the values."
|
||||
})
|
||||
public static final Property<WalkFlySpeedRestoreType> RESTORE_WALK_SPEED =
|
||||
newProperty(WalkFlySpeedRestoreType.class, "limbo.restoreWalkSpeed", WalkFlySpeedRestoreType.MAX_RESTORE);
|
||||
|
||||
private LimboSettings() {
|
||||
}
|
||||
|
||||
@SectionComments
|
||||
public static Map<String, String[]> createSectionComments() {
|
||||
String[] limboExplanation = {
|
||||
"Before a user logs in, various properties are temporarily removed from the player,",
|
||||
"such as OP status, ability to fly, and walk/fly speed.",
|
||||
"Once the user is logged in, we add back the properties we previously saved.",
|
||||
"In this section, you may define how the properties should be restored."
|
||||
};
|
||||
return ImmutableMap.of("limbo", limboExplanation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user