Skip to content

Commit

Permalink
Fixed AdminDeleteCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 18, 2018
1 parent 9847235 commit f844b9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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 {
Expand Down Expand Up @@ -53,8 +54,28 @@ public boolean execute(User user, String label, List<String> args) {
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
*/
public class IslandsManager {

private static final String SPAWNCOMMAND = "spawn";

private BentoBox plugin;

/**
Expand Down Expand Up @@ -250,12 +248,12 @@ public void deleteIsland(Island island, boolean removeBlocks) {
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);
}
Expand Down Expand Up @@ -623,7 +621,7 @@ public boolean locationIsOnIsland(Player player, Location loc) {

/**
* 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
Expand Down Expand Up @@ -674,9 +672,9 @@ public void removePlayersFromIsland(Island island) {
// 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);
}
}
}
Expand Down

0 comments on commit f844b9b

Please sign in to comment.