From bfd4b5c7b8bdca03365e2582db3942f6058802f7 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 7 Oct 2014 12:29:50 +0200 Subject: [PATCH] MStore fixes and don't confuse same priority with equality. --- .../massivecore/MassiveCoreMConfColl.java | 7 ---- .../massivecore/PriorityComparator.java | 10 +++++- .../ReversePriorityComparator.java | 10 +++++- .../massivecraft/massivecore/store/Coll.java | 35 ++++++++----------- .../massivecore/store/CollInterface.java | 4 ++- .../massivecore/store/Entity.java | 2 +- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/massivecraft/massivecore/MassiveCoreMConfColl.java b/src/main/java/com/massivecraft/massivecore/MassiveCoreMConfColl.java index 3167dabf..5c35a83a 100644 --- a/src/main/java/com/massivecraft/massivecore/MassiveCoreMConfColl.java +++ b/src/main/java/com/massivecraft/massivecore/MassiveCoreMConfColl.java @@ -28,11 +28,4 @@ public class MassiveCoreMConfColl extends Coll MassiveCoreMConf.i = this.get(MassiveCore.INSTANCE, true); } - @Override - public synchronized void loadFromRemote(Object oid) - { - super.loadFromRemote(oid); - if ( ! this.inited()) return; - } - } diff --git a/src/main/java/com/massivecraft/massivecore/PriorityComparator.java b/src/main/java/com/massivecraft/massivecore/PriorityComparator.java index 26651112..58c76704 100644 --- a/src/main/java/com/massivecraft/massivecore/PriorityComparator.java +++ b/src/main/java/com/massivecraft/massivecore/PriorityComparator.java @@ -22,7 +22,15 @@ public class PriorityComparator implements Comparator if (two == null) return 1; if (one == null) return -1; - return Integer.valueOf(one.getPriority()).compareTo(two.getPriority()); + int ret = Integer.valueOf(one.getPriority()).compareTo(two.getPriority()); + + // We should only return 0 if the items actually are equal. + if (ret == 0 && ! one.equals(two)) + { + ret = two.hashCode() - one.hashCode(); + } + + return ret; } } diff --git a/src/main/java/com/massivecraft/massivecore/ReversePriorityComparator.java b/src/main/java/com/massivecraft/massivecore/ReversePriorityComparator.java index c00aa50c..23eaf904 100644 --- a/src/main/java/com/massivecraft/massivecore/ReversePriorityComparator.java +++ b/src/main/java/com/massivecraft/massivecore/ReversePriorityComparator.java @@ -22,7 +22,15 @@ public class ReversePriorityComparator implements Comparator if (two == null) return -1; if (one == null) return 1; - return Integer.valueOf(two.getPriority()).compareTo(one.getPriority()); + int ret = Integer.valueOf(two.getPriority()).compareTo(one.getPriority()); + + // We should only return 0 if the items actually are equal. + if (ret == 0 && ! one.equals(two)) + { + ret = one.hashCode() - two.hashCode(); + } + + return ret; } } diff --git a/src/main/java/com/massivecraft/massivecore/store/Coll.java b/src/main/java/com/massivecraft/massivecore/store/Coll.java index f7073e72..c2911ea2 100644 --- a/src/main/java/com/massivecraft/massivecore/store/Coll.java +++ b/src/main/java/com/massivecraft/massivecore/store/Coll.java @@ -566,33 +566,27 @@ public class Coll implements CollInterface } } + @SuppressWarnings("unchecked") @Override - public synchronized void loadFromRemote(Object oid) + public synchronized void loadFromRemote(Object oid, Entry entry, boolean entrySupplied) { if (oid == null) throw new NullPointerException("oid"); String id = this.fixId(oid); this.clearIdentifiedChanges(id); - Entry entry = null; - try + if ( ! entrySupplied) { - entry = this.getDriver().load(this, id); + try + { + entry = this.getDriver().load(this, id); + } + catch (Exception e) + { + logLoadError(id, e.getMessage()); + return; + } } - catch (Exception e) - { - logLoadError(id, e.getMessage()); - return; - } - - loadFromRemote(id, entry); - } - - @SuppressWarnings("unchecked") - private void loadFromRemote(Object oid, Entry entry) - { - if (oid == null) throw new NullPointerException("oid"); - String id = this.fixId(oid); if (entry == null) { @@ -773,7 +767,7 @@ public class Coll implements CollInterface break; case REMOTE_ALTER: case REMOTE_ATTACH: - this.loadFromRemote(id); + this.loadFromRemote(id, null, false); if (this.inited()) { this.addSyncCount(TOTAL, true); @@ -860,7 +854,7 @@ public class Coll implements CollInterface { String id = idToEntry.getKey(); Entry entry = idToEntry.getValue(); - loadFromRemote(id, entry); + loadFromRemote(id, entry, true); } } @@ -949,6 +943,7 @@ public class Coll implements CollInterface if (this.inited()) return; this.initLoadAllFromRemote(); + // this.syncAll(); name2instance.put(this.getName(), this); } diff --git a/src/main/java/com/massivecraft/massivecore/store/CollInterface.java b/src/main/java/com/massivecraft/massivecore/store/CollInterface.java index 6fb9fbe5..f8975b91 100644 --- a/src/main/java/com/massivecraft/massivecore/store/CollInterface.java +++ b/src/main/java/com/massivecraft/massivecore/store/CollInterface.java @@ -4,10 +4,12 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.bukkit.plugin.Plugin; import com.massivecraft.massivecore.Predictate; +import com.massivecraft.massivecore.xlib.gson.JsonElement; public interface CollInterface { @@ -131,7 +133,7 @@ public interface CollInterface public E removeAtLocal(Object oid); public void removeAtRemote(Object oid); public void saveToRemote(Object oid); - public void loadFromRemote(Object oid); + public void loadFromRemote(Object oid, Entry entry, boolean entrySupplied); // -------------------------------------------- // // SYNC EXAMINE AND DO diff --git a/src/main/java/com/massivecraft/massivecore/store/Entity.java b/src/main/java/com/massivecraft/massivecore/store/Entity.java index 1db7b894..d52b085c 100644 --- a/src/main/java/com/massivecraft/massivecore/store/Entity.java +++ b/src/main/java/com/massivecraft/massivecore/store/Entity.java @@ -134,7 +134,7 @@ public abstract class Entity> implements Comparable String id = this.getId(); if (id == null) return; - this.getColl().loadFromRemote(id); + this.getColl().loadFromRemote(id, null, false); } // -------------------------------------------- //