diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt index 58ea48c..d752db5 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt @@ -6,7 +6,7 @@ import java.util.* class ExcludeGroup(name: String) : AbstractMaterialGroup(name) { override fun createDefaultSet(): MutableSet { - return NegativeSet(HashSet()) + return NegativeMaterialSet() } private var includedGroup: MutableSet = HashSet() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt new file mode 100644 index 0000000..d87004d --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt @@ -0,0 +1,22 @@ +package xyz.alexcrea.cuanvil.group + +import org.bukkit.NamespacedKey +import xyz.alexcrea.cuanvil.util.MaterialUtil +import xyz.alexcrea.cuanvil.util.NegativeSet + +class NegativeMaterialSet: NegativeSet() { + + override fun iterator(): MutableIterator { + val materials = MaterialUtil.getMaterials() + materials.removeIf { negate.contains(it) } + + return materials.iterator() + } + + override fun isEmpty(): Boolean { + return negate.size >= MaterialUtil.getMaterialCount() + } + + override val size get() = MaterialUtil.getMaterialCount() - negate.size + +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt similarity index 81% rename from src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt rename to src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt index 386ba5f..a94175b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt @@ -1,6 +1,6 @@ -package xyz.alexcrea.cuanvil.group +package xyz.alexcrea.cuanvil.util -class NegativeSet(val negate: MutableSet) : MutableSet { +open class NegativeSet(val negate: MutableSet = HashSet()) : MutableSet { override fun iterator(): MutableIterator { TODO("Not yet implemented") // can't be implemented I guess @@ -15,7 +15,7 @@ class NegativeSet(val negate: MutableSet) : MutableSet { } override fun addAll(elements: Collection): Boolean { - return negate.removeAll(elements) + return negate.removeAll(elements.toSet()) } override fun removeAll(elements: Collection): Boolean { @@ -34,7 +34,7 @@ class NegativeSet(val negate: MutableSet) : MutableSet { TODO("Not yet implemented") } - override val size get() = TODO("Not yet implemented") + override val size: Int get() = TODO("Not yet implemented") override fun contains(element: T): Boolean { return !negate.contains(element)