#1280 Add NOTHING as possible flight restore type
This commit is contained in:
parent
ce2138a65c
commit
e1826c75c8
@ -1,5 +1,5 @@
|
|||||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||||
<!-- File auto-generated on Thu Jul 06 18:45:51 CEST 2017. See docs/config/config.tpl.md -->
|
<!-- File auto-generated on Mon Jul 10 21:39:00 CEST 2017. See docs/config/config.tpl.md -->
|
||||||
|
|
||||||
## AuthMe Configuration
|
## AuthMe Configuration
|
||||||
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
||||||
@ -476,8 +476,9 @@ limbo:
|
|||||||
# Note: if you change this setting all data will be migrated. If you have a lot of data,
|
# Note: if you change this setting all data will be migrated. If you have a lot of data,
|
||||||
# change this setting only on server restart, not with /authme reload.
|
# change this setting only on server restart, not with /authme reload.
|
||||||
distributionSize: 'SIXTEEN'
|
distributionSize: 'SIXTEEN'
|
||||||
# Whether the player is allowed to fly: RESTORE, ENABLE, DISABLE.
|
# Whether the player is allowed to fly: RESTORE, ENABLE, DISABLE, NOTHING.
|
||||||
# RESTORE sets back the old property from the player.
|
# RESTORE sets back the old property from the player. NOTHING will prevent AuthMe
|
||||||
|
# from modifying the 'allow flight' property on the player.
|
||||||
restoreAllowFlight: 'RESTORE'
|
restoreAllowFlight: 'RESTORE'
|
||||||
# Restore fly speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.
|
# Restore fly speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.
|
||||||
# RESTORE: restore the speed the player had;
|
# RESTORE: restore the speed the player had;
|
||||||
@ -487,7 +488,7 @@ limbo:
|
|||||||
restoreFlySpeed: 'RESTORE_NO_ZERO'
|
restoreFlySpeed: 'RESTORE_NO_ZERO'
|
||||||
# Restore walk speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.
|
# Restore walk speed: RESTORE, DEFAULT, MAX_RESTORE, RESTORE_NO_ZERO.
|
||||||
# See above for a description of the values.
|
# See above for a description of the values.
|
||||||
restoreWalkSpeed: 'MAX_RESTORE'
|
restoreWalkSpeed: 'RESTORE_NO_ZERO'
|
||||||
BackupSystem:
|
BackupSystem:
|
||||||
# General configuration for backups: if false, no backups are possible
|
# General configuration for backups: if false, no backups are possible
|
||||||
ActivateBackup: false
|
ActivateBackup: false
|
||||||
@ -528,4 +529,4 @@ To change settings on a running server, save your changes to config.yml and use
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Thu Jul 06 18:45:51 CEST 2017
|
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Mon Jul 10 21:39:00 CEST 2017
|
||||||
|
|||||||
@ -2,8 +2,6 @@ package fr.xephi.authme.data.limbo;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Possible types to restore the "allow flight" property
|
* Possible types to restore the "allow flight" property
|
||||||
* from LimboPlayer to Bukkit Player.
|
* from LimboPlayer to Bukkit Player.
|
||||||
@ -11,24 +9,41 @@ import java.util.function.Function;
|
|||||||
public enum AllowFlightRestoreType {
|
public enum AllowFlightRestoreType {
|
||||||
|
|
||||||
/** Set value from LimboPlayer to Player. */
|
/** Set value from LimboPlayer to Player. */
|
||||||
RESTORE(LimboPlayer::isCanFly),
|
RESTORE {
|
||||||
|
@Override
|
||||||
|
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
||||||
|
player.setAllowFlight(limbo.isCanFly());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/** Always set flight enabled to true. */
|
/** Always set flight enabled to true. */
|
||||||
ENABLE(l -> true),
|
ENABLE {
|
||||||
|
@Override
|
||||||
|
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
||||||
|
player.setAllowFlight(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/** Always set flight enabled to false. */
|
/** Always set flight enabled to false. */
|
||||||
DISABLE(l -> false);
|
DISABLE {
|
||||||
|
@Override
|
||||||
|
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
||||||
|
player.setAllowFlight(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
private final Function<LimboPlayer, Boolean> valueGetter;
|
/** Always set flight enabled to false. */
|
||||||
|
NOTHING {
|
||||||
|
@Override
|
||||||
|
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Constructor.
|
public void processPlayer(Player player) {
|
||||||
*
|
// noop
|
||||||
* @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.
|
* Restores the "allow flight" property from the LimboPlayer to the Player.
|
||||||
@ -37,7 +52,15 @@ public enum AllowFlightRestoreType {
|
|||||||
* @param player the player to modify
|
* @param player the player to modify
|
||||||
* @param limbo the limbo player to read from
|
* @param limbo the limbo player to read from
|
||||||
*/
|
*/
|
||||||
public void restoreAllowFlight(Player player, LimboPlayer limbo) {
|
public abstract void restoreAllowFlight(Player player, LimboPlayer limbo);
|
||||||
player.setAllowFlight(valueGetter.apply(limbo));
|
|
||||||
|
/**
|
||||||
|
* Processes the player when a LimboPlayer instance is created based on him. Typically this
|
||||||
|
* method revokes the {@code allowFlight} property to be restored again later.
|
||||||
|
*
|
||||||
|
* @param player the player to process
|
||||||
|
*/
|
||||||
|
public void processPlayer(Player player) {
|
||||||
|
player.setAllowFlight(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
|
import fr.xephi.authme.settings.properties.LimboSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -59,7 +60,8 @@ class LimboServiceHelper {
|
|||||||
*/
|
*/
|
||||||
void revokeLimboStates(Player player) {
|
void revokeLimboStates(Player player) {
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
player.setAllowFlight(false);
|
settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)
|
||||||
|
.processPlayer(player);
|
||||||
|
|
||||||
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
|
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
|
||||||
player.setFlySpeed(0.0f);
|
player.setFlySpeed(0.0f);
|
||||||
|
|||||||
@ -45,8 +45,9 @@ public final class LimboSettings implements SettingsHolder {
|
|||||||
newProperty(SegmentSize.class, "limbo.persistence.distributionSize", SegmentSize.SIXTEEN);
|
newProperty(SegmentSize.class, "limbo.persistence.distributionSize", SegmentSize.SIXTEEN);
|
||||||
|
|
||||||
@Comment({
|
@Comment({
|
||||||
"Whether the player is allowed to fly: RESTORE, ENABLE, DISABLE.",
|
"Whether the player is allowed to fly: RESTORE, ENABLE, DISABLE, NOTHING.",
|
||||||
"RESTORE sets back the old property from the player."
|
"RESTORE sets back the old property from the player. NOTHING will prevent AuthMe",
|
||||||
|
"from modifying the 'allow flight' property on the player."
|
||||||
})
|
})
|
||||||
public static final Property<AllowFlightRestoreType> RESTORE_ALLOW_FLIGHT =
|
public static final Property<AllowFlightRestoreType> RESTORE_ALLOW_FLIGHT =
|
||||||
newProperty(AllowFlightRestoreType.class, "limbo.restoreAllowFlight", AllowFlightRestoreType.RESTORE);
|
newProperty(AllowFlightRestoreType.class, "limbo.restoreAllowFlight", AllowFlightRestoreType.RESTORE);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import org.junit.Test;
|
|||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link AllowFlightRestoreType}.
|
* Test for {@link AllowFlightRestoreType}.
|
||||||
@ -64,6 +65,42 @@ public class AllowFlightRestoreTypeTest {
|
|||||||
verify(player2).setAllowFlight(false);
|
verify(player2).setAllowFlight(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotInteractWithPlayer() {
|
||||||
|
// given
|
||||||
|
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
|
||||||
|
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
|
||||||
|
Player player1 = mock(Player.class);
|
||||||
|
Player player2 = mock(Player.class);
|
||||||
|
|
||||||
|
// when
|
||||||
|
AllowFlightRestoreType.NOTHING.restoreAllowFlight(player1, limboWithFly);
|
||||||
|
AllowFlightRestoreType.NOTHING.restoreAllowFlight(player2, limboWithoutFly);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verifyZeroInteractions(player1, player2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRemoveFlightExceptForNothingType() {
|
||||||
|
// given
|
||||||
|
AllowFlightRestoreType noInteractionType = AllowFlightRestoreType.NOTHING;
|
||||||
|
|
||||||
|
for (AllowFlightRestoreType type : AllowFlightRestoreType.values()) {
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
|
// when
|
||||||
|
type.processPlayer(player);
|
||||||
|
|
||||||
|
// then
|
||||||
|
if (type == noInteractionType) {
|
||||||
|
verifyZeroInteractions(player);
|
||||||
|
} else {
|
||||||
|
verify(player).setAllowFlight(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static LimboPlayer newLimboWithAllowFlight(boolean allowFlight) {
|
private static LimboPlayer newLimboWithAllowFlight(boolean allowFlight) {
|
||||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||||
given(limbo.isCanFly()).willReturn(allowFlight);
|
given(limbo.isCanFly()).willReturn(allowFlight);
|
||||||
|
|||||||
@ -84,6 +84,7 @@ public class LimboServiceTest {
|
|||||||
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
|
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
|
||||||
given(permissionsManager.hasGroupSupport()).willReturn(true);
|
given(permissionsManager.hasGroupSupport()).willReturn(true);
|
||||||
given(permissionsManager.getGroups(player)).willReturn(Collections.singletonList("permgrwp"));
|
given(permissionsManager.getGroups(player)).willReturn(Collections.singletonList("permgrwp"));
|
||||||
|
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.ENABLE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboService.createLimboPlayer(player, true);
|
limboService.createLimboPlayer(player, true);
|
||||||
@ -114,6 +115,7 @@ public class LimboServiceTest {
|
|||||||
Location playerLoc = mock(Location.class);
|
Location playerLoc = mock(Location.class);
|
||||||
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
|
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
|
||||||
given(permissionsManager.hasGroupSupport()).willReturn(false);
|
given(permissionsManager.hasGroupSupport()).willReturn(false);
|
||||||
|
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.RESTORE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboService.createLimboPlayer(player, false);
|
limboService.createLimboPlayer(player, false);
|
||||||
@ -143,6 +145,7 @@ public class LimboServiceTest {
|
|||||||
LimboPlayer existingLimbo = mock(LimboPlayer.class);
|
LimboPlayer existingLimbo = mock(LimboPlayer.class);
|
||||||
getLimboMap().put("carlos", existingLimbo);
|
getLimboMap().put("carlos", existingLimbo);
|
||||||
Player player = newPlayer("Carlos");
|
Player player = newPlayer("Carlos");
|
||||||
|
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.ENABLE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboService.createLimboPlayer(player, false);
|
limboService.createLimboPlayer(player, false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user