Renaming WCat to USel. Some universe messing around.
This commit is contained in:
parent
4883d0754f
commit
5845a7c19b
@ -30,13 +30,19 @@ public class Coll<E, L> implements CollInterface<E, L>
|
|||||||
// WHAT DO WE HANDLE?
|
// WHAT DO WE HANDLE?
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected String name;
|
protected final String name;
|
||||||
@Override public String name() { return this.name; }
|
@Override public String name() { return this.name; }
|
||||||
|
|
||||||
protected Class<E> entityClass;
|
protected final String nameBase;
|
||||||
|
@Override public String nameBase() { return this.nameBase; }
|
||||||
|
|
||||||
|
protected final String nameUniverse;
|
||||||
|
@Override public String nameUniverse() { return this.nameUniverse; }
|
||||||
|
|
||||||
|
protected final Class<E> entityClass;
|
||||||
@Override public Class<E> entityClass() { return this.entityClass; }
|
@Override public Class<E> entityClass() { return this.entityClass; }
|
||||||
|
|
||||||
protected Class<L> idClass;
|
protected final Class<L> idClass;
|
||||||
@Override public Class<L> idClass() { return this.idClass; }
|
@Override public Class<L> idClass() { return this.idClass; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -525,7 +531,19 @@ public class Coll<E, L> implements CollInterface<E, L>
|
|||||||
|
|
||||||
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
public Coll(Db<?> db, MPlugin mplugin, String idStrategyName, String name, Class<E> entityClass, Class<L> idClass, boolean creative)
|
||||||
{
|
{
|
||||||
|
// Setup the name and the parsed parts
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
String[] nameParts = this.name.split("\\@");
|
||||||
|
this.nameBase = nameParts[0];
|
||||||
|
if (nameParts.length > 1)
|
||||||
|
{
|
||||||
|
this.nameUniverse = nameParts[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.nameUniverse = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.entityClass = entityClass;
|
this.entityClass = entityClass;
|
||||||
this.idClass = idClass;
|
this.idClass = idClass;
|
||||||
this.creative = creative;
|
this.creative = creative;
|
||||||
|
@ -15,6 +15,8 @@ public interface CollInterface<E, L>
|
|||||||
// WHAT DO WE HANDLE?
|
// WHAT DO WE HANDLE?
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
public String name();
|
public String name();
|
||||||
|
public String nameBase();
|
||||||
|
public String nameUniverse();
|
||||||
public Class<E> entityClass();
|
public Class<E> entityClass();
|
||||||
public Class<L> idClass();
|
public Class<L> idClass();
|
||||||
|
|
||||||
|
@ -7,20 +7,39 @@ import com.massivecraft.mcore4.util.MUtil;
|
|||||||
|
|
||||||
public abstract class Colls<C extends Coll<E, L>, E, L>
|
public abstract class Colls<C extends Coll<E, L>, E, L>
|
||||||
{
|
{
|
||||||
public abstract String name();
|
protected Map<String, C> name2coll = new HashMap<String, C>();
|
||||||
public abstract C createColl(String collName);
|
|
||||||
|
|
||||||
public String collNameFromCategory(String category)
|
public abstract C createColl(String name);
|
||||||
|
|
||||||
|
public abstract String getContext();
|
||||||
|
|
||||||
|
public String universeFromWorldName(String worldName)
|
||||||
{
|
{
|
||||||
return this.name() + "_" + category;
|
USel selector = USelColl.i.get(this.getContext());
|
||||||
|
return selector.select(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, C> name2coll = new HashMap<String, C>();
|
|
||||||
public C get(Object worldNameExtractable)
|
public C get(Object worldNameExtractable)
|
||||||
{
|
{
|
||||||
String worldName = MUtil.extract(String.class, "worldName", worldNameExtractable);
|
String worldName = MUtil.extract(String.class, "worldName", worldNameExtractable);
|
||||||
String category = WCatColl.i.get(this.name()).categorize(worldName);
|
return this.getForWorld(worldName);
|
||||||
String collName = this.collNameFromCategory(category);
|
}
|
||||||
|
|
||||||
|
public E get2(Object worldNameExtractable)
|
||||||
|
{
|
||||||
|
C coll = this.get(worldNameExtractable);
|
||||||
|
if (coll == null) return null;
|
||||||
|
return coll.get(worldNameExtractable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public C getForWorld(String worldName)
|
||||||
|
{
|
||||||
|
return this.getForUniverse(this.universeFromWorldName(worldName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public C getForUniverse(String universe)
|
||||||
|
{
|
||||||
|
String collName = this.getContext() + "@" + universe;
|
||||||
|
|
||||||
C ret = this.name2coll.get(collName);
|
C ret = this.name2coll.get(collName);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
@ -31,11 +50,4 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public E get2(Object worldNameExtractable)
|
|
||||||
{
|
|
||||||
C coll = this.get(worldNameExtractable);
|
|
||||||
if (coll == null) return null;
|
|
||||||
return coll.get(worldNameExtractable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,14 @@ public abstract class Entity<E extends Entity<E, L>, L>
|
|||||||
|
|
||||||
public abstract E getDefaultInstance();
|
public abstract E getDefaultInstance();
|
||||||
|
|
||||||
|
public String getUniverse()
|
||||||
|
{
|
||||||
|
Coll<E, L> coll = this.getColl();
|
||||||
|
if (coll == null) return null;
|
||||||
|
|
||||||
|
return coll.nameUniverse();
|
||||||
|
}
|
||||||
|
|
||||||
public L attach(Coll<E, L> coll)
|
public L attach(Coll<E, L> coll)
|
||||||
{
|
{
|
||||||
return coll.attach(getThis());
|
return coll.attach(getThis());
|
||||||
|
@ -8,46 +8,46 @@ import java.util.List;
|
|||||||
import com.massivecraft.mcore4.util.MUtil;
|
import com.massivecraft.mcore4.util.MUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WCat stands for World Categorizer.
|
* USel stands for "Universe Selector".
|
||||||
* They provide a recursive matching system.
|
* The task of a USel is to select a "universe" based on a world.
|
||||||
|
* There will be one USel per "context".
|
||||||
*/
|
*/
|
||||||
public class WCat extends Entity<WCat, String>
|
public class USel extends Entity<USel, String>
|
||||||
{
|
{
|
||||||
public final static transient String RETURN = "_return";
|
public final static transient String RETURN = "_return";
|
||||||
public final static transient String RUN = "_run";
|
public final static transient String RUN = "_run";
|
||||||
public final static transient String _DEFAULT = "_default";
|
public final static transient String _DEFAULT = "_default";
|
||||||
public final static transient String DEFAULT = "default";
|
public final static transient String DEFAULT = "default";
|
||||||
public final static transient List<WCatRule> DEFAULT_RULES = MUtil.list(new WCatRule(RUN, _DEFAULT));
|
public final static transient List<USelRule> DEFAULT_RULES = MUtil.list(new USelRule(RUN, _DEFAULT));
|
||||||
public final static transient List<WCatRule> DEFAULT_DEFAULT_RULES = MUtil.list(new WCatRule(RETURN, DEFAULT));
|
public final static transient List<USelRule> DEFAULT_DEFAULT_RULES = MUtil.list(new USelRule(RETURN, DEFAULT));
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// META
|
// META
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override public Coll<WCat, String> getColl() { return WCatColl.i; }
|
@Override protected USel getThis() { return this; }
|
||||||
@Override protected WCat getThis() { return this; }
|
|
||||||
|
|
||||||
private final static transient WCat defaultInstance = new WCat();
|
private final static transient USel defaultInstance = new USel();
|
||||||
@Override public WCat getDefaultInstance(){ return defaultInstance; }
|
@Override public USel getDefaultInstance(){ return defaultInstance; }
|
||||||
@Override protected Class<WCat> getClazz() { return WCat.class; }
|
@Override protected Class<USel> getClazz() { return USel.class; }
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected List<WCatRule> rules;
|
protected List<USelRule> rules;
|
||||||
public List<WCatRule> rules() { return this.rules; };
|
public List<USelRule> rules() { return this.rules; };
|
||||||
public void rules(List<WCatRule> val) { this.rules = new ArrayList<WCatRule>(val); };
|
public void rules(List<USelRule> val) { this.rules = new ArrayList<USelRule>(val); };
|
||||||
public void rules(String... namesAndParams)
|
public void rules(String... namesAndParams)
|
||||||
{
|
{
|
||||||
this.rules = new ArrayList<WCatRule>();
|
this.rules = new ArrayList<USelRule>();
|
||||||
Iterator<String> iter = Arrays.asList(namesAndParams).iterator();
|
Iterator<String> iter = Arrays.asList(namesAndParams).iterator();
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
String name = iter.next();
|
String name = iter.next();
|
||||||
String param = iter.next();
|
String param = iter.next();
|
||||||
this.rules.add(new WCatRule(name, param));
|
this.rules.add(new USelRule(name, param));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class WCat extends Entity<WCat, String>
|
|||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public WCat()
|
public USel()
|
||||||
{
|
{
|
||||||
this.rules(DEFAULT_RULES);
|
this.rules(DEFAULT_RULES);
|
||||||
}
|
}
|
||||||
@ -64,9 +64,9 @@ public class WCat extends Entity<WCat, String>
|
|||||||
// THAT SPECIAL LOGIC
|
// THAT SPECIAL LOGIC
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public String categorize(String worldName)
|
public String select(String worldName)
|
||||||
{
|
{
|
||||||
for (WCatRule rule : this.rules())
|
for (USelRule rule : this.rules())
|
||||||
{
|
{
|
||||||
String name = rule.name();
|
String name = rule.name();
|
||||||
String param = rule.param();
|
String param = rule.param();
|
||||||
@ -76,9 +76,9 @@ public class WCat extends Entity<WCat, String>
|
|||||||
}
|
}
|
||||||
else if (name.equals(RUN))
|
else if (name.equals(RUN))
|
||||||
{
|
{
|
||||||
WCat subcat = WCatColl.i.get(param);
|
USel subSelector = USelColl.i.get(param);
|
||||||
String subcatresult = subcat.categorize(worldName);
|
String subSelectorResult = subSelector.select(worldName);
|
||||||
if (subcatresult != null) return subcatresult;
|
if (subSelectorResult != null) return subSelectorResult;
|
||||||
}
|
}
|
||||||
else if (name.equalsIgnoreCase(worldName))
|
else if (name.equalsIgnoreCase(worldName))
|
||||||
{
|
{
|
41
src/com/massivecraft/mcore4/store/USelColl.java
Normal file
41
src/com/massivecraft/mcore4/store/USelColl.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.massivecraft.mcore4.store;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore4.MCore;
|
||||||
|
|
||||||
|
public class USelColl extends Coll<USel, String>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// META
|
||||||
|
// -------------------------------------------- //
|
||||||
|
public static USelColl i = new USelColl();
|
||||||
|
|
||||||
|
private USelColl()
|
||||||
|
{
|
||||||
|
super(MCore.p, "ai", "mcore_usel", USel.class, String.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(Object ofrom, Object oto)
|
||||||
|
{
|
||||||
|
USel from = (USel)ofrom;
|
||||||
|
USel to = (USel)oto;
|
||||||
|
to.rules = from.rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
// Ensure the default WorldCategorizer is present.
|
||||||
|
USel d = this.get(USel._DEFAULT);
|
||||||
|
d.rules(USel.DEFAULT_DEFAULT_RULES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefault(USel entity)
|
||||||
|
{
|
||||||
|
return entity.rules().equals(USel.DEFAULT_RULES);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.massivecraft.mcore4.store;
|
package com.massivecraft.mcore4.store;
|
||||||
|
|
||||||
public class WCatRule
|
public class USelRule
|
||||||
{
|
{
|
||||||
protected final String name;
|
protected final String name;
|
||||||
public String name() { return this.name; }
|
public String name() { return this.name; }
|
||||||
@ -8,13 +8,13 @@ public class WCatRule
|
|||||||
protected final String param;
|
protected final String param;
|
||||||
public String param() { return this.param; }
|
public String param() { return this.param; }
|
||||||
|
|
||||||
public WCatRule()
|
public USelRule()
|
||||||
{
|
{
|
||||||
this.name = null;
|
this.name = null;
|
||||||
this.param = null;
|
this.param = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WCatRule(String name, String param)
|
public USelRule(String name, String param)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.param = param;
|
this.param = param;
|
@ -1,41 +0,0 @@
|
|||||||
package com.massivecraft.mcore4.store;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore4.MCore;
|
|
||||||
|
|
||||||
public class WCatColl extends Coll<WCat, String>
|
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// META
|
|
||||||
// -------------------------------------------- //
|
|
||||||
public static WCatColl i = new WCatColl();
|
|
||||||
|
|
||||||
private WCatColl()
|
|
||||||
{
|
|
||||||
super(MCore.p, "ai", "mcore_wcat", WCat.class, String.class, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void copy(Object ofrom, Object oto)
|
|
||||||
{
|
|
||||||
WCat from = (WCat)ofrom;
|
|
||||||
WCat to = (WCat)oto;
|
|
||||||
to.rules = from.rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init()
|
|
||||||
{
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
// Ensure the default WorldCategorizer is present.
|
|
||||||
WCat d = this.get(WCat._DEFAULT);
|
|
||||||
d.rules(WCat.DEFAULT_DEFAULT_RULES);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDefault(WCat entity)
|
|
||||||
{
|
|
||||||
return entity.rules().equals(WCat.DEFAULT_RULES);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user