fix plot delete (among other things)

This commit is contained in:
boy0001 2015-04-09 15:41:14 +10:00
parent 86c46f7ec0
commit 9ca5ba812d
13 changed files with 85 additions and 56 deletions

View File

@ -39,11 +39,13 @@ import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.TNTListener; import com.intellectualcrafters.plot.listeners.TNTListener;
import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldEvents; import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.ConsoleColors; import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -378,4 +380,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public void registerTNTListener() { public void registerTNTListener() {
getServer().getPluginManager().registerEvents(new TNTListener(), this); getServer().getPluginManager().registerEvents(new TNTListener(), this);
} }
@Override
public void unregister(PlotPlayer player) {
BukkitUtil.removePlayer(player.getName());
}
} }

View File

@ -7,6 +7,7 @@ import net.milkbowl.vault.economy.Economy;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
@ -57,5 +58,7 @@ public interface IPlotMain {
public boolean initPlotMeConverter(); public boolean initPlotMeConverter();
public void unregister(PlotPlayer player);
public ChunkGenerator getGenerator(String world, String name); public ChunkGenerator getGenerator(String world, String name);
} }

View File

@ -550,6 +550,11 @@ public class PlotSquared {
if (Settings.AUTO_CLEAR) { if (Settings.AUTO_CLEAR) {
ExpireManager.runTask(); ExpireManager.runTask();
} }
if (Settings.COMMENT_NOTIFICATION_INTERVAL > 0) {
CommentManager.runTask();
}
// Copy files // Copy files
copyFile("town.template"); copyFile("town.template");
copyFile("skyblock.template"); copyFile("skyblock.template");
@ -780,6 +785,7 @@ public class PlotSquared {
public static void setupConfig() { public static void setupConfig() {
config.set("version", VERSION); config.set("version", VERSION);
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> options = new HashMap<>();
options.put("teleport.delay", 0); options.put("teleport.delay", 0);
options.put("auto_update", false); options.put("auto_update", false);
@ -810,11 +816,10 @@ public class PlotSquared {
options.put("titles", Settings.TITLES); options.put("titles", Settings.TITLES);
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION); options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR); options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR);
options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES); options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES);
options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES); options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES);
options.put("comments.notifications.interval", Settings.COMMENT_NOTIFICATION_INTERVAL);
for (final Entry<String, Object> node : options.entrySet()) { for (final Entry<String, Object> node : options.entrySet()) {
if (!config.contains(node.getKey())) { if (!config.contains(node.getKey())) {
config.set(node.getKey(), node.getValue()); config.set(node.getKey(), node.getValue());
@ -826,7 +831,10 @@ public class PlotSquared {
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
} }
Settings.COMMENT_NOTIFICATION_INTERVAL = config.getInt("comments.notifications.interval");
Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled"); Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled");
Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES = config.getInt("chunk-processor.max-blockstates");
Settings.CHUNK_PROCESSOR_MAX_ENTITIES= config.getInt("chunk-processor.max-entities");
Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled"); Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled");
Settings.PERMISSION_CACHING = config.getBoolean("cache.permissions"); Settings.PERMISSION_CACHING = config.getBoolean("cache.permissions");

View File

@ -387,7 +387,7 @@ public enum C {
/* /*
* PlotMe * PlotMe
*/ */
NOT_USING_PLOTME("$2This server uses the $1PlotSquared $2plot management system. Please use the $1/plots $2instead"), NOT_USING_PLOTME("$2This server uses the $1PlotSquared $2plot management system. Please use the $1/ps &2or $1/p2 $2or $1/plots $2instead"),
/* /*
* Wait * Wait
*/ */

View File

@ -41,6 +41,10 @@ public class Settings {
public static boolean CONVERT_PLOTME = true; public static boolean CONVERT_PLOTME = true;
public static boolean CACHE_PLOTME = false; public static boolean CACHE_PLOTME = false;
public static boolean USE_PLOTME_ALIAS = false; public static boolean USE_PLOTME_ALIAS = false;
/**
* Comment system
*/
public static int COMMENT_NOTIFICATION_INTERVAL = -1;
/** /**
* Chunk processor * Chunk processor
*/ */

View File

@ -519,8 +519,9 @@ public class SQLManager implements AbstractDB {
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?");
stmt.setInt(1, id); stmt.setString(1, world);
stmt.setInt(2, plot.hashCode());
stmt.executeUpdate(); stmt.executeUpdate();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?");
stmt.setInt(1, id); stmt.setInt(1, id);

View File

@ -7,6 +7,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
@ -18,12 +19,10 @@ public class ChunkListener implements Listener {
@EventHandler @EventHandler
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(ChunkUnloadEvent event) {
if (!forceUnload) {
if (processChunk(event.getChunk(), true)) { if (processChunk(event.getChunk(), true)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
}
@EventHandler @EventHandler
public void onChunkLoad(ChunkLoadEvent event) { public void onChunkLoad(ChunkLoadEvent event) {
@ -53,7 +52,7 @@ public class ChunkListener implements Listener {
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
int i = 0; int i = 0;
while (System.currentTimeMillis() - start < 50) { while (System.currentTimeMillis() - start < 250) {
if (i >= tiles.length) { if (i >= tiles.length) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex); TaskManager.tasks.remove(currentIndex);
@ -65,18 +64,22 @@ public class ChunkListener implements Listener {
i++; i++;
} }
} }
}, 1); }, 5);
TaskManager.tasks.put(currentIndex, task); TaskManager.tasks.put(currentIndex, task);
} }
private boolean forceUnload = false;
public boolean processChunk(Chunk chunk, boolean unload) { public boolean processChunk(Chunk chunk, boolean unload) {
if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) {
return false; return false;
} }
Entity[] entities = chunk.getEntities(); Entity[] entities = chunk.getEntities();
BlockState[] tiles = chunk.getTileEntities(); BlockState[] tiles = chunk.getTileEntities();
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
for (Entity ent : entities) {
ent.remove();
}
PlotSquared.log("&aPlotSquared detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
}
if (tiles.length > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) { if (tiles.length > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) {
if (unload) { if (unload) {
PlotSquared.log("&cPlotSquared detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4)); PlotSquared.log("&cPlotSquared detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
@ -87,16 +90,6 @@ public class ChunkListener implements Listener {
tile.getBlock().setType(Material.AIR, false); tile.getBlock().setType(Material.AIR, false);
} }
} }
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
if (unload) {
System.out.print("FORCE UNLOAD");
chunk.load(true);
return false;
}
for (Entity ent : entities) {
ent.remove();
}
}
return false; return false;
} }
} }

View File

@ -92,8 +92,10 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
@ -997,14 +999,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler @EventHandler
public static void onLeave(final PlayerQuitEvent event) { public static void onLeave(final PlayerQuitEvent event) {
final String name = event.getPlayer().getName(); PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
if (SetupUtils.setupMap.containsKey(name)) { EventUtil.unregisterPlayer(pp);
SetupUtils.setupMap.remove(name);
}
CmdConfirm.removePending(name);
BukkitUtil.removePlayer(name);
if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) { if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) {
final Collection<Plot> plots = PlotSquared.getPlots(name).values(); final Collection<Plot> plots = PlotSquared.getPlots(pp.getName()).values();
for (final Plot plot : plots) { for (final Plot plot : plots) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world);
final PlotManager manager = PlotSquared.getPlotManager(plot.world); final PlotManager manager = PlotSquared.getPlotManager(plot.world);

View File

@ -19,7 +19,6 @@ public class BukkitPlayer implements PlotPlayer {
public HashSet<String> noPerm = new HashSet<>(); public HashSet<String> noPerm = new HashSet<>();
private int op = 0; private int op = 0;
private long last = 0; private long last = 0;
private HashMap<String, Object> tmpData = null;
/** /**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. * Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
@ -120,21 +119,4 @@ public class BukkitPlayer implements PlotPlayer {
public Location getLocationFull() { public Location getLocationFull() {
return BukkitUtil.getLocationFull(this.player); return BukkitUtil.getLocationFull(this.player);
} }
@Override
public void setTmpData(String key, Object value) {
if (tmpData == null) {
tmpData = new HashMap<>();
}
tmpData.put(key, value);
}
@Override
public Object getTmpData(String key) {
if (tmpData == null) {
return null;
}
return tmpData.get(key);
}
} }

View File

@ -9,10 +9,6 @@ import java.util.UUID;
*/ */
public interface PlotPlayer { public interface PlotPlayer {
public void setTmpData(String key, Object value);
public Object getTmpData(String key);
public long getPreviousLogin(); public long getPreviousLogin();
public Location getLocation(); public Location getLocation();

View File

@ -2,10 +2,39 @@ package com.intellectualcrafters.plot.object.comment;
import java.util.HashMap; import java.util.HashMap;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.TaskManager;
public class CommentManager { public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>(); public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
private static HashMap<String, Long> timestamps = new HashMap<>();
public static void runTask() {
// TaskManager.runTaskRepeat(new Runnable() {
//
// @Override
// public void run() {
//
// }
// }, Settings.COMMENT_NOTIFICATION_INTERVAL * 1200);
}
public static long getTimestamp(PlotPlayer player) {
Long time = timestamps.get(player.getName());
if (time == null) {
time = player.getPreviousLogin();
timestamps.put(player.getName(), time);
}
return time;
}
public static void setTime(PlotPlayer player) {
timestamps.put(player.getName(), System.currentTimeMillis());
}
public static void addInbox(CommentInbox inbox) { public static void addInbox(CommentInbox inbox) {
inboxes.put(inbox.toString().toLowerCase(), inbox); inboxes.put(inbox.toString().toLowerCase(), inbox);
} }

View File

@ -1,7 +1,5 @@
package com.intellectualcrafters.plot.object.comment; package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotHandler;

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -13,6 +14,15 @@ public abstract class EventUtil {
public static EventUtil manager = null; public static EventUtil manager = null;
public static void unregisterPlayer(PlotPlayer player) {
String name = player.getName();
if (SetupUtils.setupMap.containsKey(name)) {
SetupUtils.setupMap.remove(name);
}
CmdConfirm.removePending(name);
PlotSquared.IMP.unregister(player);
}
public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto); public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto);
public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot); public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot);