mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-24 04:57:50 -04:00
connection filter
This commit is contained in:
parent
2c76f3d7ba
commit
1cfe44ff76
@ -24,8 +24,8 @@ import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.u
|
|||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorEntityTarget
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorEntityTarget
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidSelectorKeyError
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidSelectorKeyError
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidTargetSelector
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidTargetSelector
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.uuid.InvalidUUIDError
|
import de.bixilon.minosoft.commands.parser.minecraft.uuid.InvalidUUIDError
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.commands.util.ReadResult
|
import de.bixilon.minosoft.commands.util.ReadResult
|
||||||
@ -60,7 +60,7 @@ class TargetParser(
|
|||||||
val selectorChar = readNext() ?: throw ExpectedArgumentError(this)
|
val selectorChar = readNext() ?: throw ExpectedArgumentError(this)
|
||||||
val selector = TargetSelectors.BY_CHAR[selectorChar.toChar()] ?: throw InvalidTargetSelector(this)
|
val selector = TargetSelectors.BY_CHAR[selectorChar.toChar()] ?: throw InvalidTargetSelector(this)
|
||||||
|
|
||||||
val properties: Map<String, TargetProperty> = readMap({ readKey() }, { readValue(it) }) ?: emptyMap()
|
val properties: Map<String, EntityTargetProperty> = readMap({ readKey() }, { readValue(it) }) ?: emptyMap()
|
||||||
|
|
||||||
return SelectorEntityTarget(selector, properties)
|
return SelectorEntityTarget(selector, properties)
|
||||||
}
|
}
|
||||||
@ -72,8 +72,8 @@ class TargetParser(
|
|||||||
return readUntil('='.code)
|
return readUntil('='.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CommandReader.readValue(key: ReadResult<String>): TargetProperty {
|
private fun CommandReader.readValue(key: ReadResult<String>): EntityTargetProperty {
|
||||||
val target = TargetProperties[key.result] ?: throw InvalidSelectorKeyError(this, key)
|
val target = EntityTargetProperties[key.result] ?: throw InvalidSelectorKeyError(this, key)
|
||||||
return target.read(this)
|
return target.read(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class NameEntityTarget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "{Bixilon}"
|
return "{$name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector
|
|||||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
data class SelectorProperties(
|
data class EntitySelectorProperties(
|
||||||
val entities: MutableList<Entity>,
|
val entities: MutableList<Entity>,
|
||||||
val center: Vec3d,
|
val center: Vec3d,
|
||||||
val executor: Entity?,
|
val executor: Entity?,
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector
|
|||||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.TargetSelectors
|
import de.bixilon.minosoft.commands.parser.minecraft.target.TargetSelectors
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.EntityTarget
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.EntityTarget
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.XCenterProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.XCenterProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.YCenterProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.YCenterProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.ZCenterProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center.ZCenterProperty
|
||||||
@ -26,7 +26,7 @@ import de.bixilon.minosoft.data.world.WorldEntities
|
|||||||
|
|
||||||
class SelectorEntityTarget(
|
class SelectorEntityTarget(
|
||||||
val selector: TargetSelectors,
|
val selector: TargetSelectors,
|
||||||
val properties: Map<String, TargetProperty>,
|
val properties: Map<String, EntityTargetProperty>,
|
||||||
) : EntityTarget {
|
) : EntityTarget {
|
||||||
|
|
||||||
override fun getEntities(executor: Entity?, entities: WorldEntities): List<Entity> {
|
override fun getEntities(executor: Entity?, entities: WorldEntities): List<Entity> {
|
||||||
@ -37,7 +37,7 @@ class SelectorEntityTarget(
|
|||||||
}
|
}
|
||||||
entities.lock.release()
|
entities.lock.release()
|
||||||
|
|
||||||
val selectorProperties = SelectorProperties(
|
val selectorProperties = EntitySelectorProperties(
|
||||||
entities = selected,
|
entities = selected,
|
||||||
center = executor?.position ?: Vec3d(),
|
center = executor?.position ?: Vec3d(),
|
||||||
executor = executor,
|
executor = executor,
|
||||||
|
@ -22,8 +22,8 @@ import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pro
|
|||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.sort.SortProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.sort.SortProperty
|
||||||
|
|
||||||
// See https://minecraft.fandom.com/wiki/Target_selectors
|
// See https://minecraft.fandom.com/wiki/Target_selectors
|
||||||
object TargetProperties {
|
object EntityTargetProperties {
|
||||||
val properties: MutableMap<String, TargetPropertyFactory<*>> = mutableMapOf()
|
val properties: MutableMap<String, EntityTargetPropertyFactory<*>> = mutableMapOf()
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -55,11 +55,11 @@ object TargetProperties {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fun register(factory: TargetPropertyFactory<*>) {
|
fun register(factory: EntityTargetPropertyFactory<*>) {
|
||||||
properties[factory.name] = factory
|
properties[factory.name] = factory
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(key: String): TargetPropertyFactory<*>? {
|
operator fun get(key: String): EntityTargetPropertyFactory<*>? {
|
||||||
return properties[key]
|
return properties[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,12 +13,12 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
interface TargetProperty {
|
interface EntityTargetProperty {
|
||||||
|
|
||||||
fun passes(properties: SelectorProperties, entity: Entity): Boolean
|
fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean
|
||||||
|
|
||||||
fun updateProperties(properties: SelectorProperties) = Unit
|
fun updateProperties(properties: EntitySelectorProperties) = Unit
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
|
||||||
interface TargetPropertyFactory<T : TargetProperty> {
|
interface EntityTargetPropertyFactory<T : EntityTargetProperty> {
|
||||||
val name: String
|
val name: String
|
||||||
|
|
||||||
fun read(reader: CommandReader): T
|
fun read(reader: CommandReader): T
|
@ -14,7 +14,7 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minosoft.enums.EnumParser
|
import de.bixilon.minosoft.commands.parser.minosoft.enums.EnumParser
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||||
@ -24,9 +24,9 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
|
|||||||
class GamemodeProperty(
|
class GamemodeProperty(
|
||||||
val gamemode: Gamemodes,
|
val gamemode: Gamemodes,
|
||||||
val negated: Boolean,
|
val negated: Boolean,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
if (entity !is PlayerEntity) {
|
if (entity !is PlayerEntity) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ class GamemodeProperty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<GamemodeProperty> {
|
companion object : EntityTargetPropertyFactory<GamemodeProperty> {
|
||||||
override val name: String = "gamemode"
|
override val name: String = "gamemode"
|
||||||
private val parser = EnumParser(Gamemodes)
|
private val parser = EnumParser(Gamemodes)
|
||||||
|
|
||||||
|
@ -14,19 +14,19 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._int.IntRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._int.IntRangeParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
class LevelProperty(
|
class LevelProperty(
|
||||||
val range: IntRange,
|
val range: IntRange,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<LevelProperty> {
|
companion object : EntityTargetPropertyFactory<LevelProperty> {
|
||||||
override val name: String = "level"
|
override val name: String = "level"
|
||||||
private val parser = IntRangeParser()
|
private val parser = IntRangeParser()
|
||||||
|
|
||||||
|
@ -14,20 +14,20 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._int.IntParser.Companion.readRequiredInt
|
import de.bixilon.minosoft.commands.parser.brigadier._int.IntParser.Companion.readRequiredInt
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
class LimitProperty(
|
class LimitProperty(
|
||||||
val limit: Int,
|
val limit: Int,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
return properties.entities.size < limit
|
return properties.entities.size < limit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<LimitProperty> {
|
companion object : EntityTargetPropertyFactory<LimitProperty> {
|
||||||
override val name: String = "limit"
|
override val name: String = "limit"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): LimitProperty {
|
override fun read(reader: CommandReader): LimitProperty {
|
||||||
|
@ -14,16 +14,16 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
class NameProperty(
|
class NameProperty(
|
||||||
val name: String,
|
val name: String,
|
||||||
val negated: Boolean,
|
val negated: Boolean,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
// ToDo: Check player name?
|
// ToDo: Check player name?
|
||||||
if (negated) {
|
if (negated) {
|
||||||
return entity.customName?.message != name
|
return entity.customName?.message != name
|
||||||
@ -31,7 +31,7 @@ class NameProperty(
|
|||||||
return entity.customName?.message == name
|
return entity.customName?.message == name
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<NameProperty> {
|
companion object : EntityTargetPropertyFactory<NameProperty> {
|
||||||
override val name: String = "name"
|
override val name: String = "name"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): NameProperty {
|
override fun read(reader: CommandReader): NameProperty {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
@ -22,9 +22,9 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
|||||||
class TypeProperty(
|
class TypeProperty(
|
||||||
val type: ResourceLocation,
|
val type: ResourceLocation,
|
||||||
val negated: Boolean,
|
val negated: Boolean,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
if (negated) {
|
if (negated) {
|
||||||
return entity.type.resourceLocation != type
|
return entity.type.resourceLocation != type
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ class TypeProperty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<TypeProperty> {
|
companion object : EntityTargetPropertyFactory<TypeProperty> {
|
||||||
override val name: String = "type"
|
override val name: String = "type"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): TypeProperty {
|
override fun read(reader: CommandReader): TypeProperty {
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.position.center
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.data.Axes
|
import de.bixilon.minosoft.data.Axes
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.set
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.set
|
||||||
@ -22,13 +22,13 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.set
|
|||||||
abstract class CenterProperty(
|
abstract class CenterProperty(
|
||||||
val axis: Axes,
|
val axis: Axes,
|
||||||
val value: Double,
|
val value: Double,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateProperties(properties: SelectorProperties) {
|
override fun updateProperties(properties: EntitySelectorProperties) {
|
||||||
properties.center[axis] = value
|
properties.center[axis] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.Axes
|
import de.bixilon.minosoft.data.Axes
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ class XCenterProperty(
|
|||||||
value: Double,
|
value: Double,
|
||||||
) : CenterProperty(Axes.X, value) {
|
) : CenterProperty(Axes.X, value) {
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<XCenterProperty> {
|
companion object : EntityTargetPropertyFactory<XCenterProperty> {
|
||||||
override val name: String = "x"
|
override val name: String = "x"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): XCenterProperty {
|
override fun read(reader: CommandReader): XCenterProperty {
|
||||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.Axes
|
import de.bixilon.minosoft.data.Axes
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class YCenterProperty(
|
|||||||
) : CenterProperty(Axes.Y, value) {
|
) : CenterProperty(Axes.Y, value) {
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<YCenterProperty> {
|
companion object : EntityTargetPropertyFactory<YCenterProperty> {
|
||||||
override val name: String = "y"
|
override val name: String = "y"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): YCenterProperty {
|
override fun read(reader: CommandReader): YCenterProperty {
|
||||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParseError
|
||||||
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
import de.bixilon.minosoft.commands.parser.brigadier._double.DoubleParser.Companion.readDouble
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.Axes
|
import de.bixilon.minosoft.data.Axes
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class ZCenterProperty(
|
|||||||
) : CenterProperty(Axes.Z, value) {
|
) : CenterProperty(Axes.Z, value) {
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<ZCenterProperty> {
|
companion object : EntityTargetPropertyFactory<ZCenterProperty> {
|
||||||
override val name: String = "z"
|
override val name: String = "z"
|
||||||
|
|
||||||
override fun read(reader: CommandReader): ZCenterProperty {
|
override fun read(reader: CommandReader): ZCenterProperty {
|
||||||
|
@ -15,28 +15,28 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
class DistanceProperty(
|
class DistanceProperty(
|
||||||
val range: FloatRange,
|
val range: FloatRange,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
check(range.min >= 0.0) { "Minimum distance can not be below 0" }
|
check(range.min >= 0.0) { "Minimum distance can not be below 0" }
|
||||||
check(range.max >= range.min) { "Maximum distance can not be smaller than minimum distance" }
|
check(range.max >= range.min) { "Maximum distance can not be smaller than minimum distance" }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
val entityPosition = entity.position
|
val entityPosition = entity.position
|
||||||
|
|
||||||
return (entityPosition - properties.center).length().toFloat() in range
|
return (entityPosition - properties.center).length().toFloat() in range
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<DistanceProperty> {
|
companion object : EntityTargetPropertyFactory<DistanceProperty> {
|
||||||
override val name: String = "distance"
|
override val name: String = "distance"
|
||||||
private val parser = FloatRangeParser(0.0f)
|
private val parser = FloatRangeParser(0.0f)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class PitchRotation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<YawRotation> {
|
companion object : EntityTargetPropertyFactory<YawRotation> {
|
||||||
const val MIN = -90.0f
|
const val MIN = -90.0f
|
||||||
const val MAX = 90.0f
|
const val MAX = 90.0f
|
||||||
override val name: String = "x_rotation"
|
override val name: String = "x_rotation"
|
||||||
|
@ -14,18 +14,18 @@
|
|||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.rotation
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.rotation
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
interface RotationProperty : TargetProperty {
|
interface RotationProperty : EntityTargetProperty {
|
||||||
val range: FloatRange
|
val range: FloatRange
|
||||||
|
|
||||||
fun getValue(rotation: EntityRotation): Double
|
fun getValue(rotation: EntityRotation): Double
|
||||||
|
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
val rotation = getValue(entity.rotation)
|
val rotation = getValue(entity.rotation)
|
||||||
|
|
||||||
return rotation.toFloat() in range
|
return rotation.toFloat() in range
|
||||||
|
@ -15,7 +15,7 @@ package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.pr
|
|||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRange
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class YawRotation(
|
|||||||
return rotation.yaw
|
return rotation.yaw
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<YawRotation> {
|
companion object : EntityTargetPropertyFactory<YawRotation> {
|
||||||
const val MIN = -180.0f
|
const val MIN = -180.0f
|
||||||
const val MAX = 180.0f
|
const val MAX = 180.0f
|
||||||
override val name: String = "y_rotation"
|
override val name: String = "y_rotation"
|
||||||
|
@ -13,27 +13,27 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.sort
|
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.sort
|
||||||
|
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorProperties
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.EntitySelectorProperties
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetProperty
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetPropertyFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.EntityTargetPropertyFactory
|
||||||
import de.bixilon.minosoft.commands.parser.minosoft.enums.EnumParser
|
import de.bixilon.minosoft.commands.parser.minosoft.enums.EnumParser
|
||||||
import de.bixilon.minosoft.commands.util.CommandReader
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
|
|
||||||
class SortProperty(
|
class SortProperty(
|
||||||
val sorting: Sorting,
|
val sorting: Sorting,
|
||||||
) : TargetProperty {
|
) : EntityTargetProperty {
|
||||||
|
|
||||||
override fun passes(properties: SelectorProperties, entity: Entity): Boolean {
|
override fun passes(properties: EntitySelectorProperties, entity: Entity): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateProperties(properties: SelectorProperties) {
|
override fun updateProperties(properties: EntitySelectorProperties) {
|
||||||
sorting.sort(properties.center, properties.entities)
|
sorting.sort(properties.center, properties.entities)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : TargetPropertyFactory<SortProperty> {
|
companion object : EntityTargetPropertyFactory<SortProperty> {
|
||||||
override val name: String = "sort"
|
override val name: String = "sort"
|
||||||
private val parser = EnumParser(Sorting)
|
private val parser = EnumParser(Sorting)
|
||||||
|
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
|
import de.bixilon.minosoft.commands.parser.ArgumentParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.brigadier._int.IntParser.Companion.readInt
|
||||||
|
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||||
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidSelectorKeyError
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.identifier.ConnectionId
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.selector.SelectorConnectionTarget
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties.ConnectionTargetProperties
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties.ConnectionTargetProperty
|
||||||
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
import de.bixilon.minosoft.commands.util.ReadResult
|
||||||
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
|
||||||
|
object ConnectionParser : ArgumentParser<ConnectionTarget>, ArgumentParserFactory<ConnectionParser> {
|
||||||
|
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:connection".toResourceLocation()
|
||||||
|
override val examples: List<Any?> = listOf("1", "@")
|
||||||
|
override val placeholder = ChatComponent.of("<connection>")
|
||||||
|
|
||||||
|
override fun parse(reader: CommandReader): ConnectionTarget {
|
||||||
|
if (!reader.canPeek()) {
|
||||||
|
throw ExpectedArgumentError(reader)
|
||||||
|
}
|
||||||
|
return if (reader.peek() == '@'.code) {
|
||||||
|
reader.parseSelector()
|
||||||
|
} else {
|
||||||
|
parseConnectionId(reader)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CommandReader.parseSelector(): SelectorConnectionTarget {
|
||||||
|
unsafeRead('@'.code)
|
||||||
|
|
||||||
|
val properties: Map<String, ConnectionTargetProperty> = readMap({ readKey() }, { readValue(it) }) ?: emptyMap()
|
||||||
|
|
||||||
|
return SelectorConnectionTarget(properties)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandReader.readKey(): String? {
|
||||||
|
if (peek() == '"'.code) {
|
||||||
|
return readUnquotedString()
|
||||||
|
}
|
||||||
|
return readUntil('='.code)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandReader.readValue(key: ReadResult<String>): ConnectionTargetProperty {
|
||||||
|
val target = ConnectionTargetProperties[key.result] ?: throw InvalidSelectorKeyError(this, key)
|
||||||
|
return target.read(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseConnectionId(reader: CommandReader): ConnectionTarget {
|
||||||
|
val result = reader.readResult { reader.readInt() }
|
||||||
|
if (result.result == null) {
|
||||||
|
throw ExpectedArgumentError(reader)
|
||||||
|
}
|
||||||
|
return ConnectionId(result.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSuggestions(reader: CommandReader): List<Any?> {
|
||||||
|
return examples // ToDo
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(buffer: PlayInByteBuffer): ConnectionParser = this
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
|
interface ConnectionTarget {
|
||||||
|
|
||||||
|
fun getConnections(connections: Collection<PlayConnection>): List<PlayConnection>
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.identifier
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionTarget
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
|
class ConnectionId(
|
||||||
|
val id: Int,
|
||||||
|
) : ConnectionTarget {
|
||||||
|
|
||||||
|
override fun getConnections(connections: Collection<PlayConnection>): List<PlayConnection> {
|
||||||
|
for (connection in connections) {
|
||||||
|
if (connection.connectionId == id) {
|
||||||
|
return listOf(connection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "{$id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is ConnectionId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return id == other.id
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.identifier
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.errors.parser.ParserError
|
||||||
|
import de.bixilon.minosoft.commands.util.ReadResult
|
||||||
|
import de.bixilon.minosoft.commands.util.StringReader
|
||||||
|
|
||||||
|
class ConnectionIdError(
|
||||||
|
reader: StringReader,
|
||||||
|
result: ReadResult<String?>,
|
||||||
|
) : ParserError(reader, result)
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionTarget
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties.ConnectionTargetProperty
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
|
class SelectorConnectionTarget(
|
||||||
|
val properties: Map<String, ConnectionTargetProperty>,
|
||||||
|
) : ConnectionTarget {
|
||||||
|
|
||||||
|
override fun getConnections(connections: Collection<PlayConnection>): List<PlayConnection> {
|
||||||
|
val output: MutableList<PlayConnection> = mutableListOf()
|
||||||
|
entityLoop@ for (connection in connections) {
|
||||||
|
for (property in properties.values) {
|
||||||
|
if (!property.passes(connection)) {
|
||||||
|
continue@entityLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output += connection
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
|
import de.bixilon.minosoft.commands.parser.brigadier.bool.BooleanParser.readBoolean
|
||||||
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
|
class ConnectedProperty(
|
||||||
|
val connected: Boolean,
|
||||||
|
) : ConnectionTargetProperty {
|
||||||
|
|
||||||
|
override fun passes(connection: PlayConnection): Boolean {
|
||||||
|
val connected = connection.network.connected
|
||||||
|
return connected == this.connected
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : ConnectionTargetPropertyFactory<ConnectedProperty> {
|
||||||
|
override val name: String = "connected"
|
||||||
|
|
||||||
|
override fun read(reader: CommandReader): ConnectedProperty {
|
||||||
|
return ConnectedProperty(reader.readBoolean() ?: throw ExpectedArgumentError(reader))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties
|
||||||
|
|
||||||
|
// See https://minecraft.fandom.com/wiki/Target_selectors
|
||||||
|
object ConnectionTargetProperties {
|
||||||
|
val properties: MutableMap<String, ConnectionTargetPropertyFactory<*>> = mutableMapOf()
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
register(StateProperty)
|
||||||
|
register(ConnectedProperty)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun register(factory: ConnectionTargetPropertyFactory<*>) {
|
||||||
|
properties[factory.name] = factory
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun get(key: String): ConnectionTargetPropertyFactory<*>? {
|
||||||
|
return properties[key]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
|
interface ConnectionTargetProperty {
|
||||||
|
|
||||||
|
fun passes(connection: PlayConnection): Boolean
|
||||||
|
|
||||||
|
fun updateProperties() = Unit
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
|
||||||
|
interface ConnectionTargetPropertyFactory<T : ConnectionTargetProperty> {
|
||||||
|
val name: String
|
||||||
|
|
||||||
|
fun read(reader: CommandReader): T
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.commands.parser.minosoft.connection.selector.properties
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.errors.ExpectedArgumentError
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.enums.EnumParser
|
||||||
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
|
||||||
|
|
||||||
|
class StateProperty(
|
||||||
|
val state: PlayConnectionStates,
|
||||||
|
val negated: Boolean,
|
||||||
|
) : ConnectionTargetProperty {
|
||||||
|
|
||||||
|
override fun passes(connection: PlayConnection): Boolean {
|
||||||
|
val state = connection.state
|
||||||
|
if (negated) {
|
||||||
|
return state != this.state
|
||||||
|
}
|
||||||
|
return state == this.state
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : ConnectionTargetPropertyFactory<StateProperty> {
|
||||||
|
private val parser = EnumParser(PlayConnectionStates)
|
||||||
|
override val name: String = "state"
|
||||||
|
|
||||||
|
override fun read(reader: CommandReader): StateProperty {
|
||||||
|
val (word, negated) = reader.readNegateable { parser.parse(reader) } ?: throw ExpectedArgumentError(reader)
|
||||||
|
return StateProperty(word, negated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.network.connection.play
|
package de.bixilon.minosoft.protocol.network.connection.play
|
||||||
|
|
||||||
|
import de.bixilon.kutil.enums.EnumUtil
|
||||||
|
import de.bixilon.kutil.enums.ValuesEnum
|
||||||
import de.bixilon.minosoft.data.language.Translatable
|
import de.bixilon.minosoft.data.language.Translatable
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
@ -43,7 +45,9 @@ enum class PlayConnectionStates : Translatable {
|
|||||||
override val translationKey: ResourceLocation = "minosoft:connection.play.state.${name.lowercase()}".toResourceLocation()
|
override val translationKey: ResourceLocation = "minosoft:connection.play.state.${name.lowercase()}".toResourceLocation()
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object : ValuesEnum<PlayConnectionStates> {
|
||||||
|
override val VALUES: Array<PlayConnectionStates> = values()
|
||||||
|
override val NAME_MAP: Map<String, PlayConnectionStates> = EnumUtil.getEnumValues(VALUES)
|
||||||
|
|
||||||
val PlayConnectionStates.disconnected
|
val PlayConnectionStates.disconnected
|
||||||
get() = this == DISCONNECTED || this == KICKED || this == ERROR
|
get() = this == DISCONNECTED || this == KICKED || this == ERROR
|
||||||
|
@ -15,16 +15,29 @@ package de.bixilon.minosoft.terminal.commands
|
|||||||
|
|
||||||
import de.bixilon.jiibles.Table
|
import de.bixilon.jiibles.Table
|
||||||
import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedList
|
import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedList
|
||||||
|
import de.bixilon.minosoft.commands.nodes.ArgumentNode
|
||||||
import de.bixilon.minosoft.commands.nodes.LiteralNode
|
import de.bixilon.minosoft.commands.nodes.LiteralNode
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionTarget
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
object ConnectionManageCommand : Command {
|
object ConnectionManageCommand : Command {
|
||||||
override var node = LiteralNode("connection")
|
override var node = LiteralNode("connection")
|
||||||
.addChild(LiteralNode("list", executor = {
|
.addChild(
|
||||||
val table = Table(arrayOf("Id", "State", "Address"))
|
LiteralNode("list", onlyDirectExecution = false, executor = {
|
||||||
for (connection in PlayConnection.ACTIVE_CONNECTIONS.toSynchronizedList()) {
|
val connections = PlayConnection.ACTIVE_CONNECTIONS.toSynchronizedList()
|
||||||
table += arrayOf(connection.connectionId, connection.state, connection.address)
|
connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList()
|
||||||
}
|
val filteredConnections = it.get<ConnectionTarget?>("filter")?.getConnections(connections) ?: connections
|
||||||
it.print.print(table)
|
if (filteredConnections.isEmpty()) {
|
||||||
}))
|
it.print.print("No connection matched your filter!")
|
||||||
|
return@LiteralNode
|
||||||
|
}
|
||||||
|
val table = Table(arrayOf("Id", "State", "Address"))
|
||||||
|
for (connection in filteredConnections) {
|
||||||
|
table += arrayOf(connection.connectionId, connection.state, connection.address)
|
||||||
|
}
|
||||||
|
it.print.print(table)
|
||||||
|
})
|
||||||
|
.addChild(ArgumentNode("filter", ConnectionParser, executable = true))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user