mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-18 15:18:26 +01:00
Added protection around null owners.
This commit is contained in:
parent
3d74c4a427
commit
dee635f15f
@ -10,7 +10,6 @@ import us.tastybento.bskyblock.BSkyBlock;
|
|||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
import us.tastybento.bskyblock.schematics.Schematic;
|
import us.tastybento.bskyblock.schematics.Schematic;
|
||||||
import us.tastybento.bskyblock.util.DeleteIslandBlocks;
|
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
import us.tastybento.bskyblock.util.VaultHelper;
|
import us.tastybento.bskyblock.util.VaultHelper;
|
||||||
|
|
||||||
@ -255,10 +254,16 @@ public class IslandCommand extends BSBCommand{
|
|||||||
}
|
}
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
if (plugin.getIslands().hasIsland(player.getUniqueId())) {
|
if (plugin.getIslands().hasIsland(player.getUniqueId())) {
|
||||||
plugin.getIslands().deletePlayerIsland(player.getUniqueId(), true);
|
// Get the player's old island
|
||||||
// Create new island
|
Island oldIsland = plugin.getIslands().getIsland(player.getUniqueId());
|
||||||
|
plugin.getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
|
||||||
|
// Remove them from this island (it still exists and will be deleted later)
|
||||||
|
plugin.getIslands().removePlayer(player.getUniqueId());
|
||||||
|
plugin.getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
|
||||||
|
// Create new island and then delete the old one
|
||||||
|
plugin.getLogger().info("DEBUG: making new island ");
|
||||||
Schematic schematic = plugin.getSchematics().getSchematic("default");
|
Schematic schematic = plugin.getSchematics().getSchematic("default");
|
||||||
plugin.getIslands().newIsland(player, schematic);
|
plugin.getIslands().newIsland(player, schematic, oldIsland);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Util.sendMessage(player, plugin.getLocale(player.getUniqueId()).get("error.noIsland"));
|
Util.sendMessage(player, plugin.getLocale(player.getUniqueId()).get("error.noIsland"));
|
||||||
|
@ -335,7 +335,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException {
|
public void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException {
|
||||||
// The file name of the Yaml file.
|
// The file name of the Yaml file.
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor("uniqueId", type);
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor("uniqueId", type);
|
||||||
Method method = propertyDescriptor.getReadMethod();
|
Method method = propertyDescriptor.getReadMethod();
|
||||||
|
@ -157,6 +157,6 @@ public abstract class AbstractDatabaseHandler<T> {
|
|||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
* @throws NoSuchMethodException
|
* @throws NoSuchMethodException
|
||||||
*/
|
*/
|
||||||
protected abstract void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException;
|
public abstract void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an island with owner. Note this does not create the schematic. It just reates the island data object.
|
* Create an island with owner. Note this does not create the schematic. It just creates the island data object.
|
||||||
* @param location
|
* @param location
|
||||||
* @param owner UUID
|
* @param owner UUID
|
||||||
*/
|
*/
|
||||||
@ -206,6 +206,8 @@ public class IslandsManager {
|
|||||||
//getWarpSignsListener().removeWarp(player);
|
//getWarpSignsListener().removeWarp(player);
|
||||||
Island island = getIsland(player);
|
Island island = getIsland(player);
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
|
// Set the owner of the island to no one.
|
||||||
|
island.setOwner(null);
|
||||||
if (removeBlocks) {
|
if (removeBlocks) {
|
||||||
removePlayersFromIsland(island, player);
|
removePlayersFromIsland(island, player);
|
||||||
new DeleteIslandBlocks(plugin, island);
|
new DeleteIslandBlocks(plugin, island);
|
||||||
@ -443,7 +445,7 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public boolean homeTeleport(final Player player, int number) {
|
public boolean homeTeleport(final Player player, int number) {
|
||||||
Location home = null;
|
Location home = null;
|
||||||
//plugin.getLogger().info("home teleport called for #" + number);
|
plugin.getLogger().info("home teleport called for #" + number);
|
||||||
home = getSafeHomeLocation(player.getUniqueId(), number);
|
home = getSafeHomeLocation(player.getUniqueId(), number);
|
||||||
//plugin.getLogger().info("home get safe loc = " + home);
|
//plugin.getLogger().info("home get safe loc = " + home);
|
||||||
// Check if the player is a passenger in a boat
|
// Check if the player is a passenger in a boat
|
||||||
@ -458,12 +460,12 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
//plugin.getLogger().info("Fixing home location using safe spot teleport");
|
plugin.getLogger().info("Fixing home location using safe spot teleport");
|
||||||
// Try to fix this teleport location and teleport the player if possible
|
// Try to fix this teleport location and teleport the player if possible
|
||||||
new SafeSpotTeleport(plugin, player, plugin.getPlayers().getHomeLocation(player.getUniqueId(), number), number);
|
new SafeSpotTeleport(plugin, player, plugin.getPlayers().getHomeLocation(player.getUniqueId(), number), number);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
|
plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
|
||||||
//home.getChunk().load();
|
//home.getChunk().load();
|
||||||
player.teleport(home);
|
player.teleport(home);
|
||||||
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
||||||
@ -737,11 +739,24 @@ public class IslandsManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes an island using schematic. No permission checks are made. They have to be decided
|
* Makes an island using schematic. No permission checks are made. They have to be decided
|
||||||
* before this method is called.
|
* before this method is called. If oldIsland is not null, it will be deleted after the new
|
||||||
|
* island is made.
|
||||||
* @param player
|
* @param player
|
||||||
* @param schematic
|
* @param schematic
|
||||||
*/
|
*/
|
||||||
public void newIsland(final Player player, final Schematic schematic) {
|
public void newIsland(Player player, Schematic schematic) {
|
||||||
|
newIsland(player, schematic, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes an island using schematic. No permission checks are made. They have to be decided
|
||||||
|
* before this method is called. If oldIsland is not null, it will be deleted after the new
|
||||||
|
* island is made.
|
||||||
|
* @param player
|
||||||
|
* @param schematic
|
||||||
|
* @param oldIsland - the old island to be deleted after the new island is made
|
||||||
|
*/
|
||||||
|
public void newIsland(final Player player, final Schematic schematic, Island oldIsland) {
|
||||||
plugin.getLogger().info("DEBUG: new island");
|
plugin.getLogger().info("DEBUG: new island");
|
||||||
//long time = System.nanoTime();
|
//long time = System.nanoTime();
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
@ -752,6 +767,13 @@ public class IslandsManager {
|
|||||||
plugin.getLogger().info("DEBUG: finding island location");
|
plugin.getLogger().info("DEBUG: finding island location");
|
||||||
Location next = getNextIsland(player.getUniqueId());
|
Location next = getNextIsland(player.getUniqueId());
|
||||||
plugin.getLogger().info("DEBUG: found " + next);
|
plugin.getLogger().info("DEBUG: found " + next);
|
||||||
|
|
||||||
|
// Add to the grid
|
||||||
|
Island myIsland = plugin.getIslands().createIsland(next, playerUUID);
|
||||||
|
myIsland.setLevelHandicap(schematic.getLevelHandicap());
|
||||||
|
// Save the player so that if the server is reset weird things won't happen
|
||||||
|
plugin.getPlayers().save(true);
|
||||||
|
|
||||||
// Clear any old home locations (they should be clear, but just in case)
|
// Clear any old home locations (they should be clear, but just in case)
|
||||||
plugin.getPlayers().clearHomeLocations(playerUUID);
|
plugin.getPlayers().clearHomeLocations(playerUUID);
|
||||||
|
|
||||||
@ -779,13 +801,13 @@ public class IslandsManager {
|
|||||||
next = next.toVector().toLocation(IslandWorld.getNetherWorld());
|
next = next.toVector().toLocation(IslandWorld.getNetherWorld());
|
||||||
// Set the player's island location to this new spot
|
// Set the player's island location to this new spot
|
||||||
//plugin.getPlayers().setIslandLocation(playerUUID, next);
|
//plugin.getPlayers().setIslandLocation(playerUUID, next);
|
||||||
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET);
|
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland);
|
||||||
} else {
|
} else {
|
||||||
// Over world start
|
// Over world start
|
||||||
//plugin.getLogger().info("DEBUG: pasting");
|
//plugin.getLogger().info("DEBUG: pasting");
|
||||||
//long timer = System.nanoTime();
|
//long timer = System.nanoTime();
|
||||||
// Paste the island and teleport the player home
|
// Paste the island and teleport the player home
|
||||||
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET);
|
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET, oldIsland);
|
||||||
//double diff = (System.nanoTime() - timer)/1000000;
|
//double diff = (System.nanoTime() - timer)/1000000;
|
||||||
//plugin.getLogger().info("DEBUG: nano time = " + diff + " ms");
|
//plugin.getLogger().info("DEBUG: nano time = " + diff + " ms");
|
||||||
//plugin.getLogger().info("DEBUG: pasted overworld");
|
//plugin.getLogger().info("DEBUG: pasted overworld");
|
||||||
@ -809,11 +831,7 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add to the grid
|
|
||||||
Island myIsland = plugin.getIslands().createIsland(next, playerUUID);
|
|
||||||
myIsland.setLevelHandicap(schematic.getLevelHandicap());
|
|
||||||
// Save the player so that if the server is reset weird things won't happen
|
|
||||||
plugin.getPlayers().save(true);
|
|
||||||
|
|
||||||
// Start the reset cooldown
|
// Start the reset cooldown
|
||||||
//if (!firstTime) {
|
//if (!firstTime) {
|
||||||
@ -870,7 +888,7 @@ public class IslandsManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
schematic.pasteSchematic(loc, player, false, PasteReason.PARTNER);
|
schematic.pasteSchematic(loc, player, false, PasteReason.PARTNER, null);
|
||||||
|
|
||||||
}}, 60L);
|
}}, 60L);
|
||||||
|
|
||||||
@ -969,4 +987,8 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractDatabaseHandler<Island> getHandler() {
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -728,7 +728,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#deleteObject(java.lang.Object)
|
* @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#deleteObject(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void deleteObject(T instance)
|
public void deleteObject(T instance)
|
||||||
throws IllegalAccessException, IllegalArgumentException,
|
throws IllegalAccessException, IllegalArgumentException,
|
||||||
InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException {
|
InvocationTargetException, IntrospectionException, SQLException, NoSuchMethodException, SecurityException {
|
||||||
// Delete this object from all tables
|
// Delete this object from all tables
|
||||||
|
@ -485,7 +485,7 @@ public class Island extends DataObject {
|
|||||||
* @return the island display name or the owner's name if none is set
|
* @return the island display name or the owner's name if none is set
|
||||||
*/
|
*/
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return (name != null) ? name : Bukkit.getServer().getOfflinePlayer(owner).getName();
|
return (name != null && owner != null) ? name : Bukkit.getServer().getOfflinePlayer(owner).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,6 +70,8 @@ import net.milkbowl.vault.economy.EconomyResponse;
|
|||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.config.Settings.GameType;
|
import us.tastybento.bskyblock.config.Settings.GameType;
|
||||||
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
import us.tastybento.bskyblock.util.DeleteIslandBlocks;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
import us.tastybento.bskyblock.util.VaultHelper;
|
import us.tastybento.bskyblock.util.VaultHelper;
|
||||||
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
||||||
@ -776,9 +778,10 @@ public class Schematic {
|
|||||||
* This method pastes a schematic.
|
* This method pastes a schematic.
|
||||||
* @param loc
|
* @param loc
|
||||||
* @param player
|
* @param player
|
||||||
|
* @param oldIsland
|
||||||
* @param partner
|
* @param partner
|
||||||
*/
|
*/
|
||||||
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason) {
|
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason, Island oldIsland) {
|
||||||
// If this is not a file schematic, paste the default island
|
// If this is not a file schematic, paste the default island
|
||||||
if (this.file == null) {
|
if (this.file == null) {
|
||||||
if (Settings.GAMETYPE == GameType.ACIDISLAND) {
|
if (Settings.GAMETYPE == GameType.ACIDISLAND) {
|
||||||
@ -1042,6 +1045,7 @@ public class Schematic {
|
|||||||
//player.setInvulnerable(true);
|
//player.setInvulnerable(true);
|
||||||
// Check distance. If it's too close, warp to spawn to try to clear the client's cache
|
// Check distance. If it's too close, warp to spawn to try to clear the client's cache
|
||||||
//plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
|
//plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
|
||||||
|
/*
|
||||||
if (player.getWorld().equals(world)) {
|
if (player.getWorld().equals(world)) {
|
||||||
//plugin.getLogger().info("DEBUG: same world");
|
//plugin.getLogger().info("DEBUG: same world");
|
||||||
int distSq = (int)((player.getLocation().distanceSquared(loc) - (Settings.islandDistance * Settings.islandDistance)/16));
|
int distSq = (int)((player.getLocation().distanceSquared(loc) - (Settings.islandDistance * Settings.islandDistance)/16));
|
||||||
@ -1050,7 +1054,7 @@ public class Schematic {
|
|||||||
//plugin.getLogger().info("DEBUG: teleporting");
|
//plugin.getLogger().info("DEBUG: teleporting");
|
||||||
player.teleport(world.getSpawnLocation());
|
player.teleport(world.getSpawnLocation());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1101,6 +1105,18 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the old island if required
|
||||||
|
if (oldIsland != null) {
|
||||||
|
plugin.getLogger().info("DEBUG: Deleting old island");
|
||||||
|
new DeleteIslandBlocks(plugin, oldIsland);
|
||||||
|
try {
|
||||||
|
plugin.getIslands().getHandler().deleteObject(oldIsland);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}, 10L);
|
}}, 10L);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user