Delay armor packets for player disguises
This commit is contained in:
parent
a0b47d3741
commit
4137b47ba8
@ -83,6 +83,7 @@ public class DisguiseUtilities {
|
||||
*/
|
||||
private static long velocityTime;
|
||||
private static int velocityID;
|
||||
private static HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>();
|
||||
|
||||
public static void setPlayerVelocity(Player player) {
|
||||
velocityID = player.getEntityId();
|
||||
@ -1720,7 +1721,6 @@ public class DisguiseUtilities {
|
||||
return;
|
||||
}
|
||||
|
||||
// player.spigot().setCollidesWithEntities(false);
|
||||
// Finish up
|
||||
selfDisguised.add(player.getUniqueId());
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -82,6 +83,10 @@ public class LibsPackets {
|
||||
final boolean isRemoveCancel = isSpawnPacket && largestTick.get().equals(entry.getKey());
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
if (isRemoveCancel) {
|
||||
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
||||
}
|
||||
|
||||
try {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
@ -90,10 +95,6 @@ public class LibsPackets {
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (isRemoveCancel) {
|
||||
PacketsManager.getPacketsHandler().removeCancel(disguise, observer);
|
||||
}
|
||||
}, entry.getKey());
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class PacketsHandler {
|
||||
packetHandlers.add(new PacketHandlerBed());
|
||||
packetHandlers.add(new PacketHandlerCollect());
|
||||
packetHandlers.add(new PacketHandlerEntityStatus());
|
||||
packetHandlers.add(new PacketHandlerEquipment());
|
||||
packetHandlers.add(new PacketHandlerEquipment(this));
|
||||
packetHandlers.add(new PacketHandlerHeadRotation());
|
||||
packetHandlers.add(new PacketHandlerMetadata(this));
|
||||
packetHandlers.add(new PacketHandlerMovement());
|
||||
|
@ -7,8 +7,10 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -23,6 +25,12 @@ import java.util.List;
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
*/
|
||||
public class PacketHandlerEquipment implements IPacketHandler {
|
||||
private PacketsHandler packetsHandler;
|
||||
|
||||
public PacketHandlerEquipment(PacketsHandler packetsHandler) {
|
||||
this.packetsHandler = packetsHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketType[] getHandledPackets() {
|
||||
return new PacketType[]{PacketType.Play.Server.ENTITY_EQUIPMENT};
|
||||
@ -31,6 +39,11 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
@Override
|
||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
||||
Entity entity) {
|
||||
if (packetsHandler.isCancelMeta(disguise, observer)) {
|
||||
packets.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// Else if the disguise is updating equipment
|
||||
|
||||
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
||||
@ -56,8 +69,8 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
WrappedWatchableObject watch = ReflectionManager
|
||||
.createWatchable(MetaIndex.ENTITY_META, WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META,
|
||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
|
||||
|
||||
if (watch != null)
|
||||
list.add(watch);
|
||||
|
@ -27,6 +27,7 @@ import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -71,36 +72,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
disguise.setEntity(disguisedEntity);
|
||||
}
|
||||
|
||||
// This sends the armor packets so that the player isn't naked.
|
||||
// Please note it only sends the packets that wouldn't be sent normally
|
||||
if (DisguiseConfig.isEquipmentPacketsEnabled()) {
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
||||
|
||||
if (itemstack == null || itemstack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (disguisedEntity instanceof LivingEntity) {
|
||||
ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
||||
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
||||
|
||||
packets.addDelayedPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
|
||||
@ -257,10 +228,8 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
bytes.write(0, yaw);
|
||||
bytes.write(1, pitch);
|
||||
|
||||
packets.addPacket(teleportPacket);
|
||||
}
|
||||
packets.addDelayedPacket(teleportPacket, 3);
|
||||
|
||||
if (!selfDisguise) {
|
||||
// Send a metadata packet
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
|
||||
@ -398,5 +367,49 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
|
||||
packets.addPacket(newPacket);
|
||||
}
|
||||
|
||||
boolean requiresArmor =
|
||||
(disguise.isPlayerDisguise() && disguisedEntity != observer) && disguisedEntity instanceof LivingEntity;
|
||||
// This sends the armor packets so that the player isn't naked.
|
||||
if (DisguiseConfig.isEquipmentPacketsEnabled() || requiresArmor) {
|
||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
||||
ItemStack entityItem;
|
||||
|
||||
if (itemstack == null || itemstack.getType() == Material.AIR) {
|
||||
if (requiresArmor) {
|
||||
itemstack = ReflectionManager.getEquipment(slot, disguisedEntity);
|
||||
|
||||
if (itemstack == null || itemstack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!requiresArmor && disguisedEntity instanceof LivingEntity) {
|
||||
ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity);
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
||||
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
||||
|
||||
if (requiresArmor) {
|
||||
packets.addDelayedPacket(packet, 3);
|
||||
} else {
|
||||
packets.addDelayedPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user