diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 4e2abc5c9..e3cb41578 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -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()); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index fce6ee906..907cb05ec 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -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); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index e9ca0d807..6279999e2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -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 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 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"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index abee75367..9485dbb5c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -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 */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index ca7fbbbcc..857ca68fc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -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 */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 1c8c0fece..6c7b3e9bd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -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); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java index dda9e29fe..e6a9da956 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java @@ -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; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index b821783a5..da9238f94 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -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 plots = PlotSquared.getPlots(name).values(); + final Collection 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); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index dd1594ebe..3dd04a064 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -19,7 +19,6 @@ public class BukkitPlayer implements PlotPlayer { public HashSet noPerm = new HashSet<>(); private int op = 0; private long last = 0; - private HashMap 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); - } - } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 24776994e..cb75aa726 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -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(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java index 2bad8e179..baf427a02 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java @@ -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 inboxes = new HashMap<>(); + private static HashMap 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()); } -} +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java index f2af870b7..e80e1f31a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java @@ -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; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 560493dfc..9d0a07469 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -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);