Fix for kicking offline players

https://github.com/BentoBoxWorld/BentoBox/issues/1950
This commit is contained in:
tastybento 2022-03-18 13:59:41 +00:00
parent fd44e03b7b
commit 4e8ca6d22c
2 changed files with 4 additions and 3 deletions

View File

@ -577,17 +577,17 @@ public class PlayersManager {
plugin.getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target), world)); plugin.getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target), world));
} }
// Reset the health // Reset the health
if (plugin.getIWM().isOnLeaveResetHealth(world)) { if (plugin.getIWM().isOnLeaveResetHealth(world) && target.isPlayer()) {
Util.resetHealth(target.getPlayer()); Util.resetHealth(target.getPlayer());
} }
// Reset the hunger // Reset the hunger
if (plugin.getIWM().isOnLeaveResetHunger(world)) { if (plugin.getIWM().isOnLeaveResetHunger(world) && target.isPlayer()) {
target.getPlayer().setFoodLevel(20); target.getPlayer().setFoodLevel(20);
} }
// Reset the XP // Reset the XP
if (plugin.getIWM().isOnLeaveResetXP(world)) { if (plugin.getIWM().isOnLeaveResetXP(world) && target.isPlayer()) {
target.getPlayer().setTotalExperience(0); target.getPlayer().setTotalExperience(0);
} }
// Save player // Save player

View File

@ -169,6 +169,7 @@ public class PlayersManagerTest {
when(user.getPlayer()).thenReturn(p); when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento"); when(user.getName()).thenReturn("tastybento");
when(user.isOnline()).thenReturn(true); when(user.isOnline()).thenReturn(true);
when(user.isPlayer()).thenReturn(true);
User.setPlugin(plugin); User.setPlugin(plugin);