Large refactoring, periodically refresh individual placeholders

This commit is contained in:
filoghost 2021-09-06 08:56:00 +02:00
parent f900dbe690
commit 134eba5f41
80 changed files with 1432 additions and 1213 deletions

View File

@ -1,25 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
import java.util.function.Function;
public class IndividualNMSPacket implements NMSPacket {
private final Function<Player, NMSPacket> individualPacketFactory;
public IndividualNMSPacket(Function<Player, NMSPacket> individualPacketFactory) {
this.individualPacketFactory = individualPacketFactory;
}
@Override
public void sendTo(Player player) {
individualPacketFactory.apply(player).sendTo(player);
}
}

View File

@ -1,15 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface IndividualText {
String get(Player player);
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroupImpl.IndividualTextPacketGroup1;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroupImpl.IndividualTextPacketGroup2;
import org.bukkit.entity.Player;
public interface IndividualTextPacketGroup {
void sendTo(Player player, String text);
static IndividualTextPacketGroup of(IndividualTextPacketGroupFactory packet) {
return new IndividualTextPacketGroup1(packet);
}
static IndividualTextPacketGroup of(PacketGroup packet1, IndividualTextPacketGroupFactory packet2) {
return new IndividualTextPacketGroup2(packet1, packet2);
}
@FunctionalInterface
interface IndividualTextPacketGroupFactory {
PacketGroup createPacket(String text);
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
import java.util.Objects;
class IndividualTextPacketGroupImpl {
static class IndividualTextPacketGroup1 implements IndividualTextPacketGroup {
private final IndividualTextPacketGroupFactory packetFactory;
private PacketGroup packet;
private String lastPacketText;
IndividualTextPacketGroup1(IndividualTextPacketGroupFactory packetFactory) {
this.packetFactory = packetFactory;
}
@Override
public void sendTo(Player player, String text) {
if (packet == null || !Objects.equals(lastPacketText, text)) {
packet = packetFactory.createPacket(text);
lastPacketText = text;
}
packet.sendTo(player);
}
}
static class IndividualTextPacketGroup2 extends IndividualTextPacketGroup1 implements IndividualTextPacketGroup {
private final PacketGroup packet1;
IndividualTextPacketGroup2(PacketGroup packet1, IndividualTextPacketGroupFactory packet2Factory) {
super(packet2Factory);
this.packet1 = packet1;
}
@Override
public void sendTo(Player player, String text) {
packet1.sendTo(player);
super.sendTo(player, text);
}
}
}

View File

@ -1,14 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
public interface NMSPacket {
void sendTo(Player player);
}

View File

@ -1,43 +0,0 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class NMSPacketList {
// Lazily instantiate a list only when adding more than one element
private @Nullable NMSPacket singlePacket;
private @Nullable List<NMSPacket> multiplePackets;
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;
}
}
public void sendTo(Player player) {
if (multiplePackets != null) {
for (NMSPacket packet : multiplePackets) {
packet.sendTo(player);
}
} else if (singlePacket != null) {
singlePacket.sendTo(player);
}
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import me.filoghost.holographicdisplays.nms.common.PacketGroupImpl.PacketGroup2;
import me.filoghost.holographicdisplays.nms.common.PacketGroupImpl.PacketGroup4;
import me.filoghost.holographicdisplays.nms.common.PacketGroupImpl.PacketGroup5;
import org.bukkit.entity.Player;
public interface PacketGroup {
void sendTo(Player player);
static PacketGroup of(PacketGroup packet1, PacketGroup packet2) {
return new PacketGroup2(packet1, packet2);
}
static PacketGroup of(PacketGroup packet1, PacketGroup packet2, PacketGroup packet3, PacketGroup packet4) {
return new PacketGroup4(packet1, packet2, packet3, packet4);
}
static PacketGroup of(PacketGroup packet1, PacketGroup packet2, PacketGroup packet3, PacketGroup packet4, PacketGroup packet5) {
return new PacketGroup5(packet1, packet2, packet3, packet4, packet5);
}
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.nms.common;
import org.bukkit.entity.Player;
class PacketGroupImpl {
static class PacketGroup2 implements PacketGroup {
private final PacketGroup packet1;
private final PacketGroup packet2;
PacketGroup2(PacketGroup packet1, PacketGroup packet2) {
this.packet1 = packet1;
this.packet2 = packet2;
}
@Override
public void sendTo(Player player) {
packet1.sendTo(player);
packet2.sendTo(player);
}
}
static class PacketGroup4 implements PacketGroup {
private final PacketGroup packet1;
private final PacketGroup packet2;
private final PacketGroup packet3;
private final PacketGroup packet4;
PacketGroup4(PacketGroup packet1, PacketGroup packet2, PacketGroup packet3, PacketGroup packet4) {
this.packet1 = packet1;
this.packet2 = packet2;
this.packet3 = packet3;
this.packet4 = packet4;
}
@Override
public void sendTo(Player player) {
packet1.sendTo(player);
packet2.sendTo(player);
packet3.sendTo(player);
packet4.sendTo(player);
}
}
static class PacketGroup5 implements PacketGroup {
private final PacketGroup packet1;
private final PacketGroup packet2;
private final PacketGroup packet3;
private final PacketGroup packet4;
private final PacketGroup packet5;
PacketGroup5(PacketGroup packet1, PacketGroup packet2, PacketGroup packet3, PacketGroup packet4, PacketGroup packet5) {
this.packet1 = packet1;
this.packet2 = packet2;
this.packet3 = packet3;
this.packet4 = packet4;
this.packet5 = packet5;
}
@Override
public void sendTo(Player player) {
packet1.sendTo(player);
packet2.sendTo(player);
packet3.sendTo(player);
packet4.sendTo(player);
packet5.sendTo(player);
}
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.common.entity;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
public interface ClickableNMSPacketEntity extends NMSPacketEntity {
@ -16,6 +16,6 @@ public interface ClickableNMSPacketEntity extends NMSPacketEntity {
EntityID getID();
void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position);
PacketGroup newSpawnPackets(PositionCoordinates position);
}

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.nms.common.entity;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import org.bukkit.inventory.ItemStack;
public interface ItemNMSPacketEntity extends NMSPacketEntity {
@ -14,8 +14,8 @@ public interface ItemNMSPacketEntity extends NMSPacketEntity {
double ITEM_Y_OFFSET = 0;
double ITEM_HEIGHT = 0.7;
void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack);
PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack);
void addChangePackets(NMSPacketList packetList, ItemStack itemStack);
PacketGroup newChangePackets(ItemStack itemStack);
}

View File

@ -6,12 +6,12 @@
package me.filoghost.holographicdisplays.nms.common.entity;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
public interface NMSPacketEntity {
void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position);
PacketGroup newTeleportPackets(PositionCoordinates position);
void addDestroyPackets(NMSPacketList packetList);
PacketGroup newDestroyPackets();
}

View File

@ -6,21 +6,21 @@
package me.filoghost.holographicdisplays.nms.common.entity;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
public interface TextNMSPacketEntity extends NMSPacketEntity {
double ARMOR_STAND_Y_OFFSET = -0.29;
double ARMOR_STAND_TEXT_HEIGHT = 0.23;
void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text);
PacketGroup newSpawnPackets(PositionCoordinates position, String text);
void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText);
IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position);
void addChangePackets(NMSPacketList packetList, String text);
PacketGroup newChangePackets(String text);
void addChangePackets(NMSPacketList packetList, IndividualText individualText);
IndividualTextPacketGroup newChangePackets();
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_10_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_10_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_10_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_10_R1.Packet;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_10_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_11_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_11_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_11_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_11_R1.Packet;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_11_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_12_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_12_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_12_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_12_R1.Packet;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_12_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_13_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_13_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_13_R2;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_13_R2.Packet;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_13_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_14_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_14_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,35 +22,34 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(EntityLivingSpawnNMSPacket.builder(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
EntityLivingSpawnNMSPacket.builder(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_14_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_14_R1.Packet;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_14_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,49 +20,47 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
.build();
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new IndividualNMSPacket(player ->
EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET)
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
(String text) -> EntityLivingSpawnNMSPacket.builder(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_15_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,23 +24,24 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET),
EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_15_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_15_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_15_R1.Packet;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_15_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,23 +24,24 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET),
EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_16_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_16_R1.Packet;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_16_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,23 +24,24 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET),
EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_16_R2;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_16_R2.Packet;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_16_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,23 +24,24 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET),
EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_16_R3;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_16_R3.Packet;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_16_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -8,20 +8,23 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntArrayList;
class EntityListDestroyNMSPacket extends VersionNMSPacket {
private final Packet<?> rawPacket;
EntityListDestroyNMSPacket(EntityID... entityIDs) {
EntityListDestroyNMSPacket(EntityID entityID) {
PacketByteBuffer packetByteBuffer = PacketByteBuffer.get();
IntArrayList entityIDsList = new IntArrayList(entityIDs.length);
for (EntityID entityID : entityIDs) {
entityIDsList.add(entityID.getNumericID());
}
packetByteBuffer.writeIntList(entityIDsList);
packetByteBuffer.writeVarIntArray(entityID.getNumericID());
this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer);
}
EntityListDestroyNMSPacket(EntityID entityID1, EntityID entityID2) {
PacketByteBuffer packetByteBuffer = PacketByteBuffer.get();
packetByteBuffer.writeVarIntArray(entityID1.getNumericID(), entityID2.getNumericID());
this.rawPacket = new PacketPlayOutEntityDestroy(packetByteBuffer);
}

View File

@ -17,7 +17,7 @@ class EntityMountNMSPacket extends VersionNMSPacket {
PacketByteBuffer packetByteBuffer = PacketByteBuffer.get();
packetByteBuffer.writeVarInt(vehicleEntityID.getNumericID());
packetByteBuffer.writeIntArray(passengerEntityID.getNumericID());
packetByteBuffer.writeVarIntArray(passengerEntityID.getNumericID());
this.rawPacket = new PacketPlayOutMount(packetByteBuffer);
}

View File

@ -7,7 +7,6 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketDataSerializer;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList;
import java.util.UUID;
@ -28,18 +27,21 @@ class PacketByteBuffer extends PacketDataSerializer {
super.d(i);
}
void writeVarIntArray(int i1) {
writeVarInt(1);
writeVarInt(i1);
}
void writeVarIntArray(int i1, int i2) {
writeVarInt(2);
writeVarInt(i1);
writeVarInt(i2);
}
void writeUUID(UUID uuid) {
super.a(uuid);
}
void writeIntList(IntList intList) {
super.a(intList);
}
void writeIntArray(int... array) {
super.a(array);
}
<T> void writeDataWatcherEntry(DataWatcherKey<T> key, T value) {
writeByte(key.getIndex());
writeVarInt(key.getSerializerTypeID());

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntList;
@ -17,13 +17,21 @@ class PacketHelper {
private static final boolean USE_ENTITY_LIST_DESTROY_PACKET = useEntityListDestroyPacket();
static void addDestroyPackets(NMSPacketList packetList, EntityID... entityIDs) {
static PacketGroup newDestroyPackets(EntityID entityID) {
if (USE_ENTITY_LIST_DESTROY_PACKET) {
packetList.add(new EntityListDestroyNMSPacket(entityIDs));
return new EntityListDestroyNMSPacket(entityID);
} else {
for (EntityID entityID : entityIDs) {
packetList.add(new EntityDestroyNMSPacket(entityID));
}
return new EntityDestroyNMSPacket(entityID);
}
}
static PacketGroup newDestroyPackets(EntityID entityID1, EntityID entityID2) {
if (USE_ENTITY_LIST_DESTROY_PACKET) {
return new EntityListDestroyNMSPacket(entityID1, entityID2);
} else {
return PacketGroup.of(
new EntityDestroyNMSPacket(entityID1),
new EntityDestroyNMSPacket(entityID2));
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,23 +24,24 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET),
EntityMetadataNMSPacket.builder(slimeID)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
PacketHelper.addDestroyPackets(packetList, slimeID);
public PacketGroup newDestroyPackets() {
return PacketHelper.newDestroyPackets(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
PacketHelper.addDestroyPackets(packetList, itemID, vehicleID);
public PacketGroup newDestroyPackets() {
return PacketHelper.newDestroyPackets(itemID, vehicleID);
}
}

View File

@ -5,12 +5,12 @@
*/
package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.network.protocol.Packet;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntityLivingSpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
PacketHelper.addDestroyPackets(packetList, armorStandID);
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return PacketHelper.newDestroyPackets(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_8_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_8_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_8_R3;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_8_R3.Packet;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_8_R3;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_9_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity {
@ -24,22 +24,21 @@ public class VersionClickableNMSPacketEntity implements ClickableNMSPacketEntity
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
public PacketGroup newSpawnPackets(PositionCoordinates position) {
return EntityLivingSpawnNMSPacket.builder(slimeID, EntityTypeID.SLIME, position, SLIME_Y_OFFSET)
.setInvisible()
.setSlimeSmall() // Required for a correct client-side collision box
.build()
);
.build();
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET));
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(slimeID, position, SLIME_Y_OFFSET);
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(slimeID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(slimeID);
}
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.nms.v1_9_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import org.bukkit.inventory.ItemStack;
@ -22,36 +22,35 @@ public class VersionItemNMSPacketEntity implements ItemNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, ItemStack itemStack) {
packetList.add(new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build()
public PacketGroup newSpawnPackets(PositionCoordinates position, ItemStack itemStack) {
return PacketGroup.of(
new EntitySpawnNMSPacket(vehicleID, EntityTypeID.ARMOR_STAND, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(vehicleID)
.setArmorStandMarker()
.build(),
new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET),
EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build(),
new EntityMountNMSPacket(vehicleID, itemID)
);
packetList.add(new EntitySpawnNMSPacket(itemID, EntityTypeID.ITEM, position, ITEM_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(itemID)
}
@Override
public PacketGroup newChangePackets(ItemStack itemStack) {
return EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
packetList.add(new EntityMountNMSPacket(vehicleID, itemID));
.build();
}
@Override
public void addChangePackets(NMSPacketList packetList, ItemStack itemStack) {
packetList.add(EntityMetadataNMSPacket.builder(itemID)
.setItemStack(itemStack)
.build()
);
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(vehicleID, position, ITEM_Y_OFFSET));
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(itemID, vehicleID));
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(itemID, vehicleID);
}
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.nms.v1_9_R2;
import me.filoghost.holographicdisplays.nms.common.NMSPacket;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import net.minecraft.server.v1_9_R2.Packet;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.io.IOException;
abstract class VersionNMSPacket implements NMSPacket {
abstract class VersionNMSPacket implements PacketGroup {
@Override
public void sendTo(Player player) {

View File

@ -7,9 +7,8 @@ package me.filoghost.holographicdisplays.nms.v1_9_R2;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.EntityID;
import me.filoghost.holographicdisplays.nms.common.IndividualNMSPacket;
import me.filoghost.holographicdisplays.nms.common.IndividualText;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
@ -21,51 +20,51 @@ class VersionTextNMSPacketEntity implements TextNMSPacketEntity {
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, String text) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
);
}
@Override
public void addSpawnPackets(NMSPacketList packetList, PositionCoordinates position, IndividualText individualText) {
packetList.add(new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET));
packetList.add(new IndividualNMSPacket(player ->
public PacketGroup newSpawnPackets(PositionCoordinates position, String text) {
return PacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(individualText.get(player))
.setCustomName(text)
.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))
public IndividualTextPacketGroup newSpawnPackets(PositionCoordinates position) {
return IndividualTextPacketGroup.of(
new EntitySpawnNMSPacket(armorStandID, EntityTypeID.ARMOR_STAND, position, ARMOR_STAND_Y_OFFSET),
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setArmorStandMarker()
.setCustomName(text)
.build()
));
);
}
@Override
public void addTeleportPackets(NMSPacketList packetList, PositionCoordinates position) {
packetList.add(new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET));
public PacketGroup newChangePackets(String text) {
return EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build();
}
@Override
public void addDestroyPackets(NMSPacketList packetList) {
packetList.add(new EntityDestroyNMSPacket(armorStandID));
public IndividualTextPacketGroup newChangePackets() {
return IndividualTextPacketGroup.of(
(String text) -> EntityMetadataNMSPacket.builder(armorStandID)
.setCustomName(text)
.build()
);
}
@Override
public PacketGroup newTeleportPackets(PositionCoordinates position) {
return new EntityTeleportNMSPacket(armorStandID, position, ARMOR_STAND_Y_OFFSET);
}
@Override
public PacketGroup newDestroyPackets() {
return new EntityDestroyNMSPacket(armorStandID);
}
}

View File

@ -9,6 +9,8 @@ import me.clip.placeholderapi.PlaceholderAPI;
import me.filoghost.fcommons.Strings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PlaceholderAPIHook {
@ -22,7 +24,7 @@ public class PlaceholderAPIHook {
enabled = true;
}
public static boolean containsPlaceholderPattern(String text) {
public static boolean containsPlaceholderPattern(@Nullable String text) {
if (Strings.isEmpty(text)) {
return false;
}
@ -36,7 +38,7 @@ public class PlaceholderAPIHook {
return lastIndex - firstIndex >= 2; // At least one character between the two indexes
}
public static String replacePlaceholders(Player player, String text) {
public static @NotNull String replacePlaceholders(@NotNull Player player, @NotNull String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}

View File

@ -7,13 +7,12 @@ package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import me.filoghost.holographicdisplays.nms.common.NMSManager;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.entity.ClickableNMSPacketEntity;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseClickableHologramLine;
import me.filoghost.holographicdisplays.plugin.listener.LineClickListener;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
public abstract class ClickableLineTracker<T extends BaseClickableHologramLine> extends PositionBasedLineTracker<T> {
public abstract class ClickableLineTracker<T extends TrackedPlayer> extends PositionBasedLineTracker<T> {
private final ClickableNMSPacketEntity clickableEntity;
private final double positionOffsetY;
@ -22,13 +21,15 @@ public abstract class ClickableLineTracker<T extends BaseClickableHologramLine>
private boolean spawnClickableEntity;
private boolean spawnClickableEntityChanged;
public ClickableLineTracker(T line, NMSManager nmsManager, LineClickListener lineClickListener) {
super(line);
public ClickableLineTracker(BaseClickableHologramLine line, NMSManager nmsManager, LineClickListener lineClickListener) {
this.clickableEntity = nmsManager.newClickablePacketEntity();
this.positionOffsetY = (line.getHeight() - ClickableNMSPacketEntity.SLIME_HEIGHT) / 2;
this.lineClickListener = lineClickListener;
}
@Override
protected abstract BaseClickableHologramLine getLine();
@MustBeInvokedByOverriders
@Override
public void onRemoval() {
@ -41,12 +42,12 @@ public abstract class ClickableLineTracker<T extends BaseClickableHologramLine>
protected void detectChanges() {
super.detectChanges();
boolean spawnClickableEntity = line.hasClickCallback();
boolean spawnClickableEntity = getLine().hasClickCallback();
if (this.spawnClickableEntity != spawnClickableEntity) {
this.spawnClickableEntity = spawnClickableEntity;
this.spawnClickableEntityChanged = true;
if (spawnClickableEntity) {
lineClickListener.registerLine(clickableEntity.getID(), line);
lineClickListener.registerLine(clickableEntity.getID(), getLine());
} else {
lineClickListener.unregisterLine(clickableEntity.getID());
}
@ -62,39 +63,39 @@ public abstract class ClickableLineTracker<T extends BaseClickableHologramLine>
@MustBeInvokedByOverriders
@Override
protected void addSpawnPackets(NMSPacketList packetList) {
protected void sendSpawnPackets(Viewers<T> viewers) {
if (spawnClickableEntity) {
clickableEntity.addSpawnPackets(packetList, getClickableEntityPosition());
viewers.sendPackets(clickableEntity.newSpawnPackets(getClickableEntityPosition()));
}
}
@MustBeInvokedByOverriders
@Override
protected void addDestroyPackets(NMSPacketList packetList) {
protected void sendDestroyPackets(Viewers<T> viewers) {
if (spawnClickableEntity) {
clickableEntity.addDestroyPackets(packetList);
viewers.sendPackets(clickableEntity.newDestroyPackets());
}
}
@MustBeInvokedByOverriders
@Override
protected void addChangesPackets(NMSPacketList packetList) {
super.addChangesPackets(packetList);
protected void sendChangesPackets(Viewers<T> viewers) {
super.sendChangesPackets(viewers);
if (spawnClickableEntityChanged) {
if (spawnClickableEntity) {
clickableEntity.addSpawnPackets(packetList, getClickableEntityPosition());
viewers.sendPackets(clickableEntity.newSpawnPackets(getClickableEntityPosition()));
} else {
clickableEntity.addDestroyPackets(packetList);
viewers.sendPackets(clickableEntity.newDestroyPackets());
}
}
}
@MustBeInvokedByOverriders
@Override
protected void addPositionChangePackets(NMSPacketList packetList) {
protected void sendPositionChangePackets(Viewers<T> viewers) {
if (spawnClickableEntity) {
clickableEntity.addTeleportPackets(packetList, getClickableEntityPosition());
viewers.sendPackets(clickableEntity.newTeleportPackets(getClickableEntityPosition()));
}
}

View File

@ -5,6 +5,7 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.StringWithPlaceholders;
@ -13,39 +14,88 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Objects;
class DisplayText {
private final PlaceholderTracker placeholderTracker;
private @NotNull StringWithPlaceholders textWithoutReplacements;
private @NotNull StringWithPlaceholders textWithGlobalReplacements;
private @Nullable StringWithPlaceholders unreplacedText;
private boolean allowPlaceholders;
private @Nullable String globalText;
private boolean containsPlaceholderAPIPattern;
DisplayText(PlaceholderTracker placeholderTracker) {
this.placeholderTracker = placeholderTracker;
this.textWithoutReplacements = StringWithPlaceholders.of(null);
this.textWithGlobalReplacements = textWithoutReplacements;
}
void setWithoutReplacements(@Nullable String textString) {
textWithoutReplacements = StringWithPlaceholders.of(textString);
textWithGlobalReplacements = textWithoutReplacements;
containsPlaceholderAPIPattern = textWithoutReplacements.anyLiteralPartMatch(PlaceholderAPIHook::containsPlaceholderPattern);
boolean containsIndividualPlaceholders() {
if (!allowPlaceholders || unreplacedText == null) {
return false;
}
return containsPlaceholderAPIPattern || placeholderTracker.containsIndividualPlaceholders(unreplacedText); // TODO cache boolean value based on registry
}
String getWithoutReplacements() {
return textWithoutReplacements.getString();
void setUnreplacedText(@Nullable String text) {
unreplacedText = text != null ? StringWithPlaceholders.of(text) : null;
globalText = null;
containsPlaceholderAPIPattern = unreplacedText != null
&& unreplacedText.anyLiteralPartMatch(PlaceholderAPIHook::containsPlaceholderPattern);
}
String getWithGlobalReplacements() {
return textWithGlobalReplacements.getString();
@Nullable String getUnreplacedText() {
return unreplacedText != null ? unreplacedText.getString() : null;
}
String getWithIndividualReplacements(Player player) {
return textWithGlobalReplacements.replaceParts(
public boolean isAllowPlaceholders() {
return allowPlaceholders;
}
public void setAllowPlaceholders(boolean allowPlaceholders) {
this.allowPlaceholders = allowPlaceholders;
}
@Nullable String getGlobalText() {
return globalText;
}
public boolean updateReplacements(Collection<TextLineTrackedPlayer> trackedPlayers) {
boolean changed = false;
if (containsIndividualPlaceholders()) {
for (TextLineTrackedPlayer trackedPlayer : trackedPlayers) {
String individualText = computeIndividualText(trackedPlayer);
if (trackedPlayer.updateIndividualText(individualText)) {
changed = true;
}
}
} else {
String globalText = computeGlobalText();
if (!Objects.equals(this.globalText, globalText)) {
this.globalText = globalText;
changed = true;
}
}
return changed;
}
private @Nullable String computeGlobalText() {
if (allowPlaceholders && unreplacedText != null && unreplacedText.containsPlaceholders()) {
return unreplacedText.replacePlaceholders(placeholderTracker::updateAndGetGlobalReplacement);
} else {
return unreplacedText != null ? unreplacedText.getString() : null;
}
}
public @NotNull String computeIndividualText(TrackedPlayer trackedPlayer) {
Preconditions.notNull(unreplacedText, "unreplacedText");
Player player = trackedPlayer.getPlayer();
return unreplacedText.replaceParts(
(PlaceholderOccurrence placeholderOccurrence) -> {
return placeholderTracker.updateAndGetIndividualReplacement(placeholderOccurrence, player);
return placeholderTracker.updateAndGetReplacement(placeholderOccurrence, player);
},
(String literalPart) -> {
if (containsPlaceholderAPIPattern
@ -59,24 +109,4 @@ class DisplayText {
);
}
boolean updateGlobalReplacements() {
if (!textWithoutReplacements.containsUnreplacedPlaceholders()) {
return false;
}
StringWithPlaceholders textWithGlobalReplacements =
textWithoutReplacements.partiallyReplacePlaceholders(placeholderTracker::updateAndGetGlobalReplacement);
if (Objects.equals(this.textWithGlobalReplacements, textWithGlobalReplacements)) {
return false;
}
this.textWithGlobalReplacements = textWithGlobalReplacements;
return true;
}
boolean containsIndividualPlaceholders() {
return containsPlaceholderAPIPattern || placeholderTracker.containsIndividualPlaceholders(textWithoutReplacements);
}
}

View File

@ -6,7 +6,6 @@
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.NMSManager;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.entity.ItemNMSPacketEntity;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseItemHologramLine;
import me.filoghost.holographicdisplays.plugin.listener.LineClickListener;
@ -17,8 +16,9 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders;
import java.util.Collection;
import java.util.Objects;
public class ItemLineTracker extends ClickableLineTracker<BaseItemHologramLine> {
public class ItemLineTracker extends ClickableLineTracker<TrackedPlayer> {
private final BaseItemHologramLine line;
private final ItemNMSPacketEntity itemEntity;
private ItemStack itemStack;
@ -29,18 +29,24 @@ public class ItemLineTracker extends ClickableLineTracker<BaseItemHologramLine>
public ItemLineTracker(BaseItemHologramLine line, NMSManager nmsManager, LineClickListener lineClickListener) {
super(line, nmsManager, lineClickListener);
this.line = line;
this.itemEntity = nmsManager.newItemPacketEntity();
}
@Override
public BaseItemHologramLine getLine() {
return line;
}
@MustBeInvokedByOverriders
@Override
protected void update(Collection<? extends Player> onlinePlayers) {
super.update(onlinePlayers);
if (spawnItemEntity && hasTrackedPlayers() && line.hasPickupCallback()) {
for (Player trackedPlayer : getTrackedPlayers()) {
if (CollisionHelper.isInPickupRange(trackedPlayer, position)) {
line.onPickup(trackedPlayer);
for (TrackedPlayer trackedPlayer : getTrackedPlayers()) {
if (CollisionHelper.isInPickupRange(trackedPlayer.getPlayer(), position)) {
line.onPickup(trackedPlayer.getPlayer());
}
}
}
@ -51,6 +57,11 @@ public class ItemLineTracker extends ClickableLineTracker<BaseItemHologramLine>
return false;
}
@Override
protected TrackedPlayer createTrackedPlayer(Player player) {
return new TrackedPlayer(player);
}
@MustBeInvokedByOverriders
@Override
protected void detectChanges() {
@ -79,48 +90,48 @@ public class ItemLineTracker extends ClickableLineTracker<BaseItemHologramLine>
@MustBeInvokedByOverriders
@Override
protected void addSpawnPackets(NMSPacketList packetList) {
super.addSpawnPackets(packetList);
protected void sendSpawnPackets(Viewers<TrackedPlayer> viewers) {
super.sendSpawnPackets(viewers);
if (spawnItemEntity) {
itemEntity.addSpawnPackets(packetList, position, itemStack);
viewers.sendPackets(itemEntity.newSpawnPackets(position, itemStack));
}
}
@MustBeInvokedByOverriders
@Override
protected void addDestroyPackets(NMSPacketList packetList) {
super.addDestroyPackets(packetList);
protected void sendDestroyPackets(Viewers<TrackedPlayer> viewers) {
super.sendDestroyPackets(viewers);
if (spawnItemEntity) {
itemEntity.addDestroyPackets(packetList);
viewers.sendPackets(itemEntity.newDestroyPackets());
}
}
@MustBeInvokedByOverriders
@Override
protected void addChangesPackets(NMSPacketList packetList) {
super.addChangesPackets(packetList);
protected void sendChangesPackets(Viewers<TrackedPlayer> viewers) {
super.sendChangesPackets(viewers);
if (spawnItemEntityChanged) {
if (spawnItemEntity) {
itemEntity.addSpawnPackets(packetList, position, itemStack);
viewers.sendPackets(itemEntity.newSpawnPackets(position, itemStack));
} else {
itemEntity.addDestroyPackets(packetList);
viewers.sendPackets(itemEntity.newDestroyPackets());
}
} else if (itemStackChanged) {
// Only send item changes if full spawn/destroy packets were not sent
itemEntity.addChangePackets(packetList, itemStack);
viewers.sendPackets(itemEntity.newChangePackets(itemStack));
}
}
@MustBeInvokedByOverriders
@Override
protected void addPositionChangePackets(NMSPacketList packetList) {
super.addPositionChangePackets(packetList);
protected void sendPositionChangePackets(Viewers<TrackedPlayer> viewers) {
super.sendPositionChangePackets(viewers);
if (spawnItemEntity) {
itemEntity.addTeleportPackets(packetList, position);
viewers.sendPackets(itemEntity.newTeleportPackets(position));
}
}

View File

@ -5,32 +5,33 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLine;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
public abstract class LineTracker<T extends BaseHologramLine> {
public abstract class LineTracker<T extends TrackedPlayer> {
protected final T line;
private final Set<Player> trackedPlayers;
private final Map<Player, T> trackedPlayers;
private final Viewers<T> trackedPlayersIterableView;
/**
* 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) {
this.line = line;
this.trackedPlayers = new HashSet<>();
protected LineTracker() {
this.trackedPlayers = new HashMap<>();
this.trackedPlayersIterableView = action -> trackedPlayers.values().forEach(action);
}
protected abstract BaseHologramLine getLine();
final boolean shouldBeRemoved() {
return line.isDeleted();
return getLine().isDeleted();
}
@MustBeInvokedByOverriders
@ -60,15 +61,13 @@ public abstract class LineTracker<T extends BaseHologramLine> {
// Then, send the changes (if any) to already tracked players
if (sendChangesPackets) {
if (hasTrackedPlayers()) {
NMSPacketList packetList = new NMSPacketList();
addChangesPackets(packetList);
broadcastPackets(packetList);
sendChangesPackets(trackedPlayersIterableView);
}
clearDetectedChanges();
}
// Finally, add/remove tracked players sending them the full spawn/destroy packets
updateTrackedPlayersAndSendPackets(onlinePlayers);
modifyTrackedPlayersAndSendPackets(onlinePlayers);
}
protected abstract void detectChanges();
@ -77,49 +76,59 @@ public abstract class LineTracker<T extends BaseHologramLine> {
protected abstract boolean updatePlaceholders();
private void updateTrackedPlayersAndSendPackets(Collection<? extends Player> onlinePlayers) {
if (!line.isInLoadedChunk()) {
private void modifyTrackedPlayersAndSendPackets(Collection<? extends Player> onlinePlayers) {
if (!getLine().isInLoadedChunk()) {
clearTrackedPlayersAndSendPackets();
return;
}
// Lazy initialization
NMSPacketList spawnPacketList = null;
NMSPacketList destroyPacketList = null;
MutableViewers<T> addedPlayers = null;
MutableViewers<T> removedPlayers = null;
for (Player player : onlinePlayers) {
if (shouldTrackPlayer(player)) {
if (trackedPlayers.add(player)) {
if (spawnPacketList == null) {
spawnPacketList = new NMSPacketList();
addSpawnPackets(spawnPacketList);
if (!trackedPlayers.containsKey(player)) {
T trackedPlayer = createTrackedPlayer(player);
trackedPlayers.put(player, trackedPlayer);
if (addedPlayers == null) {
addedPlayers = new MutableViewers<>();
}
spawnPacketList.sendTo(player);
addedPlayers.add(trackedPlayer);
}
} else {
if (trackedPlayers.remove(player)) {
if (destroyPacketList == null) {
destroyPacketList = new NMSPacketList();
addDestroyPackets(destroyPacketList);
if (trackedPlayers.containsKey(player)) {
T trackedPlayer = trackedPlayers.remove(player);
if (removedPlayers == null) {
removedPlayers = new MutableViewers<>();
}
destroyPacketList.sendTo(player);
removedPlayers.add(trackedPlayer);
}
}
}
if (addedPlayers != null) {
sendSpawnPackets(addedPlayers);
}
if (removedPlayers != null) {
sendDestroyPackets(removedPlayers);
}
}
protected abstract T createTrackedPlayer(Player player);
protected abstract boolean shouldTrackPlayer(Player player);
protected final boolean hasTrackedPlayers() {
return !trackedPlayers.isEmpty();
}
protected final Set<Player> getTrackedPlayers() {
return trackedPlayers;
protected final Collection<T> getTrackedPlayers() {
return trackedPlayers.values();
}
public final boolean isTrackedPlayer(Player player) {
return trackedPlayers.contains(player);
return trackedPlayers.containsKey(player);
}
protected final void removeTrackedPlayer(Player player) {
@ -131,22 +140,14 @@ public abstract class LineTracker<T extends BaseHologramLine> {
return;
}
NMSPacketList destroyPacketList = new NMSPacketList();
addDestroyPackets(destroyPacketList);
broadcastPackets(destroyPacketList);
sendDestroyPackets(trackedPlayersIterableView);
trackedPlayers.clear();
}
private void broadcastPackets(NMSPacketList packetList) {
for (Player trackedPlayer : trackedPlayers) {
packetList.sendTo(trackedPlayer);
}
}
protected abstract void sendSpawnPackets(Viewers<T> viewers);
protected abstract void addSpawnPackets(NMSPacketList packetList);
protected abstract void sendDestroyPackets(Viewers<T> viewers);
protected abstract void addDestroyPackets(NMSPacketList packetList);
protected abstract void addChangesPackets(NMSPacketList packetList);
protected abstract void sendChangesPackets(Viewers<T> viewers);
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class MutableViewers<T extends TrackedPlayer> implements Viewers<T> {
// Optimization: the viewer is frequently only a single player
private T viewer;
private List<T> additionalViewers;
public void add(T viewer) {
if (this.viewer == null) {
this.viewer = viewer;
} else {
if (this.additionalViewers == null) {
this.additionalViewers = new ArrayList<>();
}
this.additionalViewers.add(viewer);
}
}
@Override
public void forEach(Consumer<? super T> action) {
if (viewer != null) {
action.accept(viewer);
if (additionalViewers != null) {
additionalViewers.forEach(action);
}
}
}
}

View File

@ -5,8 +5,6 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLine;
import me.filoghost.holographicdisplays.common.PositionCoordinates;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -14,21 +12,17 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders;
import java.util.Objects;
abstract class PositionBasedLineTracker<T extends BaseHologramLine> extends LineTracker<T> {
abstract class PositionBasedLineTracker<T extends TrackedPlayer> extends LineTracker<T> {
private static final int ENTITY_VIEW_RANGE = 64;
protected PositionCoordinates position;
private boolean positionChanged;
PositionBasedLineTracker(T line) {
super(line);
}
@MustBeInvokedByOverriders
@Override
protected void detectChanges() {
PositionCoordinates position = line.getPosition();
PositionCoordinates position = getLine().getPosition();
if (!Objects.equals(this.position, position)) {
this.position = position;
this.positionChanged = true;
@ -44,7 +38,7 @@ abstract class PositionBasedLineTracker<T extends BaseHologramLine> extends Line
@Override
protected final boolean shouldTrackPlayer(Player player) {
Location playerLocation = player.getLocation();
if (playerLocation.getWorld() != line.getWorldIfLoaded()) {
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
return false;
}
@ -53,17 +47,17 @@ abstract class PositionBasedLineTracker<T extends BaseHologramLine> extends Line
return diffX <= (double) ENTITY_VIEW_RANGE
&& diffZ <= (double) ENTITY_VIEW_RANGE
&& line.isVisibleTo(player);
&& getLine().isVisibleTo(player);
}
@MustBeInvokedByOverriders
@Override
protected void addChangesPackets(NMSPacketList packetList) {
protected void sendChangesPackets(Viewers<T> viewers) {
if (positionChanged) {
addPositionChangePackets(packetList);
sendPositionChangePackets(viewers);
}
}
protected abstract void addPositionChangePackets(NMSPacketList packetList);
protected abstract void sendPositionChangePackets(Viewers<T> viewers);
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
class TextLineTrackedPlayer extends TrackedPlayer {
private final DisplayText displayText;
private String individualText;
private String lastSentText;
TextLineTrackedPlayer(Player player, DisplayText displayText) {
super(player);
this.displayText = displayText;
}
public void sendTextPackets(IndividualTextPacketGroup packets) {
String text = getOrComputeText();
this.lastSentText = text;
packets.sendTo(getPlayer(), text);
}
public void sendTextPacketsIfNecessary(IndividualTextPacketGroup packets) {
String text = getOrComputeText();
if (Objects.equals(lastSentText, text)) {
return; // Avoid sending unnecessary packets
}
this.lastSentText = text;
packets.sendTo(getPlayer(), text);
}
private @Nullable String getOrComputeText() {
if (displayText.containsIndividualPlaceholders()) {
if (individualText == null) {
individualText = displayText.computeIndividualText(this);
}
return individualText;
} else {
individualText = null;
return displayText.getGlobalText();
}
}
public boolean updateIndividualText(String individualText) {
if (!this.individualText.equals(individualText)) {
this.individualText = individualText;
return true;
} else {
return false;
}
}
}

View File

@ -5,23 +5,24 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.IndividualTextPacketGroup;
import me.filoghost.holographicdisplays.nms.common.NMSManager;
import me.filoghost.holographicdisplays.nms.common.NMSPacketList;
import me.filoghost.holographicdisplays.nms.common.entity.TextNMSPacketEntity;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTextHologramLine;
import me.filoghost.holographicdisplays.plugin.listener.LineClickListener;
import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import java.util.Objects;
public class TextLineTracker extends ClickableLineTracker<BaseTextHologramLine> {
public class TextLineTracker extends ClickableLineTracker<TextLineTrackedPlayer> {
private final BaseTextHologramLine line;
private final TextNMSPacketEntity textEntity;
private final DisplayText displayText;
private boolean displayTextChanged;
private boolean allowPlaceholders;
public TextLineTracker(
BaseTextHologramLine line,
@ -29,37 +30,44 @@ public class TextLineTracker extends ClickableLineTracker<BaseTextHologramLine>
LineClickListener lineClickListener,
PlaceholderTracker placeholderTracker) {
super(line, nmsManager, lineClickListener);
this.line = line;
this.textEntity = nmsManager.newTextPacketEntity();
this.displayText = new DisplayText(placeholderTracker);
}
@Override
protected boolean updatePlaceholders() {
if (!allowPlaceholders) {
return false;
}
public BaseTextHologramLine getLine() {
return line;
}
boolean placeholdersChanged = displayText.updateGlobalReplacements();
@Override
protected boolean updatePlaceholders() {
boolean placeholdersChanged = displayText.updateReplacements(getTrackedPlayers());
if (placeholdersChanged) {
displayTextChanged = true; // Mark as changed to trigger a packet send with updated placeholders
}
return placeholdersChanged;
}
@Override
protected TextLineTrackedPlayer createTrackedPlayer(Player player) {
return new TextLineTrackedPlayer(player, displayText);
}
@MustBeInvokedByOverriders
@Override
protected void detectChanges() {
super.detectChanges();
String displayText = line.getText();
if (!Objects.equals(this.displayText.getWithoutReplacements(), displayText)) {
this.displayText.setWithoutReplacements(displayText);
if (!Objects.equals(this.displayText.getUnreplacedText(), displayText)) {
this.displayText.setUnreplacedText(displayText);
this.displayTextChanged = true;
}
boolean allowPlaceholders = line.isAllowPlaceholders();
if (this.allowPlaceholders != allowPlaceholders) {
this.allowPlaceholders = allowPlaceholders;
if (this.displayText.isAllowPlaceholders() != allowPlaceholders) {
this.displayText.setAllowPlaceholders(allowPlaceholders);
this.displayTextChanged = true;
}
}
@ -73,45 +81,35 @@ public class TextLineTracker extends ClickableLineTracker<BaseTextHologramLine>
@MustBeInvokedByOverriders
@Override
protected void addSpawnPackets(NMSPacketList packetList) {
super.addSpawnPackets(packetList);
protected void sendSpawnPackets(Viewers<TextLineTrackedPlayer> viewers) {
super.sendSpawnPackets(viewers);
if (!allowPlaceholders) {
textEntity.addSpawnPackets(packetList, position, displayText.getWithoutReplacements());
} else if (displayText.containsIndividualPlaceholders()) {
textEntity.addSpawnPackets(packetList, position, displayText::getWithIndividualReplacements);
} else {
textEntity.addSpawnPackets(packetList, position, displayText.getWithGlobalReplacements());
}
IndividualTextPacketGroup spawnPackets = textEntity.newSpawnPackets(position);
viewers.forEach(viewer -> viewer.sendTextPackets(spawnPackets));
}
@MustBeInvokedByOverriders
@Override
protected void addDestroyPackets(NMSPacketList packetList) {
super.addDestroyPackets(packetList);
textEntity.addDestroyPackets(packetList);
protected void sendDestroyPackets(Viewers<TextLineTrackedPlayer> viewers) {
super.sendDestroyPackets(viewers);
viewers.sendPackets(textEntity.newDestroyPackets());
}
@Override
protected void addChangesPackets(NMSPacketList packetList) {
super.addChangesPackets(packetList);
protected void sendChangesPackets(Viewers<TextLineTrackedPlayer> viewers) {
super.sendChangesPackets(viewers);
if (displayTextChanged) {
if (!allowPlaceholders) {
textEntity.addChangePackets(packetList, displayText.getWithoutReplacements());
} else if (displayText.containsIndividualPlaceholders()) {
textEntity.addChangePackets(packetList, displayText::getWithIndividualReplacements);
} else {
textEntity.addChangePackets(packetList, displayText.getWithGlobalReplacements());
}
IndividualTextPacketGroup changePackets = textEntity.newChangePackets();
viewers.forEach(viewer -> viewer.sendTextPacketsIfNecessary(changePackets));
}
}
@MustBeInvokedByOverriders
@Override
protected void addPositionChangePackets(NMSPacketList packetList) {
super.addPositionChangePackets(packetList);
textEntity.addTeleportPackets(packetList, position);
protected void sendPositionChangePackets(Viewers<TextLineTrackedPlayer> viewers) {
super.sendPositionChangePackets(viewers);
viewers.sendPackets(textEntity.newTeleportPackets(position));
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import org.bukkit.entity.Player;
class TrackedPlayer {
private final Player player;
TrackedPlayer(Player player) {
this.player = player;
}
public final Player getPlayer() {
return player;
}
public void sendPackets(PacketGroup packetGroup) {
packetGroup.sendTo(player);
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.holographicdisplays.nms.common.PacketGroup;
import java.util.function.Consumer;
interface Viewers<T extends TrackedPlayer> {
void forEach(Consumer<? super T> action);
default void sendPackets(PacketGroup packetGroup) {
forEach(viewer -> viewer.sendPackets(packetGroup));
}
}

View File

@ -5,6 +5,7 @@
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@FunctionalInterface
@ -12,6 +13,6 @@ public interface PlaceholderReplaceFunction {
PlaceholderReplaceFunction NO_REPLACEMENTS = placeholderOccurrence -> null;
@Nullable String getReplacement(PlaceholderOccurrence placeholderOccurrence);
@Nullable String getReplacement(@NotNull PlaceholderOccurrence placeholderOccurrence);
}

View File

@ -0,0 +1,17 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import org.jetbrains.annotations.NotNull;
@FunctionalInterface
public interface StringReplaceFunction {
StringReplaceFunction NO_REPLACEMENTS = string -> string;
@NotNull String getReplacement(@NotNull String string);
}

View File

@ -12,36 +12,30 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
public final class StringWithPlaceholders {
private static final StringWithPlaceholders NULL_INSTANCE = new StringWithPlaceholders(null, null);
private static final char PLACEHOLDER_END_CHAR = '}';
private static final char PLACEHOLDER_START_CHAR = '{';
private final @Nullable String string;
private final @NotNull String string;
private final @Nullable List<StringPart> stringParts;
public static @NotNull StringWithPlaceholders of(@Nullable String string) {
if (string == null) {
return NULL_INSTANCE;
}
public static @NotNull StringWithPlaceholders of(@NotNull String string) {
return new StringWithPlaceholders(string, splitToParts(string));
}
private StringWithPlaceholders(@Nullable String string, @Nullable List<StringPart> stringParts) {
private StringWithPlaceholders(@NotNull String string, @Nullable List<StringPart> stringParts) {
this.string = string;
this.stringParts = stringParts;
}
public @Nullable String getString() {
public @NotNull String getString() {
return string;
}
public boolean containsUnreplacedPlaceholders() {
if (string == null || stringParts == null) {
public boolean containsPlaceholders() {
if (stringParts == null) {
return false;
}
@ -87,48 +81,26 @@ public final class StringWithPlaceholders {
return false;
}
public @NotNull StringWithPlaceholders partiallyReplacePlaceholders(PlaceholderReplaceFunction replaceFunction) {
if (stringParts == null) {
return this;
}
List<StringPart> newStringParts = new ArrayList<>(stringParts.size());
for (StringPart part : stringParts) {
if (part instanceof PlaceholderPart) {
String replacement = replaceFunction.getReplacement(((PlaceholderPart) part).getPlaceholderOccurrence());
if (replacement != null) {
// Do not use LiteralPart to avoid potentially replacing it again later
newStringParts.add(new ReplacementPart(replacement));
} else {
// Placeholder was not replaced, may be replaced later
newStringParts.add(part);
}
} else {
newStringParts.add(part);
}
}
return new StringWithPlaceholders(joinParts(newStringParts), newStringParts);
public @NotNull String replacePlaceholders(PlaceholderReplaceFunction replaceFunction) {
return replaceParts(replaceFunction, StringReplaceFunction.NO_REPLACEMENTS);
}
public @Nullable String replacePlaceholders(PlaceholderReplaceFunction replaceFunction) {
return replaceParts(replaceFunction, UnaryOperator.identity());
}
public String replaceLiteralParts(UnaryOperator<String> replaceFunction) {
public @NotNull String replaceLiteralParts(StringReplaceFunction replaceFunction) {
return replaceParts(PlaceholderReplaceFunction.NO_REPLACEMENTS, replaceFunction);
}
public String replaceParts(PlaceholderReplaceFunction placeholderReplaceFunction, UnaryOperator<String> literalPartReplaceFunction) {
if (string == null || stringParts == null) {
return literalPartReplaceFunction.apply(string);
public @NotNull String replaceParts(
PlaceholderReplaceFunction placeholderReplaceFunction,
StringReplaceFunction literalPartReplaceFunction) {
if (stringParts == null) {
return literalPartReplaceFunction.getReplacement(string);
}
StringBuilder output = new StringBuilder(string.length());
for (StringPart part : stringParts) {
if (part instanceof LiteralPart) {
output.append(literalPartReplaceFunction.apply(part.getRawValue()));
output.append(literalPartReplaceFunction.getReplacement(part.getRawValue()));
} else {
output.append(part.getValue(placeholderReplaceFunction));
}
@ -191,14 +163,6 @@ public final class StringWithPlaceholders {
return stringParts;
}
private static String joinParts(@NotNull List<StringPart> stringParts) {
StringBuilder stringBuilder = new StringBuilder();
for (StringPart stringPart : stringParts) {
stringBuilder.append(stringPart.getRawValue());
}
return stringBuilder.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
@ -248,27 +212,6 @@ public final class StringWithPlaceholders {
}
private static class ReplacementPart implements StringPart {
private final String replacement;
ReplacementPart(@NotNull String replacement) {
this.replacement = replacement;
}
@Override
public String getValue(PlaceholderReplaceFunction placeholderReplaceFunction) {
return replacement;
}
@Override
public String getRawValue() {
return replacement;
}
}
private static class PlaceholderPart implements StringPart {
private final PlaceholderOccurrence placeholderOccurrence;

View File

@ -57,21 +57,22 @@ public class PlaceholderTracker {
}
public @Nullable String updateAndGetGlobalReplacement(PlaceholderOccurrence placeholderOccurrence) {
return updateAndGetReplacement(placeholderOccurrence, null, false);
}
public @Nullable String updateAndGetIndividualReplacement(PlaceholderOccurrence placeholderOccurrence, Player player) {
return updateAndGetReplacement(placeholderOccurrence, player, true);
}
private @Nullable String updateAndGetReplacement(PlaceholderOccurrence placeholderOccurrence, Player player, boolean individual) {
try {
TrackedPlaceholder trackedPlaceholder = getTrackedPlaceholder(placeholderOccurrence);
if (trackedPlaceholder.isIndividual() == individual) {
return trackedPlaceholder.updateAndGetReplacement(player, tickClock.getCurrentTick());
} else {
if (trackedPlaceholder.isIndividual()) {
return null;
}
return trackedPlaceholder.updateAndGetReplacement(null, tickClock.getCurrentTick());
} catch (PlaceholderException e) {
exceptionHandler.handle(e);
return "[Error]";
}
}
public @Nullable String updateAndGetReplacement(PlaceholderOccurrence placeholderOccurrence, Player player) {
try {
TrackedPlaceholder trackedPlaceholder = getTrackedPlaceholder(placeholderOccurrence);
return trackedPlaceholder.updateAndGetReplacement(player, tickClock.getCurrentTick());
} catch (PlaceholderException e) {
exceptionHandler.handle(e);
return "[Error]";
@ -108,7 +109,7 @@ public class PlaceholderTracker {
}
}
public boolean containsIndividualPlaceholders(StringWithPlaceholders textWithPlaceholders) {
public boolean containsIndividualPlaceholders(@NotNull StringWithPlaceholders textWithPlaceholders) {
return textWithPlaceholders.anyPlaceholderMatch(occurrence -> {
PlaceholderExpansion placeholderExpansion = registry.find(occurrence);
return placeholderExpansion != null && placeholderExpansion.isIndividual();

View File

@ -25,17 +25,7 @@ class StringWithPlaceholdersTest {
StringWithPlaceholders s = StringWithPlaceholders.of(input);
assertThat(s.replacePlaceholders(occurrence -> "#")).isEqualTo(expectedOutput);
assertThat(s.containsUnreplacedPlaceholders()).isEqualTo(expectedContainsPlaceholders);
}
@ParameterizedTest(name = "[{index}] {0} -> {1}")
@MethodSource("replacementsTestArguments")
void partialReplacements(String input, String expectedOutput) {
StringWithPlaceholders s = StringWithPlaceholders.of(input);
assertThat(s.partiallyReplacePlaceholders(occurrence -> "#").getString()).isEqualTo(expectedOutput);
assertThat(s.partiallyReplacePlaceholders(occurrence -> null).replacePlaceholders(occurrence -> "#")).isEqualTo(expectedOutput);
assertThat(s.partiallyReplacePlaceholders(occurrence -> "#").containsUnreplacedPlaceholders()).isFalse();
assertThat(s.containsPlaceholders()).isEqualTo(expectedContainsPlaceholders);
}
static Stream<Arguments> replacementsTestArguments() {