MStore fixes and don't confuse same priority with equality.

This commit is contained in:
Olof Larsson 2014-10-07 12:29:50 +02:00
parent 43ec0d3eb1
commit bfd4b5c7b8
6 changed files with 37 additions and 31 deletions

View File

@ -28,11 +28,4 @@ public class MassiveCoreMConfColl extends Coll<MassiveCoreMConf>
MassiveCoreMConf.i = this.get(MassiveCore.INSTANCE, true); MassiveCoreMConf.i = this.get(MassiveCore.INSTANCE, true);
} }
@Override
public synchronized void loadFromRemote(Object oid)
{
super.loadFromRemote(oid);
if ( ! this.inited()) return;
}
} }

View File

@ -22,7 +22,15 @@ public class PriorityComparator implements Comparator<Prioritized>
if (two == null) return 1; if (two == null) return 1;
if (one == 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;
} }
} }

View File

@ -22,7 +22,15 @@ public class ReversePriorityComparator implements Comparator<Prioritized>
if (two == null) return -1; if (two == null) return -1;
if (one == 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;
} }
} }

View File

@ -566,15 +566,17 @@ public class Coll<E> implements CollInterface<E>
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public synchronized void loadFromRemote(Object oid) public synchronized void loadFromRemote(Object oid, Entry<JsonElement, Long> entry, boolean entrySupplied)
{ {
if (oid == null) throw new NullPointerException("oid"); if (oid == null) throw new NullPointerException("oid");
String id = this.fixId(oid); String id = this.fixId(oid);
this.clearIdentifiedChanges(id); this.clearIdentifiedChanges(id);
Entry<JsonElement, Long> entry = null; if ( ! entrySupplied)
{
try try
{ {
entry = this.getDriver().load(this, id); entry = this.getDriver().load(this, id);
@ -584,16 +586,8 @@ public class Coll<E> implements CollInterface<E>
logLoadError(id, e.getMessage()); logLoadError(id, e.getMessage());
return; return;
} }
loadFromRemote(id, entry);
} }
@SuppressWarnings("unchecked")
private void loadFromRemote(Object oid, Entry<JsonElement, Long> entry)
{
if (oid == null) throw new NullPointerException("oid");
String id = this.fixId(oid);
if (entry == null) if (entry == null)
{ {
logLoadError(id, "MStore driver could not load data entry. The file might not be readable or simply not exist."); logLoadError(id, "MStore driver could not load data entry. The file might not be readable or simply not exist.");
@ -773,7 +767,7 @@ public class Coll<E> implements CollInterface<E>
break; break;
case REMOTE_ALTER: case REMOTE_ALTER:
case REMOTE_ATTACH: case REMOTE_ATTACH:
this.loadFromRemote(id); this.loadFromRemote(id, null, false);
if (this.inited()) if (this.inited())
{ {
this.addSyncCount(TOTAL, true); this.addSyncCount(TOTAL, true);
@ -860,7 +854,7 @@ public class Coll<E> implements CollInterface<E>
{ {
String id = idToEntry.getKey(); String id = idToEntry.getKey();
Entry<JsonElement, Long> entry = idToEntry.getValue(); Entry<JsonElement, Long> entry = idToEntry.getValue();
loadFromRemote(id, entry); loadFromRemote(id, entry, true);
} }
} }
@ -949,6 +943,7 @@ public class Coll<E> implements CollInterface<E>
if (this.inited()) return; if (this.inited()) return;
this.initLoadAllFromRemote(); this.initLoadAllFromRemote();
// this.syncAll();
name2instance.put(this.getName(), this); name2instance.put(this.getName(), this);
} }

View File

@ -4,10 +4,12 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.massivecore.Predictate; import com.massivecraft.massivecore.Predictate;
import com.massivecraft.massivecore.xlib.gson.JsonElement;
public interface CollInterface<E> public interface CollInterface<E>
{ {
@ -131,7 +133,7 @@ public interface CollInterface<E>
public E removeAtLocal(Object oid); public E removeAtLocal(Object oid);
public void removeAtRemote(Object oid); public void removeAtRemote(Object oid);
public void saveToRemote(Object oid); public void saveToRemote(Object oid);
public void loadFromRemote(Object oid); public void loadFromRemote(Object oid, Entry<JsonElement, Long> entry, boolean entrySupplied);
// -------------------------------------------- // // -------------------------------------------- //
// SYNC EXAMINE AND DO // SYNC EXAMINE AND DO

View File

@ -134,7 +134,7 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
String id = this.getId(); String id = this.getId();
if (id == null) return; if (id == null) return;
this.getColl().loadFromRemote(id); this.getColl().loadFromRemote(id, null, false);
} }
// -------------------------------------------- // // -------------------------------------------- //