mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-24 09:02:00 +01:00
Remove code duplication between kick and leave command
This commit is contained in:
parent
f5b2b136e9
commit
372f149f3d
@ -85,43 +85,9 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
target.sendMessage("commands.island.team.kick.owner-kicked", TextVariables.GAMEMODE, getAddon().getDescription().getName());
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Execute commands when leaving
|
||||
Util.runCommands(target, getIWM().getOnLeaveCommands(oldIsland.getWorld()), "leave");
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
else {
|
||||
getPlayers().getPlayer(targetUUID).addToPendingKick(getWorld());
|
||||
getPlayers().save(targetUUID);
|
||||
}
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld()) && !getIWM().isKickedKeepInventory(getWorld())) {
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().getInventory().clear();
|
||||
} else {
|
||||
getPlayers().getPlayer(targetUUID).addToPendingKick(getWorld());
|
||||
getPlayers().save(targetUUID);
|
||||
}
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
||||
}
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
Util.resetHealth(target.getPlayer());
|
||||
}
|
||||
// Clean the target player
|
||||
getPlayers().cleanLeavingPlayer(getWorld(), target);
|
||||
|
||||
// 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
|
||||
TeamEvent.builder()
|
||||
|
@ -11,7 +11,6 @@ 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;
|
||||
|
||||
public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
|
||||
@ -72,32 +71,9 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
|
||||
// Execute commands when leaving
|
||||
Util.runCommands(user, getIWM().getOnLeaveCommands(island.getWorld()), "leave");
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
}
|
||||
if (getIWM().isOnLeaveResetInventory(getWorld())) {
|
||||
user.getPlayer().getInventory().clear();
|
||||
}
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
||||
}
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
Util.resetHealth(user.getPlayer());
|
||||
}
|
||||
// Clean the player
|
||||
getPlayers().cleanLeavingPlayer(getWorld(), user);
|
||||
|
||||
// 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
|
||||
|
@ -15,6 +15,7 @@ import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.bentobox.database.objects.Names;
|
||||
import world.bentobox.bentobox.database.objects.Players;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class PlayersManager {
|
||||
|
||||
@ -507,4 +508,49 @@ public class PlayersManager {
|
||||
playerCache.values().removeIf(p -> player.getUniqueId().toString().equals(p.getUniqueId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the player when leaving an island
|
||||
* @param world - island world
|
||||
* @param target - target user
|
||||
* @since 1.15.4
|
||||
*/
|
||||
public void cleanLeavingPlayer(World world, User target) {
|
||||
// Execute commands when leaving
|
||||
Util.runCommands(target, plugin.getIWM().getOnLeaveCommands(world), "leave");
|
||||
// Remove money inventory etc.
|
||||
if (plugin.getIWM().isOnLeaveResetEnderChest(world)) {
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().getEnderChest().clear();
|
||||
} else {
|
||||
getPlayer(target.getUniqueId()).addToPendingKick(world);
|
||||
}
|
||||
}
|
||||
if (plugin.getIWM().isOnLeaveResetInventory(world) && !plugin.getIWM().isKickedKeepInventory(world)) {
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().getInventory().clear();
|
||||
} else {
|
||||
getPlayer(target.getUniqueId()).addToPendingKick(world);
|
||||
}
|
||||
}
|
||||
if (plugin.getSettings().isUseEconomy() && plugin.getIWM().isOnLeaveResetMoney(world)) {
|
||||
plugin.getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
||||
}
|
||||
// Reset the health
|
||||
if (plugin.getIWM().isOnLeaveResetHealth(world)) {
|
||||
Util.resetHealth(target.getPlayer());
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (plugin.getIWM().isOnLeaveResetHunger(world)) {
|
||||
target.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (plugin.getIWM().isOnLeaveResetXP(world)) {
|
||||
target.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
// Save player
|
||||
save(target.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user