diff --git a/src/com/massivecraft/mcore/MCoreConfColl.java b/src/com/massivecraft/mcore/MCoreConfColl.java index 2dedc61c..f04836d6 100644 --- a/src/com/massivecraft/mcore/MCoreConfColl.java +++ b/src/com/massivecraft/mcore/MCoreConfColl.java @@ -14,7 +14,7 @@ public class MCoreConfColl extends Coll public static MCoreConfColl get() { return i; } private MCoreConfColl() { - super(MStore.getDb(ConfServer.dburi), MCore.get(), "uuid", "mcore_conf", MCoreConf.class, true); + super("mcore_conf", MCoreConf.class, MStore.getDb(ConfServer.dburi), MCore.get(), true, false); } // -------------------------------------------- // diff --git a/src/com/massivecraft/mcore/store/Coll.java b/src/com/massivecraft/mcore/store/Coll.java index e60f1f84..1cc6fbb1 100644 --- a/src/com/massivecraft/mcore/store/Coll.java +++ b/src/com/massivecraft/mcore/store/Coll.java @@ -130,18 +130,35 @@ public class Coll implements CollInterface public String fixId(Object oid) { if (oid == null) return null; - if (oid instanceof String) return (String)oid; - if (oid.getClass() == this.entityClass) return this.entity2id.get(oid); - return null; + + String ret = null; + if (oid instanceof String) + { + ret = (String)oid; + } + else if (oid.getClass() == this.entityClass) + { + ret = this.entity2id.get(oid); + } + if (ret == null) return null; + + return this.isLowercasing() ? ret.toLowerCase() : ret; } // -------------------------------------------- // - // BAHAVIOR + // BEHAVIOR // -------------------------------------------- // protected boolean creative; @Override public boolean isCreative() { return this.creative; } - @Override public void setCreative(boolean val) { this.creative = val; } + @Override public void setCreative(boolean creative) { this.creative = creative; } + + // "Lowercasing" means that the ids are always converted to lower case when fixed. + // This is highly recommended for sender colls. + // The senderIds are case insensitive by nature and some times you simply can't know the correct casing. + protected boolean lowercasing; + @Override public boolean isLowercasing() { return this.lowercasing; } + @Override public void setLowercasing(boolean lowercasing) { this.lowercasing = lowercasing; } // Should that instance be saved or not? // If it is default it should not be saved. @@ -589,7 +606,7 @@ public class Coll implements CollInterface // CONSTRUCT // -------------------------------------------- // - public Coll(Db db, Plugin plugin, String idStrategyName, String name, Class entityClass, boolean creative, Comparator idComparator, Comparator entityComparator) + public Coll(String name, Class entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, String idStrategyName, Comparator idComparator, Comparator entityComparator) { // Setup the name and the parsed parts this.name = name; @@ -607,6 +624,7 @@ public class Coll implements CollInterface // WHAT DO WE HANDLE? this.entityClass = entityClass; this.creative = creative; + this.lowercasing = lowercasing; // SUPPORTING SYSTEM this.plugin = plugin; @@ -645,14 +663,14 @@ public class Coll implements CollInterface }; } - public Coll(Db db, Plugin plugin, String idStrategyName, String name, Class entityClass, boolean creative) + public Coll(String name, Class entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing) { - this(db, plugin, idStrategyName, name, entityClass, creative, null, null); + this(name, entityClass, db, plugin, creative, lowercasing, "uuid", null, null); } - public Coll(Plugin plugin, String idStrategyName, String name, Class entityClass, boolean creative) + public Coll(String name, Class entityClass, Db db, Plugin plugin) { - this(MCore.getDb(), plugin, idStrategyName, name, entityClass, creative); + this(name, entityClass, db, plugin, false, false); } @Override diff --git a/src/com/massivecraft/mcore/store/CollInterface.java b/src/com/massivecraft/mcore/store/CollInterface.java index c9fc1fd5..6b10016e 100644 --- a/src/com/massivecraft/mcore/store/CollInterface.java +++ b/src/com/massivecraft/mcore/store/CollInterface.java @@ -53,11 +53,15 @@ public interface CollInterface public String fixId(Object oid); // -------------------------------------------- // - // BAHAVIOR + // BEHAVIOR // -------------------------------------------- // + public boolean isCreative(); public void setCreative(boolean val); + public boolean isLowercasing(); + public void setLowercasing(boolean val); + // A default entity will not be saved. // This is often used together with creative collections to save disc space. public boolean isDefault(E entity); diff --git a/src/com/massivecraft/mcore/store/SenderColl.java b/src/com/massivecraft/mcore/store/SenderColl.java index 6acdb0d3..1333a0ef 100644 --- a/src/com/massivecraft/mcore/store/SenderColl.java +++ b/src/com/massivecraft/mcore/store/SenderColl.java @@ -14,24 +14,10 @@ import com.massivecraft.mcore.util.MUtil; public class SenderColl> extends Coll implements SenderIdSource { - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static boolean DEFAULT_LOWERCASING = true; - public final static boolean DEFAULT_CREATIVE = true; - // -------------------------------------------- // // FIELDS // -------------------------------------------- // - // "Lowercasing" means that the ids are always converted to lower case when fixed. - // This is highly recommended for sender colls. - // The senderIds are case insensitive by nature and some times you simply can't know the correct casing. - - protected boolean lowercasing; - public boolean isLowercasing() { return this.lowercasing; } - protected final SenderIdSource mixinedIdSource = new SenderIdSourceCombined(this, SenderIdSourceMixinAllSenderIds.get()); public SenderIdSource getMixinedIdSource() { return this.mixinedIdSource; } @@ -39,25 +25,19 @@ public class SenderColl> extends Coll implements Se // CONSTRUCT // -------------------------------------------- // - public SenderColl(Db db, Plugin plugin, String name, Class entityClass, boolean creative, boolean lowercasing, Comparator idComparator, Comparator entityComparator) + public SenderColl(String name, Class entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, String idStrategyName, Comparator idComparator, Comparator entityComparator) { - super(db, plugin, "uuid", name, entityClass, creative, idComparator, entityComparator); - this.lowercasing = lowercasing; + super(name, entityClass, db, plugin, creative, lowercasing, idStrategyName, idComparator, entityComparator); } - public SenderColl(Db db, Plugin plugin, String name, Class entityClass, boolean creative, boolean lowercasing) - { - this(db, plugin, name, entityClass, creative, lowercasing, null, null); + public SenderColl(String name, Class entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing) + { + super(name, entityClass, db, plugin, creative, lowercasing); } - public SenderColl(Db db, Plugin plugin, String name, Class entityClass, boolean creative) - { - this(db, plugin, name, entityClass, creative, DEFAULT_LOWERCASING); - } - - public SenderColl(Db db, Plugin plugin, String name, Class entityClass) - { - this(db, plugin, name, entityClass, DEFAULT_CREATIVE); + public SenderColl(String name, Class entityClass, Db db, Plugin plugin) + { + super(name, entityClass, db, plugin, true, true); } // -------------------------------------------- // @@ -87,9 +67,24 @@ public class SenderColl> extends Coll implements Se public String fixId(Object oid) { if (oid == null) return null; - String ret = MUtil.extract(String.class, "senderId", oid); - if (ret == null) return ret; - return this.lowercasing ? ret.toLowerCase() : ret; + + String ret = null; + if (oid instanceof String) + { + ret = (String)oid; + } + else if (oid.getClass() == this.entityClass) + { + ret = this.entity2id.get(oid); + } + else + { + ret = MUtil.extract(String.class, "senderId", oid); + } + + if (ret == null) return null; + + return this.isLowercasing() ? ret.toLowerCase() : ret; } public Collection getAllOnline() diff --git a/src/com/massivecraft/mcore/usys/AspectColl.java b/src/com/massivecraft/mcore/usys/AspectColl.java index 55c7aa76..78448e20 100644 --- a/src/com/massivecraft/mcore/usys/AspectColl.java +++ b/src/com/massivecraft/mcore/usys/AspectColl.java @@ -5,6 +5,7 @@ import java.util.List; import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.MStore; public class AspectColl extends Coll { @@ -16,7 +17,7 @@ public class AspectColl extends Coll public static AspectColl get() { return i; } private AspectColl() { - super(MCore.get(), "uuid", "mcore_aspect", Aspect.class, false); + super("mcore_aspect", Aspect.class, MStore.getDb("default"), MCore.get()); } // -------------------------------------------- // diff --git a/src/com/massivecraft/mcore/usys/MultiverseColl.java b/src/com/massivecraft/mcore/usys/MultiverseColl.java index 8fab3f60..f611a9d1 100644 --- a/src/com/massivecraft/mcore/usys/MultiverseColl.java +++ b/src/com/massivecraft/mcore/usys/MultiverseColl.java @@ -2,6 +2,7 @@ package com.massivecraft.mcore.usys; import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.store.Coll; +import com.massivecraft.mcore.store.MStore; public class MultiverseColl extends Coll { @@ -13,7 +14,7 @@ public class MultiverseColl extends Coll public static MultiverseColl get() { return i; } private MultiverseColl() { - super(MCore.get(), "uuid", "mcore_multiverse", Multiverse.class, false); + super("mcore_multiverse", Multiverse.class, MStore.getDb("default"), MCore.get()); } // -------------------------------------------- //