diff --git a/README.md b/README.md index c131c27d..9a9440ef 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,9 @@ * PersistentData API 접근성 개선 * #### Supported minecraft versions - * 1.18 - * 1.18.1 - * 1.18.2 - * 1.19 - * 1.19.1 - * 1.19.2 - * 1.19.3 - * 1.19.4 - * 1.20 - * 1.20.1 + * 1.21.4 + + --- @@ -48,7 +41,7 @@ repositories { ```kotlin dependencies { - implementation("io.github.monun:tap-api:") + implementation("io.github.highright1234:tap-api:") } ``` @@ -59,19 +52,20 @@ name: ... version: ... main: ... libraries: - - io.github.monun:tap-core: + - io.github.highright1234:tap-core: ``` #### !!주의!! * `Gradle`과 `plugin.yml`의 의존성 패키지가 다르므로 주의해주세요. -* 모든 코드는 ShadowJar를 고려하여 작성되지 않았습니다. +* 기존의 Tap의 경우에는 ShadowJar를 지원하지 않았지만, 현재는 ShadowJar를 지원합니다 --- ### NOTE * 라이센스는 GPL-3.0이며 변경 혹은 삭제를 금합니다. +* 1.20.1 이후의 버전의 지원을 원하시면 issue를 넣어주시거나, 디스코드 `highright_`로 연락해주세요! --- diff --git a/build.gradle.kts b/build.gradle.kts index 6af01844..1a98815f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ subprojects { apply(plugin = "org.jetbrains.kotlin.plugin.serialization") repositories { - maven("https://papermc.io/repo/repository/maven-public/") + maven("https://repo.papermc.io/repository/maven-public/") } dependencies { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84a0b92f..d6e308a6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/tap-api/src/main/kotlin/io/github/monun/tap/fake/PlayerInteractFakeEntityEvent.kt b/tap-api/src/main/kotlin/io/github/monun/tap/fake/PlayerInteractFakeEntityEvent.kt new file mode 100644 index 00000000..d9dde581 --- /dev/null +++ b/tap-api/src/main/kotlin/io/github/monun/tap/fake/PlayerInteractFakeEntityEvent.kt @@ -0,0 +1,24 @@ +package io.github.monun.tap.fake + +import org.bukkit.entity.Entity +import org.bukkit.entity.Player +import org.bukkit.event.HandlerList +import org.bukkit.event.player.PlayerEvent +import org.bukkit.inventory.EquipmentSlot + +class PlayerInteractFakeEntityEvent( + player: Player, + val fakeEntity: FakeEntity, + val isAttack: Boolean, + val hand: EquipmentSlot, +): PlayerEvent(player) { + + val server: FakeEntityServer get() = fakeEntity.server + + companion object { + private val handlerList = HandlerList() + @JvmStatic + fun getHandlerList() = handlerList + } + override fun getHandlers() = handlerList +} \ No newline at end of file diff --git a/tap-api/src/main/kotlin/io/github/monun/tap/util/DamageCalculator.kt b/tap-api/src/main/kotlin/io/github/monun/tap/util/DamageCalculator.kt new file mode 100644 index 00000000..acffc2c9 --- /dev/null +++ b/tap-api/src/main/kotlin/io/github/monun/tap/util/DamageCalculator.kt @@ -0,0 +1,17 @@ +package io.github.monun.tap.util + +import io.github.monun.tap.loader.LibraryLoader +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +interface DamageCalculator { + companion object: DamageCalculator by LibraryLoader.loadNMS(DamageCalculator::class.java) + + /* + * 공격할수 없을시 -1을 리턴함 + */ + fun getDamage(player: Player, target: Entity): Float +} + + +fun Player.getDamage(target: Entity) = DamageCalculator.getDamage(this, target) \ No newline at end of file diff --git a/tap-core/src/main/kotlin/io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt b/tap-core/src/main/kotlin/io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt index bd5f8efe..80db16df 100644 --- a/tap-core/src/main/kotlin/io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt +++ b/tap-core/src/main/kotlin/io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt @@ -17,20 +17,21 @@ package io.github.monun.tap.fake.internal +import com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent import com.destroystokyo.paper.profile.ProfileProperty import com.google.common.collect.ImmutableList import io.github.monun.tap.fake.* +import net.kyori.adventure.text.Component import org.bukkit.Bukkit import org.bukkit.Location import org.bukkit.block.data.BlockData -import org.bukkit.entity.Entity -import org.bukkit.entity.FallingBlock -import org.bukkit.entity.Item -import org.bukkit.entity.Player +import org.bukkit.entity.* import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority import org.bukkit.event.HandlerList import org.bukkit.event.Listener import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.PlayerKickEvent import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.java.JavaPlugin @@ -227,6 +228,34 @@ class FakeEntityServerImpl(plugin: JavaPlugin) : FakeEntityServer { fun onPlayerQuit(event: PlayerQuitEvent) { trackersByPlayer.remove(event.player)?.clear() } + + @EventHandler(priority = EventPriority.HIGH) + fun onInteract(event: PlayerUseUnknownEntityEvent) { + if (event.player !in trackersByPlayer) return + val fakeEntity = entities.find { it.bukkitEntity.entityId == event.entityId } ?: return + val entity = fakeEntity.bukkitEntity + if ( + entity !is Item && + entity !is ExperienceOrb && + entity !is AbstractArrow +// (entity !== event.player || event.player.gameMode == GameMode.SPECTATOR) +// 위에 기능은 카메라 시점기능인데 구현하기 뭐한감이 있어 삭제 + ) { + if (event.isAttack) event.player.resetCooldown() + PlayerInteractFakeEntityEvent( + event.player, + fakeEntity, + event.isAttack, + event.hand + ).callEvent() + } else { + event.player.kick( + Component.translatable("multiplayer.disconnect.invalid_entity_attacked"), + PlayerKickEvent.Cause.INVALID_ENTITY_ATTACKED + ) + Bukkit.getLogger().warning("Player ${event.player.name} tried to attack an invalid entity") + } + } } } diff --git a/tap-dongle/build.gradle.kts b/tap-dongle/build.gradle.kts index b68b4150..32c5f3f6 100644 --- a/tap-dongle/build.gradle.kts +++ b/tap-dongle/build.gradle.kts @@ -1,7 +1,7 @@ import io.papermc.paperweight.tasks.RemapJar plugins { - id("io.papermc.paperweight.userdev") version "1.5.5" apply false + id("io.papermc.paperweight.userdev") version "2.0.0-beta.14" apply false } subprojects { diff --git a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSEntityTypes.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSEntityTypes.kt deleted file mode 100644 index 807d88d7..00000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_1.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_18_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSFakeSupport.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSFakeSupport.kt deleted file mode 100644 index b49de8aa..00000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_1.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_18_1.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_18_R1.CraftServer -import org.bukkit.craftbukkit.v1_18_R1.CraftWorld -import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(UUID.randomUUID(), name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/item/NMSItemSupport.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/item/NMSItemSupport.kt deleted file mode 100644 index 493a6684..00000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_1.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_18_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketContainer.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketContainer.kt deleted file mode 100644 index 018f29ce..00000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_1.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketSupport.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketSupport.kt deleted file mode 100644 index 8bb6f72b..00000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_1.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - - -class NMSPacketSupport : PacketSupport { - - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - /* Modified */ - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSEntityTypes.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSEntityTypes.kt deleted file mode 100644 index bd7329e0..00000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_2.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_18_R2.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSFakeSupport.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSFakeSupport.kt deleted file mode 100644 index 9a408049..00000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_2.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_18_2.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_18_R2.CraftServer -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(UUID.randomUUID(), name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/item/NMSItemSupport.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/item/NMSItemSupport.kt deleted file mode 100644 index 8b26dc5a..00000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_2.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_18_R2.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketContainer.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketContainer.kt deleted file mode 100644 index 030658e1..00000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_2.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketSupport.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketSupport.kt deleted file mode 100644 index fe63694e..00000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18_2.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - /* Modified */ - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSEntityTypes.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSEntityTypes.kt deleted file mode 100644 index b0b6180f..00000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_18_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSFakeSupport.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSFakeSupport.kt deleted file mode 100644 index 2c44e262..00000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_18.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_18_R1.CraftServer -import org.bukkit.craftbukkit.v1_18_R1.CraftWorld -import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(UUID.randomUUID(), name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/item/NMSItemSupport.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/item/NMSItemSupport.kt deleted file mode 100644 index f6628b8b..00000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_18_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketContainer.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketContainer.kt deleted file mode 100644 index 68c30ef8..00000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketSupport.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketSupport.kt deleted file mode 100644 index 2d8b99ea..00000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_18.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - - -class NMSPacketSupport : PacketSupport { - - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - /* Modified */ - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSEntityTypes.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSEntityTypes.kt deleted file mode 100644 index 037e291a..00000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_1.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSFakeSupport.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSFakeSupport.kt deleted file mode 100644 index 79e13967..00000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_1.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_19_1.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(UUID.randomUUID(), name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - }, - null - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/item/NMSItemSupport.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/item/NMSItemSupport.kt deleted file mode 100644 index ffea5fb7..00000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_1.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketContainer.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketContainer.kt deleted file mode 100644 index 301765ec..00000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_1.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketSupport.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketSupport.kt deleted file mode 100644 index 026c14e6..00000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_1.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - /* Modified */ - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSEntityTypes.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSEntityTypes.kt deleted file mode 100644 index 3077ed9a..00000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_2.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSFakeSupport.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSFakeSupport.kt deleted file mode 100644 index 2fbffe97..00000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_2.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_19_2.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(uniqueId, name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - }, - null - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/item/NMSItemSupport.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/item/NMSItemSupport.kt deleted file mode 100644 index 37ab4d85..00000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_2.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketContainer.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketContainer.kt deleted file mode 100644 index b46d2a67..00000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_2.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketSupport.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketSupport.kt deleted file mode 100644 index 8500185a..00000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_2.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSEntityTypes.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSEntityTypes.kt deleted file mode 100644 index 6b463d13..00000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_3.fake - -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_19_R2.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - BuiltInRegistries.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSFakeSupport.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSFakeSupport.kt deleted file mode 100644 index 13b7a985..00000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_3.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_19_3.protocol.NMSPacketContainer -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_19_R2.CraftServer -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld -import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return BuiltInRegistries.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoUpdatePacket( - ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(uniqueId, name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/item/NMSItemSupport.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/item/NMSItemSupport.kt deleted file mode 100644 index e721f62c..00000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_3.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_19_R2.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketContainer.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketContainer.kt deleted file mode 100644 index 8487d293..00000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_3.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketSupport.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketSupport.kt deleted file mode 100644 index 5febe2b6..00000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_3.protocol - -import io.github.monun.tap.protocol.* -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import java.util.* -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - // nonDefaultValues가 null일때 ClientboundSetEntityDataPacket.pack(ClientboundSetEntityDataPacket.java:17) 에서 NPE 발생 - val packet = ClientboundSetEntityDataPacket(entityId, entityData.nonDefaultValues ?: emptyList()) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - if (action == PlayerInfoAction.REMOVE) { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(listOf(player.uniqueId))) - } - - when (action) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - else -> throw IllegalArgumentException("impossible") - }.let { nmsAction -> - return NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoUpdate(action: PlayerInfoUpdateAction, player: Player): PacketContainer { - return when (action) { - PlayerInfoUpdateAction.ADD_PLAYER -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoUpdateAction.INITIALIZE_CHAT -> ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT - PlayerInfoUpdateAction.UPDATE_GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoUpdateAction.UPDATE_LISTED -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED - PlayerInfoUpdateAction.UPDATE_LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoUpdateAction.UPDATE_DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - }.let { nmsAction -> - NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoRemove(list: List): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(list)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSEntityTypes.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSEntityTypes.kt deleted file mode 100644 index 69775803..00000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_4.fake - -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_19_R3.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - BuiltInRegistries.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSFakeSupport.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSFakeSupport.kt deleted file mode 100644 index 5b8d366f..00000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_4.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_19_4.protocol.NMSPacketContainer -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_19_R3.CraftServer -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld -import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return BuiltInRegistries.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoUpdatePacket( - ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(uniqueId, name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/item/NMSItemSupport.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/item/NMSItemSupport.kt deleted file mode 100644 index 44dac4b4..00000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/item/NMSItemSupport.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_4.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_19_R3.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor( - nmsInventory.player.damageSources().lava(), - attackDamage.toFloat(), - Inventory.ALL_ARMOR_SLOTS - ) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketContainer.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketContainer.kt deleted file mode 100644 index 3b236b12..00000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_4.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketSupport.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketSupport.kt deleted file mode 100644 index 67457196..00000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19_4.protocol - -import io.github.monun.tap.protocol.* -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import java.util.* -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - // nonDefaultValues가 null일때 ClientboundSetEntityDataPacket.pack(ClientboundSetEntityDataPacket.java:17) 에서 NPE 발생 - val packet = ClientboundSetEntityDataPacket(entityId, entityData.nonDefaultValues ?: emptyList()) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun hurtAnimation(entityId: Int, yaw: Float): PacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeFloat(yaw) - - val packet = ClientboundHurtAnimationPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - if (action == PlayerInfoAction.REMOVE) { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(listOf(player.uniqueId))) - } - - when (action) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - else -> throw IllegalArgumentException("impossible") - }.let { nmsAction -> - return NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoUpdate(action: PlayerInfoUpdateAction, player: Player): PacketContainer { - return when (action) { - PlayerInfoUpdateAction.ADD_PLAYER -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoUpdateAction.INITIALIZE_CHAT -> ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT - PlayerInfoUpdateAction.UPDATE_GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoUpdateAction.UPDATE_LISTED -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED - PlayerInfoUpdateAction.UPDATE_LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoUpdateAction.UPDATE_DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - }.let { nmsAction -> - NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoRemove(list: List): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(list)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSEntityTypes.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSEntityTypes.kt deleted file mode 100644 index 7e0ab120..00000000 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19.fake - -import net.minecraft.core.Registry -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - - Registry.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSFakeSupport.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSFakeSupport.kt deleted file mode 100644 index 70f2d694..00000000 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_19.protocol.NMSPacketContainer -import net.minecraft.core.Registry -import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_19_R1.CraftServer -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return Registry.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.level = (world as CraftWorld).handle - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoPacket( - ClientboundPlayerInfoPacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(UUID.randomUUID(), name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - }, - null - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/item/NMSItemSupport.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/item/NMSItemSupport.kt deleted file mode 100644 index d74e8a69..00000000 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/item/NMSItemSupport.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor(DamageSource.LAVA, attackDamage.toFloat(), Inventory.ALL_ARMOR_SLOTS) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketSupport.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketSupport.kt deleted file mode 100644 index 84524396..00000000 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_19.protocol - -import io.github.monun.tap.protocol.PacketContainer -import io.github.monun.tap.protocol.PacketSupport -import io.github.monun.tap.protocol.PlayerInfoAction -import io.github.monun.tap.protocol.toProtocolDegrees -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - - /* Modified */ - private fun PlayerInfoAction.toNMS(): ClientboundPlayerInfoPacket.Action { - return when (this) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoPacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoPacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoPacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME - PlayerInfoAction.REMOVE -> ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - val packet = ClientboundSetEntityDataPacket(entityId, entityData, true) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoPacket(action.toNMS(), (player as CraftPlayer).handle)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSEntityTypes.kt b/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSEntityTypes.kt deleted file mode 100644 index 4cd87691..00000000 --- a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSEntityTypes.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20_1.fake - -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.EntityType -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_20_R1.CraftServer -import org.bukkit.entity.Entity as BukkitEntity - -/** - * @author Nemo - */ -internal object NMSEntityTypes { - private val ENTITIES = HashMap, EntityType<*>>() - - init { - val server: MinecraftServer = (Bukkit.getServer() as CraftServer).server - val level = server.allLevels.first() - - BuiltInRegistries.ENTITY_TYPE.forEach { type -> - type.create(level)?.let { entity -> - val bukkitClass = entity.bukkitEntity.javaClass - val interfaces = bukkitClass.interfaces - - ENTITIES[bukkitClass.asSubclass(BukkitEntity::class.java)] = type - - for (i in interfaces) { - if (BukkitEntity::class.java.isAssignableFrom(i)) { - ENTITIES[i.asSubclass(BukkitEntity::class.java)] = type - } - } - } - } - } - - @JvmStatic - fun findType(bukkitClass: Class): EntityType<*> { - return ENTITIES[bukkitClass] ?: error("Unknown entity type $bukkitClass") - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSFakeSupport.kt b/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSFakeSupport.kt deleted file mode 100644 index 5568a724..00000000 --- a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSFakeSupport.kt +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20_1.fake - -import com.destroystokyo.paper.profile.ProfileProperty -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import io.github.monun.tap.fake.FakeSkinParts -import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_20_1.protocol.NMSPacketContainer -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket -import net.minecraft.server.level.ServerPlayer -import net.minecraft.world.entity.item.FallingBlockEntity -import net.minecraft.world.entity.item.ItemEntity -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.World -import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_20_R1.CraftServer -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack -import org.bukkit.entity.* -import org.bukkit.inventory.ItemStack -import java.util.* - -/** - * @author Nemo - */ -class NMSFakeSupport : FakeSupport { - - override fun getNetworkId(entity: Entity): Int { - entity as CraftEntity - - return BuiltInRegistries.ENTITY_TYPE.getId(entity.handle.type) - } - - @Suppress("UNCHECKED_CAST") - override fun createEntity(entityClass: Class, world: World): T { - return NMSEntityTypes.findType(entityClass).run { - val nmsWorld = (world as CraftWorld).handle - this.create(nmsWorld)?.bukkitEntity as T - } - } - - override fun isInvisible(entity: Entity): Boolean { - entity as CraftEntity - val nmsEntity = entity.handle - - return nmsEntity.isInvisible - } - - override fun setInvisible(entity: Entity, invisible: Boolean) { - entity as CraftEntity - val nmsEntity = entity.handle - - nmsEntity.isInvisible = invisible - } - - private val nmsPoses = net.minecraft.world.entity.Pose.values() - override fun setPose(entity: Entity, pose: Pose) { - (entity as CraftEntity).handle.pose = nmsPoses[pose.ordinal] - } - - override fun setLocation( - entity: Entity, - loc: Location - ) { - entity as CraftEntity - val nmsEntity = entity.handle - - loc.run { - nmsEntity.setLevel((world as CraftWorld).handle) - nmsEntity.moveTo(x, y, z, yaw, pitch) - } - } - - override fun getMountedYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.passengersRidingOffset - } - - override fun getYOffset(entity: Entity): Double { - entity as CraftEntity - - return entity.handle.myRidingOffset - } - - /* Modified */ - override fun createSpawnPacket(entity: Entity): Array { - val packets = arrayListOf() - entity as CraftEntity - if (entity is Player) { - packets.add( - NMSPacketContainer( - ClientboundPlayerInfoUpdatePacket( - ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, - entity.handle as ServerPlayer - ) - ) - ) - } - packets.add(NMSPacketContainer(entity.handle.addEntityPacket)) - - return packets.toTypedArray() - } - - override fun createFallingBlock(blockData: BlockData): FallingBlock { - val entity = - FallingBlockEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - (blockData as CraftBlockData).state - ) - - return entity.bukkitEntity as FallingBlock - } - - override fun createItemEntity(item: ItemStack): Item { - val entity = - ItemEntity( - (Bukkit.getWorlds().first() as CraftWorld).handle, - 0.0, - 0.0, - 0.0, - CraftItemStack.asNMSCopy(item) - ) - entity.setNeverPickUp() - - return entity.bukkitEntity as Item - } - - override fun createPlayerEntity( - name: String, - profileProperties: Set, - skinParts: FakeSkinParts, - uniqueId: UUID - ): Player { - val player = ServerPlayer( - (Bukkit.getServer() as CraftServer).handle.server, - (Bukkit.getWorlds().first() as CraftWorld).handle, - GameProfile(uniqueId, name).apply { - for (property in profileProperties) { - val propertyName = property.name - properties.put(propertyName, Property(propertyName, property.value, property.signature)) - } - } - ) - - player.entityData.set( - ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, - skinParts.raw.toByte() - ) - - return player.bukkitEntity - } - - override fun setSkinParts(player: Player, raw: Int) { - (player as CraftPlayer).handle.apply { - entityData.set(ServerPlayer.DATA_PLAYER_MODE_CUSTOMISATION, raw.toByte()) - } - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/item/NMSItemSupport.kt b/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/item/NMSItemSupport.kt deleted file mode 100644 index c524f34a..00000000 --- a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/item/NMSItemSupport.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20_1.item - -import io.github.monun.tap.item.ItemSupport -import net.minecraft.nbt.CompoundTag -import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack as BukkitItemStack -import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory - -class NMSItemSupport : ItemSupport { - override fun saveToJsonString(item: BukkitItemStack): String { - val nmsItem = CraftItemStack.asNMSCopy(item) - return nmsItem.save(CompoundTag()).toString() - } - - override fun damageArmor(playerInventory: BukkitPlayerInventory, attackDamage: Double) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - - nmsInventory.hurtArmor( - nmsInventory.player.damageSources().lava(), - attackDamage.toFloat(), - Inventory.ALL_ARMOR_SLOTS - ) - } - - override fun damageSlot(playerInventory: BukkitPlayerInventory, slot: EquipmentSlot, damage: Int) { - val nmsInventory = (playerInventory as CraftInventoryPlayer).inventory - val nmsSlot = CraftEquipmentSlot.getNMS(slot) - val nmsItem = nmsInventory.getItem(slot) - - if (!nmsItem.isEmpty) { - nmsItem.hurtAndBreak(damage, (playerInventory.holder as CraftPlayer).handle) { player -> - player.broadcastBreakEvent(nmsSlot) - } - } - } -} - -internal fun Inventory.getItem(slot: EquipmentSlot): ItemStack { - return when (slot) { - EquipmentSlot.HAND -> getSelected() - EquipmentSlot.OFF_HAND -> offhand[0] - EquipmentSlot.FEET -> armorContents[0] - EquipmentSlot.LEGS -> armorContents[1] - EquipmentSlot.CHEST -> armorContents[2] - EquipmentSlot.HEAD -> armorContents[3] - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketContainer.kt b/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketContainer.kt deleted file mode 100644 index d1c72c2c..00000000 --- a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20_1.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketContainer.kt b/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketContainer.kt deleted file mode 100644 index a3520402..00000000 --- a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketContainer.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20.protocol - -import io.github.monun.tap.protocol.PacketContainer -import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.entity.Player - - -class NMSPacketContainer(private val packet: Packet<*>) : PacketContainer { - override fun sendTo(player: Player) { - (player as CraftPlayer).handle.connection.send(packet, null) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketSupport.kt b/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketSupport.kt deleted file mode 100644 index 9b93ffdd..00000000 --- a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketSupport.kt +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2023 Monun - * - * 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 - * 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 . - */ - -package io.github.monun.tap.v1_20.protocol - -import io.github.monun.tap.protocol.* -import io.netty.buffer.Unpooled -import it.unimi.dsi.fastutil.ints.IntArrayList -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.protocol.game.* -import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack -import org.bukkit.entity.Entity -import org.bukkit.entity.Player -import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.ItemStack -import org.bukkit.util.Vector -import java.util.* -import net.minecraft.world.entity.EquipmentSlot as NMSEquipmentSlot - -class NMSPacketSupport : PacketSupport { - companion object { - private fun EquipmentSlot.toNMS(): NMSEquipmentSlot { - return when (this) { - EquipmentSlot.HAND -> NMSEquipmentSlot.MAINHAND - EquipmentSlot.OFF_HAND -> NMSEquipmentSlot.OFFHAND - EquipmentSlot.FEET -> NMSEquipmentSlot.FEET - EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS - EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST - EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD - } - } - } - - override fun entityMetadata(entity: Entity): NMSPacketContainer { - entity as CraftEntity - - val entityId = entity.entityId - val entityData = entity.handle.entityData - - // nonDefaultValues가 null일때 ClientboundSetEntityDataPacket.pack(ClientboundSetEntityDataPacket.java:17) 에서 NPE 발생 - val packet = ClientboundSetEntityDataPacket(entityId, entityData.nonDefaultValues ?: emptyList()) - return NMSPacketContainer(packet) - } - - - override fun entityEquipment(entityId: Int, equipments: Map): NMSPacketContainer { - val packet = ClientboundSetEquipmentPacket(entityId, equipments.map { entry -> - com.mojang.datafixers.util.Pair(entry.key.toNMS(), CraftItemStack.asNMSCopy(entry.value)) - }) - return NMSPacketContainer(packet) - } - - override fun entityTeleport( - entityId: Int, - x: Double, - y: Double, - z: Double, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeDouble(x) - byteBuf.writeDouble(y) - byteBuf.writeDouble(z) - byteBuf.writeByte(yaw.toProtocolDegrees()) - byteBuf.writeByte(pitch.toProtocolDegrees()) - byteBuf.writeBoolean(onGround) - - val packet = ClientboundTeleportEntityPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun relEntityMove( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.Pos(entityId, deltaX, deltaY, deltaZ, onGround) - return NMSPacketContainer(packet) - } - - override fun relEntityMoveLook( - entityId: Int, - deltaX: Short, - deltaY: Short, - deltaZ: Short, - yaw: Float, - pitch: Float, - onGround: Boolean - ): NMSPacketContainer { - val packet = ClientboundMoveEntityPacket.PosRot( - entityId, - deltaX, - deltaY, - deltaZ, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - return NMSPacketContainer(packet) - } - - override fun entityRotation(entityId: Int, yaw: Float, pitch: Float, onGround: Boolean): PacketContainer { - return NMSPacketContainer( - ClientboundMoveEntityPacket.Rot( - entityId, - yaw.toProtocolDegrees().toByte(), - pitch.toProtocolDegrees().toByte(), - onGround - ) - ) - } - - override fun entityHeadLook(entityId: Int, yaw: Float): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(yaw.toProtocolDegrees()) - - return NMSPacketContainer(ClientboundRotateHeadPacket(byteBuf)) - } - - override fun entityVelocity(entityId: Int, vector: Vector): NMSPacketContainer { - val packet = ClientboundSetEntityMotionPacket(entityId, Vec3(vector.x, vector.y, vector.z)) - - return NMSPacketContainer(packet) - } - - override fun entityStatus( - entityId: Int, - data: Byte - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeInt(entityId) - byteBuf.writeByte(data.toInt()) - - val packet = ClientboundEntityEventPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun entityAnimation( - entityId: Int, - action: Int - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeByte(action) - - return NMSPacketContainer(ClientboundAnimatePacket(byteBuf)) - } - - override fun hurtAnimation(entityId: Int, yaw: Float): PacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeFloat(yaw) - - val packet = ClientboundHurtAnimationPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun mount( - entityId: Int, - mountEntityIds: IntArray - ): NMSPacketContainer { - val byteBuf = FriendlyByteBuf(Unpooled.buffer()) - - byteBuf.writeVarInt(entityId) - byteBuf.writeVarIntArray(mountEntityIds) - - val packet = ClientboundSetPassengersPacket(byteBuf) - return NMSPacketContainer(packet) - } - - override fun takeItem( - entityId: Int, - collectorId: Int, - stackAmount: Int - ): NMSPacketContainer { - val packet = ClientboundTakeItemEntityPacket(entityId, collectorId, stackAmount) - return NMSPacketContainer(packet) - } - - override fun removeEntity( - entityId: Int - ): NMSPacketContainer { - val packet = ClientboundRemoveEntitiesPacket(entityId) - return NMSPacketContainer(packet) - } - - override fun removeEntities(vararg entityIds: Int): PacketContainer { - return NMSPacketContainer(ClientboundRemoveEntitiesPacket(IntArrayList((entityIds)))) - } - - override fun containerSetSlot(containerId: Int, stateId: Int, slot: Int, item: ItemStack?): NMSPacketContainer { - return NMSPacketContainer( - ClientboundContainerSetSlotPacket( - containerId, - stateId, - slot, - CraftItemStack.asNMSCopy(item) - ) - ) - } - - @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") - override fun playerInfoAction(action: PlayerInfoAction, player: Player): PacketContainer { - if (action == PlayerInfoAction.REMOVE) { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(listOf(player.uniqueId))) - } - - when (action) { - PlayerInfoAction.ADD -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoAction.GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoAction.LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoAction.DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - else -> throw IllegalArgumentException("impossible") - }.let { nmsAction -> - return NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoUpdate(action: PlayerInfoUpdateAction, player: Player): PacketContainer { - return when (action) { - PlayerInfoUpdateAction.ADD_PLAYER -> ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER - PlayerInfoUpdateAction.INITIALIZE_CHAT -> ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT - PlayerInfoUpdateAction.UPDATE_GAME_MODE -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE - PlayerInfoUpdateAction.UPDATE_LISTED -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED - PlayerInfoUpdateAction.UPDATE_LATENCY -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY - PlayerInfoUpdateAction.UPDATE_DISPLAY_NAME -> ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME - }.let { nmsAction -> - NMSPacketContainer(ClientboundPlayerInfoUpdatePacket(nmsAction, (player as CraftPlayer).handle)) - } - } - - override fun playerInfoRemove(list: List): PacketContainer { - return NMSPacketContainer(ClientboundPlayerInfoRemovePacket(list)) - } -} \ No newline at end of file diff --git a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSEntityTypes.kt b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSEntityTypes.kt similarity index 95% rename from tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSEntityTypes.kt rename to tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSEntityTypes.kt index ca44f9a7..25e55257 100644 --- a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSEntityTypes.kt +++ b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSEntityTypes.kt @@ -15,13 +15,13 @@ * along with this program. If not, see . */ -package io.github.monun.tap.v1_20.fake +package io.github.monun.tap.v1_21_4.fake import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.server.MinecraftServer import net.minecraft.world.entity.EntityType import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_20_R1.CraftServer +import org.bukkit.craftbukkit.CraftServer import org.bukkit.entity.Entity as BukkitEntity /** diff --git a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSFakeSupport.kt b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSFakeSupport.kt similarity index 92% rename from tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSFakeSupport.kt rename to tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSFakeSupport.kt index 6d8f4714..abdfad28 100644 --- a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/fake/NMSFakeSupport.kt +++ b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/fake/NMSFakeSupport.kt @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -package io.github.monun.tap.v1_20.fake +package io.github.monun.tap.v1_21_4.fake import com.destroystokyo.paper.profile.ProfileProperty import com.mojang.authlib.GameProfile import com.mojang.authlib.properties.Property import io.github.monun.tap.fake.FakeSkinParts import io.github.monun.tap.fake.FakeSupport -import io.github.monun.tap.v1_20.protocol.NMSPacketContainer +import io.github.monun.tap.v1_21_4.protocol.NMSPacketContainer import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket import net.minecraft.server.level.ServerPlayer @@ -32,12 +32,12 @@ import org.bukkit.Bukkit import org.bukkit.Location import org.bukkit.World import org.bukkit.block.data.BlockData -import org.bukkit.craftbukkit.v1_20_R1.CraftServer -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack +import org.bukkit.craftbukkit.CraftServer +import org.bukkit.craftbukkit.CraftWorld +import org.bukkit.craftbukkit.block.data.CraftBlockData +import org.bukkit.craftbukkit.entity.CraftEntity +import org.bukkit.craftbukkit.entity.CraftPlayer +import org.bukkit.craftbukkit.inventory.CraftItemStack import org.bukkit.entity.* import org.bukkit.inventory.ItemStack import java.util.* diff --git a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/item/NMSItemSupport.kt b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/item/NMSItemSupport.kt similarity index 89% rename from tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/item/NMSItemSupport.kt rename to tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/item/NMSItemSupport.kt index 1a7fdb3c..bd8f178d 100644 --- a/tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/item/NMSItemSupport.kt +++ b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/item/NMSItemSupport.kt @@ -15,16 +15,16 @@ * along with this program. If not, see . */ -package io.github.monun.tap.v1_20.item +package io.github.monun.tap.v1_21_4.item import io.github.monun.tap.item.ItemSupport import net.minecraft.nbt.CompoundTag import net.minecraft.world.entity.player.Inventory import net.minecraft.world.item.ItemStack -import org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack +import org.bukkit.craftbukkit.CraftEquipmentSlot +import org.bukkit.craftbukkit.entity.CraftPlayer +import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer +import org.bukkit.craftbukkit.inventory.CraftItemStack import org.bukkit.inventory.EquipmentSlot import org.bukkit.inventory.ItemStack as BukkitItemStack import org.bukkit.inventory.PlayerInventory as BukkitPlayerInventory diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketContainer.kt b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketContainer.kt similarity index 90% rename from tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketContainer.kt rename to tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketContainer.kt index acf61031..5689638c 100644 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketContainer.kt +++ b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketContainer.kt @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package io.github.monun.tap.v1_19.protocol +package io.github.monun.tap.v1_21_4.protocol import io.github.monun.tap.protocol.PacketContainer import net.minecraft.network.protocol.Packet -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer +import org.bukkit.craftbukkit.entity.CraftPlayer import org.bukkit.entity.Player diff --git a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketSupport.kt b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketSupport.kt similarity index 97% rename from tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketSupport.kt rename to tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketSupport.kt index e31519aa..71edea04 100644 --- a/tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketSupport.kt +++ b/tap-dongle/v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4/protocol/NMSPacketSupport.kt @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package io.github.monun.tap.v1_20_1.protocol +package io.github.monun.tap.v1_21_4.protocol import io.github.monun.tap.protocol.* import io.netty.buffer.Unpooled @@ -23,9 +23,9 @@ import it.unimi.dsi.fastutil.ints.IntArrayList import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.protocol.game.* import net.minecraft.world.phys.Vec3 -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack +import org.bukkit.craftbukkit.entity.CraftEntity +import org.bukkit.craftbukkit.entity.CraftPlayer +import org.bukkit.craftbukkit.inventory.CraftItemStack import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.inventory.EquipmentSlot @@ -44,6 +44,7 @@ class NMSPacketSupport : PacketSupport { EquipmentSlot.LEGS -> NMSEquipmentSlot.LEGS EquipmentSlot.CHEST -> NMSEquipmentSlot.CHEST EquipmentSlot.HEAD -> NMSEquipmentSlot.HEAD + EquipmentSlot.BODY -> NMSEquipmentSlot.BODY } } }