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);
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();
}

View File

@ -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