diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java deleted file mode 100644 index f1a996c5..00000000 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/AbstractNMSPacketList.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.common.nms; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public abstract class AbstractNMSPacketList implements NMSPacketList { - - // Lazily instantiate a list only when adding more than one element - private @Nullable NMSPacket singlePacket; - private @Nullable List multiplePackets; - - protected final void add(NMSPacket packet) { - if (multiplePackets != null) { - multiplePackets.add(packet); - } else if (singlePacket != null) { - multiplePackets = new ArrayList<>(); - multiplePackets.add(singlePacket); - multiplePackets.add(packet); - singlePacket = null; - } else { - singlePacket = packet; - } - } - - @Override - public final void sendTo(Player player) { - if (multiplePackets != null) { - for (NMSPacket packet : multiplePackets) { - packet.sendTo(player); - } - } else if (singlePacket != null) { - singlePacket.sendTo(player); - } - } - -} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualText.java similarity index 85% rename from common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java rename to common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualText.java index c868ea01..b09a6987 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualCustomName.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/IndividualText.java @@ -8,7 +8,7 @@ package me.filoghost.holographicdisplays.common.nms; import org.bukkit.entity.Player; @FunctionalInterface -public interface IndividualCustomName { +public interface IndividualText { String get(Player player); diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java index ea0be0d6..3a567c52 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSManager.java @@ -5,13 +5,18 @@ */ package me.filoghost.holographicdisplays.common.nms; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import org.bukkit.entity.Player; public interface NMSManager { - EntityID newEntityID(); + TextNMSPacketEntity newTextPacketEntity(); - NMSPacketList createPacketList(); + ItemNMSPacketEntity newItemPacketEntity(); + + ClickableNMSPacketEntity newClickablePacketEntity(); void injectPacketListener(Player player, PacketListener packetListener); diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java index 1988cc8d..8cd6be9e 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/NMSPacketList.java @@ -6,33 +6,38 @@ package me.filoghost.holographicdisplays.common.nms; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; -public interface NMSPacketList { +import java.util.ArrayList; +import java.util.List; - void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ); +public class NMSPacketList { - void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName); + // Lazily instantiate a list only when adding more than one element + private @Nullable NMSPacket singlePacket; + private @Nullable List multiplePackets; - void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName); + public void add(NMSPacket packet) { + if (multiplePackets != null) { + multiplePackets.add(packet); + } else if (singlePacket != null) { + multiplePackets = new ArrayList<>(); + multiplePackets.add(singlePacket); + multiplePackets.add(packet); + singlePacket = null; + } else { + singlePacket = packet; + } + } - void addArmorStandNameChangePackets(EntityID entityID, String customName); - - void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName); - - void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack); - - void addItemStackChangePackets(EntityID entityID, ItemStack itemStack); - - void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ); - - void addEntityDestroyPackets(EntityID... entityIDs); - - void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ); - - void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID); - - void sendTo(Player player); + public void sendTo(Player player) { + if (multiplePackets != null) { + for (NMSPacket packet : multiplePackets) { + packet.sendTo(player); + } + } else if (singlePacket != null) { + singlePacket.sendTo(player); + } + } } diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ClickableNMSPacketEntity.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ClickableNMSPacketEntity.java new file mode 100644 index 00000000..49e4cb00 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ClickableNMSPacketEntity.java @@ -0,0 +1,17 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms.entity; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; + +public interface ClickableNMSPacketEntity extends NMSPacketEntity { + + EntityID getID(); + + void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ItemNMSPacketEntity.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ItemNMSPacketEntity.java new file mode 100644 index 00000000..bed5be04 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/ItemNMSPacketEntity.java @@ -0,0 +1,17 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms.entity; + +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import org.bukkit.inventory.ItemStack; + +public interface ItemNMSPacketEntity extends NMSPacketEntity { + + void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack); + + void addChangePackets(NMSPacketList packetList, ItemStack itemStack); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSPacketEntity.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSPacketEntity.java new file mode 100644 index 00000000..eb6f37f6 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/NMSPacketEntity.java @@ -0,0 +1,16 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms.entity; + +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; + +public interface NMSPacketEntity { + + void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ); + + void addDestroyPackets(NMSPacketList packetList); + +} diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/TextNMSPacketEntity.java b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/TextNMSPacketEntity.java new file mode 100644 index 00000000..714f8936 --- /dev/null +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/nms/entity/TextNMSPacketEntity.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.common.nms.entity; + +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; + +public interface TextNMSPacketEntity extends NMSPacketEntity { + + void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ); + + void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text); + + void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText); + + void addChangePackets(NMSPacketList packetList, String text); + + void addChangePackets(NMSPacketList packetList, IndividualText individualText); + + +} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionClickableNMSPacketEntity.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..f1130a33 --- /dev/null +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_10_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionItemNMSPacketEntity.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..d74c9165 --- /dev/null +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_10_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java index 6e32ac5e..ac2c5b83 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.NetworkManager; import net.minecraft.server.v1_10_R1.PlayerConnection; @@ -65,14 +67,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacketList.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacketList.java deleted file mode 100644 index 1f4c3f40..00000000 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_10_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionTextNMSPacketEntity.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..8dda1cec --- /dev/null +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_10_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionClickableNMSPacketEntity.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..5e12cdf8 --- /dev/null +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_11_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionItemNMSPacketEntity.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..5ae1bd01 --- /dev/null +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_11_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java index 4191368d..7f994204 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_11_R1.Entity; import net.minecraft.server.v1_11_R1.NetworkManager; import net.minecraft.server.v1_11_R1.PlayerConnection; @@ -65,14 +67,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacketList.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacketList.java deleted file mode 100644 index 9681271b..00000000 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_11_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionTextNMSPacketEntity.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..8c01d972 --- /dev/null +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_11_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionClickableNMSPacketEntity.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..f1de457f --- /dev/null +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_12_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionItemNMSPacketEntity.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..2dcbc096 --- /dev/null +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_12_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java index 43073512..b14e8530 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_12_R1.Entity; import net.minecraft.server.v1_12_R1.NetworkManager; import net.minecraft.server.v1_12_R1.PlayerConnection; @@ -65,14 +67,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacketList.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacketList.java deleted file mode 100644 index 9c2013b4..00000000 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_12_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionTextNMSPacketEntity.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..9d6f278d --- /dev/null +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_12_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionClickableNMSPacketEntity.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..6ce2b64e --- /dev/null +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_13_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionItemNMSPacketEntity.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..ec135126 --- /dev/null +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_13_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java index cfb0d9e7..25d501d3 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_13_R2.Entity; import net.minecraft.server.v1_13_R2.NetworkManager; import net.minecraft.server.v1_13_R2.PlayerConnection; @@ -65,14 +67,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacketList.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacketList.java deleted file mode 100644 index a62d1dc8..00000000 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_13_R2; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionTextNMSPacketEntity.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..31b490c5 --- /dev/null +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_13_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionClickableNMSPacketEntity.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..8d6e2098 --- /dev/null +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_14_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(EntityLivingSpawnNMSPacket.builder(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionItemNMSPacketEntity.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..c47fdf17 --- /dev/null +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_14_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(EntityLivingSpawnNMSPacket.builder(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java index 79581ad9..542be895 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.NetworkManager; import net.minecraft.server.v1_14_R1.PlayerConnection; @@ -50,14 +52,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacketList.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacketList.java deleted file mode 100644 index 52e34bd2..00000000 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_14_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityLivingSpawnNMSPacket.builder( - entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionTextNMSPacketEntity.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..585f42da --- /dev/null +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_14_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityLivingSpawnNMSPacket.builder( + armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionClickableNMSPacketEntity.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..bf85a1d7 --- /dev/null +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_15_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(slimeID) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionItemNMSPacketEntity.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..9922f4f5 --- /dev/null +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_15_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java index a9183a37..975d4339 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.NetworkManager; import net.minecraft.server.v1_15_R1.PlayerConnection; @@ -50,14 +52,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacketList.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacketList.java deleted file mode 100644 index 3472d11b..00000000 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_15_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionTextNMSPacketEntity.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..8a8b5627 --- /dev/null +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_15_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionClickableNMSPacketEntity.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..14b0c048 --- /dev/null +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(slimeID) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionItemNMSPacketEntity.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..f23b5182 --- /dev/null +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java index cb698f4a..c960bfb9 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_16_R1.Entity; import net.minecraft.server.v1_16_R1.NetworkManager; import net.minecraft.server.v1_16_R1.PlayerConnection; @@ -50,14 +52,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacketList.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacketList.java deleted file mode 100644 index 1b409236..00000000 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R1; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionTextNMSPacketEntity.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..a2130f3a --- /dev/null +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionClickableNMSPacketEntity.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..3e259270 --- /dev/null +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionClickableNMSPacketEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(slimeID) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionItemNMSPacketEntity.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..c929cd3b --- /dev/null +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java index 2d08e185..1a145bb0 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_16_R2.Entity; import net.minecraft.server.v1_16_R2.NetworkManager; import net.minecraft.server.v1_16_R2.PlayerConnection; @@ -50,14 +52,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacketList.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacketList.java deleted file mode 100644 index 7530302d..00000000 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSPacketList.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R2; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionTextNMSPacketEntity.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..db0eb2bc --- /dev/null +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionClickableNMSPacketEntity.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..f62246ce --- /dev/null +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionClickableNMSPacketEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(slimeID) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionItemNMSPacketEntity.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..ca881740 --- /dev/null +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java index 88befa08..12881a5f 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_16_R3.Entity; import net.minecraft.server.v1_16_R3.NetworkManager; import net.minecraft.server.v1_16_R3.PlayerConnection; @@ -50,14 +52,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacketList.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacketList.java deleted file mode 100644 index d5ee0667..00000000 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSPacketList.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_16_R3; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionTextNMSPacketEntity.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..7c4fb151 --- /dev/null +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketHelper.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketHelper.java new file mode 100644 index 00000000..3fdee7e0 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/PacketHelper.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.fcommons.logging.Log; +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList; + +import java.lang.reflect.Field; + +class PacketHelper { + + private static final boolean USE_ENTITY_LIST_DESTROY_PACKET = useEntityListDestroyPacket(); + + static void addDestroyPackets(NMSPacketList packetList, EntityID... entityIDs) { + if (USE_ENTITY_LIST_DESTROY_PACKET) { + packetList.add(new EntityListDestroyNMSPacket(entityIDs)); + } else { + for (EntityID entityID : entityIDs) { + packetList.add(new EntityDestroyNMSPacket(entityID)); + } + } + } + + private static boolean useEntityListDestroyPacket() { + try { + for (Field field : PacketPlayOutEntityDestroy.class.getDeclaredFields()) { + if (field.getType() == IntList.class) { + return true; + } + } + return false; + } catch (Throwable t) { + Log.warning("Could not detect PacketPlayOutEntityDestroy details, error can be ignored if on Minecraft 1.17.1+", t); + return true; // Assume newer Minecraft version + } + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionClickableNMSPacketEntity.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..3915f6c5 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionClickableNMSPacketEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(slimeID) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + PacketHelper.addDestroyPackets(packetList, slimeID, vehicleID); + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionItemNMSPacketEntity.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..3a6673ff --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + PacketHelper.addDestroyPackets(packetList, itemID, vehicleID); + } + +} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java index 5cac96e9..70c9b9a3 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.network.NetworkManager; import net.minecraft.server.network.PlayerConnection; import net.minecraft.world.entity.Entity; @@ -49,14 +51,23 @@ public class VersionNMSManager implements NMSManager { } } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java deleted file mode 100644 index f2ba9a61..00000000 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSPacketList.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_17_R1; - -import me.filoghost.fcommons.logging.Log; -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList; -import org.bukkit.inventory.ItemStack; - -import java.lang.reflect.Field; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - private static final boolean USE_ENTITY_LIST_DESTROY_PACKET = useEntityListDestroyPacket(); - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityLivingSpawnNMSPacket(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - if (USE_ENTITY_LIST_DESTROY_PACKET) { - add(new EntityListDestroyNMSPacket(entityIDs)); - } else { - for (EntityID entityID : entityIDs) { - add(new EntityDestroyNMSPacket(entityID)); - } - } - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - - private static boolean useEntityListDestroyPacket() { - try { - for (Field field : PacketPlayOutEntityDestroy.class.getDeclaredFields()) { - if (field.getType() == IntList.class) { - return true; - } - } - return false; - } catch (Throwable t) { - Log.warning("Could not detect PacketPlayOutEntityDestroy details, error can be ignored if on Minecraft 1.17.1+", t); - return true; // Assume newer Minecraft version - } - } - -} diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionTextNMSPacketEntity.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..de071cb7 --- /dev/null +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_17_R1; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + PacketHelper.addDestroyPackets(packetList, armorStandID); + } + +} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionClickableNMSPacketEntity.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..2a3603de --- /dev/null +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_8_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionItemNMSPacketEntity.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..96827b60 --- /dev/null +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_8_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java index adaf475e..36e2f86d 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.NetworkManager; import net.minecraft.server.v1_8_R3.PlayerConnection; @@ -62,14 +64,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacketList.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacketList.java deleted file mode 100644 index f41bbe8d..00000000 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_8_R3; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionTextNMSPacketEntity.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..3f10abfd --- /dev/null +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_8_R3; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionClickableNMSPacketEntity.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionClickableNMSPacketEntity.java new file mode 100644 index 00000000..e1cd6ecb --- /dev/null +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionClickableNMSPacketEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_9_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; + +public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity { + + private final EntityID slimeID; + private final EntityID vehicleID; + + public VersionClickableNMSPacketEntity(EntityID slimeID, EntityID vehicleID) { + this.slimeID = slimeID; + this.vehicleID = vehicleID; + } + + @Override + public EntityID getID() { + return slimeID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, positionX, positionY, positionZ) + .setInvisible() + .setSlimeSmall() // Required for a correct client-side collision box + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, slimeID)); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(slimeID, vehicleID)); + } + +} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionItemNMSPacketEntity.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionItemNMSPacketEntity.java new file mode 100644 index 00000000..344da636 --- /dev/null +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionItemNMSPacketEntity.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_9_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import org.bukkit.inventory.ItemStack; + +public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity { + + private final EntityID itemID; + private final EntityID vehicleID; + + public VersionItemNMSPacketEntity(EntityID itemID, EntityID vehicleID) { + this.itemID = itemID; + this.vehicleID = vehicleID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, ItemStack itemStack) { + packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(vehicleID) + .setArmorStandMarker() + .build() + ); + packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + packetList.add(new EntityMountNMSPacket(vehicleID, itemID)); + } + + @Override + public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) { + packetList.add(EntityMetadataNMSPacket.builder(itemID) + .setItemStack(itemStack) + .build() + ); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(vehicleID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID)); + } + +} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java index c8af8be1..5d90eb9d 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java @@ -15,8 +15,10 @@ import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSErrors; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import net.minecraft.server.v1_9_R2.Entity; import net.minecraft.server.v1_9_R2.NetworkManager; import net.minecraft.server.v1_9_R2.PlayerConnection; @@ -65,14 +67,23 @@ public class VersionNMSManager implements NMSManager { field.setStatic(value); } - @Override - public EntityID newEntityID() { + private EntityID newEntityID() { return new EntityID(entityIDGenerator); } @Override - public NMSPacketList createPacketList() { - return new VersionNMSPacketList(); + public TextNMSPacketEntity newTextPacketEntity() { + return new VersionTextNMSPacketEntity(newEntityID()); + } + + @Override + public ItemNMSPacketEntity newItemPacketEntity() { + return new VersionItemNMSPacketEntity(newEntityID(), newEntityID()); + } + + @Override + public ClickableNMSPacketEntity newClickablePacketEntity() { + return new VersionClickableNMSPacketEntity(newEntityID(), newEntityID()); } @Override diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacketList.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacketList.java deleted file mode 100644 index 048b0342..00000000 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSPacketList.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.nms.v1_9_R2; - -import me.filoghost.holographicdisplays.common.nms.AbstractNMSPacketList; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.IndividualCustomName; -import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; -import org.bukkit.inventory.ItemStack; - -class VersionNMSPacketList extends AbstractNMSPacketList { - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, String customName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandSpawnPackets( - EntityID entityID, double positionX, double positionY, double positionZ, IndividualCustomName individualCustomName) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setArmorStandMarker() - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, String customName) { - add(EntityMetadataNMSPacket.builder(entityID) - .setCustomName(customName) - .build() - ); - } - - @Override - public void addArmorStandNameChangePackets(EntityID entityID, IndividualCustomName individualCustomName) { - add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(entityID) - .setCustomName(individualCustomName.get(player)) - .build() - )); - } - - @Override - public void addItemSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ, ItemStack itemStack) { - add(new EntitySpawnNMSPacket(entityID, EntityTypeID.ITEM, positionX, positionY, positionZ)); - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addItemStackChangePackets(EntityID entityID, ItemStack itemStack) { - add(EntityMetadataNMSPacket.builder(entityID) - .setItemStack(itemStack) - .build() - ); - } - - @Override - public void addSlimeSpawnPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(EntityLivingSpawnNMSPacket.builder(entityID, EntityTypeID.SLIME, positionX, positionY, positionZ) - .setInvisible() - .setSlimeSmall() // Required for a correct client-side collision box - .build() - ); - } - - @Override - public void addEntityDestroyPackets(EntityID... entityIDs) { - add(new EntityDestroyNMSPacket(entityIDs)); - } - - @Override - public void addTeleportPackets(EntityID entityID, double positionX, double positionY, double positionZ) { - add(new EntityTeleportNMSPacket(entityID, positionX, positionY, positionZ)); - } - - @Override - public void addMountPackets(EntityID vehicleEntityID, EntityID passengerEntityID) { - add(new EntityMountNMSPacket(vehicleEntityID, passengerEntityID)); - } - -} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionTextNMSPacketEntity.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionTextNMSPacketEntity.java new file mode 100644 index 00000000..5fa61273 --- /dev/null +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionTextNMSPacketEntity.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_9_R2; + +import me.filoghost.holographicdisplays.common.nms.EntityID; +import me.filoghost.holographicdisplays.common.nms.IndividualNMSPacket; +import me.filoghost.holographicdisplays.common.nms.IndividualText; +import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; + +class VersionTextNMSPacketEntity implements TextNMSPacketEntity { + + private final EntityID armorStandID; + + VersionTextNMSPacketEntity(EntityID armorStandID) { + this.armorStandID = armorStandID; + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .build() + ); + } + + @Override + public void addSpawnPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ, String text) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(text) + .build() + ); + } + + @Override + public void addSpawnPackets( + NMSPacketList packetList, double positionX, double positionY, double positionZ, IndividualText individualText) { + packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, positionX, positionY, positionZ)); + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setArmorStandMarker() + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addChangePackets(NMSPacketList packetList, String text) { + packetList.add(EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(text) + .build() + ); + } + + @Override + public void addChangePackets(NMSPacketList packetList, IndividualText individualText) { + packetList.add(new IndividualNMSPacket(player -> EntityMetadataNMSPacket.builder(armorStandID) + .setCustomName(individualText.get(player)) + .build() + )); + } + + @Override + public void addTeleportPackets(NMSPacketList packetList, double positionX, double positionY, double positionZ) { + packetList.add(new EntityTeleportNMSPacket(armorStandID, positionX, positionY, positionZ)); + } + + @Override + public void addDestroyPackets(NMSPacketList packetList) { + packetList.add(new EntityDestroyNMSPacket(armorStandID)); + } + +} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java index 1278b622..b101d3d9 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java @@ -5,28 +5,26 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.tracking; -import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseClickableLine; import me.filoghost.holographicdisplays.plugin.listener.LineClickListener; import org.jetbrains.annotations.MustBeInvokedByOverriders; public abstract class ClickableLineTracker extends PositionBasedLineTracker { - private static final double SLIME_HEIGHT = 0.5; + private static final double CLICKABLE_ENTITY_HEIGHT = 0.5; + private final ClickableNMSPacketEntity clickableEntity; private final LineClickListener lineClickListener; - private final EntityID vehicleEntityID; - private final EntityID slimeEntityID; - private boolean spawnSlimeEntities; - private boolean spawnSlimeEntitiesChanged; + private boolean spawnClickableEntity; + private boolean spawnClickableEntityChanged; public ClickableLineTracker(T line, NMSManager nmsManager, LineClickListener lineClickListener) { - super(line, nmsManager); - this.vehicleEntityID = nmsManager.newEntityID(); - this.slimeEntityID = nmsManager.newEntityID(); + super(line); + this.clickableEntity = nmsManager.newClickablePacketEntity(); this.lineClickListener = lineClickListener; } @@ -34,7 +32,7 @@ public abstract class ClickableLineTracker extends @Override public void onRemoval() { super.onRemoval(); - lineClickListener.unregisterLine(slimeEntityID); + lineClickListener.unregisterLine(clickableEntity.getID()); } @MustBeInvokedByOverriders @@ -42,14 +40,14 @@ public abstract class ClickableLineTracker extends protected void detectChanges() { super.detectChanges(); - boolean spawnSlimeEntities = line.getClickListener() != null; - if (this.spawnSlimeEntities != spawnSlimeEntities) { - this.spawnSlimeEntities = spawnSlimeEntities; - this.spawnSlimeEntitiesChanged = true; - if (spawnSlimeEntities) { - lineClickListener.registerLine(slimeEntityID, line); + boolean spawnClickableEntity = line.getClickListener() != null; + if (this.spawnClickableEntity != spawnClickableEntity) { + this.spawnClickableEntity = spawnClickableEntity; + this.spawnClickableEntityChanged = true; + if (spawnClickableEntity) { + lineClickListener.registerLine(clickableEntity.getID(), line); } else { - lineClickListener.unregisterLine(slimeEntityID); + lineClickListener.unregisterLine(clickableEntity.getID()); } } } @@ -58,22 +56,22 @@ public abstract class ClickableLineTracker extends @Override protected void clearDetectedChanges() { super.clearDetectedChanges(); - this.spawnSlimeEntitiesChanged = false; + this.spawnClickableEntityChanged = false; } @MustBeInvokedByOverriders @Override protected void addSpawnPackets(NMSPacketList packetList) { - if (spawnSlimeEntities) { - addSlimeSpawnPackets(packetList); + if (spawnClickableEntity) { + clickableEntity.addSpawnPackets(packetList, positionX, getClickablePositionY(), positionZ); } } @MustBeInvokedByOverriders @Override protected void addDestroyPackets(NMSPacketList packetList) { - if (spawnSlimeEntities) { - addSlimeDestroyPackets(packetList); + if (spawnClickableEntity) { + clickableEntity.addDestroyPackets(packetList); } } @@ -82,11 +80,11 @@ public abstract class ClickableLineTracker extends protected void addChangesPackets(NMSPacketList packetList) { super.addChangesPackets(packetList); - if (spawnSlimeEntitiesChanged) { - if (spawnSlimeEntities) { - addSlimeSpawnPackets(packetList); + if (spawnClickableEntityChanged) { + if (spawnClickableEntity) { + clickableEntity.addSpawnPackets(packetList, positionX, getClickablePositionY(), positionZ); } else { - addSlimeDestroyPackets(packetList); + clickableEntity.addDestroyPackets(packetList); } } } @@ -94,23 +92,13 @@ public abstract class ClickableLineTracker extends @MustBeInvokedByOverriders @Override protected void addPositionChangePackets(NMSPacketList packetList) { - if (spawnSlimeEntities) { - packetList.addTeleportPackets(vehicleEntityID, positionX, getSlimePositionY(), positionZ); + if (spawnClickableEntity) { + clickableEntity.addTeleportPackets(packetList, positionX, getClickablePositionY(), positionZ); } } - private void addSlimeSpawnPackets(NMSPacketList packetList) { - packetList.addArmorStandSpawnPackets(vehicleEntityID, positionX, getSlimePositionY(), positionZ); - packetList.addSlimeSpawnPackets(slimeEntityID, positionX, getSlimePositionY(), positionZ); - packetList.addMountPackets(vehicleEntityID, slimeEntityID); - } - - private void addSlimeDestroyPackets(NMSPacketList packetList) { - packetList.addEntityDestroyPackets(slimeEntityID, vehicleEntityID); - } - - private double getSlimePositionY() { - return positionY + ((line.getHeight() - SLIME_HEIGHT) / 2); + private double getClickablePositionY() { + return positionY + ((line.getHeight() - CLICKABLE_ENTITY_HEIGHT) / 2); } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java index 3687ffef..f7eec2f2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java @@ -5,9 +5,9 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.tracking; -import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseItemLine; import me.filoghost.holographicdisplays.plugin.listener.LineClickListener; import org.bukkit.entity.Player; @@ -19,19 +19,17 @@ import java.util.Objects; public class ItemLineTracker extends ClickableLineTracker { - private final EntityID vehicleEntityID; - private final EntityID itemEntityID; + private final ItemNMSPacketEntity itemEntity; private ItemStack itemStack; private boolean itemStackChanged; - private boolean spawnItemEntities; - private boolean spawnItemEntitiesChanged; + private boolean spawnItemEntity; + private boolean spawnItemEntityChanged; public ItemLineTracker(BaseItemLine line, NMSManager nmsManager, LineClickListener lineClickListener) { super(line, nmsManager, lineClickListener); - this.vehicleEntityID = nmsManager.newEntityID(); - this.itemEntityID = nmsManager.newEntityID(); + this.itemEntity = nmsManager.newItemPacketEntity(); } @MustBeInvokedByOverriders @@ -39,7 +37,7 @@ public class ItemLineTracker extends ClickableLineTracker { protected void update(Collection onlinePlayers) { super.update(onlinePlayers); - if (spawnItemEntities && hasTrackedPlayers()) { + if (spawnItemEntity && hasTrackedPlayers()) { for (Player trackedPlayer : getTrackedPlayers()) { if (CollisionHelper.isInPickupRange(trackedPlayer, positionX, positionY, positionZ)) { line.onPickup(trackedPlayer); @@ -64,10 +62,10 @@ public class ItemLineTracker extends ClickableLineTracker { this.itemStackChanged = true; } - boolean spawnItemEntities = itemStack != null; - if (this.spawnItemEntities != spawnItemEntities) { - this.spawnItemEntities = spawnItemEntities; - this.spawnItemEntitiesChanged = true; + boolean spawnItemEntity = itemStack != null; + if (this.spawnItemEntity != spawnItemEntity) { + this.spawnItemEntity = spawnItemEntity; + this.spawnItemEntityChanged = true; } } @@ -76,7 +74,7 @@ public class ItemLineTracker extends ClickableLineTracker { protected void clearDetectedChanges() { super.clearDetectedChanges(); this.itemStackChanged = false; - this.spawnItemEntitiesChanged = false; + this.spawnItemEntityChanged = false; } @MustBeInvokedByOverriders @@ -84,8 +82,8 @@ public class ItemLineTracker extends ClickableLineTracker { protected void addSpawnPackets(NMSPacketList packetList) { super.addSpawnPackets(packetList); - if (spawnItemEntities) { - addItemSpawnPackets(packetList); + if (spawnItemEntity) { + itemEntity.addSpawnPackets(packetList, positionX, getItemPositionY(), positionZ, itemStack); } } @@ -94,8 +92,8 @@ public class ItemLineTracker extends ClickableLineTracker { protected void addDestroyPackets(NMSPacketList packetList) { super.addDestroyPackets(packetList); - if (spawnItemEntities) { - addItemDestroyPackets(packetList); + if (spawnItemEntity) { + itemEntity.addDestroyPackets(packetList); } } @@ -104,15 +102,15 @@ public class ItemLineTracker extends ClickableLineTracker { protected void addChangesPackets(NMSPacketList packetList) { super.addChangesPackets(packetList); - if (spawnItemEntitiesChanged) { - if (spawnItemEntities) { - addItemSpawnPackets(packetList); + if (spawnItemEntityChanged) { + if (spawnItemEntity) { + itemEntity.addSpawnPackets(packetList, positionX, getItemPositionY(), positionZ, itemStack); } else { - addItemDestroyPackets(packetList); + itemEntity.addDestroyPackets(packetList); } } else if (itemStackChanged) { // Only send item changes if full spawn/destroy packets were not sent - packetList.addItemStackChangePackets(itemEntityID, itemStack); + itemEntity.addChangePackets(packetList, itemStack); } } @@ -121,21 +119,11 @@ public class ItemLineTracker extends ClickableLineTracker { protected void addPositionChangePackets(NMSPacketList packetList) { super.addPositionChangePackets(packetList); - if (spawnItemEntities) { - packetList.addTeleportPackets(vehicleEntityID, positionX, getItemPositionY(), positionZ); + if (spawnItemEntity) { + itemEntity.addTeleportPackets(packetList, positionX, getItemPositionY(), positionZ); } } - private void addItemSpawnPackets(NMSPacketList packetList) { - packetList.addArmorStandSpawnPackets(vehicleEntityID, positionX, getItemPositionY(), positionZ); - packetList.addItemSpawnPackets(itemEntityID, positionX, getItemPositionY(), positionZ, itemStack); - packetList.addMountPackets(vehicleEntityID, itemEntityID); - } - - private void addItemDestroyPackets(NMSPacketList packetList) { - packetList.addEntityDestroyPackets(itemEntityID, vehicleEntityID); - } - private double getItemPositionY() { return positionY; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java index 035829ff..10319b3a 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.tracking; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLine; import org.bukkit.entity.Player; @@ -19,17 +18,15 @@ public abstract class LineTracker { protected final T line; private final Set trackedPlayers; - private final NMSManager nmsManager; /** * Flag to indicate that the line has changed in some way and there could be the need to send update packets. */ private boolean lineChanged; - LineTracker(T line, NMSManager nmsManager) { + LineTracker(T line) { this.line = line; this.trackedPlayers = new HashSet<>(); - this.nmsManager = nmsManager; } final boolean shouldBeRemoved() { @@ -63,7 +60,7 @@ public abstract class LineTracker { // Then, send the changes (if any) to already tracked players if (sendChangesPackets) { if (hasTrackedPlayers()) { - NMSPacketList packetList = nmsManager.createPacketList(); + NMSPacketList packetList = new NMSPacketList(); addChangesPackets(packetList); broadcastPackets(packetList); } @@ -94,7 +91,7 @@ public abstract class LineTracker { if (shouldTrackPlayer(player)) { if (trackedPlayers.add(player)) { if (spawnPacketList == null) { - spawnPacketList = nmsManager.createPacketList(); + spawnPacketList = new NMSPacketList(); addSpawnPackets(spawnPacketList); } spawnPacketList.sendTo(player); @@ -102,7 +99,7 @@ public abstract class LineTracker { } else { if (trackedPlayers.remove(player)) { if (destroyPacketList == null) { - destroyPacketList = nmsManager.createPacketList(); + destroyPacketList = new NMSPacketList(); addDestroyPackets(destroyPacketList); } destroyPacketList.sendTo(player); @@ -134,7 +131,7 @@ public abstract class LineTracker { return; } - NMSPacketList destroyPacketList = nmsManager.createPacketList(); + NMSPacketList destroyPacketList = new NMSPacketList(); addDestroyPackets(destroyPacketList); broadcastPackets(destroyPacketList); trackedPlayers.clear(); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java index 2ca901a6..3b280588 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.tracking; -import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLine; import org.bukkit.Location; @@ -21,8 +20,8 @@ abstract class PositionBasedLineTracker extends Line protected double positionZ; private boolean positionChanged; - PositionBasedLineTracker(T line, NMSManager nmsManager) { - super(line, nmsManager); + PositionBasedLineTracker(T line) { + super(line); } @MustBeInvokedByOverriders diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java index a19532cb..137cef5c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java @@ -5,9 +5,9 @@ */ package me.filoghost.holographicdisplays.plugin.hologram.tracking; -import me.filoghost.holographicdisplays.common.nms.EntityID; import me.filoghost.holographicdisplays.common.nms.NMSManager; import me.filoghost.holographicdisplays.common.nms.NMSPacketList; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTextLine; import me.filoghost.holographicdisplays.plugin.listener.LineClickListener; import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; @@ -17,7 +17,7 @@ import java.util.Objects; public class TextLineTracker extends ClickableLineTracker { - private final EntityID armorStandEntityID; + private final TextNMSPacketEntity textEntity; private final DisplayText displayText; private boolean displayTextChanged; @@ -29,7 +29,7 @@ public class TextLineTracker extends ClickableLineTracker { LineClickListener lineClickListener, PlaceholderTracker placeholderTracker) { super(line, nmsManager, lineClickListener); - this.armorStandEntityID = nmsManager.newEntityID(); + this.textEntity = nmsManager.newTextPacketEntity(); this.displayText = new DisplayText(placeholderTracker); } @@ -77,14 +77,14 @@ public class TextLineTracker extends ClickableLineTracker { super.addSpawnPackets(packetList); if (!allowPlaceholders) { - packetList.addArmorStandSpawnPackets( - armorStandEntityID, positionX, getArmorStandPositionY(), positionZ, displayText.getWithoutReplacements()); + textEntity.addSpawnPackets( + packetList, positionX, getTextPositionY(), positionZ, displayText.getWithoutReplacements()); } else if (displayText.containsIndividualPlaceholders()) { - packetList.addArmorStandSpawnPackets( - armorStandEntityID, positionX, getArmorStandPositionY(), positionZ, displayText::getWithIndividualReplacements); + textEntity.addSpawnPackets( + packetList, positionX, getTextPositionY(), positionZ, displayText::getWithIndividualReplacements); } else { - packetList.addArmorStandSpawnPackets( - armorStandEntityID, positionX, getArmorStandPositionY(), positionZ, displayText.getWithGlobalReplacements()); + textEntity.addSpawnPackets( + packetList, positionX, getTextPositionY(), positionZ, displayText.getWithGlobalReplacements()); } } @@ -92,7 +92,7 @@ public class TextLineTracker extends ClickableLineTracker { @Override protected void addDestroyPackets(NMSPacketList packetList) { super.addDestroyPackets(packetList); - packetList.addEntityDestroyPackets(armorStandEntityID); + textEntity.addDestroyPackets(packetList); } @Override @@ -101,11 +101,11 @@ public class TextLineTracker extends ClickableLineTracker { if (displayTextChanged) { if (!allowPlaceholders) { - packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText.getWithoutReplacements()); + textEntity.addChangePackets(packetList, displayText.getWithoutReplacements()); } else if (displayText.containsIndividualPlaceholders()) { - packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText::getWithIndividualReplacements); + textEntity.addChangePackets(packetList, displayText::getWithIndividualReplacements); } else { - packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText.getWithGlobalReplacements()); + textEntity.addChangePackets(packetList, displayText.getWithGlobalReplacements()); } } } @@ -114,10 +114,10 @@ public class TextLineTracker extends ClickableLineTracker { @Override protected void addPositionChangePackets(NMSPacketList packetList) { super.addPositionChangePackets(packetList); - packetList.addTeleportPackets(armorStandEntityID, positionX, getArmorStandPositionY(), positionZ); + textEntity.addTeleportPackets(packetList, positionX, getTextPositionY(), positionZ); } - private double getArmorStandPositionY() { + private double getTextPositionY() { return positionY - 0.29; } diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java index 00b7c689..7af93b15 100644 --- a/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/plugin/test/TestNMSManager.java @@ -5,35 +5,28 @@ */ package me.filoghost.holographicdisplays.plugin.test; -import me.filoghost.holographicdisplays.common.nms.EntityID; -import me.filoghost.holographicdisplays.common.nms.FallbackEntityIDGenerator; import me.filoghost.holographicdisplays.common.nms.NMSManager; -import me.filoghost.holographicdisplays.common.nms.NMSPacketList; import me.filoghost.holographicdisplays.common.nms.PacketListener; +import me.filoghost.holographicdisplays.common.nms.entity.ClickableNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity; +import me.filoghost.holographicdisplays.common.nms.entity.TextNMSPacketEntity; import org.bukkit.entity.Player; -import java.util.function.Supplier; - -import static org.mockito.Mockito.*; - public class TestNMSManager implements NMSManager { - private final Supplier entityIDGenerator; - private final NMSPacketList packetList; - - public TestNMSManager() { - this.entityIDGenerator = new FallbackEntityIDGenerator(); - this.packetList = mock(NMSPacketList.class); + @Override + public TextNMSPacketEntity newTextPacketEntity() { + return null; } @Override - public EntityID newEntityID() { - return new EntityID(entityIDGenerator); + public ItemNMSPacketEntity newItemPacketEntity() { + return null; } @Override - public NMSPacketList createPacketList() { - return packetList; + public ClickableNMSPacketEntity newClickablePacketEntity() { + return null; } @Override