From efe62beccdaa7ca27ec77314862744d146f9c9ef Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 9 Aug 2016 19:44:32 +0200 Subject: [PATCH] Reset speed if it was 0 #890 --- .../xephi/authme/cache/limbo/LimboCache.java | 16 ++++++---- .../authme/cache/limbo/LimboCacheTest.java | 30 +++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 8c853828f..dd8052821 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -81,11 +81,17 @@ public class LimboCache { PlayerData data = cache.get(lowerName); player.setOp(data.isOperator()); player.setAllowFlight(data.isCanFly()); - //player.setWalkSpeed(data.getWalkSpeed()); - //player.setFlySpeed(data.getFlySpeed()); - // FIXME: this is a temp fix! - player.setWalkSpeed(0.2f); - player.setFlySpeed(0.2f); + float walkSpeed = data.getWalkSpeed(); + float flySpeed = data.getFlySpeed(); + // Reset the speed value if it was 0 + if(walkSpeed == 0f) { + walkSpeed = 0.2f; + } + if(flySpeed == 0f) { + flySpeed = 0.2f; + } + player.setWalkSpeed(walkSpeed); + player.setFlySpeed(flySpeed); restoreGroup(player, data.getGroup()); data.clearTasks(); } diff --git a/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java b/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java index 8f25d10f6..26da8f7dc 100644 --- a/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java +++ b/src/test/java/fr/xephi/authme/cache/limbo/LimboCacheTest.java @@ -128,16 +128,40 @@ public class LimboCacheTest { // when limboCache.restoreData(player); - // FIXME: speeds // then verify(player).setOp(true); - //verify(player).setWalkSpeed(walkSpeed); + verify(player).setWalkSpeed(walkSpeed); verify(player).setAllowFlight(true); - //verify(player).setFlySpeed(flySpeed); + verify(player).setFlySpeed(flySpeed); verify(permissionsManager).setGroup(player, group); verify(playerData).clearTasks(); } + @Test + public void shouldResetPlayerSpeed() { + // given + String name = "Champ"; + Player player = mock(Player.class); + given(player.getName()).willReturn(name); + PlayerData playerData = mock(PlayerData.class); + given(playerData.isOperator()).willReturn(true); + given(playerData.getWalkSpeed()).willReturn(0f); + given(playerData.isCanFly()).willReturn(true); + given(playerData.getFlySpeed()).willReturn(0f); + String group = "primary-group"; + given(playerData.getGroup()).willReturn(group); + getCache().put(name.toLowerCase(), playerData); + given(settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)).willReturn(true); + given(permissionsManager.hasGroupSupport()).willReturn(true); + + // when + limboCache.restoreData(player); + + // then + verify(player).setWalkSpeed(0.2f); + verify(player).setFlySpeed(0.2f); + } + @Test public void shouldNotInteractWithPlayerIfNoDataAvailable() { // given