diff --git a/src/com/massivecraft/massivecore/collections/ExceptionSet.java b/src/com/massivecraft/massivecore/collections/ExceptionSet.java new file mode 100644 index 00000000..87c7583f --- /dev/null +++ b/src/com/massivecraft/massivecore/collections/ExceptionSet.java @@ -0,0 +1,51 @@ +package com.massivecraft.massivecore.collections; + +import com.massivecraft.massivecore.CaseInsensitiveComparator; + +public class ExceptionSet +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public boolean standard = true; + + public MassiveTreeSet exceptions = new MassiveTreeSet(CaseInsensitiveComparator.get()); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ExceptionSet() + { + + } + + public ExceptionSet(boolean standard) + { + this.standard = standard; + } + + // -------------------------------------------- // + // CONTAINS + // -------------------------------------------- // + + public boolean contains(String item) + { + if (this.exceptions.contains(item)) return ! this.standard; + return this.standard; + } + + public boolean contains(T item) + { + if (item == null) return ! this.standard; + + return this.contains(convert(item)); + } + + public String convert(T item) + { + return item.toString(); + } + +} diff --git a/src/com/massivecraft/massivecore/collections/WorldExceptionSet.java b/src/com/massivecraft/massivecore/collections/WorldExceptionSet.java index 7f70e1ef..1b9380b8 100644 --- a/src/com/massivecraft/massivecore/collections/WorldExceptionSet.java +++ b/src/com/massivecraft/massivecore/collections/WorldExceptionSet.java @@ -4,19 +4,10 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; -import com.massivecraft.massivecore.CaseInsensitiveComparator; import com.massivecraft.massivecore.ps.PS; -public class WorldExceptionSet +public class WorldExceptionSet extends ExceptionSet { - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public boolean standard = true; - - public MassiveTreeSet exceptions = new MassiveTreeSet(CaseInsensitiveComparator.get()); - // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // @@ -28,17 +19,17 @@ public class WorldExceptionSet public WorldExceptionSet(boolean standard) { - this.standard = standard; + super(standard); } // -------------------------------------------- // // CONTAINS // -------------------------------------------- // - public boolean contains(String world) + @Override + public String convert(World world) { - if (this.exceptions.contains(world)) return !this.standard; - return this.standard; + return world.getName(); } public boolean contains(PS ps) @@ -46,11 +37,6 @@ public class WorldExceptionSet return this.contains(ps.getWorld()); } - public boolean contains(World world) - { - return this.contains(world.getName()); - } - public boolean contains(Location loc) { return this.contains(loc.getWorld());