From 7e33bd0bf16d0d3a39f110c543029128df271c90 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 16:27:47 +0200 Subject: [PATCH] Add an intermediate Colls class for that shared universe-get logic. --- src/com/massivecraft/factions/Const.java | 3 -- .../factions/entity/BoardColls.java | 34 +---------------- .../factions/entity/FactionColls.java | 34 +---------------- .../factions/entity/UConfColls.java | 3 +- .../factions/entity/UPlayerColls.java | 34 +---------------- .../massivecraft/factions/entity/XColls.java | 37 +++++++++++++++++++ 6 files changed, 41 insertions(+), 104 deletions(-) create mode 100644 src/com/massivecraft/factions/entity/XColls.java diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java index 00991761..485ffeb1 100644 --- a/src/com/massivecraft/factions/Const.java +++ b/src/com/massivecraft/factions/Const.java @@ -64,9 +64,6 @@ public class Const Material.TRAPPED_CHEST ); - //public static Set territoryProtectedMaterialsWhenOffline = EnumSet.noneOf(Material.class); - //public static Set territoryDenyUseageMaterialsWhenOffline = EnumSet.noneOf(Material.class); - public static final Set ENTITY_TYPES_MONSTERS = MUtil.set( EntityType.BLAZE, EntityType.CAVE_SPIDER, diff --git a/src/com/massivecraft/factions/entity/BoardColls.java b/src/com/massivecraft/factions/entity/BoardColls.java index 0ad410a0..1a1b3c75 100644 --- a/src/com/massivecraft/factions/entity/BoardColls.java +++ b/src/com/massivecraft/factions/entity/BoardColls.java @@ -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 implements BoardInterface +public class BoardColls extends XColls implements BoardInterface { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -56,31 +49,6 @@ public class BoardColls extends Colls 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() { diff --git a/src/com/massivecraft/factions/entity/FactionColls.java b/src/com/massivecraft/factions/entity/FactionColls.java index 27ab2e86..ee98ffe8 100644 --- a/src/com/massivecraft/factions/entity/FactionColls.java +++ b/src/com/massivecraft/factions/entity/FactionColls.java @@ -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 +public class FactionColls extends XColls { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -50,31 +43,6 @@ public class FactionColls extends Colls 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() { diff --git a/src/com/massivecraft/factions/entity/UConfColls.java b/src/com/massivecraft/factions/entity/UConfColls.java index d4e0ac73..49b4d5c9 100644 --- a/src/com/massivecraft/factions/entity/UConfColls.java +++ b/src/com/massivecraft/factions/entity/UConfColls.java @@ -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 +public class UConfColls extends XColls { // -------------------------------------------- // // INSTANCE & CONSTRUCT diff --git a/src/com/massivecraft/factions/entity/UPlayerColls.java b/src/com/massivecraft/factions/entity/UPlayerColls.java index a8b0b60a..0928e216 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColls.java +++ b/src/com/massivecraft/factions/entity/UPlayerColls.java @@ -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 +public class UPlayerColls extends XColls { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -50,31 +43,6 @@ public class UPlayerColls extends Colls 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() { diff --git a/src/com/massivecraft/factions/entity/XColls.java b/src/com/massivecraft/factions/entity/XColls.java new file mode 100644 index 00000000..0fb7e15f --- /dev/null +++ b/src/com/massivecraft/factions/entity/XColls.java @@ -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, E> extends Colls +{ + @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); + } +}