From 4367e3a36acab93e2514dc5d456f6ced1b1c186e Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sat, 10 Mar 2012 16:17:29 -0800 Subject: [PATCH] [Version 0.7.6] - Moved gate opening/closing to a Queue/Runnable system to resolve server lag issues with very large gates --- README | 2 ++ src/net/TheDgtl/Stargate/BloxPopulator.java | 28 +++++++++++++++++++++ src/net/TheDgtl/Stargate/Portal.java | 6 +++-- src/net/TheDgtl/Stargate/Stargate.java | 17 +++++++++++++ src/plugin.yml | 2 +- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/net/TheDgtl/Stargate/BloxPopulator.java diff --git a/README b/README index 13e92e4..6e235af 100644 --- a/README +++ b/README @@ -202,6 +202,8 @@ createConflict=Gate conflicts with existing gate ============= Changes ============= +[Version 0.7.6] + - Moved gate opening/closing to a Queue/Runnable system to resolve server lag issues with very large gates [Version 0.7.5.11] - PEX now returns accurate results without requiring use of the bridge. [Version 0.7.5.10] diff --git a/src/net/TheDgtl/Stargate/BloxPopulator.java b/src/net/TheDgtl/Stargate/BloxPopulator.java new file mode 100644 index 0000000..983ff53 --- /dev/null +++ b/src/net/TheDgtl/Stargate/BloxPopulator.java @@ -0,0 +1,28 @@ +package net.TheDgtl.Stargate; + +public class BloxPopulator { + private Blox blox; + private int nextMat; + + public BloxPopulator(Blox b, int m) { + blox = b; + nextMat = m; + } + + public void setBlox(Blox b) { + blox = b; + } + + public void setMat(int m) { + nextMat = m; + } + + public Blox getBlox() { + return blox; + } + + public int getMat() { + return nextMat; + } + +} diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 280de54..69411ca 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -320,8 +320,9 @@ public class Portal { getWorld().loadChunk(getWorld().getChunkAt(topLeft.getBlock())); + int openType = gate.getPortalBlockOpen(); for (Blox inside : getEntrances()) { - inside.setType(gate.getPortalBlockOpen()); + Stargate.blockPopulatorQueue.add(new BloxPopulator(inside, openType)); } isOpen = true; @@ -356,8 +357,9 @@ public class Portal { if (isAlwaysOn() && !force) return; // Only close always-open if forced // Close this gate, then the dest gate. + int closedType = gate.getPortalBlockClosed(); for (Blox inside : getEntrances()) { - inside.setType(gate.getPortalBlockClosed()); + Stargate.blockPopulatorQueue.add(new BloxPopulator(inside, closedType)); } player = null; diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 7c1e8a4..1ea174f 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -2,6 +2,8 @@ package net.TheDgtl.Stargate; import java.io.File; import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import java.util.logging.Logger; @@ -103,6 +105,9 @@ public class Stargate extends JavaPlugin { public static ConcurrentLinkedQueue openList = new ConcurrentLinkedQueue(); public static ConcurrentLinkedQueue activeList = new ConcurrentLinkedQueue(); + // Used for populating gate open/closed material. + public static Queue blockPopulatorQueue = new LinkedList(); + public void onDisable() { Portal.closeAllGates(); Portal.clearGates(); @@ -152,6 +157,7 @@ public class Stargate extends JavaPlugin { } getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); + getServer().getScheduler().scheduleSyncRepeatingTask(this, new BlockPopulatorThread(), 0L, 1L); } public void loadConfig() { @@ -1129,6 +1135,17 @@ public class Stargate extends JavaPlugin { } } + private class BlockPopulatorThread implements Runnable { + public void run() { + long sTime = System.nanoTime(); + while (System.nanoTime() - sTime < 50000000) { + BloxPopulator b = Stargate.blockPopulatorQueue.poll(); + if (b == null) return; + b.getBlox().getBlock().setTypeId(b.getMat()); + } + } + } + private class SGThread implements Runnable { public void run() { long time = System.currentTimeMillis() / 1000; diff --git a/src/plugin.yml b/src/plugin.yml index c068823..620ec77 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.5.11 +version: 0.7.6.0 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net