Reset speed if it was 0 #890

This commit is contained in:
Gabriele C 2016-08-09 19:44:32 +02:00
parent 402a5e016e
commit efe62beccd
2 changed files with 38 additions and 8 deletions

View File

@ -81,11 +81,17 @@ public class LimboCache {
PlayerData data = cache.get(lowerName); PlayerData data = cache.get(lowerName);
player.setOp(data.isOperator()); player.setOp(data.isOperator());
player.setAllowFlight(data.isCanFly()); player.setAllowFlight(data.isCanFly());
//player.setWalkSpeed(data.getWalkSpeed()); float walkSpeed = data.getWalkSpeed();
//player.setFlySpeed(data.getFlySpeed()); float flySpeed = data.getFlySpeed();
// FIXME: this is a temp fix! // Reset the speed value if it was 0
player.setWalkSpeed(0.2f); if(walkSpeed == 0f) {
player.setFlySpeed(0.2f); walkSpeed = 0.2f;
}
if(flySpeed == 0f) {
flySpeed = 0.2f;
}
player.setWalkSpeed(walkSpeed);
player.setFlySpeed(flySpeed);
restoreGroup(player, data.getGroup()); restoreGroup(player, data.getGroup());
data.clearTasks(); data.clearTasks();
} }

View File

@ -128,16 +128,40 @@ public class LimboCacheTest {
// when // when
limboCache.restoreData(player); limboCache.restoreData(player);
// FIXME: speeds
// then // then
verify(player).setOp(true); verify(player).setOp(true);
//verify(player).setWalkSpeed(walkSpeed); verify(player).setWalkSpeed(walkSpeed);
verify(player).setAllowFlight(true); verify(player).setAllowFlight(true);
//verify(player).setFlySpeed(flySpeed); verify(player).setFlySpeed(flySpeed);
verify(permissionsManager).setGroup(player, group); verify(permissionsManager).setGroup(player, group);
verify(playerData).clearTasks(); 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 @Test
public void shouldNotInteractWithPlayerIfNoDataAvailable() { public void shouldNotInteractWithPlayerIfNoDataAvailable() {
// given // given