Add an intermediate Colls class for that shared universe-get logic.

This commit is contained in:
Olof Larsson 2013-04-24 16:27:47 +02:00
parent 643d6ba3c7
commit 7e33bd0bf1
6 changed files with 41 additions and 104 deletions

View File

@ -64,9 +64,6 @@ public class Const
Material.TRAPPED_CHEST
);
//public static Set<Material> territoryProtectedMaterialsWhenOffline = EnumSet.noneOf(Material.class);
//public static Set<Material> territoryDenyUseageMaterialsWhenOffline = EnumSet.noneOf(Material.class);
public static final Set<EntityType> ENTITY_TYPES_MONSTERS = MUtil.set(
EntityType.BLAZE,
EntityType.CAVE_SPIDER,

View File

@ -8,24 +8,17 @@ import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PSBuilder;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Colls;
import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class BoardColls extends Colls<BoardColl, Board> implements BoardInterface
public class BoardColls extends XColls<BoardColl, Board> implements BoardInterface
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -56,31 +49,6 @@ public class BoardColls extends Colls<BoardColl, Board> implements BoardInterfac
return Const.COLLECTION_BASENAME_UCONF;
}
@Override
public BoardColl get(Object o)
{
if (o == null) return null;
if (o instanceof Entity)
{
return this.getForUniverse(((Entity<?>)o).getUniverse());
}
if (o instanceof Coll)
{
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
}
@Override
public void init()
{

View File

@ -5,21 +5,14 @@ import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Colls;
import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class FactionColls extends Colls<FactionColl, Faction>
public class FactionColls extends XColls<FactionColl, Faction>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -50,31 +43,6 @@ public class FactionColls extends Colls<FactionColl, Faction>
return Const.COLLECTION_BASENAME_FACTION;
}
@Override
public FactionColl get(Object o)
{
if (o == null) return null;
if (o instanceof Entity)
{
return this.getForUniverse(((Entity<?>)o).getUniverse());
}
if (o instanceof Coll)
{
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
}
@Override
public void init()
{

View File

@ -3,10 +3,9 @@ package com.massivecraft.factions.entity;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Colls;
import com.massivecraft.mcore.usys.Aspect;
public class UConfColls extends Colls<UConfColl, UConf>
public class UConfColls extends XColls<UConfColl, UConf>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT

View File

@ -5,21 +5,14 @@ import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Colls;
import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.util.DiscUtil;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.reflect.TypeToken;
public class UPlayerColls extends Colls<UPlayerColl, UPlayer>
public class UPlayerColls extends XColls<UPlayerColl, UPlayer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -50,31 +43,6 @@ public class UPlayerColls extends Colls<UPlayerColl, UPlayer>
return Const.COLLECTION_BASENAME_UPLAYER;
}
@Override
public UPlayerColl get(Object o)
{
if (o == null) return null;
if (o instanceof Entity)
{
return this.getForUniverse(((Entity<?>)o).getUniverse());
}
if (o instanceof Coll)
{
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
}
@Override
public void init()
{

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.entity;
import org.bukkit.Bukkit;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Colls;
import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.SenderUtil;
public abstract class XColls<C extends Coll<E>, E> extends Colls<C, E>
{
@Override
public C get(Object o)
{
if (o == null) return null;
if (o instanceof Entity)
{
return this.getForUniverse(((Entity<?>)o).getUniverse());
}
if (o instanceof Coll)
{
return this.getForUniverse(((Coll<?>)o).getUniverse());
}
if (SenderUtil.isNonplayer(o))
{
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
}
String worldName = MUtil.extract(String.class, "worldName", o);
if (worldName == null) return null;
return this.getForWorld(worldName);
}
}