Switch to use Util method to reset player health.

Reduces duplicate code.
This commit is contained in:
tastybento 2020-10-11 09:18:53 -07:00
parent ae1db70ff6
commit b024d0cc8b
7 changed files with 26 additions and 19 deletions

View File

@ -100,7 +100,7 @@ public class AdminDeleteCommand extends ConfirmableCommand {
} }
// Reset the health // Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) { if (getIWM().isOnLeaveResetHealth(getWorld())) {
target.getPlayer().setHealth(20.0D); Util.resetHealth(target.getPlayer());
} }
// Reset the hunger // Reset the hunger

View File

@ -205,7 +205,7 @@ public class IslandResetCommand extends ConfirmableCommand {
// Reset the health // Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) { if (getIWM().isOnLeaveResetHealth(getWorld())) {
member.getPlayer().setHealth(20.0D); Util.resetHealth(member.getPlayer());
} }
// Reset the hunger // Reset the hunger

View File

@ -3,8 +3,6 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.attribute.Attribute;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type; import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
@ -14,6 +12,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;
/** /**
* @author tastybento * @author tastybento
@ -197,8 +196,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Reset the health // Reset the health
if (getIWM().isOnJoinResetHealth(getWorld())) { if (getIWM().isOnJoinResetHealth(getWorld())) {
double maxHealth = user.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); Util.resetHealth(user.getPlayer());
user.getPlayer().setHealth(maxHealth);
} }
// Reset the hunger // Reset the hunger

View File

@ -110,7 +110,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
} }
// Reset the health // Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) { if (getIWM().isOnLeaveResetHealth(getWorld())) {
target.getPlayer().setHealth(20.0D); Util.resetHealth(target.getPlayer());
} }
// Reset the hunger // Reset the hunger

View File

@ -86,7 +86,7 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
} }
// Reset the health // Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) { if (getIWM().isOnLeaveResetHealth(getWorld())) {
user.getPlayer().setHealth(20.0D); Util.resetHealth(user.getPlayer());
} }
// Reset the hunger // Reset the hunger

View File

@ -22,7 +22,6 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.TreeSpecies; import org.bukkit.TreeSpecies;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
@ -924,7 +923,7 @@ public class IslandsManager {
// Reset the health // Reset the health
if (plugin.getIWM().isOnJoinResetHealth(world)) { if (plugin.getIWM().isOnJoinResetHealth(world)) {
user.getPlayer().setHealth(user.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()); Util.resetHealth(user.getPlayer());
} }
// Reset the hunger // Reset the hunger

View File

@ -19,6 +19,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
@ -646,4 +647,13 @@ public class Util {
}); });
} }
/**
* Resets the player's heath to maximum
* @param player - player
*/
public static void resetHealth(Player player) {
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
player.setHealth(maxHealth);
}
} }