From c7c90202cb5eb9ee4a4860641805d1840db2ea7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= <77767930+highright1234@users.noreply.github.com> Date: Wed, 12 Apr 2023 23:20:30 +0900 Subject: [PATCH 1/6] Add PlayerInteractFakeEntityEvent --- .../tap/fake/PlayerInteractFakeEntityEvent.kt | 24 +++++++++++++++++++ .../tap/fake/internal/FakeEntityServerImpl.kt | 13 ++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tap-api/src/main/kotlin/io/github/monun/tap/fake/PlayerInteractFakeEntityEvent.kt 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 0000000..d9dde58 --- /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-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 bd5f8ef..03c89c4 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,6 +17,7 @@ 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.* @@ -28,6 +29,7 @@ import org.bukkit.entity.FallingBlock import org.bukkit.entity.Item import org.bukkit.entity.Player 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 @@ -227,6 +229,17 @@ class FakeEntityServerImpl(plugin: JavaPlugin) : FakeEntityServer { fun onPlayerQuit(event: PlayerQuitEvent) { trackersByPlayer.remove(event.player)?.clear() } + + @EventHandler(priority = EventPriority.HIGH) + fun onInteract(event: PlayerUseUnknownEntityEvent) { + val fakeEntity = entities.find { it.bukkitEntity.entityId == event.entityId } ?: return + PlayerInteractFakeEntityEvent( + event.player, + fakeEntity, + event.isAttack, + event.hand + ).callEvent() + } } } From 88967072d4b5e69db586aa9b22d9e2da24840bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= <77767930+highright1234@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:11:56 +0900 Subject: [PATCH 2/6] PlayerInteractFakeEntityEvent filtering players --- .../io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt | 1 + 1 file changed, 1 insertion(+) 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 03c89c4..11e72c6 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 @@ -232,6 +232,7 @@ class FakeEntityServerImpl(plugin: JavaPlugin) : FakeEntityServer { @EventHandler(priority = EventPriority.HIGH) fun onInteract(event: PlayerUseUnknownEntityEvent) { + if (event.player !in trackersByPlayer) return val fakeEntity = entities.find { it.bukkitEntity.entityId == event.entityId } ?: return PlayerInteractFakeEntityEvent( event.player, From c8d6038472902e44a6f36f08984218f0fcf91980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= <77767930+highright1234@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:33:27 +0900 Subject: [PATCH 3/6] PlayerInteractFakeEntityEvent filtering entity-type --- .../tap/fake/internal/FakeEntityServerImpl.kt | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) 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 11e72c6..fe5f4bf 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 @@ -21,18 +21,17 @@ 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 @@ -234,12 +233,27 @@ class FakeEntityServerImpl(plugin: JavaPlugin) : FakeEntityServer { fun onInteract(event: PlayerUseUnknownEntityEvent) { if (event.player !in trackersByPlayer) return val fakeEntity = entities.find { it.bukkitEntity.entityId == event.entityId } ?: return - PlayerInteractFakeEntityEvent( - event.player, - fakeEntity, - event.isAttack, - event.hand - ).callEvent() + val entity = fakeEntity.bukkitEntity + if ( + entity !is Item && + entity !is ExperienceOrb && + entity !is AbstractArrow +// (entity !== event.player || event.player.gameMode == GameMode.SPECTATOR) +// 위에 기능은 카메라 시점기능인데 구현하기 뭐한감이 있어 삭제 + ) { + 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") + } } } } From d6e15137899b550f1614d7d80e81f143e5bfb8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= <77767930+highright1234@users.noreply.github.com> Date: Sat, 22 Apr 2023 12:32:14 +0900 Subject: [PATCH 4/6] Add DamageCalculator --- .../github/monun/tap/util/DamageCalculator.kt | 17 +++++ .../tap/v1_18_1/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_18_2/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_18/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_19_1/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_19_2/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_19_3/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_19_4/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ .../tap/v1_19/util/NMSDamageCalculator.kt | 62 +++++++++++++++++++ 9 files changed, 513 insertions(+) create mode 100644 tap-api/src/main/kotlin/io/github/monun/tap/util/DamageCalculator.kt create mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt create mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt 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 0000000..acffc2c --- /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-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..a5ee7b1 --- /dev/null +++ b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_18_1.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..a6895b0 --- /dev/null +++ b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_18_2.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..25259df --- /dev/null +++ b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_18.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..0677457 --- /dev/null +++ b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_19_1.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..9078e71 --- /dev/null +++ b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_19_2.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..d729353 --- /dev/null +++ b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_19_3.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..c9490ad --- /dev/null +++ b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_19_4.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + val damageSources = playerHandle.damageSources() + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + damageSources.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = 0f + + } + return attackDamage + } +} \ No newline at end of file diff --git a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt new file mode 100644 index 0000000..a3d2d2f --- /dev/null +++ b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt @@ -0,0 +1,62 @@ +package io.github.monun.tap.v1_19.util + +import io.github.monun.tap.util.DamageCalculator +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.effect.MobEffects +import net.minecraft.world.entity.ai.attributes.Attributes +import net.minecraft.world.item.enchantment.EnchantmentHelper +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer +import org.bukkit.entity.Entity +import org.bukkit.entity.Player + +class NMSDamageCalculator: DamageCalculator { + override fun getDamage(player: Player, target: Entity): Float { + + player as CraftPlayer + target as CraftLivingEntity + + val playerHandle = player.handle + val targetHandle = target.handle + + var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() + + var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) + + val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) + + + attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f + damageBonus *= attackStrengthScale + if (attackDamage > 0.0f || damageBonus > 0.0f) { + val isCharged = attackStrengthScale > 0.9f + var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) + if (playerHandle.isSprinting && isCharged) { + ++knockBackBonus + } + var isCrit = isCharged && + playerHandle.fallDistance > 0.0f && + !playerHandle.onGround && + !playerHandle.onClimbable() && + !playerHandle.isInWater && + !playerHandle.hasEffect(MobEffects.BLINDNESS) && + !playerHandle.isPassenger + + isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits + isCrit = isCrit && !playerHandle.isSprinting + if (isCrit) { + attackDamage *= 1.5f + } + attackDamage += damageBonus + + + val canHurt: Boolean = !targetHandle.isInvulnerableTo( + DamageSource.playerAttack(playerHandle).critical(isCrit) + ) + + if (!canHurt) attackDamage = -1f + + } + return attackDamage + } +} \ No newline at end of file From 2664eeed324a40f5634301f88a7781effae12b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8A=B8?= <77767930+highright1234@users.noreply.github.com> Date: Sat, 22 Apr 2023 14:38:26 +0900 Subject: [PATCH 5/6] reset cool-down when a player clicked fake-entity --- .../io/github/monun/tap/fake/internal/FakeEntityServerImpl.kt | 1 + 1 file changed, 1 insertion(+) 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 fe5f4bf..80db16d 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 @@ -241,6 +241,7 @@ class FakeEntityServerImpl(plugin: JavaPlugin) : FakeEntityServer { // (entity !== event.player || event.player.gameMode == GameMode.SPECTATOR) // 위에 기능은 카메라 시점기능인데 구현하기 뭐한감이 있어 삭제 ) { + if (event.isAttack) event.player.resetCooldown() PlayerInteractFakeEntityEvent( event.player, fakeEntity, From e21af942bee282090aa02ed958cef4abdb73aac3 Mon Sep 17 00:00:00 2001 From: highright1234 Date: Fri, 21 Feb 2025 00:23:34 +0900 Subject: [PATCH 6/6] Update(NMS is not fixed) --- README.md | 20 +- build.gradle.kts | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- tap-dongle/build.gradle.kts | 2 +- .../monun/tap/v1_18_1/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_18_1/fake/NMSFakeSupport.kt | 185 ------------- .../monun/tap/v1_18_1/item/NMSItemSupport.kt | 67 ----- .../v1_18_1/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_18_1/protocol/NMSPacketSupport.kt | 236 ---------------- .../tap/v1_18_1/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_18_2/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_18_2/fake/NMSFakeSupport.kt | 186 ------------- .../monun/tap/v1_18_2/item/NMSItemSupport.kt | 67 ----- .../v1_18_2/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_18_2/protocol/NMSPacketSupport.kt | 235 ---------------- .../tap/v1_18_2/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_18/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_18/fake/NMSFakeSupport.kt | 185 ------------- .../monun/tap/v1_18/item/NMSItemSupport.kt | 67 ----- .../tap/v1_18/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_18/protocol/NMSPacketSupport.kt | 236 ---------------- .../tap/v1_18/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_19_1/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_19_1/fake/NMSFakeSupport.kt | 186 ------------- .../monun/tap/v1_19_1/item/NMSItemSupport.kt | 67 ----- .../v1_19_1/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_19_1/protocol/NMSPacketSupport.kt | 235 ---------------- .../tap/v1_19_1/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_19_2/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_19_2/fake/NMSFakeSupport.kt | 185 ------------- .../monun/tap/v1_19_2/item/NMSItemSupport.kt | 67 ----- .../v1_19_2/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_19_2/protocol/NMSPacketSupport.kt | 233 ---------------- .../tap/v1_19_2/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_19_3/fake/NMSEntityTypes.kt | 57 ---- .../monun/tap/v1_19_3/fake/NMSFakeSupport.kt | 184 ------------ .../monun/tap/v1_19_3/item/NMSItemSupport.kt | 67 ----- .../v1_19_3/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_19_3/protocol/NMSPacketSupport.kt | 252 ----------------- .../tap/v1_19_3/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_19_4/fake/NMSEntityTypes.kt | 57 ---- .../monun/tap/v1_19_4/fake/NMSFakeSupport.kt | 184 ------------ .../monun/tap/v1_19_4/item/NMSItemSupport.kt | 70 ----- .../v1_19_4/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_19_4/protocol/NMSPacketSupport.kt | 262 ------------------ .../tap/v1_19_4/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_19/fake/NMSEntityTypes.kt | 58 ---- .../monun/tap/v1_19/fake/NMSFakeSupport.kt | 186 ------------- .../monun/tap/v1_19/item/NMSItemSupport.kt | 67 ----- .../tap/v1_19/protocol/NMSPacketSupport.kt | 235 ---------------- .../tap/v1_19/util/NMSDamageCalculator.kt | 62 ----- .../monun/tap/v1_20_1/fake/NMSEntityTypes.kt | 57 ---- .../monun/tap/v1_20_1/fake/NMSFakeSupport.kt | 184 ------------ .../monun/tap/v1_20_1/item/NMSItemSupport.kt | 70 ----- .../v1_20_1/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_20/protocol/NMSPacketContainer.kt | 30 -- .../tap/v1_20/protocol/NMSPacketSupport.kt | 262 ------------------ .../monun/tap/v1_21_4}/fake/NMSEntityTypes.kt | 4 +- .../monun/tap/v1_21_4}/fake/NMSFakeSupport.kt | 16 +- .../monun/tap/v1_21_4}/item/NMSItemSupport.kt | 10 +- .../v1_21_4}/protocol/NMSPacketContainer.kt | 4 +- .../tap/v1_21_4}/protocol/NMSPacketSupport.kt | 9 +- 62 files changed, 32 insertions(+), 5782 deletions(-) delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/protocol/NMSPacketSupport.kt delete mode 100644 tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt delete mode 100644 tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSEntityTypes.kt delete mode 100644 tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/fake/NMSFakeSupport.kt delete mode 100644 tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/item/NMSItemSupport.kt delete mode 100644 tap-dongle/v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketContainer.kt delete mode 100644 tap-dongle/v1.20/src/main/kotlin/io/github/monun/tap/v1_20/protocol/NMSPacketSupport.kt rename tap-dongle/{v1.20/src/main/kotlin/io/github/monun/tap/v1_20 => v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4}/fake/NMSEntityTypes.kt (95%) rename tap-dongle/{v1.20/src/main/kotlin/io/github/monun/tap/v1_20 => v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4}/fake/NMSFakeSupport.kt (92%) rename tap-dongle/{v1.20/src/main/kotlin/io/github/monun/tap/v1_20 => v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4}/item/NMSItemSupport.kt (89%) rename tap-dongle/{v1.19/src/main/kotlin/io/github/monun/tap/v1_19 => v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4}/protocol/NMSPacketContainer.kt (90%) rename tap-dongle/{v1.20.1/src/main/kotlin/io/github/monun/tap/v1_20_1 => v1.21.4/src/main/kotlin/io/github/monun/tap/v1_21_4}/protocol/NMSPacketSupport.kt (97%) diff --git a/README.md b/README.md index c131c27..9a9440e 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 6af0184..1a98815 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 84a0b92..d6e308a 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-dongle/build.gradle.kts b/tap-dongle/build.gradle.kts index b68b415..32c5f3f 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 807d88d..0000000 --- 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 b49de8a..0000000 --- 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 493a668..0000000 --- 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 018f29c..0000000 --- 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 8bb6f72..0000000 --- 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.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt b/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt deleted file mode 100644 index a5ee7b1..0000000 --- a/tap-dongle/v1.18.1/src/main/kotlin/io/github/monun/tap/v1_18_1/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_18_1.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 bd7329e..0000000 --- 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 9a40804..0000000 --- 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 8b26dc5..0000000 --- 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 030658e..0000000 --- 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 fe63694..0000000 --- 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.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt b/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt deleted file mode 100644 index a6895b0..0000000 --- a/tap-dongle/v1.18.2/src/main/kotlin/io/github/monun/tap/v1_18_2/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_18_2.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 b0b6180..0000000 --- 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 2c44e26..0000000 --- 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 f6628b8..0000000 --- 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 68c30ef..0000000 --- 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 2d8b99e..0000000 --- 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.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt b/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt deleted file mode 100644 index 25259df..0000000 --- a/tap-dongle/v1.18/src/main/kotlin/io/github/monun/tap/v1_18/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_18.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 037e291..0000000 --- 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 79e1396..0000000 --- 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 ffea5fb..0000000 --- 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 301765e..0000000 --- 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 026c14e..0000000 --- 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.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt deleted file mode 100644 index 0677457..0000000 --- a/tap-dongle/v1.19.1/src/main/kotlin/io/github/monun/tap/v1_19_1/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_19_1.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 3077ed9..0000000 --- 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 2fbffe9..0000000 --- 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 37ab4d8..0000000 --- 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 b46d2a6..0000000 --- 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 8500185..0000000 --- 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.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt deleted file mode 100644 index 9078e71..0000000 --- a/tap-dongle/v1.19.2/src/main/kotlin/io/github/monun/tap/v1_19_2/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_19_2.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 6b463d1..0000000 --- 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 13b7a98..0000000 --- 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 e721f62..0000000 --- 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 8487d29..0000000 --- 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 5febe2b..0000000 --- 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.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt deleted file mode 100644 index d729353..0000000 --- a/tap-dongle/v1.19.3/src/main/kotlin/io/github/monun/tap/v1_19_3/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_19_3.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 6977580..0000000 --- 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 5b8d366..0000000 --- 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 44dac4b..0000000 --- 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 3b236b1..0000000 --- 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 6745719..0000000 --- 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.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt b/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt deleted file mode 100644 index c9490ad..0000000 --- a/tap-dongle/v1.19.4/src/main/kotlin/io/github/monun/tap/v1_19_4/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_19_4.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - val damageSources = playerHandle.damageSources() - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - damageSources.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = 0f - - } - return attackDamage - } -} \ 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 7e0ab12..0000000 --- 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 70f2d69..0000000 --- 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 d74e8a6..0000000 --- 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 8452439..0000000 --- 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.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt b/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt deleted file mode 100644 index a3d2d2f..0000000 --- a/tap-dongle/v1.19/src/main/kotlin/io/github/monun/tap/v1_19/util/NMSDamageCalculator.kt +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.monun.tap.v1_19.util - -import io.github.monun.tap.util.DamageCalculator -import net.minecraft.world.damagesource.DamageSource -import net.minecraft.world.effect.MobEffects -import net.minecraft.world.entity.ai.attributes.Attributes -import net.minecraft.world.item.enchantment.EnchantmentHelper -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Entity -import org.bukkit.entity.Player - -class NMSDamageCalculator: DamageCalculator { - override fun getDamage(player: Player, target: Entity): Float { - - player as CraftPlayer - target as CraftLivingEntity - - val playerHandle = player.handle - val targetHandle = target.handle - - var attackDamage = playerHandle.getAttributeValue(Attributes.ATTACK_DAMAGE).toFloat() - - var damageBonus = EnchantmentHelper.getDamageBonus(playerHandle.mainHandItem, targetHandle.mobType) - - val attackStrengthScale = playerHandle.getAttackStrengthScale(0.5f) - - - attackDamage *= 0.2f + attackStrengthScale * attackStrengthScale * 0.8f - damageBonus *= attackStrengthScale - if (attackDamage > 0.0f || damageBonus > 0.0f) { - val isCharged = attackStrengthScale > 0.9f - var knockBackBonus = EnchantmentHelper.getKnockbackBonus(playerHandle) - if (playerHandle.isSprinting && isCharged) { - ++knockBackBonus - } - var isCrit = isCharged && - playerHandle.fallDistance > 0.0f && - !playerHandle.onGround && - !playerHandle.onClimbable() && - !playerHandle.isInWater && - !playerHandle.hasEffect(MobEffects.BLINDNESS) && - !playerHandle.isPassenger - - isCrit = isCrit && !playerHandle.level.paperConfig().entities.behavior.disablePlayerCrits - isCrit = isCrit && !playerHandle.isSprinting - if (isCrit) { - attackDamage *= 1.5f - } - attackDamage += damageBonus - - - val canHurt: Boolean = !targetHandle.isInvulnerableTo( - DamageSource.playerAttack(playerHandle).critical(isCrit) - ) - - if (!canHurt) attackDamage = -1f - - } - return attackDamage - } -} \ 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 4cd8769..0000000 --- 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 5568a72..0000000 --- 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 c524f34..0000000 --- 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 d1c72c2..0000000 --- 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 a352040..0000000 --- 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 9b93ffd..0000000 --- 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 ca44f9a..25e5525 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 6d8f471..abdfad2 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 1a7fdb3..bd8f178 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 acf6103..5689638 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 e31519a..71edea0 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 } } }