mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-08 09:27:38 +01:00
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:
parent
6f96f47ae5
commit
77e0f01510
@ -98,6 +98,20 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
|||||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
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();
|
vector = oldIsland.getCenter().toVector();
|
||||||
getIslands().deleteIsland(oldIsland, true, targetUUID);
|
getIslands().deleteIsland(oldIsland, true, targetUUID);
|
||||||
|
@ -131,7 +131,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
|||||||
Builder builder = NewIsland.builder()
|
Builder builder = NewIsland.builder()
|
||||||
.player(user)
|
.player(user)
|
||||||
.reason(Reason.RESET)
|
.reason(Reason.RESET)
|
||||||
.addon((GameModeAddon)getAddon())
|
.addon(getAddon())
|
||||||
.oldIsland(oldIsland)
|
.oldIsland(oldIsland)
|
||||||
.name(name);
|
.name(name);
|
||||||
if (noPaste) builder.noPaste();
|
if (noPaste) builder.noPaste();
|
||||||
@ -199,6 +199,21 @@ public class IslandResetCommand extends ConfirmableCommand {
|
|||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(member, vault.getBalance(member)));
|
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
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
IslandBaseEvent e = TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
|
@ -170,5 +170,20 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
if (getSettings().isUseEconomy() && (getIWM().isOnLeaveResetMoney(getWorld()) || getIWM().isOnJoinResetMoney(getWorld()))) {
|
if (getSettings().isUseEconomy() && (getIWM().isOnLeaveResetMoney(getWorld()) || getIWM().isOnJoinResetMoney(getWorld()))) {
|
||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,20 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
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());
|
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
IslandBaseEvent e = TeamEvent.builder()
|
||||||
|
@ -93,6 +93,20 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
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
|
// Add cooldown for this player and target
|
||||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||||
// Get the invite class from the parent
|
// Get the invite class from the parent
|
||||||
|
@ -197,6 +197,27 @@ public interface WorldSettings extends ConfigObject {
|
|||||||
*/
|
*/
|
||||||
boolean isOnJoinResetMoney();
|
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/>
|
* 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/>
|
* 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();
|
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/>
|
* 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/>
|
* 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/>
|
||||||
|
@ -562,6 +562,36 @@ public class IslandWorldManager {
|
|||||||
return gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
|
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.
|
* Returns a list of commands to execute when the player creates or joins an island.
|
||||||
* @param world the World
|
* @param world the World
|
||||||
@ -595,6 +625,36 @@ public class IslandWorldManager {
|
|||||||
return gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
|
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.
|
* Returns a list of commands to execute when the player resets or leaves an island.
|
||||||
* @param world the World
|
* @param world the World
|
||||||
|
@ -701,6 +701,21 @@ public class IslandsManager {
|
|||||||
if (plugin.getSettings().isUseEconomy() && plugin.getIWM().isOnJoinResetMoney(world)) {
|
if (plugin.getSettings().isUseEconomy() && plugin.getIWM().isOnJoinResetMoney(world)) {
|
||||||
plugin.getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user