From 86ddbdcf15a868844cf624f8aed285212c13536f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 13 Mar 2015 12:58:58 +0100 Subject: [PATCH] Random possibly required security --- .../massivecraft/massivecore/MassiveCore.java | 4 ++++ src/com/massivecraft/massivecore/store/Coll.java | 12 ++++++++---- .../massivecore/store/CollInterface.java | 2 +- src/com/massivecraft/massivecore/util/MUtil.java | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/com/massivecraft/massivecore/MassiveCore.java b/src/com/massivecraft/massivecore/MassiveCore.java index cb9d03d7..bb9c6cbc 100644 --- a/src/com/massivecraft/massivecore/MassiveCore.java +++ b/src/com/massivecraft/massivecore/MassiveCore.java @@ -49,6 +49,7 @@ import com.massivecraft.massivecore.teleport.EngineScheduledTeleport; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.PlayerUtil; +import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.Gson; import com.massivecraft.massivecore.xlib.gson.GsonBuilder; @@ -158,6 +159,9 @@ public class MassiveCore extends MassivePlugin if ( ! preEnable()) return; + // TODO: This seems to fix most race conditions within the class asynchronous class loader. + System.out.println("TimeUnit.MILLIS_PER_MINUTE: " + TimeUnit.MILLIS_PER_MINUTE); + // Load Server Config ConfServer.get().load(); diff --git a/src/com/massivecraft/massivecore/store/Coll.java b/src/com/massivecraft/massivecore/store/Coll.java index b9064f24..5452a1be 100644 --- a/src/com/massivecraft/massivecore/store/Coll.java +++ b/src/com/massivecraft/massivecore/store/Coll.java @@ -440,7 +440,7 @@ public class Coll implements CollInterface protected Map identifiedModifications; - protected void removeIdentifiedModification(Object oid) + protected synchronized void removeIdentifiedModification(Object oid) { if (oid == null) throw new NullPointerException("oid"); String id = this.fixId(oid); @@ -839,12 +839,16 @@ public class Coll implements CollInterface } @Override - public void syncIdentified() + public void syncIdentified(boolean safe) { for (Entry entry : this.identifiedModifications.entrySet()) { String id = entry.getKey(); Modification modification = entry.getValue(); + if (safe) + { + modification = null; + } this.syncId(id, modification); } } @@ -853,7 +857,7 @@ public class Coll implements CollInterface public void syncAll() { this.identifyModifications(); - this.syncIdentified(); + this.syncIdentified(false); } @Override @@ -879,7 +883,7 @@ public class Coll implements CollInterface @Override public void onTick() { - this.syncIdentified(); + this.syncIdentified(true); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/store/CollInterface.java b/src/com/massivecraft/massivecore/store/CollInterface.java index 87402739..e2f85177 100644 --- a/src/com/massivecraft/massivecore/store/CollInterface.java +++ b/src/com/massivecraft/massivecore/store/CollInterface.java @@ -140,7 +140,7 @@ public interface CollInterface public Modification syncId(Object oid); public Modification syncId(Object oid, Modification modificationState); public Modification syncId(Object oid, Modification modificationState, Entry remoteEntry); - public void syncIdentified(); + public void syncIdentified(boolean safe); public void syncAll(); public void identifyModifications(); public void initLoadAllFromRemote(); diff --git a/src/com/massivecraft/massivecore/util/MUtil.java b/src/com/massivecraft/massivecore/util/MUtil.java index eb91749e..390a8145 100644 --- a/src/com/massivecraft/massivecore/util/MUtil.java +++ b/src/com/massivecraft/massivecore/util/MUtil.java @@ -373,6 +373,22 @@ public class MUtil list.addAll(repeat(object, length - list.size())); } + // -------------------------------------------- // + // MAP OPERATIONS + // -------------------------------------------- // + + public static void keepLeft(Map map, int maxSize) + { + int i = 0; + Iterator iter = map.entrySet().iterator(); + while (iter.hasNext()) + { + iter.next(); + i++; + if (i > maxSize) iter.remove(); + } + } + // -------------------------------------------- // // ITERABLE MATH // -------------------------------------------- //