From 9b95990ba60181bc1252b61b651e51e7e67a8f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 4 Aug 2016 16:50:37 +0200 Subject: [PATCH 1/7] Update this here as well --- Bukkit/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 5b759bf95..83d6b2443 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -1,7 +1,7 @@ repositories { maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"} maven { url = "https://oss.sonatype.org/content/repositories/snapshots/"} - maven {url "http://nexus.theyeticave.net/content/repositories/pub_releases"} + maven {url "http://nexus.hc.to/content/repositories/pub_releases"} } dependencies { @@ -39,4 +39,4 @@ shadowJar.doLast { ant.checksum file: task.archivePath } -build.dependsOn(shadowJar); \ No newline at end of file +build.dependsOn(shadowJar); From f408ac82be0f7186c58963cc794b081400b39e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 5 Aug 2016 12:13:39 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d8819242..e5b160d35 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ is to provide a lag-free and smooth experience. ### Developer Resources * [JavaDocs] Link Temporarily Unavailable -* [Build Server] Link Temporarily Unavailable +* [Build Server] [![Build Status](http://ci.plotsquared.com/buildStatus/icon?job=PlotSquared)](http://ci.plotsquared.com/job/PlotSquared) * [Maven Repo] Link Temporarily Unavailable # Building From c99dd1e74aae450c2a3c24087155285c195fd587 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 6 Aug 2016 00:10:11 +1000 Subject: [PATCH 3/7] Needs sponge builds --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5b160d35..ca459a93a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ is to provide a lag-free and smooth experience. ### Developer Resources * [JavaDocs] Link Temporarily Unavailable -* [Build Server] [![Build Status](http://ci.plotsquared.com/buildStatus/icon?job=PlotSquared)](http://ci.plotsquared.com/job/PlotSquared) +* [Build Server] [![Build Status](http://ci.plotsquared.com/buildStatus/icon?job=PlotSquared)](http://ci.athion.net/job/PlotSquared/) * [Maven Repo] Link Temporarily Unavailable # Building From 1ae694ff5b83ffaff51d66d45499773fbb158902 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 7 Aug 2016 03:52:37 +1000 Subject: [PATCH 4/7] Tweak entity counting --- .../java/com/plotsquared/bukkit/listeners/PlayerEvents.java | 3 +++ .../java/com/plotsquared/bukkit/util/BukkitChunkManager.java | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index cf47f39a6..6297fe1b5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1408,6 +1408,9 @@ public class PlayerEvents extends PlotListener implements Listener { if (cap == Integer.MAX_VALUE) { continue; } + if (cap == 0) { + return false; + } if (mobs == null) { mobs = plot.countEntities(); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index fef2434e0..ba16915b4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -449,9 +449,9 @@ public class BukkitChunkManager extends ChunkManager { boolean doWhole = false; List entities = null; - if (size > 200) { + if (size > 200 && chunks.size() > 200) { entities = world.getEntities(); - if (entities.size() < 16 + size * size / 64) { + if (entities.size() < 16 + size / 8) { doWhole = true; } } From facd43700d48686d071061f41667d969f4ce8388 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 7 Aug 2016 04:00:50 +1000 Subject: [PATCH 5/7] Cache entity count every second --- .../bukkit/listeners/EntitySpawnListener.java | 6 +++--- .../com/plotsquared/bukkit/listeners/PlayerEvents.java | 9 +++++++-- .../com/plotsquared/bukkit/util/BukkitChunkManager.java | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java index 3c1ea45e1..4dedca86d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -22,6 +22,9 @@ public class EntitySpawnListener implements Listener { return; } Plot plot = area.getOwnedPlotAbs(location); + if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { + event.setCancelled(true); + } switch (entity.getType()) { case ENDER_CRYSTAL: if (plot == null) { @@ -34,8 +37,5 @@ public class EntitySpawnListener implements Listener { event.setCancelled(true); } } - if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { - event.setCancelled(true); - } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 6297fe1b5..bd81c5b01 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1409,15 +1409,20 @@ public class PlayerEvents extends PlotListener implements Listener { continue; } if (cap == 0) { - return false; + return true; } if (mobs == null) { mobs = plot.countEntities(); } - if (mobs[i] >= cap) { + if (mobs[i]++ >= cap) { return true; } } + if (mobs != null) { + plot.setMeta("EntityCount", mobs); + plot.setMeta("EntityCountTime", System.currentTimeMillis()); + } + return false; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index ba16915b4..8e008c08c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -425,6 +425,10 @@ public class BukkitChunkManager extends ChunkManager { @Override public int[] countEntities(Plot plot) { + int[] existing = (int[]) plot.getMeta("EntityCount"); + if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) { + return existing; + } PlotArea area = plot.getArea(); World world = BukkitUtil.getWorld(area.worldname); From 395d6364be702558c3c30cbe0273d7e466a41507 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 7 Aug 2016 04:43:41 +1000 Subject: [PATCH 6/7] Cache on fail as well --- .../bukkit/listeners/PlayerEvents.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index bd81c5b01..99eb2cf84 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1414,15 +1414,42 @@ public class PlayerEvents extends PlotListener implements Listener { if (mobs == null) { mobs = plot.countEntities(); } - if (mobs[i]++ >= cap) { + if (mobs[i] >= cap) { + plot.setMeta("EntityCount", mobs); + plot.setMeta("EntityCountTime", System.currentTimeMillis()); return true; } } + for (IntegerFlag flag : flags) { + int i; + switch (flag.getName()) { + case "entity-cap": + i = 0; + break; + case "mob-cap": + i = 3; + break; + case "hostile-cap": + i = 2; + break; + case "animal-cap": + i = 1; + break; + case "vehicle-cap": + i = 4; + break; + case "misc-cap": + i = 5; + break; + default: + i = 0; + } + mobs[i]++; + } if (mobs != null) { plot.setMeta("EntityCount", mobs); plot.setMeta("EntityCountTime", System.currentTimeMillis()); } - return false; } From 91c78407cd82501954460e3eec3fdca06dbf7184 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 7 Aug 2016 11:29:59 +1000 Subject: [PATCH 7/7] Use a queue for expiry --- .../bukkit/listeners/PlayerEvents.java | 52 +++++++++---------- .../plot/util/block/GlobalBlockQueue.java | 2 +- .../plot/util/expiry/ExpireManager.java | 28 ++++++---- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 99eb2cf84..cf08c81da 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1420,33 +1420,33 @@ public class PlayerEvents extends PlotListener implements Listener { return true; } } - for (IntegerFlag flag : flags) { - int i; - switch (flag.getName()) { - case "entity-cap": - i = 0; - break; - case "mob-cap": - i = 3; - break; - case "hostile-cap": - i = 2; - break; - case "animal-cap": - i = 1; - break; - case "vehicle-cap": - i = 4; - break; - case "misc-cap": - i = 5; - break; - default: - i = 0; - } - mobs[i]++; - } if (mobs != null) { + for (IntegerFlag flag : flags) { + int i; + switch (flag.getName()) { + case "entity-cap": + i = 0; + break; + case "mob-cap": + i = 3; + break; + case "hostile-cap": + i = 2; + break; + case "animal-cap": + i = 1; + break; + case "vehicle-cap": + i = 4; + break; + case "misc-cap": + i = 5; + break; + default: + i = 0; + } + mobs[i]++; + } plot.setMeta("EntityCount", mobs); plot.setMeta("EntityCountTime", System.currentTimeMillis()); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/block/GlobalBlockQueue.java b/Core/src/main/java/com/intellectualcrafters/plot/util/block/GlobalBlockQueue.java index 3980335fc..461f30b60 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/block/GlobalBlockQueue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/block/GlobalBlockQueue.java @@ -291,7 +291,7 @@ public class GlobalBlockQueue { if (this.runnables.isEmpty()) { return false; } - final ConcurrentLinkedDeque tmp = new ConcurrentLinkedDeque<>(this.runnables); + final ArrayList tmp = new ArrayList<>(this.runnables); this.runnables.clear(); for (final Runnable runnable : tmp) { runnable.run(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java index a78ca1b5c..c75290f7f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java @@ -18,7 +18,6 @@ import com.intellectualcrafters.plot.object.RunnableVal3; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; - import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; @@ -26,9 +25,9 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Objects; -import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedDeque; public class ExpireManager { @@ -217,7 +216,7 @@ public class ExpireManager { return false; } this.running = 2; - final Set plots = PS.get().getPlots(); + final ConcurrentLinkedDeque plots = new ConcurrentLinkedDeque(PS.get().getPlots()); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { @@ -226,14 +225,12 @@ public class ExpireManager { return; } long start = System.currentTimeMillis(); - Iterator iterator = plots.iterator(); - while (iterator.hasNext() && System.currentTimeMillis() - start < 2) { + while (!plots.isEmpty()) { if (ExpireManager.this.running != 2) { ExpireManager.this.running = 0; return; } - final Plot plot = iterator.next(); - iterator.remove(); + final Plot plot = plots.poll(); PlotArea area = plot.getArea(); final ArrayDeque applicable = new ArrayDeque<>(tasks); final Collection expired = isExpired(applicable, plot); @@ -242,7 +239,13 @@ public class ExpireManager { } for (ExpiryTask expiryTask : expired) { if (!expiryTask.needsAnalysis()) { - expiredTask.run(plot, this, expiryTask.requiresConfirmation()); + expiredTask.run(plot, new Runnable() { + @Override + public void run() { + TaskManager.IMP.taskLaterAsync(this, 1); + } + }, expiryTask.requiresConfirmation()); + return; } } final Runnable task = this; @@ -252,7 +255,12 @@ public class ExpireManager { passesComplexity(changed, expired, new RunnableVal() { @Override public void run(Boolean confirmation) { - expiredTask.run(plot, task, confirmation); + expiredTask.run(plot, new Runnable() { + @Override + public void run() { + TaskManager.IMP.taskLaterAsync(task, 1); + } + }, confirmation); } }, new Runnable() { @Override @@ -280,7 +288,7 @@ public class ExpireManager { }, new Runnable() { @Override public void run() { - task.run(); + TaskManager.IMP.taskLaterAsync(task, 1); } }); } else {