diff --git a/src/main/kotlin/com/github/shynixn/mctennis/MCTennisDependencyInjectionModule.kt b/src/main/kotlin/com/github/shynixn/mctennis/MCTennisDependencyInjectionModule.kt index 95b045d..5b701a8 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/MCTennisDependencyInjectionModule.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/MCTennisDependencyInjectionModule.kt @@ -14,7 +14,6 @@ import com.github.shynixn.mcutils.common.chat.ChatMessageService import com.github.shynixn.mcutils.common.command.CommandService import com.github.shynixn.mcutils.common.command.CommandServiceImpl import com.github.shynixn.mcutils.common.item.ItemService -import com.github.shynixn.mcutils.common.item.ItemServiceImpl import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcher import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcherImpl import com.github.shynixn.mcutils.common.physic.PhysicObjectService @@ -29,14 +28,12 @@ import com.github.shynixn.mcutils.guice.DependencyInjectionModule import com.github.shynixn.mcutils.packet.api.EntityService import com.github.shynixn.mcutils.packet.api.PacketService import com.github.shynixn.mcutils.packet.api.RayTracingService -import com.github.shynixn.mcutils.packet.impl.service.ChatMessageServiceImpl -import com.github.shynixn.mcutils.packet.impl.service.EntityServiceImpl -import com.github.shynixn.mcutils.packet.impl.service.PacketServiceImpl -import com.github.shynixn.mcutils.packet.impl.service.RayTracingServiceImpl +import com.github.shynixn.mcutils.packet.impl.service.* import com.github.shynixn.mcutils.sign.SignService import com.github.shynixn.mcutils.sign.SignServiceImpl import org.bukkit.Bukkit import org.bukkit.plugin.Plugin +import java.util.concurrent.Executor import java.util.logging.Level class MCTennisDependencyInjectionModule(private val plugin: Plugin) : DependencyInjectionModule() { @@ -79,7 +76,8 @@ class MCTennisDependencyInjectionModule(private val plugin: Plugin) : Dependency addService(PhysicObjectDispatcherImpl(plugin)) addService(ConfigurationServiceImpl(plugin)) addService(SoundServiceImpl(plugin)) - addService(PacketServiceImpl(plugin)) + addService(PacketServiceImpl(plugin + ) { command -> plugin.server.scheduler.runTask(plugin, command) }) addService(ItemServiceImpl()) addService() addService() diff --git a/src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt b/src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt index 96651ed..2c9715d 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt @@ -59,16 +59,17 @@ class MCTennisPlugin : JavaPlugin() { Version.VERSION_1_19_R3, Version.VERSION_1_20_R1, Version.VERSION_1_20_R2, - Version.VERSION_1_20_R3 + Version.VERSION_1_20_R3, + Version.VERSION_1_20_R4 ) } else { - listOf(Version.VERSION_1_20_R3) + listOf(Version.VERSION_1_20_R4) } if (!Version.serverVersion.isCompatible(*versions.toTypedArray())) { logger.log(Level.SEVERE, "================================================") logger.log(Level.SEVERE, "MCTennis does not support your server version") - logger.log(Level.SEVERE, "Install v" + versions[0].id + " - v" + versions[versions.size - 1].id) + logger.log(Level.SEVERE, "Install v" + versions[0].from + " - v" + versions[versions.size - 1].to) logger.log(Level.SEVERE, "Need support for a particular version? Go to https://www.patreon.com/Shynixn") logger.log(Level.SEVERE, "Plugin gets now disabled!") logger.log(Level.SEVERE, "================================================") @@ -76,7 +77,7 @@ class MCTennisPlugin : JavaPlugin() { return } - logger.log(Level.INFO, "Loaded NMS version ${Version.serverVersion.bukkitId}.") + logger.log(Level.INFO, "Loaded NMS version ${Version.serverVersion}.") // Guice this.module = MCTennisDependencyInjectionModule(this).build() diff --git a/src/main/kotlin/com/github/shynixn/mctennis/entity/TennisBallSettings.kt b/src/main/kotlin/com/github/shynixn/mctennis/entity/TennisBallSettings.kt index 10fb602..563487f 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/entity/TennisBallSettings.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/entity/TennisBallSettings.kt @@ -3,9 +3,19 @@ package com.github.shynixn.mctennis.entity import com.github.shynixn.mctennis.enumeration.VisibilityType import com.github.shynixn.mcutils.common.EffectTargetType import com.github.shynixn.mcutils.common.command.CommandMeta +import com.github.shynixn.mcutils.common.item.Item import com.github.shynixn.mcutils.common.sound.SoundMeta class TennisBallSettings { + /** + * Item. + */ + var item: Item = Item().also { + it.typeName = "PLAYER_HEAD,397" + it.durability = 3 + it.skinBase64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0=" + } + // Ground var horizontalBaseMultiplier: Double = 0.4 diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/TennisGameImpl.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/TennisGameImpl.kt index 12fae46..d530bc0 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/TennisGameImpl.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/TennisGameImpl.kt @@ -422,7 +422,7 @@ class TennisGameImpl( val teamMetaData = getTeamMetaFromTeam(team) // Spawnpoint 0 is always serving. val spawnpoint = teamMetaData.spawnpoints[0] - val ballspawnpoint = spawnpoint.clone().addRelativeFront(2.0).addRelativeUp(0.5) + val ballspawnpoint = spawnpoint.copy().addRelativeFront(2.0).addRelativeUp(0.5) ball = tennisBallFactory.createTennisBall(ballspawnpoint.toLocation(), arena.ballSettings, this) diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/ArmorstandEntityComponent.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/ArmorstandEntityComponent.kt index 27be803..4e3ed18 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/ArmorstandEntityComponent.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/ArmorstandEntityComponent.kt @@ -1,6 +1,8 @@ package com.github.shynixn.mctennis.impl.physic +import com.github.shynixn.mctennis.entity.TennisBallSettings import com.github.shynixn.mcutils.common.* +import com.github.shynixn.mcutils.common.item.ItemService import com.github.shynixn.mcutils.common.physic.PhysicComponent import com.github.shynixn.mcutils.packet.api.* import com.github.shynixn.mcutils.packet.api.meta.enumeration.ArmorSlotType @@ -14,6 +16,8 @@ class ArmorstandEntityComponent( physicsComponent: MathComponent, private val packetService: PacketService, private val playerComponent: PlayerComponent, + private val itemService: ItemService, + private val ballSettings: TennisBallSettings, val entityId: Int, private var filteredPlayers: HashSet, private val renderOffsetY : Double @@ -37,12 +41,7 @@ class ArmorstandEntityComponent( it.target = location.toVector3d().addRelativeUp(renderOffsetY).toLocation() }) - val itemStack = item { - this.typeName = "PLAYER_HEAD,397" - this.durability = 3 - this.nbt = - "{SkullOwner:{Name:\"MCTennis\",Properties:{textures:[{Value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0=\"}]}}}" - }.toItemStack() + val itemStack = itemService.toItemStack(ballSettings.item) packetService.sendPacketOutEntityEquipment(player, PacketOutEntityEquipment().also { it.entityId = this.entityId @@ -82,7 +81,7 @@ class ArmorstandEntityComponent( packetService.sendPacketOutEntityTeleport(player, PacketOutEntityTeleport().also { it.entityId = this.entityId - it.target = position.clone().addRelativeUp(renderOffsetY).toLocation() + it.target = position.copy().addRelativeUp(renderOffsetY).toLocation() }) } diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/BounceComponent.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/BounceComponent.kt index cc17e6d..1f197cf 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/BounceComponent.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/BounceComponent.kt @@ -2,7 +2,6 @@ package com.github.shynixn.mctennis.impl.physic import com.github.shynixn.mcutils.common.Vector3d import com.github.shynixn.mcutils.common.physic.PhysicComponent -import com.github.shynixn.mcutils.common.vector import com.github.shynixn.mcutils.packet.api.meta.enumeration.BlockDirection class BounceComponent( @@ -78,38 +77,38 @@ class BounceComponent( ): Vector3d { val normalVector = when (blockDirection) { BlockDirection.WEST -> { - vector { - x = -1.0 + Vector3d().also { + it.x = -1.0 } } BlockDirection.EAST -> { - vector { - x = 1.0 + Vector3d().also { + it.x = 1.0 } } BlockDirection.NORTH -> { - vector { - z = -1.0 + Vector3d().also{ + it.z = -1.0 } } BlockDirection.SOUTH -> { - vector { - z = 1.0 + Vector3d().also { + it.z = 1.0 } } else -> if (blockDirection == BlockDirection.DOWN) { - vector { - y = -1.0 + Vector3d().also{ + it.y = -1.0 } } else { - vector { - y = 1.0 + Vector3d().also { + it.y = 1.0 } }.normalize() } val radianAngle = 2 * incomingVector.dot(normalVector) - val outgoingVector = incomingVector.clone().subtract(normalVector.multiply(radianAngle)) + val outgoingVector = incomingVector.copy().subtract(normalVector.multiply(radianAngle)) if (blockDirection == BlockDirection.UP) { outgoingVector.y = outgoingVector.y * groundBouncing diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/MathComponent.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/MathComponent.kt index f676191..b138e13 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/MathComponent.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/MathComponent.kt @@ -5,7 +5,6 @@ import com.github.shynixn.mcutils.common.Vector3d import com.github.shynixn.mcutils.common.physic.PhysicComponent import com.github.shynixn.mcutils.common.toLocation import com.github.shynixn.mcutils.common.toVector -import com.github.shynixn.mcutils.common.vector import com.github.shynixn.mcutils.packet.api.RayTraceResult import com.github.shynixn.mcutils.packet.api.RayTracingService import com.github.shynixn.mcutils.packet.api.meta.enumeration.BlockDirection @@ -29,10 +28,10 @@ class MathComponent( /** * Origin coordinate to make relative rotations in the world. */ - private val origin = vector { - x = 0.0 - y = 0.0 - z = -1.0 + private val origin = Vector3d().also { + it.x = 0.0 + it.y = 0.0 + it.z = -1.0 }.normalize() var motion: Vector3d = Vector3d(null, 0.0, 0.0, 0.0) @@ -50,7 +49,7 @@ class MathComponent( */ fun setVelocity(vector: Vector3d) { // Motion per step is the new motion. - this.motion = vector.clone() + this.motion = vector.copy() // Move the object a little up otherwise wallcollision of ground immediately cancel movement. // this.position.y += 0.25 // Correct the yaw of the object after bouncing. @@ -154,7 +153,7 @@ class MathComponent( * Fixes the yaw value after a motion change. */ fun fixYawMotion() { - this.position.yaw = getYawFromVector(origin, this.motion.clone().normalize()) * -1 + this.position.yaw = getYawFromVector(origin, this.motion.copy().normalize()) * -1 this.position.pitch = 0.0 } @@ -173,7 +172,7 @@ class MathComponent( this.motion = this.motion.multiply(settings.airResistanceRelative) // Reduces the motion absolute by a negative normalized value. - val reductionVector = this.motion.clone().normalize().multiply(settings.airResistanceAbsolute) + val reductionVector = this.motion.copy().normalize().multiply(settings.airResistanceAbsolute) reduceVectorIfBiggerZero(this.motion, reductionVector) fixMotionFloatingPoints() @@ -198,7 +197,7 @@ class MathComponent( this.motion = this.motion.multiply(settings.groundResistanceRelative) // Reduces the motion absolute by a negative normalized value. - val reductionVector = this.motion.clone().normalize().multiply(settings.groundResistanceAbsolute) + val reductionVector = this.motion.copy().normalize().multiply(settings.groundResistanceAbsolute) reduceVectorIfBiggerZero(this.motion, reductionVector) fixMotionFloatingPoints() } diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/SpinComponent.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/SpinComponent.kt index 1611caf..f36c54a 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/SpinComponent.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/physic/SpinComponent.kt @@ -2,7 +2,6 @@ package com.github.shynixn.mctennis.impl.physic import com.github.shynixn.mcutils.common.Vector3d import com.github.shynixn.mcutils.common.physic.PhysicComponent -import com.github.shynixn.mcutils.common.vector import kotlin.math.abs import kotlin.math.atan2 import kotlin.math.cos @@ -56,15 +55,15 @@ class SpinComponent( return } - val addVector = vector { - this.x = -motion.z - this.z = motion.x + val addVector = Vector3d().also { + it.x = -motion.z + it.z = motion.x }.multiply(angularVelocity) - this.physicComponent.motion = vector { - x = motion.x + addVector.x - y = motion.y - z = motion.z + addVector.z + this.physicComponent.motion = Vector3d().also { + it.x = motion.x + addVector.x + it.y = motion.y + it.z = motion.z + addVector.z } angularVelocity /= 2 diff --git a/src/main/kotlin/com/github/shynixn/mctennis/impl/service/TennisBallFactoryImpl.kt b/src/main/kotlin/com/github/shynixn/mctennis/impl/service/TennisBallFactoryImpl.kt index 25561d2..64794bd 100644 --- a/src/main/kotlin/com/github/shynixn/mctennis/impl/service/TennisBallFactoryImpl.kt +++ b/src/main/kotlin/com/github/shynixn/mctennis/impl/service/TennisBallFactoryImpl.kt @@ -6,6 +6,7 @@ import com.github.shynixn.mctennis.enumeration.VisibilityType import com.github.shynixn.mctennis.impl.TennisBallImpl import com.github.shynixn.mctennis.entity.MathSettings import com.github.shynixn.mctennis.impl.physic.* +import com.github.shynixn.mcutils.common.item.ItemService import com.github.shynixn.mcutils.common.physic.PhysicObjectService import com.github.shynixn.mcutils.common.sound.SoundService import com.github.shynixn.mcutils.common.toVector3d @@ -24,6 +25,7 @@ class TennisBallFactoryImpl @Inject constructor( private val bedrockService: BedrockService, private val packetService: PacketService, private val rayTracingService: RayTracingService, + private val itemService: ItemService ) : TennisBallFactory { @@ -65,6 +67,8 @@ class TennisBallFactoryImpl @Inject constructor( mathPhysicComponent, packetService, playerComponent, + itemService, + settings, armorStandEntityId, bedrockService.javaPlayers, settings.renderYOffset @@ -75,6 +79,8 @@ class TennisBallFactoryImpl @Inject constructor( mathPhysicComponent, packetService, playerComponent, + itemService, + settings, armorStandEntityId, bedrockService.bedRockPlayers, settings.renderYOffset @@ -85,6 +91,8 @@ class TennisBallFactoryImpl @Inject constructor( mathPhysicComponent, packetService, playerComponent, + itemService, + settings, armorStandEntityId, hashSetOf(), settings.renderYOffset