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.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
@ -378,4 +380,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public void registerTNTListener() {
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 com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil;
@ -56,6 +57,8 @@ public interface IPlotMain {
public UUIDWrapper initUUIDHandler();
public boolean initPlotMeConverter();
public void unregister(PlotPlayer player);
public ChunkGenerator getGenerator(String world, String name);
}

View File

@ -550,6 +550,11 @@ public class PlotSquared {
if (Settings.AUTO_CLEAR) {
ExpireManager.runTask();
}
if (Settings.COMMENT_NOTIFICATION_INTERVAL > 0) {
CommentManager.runTask();
}
// Copy files
copyFile("town.template");
copyFile("skyblock.template");
@ -780,6 +785,7 @@ public class PlotSquared {
public static void setupConfig() {
config.set("version", VERSION);
final Map<String, Object> options = new HashMap<>();
options.put("teleport.delay", 0);
options.put("auto_update", false);
@ -810,11 +816,10 @@ public class PlotSquared {
options.put("titles", Settings.TITLES);
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION);
options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR);
options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES);
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()) {
if (!config.contains(node.getKey())) {
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.");
}
Settings.COMMENT_NOTIFICATION_INTERVAL = config.getInt("comments.notifications.interval");
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.PERMISSION_CACHING = config.getBoolean("cache.permissions");

View File

@ -387,7 +387,7 @@ public enum C {
/*
* 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
*/

View File

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

View File

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

View File

@ -7,6 +7,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
@ -18,13 +19,11 @@ public class ChunkListener implements Listener {
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
if (!forceUnload) {
if (processChunk(event.getChunk(), true)) {
event.setCancelled(true);
}
if (processChunk(event.getChunk(), true)) {
event.setCancelled(true);
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
processChunk(event.getChunk(), false);
@ -53,7 +52,7 @@ public class ChunkListener implements Listener {
}
long start = System.currentTimeMillis();
int i = 0;
while (System.currentTimeMillis() - start < 50) {
while (System.currentTimeMillis() - start < 250) {
if (i >= tiles.length) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
@ -65,18 +64,22 @@ public class ChunkListener implements Listener {
i++;
}
}
}, 1);
}, 5);
TaskManager.tasks.put(currentIndex, task);
}
private boolean forceUnload = false;
public boolean processChunk(Chunk chunk, boolean unload) {
if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) {
return false;
}
Entity[] entities = chunk.getEntities();
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 (unload) {
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);
}
}
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;
}
}

View File

@ -92,8 +92,10 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetupUtils;
@ -997,14 +999,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler
public static void onLeave(final PlayerQuitEvent event) {
final String name = event.getPlayer().getName();
if (SetupUtils.setupMap.containsKey(name)) {
SetupUtils.setupMap.remove(name);
}
CmdConfirm.removePending(name);
BukkitUtil.removePlayer(name);
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
EventUtil.unregisterPlayer(pp);
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) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(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<>();
private int op = 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.
@ -120,21 +119,4 @@ public class BukkitPlayer implements PlotPlayer {
public Location getLocationFull() {
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 void setTmpData(String key, Object value);
public Object getTmpData(String key);
public long getPreviousLogin();
public Location getLocation();

View File

@ -2,10 +2,39 @@ package com.intellectualcrafters.plot.object.comment;
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 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) {
inboxes.put(inbox.toString().toLowerCase(), inbox);
}
@ -15,4 +44,4 @@ public class CommentManager {
addInbox(new InboxPublic());
addInbox(new InboxOwner());
}
}
}

View File

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

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -13,6 +14,15 @@ public abstract class EventUtil {
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 callTeleport(final PlotPlayer player, Location from, final Plot plot);