2016-05-12 13:30:22 +02:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
|
|
|
|
|
|
|
import com.comphenix.protocol.PacketType;
|
2016-10-04 15:11:50 +02:00
|
|
|
import com.comphenix.protocol.PacketType.Play;
|
2016-05-12 13:30:22 +02:00
|
|
|
import com.comphenix.protocol.PacketType.Play.Server;
|
|
|
|
import com.comphenix.protocol.ProtocolLibrary;
|
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
|
|
|
import com.comphenix.protocol.events.PacketListener;
|
|
|
|
import com.comphenix.protocol.reflect.StructureModifier;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
2018-02-14 08:15:56 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.*;
|
2018-09-23 01:07:54 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
2016-05-12 13:30:22 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
2018-02-14 08:15:56 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.packetlisteners.*;
|
|
|
|
import org.bukkit.Art;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.*;
|
|
|
|
import org.bukkit.inventory.EquipmentSlot;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Map.Entry;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public class PacketsManager {
|
|
|
|
public static class LibsPackets {
|
2017-06-27 04:53:10 +02:00
|
|
|
private ArrayList<PacketContainer> packets = new ArrayList<>();
|
|
|
|
private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>();
|
2016-11-28 15:00:03 +01:00
|
|
|
private boolean isSpawnPacket;
|
2016-10-04 15:11:50 +02:00
|
|
|
private Disguise disguise;
|
|
|
|
private boolean doNothing;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void setUnhandled() {
|
2016-10-04 15:11:50 +02:00
|
|
|
doNothing = true;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public boolean isUnhandled() {
|
2016-10-04 15:11:50 +02:00
|
|
|
return doNothing;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
private LibsPackets(Disguise disguise) {
|
2016-10-04 15:11:50 +02:00
|
|
|
this.disguise = disguise;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public Disguise getDisguise() {
|
2016-10-04 15:11:50 +02:00
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void setPacketType(PacketType type) {
|
2016-11-30 05:31:12 +01:00
|
|
|
isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY");
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void addPacket(PacketContainer packet) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.add(packet);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void addDelayedPacket(PacketContainer packet) {
|
2016-10-04 15:11:50 +02:00
|
|
|
addDelayedPacket(packet, 2);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void clear() {
|
2016-10-04 15:11:50 +02:00
|
|
|
getPackets().clear();
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public void addDelayedPacket(PacketContainer packet, int ticksDelayed) {
|
2016-10-04 15:11:50 +02:00
|
|
|
if (!delayedPackets.containsKey(ticksDelayed))
|
|
|
|
delayedPackets.put(ticksDelayed, new ArrayList<PacketContainer>());
|
|
|
|
|
|
|
|
delayedPackets.get(ticksDelayed).add(packet);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public ArrayList<PacketContainer> getPackets() {
|
2016-10-04 15:11:50 +02:00
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
2016-11-26 16:36:57 +01:00
|
|
|
public Collection<ArrayList<PacketContainer>> getDelayedPackets() {
|
|
|
|
return delayedPackets.values();
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
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()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (InvocationTargetException e) {
|
2016-10-04 15:11:50 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:00:03 +01:00
|
|
|
if (isSpawnPacket) {
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketsManager.removeCancel(disguise, observer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, entry.getKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
private static PacketListener clientInteractEntityListener;
|
|
|
|
private static PacketListener inventoryListener;
|
|
|
|
private static boolean inventoryModifierEnabled;
|
|
|
|
private static LibsDisguises libsDisguises;
|
|
|
|
private static PacketListener mainListener;
|
|
|
|
private static PacketListener soundsListener;
|
|
|
|
private static boolean soundsListenerEnabled;
|
|
|
|
private static PacketListener viewDisguisesListener;
|
|
|
|
private static boolean viewDisguisesListenerEnabled;
|
2017-06-27 04:53:10 +02:00
|
|
|
private static HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<>();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void addPacketListeners() {
|
2016-05-12 13:30:22 +02:00
|
|
|
// Add a client listener to cancel them interacting with uninteractable disguised entitys.
|
|
|
|
// You ain't supposed to be allowed to 'interact' with a item that cannot be clicked.
|
|
|
|
// Because it kicks you for hacking.
|
|
|
|
|
|
|
|
clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises);
|
2017-06-27 04:53:10 +02:00
|
|
|
PacketListener tabListListener = new PacketListenerTabList(libsDisguises);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener);
|
2016-11-30 05:08:12 +01:00
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
// Now I call this and the main listener is registered!
|
|
|
|
setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void removeCancel(Disguise disguise, Player observer) {
|
2016-10-04 15:11:50 +02:00
|
|
|
ArrayList<UUID> cancel;
|
|
|
|
|
2016-11-30 05:31:12 +01:00
|
|
|
if ((cancel = cancelMeta.get(disguise)) == null)
|
2016-10-04 15:11:50 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
cancel.remove(observer.getUniqueId());
|
|
|
|
|
|
|
|
if (!cancel.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 05:31:12 +01:00
|
|
|
cancelMeta.remove(disguise);
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
/**
|
|
|
|
* Construct the packets I need to spawn in the disguise
|
|
|
|
*/
|
2017-03-21 13:22:00 +01:00
|
|
|
private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets,
|
|
|
|
Entity disguisedEntity) {
|
2016-10-04 15:11:50 +02:00
|
|
|
Disguise disguise = packets.getDisguise();
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise.getEntity() == null) {
|
2016-05-12 13:30:22 +02:00
|
|
|
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
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isEquipmentPacketsEnabled()) {
|
|
|
|
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (itemstack == null || itemstack.getType() == Material.AIR) {
|
2016-05-12 13:30:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguisedEntity instanceof LivingEntity) {
|
2017-06-27 04:53:10 +02:00
|
|
|
ItemStack item = ReflectionManager.getEquipment(slot, disguisedEntity);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-06-27 04:53:10 +02:00
|
|
|
if (item != null && item.getType() != Material.AIR) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PacketContainer packet = new PacketContainer(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));
|
|
|
|
|
2017-06-27 04:53:10 +02:00
|
|
|
packets.addDelayedPacket(packet);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
|
|
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-06-27 04:53:10 +02:00
|
|
|
ArrayList<WrappedAttribute> attributes = new ArrayList<>();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth");
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
2018-02-14 08:15:56 +01:00
|
|
|
} else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() &&
|
|
|
|
disguisedEntity instanceof Damageable) {
|
2016-05-12 13:30:22 +02:00
|
|
|
builder.baseValue(((Damageable) disguisedEntity).getMaxHealth());
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-05-12 13:30:22 +02:00
|
|
|
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
|
|
|
}
|
|
|
|
|
|
|
|
PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
|
|
|
|
|
|
|
|
builder.packet(packet);
|
|
|
|
|
|
|
|
attributes.add(builder.build());
|
|
|
|
|
|
|
|
packet.getIntegers().write(0, disguisedEntity.getEntityId());
|
|
|
|
packet.getAttributeCollectionModifier().write(0, attributes);
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(packet);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise), 0);
|
|
|
|
|
|
|
|
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
|
|
|
|
byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isMovementPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
yaw = getYaw(disguise.getType(), disguisedEntity.getType(), yaw);
|
|
|
|
pitch = getPitch(disguise.getType(), DisguiseType.getType(disguisedEntity.getType()), pitch);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer spawnOrb = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
|
|
|
packets.addPacket(spawnOrb);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Object> mods = spawnOrb.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
mods.write(0, disguisedEntity.getEntityId());
|
|
|
|
mods.write(1, loc.getX());
|
|
|
|
mods.write(2, loc.getY() + 0.06);
|
|
|
|
mods.write(3, loc.getZ());
|
|
|
|
mods.write(4, 1);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType() == DisguiseType.PAINTING) {
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer spawnPainting = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
|
|
|
packets.addPacket(spawnPainting);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Object> mods = spawnPainting.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
mods.write(0, disguisedEntity.getEntityId());
|
|
|
|
mods.write(1, disguisedEntity.getUniqueId());
|
|
|
|
mods.write(2, ReflectionManager.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
|
|
|
mods.write(3, ReflectionManager.getEnumDirection(((int) loc.getYaw()) % 4));
|
|
|
|
|
|
|
|
int id = ((MiscDisguise) disguise).getData();
|
|
|
|
|
|
|
|
mods.write(4, ReflectionManager.getEnumArt(Art.values()[id]));
|
|
|
|
|
|
|
|
// Make the teleport packet to make it visible..
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer teleportPainting = new PacketContainer(Server.ENTITY_TELEPORT);
|
|
|
|
packets.addPacket(teleportPainting);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
mods = teleportPainting.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
mods.write(0, disguisedEntity.getEntityId());
|
|
|
|
mods.write(1, loc.getX());
|
|
|
|
mods.write(2, loc.getY());
|
|
|
|
mods.write(3, loc.getZ());
|
|
|
|
mods.write(4, yaw);
|
|
|
|
mods.write(5, pitch);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType().isPlayer()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
|
|
|
|
2016-06-14 11:08:53 +02:00
|
|
|
String name = playerDisguise.getName();
|
2018-02-14 08:15:56 +01:00
|
|
|
WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
int entityId = disguisedEntity.getEntityId();
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Send player info along with the disguise
|
|
|
|
PacketContainer sendTab = new PacketContainer(Server.PLAYER_INFO);
|
2016-11-30 05:08:12 +01:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
|
|
|
// Add player to the list, necessary to spawn them
|
|
|
|
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
2016-10-04 15:11:50 +02:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
List playerList = Collections
|
|
|
|
.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), gameProfile));
|
|
|
|
sendTab.getModifier().write(1, playerList);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
packets.addPacket(sendTab);
|
|
|
|
}
|
2016-06-27 20:05:24 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Spawn the player
|
|
|
|
PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnPlayer.getIntegers().write(0, entityId); // Id
|
|
|
|
spawnPlayer.getModifier().write(1, gameProfile.getUUID());
|
2016-06-27 20:05:24 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
Location spawnAt = disguisedEntity.getLocation();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
boolean selfDisguise = observer == disguisedEntity;
|
|
|
|
|
|
|
|
WrappedDataWatcher newWatcher;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (selfDisguise) {
|
2017-03-21 13:22:00 +01:00
|
|
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
|
|
|
|
disguise.getWatcher());
|
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
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());
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Byte> bytes = spawnPlayer.getBytes();
|
2017-07-18 10:15:06 +02:00
|
|
|
bytes.write(0, yaw);
|
|
|
|
bytes.write(1, pitch);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Make him invisible
|
2017-06-27 04:53:10 +02:00
|
|
|
newWatcher
|
|
|
|
.setObject(new WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), Registry.get(Byte.class)),
|
|
|
|
(byte) 32);
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
packets.addPacket(spawnPlayer);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
2016-06-13 22:55:30 +02:00
|
|
|
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(
|
2016-05-12 13:30:22 +02:00
|
|
|
loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0),
|
|
|
|
observer.getLocation(), ((PlayerDisguise) disguise));
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (PacketContainer packet : bedPackets) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(packet);
|
|
|
|
}
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (!selfDisguise) {
|
2016-10-04 15:11:50 +02:00
|
|
|
// Teleport the player back to where he's supposed to be
|
|
|
|
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
doubles = teleportPacket.getDoubles();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
teleportPacket.getIntegers().write(0, entityId); // Id
|
|
|
|
doubles.write(0, loc.getX());
|
|
|
|
doubles.write(1, loc.getY());
|
|
|
|
doubles.write(2, loc.getZ());
|
|
|
|
|
|
|
|
bytes = teleportPacket.getBytes();
|
2017-07-18 10:15:06 +02:00
|
|
|
bytes.write(0, yaw);
|
|
|
|
bytes.write(1, pitch);
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
packets.addPacket(teleportPacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (!selfDisguise) {
|
2016-10-04 15:11:50 +02:00
|
|
|
// Send a metadata packet
|
|
|
|
PacketContainer metaPacket = new PacketContainer(Play.Server.ENTITY_METADATA);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-03-21 13:22:00 +01:00
|
|
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
|
|
|
|
disguise.getWatcher());
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
metaPacket.getIntegers().write(0, entityId); // Id
|
|
|
|
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-30 05:31:12 +01:00
|
|
|
if (!cancelMeta.containsKey(disguise))
|
|
|
|
cancelMeta.put(disguise, new ArrayList<UUID>());
|
|
|
|
|
|
|
|
cancelMeta.get(disguise).add(observer.getUniqueId());
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addDelayedPacket(metaPacket, 4);
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Remove player from the list
|
|
|
|
PacketContainer deleteTab = sendTab.shallowClone();
|
|
|
|
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
2016-11-30 05:08:12 +01:00
|
|
|
|
|
|
|
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
|
|
|
packets.addDelayedPacket(deleteTab, 40);
|
|
|
|
}
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
2016-05-12 13:30:22 +02:00
|
|
|
Vector vec = disguisedEntity.getVelocity();
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
|
|
|
packets.addPacket(spawnEntity);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Object> mods = spawnEntity.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
mods.write(0, disguisedEntity.getEntityId());
|
2017-04-26 15:57:03 +02:00
|
|
|
mods.write(1, disguisedEntity.getUniqueId());
|
2016-05-12 13:30:22 +02:00
|
|
|
mods.write(2, disguise.getType().getTypeId());
|
|
|
|
|
|
|
|
// region Vector calculations
|
|
|
|
double d1 = 3.9D;
|
|
|
|
double d2 = vec.getX();
|
|
|
|
double d3 = vec.getY();
|
|
|
|
double d4 = vec.getZ();
|
|
|
|
if (d2 < -d1)
|
|
|
|
d2 = -d1;
|
|
|
|
if (d3 < -d1)
|
|
|
|
d3 = -d1;
|
|
|
|
if (d4 < -d1)
|
|
|
|
d4 = -d1;
|
|
|
|
if (d2 > d1)
|
|
|
|
d2 = d1;
|
|
|
|
if (d3 > d1)
|
|
|
|
d3 = d1;
|
|
|
|
if (d4 > d1)
|
|
|
|
d4 = d1;
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
mods.write(3, loc.getX());
|
|
|
|
mods.write(4, loc.getY());
|
|
|
|
mods.write(5, loc.getZ());
|
|
|
|
mods.write(6, (int) (d2 * 8000.0D));
|
|
|
|
mods.write(7, (int) (d3 * 8000.0D));
|
|
|
|
mods.write(8, (int) (d4 * 8000.0D));
|
|
|
|
mods.write(9, yaw);
|
|
|
|
mods.write(10, pitch);
|
2017-07-18 10:35:46 +02:00
|
|
|
mods.write(11, yaw);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnEntity.getDataWatcherModifier().write(0,
|
2016-05-12 13:30:22 +02:00
|
|
|
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType().isMisc()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
int objectId = disguise.getType().getObjectId();
|
|
|
|
int data = ((MiscDisguise) disguise).getData();
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
2018-09-23 01:07:54 +02:00
|
|
|
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
|
|
|
|
|
|
|
|
data = ReflectionManager.getCombinedIdByItemStack(block);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {
|
2018-02-14 08:15:56 +01:00
|
|
|
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners
|
|
|
|
// entity id
|
2016-11-26 08:12:57 +01:00
|
|
|
data = observer.getEntityId();
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
2016-05-12 13:30:22 +02:00
|
|
|
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
|
|
|
|
2017-06-27 04:53:10 +02:00
|
|
|
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
|
|
|
|
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
|
|
|
|
.createPacket(nmsEntity, objectId, data);
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(spawnEntity);
|
|
|
|
|
2018-09-23 01:07:54 +02:00
|
|
|
// If it's not the same type, then highly likely they have different velocity settings which we'd want to
|
|
|
|
// cancel
|
|
|
|
if (DisguiseType.getType(disguisedEntity) != disguise.getType()) {
|
|
|
|
StructureModifier<Integer> ints = spawnEntity.getIntegers();
|
|
|
|
|
|
|
|
ints.write(1, 0);
|
|
|
|
ints.write(2, 0);
|
|
|
|
ints.write(3, 0);
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnEntity.getModifier().write(8, pitch);
|
|
|
|
spawnEntity.getModifier().write(9, yaw);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
|
|
|
if (data % 2 == 0) {
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnEntity.getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1));
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
spawnEntity.getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1));
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 10:35:46 +02:00
|
|
|
if (packets.getPackets().size() <= 1 || disguise.isPlayerDisguise()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer rotateHead = new PacketContainer(Server.ENTITY_HEAD_ROTATION);
|
|
|
|
packets.addPacket(rotateHead);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Object> mods = rotateHead.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
mods.write(0, disguisedEntity.getEntityId());
|
|
|
|
mods.write(1, yaw);
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
|
2016-11-26 16:36:57 +01:00
|
|
|
if (disguise.getType() == DisguiseType.EVOKER_FANGS) {
|
|
|
|
PacketContainer newPacket = new PacketContainer(Server.ENTITY_STATUS);
|
|
|
|
|
|
|
|
StructureModifier<Object> mods = newPacket.getModifier();
|
|
|
|
mods.write(0, disguise.getEntity().getEntityId());
|
|
|
|
mods.write(1, (byte) 4);
|
|
|
|
|
|
|
|
packets.addPacket(newPacket);
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
return packets;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new datawatcher but with the 'correct' values
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
2016-05-12 13:30:22 +02:00
|
|
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
try {
|
2017-06-27 04:53:10 +02:00
|
|
|
List<WrappedWatchableObject> list =
|
|
|
|
DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher.getWatchableObjects()) :
|
|
|
|
flagWatcher.getWatchableObjects();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (WrappedWatchableObject watchableObject : list) {
|
2016-05-12 13:30:22 +02:00
|
|
|
if (watchableObject == null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (watchableObject.getValue() == null)
|
|
|
|
continue;
|
|
|
|
|
2018-08-05 10:34:02 +02:00
|
|
|
WrappedDataWatcherObject obj = ReflectionManager
|
|
|
|
.createDataWatcherObject(watchableObject.getIndex(), watchableObject.getValue());
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
newWatcher.setObject(obj, watchableObject.getValue());
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (Exception ex) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return newWatcher;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static byte getPitch(DisguiseType disguiseType, DisguiseType entityType, byte value) {
|
2018-08-23 07:10:16 +02:00
|
|
|
return getPitch(disguiseType, getPitch(entityType, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static byte getPitch(DisguiseType disguiseType, byte value) {
|
2016-11-25 13:07:02 +01:00
|
|
|
switch (disguiseType) {
|
2017-03-21 13:22:00 +01:00
|
|
|
case MINECART:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
2018-08-23 07:10:16 +02:00
|
|
|
case PHANTOM:
|
|
|
|
return (byte) -value;
|
2017-03-21 13:22:00 +01:00
|
|
|
default:
|
2018-08-23 07:10:16 +02:00
|
|
|
return value;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the yaw for the disguises
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) {
|
|
|
|
switch (disguiseType) {
|
2017-03-21 13:22:00 +01:00
|
|
|
case MINECART:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
value += 64;
|
|
|
|
break;
|
|
|
|
case BOAT:
|
|
|
|
case ENDER_DRAGON:
|
|
|
|
case WITHER_SKULL:
|
|
|
|
value -= 128;
|
|
|
|
break;
|
|
|
|
case ARROW:
|
|
|
|
case TIPPED_ARROW:
|
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
value = (byte) -value;
|
|
|
|
break;
|
|
|
|
case PAINTING:
|
|
|
|
case ITEM_FRAME:
|
|
|
|
value = (byte) -(value + 128);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (disguiseType.isMisc() && disguiseType != DisguiseType.ARMOR_STAND) {
|
|
|
|
value -= 64;
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-03-21 13:22:00 +01:00
|
|
|
break;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
switch (entityType) {
|
2017-03-21 13:22:00 +01:00
|
|
|
case MINECART:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
value -= 64;
|
|
|
|
break;
|
|
|
|
case ENDER_DRAGON:
|
|
|
|
case WITHER_SKULL:
|
|
|
|
value += 128;
|
|
|
|
break;
|
|
|
|
case ARROW:
|
|
|
|
value = (byte) -value;
|
|
|
|
break;
|
|
|
|
case PAINTING:
|
|
|
|
case ITEM_FRAME:
|
|
|
|
value = (byte) -(value - 128);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!entityType.isAlive()) {
|
|
|
|
value += 64;
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-03-21 13:22:00 +01:00
|
|
|
break;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Y level to add to the disguise for realism.
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
public static double getYModifier(Entity entity, Disguise disguise) {
|
2016-05-12 13:30:22 +02:00
|
|
|
double yMod = 0;
|
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) &&
|
|
|
|
entity.getType() == EntityType.DROPPED_ITEM) {
|
2016-05-12 13:30:22 +02:00
|
|
|
yMod -= 0.13;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
switch (disguise.getType()) {
|
2017-03-21 13:22:00 +01:00
|
|
|
case BAT:
|
|
|
|
if (entity instanceof LivingEntity)
|
|
|
|
return yMod + ((LivingEntity) entity).getEyeHeight();
|
2016-05-12 13:30:22 +02:00
|
|
|
case MINECART:
|
2017-03-21 13:22:00 +01:00
|
|
|
case MINECART_COMMAND:
|
2016-05-12 13:30:22 +02:00
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
2017-03-21 13:22:00 +01:00
|
|
|
switch (entity.getType()) {
|
|
|
|
case MINECART:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
return yMod;
|
|
|
|
default:
|
|
|
|
return yMod + 0.4;
|
|
|
|
}
|
|
|
|
case TIPPED_ARROW:
|
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
case BOAT:
|
|
|
|
case EGG:
|
|
|
|
case ENDER_PEARL:
|
|
|
|
case ENDER_SIGNAL:
|
|
|
|
case FIREWORK:
|
|
|
|
case PAINTING:
|
|
|
|
case SMALL_FIREBALL:
|
|
|
|
case SNOWBALL:
|
|
|
|
case SPLASH_POTION:
|
|
|
|
case THROWN_EXP_BOTTLE:
|
|
|
|
case WITHER_SKULL:
|
|
|
|
return yMod + 0.7;
|
|
|
|
case PLAYER:
|
|
|
|
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
|
|
|
return yMod + 0.35;
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-03-21 13:22:00 +01:00
|
|
|
break;
|
|
|
|
case DROPPED_ITEM:
|
|
|
|
return yMod + 0.13;
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
return yMod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the packet listeners
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void init(LibsDisguises plugin) {
|
2016-05-12 13:30:22 +02:00
|
|
|
libsDisguises = plugin;
|
|
|
|
soundsListener = new PacketListenerSounds(libsDisguises);
|
|
|
|
|
|
|
|
// Self disguise (/vsd) listener
|
|
|
|
viewDisguisesListener = new PacketListenerViewDisguises(libsDisguises);
|
|
|
|
|
|
|
|
inventoryListener = new PacketListenerInventory(libsDisguises);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static boolean isHearDisguisesEnabled() {
|
2016-05-12 13:30:22 +02:00
|
|
|
return soundsListenerEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static boolean isInventoryListenerEnabled() {
|
2016-05-12 13:30:22 +02:00
|
|
|
return inventoryModifierEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static boolean isViewDisguisesListenerEnabled() {
|
2016-05-12 13:30:22 +02:00
|
|
|
return viewDisguisesListenerEnabled;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void setHearDisguisesListener(boolean enabled) {
|
|
|
|
if (soundsListenerEnabled != enabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
soundsListenerEnabled = enabled;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (soundsListenerEnabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void setInventoryListenerEnabled(boolean enabled) {
|
|
|
|
if (inventoryModifierEnabled != enabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
inventoryModifierEnabled = enabled;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (inventoryModifierEnabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise != null) {
|
2018-02-14 08:15:56 +01:00
|
|
|
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() &&
|
|
|
|
(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
2016-05-12 13:30:22 +02:00
|
|
|
player.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void setupMainPacketsListener() {
|
|
|
|
if (clientInteractEntityListener != null) {
|
|
|
|
if (mainListener != null) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
|
|
|
|
}
|
|
|
|
|
2017-06-27 04:53:10 +02:00
|
|
|
ArrayList<PacketType> packetsToListen = new ArrayList<>();
|
2016-05-12 13:30:22 +02:00
|
|
|
// Add spawn packets
|
|
|
|
{
|
|
|
|
packetsToListen.add(Server.NAMED_ENTITY_SPAWN);
|
|
|
|
packetsToListen.add(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
|
|
|
packetsToListen.add(Server.SPAWN_ENTITY);
|
|
|
|
packetsToListen.add(Server.SPAWN_ENTITY_LIVING);
|
|
|
|
packetsToListen.add(Server.SPAWN_ENTITY_PAINTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add packets that always need to be enabled to ensure safety
|
|
|
|
{
|
|
|
|
packetsToListen.add(Server.ENTITY_METADATA);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isCollectPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.COLLECT);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.UPDATE_ATTRIBUTES);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The bed packet.
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isBedPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.BED);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add movement packets
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isMovementPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.ENTITY_LOOK);
|
|
|
|
packetsToListen.add(Server.REL_ENTITY_MOVE_LOOK);
|
|
|
|
packetsToListen.add(Server.ENTITY_HEAD_ROTATION);
|
|
|
|
packetsToListen.add(Server.ENTITY_TELEPORT);
|
|
|
|
packetsToListen.add(Server.REL_ENTITY_MOVE);
|
2018-01-10 13:36:22 +01:00
|
|
|
packetsToListen.add(Server.ENTITY_VELOCITY);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add equipment packet
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isEquipmentPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.ENTITY_EQUIPMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the packet that ensures if they are sleeping or not
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isAnimationPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.ANIMATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the packet that makes sure that entities with armor do not send unpickupable armor on death
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseConfig.isEntityStatusPacketsEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
packetsToListen.add(Server.ENTITY_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
mainListener = new PacketListenerMain(libsDisguises, packetsToListen);
|
|
|
|
|
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(mainListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public static void setViewDisguisesListener(boolean enabled) {
|
|
|
|
if (viewDisguisesListenerEnabled != enabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
viewDisguisesListenerEnabled = enabled;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (viewDisguisesListenerEnabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-05-12 13:30:22 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise != null) {
|
|
|
|
if (disguise.isSelfDisguiseVisible()) {
|
|
|
|
if (enabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
DisguiseUtilities.setupFakeDisguise(disguise);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-05-12 13:30:22 +02:00
|
|
|
DisguiseUtilities.removeSelfDisguise(player);
|
|
|
|
}
|
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
if (inventoryModifierEnabled &&
|
|
|
|
(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
2016-05-12 13:30:22 +02:00
|
|
|
player.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-14 08:15:56 +01:00
|
|
|
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if
|
|
|
|
* its not
|
2016-05-12 13:30:22 +02:00
|
|
|
* transformed
|
|
|
|
*/
|
2017-03-21 13:22:00 +01:00
|
|
|
public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer,
|
|
|
|
Entity entity) {
|
2016-10-04 15:11:50 +02:00
|
|
|
LibsPackets packets = new LibsPackets(disguise);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
try {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(sentPacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// This packet sends attributes
|
2016-11-25 13:07:02 +01:00
|
|
|
if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES) {
|
|
|
|
if (disguise.isMiscDisguise()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
List<WrappedAttribute> attributes = new ArrayList<>();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
|
|
|
|
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer updateAttributes = new PacketContainer(Server.UPDATE_ATTRIBUTES);
|
|
|
|
packets.addPacket(updateAttributes);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
Builder builder;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
builder = WrappedAttribute.newBuilder();
|
|
|
|
builder.attributeKey("generic.maxHealth");
|
|
|
|
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
builder = WrappedAttribute.newBuilder(attribute);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
builder = WrappedAttribute.newBuilder();
|
|
|
|
builder.attributeKey("generic.maxHealth");
|
|
|
|
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
builder.packet(updateAttributes);
|
|
|
|
|
|
|
|
attributes.add(builder.build());
|
|
|
|
break;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (!attributes.isEmpty()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.getPackets().get(0).getIntegers().write(0, entity.getEntityId());
|
|
|
|
packets.getPackets().get(0).getAttributeCollectionModifier().write(0, attributes);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else if the packet is sending entity metadata
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.ENTITY_METADATA) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) ||
|
|
|
|
!cancelMeta.get(disguise).contains(observer.getUniqueId()))) {
|
2017-06-27 04:53:10 +02:00
|
|
|
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
|
|
|
|
.convert(sentPacket.getWatchableCollectionModifier().read(0));
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
|
|
|
|
|
|
|
|
packets.addPacket(metaPacket);
|
|
|
|
|
|
|
|
StructureModifier<Object> newMods = metaPacket.getModifier();
|
|
|
|
|
|
|
|
newMods.write(0, entity.getEntityId());
|
|
|
|
|
|
|
|
metaPacket.getWatchableCollectionModifier().write(0, watchableObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Else if the packet is spawning..
|
2018-02-14 08:15:56 +01:00
|
|
|
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 ||
|
|
|
|
sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
|
|
|
|
|
|
|
constructSpawnPackets(observer, packets, entity);
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Else if the disguise is attempting to send players a forbidden packet
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.ANIMATION) {
|
2018-02-14 08:15:56 +01:00
|
|
|
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 &&
|
|
|
|
(!disguise.getType().isPlayer() || (DisguiseConfig.isBedPacketsEnabled() &&
|
|
|
|
((PlayerWatcher) disguise.getWatcher()).isSleeping())))) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Else if the disguise is collecting stuff
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.COLLECT) {
|
|
|
|
if (disguise.getType().isMisc()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2018-02-14 08:15:56 +01:00
|
|
|
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() &&
|
|
|
|
((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer newPacket = new PacketContainer(Server.ANIMATION);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Integer> mods = newPacket.getIntegers();
|
|
|
|
mods.write(0, disguise.getEntity().getEntityId());
|
|
|
|
mods.write(1, 3);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(newPacket);
|
|
|
|
packets.addPacket(sentPacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Else if the disguise is moving.
|
2018-02-14 08:15:56 +01:00
|
|
|
else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK ||
|
|
|
|
sentPacket.getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT ||
|
|
|
|
sentPacket.getType() == Server.REL_ENTITY_MOVE) {
|
|
|
|
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE ||
|
|
|
|
sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) {
|
2016-10-04 15:11:50 +02:00
|
|
|
// Rabbit robbing...
|
2018-02-14 08:15:56 +01:00
|
|
|
if (entity.getMetadata("LibsRabbitHop").isEmpty() ||
|
|
|
|
System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 ||
|
|
|
|
System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
|
|
|
|
if (entity.getMetadata("LibsRabbitHop").isEmpty() ||
|
|
|
|
System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() >
|
|
|
|
500) {
|
2016-10-04 15:11:50 +02:00
|
|
|
entity.removeMetadata("LibsRabbitHop", libsDisguises);
|
|
|
|
entity.setMetadata("LibsRabbitHop",
|
|
|
|
new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer statusPacket = new PacketContainer(Server.ENTITY_STATUS);
|
|
|
|
packets.addPacket(statusPacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
statusPacket.getIntegers().write(0, entity.getEntityId());
|
|
|
|
statusPacket.getBytes().write(0, (byte) 1);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Stop wither skulls from looking
|
2016-11-25 13:07:02 +01:00
|
|
|
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2017-03-21 13:22:00 +01:00
|
|
|
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer movePacket = sentPacket.shallowClone();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(movePacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Byte> bytes = movePacket.getBytes();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
byte yawValue = bytes.read(0);
|
|
|
|
byte pitchValue = bytes.read(1);
|
|
|
|
|
|
|
|
bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue));
|
|
|
|
bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
if (sentPacket.getType() == Server.ENTITY_TELEPORT &&
|
|
|
|
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Double> doubles = movePacket.getDoubles();
|
|
|
|
|
|
|
|
Location loc = entity.getLocation();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
double data = (((loc.getYaw() % 360) + 720 + 45) / 90) % 4;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (data % 2 == 0) {
|
|
|
|
if (data % 2 == 0) {
|
2016-10-04 15:11:50 +02:00
|
|
|
doubles.write(3, loc.getZ());
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
doubles.write(1, loc.getZ());
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
double y = getYModifier(entity, disguise);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (y != 0) {
|
2016-10-04 15:11:50 +02:00
|
|
|
doubles.write(2, doubles.read(2) + y);
|
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else if the disguise is updating equipment
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) {
|
2017-06-27 04:53:10 +02:00
|
|
|
EquipmentSlot slot = ReflectionManager
|
|
|
|
.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (itemStack != null) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer equipPacket = sentPacket.shallowClone();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(equipPacket);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
equipPacket.getModifier().write(2,
|
2016-11-30 05:31:12 +01:00
|
|
|
ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) {
|
2016-10-04 15:11:50 +02:00
|
|
|
ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (heldItem != null && heldItem.getType() != Material.AIR) {
|
2016-10-04 15:11:50 +02:00
|
|
|
// Convert the datawatcher
|
|
|
|
List<WrappedWatchableObject> list = new ArrayList<>();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-30 05:31:12 +01:00
|
|
|
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
2017-06-27 04:53:10 +02:00
|
|
|
WrappedWatchableObject watch = ReflectionManager
|
|
|
|
.createWatchable(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2017-07-24 20:58:58 +02:00
|
|
|
if (watch != null)
|
|
|
|
list.add(watch);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
list = disguise.getWatcher().convert(list);
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-11-25 13:07:02 +01:00
|
|
|
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
|
|
|
if (obj.getIndex() == 0) {
|
2016-10-04 15:11:50 +02:00
|
|
|
list.add(obj);
|
|
|
|
break;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// Construct the packets to return
|
|
|
|
PacketContainer packetBlock = new PacketContainer(Server.ENTITY_METADATA);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packetBlock.getModifier().write(0, entity.getEntityId());
|
|
|
|
packetBlock.getWatchableCollectionModifier().write(0, list);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer packetUnblock = packetBlock.deepClone();
|
|
|
|
// Make a packet to send the 'unblock'
|
2016-11-25 13:07:02 +01:00
|
|
|
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
|
2016-10-04 15:11:50 +02:00
|
|
|
watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4)));
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
|
2018-02-14 08:15:56 +01:00
|
|
|
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why?
|
|
|
|
// Scheduler
|
2016-10-04 15:11:50 +02:00
|
|
|
// delay.
|
|
|
|
|
|
|
|
PacketContainer packet1 = packets.getPackets().get(0);
|
|
|
|
|
|
|
|
packets.clear();
|
|
|
|
|
|
|
|
packets.addPacket(packetUnblock);
|
|
|
|
packets.addPacket(packet1);
|
|
|
|
packets.addPacket(packetBlock);
|
2018-02-14 08:15:56 +01:00
|
|
|
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have
|
|
|
|
// to reset
|
2016-10-04 15:11:50 +02:00
|
|
|
// it.
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// If the entity is going into a bed, stop everything but players from doing this
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.BED) {
|
|
|
|
if (!disguise.getType().isPlayer()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// If the entity is updating their Facebook status, stop them from showing death
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.ENTITY_STATUS) {
|
|
|
|
if (packets.getPackets().get(0).getBytes().read(0) == (byte) 3) {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
}
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2018-01-10 13:36:22 +01:00
|
|
|
// If the entity is sending velocity and its a falling block
|
|
|
|
else if (sentPacket.getType() == Server.ENTITY_VELOCITY) {
|
2018-09-23 01:07:54 +02:00
|
|
|
// If the disguise is a misc and the disguised is not the same type
|
|
|
|
if (disguise.getType().isMisc() && DisguiseType.getType(entity) != disguise.getType()) {
|
2018-01-10 13:36:22 +01:00
|
|
|
packets.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// If the entity is rotating his head
|
2016-11-25 13:07:02 +01:00
|
|
|
else if (sentPacket.getType() == Server.ENTITY_HEAD_ROTATION) {
|
|
|
|
if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) {
|
2016-10-04 15:11:50 +02:00
|
|
|
Location loc = entity.getLocation();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()),
|
|
|
|
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
|
|
|
byte yaw = getYaw(disguise.getType(), entity.getType(), sentPacket.getBytes().read(0));
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer rotation = new PacketContainer(Server.ENTITY_HEAD_ROTATION);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
StructureModifier<Object> mods = rotation.getModifier();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
mods.write(0, entity.getEntityId());
|
|
|
|
mods.write(1, yaw);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
PacketContainer look = new PacketContainer(Server.ENTITY_LOOK);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
look.getIntegers().write(0, entity.getEntityId());
|
|
|
|
look.getBytes().write(0, yaw);
|
|
|
|
look.getBytes().write(1, pitch);
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.clear();
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.addPacket(look);
|
|
|
|
packets.addPacket(rotation);
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
2017-03-21 13:22:00 +01:00
|
|
|
} else {
|
2016-10-04 15:11:50 +02:00
|
|
|
packets.setUnhandled();
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (Exception e) {
|
2016-05-12 13:30:22 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-10-04 15:11:50 +02:00
|
|
|
|
|
|
|
return packets;
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|