Fixed AdminDeleteCommand.

This commit is contained in:
tastybento 2018-08-18 10:39:07 -07:00
parent 9847235df1
commit f844b9bb40
2 changed files with 29 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
public class AdminDeleteCommand extends ConfirmableCommand {
@ -53,8 +54,28 @@ public class AdminDeleteCommand extends ConfirmableCommand {
private void deletePlayer(User user, UUID targetUUID) {
// Delete player and island
user.sendMessage("commands.admin.delete.deleted-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
getIslands().deleteIsland(getIslands().getIsland(getWorld(), targetUUID), true);
getIslands().removePlayer(getWorld(), targetUUID);
// Get the target's island
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
if (oldIsland != null) {
// Check if player is online and on the island
User target = User.getInstance(targetUUID);
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(getWorld(), targetUUID);
if (target.isOnline()) {
// Remove money inventory etc.
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
target.getPlayer().getEnderChest().clear();
}
if (getIWM().isOnLeaveResetInventory(getWorld())) {
target.getPlayer().getInventory().clear();
}
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
// TODO: needs Vault
}
}
getIslands().deleteIsland(oldIsland, true);
}
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("general.success");
}

View File

@ -42,8 +42,6 @@ import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
*/
public class IslandsManager {
private static final String SPAWNCOMMAND = "spawn";
private BentoBox plugin;
/**
@ -250,12 +248,12 @@ public class IslandsManager {
island.setOwner(null);
island.setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
if (removeBlocks) {
// Remove players from island
removePlayersFromIsland(island);
// Remove island from the cache
islandCache.deleteIslandFromCache(island);
// Remove the island from the database
handler.deleteObject(island);
// Remove players from island
removePlayersFromIsland(island);
// Remove blocks from world
new DeleteIslandChunks(plugin, island);
}
@ -623,7 +621,7 @@ public class IslandsManager {
/**
* Checks if an online player is in the protected area of their island, a team island or a
* coop island in the specific world in the arguments. Note that the user
* coop island in the specific world in the arguments.
*
* @param world - the world to check
* @param user - the user
@ -674,9 +672,9 @@ public class IslandsManager {
// go to island spawn
player.teleport(spawn.get(island.getWorld()).getSpawnPoint(island.getWorld().getEnvironment()));
} else {
if (!player.performCommand(SPAWNCOMMAND)) {
plugin.logWarning("During island deletion player " + player.getName() + " could not be sent to spawn so was dropped, sorry.");
}
plugin.logWarning("During island deletion player " + player.getName() + " could not be sent home so was placed into spectator mode.");
player.setGameMode(GameMode.SPECTATOR);
player.getPlayer().setFlying(true);
}
}
}