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
if (getIWM().isOnLeaveResetHealth(getWorld())) {
target.getPlayer().setHealth(20.0D);
Util.resetHealth(target.getPlayer());
}
// Reset the hunger

View File

@ -126,7 +126,7 @@ public class IslandResetCommand extends ConfirmableCommand {
.oldIsland(oldIsland)
.location(oldIsland.getCenter())
.build();
// Reset the island
user.sendMessage("commands.island.create.creating-island");
@ -205,7 +205,7 @@ public class IslandResetCommand extends ConfirmableCommand {
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
member.getPlayer().setHealth(20.0D);
Util.resetHealth(member.getPlayer());
}
// Reset the hunger

View File

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

View File

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

View File

@ -86,7 +86,7 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
user.getPlayer().setHealth(20.0D);
Util.resetHealth(user.getPlayer());
}
// Reset the hunger
@ -118,11 +118,11 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
.involvedPlayer(user.getUniqueId())
.build();
IslandEvent.builder()
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.VISITOR_RANK)
.build();
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.VISITOR_RANK)
.build();
}
}

View File

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

View File

@ -19,6 +19,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Animals;
@ -279,7 +280,7 @@ public class Util {
return 90F;
case EAST_NORTH_EAST:
return 67.5F;
case NORTH_EAST:
case NORTH_EAST:
return 45F;
case NORTH_NORTH_EAST:
return 22.5F;
@ -644,6 +645,15 @@ 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);
}
}