Cleanup, fix skins not appearing by increasing tablist delay
This commit is contained in:
parent
2af792bbf1
commit
b19bb87e53
@ -9,6 +9,7 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||||
import com.comphenix.protocol.wrappers.Vector3F;
|
import com.comphenix.protocol.wrappers.Vector3F;
|
||||||
|
@ -56,6 +56,7 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||||
|
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||||
|
|
||||||
public class DisguiseUtilities
|
public class DisguiseUtilities
|
||||||
{
|
{
|
||||||
@ -1266,17 +1267,22 @@ public class DisguiseUtilities
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code to stop player pushing in 1.9
|
// Code to stop player pushing
|
||||||
Scoreboard scoreboard = player.getScoreboard();
|
Scoreboard scoreboard = player.getScoreboard();
|
||||||
Team t;
|
Team t;
|
||||||
|
|
||||||
if ((t = scoreboard.getTeam("LDPushing")) == null)
|
if ((t = scoreboard.getTeam("LDPushing")) == null)
|
||||||
{
|
{
|
||||||
t = scoreboard.registerNewTeam("LDPushing");
|
t = scoreboard.registerNewTeam("LDPushing");
|
||||||
|
|
||||||
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER)
|
||||||
|
{
|
||||||
|
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
||||||
|
t.setCanSeeFriendlyInvisibles(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!t.hasEntry(player.getName()))
|
||||||
t.addEntry(player.getName());
|
t.addEntry(player.getName());
|
||||||
|
|
||||||
// Add himself to his own entity tracker
|
// Add himself to his own entity tracker
|
||||||
@ -1411,52 +1417,33 @@ public class DisguiseUtilities
|
|||||||
/**
|
/**
|
||||||
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
||||||
*/
|
*/
|
||||||
private static void sendSelfPacket(final Player player, PacketContainer packet)
|
private static void sendSelfPacket(final Player player, final PacketContainer packet)
|
||||||
{
|
{
|
||||||
PacketContainer[][] transformed = PacketsManager.transformPacket(packet, player, player);
|
final Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||||
|
|
||||||
PacketContainer[] packets = transformed == null ? null : transformed[0];
|
// If disguised.
|
||||||
|
if (disguise == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final PacketContainer[] delayed = transformed == null ? null : transformed[1];
|
LibsPackets transformed = PacketsManager.transformPacket(packet, disguise, player, player);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (packets == null)
|
if (transformed.isUnhandled())
|
||||||
{
|
transformed.addPacket(packet);
|
||||||
packets = new PacketContainer[]
|
|
||||||
{
|
|
||||||
packet
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PacketContainer p : packets)
|
transformed.setPacketType(packet.getType());
|
||||||
|
|
||||||
|
for (PacketContainer p : transformed.getPackets())
|
||||||
{
|
{
|
||||||
p = p.deepClone();
|
p = p.deepClone();
|
||||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delayed != null && delayed.length > 0)
|
transformed.sendDelayed(player);
|
||||||
{
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (PacketContainer packet : delayed)
|
|
||||||
{
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e)
|
catch (InvocationTargetException e)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Art;
|
import org.bukkit.Art;
|
||||||
@ -20,6 +22,7 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.PacketType.Play;
|
||||||
import com.comphenix.protocol.PacketType.Play.Server;
|
import com.comphenix.protocol.PacketType.Play.Server;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
@ -38,6 +41,7 @@ import me.libraryaddict.disguise.DisguiseConfig;
|
|||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.FlagType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||||
@ -51,6 +55,97 @@ import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerViewDis
|
|||||||
|
|
||||||
public class PacketsManager
|
public class PacketsManager
|
||||||
{
|
{
|
||||||
|
public static class LibsPackets
|
||||||
|
{
|
||||||
|
private ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>();
|
||||||
|
private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<Integer, ArrayList<PacketContainer>>();
|
||||||
|
private boolean isSpawnPlayer;
|
||||||
|
private Disguise disguise;
|
||||||
|
private boolean doNothing;
|
||||||
|
|
||||||
|
public void setUnhandled()
|
||||||
|
{
|
||||||
|
doNothing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUnhandled()
|
||||||
|
{
|
||||||
|
return doNothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LibsPackets(Disguise disguise)
|
||||||
|
{
|
||||||
|
this.disguise = disguise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Disguise getDisguise()
|
||||||
|
{
|
||||||
|
return disguise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPacketType(PacketType type)
|
||||||
|
{
|
||||||
|
isSpawnPlayer = type.name().contains("SPAWN_");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPacket(PacketContainer packet)
|
||||||
|
{
|
||||||
|
packets.add(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDelayedPacket(PacketContainer packet)
|
||||||
|
{
|
||||||
|
addDelayedPacket(packet, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
getPackets().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDelayedPacket(PacketContainer packet, int ticksDelayed)
|
||||||
|
{
|
||||||
|
if (!delayedPackets.containsKey(ticksDelayed))
|
||||||
|
delayedPackets.put(ticksDelayed, new ArrayList<PacketContainer>());
|
||||||
|
|
||||||
|
delayedPackets.get(ticksDelayed).add(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<PacketContainer> getPackets()
|
||||||
|
{
|
||||||
|
return packets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDelayed(final Player observer)
|
||||||
|
{
|
||||||
|
for (final Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet())
|
||||||
|
{
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (PacketContainer packet : entry.getValue())
|
||||||
|
{
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSpawnPlayer)
|
||||||
|
{
|
||||||
|
PacketsManager.removeCancel(disguise, observer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static PacketListener clientInteractEntityListener;
|
private static PacketListener clientInteractEntityListener;
|
||||||
private static PacketListener inventoryListener;
|
private static PacketListener inventoryListener;
|
||||||
private static boolean inventoryModifierEnabled;
|
private static boolean inventoryModifierEnabled;
|
||||||
@ -60,6 +155,7 @@ public class PacketsManager
|
|||||||
private static boolean soundsListenerEnabled;
|
private static boolean soundsListenerEnabled;
|
||||||
private static PacketListener viewDisguisesListener;
|
private static PacketListener viewDisguisesListener;
|
||||||
private static boolean viewDisguisesListenerEnabled;
|
private static boolean viewDisguisesListenerEnabled;
|
||||||
|
private static HashMap<Disguise, ArrayList<UUID>> _cancelMeta = new HashMap<Disguise, ArrayList<UUID>>();
|
||||||
|
|
||||||
public static void addPacketListeners()
|
public static void addPacketListeners()
|
||||||
{
|
{
|
||||||
@ -75,18 +171,33 @@ public class PacketsManager
|
|||||||
setupMainPacketsListener();
|
setupMainPacketsListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeCancel(Disguise disguise, Player observer)
|
||||||
|
{
|
||||||
|
ArrayList<UUID> cancel;
|
||||||
|
|
||||||
|
if ((cancel = _cancelMeta.get(disguise)) == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cancel.remove(observer.getUniqueId());
|
||||||
|
|
||||||
|
if (!cancel.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
_cancelMeta.remove(disguise);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the packets I need to spawn in the disguise
|
* Construct the packets I need to spawn in the disguise
|
||||||
*/
|
*/
|
||||||
public static PacketContainer[][] constructSpawnPackets(final Player observer, Disguise disguise, Entity disguisedEntity)
|
private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity)
|
||||||
{
|
{
|
||||||
|
Disguise disguise = packets.getDisguise();
|
||||||
|
|
||||||
if (disguise.getEntity() == null)
|
if (disguise.getEntity() == null)
|
||||||
{
|
{
|
||||||
disguise.setEntity(disguisedEntity);
|
disguise.setEntity(disguisedEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<PacketContainer> packets = new ArrayList<>();
|
|
||||||
|
|
||||||
// This sends the armor packets so that the player isn't naked.
|
// 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
|
// Please note it only sends the packets that wouldn't be sent normally
|
||||||
if (DisguiseConfig.isEquipmentPacketsEnabled())
|
if (DisguiseConfig.isEquipmentPacketsEnabled())
|
||||||
@ -120,7 +231,7 @@ public class PacketsManager
|
|||||||
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
||||||
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
||||||
|
|
||||||
packets.add(packet);
|
packets.addPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,18 +266,10 @@ public class PacketsManager
|
|||||||
packet.getIntegers().write(0, disguisedEntity.getEntityId());
|
packet.getIntegers().write(0, disguisedEntity.getEntityId());
|
||||||
packet.getAttributeCollectionModifier().write(0, attributes);
|
packet.getAttributeCollectionModifier().write(0, attributes);
|
||||||
|
|
||||||
packets.add(packet);
|
packets.addPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer[] spawnPackets = new PacketContainer[2 + packets.size()];
|
|
||||||
PacketContainer[] delayedPackets = new PacketContainer[0];
|
|
||||||
|
|
||||||
for (int i = 0; i < packets.size(); i++)
|
|
||||||
{
|
|
||||||
spawnPackets[i + 2] = packets.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise), 0);
|
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise), 0);
|
||||||
|
|
||||||
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
|
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
|
||||||
@ -180,9 +283,10 @@ public class PacketsManager
|
|||||||
|
|
||||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB)
|
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB)
|
||||||
{
|
{
|
||||||
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
PacketContainer spawnOrb = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
||||||
|
packets.addPacket(spawnOrb);
|
||||||
|
|
||||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
StructureModifier<Object> mods = spawnOrb.getModifier();
|
||||||
|
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, loc.getX());
|
mods.write(1, loc.getX());
|
||||||
@ -192,9 +296,10 @@ public class PacketsManager
|
|||||||
}
|
}
|
||||||
else if (disguise.getType() == DisguiseType.PAINTING)
|
else if (disguise.getType() == DisguiseType.PAINTING)
|
||||||
{
|
{
|
||||||
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
PacketContainer spawnPainting = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
||||||
|
packets.addPacket(spawnPainting);
|
||||||
|
|
||||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
StructureModifier<Object> mods = spawnPainting.getModifier();
|
||||||
|
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, disguisedEntity.getUniqueId());
|
mods.write(1, disguisedEntity.getUniqueId());
|
||||||
@ -206,9 +311,10 @@ public class PacketsManager
|
|||||||
mods.write(4, ReflectionManager.getEnumArt(Art.values()[id]));
|
mods.write(4, ReflectionManager.getEnumArt(Art.values()[id]));
|
||||||
|
|
||||||
// Make the teleport packet to make it visible..
|
// Make the teleport packet to make it visible..
|
||||||
spawnPackets[1] = new PacketContainer(Server.ENTITY_TELEPORT);
|
PacketContainer teleportPainting = new PacketContainer(Server.ENTITY_TELEPORT);
|
||||||
|
packets.addPacket(teleportPainting);
|
||||||
|
|
||||||
mods = spawnPackets[1].getModifier();
|
mods = teleportPainting.getModifier();
|
||||||
|
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, loc.getX());
|
mods.write(1, loc.getX());
|
||||||
@ -237,78 +343,123 @@ public class PacketsManager
|
|||||||
DisguiseUtilities.getAddedByPlugins().remove(name);
|
DisguiseUtilities.getAddedByPlugins().remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
// Send player info along with the disguise
|
||||||
|
PacketContainer sendTab = new PacketContainer(Server.PLAYER_INFO);
|
||||||
|
packets.addPacket(sendTab);
|
||||||
|
|
||||||
spawnPackets[0].getIntegers().write(0, entityId); // Id
|
// Add player to the list, necessary to spawn them
|
||||||
spawnPackets[0].getModifier().write(1, gameProfile.getUUID());
|
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
||||||
|
|
||||||
spawnPackets[0].getDoubles().write(0, loc.getX());
|
List playerList = new ArrayList();
|
||||||
spawnPackets[0].getDoubles().write(1, loc.getY());
|
|
||||||
spawnPackets[0].getDoubles().write(2, loc.getZ());
|
|
||||||
|
|
||||||
spawnPackets[0].getBytes().write(0, ((byte) (int) (loc.getYaw() * 256.0F / 360.0F)));
|
playerList.add(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), playerDisguise.getGameProfile()));
|
||||||
spawnPackets[0].getBytes().write(1, ((byte) (int) (loc.getPitch() * 256.0F / 360.0F)));
|
sendTab.getModifier().write(1, playerList);
|
||||||
|
|
||||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
// Spawn the player
|
||||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); // watcher,
|
PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||||
// duh
|
|
||||||
|
spawnPlayer.getIntegers().write(0, entityId); // Id
|
||||||
|
spawnPlayer.getModifier().write(1, gameProfile.getUUID());
|
||||||
|
|
||||||
|
Location spawnAt = disguisedEntity.getLocation();
|
||||||
|
|
||||||
|
boolean selfDisguise = observer == disguisedEntity;
|
||||||
|
|
||||||
|
WrappedDataWatcher newWatcher;
|
||||||
|
|
||||||
|
if (selfDisguise)
|
||||||
|
{
|
||||||
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newWatcher = new WrappedDataWatcher();
|
||||||
|
|
||||||
|
spawnAt = observer.getLocation();
|
||||||
|
spawnAt.add(spawnAt.getDirection().normalize().multiply(20));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawn him in front of the observer
|
||||||
|
StructureModifier<Double> doubles = spawnPlayer.getDoubles();
|
||||||
|
doubles.write(0, spawnAt.getX());
|
||||||
|
doubles.write(1, spawnAt.getY());
|
||||||
|
doubles.write(2, spawnAt.getZ());
|
||||||
|
|
||||||
|
StructureModifier<Byte> bytes = spawnPlayer.getBytes();
|
||||||
|
bytes.write(0, ((byte) (int) (loc.getYaw() * 256.0F / 360.0F)));
|
||||||
|
bytes.write(1, ((byte) (int) (loc.getPitch() * 256.0F / 360.0F)));
|
||||||
|
|
||||||
|
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
|
||||||
|
|
||||||
|
// Make him invisible
|
||||||
|
newWatcher.setObject(new WrappedDataWatcherObject(FlagType.ENTITY_META.getIndex(), Registry.get(Byte.class)),
|
||||||
|
(byte) 32);
|
||||||
|
|
||||||
|
packets.addPacket(spawnPlayer);
|
||||||
|
|
||||||
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())
|
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())
|
||||||
{
|
{
|
||||||
PacketContainer[] newPackets = new PacketContainer[spawnPackets.length + 1];
|
|
||||||
|
|
||||||
System.arraycopy(spawnPackets, 1, newPackets, 2, spawnPackets.length - 1);
|
|
||||||
|
|
||||||
newPackets[0] = spawnPackets[0];
|
|
||||||
spawnPackets = newPackets;
|
|
||||||
|
|
||||||
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(
|
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(
|
||||||
loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0),
|
loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0),
|
||||||
observer.getLocation(), ((PlayerDisguise) disguise));
|
observer.getLocation(), ((PlayerDisguise) disguise));
|
||||||
|
|
||||||
System.arraycopy(bedPackets, 0, spawnPackets, 1, 2);
|
for (PacketContainer packet : bedPackets)
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
|
|
||||||
newPackets.add(null);
|
|
||||||
|
|
||||||
for (PacketContainer spawnPacket : spawnPackets)
|
|
||||||
{
|
{
|
||||||
if (spawnPacket != null)
|
packets.addPacket(packet);
|
||||||
{ // Get rid of empty packet '1' if it exists.
|
|
||||||
newPackets.add(spawnPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!selfDisguise)
|
||||||
|
{
|
||||||
|
// Teleport the player back to where he's supposed to be
|
||||||
|
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||||
|
|
||||||
// Send player info along with the disguise
|
doubles = teleportPacket.getDoubles();
|
||||||
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
|
|
||||||
spawnPackets[0] = new PacketContainer(Server.PLAYER_INFO);
|
|
||||||
|
|
||||||
// Add player to the list, necessary to spawn them
|
teleportPacket.getIntegers().write(0, entityId); // Id
|
||||||
spawnPackets[0].getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
doubles.write(0, loc.getX());
|
||||||
|
doubles.write(1, loc.getY());
|
||||||
|
doubles.write(2, loc.getZ());
|
||||||
|
|
||||||
List playerList = new ArrayList();
|
bytes = teleportPacket.getBytes();
|
||||||
|
bytes.write(0, ((byte) (int) (loc.getYaw() * 256.0F / 360.0F)));
|
||||||
|
bytes.write(1, ((byte) (int) (loc.getPitch() * 256.0F / 360.0F)));
|
||||||
|
|
||||||
playerList.add(ReflectionManager.getPlayerInfoData(spawnPackets[0].getHandle(), playerDisguise.getGameProfile()));
|
packets.addPacket(teleportPacket);
|
||||||
spawnPackets[0].getModifier().write(1, playerList);
|
}
|
||||||
|
|
||||||
|
if (!selfDisguise)
|
||||||
|
{
|
||||||
|
// Send a metadata packet
|
||||||
|
PacketContainer metaPacket = new PacketContainer(Play.Server.ENTITY_METADATA);
|
||||||
|
|
||||||
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||||
|
newWatcher.setObject(new WrappedDataWatcherObject(FlagType.ENTITY_META.getIndex(), Registry.get(Byte.class)),
|
||||||
|
(byte) 0);
|
||||||
|
|
||||||
|
metaPacket.getIntegers().write(0, entityId); // Id
|
||||||
|
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
|
||||||
|
|
||||||
|
if (!_cancelMeta.containsKey(disguise))
|
||||||
|
_cancelMeta.put(disguise, new ArrayList<UUID>());
|
||||||
|
|
||||||
|
_cancelMeta.get(disguise).add(observer.getUniqueId());
|
||||||
|
packets.addDelayedPacket(metaPacket, 4);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove player from the list
|
// Remove player from the list
|
||||||
PacketContainer delayedPacket = spawnPackets[0].shallowClone();
|
PacketContainer deleteTab = sendTab.shallowClone();
|
||||||
|
packets.addDelayedPacket(deleteTab, 40);
|
||||||
|
|
||||||
delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||||
|
|
||||||
delayedPackets = new PacketContainer[]
|
|
||||||
{
|
|
||||||
delayedPacket
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND)
|
else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND)
|
||||||
{
|
{
|
||||||
Vector vec = disguisedEntity.getVelocity();
|
Vector vec = disguisedEntity.getVelocity();
|
||||||
|
|
||||||
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
||||||
|
packets.addPacket(spawnEntity);
|
||||||
|
|
||||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
StructureModifier<Object> mods = spawnEntity.getModifier();
|
||||||
|
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, UUID.randomUUID());
|
mods.write(1, UUID.randomUUID());
|
||||||
@ -342,7 +493,7 @@ public class PacketsManager
|
|||||||
mods.write(9, yaw);
|
mods.write(9, yaw);
|
||||||
mods.write(10, pitch);
|
mods.write(10, pitch);
|
||||||
|
|
||||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
spawnEntity.getDataWatcherModifier().write(0,
|
||||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
}
|
}
|
||||||
else if (disguise.getType().isMisc())
|
else if (disguise.getType().isMisc())
|
||||||
@ -366,46 +517,39 @@ public class PacketsManager
|
|||||||
|
|
||||||
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
||||||
|
|
||||||
spawnPackets[0] = ProtocolLibrary.getProtocolManager()
|
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
|
||||||
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
|
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
|
||||||
.createPacket(nmsEntity, objectId, data);
|
.createPacket(nmsEntity, objectId, data);
|
||||||
spawnPackets[0].getModifier().write(8, pitch);
|
packets.addPacket(spawnEntity);
|
||||||
spawnPackets[0].getModifier().write(9, yaw);
|
|
||||||
|
spawnEntity.getModifier().write(8, pitch);
|
||||||
|
spawnEntity.getModifier().write(9, yaw);
|
||||||
|
|
||||||
if (disguise.getType() == DisguiseType.ITEM_FRAME)
|
if (disguise.getType() == DisguiseType.ITEM_FRAME)
|
||||||
{
|
{
|
||||||
if (data % 2 == 0)
|
if (data % 2 == 0)
|
||||||
{
|
{
|
||||||
spawnPackets[0].getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1));
|
spawnEntity.getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spawnPackets[0].getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1));
|
spawnEntity.getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (spawnPackets[1] == null || disguise.isPlayerDisguise())
|
|
||||||
|
if (packets.getPackets().size() <= 1 || disguise.isPlayerDisguise())
|
||||||
{
|
{
|
||||||
int entry = spawnPackets[1] == null ? 1 : 0;
|
PacketContainer rotateHead = new PacketContainer(Server.ENTITY_HEAD_ROTATION);
|
||||||
|
packets.addPacket(rotateHead);
|
||||||
|
|
||||||
if (entry == 0)
|
StructureModifier<Object> mods = rotateHead.getModifier();
|
||||||
{
|
|
||||||
entry = spawnPackets.length;
|
|
||||||
spawnPackets = Arrays.copyOf(spawnPackets, spawnPackets.length + 1);
|
|
||||||
}
|
|
||||||
// Make a packet to turn his head!
|
|
||||||
|
|
||||||
spawnPackets[entry] = new PacketContainer(Server.ENTITY_HEAD_ROTATION);
|
|
||||||
|
|
||||||
StructureModifier<Object> mods = spawnPackets[entry].getModifier();
|
|
||||||
|
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, yaw);
|
mods.write(1, yaw);
|
||||||
}
|
}
|
||||||
return new PacketContainer[][]
|
|
||||||
{
|
return packets;
|
||||||
spawnPackets, delayedPackets
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -813,30 +957,20 @@ public class PacketsManager
|
|||||||
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not
|
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not
|
||||||
* transformed
|
* transformed
|
||||||
*/
|
*/
|
||||||
public static PacketContainer[][] transformPacket(PacketContainer sentPacket, Player observer, Entity entity)
|
public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, Entity entity)
|
||||||
{
|
{
|
||||||
PacketContainer[] packets = null;
|
LibsPackets packets = new LibsPackets(disguise);
|
||||||
|
|
||||||
PacketContainer[] delayedPackets = new PacketContainer[0];
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
packets.addPacket(sentPacket);
|
||||||
|
|
||||||
// If disguised.
|
|
||||||
if (disguise != null)
|
|
||||||
{
|
|
||||||
packets = new PacketContainer[]
|
|
||||||
{
|
|
||||||
sentPacket
|
|
||||||
};
|
|
||||||
|
|
||||||
// This packet sends attributes
|
// This packet sends attributes
|
||||||
if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES)
|
if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
if (disguise.isMiscDisguise())
|
if (disguise.isMiscDisguise())
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -846,7 +980,10 @@ public class PacketsManager
|
|||||||
{
|
{
|
||||||
if (attribute.getAttributeKey().equals("generic.maxHealth"))
|
if (attribute.getAttributeKey().equals("generic.maxHealth"))
|
||||||
{
|
{
|
||||||
packets[0] = new PacketContainer(Server.UPDATE_ATTRIBUTES);
|
packets.clear();
|
||||||
|
|
||||||
|
PacketContainer updateAttributes = new PacketContainer(Server.UPDATE_ATTRIBUTES);
|
||||||
|
packets.addPacket(updateAttributes);
|
||||||
|
|
||||||
Builder builder;
|
Builder builder;
|
||||||
|
|
||||||
@ -867,7 +1004,7 @@ public class PacketsManager
|
|||||||
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.packet(packets[0]);
|
builder.packet(updateAttributes);
|
||||||
|
|
||||||
attributes.add(builder.build());
|
attributes.add(builder.build());
|
||||||
break;
|
break;
|
||||||
@ -876,12 +1013,12 @@ public class PacketsManager
|
|||||||
|
|
||||||
if (!attributes.isEmpty())
|
if (!attributes.isEmpty())
|
||||||
{
|
{
|
||||||
packets[0].getIntegers().write(0, entity.getEntityId());
|
packets.getPackets().get(0).getIntegers().write(0, entity.getEntityId());
|
||||||
packets[0].getAttributeCollectionModifier().write(0, attributes);
|
packets.getPackets().get(0).getAttributeCollectionModifier().write(0, attributes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -889,43 +1026,43 @@ public class PacketsManager
|
|||||||
// Else if the packet is sending entity metadata
|
// Else if the packet is sending entity metadata
|
||||||
else if (sentPacket.getType() == Server.ENTITY_METADATA)
|
else if (sentPacket.getType() == Server.ENTITY_METADATA)
|
||||||
{
|
{
|
||||||
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise))
|
packets.clear();
|
||||||
|
|
||||||
|
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)
|
||||||
|
&& (!_cancelMeta.containsKey(disguise) || !_cancelMeta.get(disguise).contains(observer.getUniqueId())))
|
||||||
{
|
{
|
||||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
|
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
|
||||||
.convert(packets[0].getWatchableCollectionModifier().read(0));
|
.convert(sentPacket.getWatchableCollectionModifier().read(0));
|
||||||
|
|
||||||
packets[0] = new PacketContainer(Server.ENTITY_METADATA);
|
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
|
||||||
|
|
||||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
packets.addPacket(metaPacket);
|
||||||
|
|
||||||
|
StructureModifier<Object> newMods = metaPacket.getModifier();
|
||||||
|
|
||||||
newMods.write(0, entity.getEntityId());
|
newMods.write(0, entity.getEntityId());
|
||||||
|
|
||||||
packets[0].getWatchableCollectionModifier().write(0, watchableObjects);
|
metaPacket.getWatchableCollectionModifier().write(0, watchableObjects);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
packets = new PacketContainer[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else if the packet is spawning..
|
// Else if the packet is spawning..
|
||||||
else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING
|
else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING
|
||||||
|| sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB
|
|| sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == Server.SPAWN_ENTITY
|
||||||
|| sentPacket.getType() == Server.SPAWN_ENTITY || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING)
|
|| sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING)
|
||||||
{
|
{
|
||||||
PacketContainer[][] spawnPackets = constructSpawnPackets(observer, disguise, entity);
|
packets.clear();
|
||||||
|
|
||||||
packets = spawnPackets[0];
|
constructSpawnPackets(observer, packets, entity);
|
||||||
delayedPackets = spawnPackets[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else if the disguise is attempting to send players a forbidden packet
|
// Else if the disguise is attempting to send players a forbidden packet
|
||||||
else if (sentPacket.getType() == Server.ANIMATION)
|
else if (sentPacket.getType() == Server.ANIMATION)
|
||||||
{
|
{
|
||||||
if (disguise.getType().isMisc() || (packets[0].getIntegers().read(1) == 2 && (!disguise.getType().isPlayer()
|
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType().isPlayer()
|
||||||
|| (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()))))
|
|| (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()))))
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -934,7 +1071,7 @@ public class PacketsManager
|
|||||||
{
|
{
|
||||||
if (disguise.getType().isMisc())
|
if (disguise.getType().isMisc())
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
|
else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
|
||||||
@ -946,10 +1083,10 @@ public class PacketsManager
|
|||||||
mods.write(0, disguise.getEntity().getEntityId());
|
mods.write(0, disguise.getEntity().getEntityId());
|
||||||
mods.write(1, 3);
|
mods.write(1, 3);
|
||||||
|
|
||||||
packets = new PacketContainer[]
|
packets.clear();
|
||||||
{
|
|
||||||
newPacket, sentPacket
|
packets.addPacket(newPacket);
|
||||||
};
|
packets.addPacket(sentPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,25 +1110,28 @@ public class PacketsManager
|
|||||||
new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
|
new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
packets = Arrays.copyOf(packets, packets.length + 1);
|
PacketContainer statusPacket = new PacketContainer(Server.ENTITY_STATUS);
|
||||||
|
packets.addPacket(statusPacket);
|
||||||
|
|
||||||
packets[1] = new PacketContainer(Server.ENTITY_STATUS);
|
statusPacket.getIntegers().write(0, entity.getEntityId());
|
||||||
|
statusPacket.getBytes().write(0, (byte) 1);
|
||||||
packets[1].getIntegers().write(0, entity.getEntityId());
|
|
||||||
packets[1].getBytes().write(0, (byte) 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop wither skulls from looking
|
// Stop wither skulls from looking
|
||||||
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL)
|
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL)
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
else if (sentPacket.getType() != Server.REL_ENTITY_MOVE)
|
else if (sentPacket.getType() != Server.REL_ENTITY_MOVE)
|
||||||
{
|
{
|
||||||
packets[0] = sentPacket.shallowClone();
|
packets.clear();
|
||||||
|
|
||||||
StructureModifier<Byte> bytes = packets[0].getBytes();
|
PacketContainer movePacket = sentPacket.shallowClone();
|
||||||
|
|
||||||
|
packets.addPacket(movePacket);
|
||||||
|
|
||||||
|
StructureModifier<Byte> bytes = movePacket.getBytes();
|
||||||
|
|
||||||
byte yawValue = bytes.read(0);
|
byte yawValue = bytes.read(0);
|
||||||
byte pitchValue = bytes.read(1);
|
byte pitchValue = bytes.read(1);
|
||||||
@ -1001,7 +1141,7 @@ public class PacketsManager
|
|||||||
|
|
||||||
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME)
|
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME)
|
||||||
{
|
{
|
||||||
StructureModifier<Double> doubles = packets[0].getDoubles();
|
StructureModifier<Double> doubles = movePacket.getDoubles();
|
||||||
|
|
||||||
Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
|
|
||||||
@ -1032,20 +1172,25 @@ public class PacketsManager
|
|||||||
// Else if the disguise is updating equipment
|
// Else if the disguise is updating equipment
|
||||||
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT)
|
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT)
|
||||||
{
|
{
|
||||||
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets[0].getModifier().read(1));
|
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
||||||
|
|
||||||
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
|
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
|
||||||
|
|
||||||
if (itemStack != null)
|
if (itemStack != null)
|
||||||
{
|
{
|
||||||
packets[0] = packets[0].shallowClone();
|
packets.clear();
|
||||||
|
|
||||||
packets[0].getModifier().write(2,
|
PacketContainer equipPacket = sentPacket.shallowClone();
|
||||||
|
|
||||||
|
packets.addPacket(equipPacket);
|
||||||
|
|
||||||
|
equipPacket.getModifier().write(2,
|
||||||
(itemStack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemStack)));
|
(itemStack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemStack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND)
|
if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND)
|
||||||
{
|
{
|
||||||
ItemStack heldItem = packets[0].getItemModifier().read(0);
|
ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0);
|
||||||
|
|
||||||
if (heldItem != null && heldItem.getType() != Material.AIR)
|
if (heldItem != null && heldItem.getType() != Material.AIR)
|
||||||
{
|
{
|
||||||
@ -1088,10 +1233,14 @@ public class PacketsManager
|
|||||||
|
|
||||||
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler
|
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler
|
||||||
// delay.
|
// delay.
|
||||||
packets = new PacketContainer[]
|
|
||||||
{
|
PacketContainer packet1 = packets.getPackets().get(0);
|
||||||
packetUnblock, packets[0], packetBlock
|
|
||||||
};
|
packets.clear();
|
||||||
|
|
||||||
|
packets.addPacket(packetUnblock);
|
||||||
|
packets.addPacket(packet1);
|
||||||
|
packets.addPacket(packetBlock);
|
||||||
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset
|
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset
|
||||||
// it.
|
// it.
|
||||||
}
|
}
|
||||||
@ -1103,16 +1252,16 @@ public class PacketsManager
|
|||||||
{
|
{
|
||||||
if (!disguise.getType().isPlayer())
|
if (!disguise.getType().isPlayer())
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the entity is updating their Facebook status, stop them from showing death
|
// If the entity is updating their Facebook status, stop them from showing death
|
||||||
else if (sentPacket.getType() == Server.ENTITY_STATUS)
|
else if (sentPacket.getType() == Server.ENTITY_STATUS)
|
||||||
{
|
{
|
||||||
if (packets[0].getBytes().read(0) == (byte) 3)
|
if (packets.getPackets().get(0).getBytes().read(0) == (byte) 3)
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[0];
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1140,29 +1289,23 @@ public class PacketsManager
|
|||||||
look.getBytes().write(0, yaw);
|
look.getBytes().write(0, yaw);
|
||||||
look.getBytes().write(1, pitch);
|
look.getBytes().write(1, pitch);
|
||||||
|
|
||||||
packets = new PacketContainer[]
|
packets.clear();
|
||||||
{
|
|
||||||
look, rotation
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Whatever
|
packets.addPacket(look);
|
||||||
|
packets.addPacket(rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
packets = null;
|
packets.setUnhandled();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return packets == null ? null : new PacketContainer[][]
|
|
||||||
{
|
return packets;
|
||||||
packets, delayedPackets
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@ import org.bukkit.inventory.EntityEquipment;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||||
import com.comphenix.protocol.wrappers.MinecraftKey;
|
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||||
|
@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities.packetlisteners;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -16,31 +15,30 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||||
|
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||||
|
|
||||||
public class PacketListenerMain extends PacketAdapter
|
public class PacketListenerMain extends PacketAdapter
|
||||||
{
|
{
|
||||||
private LibsDisguises libsDisguises;
|
|
||||||
|
|
||||||
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
|
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
|
||||||
{
|
{
|
||||||
super(plugin, ListenerPriority.HIGH, packetsToListen);
|
super(plugin, ListenerPriority.HIGH, packetsToListen);
|
||||||
|
|
||||||
libsDisguises = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event)
|
public void onPacketSending(final PacketEvent event)
|
||||||
{
|
{
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
|
||||||
return;
|
|
||||||
|
|
||||||
final Player observer = event.getPlayer();
|
final Player observer = event.getPlayer();
|
||||||
|
|
||||||
|
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
|
||||||
|
return;
|
||||||
|
|
||||||
// First get the entity, the one sending this packet
|
// First get the entity, the one sending this packet
|
||||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
|
||||||
|
|
||||||
@ -51,11 +49,16 @@ public class PacketListenerMain extends PacketAdapter
|
|||||||
if (entity == observer)
|
if (entity == observer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PacketContainer[][] packets;
|
final Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||||
|
|
||||||
|
if (disguise == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
LibsPackets packets;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity);
|
packets = PacketsManager.transformPacket(event.getPacket(), disguise, observer, entity);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -64,44 +67,23 @@ public class PacketListenerMain extends PacketAdapter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packets == null)
|
if (packets.isUnhandled())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packets.setPacketType(event.getPacketType());
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (PacketContainer packet : packets[0])
|
for (PacketContainer packet : packets.getPackets())
|
||||||
{
|
{
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PacketContainer[] delayed = packets[1];
|
packets.sendDelayed(observer);
|
||||||
|
|
||||||
if (delayed.length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (PacketContainer packet : delayed)
|
|
||||||
{
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2);
|
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex)
|
catch (InvocationTargetException ex)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType.Play.Server;
|
import com.comphenix.protocol.PacketType.Play.Server;
|
||||||
@ -20,24 +19,21 @@ import me.libraryaddict.disguise.DisguiseAPI;
|
|||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||||
|
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
|
||||||
public class PacketListenerViewDisguises extends PacketAdapter
|
public class PacketListenerViewDisguises extends PacketAdapter
|
||||||
{
|
{
|
||||||
private LibsDisguises libsDisguises;
|
|
||||||
|
|
||||||
public PacketListenerViewDisguises(LibsDisguises plugin)
|
public PacketListenerViewDisguises(LibsDisguises plugin)
|
||||||
{
|
{
|
||||||
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
|
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
|
||||||
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
|
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
|
||||||
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
|
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
|
||||||
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
|
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
|
||||||
|
|
||||||
libsDisguises = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event)
|
public void onPacketSending(final PacketEvent event)
|
||||||
{
|
{
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
@ -59,22 +55,22 @@ public class PacketListenerViewDisguises extends PacketAdapter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
|
||||||
|
|
||||||
|
if (disguise == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
|
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
|
||||||
PacketContainer[][] transformed = PacketsManager.transformPacket(event.getPacket(), observer, observer);
|
LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer);
|
||||||
|
|
||||||
PacketContainer[] packets = transformed == null ? null : transformed[0];
|
if (transformed.isUnhandled())
|
||||||
|
|
||||||
final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1];
|
|
||||||
|
|
||||||
if (packets == null)
|
|
||||||
{
|
{
|
||||||
packets = new PacketContainer[]
|
transformed.getPackets().add(event.getPacket());
|
||||||
{
|
|
||||||
event.getPacket()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PacketContainer packet : packets)
|
transformed.setPacketType(event.getPacketType());
|
||||||
|
|
||||||
|
for (PacketContainer packet : transformed.getPackets())
|
||||||
{
|
{
|
||||||
if (packet.getType() != Server.PLAYER_INFO)
|
if (packet.getType() != Server.PLAYER_INFO)
|
||||||
{
|
{
|
||||||
@ -96,26 +92,7 @@ public class PacketListenerViewDisguises extends PacketAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delayedPackets != null && delayedPackets.length > 0)
|
transformed.sendDelayed(observer);
|
||||||
{
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (PacketContainer packet : delayedPackets)
|
|
||||||
{
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvocationTargetException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getPacketType() == Server.ENTITY_METADATA)
|
if (event.getPacketType() == Server.ENTITY_METADATA)
|
||||||
{
|
{
|
||||||
@ -182,8 +159,6 @@ public class PacketListenerViewDisguises extends PacketAdapter
|
|||||||
}
|
}
|
||||||
else if (event.getPacketType() == Server.ENTITY_STATUS)
|
else if (event.getPacketType() == Server.ENTITY_STATUS)
|
||||||
{
|
{
|
||||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
|
||||||
|
|
||||||
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
|
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
|
||||||
&& event.getPacket().getBytes().read(0) == 2)
|
&& event.getPacket().getBytes().read(0) == 2)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user