Added options to reset player's health, hunger and XP

Implements https://github.com/BentoBoxWorld/BentoBox/issues/958

Added the following methods in WorldSettings and IslandWorldManager:
* #isOnJoinResetHealth()
* #isOnJoinResetHunger()
* #isOnJoinResetXP()
* #isOnLeaveResetHealth()
* #isOnLeaveResetHunger()
* #isOnLeaveResetXP()
This commit is contained in:
Florian CUNY 2019-10-13 10:29:32 +02:00
parent 6f96f47ae5
commit 77e0f01510
8 changed files with 190 additions and 1 deletions

View File

@ -98,6 +98,20 @@ public class AdminDeleteCommand extends ConfirmableCommand {
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
target.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
target.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
target.getPlayer().setTotalExperience(0);
}
}
vector = oldIsland.getCenter().toVector();
getIslands().deleteIsland(oldIsland, true, targetUUID);

View File

@ -131,7 +131,7 @@ public class IslandResetCommand extends ConfirmableCommand {
Builder builder = NewIsland.builder()
.player(user)
.reason(Reason.RESET)
.addon((GameModeAddon)getAddon())
.addon(getAddon())
.oldIsland(oldIsland)
.name(name);
if (noPaste) builder.noPaste();
@ -199,6 +199,21 @@ public class IslandResetCommand extends ConfirmableCommand {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(member, vault.getBalance(member)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
member.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
member.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
member.getPlayer().setTotalExperience(0);
}
// Fire event
IslandBaseEvent e = TeamEvent.builder()
.island(island)

View File

@ -170,5 +170,20 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
if (getSettings().isUseEconomy() && (getIWM().isOnLeaveResetMoney(getWorld()) || getIWM().isOnJoinResetMoney(getWorld()))) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
}
// Reset the health
if (getIWM().isOnJoinResetHealth(getWorld())) {
user.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (getIWM().isOnJoinResetHunger(getWorld())) {
user.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnJoinResetXP(getWorld())) {
user.getPlayer().setTotalExperience(0);
}
}
}

View File

@ -110,6 +110,20 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
target.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
target.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
target.getPlayer().setTotalExperience(0);
}
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
// Fire event
IslandBaseEvent e = TeamEvent.builder()

View File

@ -93,6 +93,20 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
}
// Reset the health
if (getIWM().isOnLeaveResetHealth(getWorld())) {
user.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (getIWM().isOnLeaveResetHunger(getWorld())) {
user.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (getIWM().isOnLeaveResetXP(getWorld())) {
user.getPlayer().setTotalExperience(0);
}
// Add cooldown for this player and target
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
// Get the invite class from the parent

View File

@ -197,6 +197,27 @@ public interface WorldSettings extends ConfigObject {
*/
boolean isOnJoinResetMoney();
/**
* Whether the player's health should be reset upon him joining an island or creating it.
* @return the onJoinResetHealth
* @since 1.8.0
*/
boolean isOnJoinResetHealth();
/**
* Whether the player's hunger should be reset upon him joining an island or creating it.
* @return the onJoinResetHunger
* @since 1.8.0
*/
boolean isOnJoinResetHunger();
/**
* Whether the player's XP should be reset upon him joining an island or creating it.
* @return the onJoinResetXP
* @since 1.8.0
*/
boolean isOnJoinResetXP();
/**
* Returns a list of commands that should be executed when the player joins an island or creates one.<br/>
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
@ -233,6 +254,27 @@ public interface WorldSettings extends ConfigObject {
*/
boolean isOnLeaveResetMoney();
/**
* Whether the player's health should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetHealth
* @since 1.8.0
*/
boolean isOnLeaveResetHealth();
/**
* Whether the player's hunger should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetHunger
* @since 1.8.0
*/
boolean isOnLeaveResetHunger();
/**
* Whether the player's XP should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetXP
* @since 1.8.0
*/
boolean isOnLeaveResetXP();
/**
* Returns a list of commands that should be executed when the player leaves an island or resets one.<br/>
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>

View File

@ -562,6 +562,36 @@ public class IslandWorldManager {
return gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
}
/**
* Returns whether a player's health should be reset upon him joining or creating an island in this World.
* @param world the World
* @return {@code true} if health should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnJoinResetHealth(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnJoinResetHealth();
}
/**
* Returns whether a player's hunger should be reset upon him joining or creating an island in this World.
* @param world the World
* @return {@code true} if hunger should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnJoinResetHunger(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnJoinResetHunger();
}
/**
* Returns whether a player's XP should be reset upon him joining or creating an island in this World.
* @param world the World
* @return {@code true} if XP should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnJoinResetXP(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnJoinResetXP();
}
/**
* Returns a list of commands to execute when the player creates or joins an island.
* @param world the World
@ -595,6 +625,36 @@ public class IslandWorldManager {
return gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
}
/**
* Returns whether a player's health should be reset upon him leaving or resetting his island in this World.
* @param world the World
* @return {@code true} if health should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnLeaveResetHealth(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnLeaveResetHealth();
}
/**
* Returns whether a player's hunger should be reset upon him leaving or resetting his island in this World.
* @param world the World
* @return {@code true} if hunger should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnLeaveResetHunger(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnLeaveResetHunger();
}
/**
* Returns whether a player's XP should be reset upon him leaving or resetting his island in this World.
* @param world the World
* @return {@code true} if XP should be reset, {@code false} otherwise.
* @since 1.8.0
*/
public boolean isOnLeaveResetXP(@NonNull World world) {
return gameModes.get(world).getWorldSettings().isOnLeaveResetXP();
}
/**
* Returns a list of commands to execute when the player resets or leaves an island.
* @param world the World

View File

@ -701,6 +701,21 @@ public class IslandsManager {
if (plugin.getSettings().isUseEconomy() && plugin.getIWM().isOnJoinResetMoney(world)) {
plugin.getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
}
// Reset the health
if (plugin.getIWM().isOnJoinResetHealth(world)) {
user.getPlayer().setHealth(20.0D);
}
// Reset the hunger
if (plugin.getIWM().isOnJoinResetHunger(world)) {
user.getPlayer().setFoodLevel(20);
}
// Reset the XP
if (plugin.getIWM().isOnJoinResetXP(world)) {
user.getPlayer().setTotalExperience(0);
}
}
}