From 06cf396851d0a799805f282ca04b99a6bef8f824 Mon Sep 17 00:00:00 2001 From: unldenis Date: Sun, 3 Nov 2024 14:29:31 +0100 Subject: [PATCH] adding opt packetevents support --- holoeasy-core/pom.xml | 19 + .../src/main/kotlin/org/holoeasy/HoloEasy.kt | 15 +- .../org/holoeasy/animation/Animations.kt | 10 +- .../kotlin/org/holoeasy/line/BlockLine.kt | 15 +- .../main/kotlin/org/holoeasy/line/ItemLine.kt | 12 +- .../src/main/kotlin/org/holoeasy/line/Line.kt | 21 +- .../main/kotlin/org/holoeasy/line/TextLine.kt | 21 +- .../kotlin/org/holoeasy/packet/IPacket.kt | 98 +--- .../org/holoeasy/packet/PacketBuilder.kt | 9 +- .../holoeasy/packet/PacketEventsPackets.kt | 207 +++++++++ .../kotlin/org/holoeasy/packet/PacketImpl.kt | 10 + .../org/holoeasy/packet/ProtocolLibPackets.kt | 418 ++++++++++++++++++ .../holoeasy/packet/delete/DeletePacketA.kt | 20 - .../holoeasy/packet/delete/DeletePacketB.kt | 19 - .../holoeasy/packet/delete/IDeletePacket.kt | 9 - .../packet/equipment/EquipmentPacketA.kt | 28 -- .../packet/equipment/EquipmentPacketB.kt | 28 -- .../packet/equipment/EquipmentPacketC.kt | 30 -- .../packet/equipment/IEquipmentPacket.kt | 10 - .../metadata/item/IMetadataItemPacket.kt | 9 - .../metadata/item/MetadataItemPacketA.kt | 34 -- .../metadata/item/MetadataItemPacketB.kt | 31 -- .../metadata/item/MetadataItemPacketC.kt | 32 -- .../metadata/item/MetadataItemPacketD.kt | 47 -- .../metadata/item/MetadataItemPacketE.kt | 36 -- .../metadata/text/IMetadataTextPacket.kt | 9 - .../metadata/text/MetadataTextPacketA.kt | 33 -- .../metadata/text/MetadataTextPacketB.kt | 36 -- .../metadata/text/MetadataTextPacketC.kt | 34 -- .../metadata/text/MetadataTextPacketD.kt | 35 -- .../metadata/text/MetadataTextPacketE.kt | 61 --- .../holoeasy/packet/rotate/IRotatePacket.kt | 9 - .../holoeasy/packet/rotate/RotatePacketA.kt | 22 - .../org/holoeasy/packet/spawn/ISpawnPacket.kt | 15 - .../org/holoeasy/packet/spawn/SpawnPacketA.kt | 55 --- .../org/holoeasy/packet/spawn/SpawnPacketB.kt | 39 -- .../org/holoeasy/packet/spawn/SpawnPacketC.kt | 73 --- .../org/holoeasy/packet/spawn/SpawnPacketD.kt | 33 -- .../packet/teleport/ITeleportPacket.kt | 9 - .../packet/teleport/TeleportPacketA.kt | 29 -- .../packet/teleport/TeleportPacketB.kt | 33 -- .../packet/velocity/IVelocityPacket.kt | 9 - .../packet/velocity/VelocityPacketA.kt | 24 - .../kotlin/org/holoeasy/util/Serializers.kt | 5 + .../pom.xml | 17 +- .../org/holoeasy/plugin/ExamplePlugin.java | 23 +- .../holoeasy/plugin/HelloWorldHologram.java | 0 .../src/main/resources/plugin.yml | 1 - .../pom.xml | 2 +- .../src/main/kotlin/ExamplePlugin.kt | 6 +- .../src/main/kotlin/HelloWorldHologram.kt | 2 + .../src/main/resources/plugin.yml | 0 pom.xml | 4 +- 53 files changed, 764 insertions(+), 1042 deletions(-) create mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketEventsPackets.kt create mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketImpl.kt create mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/ProtocolLibPackets.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/IDeletePacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketC.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/IEquipmentPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/IRotatePacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/RotatePacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/ISpawnPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketC.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketD.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/ITeleportPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketA.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketB.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/IVelocityPacket.kt delete mode 100644 holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/VelocityPacketA.kt rename {holoeasy-example => holoeasy-example-packetevents}/pom.xml (81%) rename {holoeasy-example => holoeasy-example-packetevents}/src/main/java/org/holoeasy/plugin/ExamplePlugin.java (75%) rename {holoeasy-example => holoeasy-example-packetevents}/src/main/java/org/holoeasy/plugin/HelloWorldHologram.java (100%) rename {holoeasy-example => holoeasy-example-packetevents}/src/main/resources/plugin.yml (83%) rename {holoeasy-example-kotlin => holoeasy-example-protocollib}/pom.xml (98%) rename {holoeasy-example-kotlin => holoeasy-example-protocollib}/src/main/kotlin/ExamplePlugin.kt (90%) rename {holoeasy-example-kotlin => holoeasy-example-protocollib}/src/main/kotlin/HelloWorldHologram.kt (85%) rename {holoeasy-example-kotlin => holoeasy-example-protocollib}/src/main/resources/plugin.yml (100%) diff --git a/holoeasy-core/pom.xml b/holoeasy-core/pom.xml index 924a43f..84273bc 100644 --- a/holoeasy-core/pom.xml +++ b/holoeasy-core/pom.xml @@ -19,6 +19,7 @@ + dmulloy2-repo https://repo.dmulloy2.net/repository/public/ @@ -28,6 +29,16 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + codemc-releases + https://repo.codemc.io/repository/maven-releases/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + @@ -146,6 +157,14 @@ provided + + + com.github.retrooper + packetevents-spigot + 2.5.0 + provided + + diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/HoloEasy.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/HoloEasy.kt index 4dfee2b..99f65fb 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/HoloEasy.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/HoloEasy.kt @@ -4,6 +4,8 @@ package org.holoeasy import org.bukkit.plugin.Plugin import org.holoeasy.action.ClickAction import org.holoeasy.hologram.Hologram +import org.holoeasy.packet.IPacket +import org.holoeasy.packet.PacketImpl import org.holoeasy.pool.HologramPool import org.holoeasy.pool.IHologramPool import org.holoeasy.pool.InteractiveHologramPool @@ -13,6 +15,8 @@ object HoloEasy { private var PLUGIN: Plugin? = null + private var PACKET_IMPL : IPacket? = null + fun plugin(): Plugin { if (PLUGIN == null) { throw IllegalStateException("HoloEasy Plugin is not set") @@ -20,9 +24,18 @@ object HoloEasy { return PLUGIN!! } + fun packetImpl() : IPacket { + if (PACKET_IMPL == null) { + throw IllegalStateException("HoloEasy PacketImpl is not set") + } + return PACKET_IMPL!! + } + @JvmStatic - fun bind(plugin: Plugin) { + @JvmOverloads + fun bind(plugin: Plugin, packetImpl : PacketImpl = PacketImpl.ProtocolLib) { this.PLUGIN = plugin + this.PACKET_IMPL = packetImpl.impl } @JvmStatic diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/animation/Animations.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/animation/Animations.kt index 0680227..ae34623 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/animation/Animations.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/animation/Animations.kt @@ -1,13 +1,10 @@ package org.holoeasy.animation import org.bukkit.Bukkit -import org.bukkit.scheduler.BukkitScheduler import org.bukkit.scheduler.BukkitTask import org.holoeasy.HoloEasy -import org.holoeasy.ext.send import org.holoeasy.line.ILine -import org.holoeasy.packet.PacketType enum class Animations(val task : (ILine<*>) -> BukkitTask) { @@ -17,10 +14,13 @@ enum class Animations(val task : (ILine<*>) -> BukkitTask) { Bukkit.getScheduler().runTaskTimerAsynchronously(HoloEasy.plugin(), java.lang.Runnable { - val packet = PacketType.ROTATE.rotate(line.entityId, yaw = yaw) + holo.pvt.seeingPlayers.forEach { player -> - packet.send(player) + + HoloEasy.packetImpl() + .rotate(player, line.entityId, yaw = yaw) + } yaw += 10 diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/line/BlockLine.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/line/BlockLine.kt index 5882b06..746e49f 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/line/BlockLine.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/line/BlockLine.kt @@ -5,12 +5,8 @@ import org.bukkit.Location import org.bukkit.entity.EntityType import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.send -import org.holoeasy.packet.PacketType +import org.holoeasy.HoloEasy import org.holoeasy.reactive.MutableState -import org.holoeasy.util.VersionEnum -import org.holoeasy.util.VersionUtil class BlockLine(obj: MutableState) : ILine { constructor(obj: ItemStack) : this(MutableState(obj)) @@ -41,8 +37,9 @@ class BlockLine(obj: MutableState) : ILine { override fun show(player: Player) { line.spawn(player) - PacketType.METADATA_TEXT - .metadata(entityId, nameTag = null, invisible = true).send(player) + + HoloEasy.packetImpl() + .metadataText(player, entityId, nameTag = null, invisible = true) this.update(player) @@ -61,8 +58,8 @@ class BlockLine(obj: MutableState) : ILine { } override fun update(player: Player) { - PacketType.EQUIPMENT - .equip(entityId, helmet = _mutableStateOf.get()).send(player) + HoloEasy.packetImpl() + .metadataItem(player, entityId, item = _mutableStateOf.get()) } } diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/line/ItemLine.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/line/ItemLine.kt index 0fe33fc..66d4332 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/line/ItemLine.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/line/ItemLine.kt @@ -5,9 +5,7 @@ import org.bukkit.Location import org.bukkit.entity.EntityType import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.send -import org.holoeasy.packet.PacketType +import org.holoeasy.HoloEasy import org.holoeasy.reactive.MutableState import org.holoeasy.util.VersionEnum import org.holoeasy.util.VersionUtil @@ -23,7 +21,6 @@ class ItemLine(item: MutableState) : ILine { } private val line: Line = Line(EntityType.DROPPED_ITEM) - private val resetVelocity = PacketType.VELOCITY.velocity(line.entityID, 0, 0,0) private val _mutableStateOf = item private var firstRender = true @@ -51,7 +48,8 @@ class ItemLine(item: MutableState) : ILine { line.spawn(player) this.update(player) - resetVelocity.send(player) + HoloEasy.packetImpl() + .velocity(player, line.entityID, 0.0, 0.0,0.0) if(firstRender) { firstRender = false @@ -68,8 +66,8 @@ class ItemLine(item: MutableState) : ILine { } override fun update(player: Player) { - PacketType.METADATA_ITEM - .metadata(entityId, obj).send(player) + HoloEasy.packetImpl() + .metadataItem(player, entityId, item = obj) } } diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/line/Line.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/line/Line.kt index 2e1abb6..7d6ea71 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/line/Line.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/line/Line.kt @@ -1,14 +1,9 @@ package org.holoeasy.line -import com.comphenix.protocol.events.PacketContainer import org.bukkit.Location import org.bukkit.entity.EntityType import org.bukkit.entity.Player -import org.bukkit.plugin.Plugin import org.holoeasy.HoloEasy -import org.holoeasy.ext.invoke -import org.holoeasy.packet.IPacket -import org.holoeasy.packet.PacketType import java.util.* import java.util.concurrent.atomic.AtomicInteger @@ -17,25 +12,21 @@ class Line( private val entityType: EntityType, var location: Location? = null) companion object { val IDs_COUNTER = AtomicInteger(Random().nextInt()) } - val plugin: Plugin = HoloEasy.plugin() val entityID: Int = IDs_COUNTER.getAndIncrement() - private val entityDestroyPacket : PacketContainer = PacketType.DELETE.delete(entityID) fun destroy(player: Player) { - entityDestroyPacket(player) + HoloEasy.packetImpl() + .deletePacket(player, entityID) } fun spawn(player: Player) { - val packet = PacketType.SPAWN - .spawn(entityID, entityType, location ?: throw RuntimeException("Forgot the location?"), plugin) - packet(player) + HoloEasy.packetImpl() + .spawn(player, entityID, entityType,location ?: throw RuntimeException("Forgot the location?") ) } fun teleport(player: Player) { - - val packet = PacketType.TELEPORT - .teleport(entityID, location ?: throw RuntimeException("Forgot the location?")) - packet(player) + HoloEasy.packetImpl() + .teleport(player, entityID, location ?: throw RuntimeException("Forgot the location?")) } diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/line/TextLine.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/line/TextLine.kt index f8ccf26..564e4ad 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/line/TextLine.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/line/TextLine.kt @@ -3,13 +3,9 @@ package org.holoeasy.line import org.bukkit.Location import org.bukkit.entity.EntityType import org.bukkit.entity.Player -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.send -import org.holoeasy.packet.IPacket -import org.holoeasy.packet.PacketType +import org.holoeasy.HoloEasy import org.holoeasy.reactive.MutableState import org.holoeasy.util.AABB -import java.util.LinkedHashMap class TextLine( obj: String, @@ -90,8 +86,9 @@ class TextLine( isEmpty = obj.isEmpty() if (!isEmpty) { line.spawn(player) - val packet = PacketType.METADATA_TEXT.metadata(entityId, parse(player)) - packet.send(player) + + HoloEasy.packetImpl() + .metadataText(player, entityId, nameTag = parse(player)) } } @@ -119,14 +116,14 @@ class TextLine( 0x01 -> { line.spawn(player) isEmpty = false - PacketType.METADATA_TEXT - .metadata(entityId, parse(player)).send(player) + + HoloEasy.packetImpl() + .metadataText(player, entityId, nameTag = parse(player)) } 0x00 -> - PacketType.METADATA_TEXT - .metadata(entityId, parse(player), invisible = false) - .send(player) + HoloEasy.packetImpl() + .metadataText(player, entityId, nameTag = parse(player), invisible = false) } } diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/IPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/IPacket.kt index 064164c..4d52cff 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/IPacket.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/IPacket.kt @@ -1,101 +1,27 @@ package org.holoeasy.packet -import org.holoeasy.HoloEasy -import org.holoeasy.packet.delete.DeletePacketA -import org.holoeasy.packet.delete.DeletePacketB -import org.holoeasy.packet.equipment.EquipmentPacketA -import org.holoeasy.packet.equipment.EquipmentPacketB -import org.holoeasy.packet.equipment.EquipmentPacketC -import org.holoeasy.packet.equipment.IEquipmentPacket -import org.holoeasy.packet.metadata.item.* -import org.holoeasy.packet.metadata.text.* -import org.holoeasy.packet.rotate.IRotatePacket -import org.holoeasy.packet.rotate.RotatePacketA -import org.holoeasy.packet.spawn.* -import org.holoeasy.packet.teleport.TeleportPacketA -import org.holoeasy.packet.teleport.TeleportPacketB -import org.holoeasy.packet.velocity.IVelocityPacket -import org.holoeasy.packet.velocity.VelocityPacketA -import org.holoeasy.util.VersionEnum -import org.holoeasy.util.VersionUtil +import org.bukkit.Location +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack interface IPacket { - val versionSupport: Array> + fun deletePacket(player: Player, entityId: Int) - fun isCurrentVersion(): Boolean { - for (range in versionSupport) { - if (VersionUtil.CLEAN_VERSION in range) { - return true - } - } - return false - } + fun equip(player: Player, entityId : Int, helmet : ItemStack) -} + fun metadataItem(player: Player,entityId: Int, item: ItemStack) + fun metadataText(player: Player, entityId: Int, nameTag: String?, invisible : Boolean = true) -object PacketType { - private fun getCurrImpl(vararg impls: T): T { - val rightImpl = impls.firstOrNull(IPacket::isCurrentVersion) - if (rightImpl != null) { - return rightImpl as T - } + fun rotate(player: Player, entityId : Int, yaw : Double) - if (HoloEasy.useLastSupportedVersion) { - return impls.last() as T - } + fun spawn(player: Player, entityId: Int, entityType: EntityType, location: Location) - throw RuntimeException( - """ - No version support for this packet - Set HoloEasy.useLastSupportedVersion to true or - open an issue at https://github.com/unldenis/holoeasy - """.trimIndent() - ) - } + fun teleport(player: Player, entityId: Int, location: Location) - val DELETE by lazy { getCurrImpl(DeletePacketA, DeletePacketB) } - - val METADATA_TEXT by lazy { - getCurrImpl( - MetadataTextPacketA, - MetadataTextPacketB, - MetadataTextPacketC, - MetadataTextPacketD, - MetadataTextPacketE - ) - } - - val METADATA_ITEM by lazy { - getCurrImpl( - MetadataItemPacketA, - MetadataItemPacketB, - MetadataItemPacketC, - MetadataItemPacketD, - MetadataItemPacketE - ) - } - - val SPAWN by lazy { - getCurrImpl(SpawnPacketA, SpawnPacketB, SpawnPacketC, SpawnPacketD) - } - - val TELEPORT by lazy { - getCurrImpl(TeleportPacketA, TeleportPacketB) - } - - val VELOCITY by lazy { getCurrImpl(VelocityPacketA) } - - val ROTATE by lazy { getCurrImpl(RotatePacketA) } - - val EQUIPMENT by lazy { - getCurrImpl( - EquipmentPacketA, - EquipmentPacketB, - EquipmentPacketC - ) - } + fun velocity(player: Player, entityId: Int, x: Double, y : Double, z : Double) } \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketBuilder.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketBuilder.kt index 6025e6f..6f25f41 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketBuilder.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketBuilder.kt @@ -2,8 +2,15 @@ package org.holoeasy.packet import com.comphenix.protocol.PacketType import com.comphenix.protocol.events.PacketContainer +import com.github.retrooper.packetevents.PacketEvents +import com.github.retrooper.packetevents.wrapper.PacketWrapper +import org.bukkit.entity.Player -fun packet(type: PacketType, initializer: PacketContainer.() -> Unit): PacketContainer { +internal fun packet(type: PacketType, initializer: PacketContainer.() -> Unit): PacketContainer { return PacketContainer(type).apply(initializer) +} + +internal fun PacketWrapper<*>.send(player: Player) { + PacketEvents.getAPI().playerManager.sendPacket(player, this); } \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketEventsPackets.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketEventsPackets.kt new file mode 100644 index 0000000..a4122d2 --- /dev/null +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketEventsPackets.kt @@ -0,0 +1,207 @@ +package org.holoeasy.packet + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes +import com.github.retrooper.packetevents.protocol.player.Equipment +import com.github.retrooper.packetevents.protocol.player.EquipmentSlot +import com.github.retrooper.packetevents.util.Vector3d +import com.github.retrooper.packetevents.wrapper.play.server.* +import io.github.retrooper.packetevents.adventure.serializer.gson.GsonComponentSerializer +import io.github.retrooper.packetevents.util.SpigotConversionUtil +import net.kyori.adventure.text.Component +import org.bukkit.Location +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.holoeasy.util.VersionEnum +import org.holoeasy.util.VersionUtil +import java.util.* + + +class PacketEventsPackets : IPacket { + + val SERIALIZER: GsonComponentSerializer = GsonComponentSerializer.builder().build() + + + override fun deletePacket(player: Player, entityId: Int) { + val packet = WrapperPlayServerDestroyEntities(entityId) + packet.send(player) + } + + override fun equip(player: Player, entityId: Int, helmet: ItemStack) { + val packet = WrapperPlayServerEntityEquipment( + entityId, listOf( + Equipment( + EquipmentSlot.HELMET, + SpigotConversionUtil.fromBukkitItemStack(helmet) + ) + ) + ) + packet.send(player) + } + + override fun metadataItem(player: Player, entityId: Int, item: ItemStack) { + + val entityData = mutableListOf() + + + if (VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + entityData.add( + EntityData( + 10, + EntityDataTypes.ITEMSTACK, + SpigotConversionUtil.fromBukkitItemStack(item) + ) + ) + + } else if (VersionUtil.CLEAN_VERSION in VersionEnum.V1_9..VersionEnum.V1_12) { + entityData.add( + EntityData( + 5, + EntityDataTypes.BOOLEAN, + true + ) + ) + entityData.add( + EntityData( + 6, + EntityDataTypes.ITEMSTACK, + SpigotConversionUtil.fromBukkitItemStack(item) + ) + ) + + } else if (VersionUtil.CLEAN_VERSION in VersionEnum.V1_13..VersionEnum.V1_18) { + entityData.add( + EntityData( + 5, + EntityDataTypes.BOOLEAN, + true + ) + ) + entityData.add( + EntityData( + 7, + EntityDataTypes.ITEMSTACK, + SpigotConversionUtil.fromBukkitItemStack(item) + ) + ) + } else { + entityData.add( + EntityData( + 5, + EntityDataTypes.BOOLEAN, + true + ) + ) + entityData.add( + EntityData( + 8, + EntityDataTypes.ITEMSTACK, + SpigotConversionUtil.fromBukkitItemStack(item) + ) + ) + } + + val packet = WrapperPlayServerEntityMetadata(entityId, entityData) + packet.send(player) + } + + override fun metadataText(player: Player, entityId: Int, nameTag: String?, invisible: Boolean) { + val entityData = mutableListOf() + + if (VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + + if (invisible) { + entityData.add( + EntityData( + 0, + EntityDataTypes.BYTE, + 0x20.toByte() + ) + ) + } + + if (nameTag != null) { + entityData.add( + EntityData( + 2, + EntityDataTypes.STRING, + nameTag + ) + ) + entityData.add( + EntityData( + 3, + EntityDataTypes.BYTE, + 1.toByte() + ) + ) + } + + } else { + + if (invisible) { + entityData.add( + EntityData( + 0, + EntityDataTypes.BYTE, + 0x20.toByte() + ) + ) + } + + if (nameTag != null) { + entityData.add( + EntityData( + 2, + EntityDataTypes.OPTIONAL_ADV_COMPONENT, + Optional.of(Component.text(nameTag)) + ) + ) + + entityData.add( + EntityData( + 3, + EntityDataTypes.BOOLEAN, + true + ) + ) + } + + } + + val packet = WrapperPlayServerEntityMetadata(entityId, entityData) + packet.send(player) + } + + override fun rotate(player: Player, entityId: Int, yaw: Double) { + val packet = WrapperPlayServerEntityRotation(entityId, yaw.toFloat(), 0f, false) + packet.send(player) + } + + override fun spawn(player: Player, entityId: Int, entityType: EntityType, location: Location) { + val packet = WrapperPlayServerSpawnEntity( + entityId, + UUID.randomUUID(), + SpigotConversionUtil.fromBukkitEntityType(entityType), + SpigotConversionUtil.fromBukkitLocation(location), + location.yaw, + 0, + null + ) + packet.send(player) + } + + override fun teleport(player: Player, entityId: Int, location: Location) { + val packet = WrapperPlayServerEntityTeleport(entityId, SpigotConversionUtil.fromBukkitLocation(location), false) + packet.send(player) + } + + override fun velocity(player: Player, entityId: Int, x: Double, y: Double, z: Double) { + val packet = WrapperPlayServerEntityVelocity(entityId, Vector3d(x, y, z)) + packet.send(player) + } + + + +} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketImpl.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketImpl.kt new file mode 100644 index 0000000..f31eb9e --- /dev/null +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/PacketImpl.kt @@ -0,0 +1,10 @@ +package org.holoeasy.packet + +import org.jetbrains.annotations.ApiStatus + +enum class PacketImpl(val impl: IPacket) { + ProtocolLib(ProtocolLibPackets()), + + @ApiStatus.Experimental + PacketEvents(PacketEventsPackets()) +} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/ProtocolLibPackets.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/ProtocolLibPackets.kt new file mode 100644 index 0000000..6b0bf93 --- /dev/null +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/ProtocolLibPackets.kt @@ -0,0 +1,418 @@ +package org.holoeasy.packet + +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.events.PacketContainer +import com.comphenix.protocol.wrappers.* +import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot +import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject +import org.bukkit.Bukkit +import org.bukkit.Location +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.plugin.Plugin +import org.holoeasy.HoloEasy +import org.holoeasy.ext.* +import org.holoeasy.ext.bukkitGeneric +import org.holoeasy.ext.send +import org.holoeasy.ext.setBool +import org.holoeasy.util.* +import org.holoeasy.util.BOOL_SERIALIZER +import org.holoeasy.util.BYTE_SERIALIZER +import org.holoeasy.util.ITEM_SERIALIZER +import java.util.* +import java.util.concurrent.CompletableFuture +import kotlin.collections.ArrayList +import kotlin.math.max +import kotlin.math.min + +class ProtocolLibPackets : IPacket { + override fun deletePacket(player: Player, entityId: Int) { + + val packet = if(VersionUtil.isBelow(VersionEnum.V1_16)) { + packet(PacketType.Play.Server.ENTITY_DESTROY) { + integerArrays[0] = intArrayOf(entityId) + } + } else { + packet(PacketType.Play.Server.ENTITY_DESTROY) { + intLists[0] = listOf(entityId) + } + } + packet.send(player) + } + + override fun equip(player: Player, entityId: Int, helmet: ItemStack) { + + val packet = if(VersionUtil.isCompatible(VersionEnum.V1_8)) { + packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { + integers[0] = entityId + + // Use legacy form to update the head slot. + integers[1] = 4 + + itemModifier[0] = helmet + } + } else if(VersionUtil.isBetween(VersionEnum.V1_9, VersionEnum.V1_12)) { + packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { + integers[0] = entityId + + itemSlots[0] = EnumWrappers.ItemSlot.HEAD + + itemModifier[0] = helmet + } + } else { + // 1_13 > + packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { + integers[0] = entityId + + val pairList = ArrayList>() + pairList.add(Pair(ItemSlot.HEAD, helmet)) + + slotStackPairLists[0] = pairList + } + } + packet.send(player) + } + + override fun metadataItem(player: Player, entityId: Int, item: ItemStack) { + + val packet = if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + val watcher = WrappedDataWatcher() + + watcher.setObject(10, item.bukkitGeneric()) + + packet(PacketType.Play.Server.ENTITY_METADATA) { + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_9..VersionEnum.V1_12) { + val watcher = WrappedDataWatcher() + + watcher.setBool(5, true) + watcher.setItemStack(6, item) + + packet(PacketType.Play.Server.ENTITY_METADATA) { + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_13..VersionEnum.V1_18) { + val watcher = WrappedDataWatcher() + + watcher.setBool(5, true) + watcher.setItemStack(7, item) + + packet(PacketType.Play.Server.ENTITY_METADATA) { + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_19..VersionEnum.V1_19) { + val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) + packet.integers.write(0, entityId) + + val watcher = WrappedDataWatcher() + + val gravity = WrappedDataWatcherObject( + 5, BOOL_SERIALIZER + ) + watcher.setObject(gravity,true) + + val itemSer = WrappedDataWatcherObject( + 8, ITEM_SERIALIZER + ) + watcher.setObject(itemSer, item.bukkitGeneric()) + + // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187 + packet.parse119(watcher) + + packet + } else { + // 1.20 > + val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) + + packet.integers.write(0, entityId) + + packet.dataValueCollectionModifier + .write( + 0, listOf( + WrappedDataValue(5, BOOL_SERIALIZER, true), + + WrappedDataValue(8, ITEM_SERIALIZER, item.bukkitGeneric()) + ) + ) + + + packet + } + packet.send(player) + } + + override fun metadataText(player: Player, entityId: Int, nameTag: String?, invisible: Boolean) { + val packet = if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + val watcher = WrappedDataWatcher() + + if (invisible) + watcher.setObject(0, 0x20.toByte()) + + if(nameTag != null) { + watcher.setObject(2, nameTag) + watcher.setObject(3, 1.toByte()) + } + + packet(PacketType.Play.Server.ENTITY_METADATA) { + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_9..VersionEnum.V1_12) { + val watcher = WrappedDataWatcher() + + if(invisible) + watcher.setByte(0, 0x20.toByte()) + + if(nameTag != null) { + watcher.setString(2, nameTag) + watcher.setBool(3, true) + } + + packet(PacketType.Play.Server.ENTITY_METADATA) { + modifier.writeDefaults() + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_13..VersionEnum.V1_18) { + val watcher = WrappedDataWatcher() + + if(invisible) + watcher.setByte(0, 0x20.toByte()) + + if(nameTag != null) { + watcher.setChatComponent(2, nameTag) + watcher.setBool(3, true) + } + packet(PacketType.Play.Server.ENTITY_METADATA) { + integers[0] = entityId + watchableCollectionModifier[0] = watcher.watchableObjects + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_19..VersionEnum.V1_19) { + val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) + packet.integers.write(0, entityId) + + val watcher = WrappedDataWatcher() + + if(invisible) + watcher.setByte(0, 0x20.toByte()) + + if(nameTag != null) { + watcher.setChatComponent(2, nameTag) + watcher.setBool(3, true) + } + + // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187 + packet.parse119(watcher) + + packet + } else { + // 1.20 > + val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) + packet.integers.write(0, entityId) + + val watcher = WrappedDataWatcher() + + packet.watchableCollectionModifier.write(0, watcher.watchableObjects) + val wrappedDataValueList: MutableList = java.util.ArrayList() + + + + if(invisible) { + wrappedDataValueList.add( + WrappedDataValue(0, BYTE_SERIALIZER, 0x20.toByte()) + ) + } + + + nameTag?.let { + val opt: Optional<*> = Optional.of( + WrappedChatComponent.fromChatMessage( + it + )[0].handle + ) + + wrappedDataValueList.add( + WrappedDataValue( + 2, WrappedDataWatcher.Registry.getChatComponentSerializer(true), + opt + ) + ) + + wrappedDataValueList.add( + WrappedDataValue(3, BOOL_SERIALIZER, true) + ) + } + + + packet.dataValueCollectionModifier.write(0, wrappedDataValueList) + + packet + } + packet.send(player) + } + + override fun rotate(player: Player, entityId: Int, yaw: Double) { + packet(PacketType.Play.Server.ENTITY_LOOK) { + integers[0] = entityId + bytes[0] = yaw.compressAngle + }.send(player) + } + + override fun spawn(player: Player, entityId: Int, entityType: EntityType, location: Location) { + val packet = if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { + integers[0] = entityId + + integers[1] = VersionUtil.CLEAN_VERSION.armorstandId + + integers[2] = (location.x * 32).toInt() + integers[3] = (location.y * 32).toInt() + integers[4] = (location.z * 32).toInt() + + if (defaultDataWatcher == null) { + loadDefaultWatcher(HoloEasy.plugin()).join() + } + + dataWatcherModifier[0] = defaultDataWatcher + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_9..VersionEnum.V1_15) { + val extraData = 1 + + packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { + modifier.writeDefaults() + + integers[0] = entityId + integers[1] = if(entityType == EntityType.ARMOR_STAND) + VersionUtil.CLEAN_VERSION.armorstandId else VersionUtil.CLEAN_VERSION.droppedItemId + integers[2] = extraData + + uuiDs[0] = UUID.randomUUID() + + doubles[0] = location.x + doubles[1] = location.y + doubles[2] = location.z + } + } else if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_16..VersionEnum.V1_18) { + val extraData = 1 + + if(entityType == EntityType.ARMOR_STAND) { + packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { + modifier.writeDefaults() + + integers[0] = entityId + integers[1] = VersionUtil.CLEAN_VERSION.armorstandId + integers[2] = extraData + + uuiDs[0] = UUID.randomUUID() + + doubles[0] = location.x + doubles[1] = location.y + doubles[2] = location.z + } + } else { + packet(PacketType.Play.Server.SPAWN_ENTITY) { + modifier.writeDefaults() + + integers[0] = entityId + + entityTypeModifier[0] = EntityType.DROPPED_ITEM + + uuiDs[0] = UUID.randomUUID() + + doubles[0] = location.x + doubles[1] = location.y + doubles[2] = location.z + + integers[2] = convertVelocity(0.0) + integers[3] = convertVelocity(0.0) + integers[4] = convertVelocity(0.0) + } + } + } else { + // 1.19 > + packet(PacketType.Play.Server.SPAWN_ENTITY) { + integers[0] = entityId + + entityTypeModifier[0] = entityType + + uuiDs[0] = UUID.randomUUID() + + doubles[0] = location.x + doubles[1] = location.y + doubles[2] = location.z + + } + } + packet.send(player) + } + + override fun teleport(player: Player, entityId: Int, location: Location) { + val packet = if(VersionUtil.CLEAN_VERSION in VersionEnum.V1_8..VersionEnum.V1_8) { + packet(PacketType.Play.Server.ENTITY_TELEPORT) { + integers[0] = entityId + integers[1] = location.x.fixCoordinate + integers[2] = location.y.fixCoordinate + integers[3] = location.z.fixCoordinate + bytes[0] = location.yaw.toDouble().compressAngle + bytes[1] = location.pitch.toDouble().compressAngle + booleans[0] = false + } + } else { + // 1.19 > + packet(PacketType.Play.Server.ENTITY_TELEPORT) { + integers[0] = entityId + + doubles[0] = location.x + doubles[1] = location.y + doubles[2] = location.z + + bytes[0] = location.yaw.toDouble().compressAngle + bytes[1] = location.pitch.toDouble().compressAngle + + booleans[0] = false + } + } + + packet.send(player) + } + + override fun velocity(player: Player, entityId: Int, x: Double, y: Double, z: Double) { + packet(PacketType.Play.Server.ENTITY_VELOCITY) { + integers[0] = entityId + integers[1] = x.toInt() + integers[2] = y.toInt() + integers[3] = z.toInt() + }.send(player) + } + + // 1.8 + private var defaultDataWatcher: WrappedDataWatcher? = null + + private fun loadDefaultWatcher(plugin: Plugin): CompletableFuture { + return BukkitFuture.runSync(plugin) { + val world = Bukkit.getWorlds()[0] + val entity = + world.spawnEntity(Location(world, 0.0, 256.0, 0.0), EntityType.ARMOR_STAND) + entity.remove() + } + } + + + private fun convertVelocity(velocity: Double): Int { + /* + Minecraft represents a velocity within 4 blocks per second, in any direction, + by using the entire Short range, meaning you can only move up to 4 blocks/second + on any given direction + */ + return (clamp(velocity, -3.9, 3.9) * 8000).toInt() + } + private fun clamp(targetNum: Double, min: Double, max: Double): Double { + // Makes sure a number is within a range + return max(min, min(targetNum, max)) + } +} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketA.kt deleted file mode 100644 index 147975f..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketA.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.holoeasy.packet.delete - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object DeletePacketA : IDeletePacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_16) - - override fun delete(entityId: Int): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_DESTROY) { - integerArrays[0] = intArrayOf(entityId) - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketB.kt deleted file mode 100644 index 131d1ea..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/DeletePacketB.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.holoeasy.packet.delete - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object DeletePacketB : IDeletePacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_17..VersionEnum.LATEST) - - override fun delete(entityId: Int): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_DESTROY) { - intLists[0] = listOf(entityId) - } - } -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/IDeletePacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/IDeletePacket.kt deleted file mode 100644 index d657b5f..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/delete/IDeletePacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.delete - -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.packet.IPacket - -interface IDeletePacket : IPacket { - - fun delete(entityId: Int): PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketA.kt deleted file mode 100644 index 890235d..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketA.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.holoeasy.packet.equipment - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object EquipmentPacketA : IEquipmentPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8) - - override fun equip(entityId: Int, helmet: ItemStack): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { - integers[0] = entityId - - // Use legacy form to update the head slot. - integers[1] = 4 - - itemModifier[0] = helmet - } - } - - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketB.kt deleted file mode 100644 index ae20acc..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketB.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.holoeasy.packet.equipment - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.EnumWrappers -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object EquipmentPacketB : IEquipmentPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_12) - - override fun equip(entityId: Int, helmet: ItemStack): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { - integers[0] = entityId - - itemSlots[0] = EnumWrappers.ItemSlot.HEAD - - itemModifier[0] = helmet - } - } - - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketC.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketC.kt deleted file mode 100644 index bc09472..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/EquipmentPacketC.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.holoeasy.packet.equipment - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -import com.comphenix.protocol.wrappers.Pair; -object EquipmentPacketC : IEquipmentPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_13..VersionEnum.LATEST) - - override fun equip(entityId: Int, helmet: ItemStack): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_EQUIPMENT) { - integers[0] = entityId - - val pairList = ArrayList>() - pairList.add(Pair(ItemSlot.HEAD, helmet)) - - slotStackPairLists[0] = pairList - } - } - - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/IEquipmentPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/IEquipmentPacket.kt deleted file mode 100644 index 10cd6a6..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/equipment/IEquipmentPacket.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.holoeasy.packet.equipment - -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.inventory.ItemStack -import org.holoeasy.packet.IPacket - -interface IEquipmentPacket : IPacket { - - fun equip(entityId : Int, helmet : ItemStack) : PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt deleted file mode 100644 index f47b735..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/IMetadataItemPacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.inventory.ItemStack -import org.holoeasy.packet.IPacket - -interface IMetadataItemPacket : IPacket { - fun metadata(entityId: Int, item: ItemStack): PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt deleted file mode 100644 index 103706b..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketA.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.bukkitGeneric -import org.holoeasy.ext.set -import org.holoeasy.ext.setByte -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - - -object MetadataItemPacketA : IMetadataItemPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8) - - override fun metadata(entityId: Int, item: ItemStack): PacketContainer { - val watcher = WrappedDataWatcher() - - -// watcher.setObject(5, true) -// watcher.setObject(15, 1.toByte()) - watcher.setObject(10, item.bukkitGeneric()) - - - return packet(PacketType.Play.Server.ENTITY_METADATA) { - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt deleted file mode 100644 index 7906c60..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketB.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.set -import org.holoeasy.ext.setBool -import org.holoeasy.ext.setItemStack -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - - -object MetadataItemPacketB : IMetadataItemPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_12) - - override fun metadata(entityId: Int, item: ItemStack): PacketContainer { - val watcher = WrappedDataWatcher() - - watcher.setBool(5, true) - watcher.setItemStack(6, item) - - return packet(PacketType.Play.Server.ENTITY_METADATA) { - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt deleted file mode 100644 index 1910dc6..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketC.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.EnumWrappers.EntityPose -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.set -import org.holoeasy.ext.setBool -import org.holoeasy.ext.setItemStack -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - - -object MetadataItemPacketC : IMetadataItemPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_13..VersionEnum.V1_18) - - override fun metadata(entityId: Int, item: ItemStack): PacketContainer { - val watcher = WrappedDataWatcher() - - watcher.setBool(5, true) - watcher.setItemStack(7, item) - - return packet(PacketType.Play.Server.ENTITY_METADATA) { - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt deleted file mode 100644 index 60093ad..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketD.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.utility.MinecraftVersion -import com.comphenix.protocol.wrappers.WrappedChatComponent -import com.comphenix.protocol.wrappers.WrappedDataValue -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject -import com.google.common.collect.Lists -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.bukkitGeneric -import org.holoeasy.ext.parse119 -import org.holoeasy.ext.setBool -import org.holoeasy.util.BOOL_SERIALIZER -import org.holoeasy.util.ITEM_SERIALIZER -import org.holoeasy.util.VersionEnum -import java.util.* - - -object MetadataItemPacketD : IMetadataItemPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_19) - - override fun metadata(entityId: Int, item: ItemStack): PacketContainer { - val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) - packet.integers.write(0, entityId) - - val watcher = WrappedDataWatcher() - - val gravity = WrappedDataWatcherObject( - 5, BOOL_SERIALIZER - ) - watcher.setObject(gravity,true) - - val itemSer = WrappedDataWatcherObject( - 8, ITEM_SERIALIZER - ) - watcher.setObject(itemSer, item.bukkitGeneric()) - - // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187 - packet.parse119(watcher) - - return packet - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt deleted file mode 100644 index a9eb3f8..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/item/MetadataItemPacketE.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.holoeasy.packet.metadata.item - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataValue -import org.bukkit.inventory.ItemStack -import org.holoeasy.ext.bukkitGeneric -import org.holoeasy.util.BOOL_SERIALIZER -import org.holoeasy.util.ITEM_SERIALIZER -import org.holoeasy.util.VersionEnum - - -object MetadataItemPacketE : IMetadataItemPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_19..VersionEnum.LATEST) - - override fun metadata(entityId: Int, item: ItemStack): PacketContainer { - val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) - - packet.integers.write(0, entityId) - - packet.dataValueCollectionModifier - .write( - 0, listOf( - WrappedDataValue(5, BOOL_SERIALIZER, true), - - WrappedDataValue(8, ITEM_SERIALIZER, item.bukkitGeneric()) - ) - ) - - - return packet - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt deleted file mode 100644 index c8562c5..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/IMetadataTextPacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.packet.IPacket - -interface IMetadataTextPacket : IPacket { - - fun metadata(entityId: Int, nameTag: String?, invisible : Boolean = true): PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt deleted file mode 100644 index cecd647..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketA.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object MetadataTextPacketA : IMetadataTextPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8) - - override fun metadata(entityId: Int, nameTag: String?, invisible: Boolean): PacketContainer { - val watcher = WrappedDataWatcher() - - if (invisible) - watcher.setObject(0, 0x20.toByte()) - - if(nameTag != null) { - watcher.setObject(2, nameTag) - watcher.setObject(3, 1.toByte()) - } - - - return packet(PacketType.Play.Server.ENTITY_METADATA) { - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt deleted file mode 100644 index 42114e9..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketB.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.holoeasy.ext.set -import org.holoeasy.ext.setBool -import org.holoeasy.ext.setByte -import org.holoeasy.ext.setString -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object MetadataTextPacketB : IMetadataTextPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_12) - - override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer { - val watcher = WrappedDataWatcher() - - if(invisible) - watcher.setByte(0, 0x20.toByte()) - - if(nameTag != null) { - watcher.setString(2, nameTag) - watcher.setBool(3, true) - } - - return packet(PacketType.Play.Server.ENTITY_METADATA) { - modifier.writeDefaults() - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt deleted file mode 100644 index c3601d0..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketC.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.holoeasy.ext.set -import org.holoeasy.ext.setBool -import org.holoeasy.ext.setByte -import org.holoeasy.ext.setChatComponent -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object MetadataTextPacketC : IMetadataTextPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_13..VersionEnum.V1_18) - - override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer { - val watcher = WrappedDataWatcher() - - if(invisible) - watcher.setByte(0, 0x20.toByte()) - - if(nameTag != null) { - watcher.setChatComponent(2, nameTag) - watcher.setBool(3, true) - } - return packet(PacketType.Play.Server.ENTITY_METADATA) { - integers[0] = entityId - watchableCollectionModifier[0] = watcher.watchableObjects - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt deleted file mode 100644 index d447c72..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketD.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.holoeasy.ext.* -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object MetadataTextPacketD : IMetadataTextPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_19..VersionEnum.V1_19) - - override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer { - val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) - packet.integers.write(0, entityId) - - val watcher = WrappedDataWatcher() - - if(invisible) - watcher.setByte(0, 0x20.toByte()) - - if(nameTag != null) { - watcher.setChatComponent(2, nameTag) - watcher.setBool(3, true) - } - - // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/#post-4517187 - packet.parse119(watcher) - - return packet - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt deleted file mode 100644 index 6f151fb..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/metadata/text/MetadataTextPacketE.kt +++ /dev/null @@ -1,61 +0,0 @@ -package org.holoeasy.packet.metadata.text - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedChatComponent -import com.comphenix.protocol.wrappers.WrappedDataValue -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.holoeasy.util.BOOL_SERIALIZER -import org.holoeasy.util.BYTE_SERIALIZER -import org.holoeasy.util.VersionEnum -import java.util.* - -object MetadataTextPacketE : IMetadataTextPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_20..VersionEnum.LATEST) - - override fun metadata(entityId: Int, nameTag: String?, invisible : Boolean): PacketContainer { - val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) - packet.integers.write(0, entityId) - - val watcher = WrappedDataWatcher() - - packet.watchableCollectionModifier.write(0, watcher.watchableObjects) - val wrappedDataValueList: MutableList = ArrayList() - - - - if(invisible) { - wrappedDataValueList.add( - WrappedDataValue(0, BYTE_SERIALIZER, 0x20.toByte()) - ) - } - - - nameTag?.let { - val opt: Optional<*> = Optional.of( - WrappedChatComponent.fromChatMessage( - it - )[0].handle - ) - - wrappedDataValueList.add( - WrappedDataValue( - 2, WrappedDataWatcher.Registry.getChatComponentSerializer(true), - opt - ) - ) - - wrappedDataValueList.add( - WrappedDataValue(3, BOOL_SERIALIZER, true) - ) - } - - - packet.dataValueCollectionModifier.write(0, wrappedDataValueList) - - return packet - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/IRotatePacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/IRotatePacket.kt deleted file mode 100644 index 6aa96a7..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/IRotatePacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.rotate - -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.packet.IPacket - -interface IRotatePacket : IPacket { - - fun rotate(entityId : Int, yaw : Double) : PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/RotatePacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/RotatePacketA.kt deleted file mode 100644 index a6ce568..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/rotate/RotatePacketA.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.holoeasy.packet.rotate - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.ext.compressAngle -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object RotatePacketA : IRotatePacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.LATEST) - - override fun rotate(entityId: Int, yaw: Double) : PacketContainer { - return packet(PacketType.Play.Server.ENTITY_LOOK) { - integers[0] = entityId - bytes[0] = yaw.compressAngle - } - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/ISpawnPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/ISpawnPacket.kt deleted file mode 100644 index d5ecf10..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/ISpawnPacket.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.holoeasy.packet.spawn - -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.bukkit.entity.EntityType -import org.bukkit.plugin.Plugin -import org.holoeasy.packet.IPacket - -interface ISpawnPacket : IPacket { - - fun spawn( - entityId: Int, entityType: EntityType, location: Location, - plugin: Plugin? = null - ): PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketA.kt deleted file mode 100644 index 9c49ed4..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketA.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.holoeasy.packet.spawn - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.wrappers.WrappedDataWatcher -import org.bukkit.Bukkit -import org.bukkit.Location -import org.bukkit.Material -import org.bukkit.entity.EntityType -import org.bukkit.inventory.ItemStack -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.BukkitFuture -import org.holoeasy.util.VersionEnum -import org.holoeasy.util.VersionUtil -import java.util.concurrent.CompletableFuture - -object SpawnPacketA : ISpawnPacket { - - private fun loadDefaultWatcher(plugin: Plugin): CompletableFuture { - return BukkitFuture.runSync(plugin) { - val world = Bukkit.getWorlds()[0] - val entity = - world.spawnEntity(Location(world, 0.0, 256.0, 0.0), EntityType.ARMOR_STAND) - entity.remove() - } - } - - private var defaultDataWatcher: WrappedDataWatcher? = null - - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8) - - override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer { - return packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { - integers[0] = entityId - - integers[1] = VersionUtil.CLEAN_VERSION.armorstandId - - integers[2] = (location.x * 32).toInt() - integers[3] = (location.y * 32).toInt() - integers[4] = (location.z * 32).toInt() - - if (defaultDataWatcher == null) { - loadDefaultWatcher(plugin ?: throw RuntimeException("Plugin cannot be null")).join() - } - - dataWatcherModifier[0] = defaultDataWatcher - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketB.kt deleted file mode 100644 index 9538982..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketB.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.holoeasy.packet.spawn - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.bukkit.entity.EntityType -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum -import org.holoeasy.util.VersionUtil -import java.util.* - -object SpawnPacketB : ISpawnPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_9..VersionEnum.V1_15) - - override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer { - val extraData = 1 - - return packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { - modifier.writeDefaults() - - integers[0] = entityId - integers[1] = if(entityType == EntityType.ARMOR_STAND) - VersionUtil.CLEAN_VERSION.armorstandId else VersionUtil.CLEAN_VERSION.droppedItemId - integers[2] = extraData - - uuiDs[0] = UUID.randomUUID() - - doubles[0] = location.x - doubles[1] = location.y - doubles[2] = location.z - } - - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketC.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketC.kt deleted file mode 100644 index 9774b13..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketC.kt +++ /dev/null @@ -1,73 +0,0 @@ -package org.holoeasy.packet.spawn - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.bukkit.entity.EntityType -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum -import org.holoeasy.util.VersionUtil -import java.util.* -import kotlin.math.max -import kotlin.math.min - -object SpawnPacketC : ISpawnPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_16..VersionEnum.V1_18) - - override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer { - val extraData = 1 - - if(entityType == EntityType.ARMOR_STAND) { - return packet(PacketType.Play.Server.SPAWN_ENTITY_LIVING) { - modifier.writeDefaults() - - integers[0] = entityId - integers[1] = VersionUtil.CLEAN_VERSION.armorstandId - integers[2] = extraData - - uuiDs[0] = UUID.randomUUID() - - doubles[0] = location.x - doubles[1] = location.y - doubles[2] = location.z - } - } else { - return packet(PacketType.Play.Server.SPAWN_ENTITY) { - modifier.writeDefaults() - - integers[0] = entityId - - entityTypeModifier[0] = EntityType.DROPPED_ITEM - - uuiDs[0] = UUID.randomUUID() - - doubles[0] = location.x - doubles[1] = location.y - doubles[2] = location.z - - integers[2] = convertVelocity(0.0) - integers[3] = convertVelocity(0.0) - integers[4] = convertVelocity(0.0) - } - } - - } - - private fun convertVelocity(velocity: Double): Int { - /* - Minecraft represents a velocity within 4 blocks per second, in any direction, - by using the entire Short range, meaning you can only move up to 4 blocks/second - on any given direction - */ - return (clamp(velocity, -3.9, 3.9) * 8000).toInt() - } - private fun clamp(targetNum: Double, min: Double, max: Double): Double { - // Makes sure a number is within a range - return max(min, min(targetNum, max)) - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketD.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketD.kt deleted file mode 100644 index a3f89fd..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/spawn/SpawnPacketD.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.holoeasy.packet.spawn - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.bukkit.entity.EntityType -import org.bukkit.plugin.Plugin -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum -import java.util.* - -object SpawnPacketD : ISpawnPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_19..VersionEnum.LATEST) - - override fun spawn(entityId: Int, entityType: EntityType, location: Location, plugin: Plugin?): PacketContainer { - return packet(PacketType.Play.Server.SPAWN_ENTITY) { - integers[0] = entityId - - entityTypeModifier[0] = entityType - - uuiDs[0] = UUID.randomUUID() - - doubles[0] = location.x - doubles[1] = location.y - doubles[2] = location.z - - } - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/ITeleportPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/ITeleportPacket.kt deleted file mode 100644 index d52a7e6..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/ITeleportPacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.teleport - -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.holoeasy.packet.IPacket - -interface ITeleportPacket : IPacket { - fun teleport(entityId: Int, location: Location): PacketContainer -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketA.kt deleted file mode 100644 index fe54d83..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketA.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.holoeasy.packet.teleport - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.holoeasy.ext.compressAngle -import org.holoeasy.ext.fixCoordinate -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object TeleportPacketA : ITeleportPacket { - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.V1_8) - - override fun teleport(entityId: Int, location: Location): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_TELEPORT) { - integers[0] = entityId - integers[1] = location.x.fixCoordinate - integers[2] = location.y.fixCoordinate - integers[3] = location.z.fixCoordinate - bytes[0] = location.yaw.toDouble().compressAngle - bytes[1] = location.pitch.toDouble().compressAngle - booleans[0] = false - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketB.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketB.kt deleted file mode 100644 index 0d7b737..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/teleport/TeleportPacketB.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.holoeasy.packet.teleport - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.bukkit.Location -import org.holoeasy.ext.compressAngle -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object TeleportPacketB : ITeleportPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_9..VersionEnum.LATEST) - - override fun teleport(entityId: Int, location: Location): PacketContainer { - val teleportPacket = packet(PacketType.Play.Server.ENTITY_TELEPORT) { - integers[0] = entityId - - doubles[0] = location.x - doubles[1] = location.y - doubles[2] = location.z - - bytes[0] = location.yaw.toDouble().compressAngle - bytes[1] = location.pitch.toDouble().compressAngle - - booleans[0] = false - } - - return teleportPacket - } - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/IVelocityPacket.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/IVelocityPacket.kt deleted file mode 100644 index ba54d34..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/IVelocityPacket.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.holoeasy.packet.velocity - -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.packet.IPacket - -interface IVelocityPacket : IPacket { - fun velocity(entityId: Int, x: Int, y : Int, z : Int): PacketContainer - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/VelocityPacketA.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/VelocityPacketA.kt deleted file mode 100644 index bfef59d..0000000 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/packet/velocity/VelocityPacketA.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.holoeasy.packet.velocity - -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.events.PacketContainer -import org.holoeasy.ext.set -import org.holoeasy.packet.packet -import org.holoeasy.util.VersionEnum - -object VelocityPacketA : IVelocityPacket { - - override val versionSupport: Array> - get() = arrayOf(VersionEnum.V1_8..VersionEnum.LATEST) - - override fun velocity(entityId: Int, x: Int, y: Int, z: Int): PacketContainer { - return packet(PacketType.Play.Server.ENTITY_VELOCITY) { - integers[0] = entityId - integers[1] = x - integers[2] = y - integers[3] = z - } - } - - -} \ No newline at end of file diff --git a/holoeasy-core/src/main/kotlin/org/holoeasy/util/Serializers.kt b/holoeasy-core/src/main/kotlin/org/holoeasy/util/Serializers.kt index ea21970..3ecb22c 100644 --- a/holoeasy-core/src/main/kotlin/org/holoeasy/util/Serializers.kt +++ b/holoeasy-core/src/main/kotlin/org/holoeasy/util/Serializers.kt @@ -2,6 +2,11 @@ package org.holoeasy.util import com.comphenix.protocol.wrappers.WrappedDataWatcher + +fun test() { + +} + internal val BYTE_SERIALIZER : WrappedDataWatcher.Serializer get() = WrappedDataWatcher.Registry.get(java.lang.Byte::class.java) diff --git a/holoeasy-example/pom.xml b/holoeasy-example-packetevents/pom.xml similarity index 81% rename from holoeasy-example/pom.xml rename to holoeasy-example-packetevents/pom.xml index a8eef13..2957ccb 100644 --- a/holoeasy-example/pom.xml +++ b/holoeasy-example-packetevents/pom.xml @@ -9,7 +9,7 @@ holoeasy 4.1.0 - holoeasy-example + holoeasy-example-packetevents @@ -32,6 +32,15 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + codemc-releases + https://repo.codemc.io/repository/maven-releases/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + @@ -52,7 +61,11 @@ holoeasy-core ${parent.version} - + + com.github.retrooper + packetevents-spigot + 2.5.0 + diff --git a/holoeasy-example/src/main/java/org/holoeasy/plugin/ExamplePlugin.java b/holoeasy-example-packetevents/src/main/java/org/holoeasy/plugin/ExamplePlugin.java similarity index 75% rename from holoeasy-example/src/main/java/org/holoeasy/plugin/ExamplePlugin.java rename to holoeasy-example-packetevents/src/main/java/org/holoeasy/plugin/ExamplePlugin.java index 3e139ec..b9c1a7e 100644 --- a/holoeasy-example/src/main/java/org/holoeasy/plugin/ExamplePlugin.java +++ b/holoeasy-example-packetevents/src/main/java/org/holoeasy/plugin/ExamplePlugin.java @@ -1,35 +1,48 @@ package org.holoeasy.plugin; +import com.github.retrooper.packetevents.PacketEvents; +import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.holoeasy.HoloEasy; -import org.holoeasy.action.ClickAction; import org.holoeasy.builder.TextLineModifiers; import org.holoeasy.hologram.Hologram; import org.holoeasy.line.ILine; import org.holoeasy.line.ITextLine; -import org.holoeasy.line.ItemLine; +import org.holoeasy.packet.PacketImpl; import org.holoeasy.pool.IHologramPool; import org.holoeasy.reactive.MutableState; import org.jetbrains.annotations.NotNull; -import java.util.Map; public class ExamplePlugin extends JavaPlugin { + @Override + public void onLoad() { + PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this)); + //On Bukkit, calling this here is essential, hence the name "load" + PacketEvents.getAPI().load(); + } + + @Override + public void onDisable() { + //Terminate the instance (clean up process) + PacketEvents.getAPI().terminate(); + } @Override public void onEnable() { + //Initialize! + PacketEvents.getAPI().init(); // ** Bind the library - HoloEasy.bind(this); + HoloEasy.bind(this, PacketImpl.PacketEvents); // ** Create a MyHolo Pool, why not? IHologramPool myPool = HoloEasy.startInteractivePool(60); diff --git a/holoeasy-example/src/main/java/org/holoeasy/plugin/HelloWorldHologram.java b/holoeasy-example-packetevents/src/main/java/org/holoeasy/plugin/HelloWorldHologram.java similarity index 100% rename from holoeasy-example/src/main/java/org/holoeasy/plugin/HelloWorldHologram.java rename to holoeasy-example-packetevents/src/main/java/org/holoeasy/plugin/HelloWorldHologram.java diff --git a/holoeasy-example/src/main/resources/plugin.yml b/holoeasy-example-packetevents/src/main/resources/plugin.yml similarity index 83% rename from holoeasy-example/src/main/resources/plugin.yml rename to holoeasy-example-packetevents/src/main/resources/plugin.yml index 91f1da2..fb1d939 100644 --- a/holoeasy-example/src/main/resources/plugin.yml +++ b/holoeasy-example-packetevents/src/main/resources/plugin.yml @@ -1,7 +1,6 @@ name: ExamplePlugin main: org.holoeasy.plugin.ExamplePlugin version: 1.0 -depend: [ProtocolLib] api-version: 1.13 commands: hologram: \ No newline at end of file diff --git a/holoeasy-example-kotlin/pom.xml b/holoeasy-example-protocollib/pom.xml similarity index 98% rename from holoeasy-example-kotlin/pom.xml rename to holoeasy-example-protocollib/pom.xml index 547d33f..80093cb 100644 --- a/holoeasy-example-kotlin/pom.xml +++ b/holoeasy-example-protocollib/pom.xml @@ -9,7 +9,7 @@ 4.1.0 - holoeasy-example-kotlin + holoeasy-example-protocollib UTF-8 diff --git a/holoeasy-example-kotlin/src/main/kotlin/ExamplePlugin.kt b/holoeasy-example-protocollib/src/main/kotlin/ExamplePlugin.kt similarity index 90% rename from holoeasy-example-kotlin/src/main/kotlin/ExamplePlugin.kt rename to holoeasy-example-protocollib/src/main/kotlin/ExamplePlugin.kt index ca40790..4a65a58 100644 --- a/holoeasy-example-kotlin/src/main/kotlin/ExamplePlugin.kt +++ b/holoeasy-example-protocollib/src/main/kotlin/ExamplePlugin.kt @@ -1,6 +1,5 @@ package org.holoeasy.plugin -import HelloWorldHologram import org.bukkit.Location import org.bukkit.Material import org.bukkit.entity.Player @@ -10,15 +9,14 @@ import org.bukkit.plugin.java.JavaPlugin import org.holoeasy.HoloEasy import org.holoeasy.builder.TextLineModifiers import org.holoeasy.hologram.Hologram -import org.holoeasy.hologram.Hologram.Companion.deserialize -import org.holoeasy.reactive.MutableState +import org.holoeasy.packet.PacketImpl class ExamplePlugin : JavaPlugin() { override fun onEnable() { // ** Bind the library - HoloEasy.bind(this) + HoloEasy.bind(this, PacketImpl.ProtocolLib) getCommand("hologram")?.setExecutor { sender, _, _, _ -> diff --git a/holoeasy-example-kotlin/src/main/kotlin/HelloWorldHologram.kt b/holoeasy-example-protocollib/src/main/kotlin/HelloWorldHologram.kt similarity index 85% rename from holoeasy-example-kotlin/src/main/kotlin/HelloWorldHologram.kt rename to holoeasy-example-protocollib/src/main/kotlin/HelloWorldHologram.kt index 6bcdcee..03755d3 100644 --- a/holoeasy-example-kotlin/src/main/kotlin/HelloWorldHologram.kt +++ b/holoeasy-example-protocollib/src/main/kotlin/HelloWorldHologram.kt @@ -1,3 +1,5 @@ +package org.holoeasy.plugin + import org.bukkit.Location import org.holoeasy.hologram.Hologram diff --git a/holoeasy-example-kotlin/src/main/resources/plugin.yml b/holoeasy-example-protocollib/src/main/resources/plugin.yml similarity index 100% rename from holoeasy-example-kotlin/src/main/resources/plugin.yml rename to holoeasy-example-protocollib/src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index 00c6788..670588d 100644 --- a/pom.xml +++ b/pom.xml @@ -29,8 +29,8 @@ pom holoeasy-core - holoeasy-example - holoeasy-example-kotlin + holoeasy-example-packetevents + holoeasy-example-protocollib 1.8