2013-05-17 23:05:19 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2013-07-30 02:44:00 +02:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.Collection;
|
2013-06-01 08:35:31 +02:00
|
|
|
import java.util.HashMap;
|
2013-07-30 02:44:00 +02:00
|
|
|
import java.util.Iterator;
|
2013-09-25 16:49:24 +02:00
|
|
|
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|
|
|
import me.libraryaddict.disguise.events.DisguiseEvent;
|
|
|
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
2013-09-20 05:59:28 +02:00
|
|
|
import net.minecraft.server.v1_6_R3.AttributeMapServer;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityHuman;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityInsentient;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityLiving;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
|
|
|
import net.minecraft.server.v1_6_R3.ItemStack;
|
|
|
|
import net.minecraft.server.v1_6_R3.MobEffect;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet17EntityLocationAction;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet20NamedEntitySpawn;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet28EntityVelocity;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet35EntityHeadRotation;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet39AttachEntity;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet40EntityMetadata;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet41MobEffect;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet44UpdateAttributes;
|
|
|
|
import net.minecraft.server.v1_6_R3.Packet5EntityEquipment;
|
|
|
|
import net.minecraft.server.v1_6_R3.WorldServer;
|
2013-05-29 00:29:36 +02:00
|
|
|
|
2013-07-24 02:16:54 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2013-09-20 05:59:28 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
2013-05-29 00:29:36 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
2013-05-17 23:05:19 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-05-29 00:29:36 +02:00
|
|
|
|
|
|
|
import com.comphenix.protocol.Packets;
|
|
|
|
import com.comphenix.protocol.ProtocolLibrary;
|
2013-07-22 15:33:58 +02:00
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
2013-05-29 00:29:36 +02:00
|
|
|
import com.comphenix.protocol.reflect.StructureModifier;
|
2013-05-17 23:05:19 +02:00
|
|
|
|
|
|
|
public class DisguiseAPI {
|
|
|
|
|
2013-08-13 10:29:25 +02:00
|
|
|
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
|
2013-08-07 12:51:42 +02:00
|
|
|
private static HashMap<Integer, Disguise> disguises = new HashMap<Integer, Disguise>();
|
2013-08-01 09:56:27 +02:00
|
|
|
private static boolean hearSelfDisguise;
|
2013-09-29 02:32:26 +02:00
|
|
|
private static boolean hidingArmor;
|
|
|
|
private static boolean hidingHeldItem;
|
2013-07-30 02:44:00 +02:00
|
|
|
private static LibsDisguises libsDisguises;
|
2013-09-29 02:32:26 +02:00
|
|
|
|
2013-08-13 10:29:25 +02:00
|
|
|
// A internal storage of fake entity ID's I can use.
|
|
|
|
// Realistically I could probably use a ID like "4" for everyone seeing as no one shares the ID
|
2013-08-01 09:56:27 +02:00
|
|
|
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
|
2013-09-29 02:32:26 +02:00
|
|
|
|
2013-07-21 05:17:21 +02:00
|
|
|
private static boolean sendVelocity;
|
2013-05-29 00:52:54 +02:00
|
|
|
|
2013-08-01 09:56:27 +02:00
|
|
|
public static boolean canHearSelfDisguise() {
|
|
|
|
return hearSelfDisguise;
|
|
|
|
}
|
|
|
|
|
2013-09-29 02:32:26 +02:00
|
|
|
public static void setInventoryListenerEnabled(boolean inventoryListenerEnabled) {
|
|
|
|
if (PacketsManager.isInventoryListenerEnabled() != inventoryListenerEnabled) {
|
|
|
|
PacketsManager.setInventoryListenerEnabled(inventoryListenerEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInventoryListenerEnabled() {
|
|
|
|
return PacketsManager.isInventoryListenerEnabled();
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
|
|
|
*/
|
2013-08-08 23:14:44 +02:00
|
|
|
public static void disguiseNextEntity(Disguise disguise) {
|
|
|
|
if (disguise == null)
|
|
|
|
return;
|
2013-08-13 11:44:54 +02:00
|
|
|
if (disguise.getEntity() != null || disguises.containsValue(disguise)) {
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
2013-08-08 23:14:44 +02:00
|
|
|
try {
|
2013-09-20 05:59:28 +02:00
|
|
|
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
|
2013-08-08 23:14:44 +02:00
|
|
|
field.setAccessible(true);
|
|
|
|
int id = field.getInt(null);
|
|
|
|
disguises.put(id, disguise);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 00:52:54 +02:00
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Disguise this entity with this disguise
|
2013-05-29 00:52:54 +02:00
|
|
|
*/
|
|
|
|
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// If they are trying to disguise a null entity or use a null disguise
|
|
|
|
// Just return.
|
2013-08-08 19:56:13 +02:00
|
|
|
if (entity == null || disguise == null)
|
2013-06-01 08:35:31 +02:00
|
|
|
return;
|
2013-08-13 05:19:50 +02:00
|
|
|
// Fire a disguise event
|
2013-08-11 20:32:51 +02:00
|
|
|
DisguiseEvent event = new DisguiseEvent(entity, disguise);
|
2013-07-31 09:39:16 +02:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2013-08-13 05:19:50 +02:00
|
|
|
// If they cancelled this disguise event. No idea why.
|
|
|
|
// Just return.
|
|
|
|
if (event.isCancelled())
|
2013-07-31 09:39:16 +02:00
|
|
|
return;
|
2013-08-13 11:44:54 +02:00
|
|
|
// The event wasn't cancelled.
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguise entity isn't the same as the one we are disguising
|
2013-07-28 00:58:21 +02:00
|
|
|
if (disguise.getEntity() != entity) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguise entity actually exists
|
2013-08-07 12:51:42 +02:00
|
|
|
if (disguise.getEntity() != null) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// Clone the disguise
|
2013-07-28 00:58:21 +02:00
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Set the disguise's entity
|
2013-08-07 12:51:42 +02:00
|
|
|
disguise.setEntity(entity);
|
2013-08-13 11:44:54 +02:00
|
|
|
} // If there was a old disguise
|
|
|
|
Disguise oldDisguise = getDisguise(entity);
|
2013-08-13 05:19:50 +02:00
|
|
|
// Stick the disguise in the disguises bin
|
2013-08-07 12:51:42 +02:00
|
|
|
disguises.put(entity.getEntityId(), disguise);
|
2013-08-13 05:19:50 +02:00
|
|
|
// Resend the disguised entity's packet
|
2013-08-13 10:29:25 +02:00
|
|
|
refreshTrackers(entity);
|
2013-08-13 05:19:50 +02:00
|
|
|
// If he is a player, then self disguise himself
|
2013-08-13 10:29:25 +02:00
|
|
|
setupPlayerFakeDisguise(disguise);
|
2013-08-13 11:44:54 +02:00
|
|
|
// Discard the disguise
|
|
|
|
if (oldDisguise != null)
|
2013-08-13 11:57:21 +02:00
|
|
|
oldDisguise.removeDisguise();
|
2013-05-29 00:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-13 05:19:50 +02:00
|
|
|
* Get the disguise of a entity
|
2013-05-29 00:52:54 +02:00
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static Disguise getDisguise(Entity disguiser) {
|
2013-08-08 19:56:13 +02:00
|
|
|
if (disguiser == null)
|
|
|
|
return null;
|
2013-08-13 11:44:54 +02:00
|
|
|
if (disguises.containsKey(disguiser.getEntityId()))
|
|
|
|
return disguises.get(disguiser.getEntityId());
|
|
|
|
return null;
|
2013-05-29 00:52:54 +02:00
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
/**
|
|
|
|
* Get the ID of a fake disguise for a entityplayer
|
|
|
|
*/
|
2013-07-30 02:44:00 +02:00
|
|
|
public static int getFakeDisguise(int id) {
|
2013-07-31 07:12:39 +02:00
|
|
|
if (selfDisguisesIds.containsKey(id))
|
|
|
|
return selfDisguisesIds.get(id);
|
2013-07-30 02:44:00 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void init(LibsDisguises mainPlugin) {
|
|
|
|
libsDisguises = mainPlugin;
|
2013-05-29 00:29:36 +02:00
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Is this entity disguised
|
2013-05-17 23:05:19 +02:00
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static boolean isDisguised(Entity disguiser) {
|
2013-08-07 12:51:42 +02:00
|
|
|
return getDisguise(disguiser) != null;
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
|
2013-09-29 02:32:26 +02:00
|
|
|
/**
|
|
|
|
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
|
|
|
|
*/
|
|
|
|
public static boolean isHidingArmorFromSelf() {
|
|
|
|
return hidingArmor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
|
|
|
*/
|
|
|
|
public static boolean isHidingHeldItemFromSelf() {
|
|
|
|
return hidingHeldItem;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Is the sound packets caught and modified
|
|
|
|
*/
|
2013-08-11 21:24:52 +02:00
|
|
|
public static boolean isSoundEnabled() {
|
2013-08-13 05:19:50 +02:00
|
|
|
return PacketsManager.isHearDisguisesEnabled();
|
2013-08-11 21:24:52 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Is the velocity packets sent
|
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static boolean isVelocitySent() {
|
|
|
|
return sendVelocity;
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
/**
|
|
|
|
* The default value if a player views his own disguise
|
|
|
|
*/
|
|
|
|
public static boolean isViewDisguises() {
|
|
|
|
return PacketsManager.isViewDisguisesListenerEnabled();
|
|
|
|
}
|
|
|
|
|
2013-05-30 16:31:18 +02:00
|
|
|
/**
|
|
|
|
* @param Resends
|
|
|
|
* the entity to all the watching players, which is where the magic begins
|
|
|
|
*/
|
2013-08-13 10:29:25 +02:00
|
|
|
private static void refreshTrackers(Entity entity) {
|
2013-05-29 00:29:36 +02:00
|
|
|
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
|
|
|
.get(entity.getEntityId());
|
|
|
|
if (entry != null) {
|
2013-05-29 19:17:48 +02:00
|
|
|
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
2013-05-29 16:25:00 +02:00
|
|
|
for (EntityPlayer player : players) {
|
2013-05-29 01:00:31 +02:00
|
|
|
if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity))
|
|
|
|
continue;
|
2013-05-29 00:29:36 +02:00
|
|
|
entry.clear(player);
|
|
|
|
entry.updatePlayer(player);
|
|
|
|
}
|
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
private static void removeSelfDisguise(Player player) {
|
2013-07-31 07:12:39 +02:00
|
|
|
if (selfDisguisesIds.containsKey(player.getEntityId())) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// Send a packet to destroy the fake entity
|
2013-07-30 02:44:00 +02:00
|
|
|
PacketContainer packet = new PacketContainer(Packets.Server.DESTROY_ENTITY);
|
2013-07-31 07:12:39 +02:00
|
|
|
packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getEntityId()) });
|
2013-07-30 02:44:00 +02:00
|
|
|
try {
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Remove the fake entity ID from the disguise bin
|
2013-07-31 07:12:39 +02:00
|
|
|
selfDisguisesIds.remove(player.getEntityId());
|
2013-08-13 05:19:50 +02:00
|
|
|
// Get the entity tracker
|
2013-08-01 09:56:27 +02:00
|
|
|
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
|
|
|
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities
|
|
|
|
.get(player.getEntityId());
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the tracker exists. Remove himself from his tracker
|
2013-08-01 09:56:27 +02:00
|
|
|
if (tracker != null) {
|
|
|
|
tracker.trackedPlayers.remove(entityplayer);
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Resend entity metadata else he will be invisible to himself until its resent
|
2013-08-01 09:56:27 +02:00
|
|
|
PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
|
|
|
StructureModifier<Object> mods = packetMetadata.getModifier();
|
|
|
|
mods.write(0, player.getEntityId());
|
|
|
|
mods.write(1, entityplayer.getDataWatcher().c());
|
|
|
|
try {
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
2013-08-01 09:56:27 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Can players hear their own disguises
|
|
|
|
*/
|
2013-08-01 09:56:27 +02:00
|
|
|
public static void setHearSelfDisguise(boolean replaceSound) {
|
|
|
|
if (hearSelfDisguise != replaceSound) {
|
|
|
|
hearSelfDisguise = replaceSound;
|
2013-07-31 07:12:39 +02:00
|
|
|
}
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-09-29 02:32:26 +02:00
|
|
|
/**
|
|
|
|
* Set the plugin to hide self disguises armor from theirselves
|
|
|
|
*/
|
|
|
|
public static void setHideArmorFromSelf(boolean hideArmor) {
|
|
|
|
if (hidingArmor != hideArmor) {
|
|
|
|
hidingArmor = hideArmor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
|
|
|
*/
|
|
|
|
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
|
|
|
|
if (hidingHeldItem != hideHelditem) {
|
|
|
|
hidingHeldItem = hideHelditem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Set if the disguises play sounds when hurt
|
|
|
|
*/
|
2013-08-13 05:19:50 +02:00
|
|
|
public static void setSoundsEnabled(boolean isSoundsEnabled) {
|
|
|
|
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup it so he can see himself when disguised
|
|
|
|
*/
|
2013-08-13 10:29:25 +02:00
|
|
|
private static void setupPlayerFakeDisguise(final Disguise disguise) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguises entity is null, or the disguised entity isn't a player return
|
2013-08-11 21:24:52 +02:00
|
|
|
if (disguise.getEntity() == null || !(disguise.getEntity() instanceof Player))
|
|
|
|
return;
|
|
|
|
Player player = (Player) disguise.getEntity();
|
2013-08-13 05:19:50 +02:00
|
|
|
// Remove the old disguise, else we have weird disguises around the place
|
2013-08-13 11:44:54 +02:00
|
|
|
removeSelfDisguise(player);
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguised player can't see himself. Return
|
2013-08-11 21:24:52 +02:00
|
|
|
if (!disguise.viewSelfDisguise())
|
2013-07-30 02:44:00 +02:00
|
|
|
return;
|
2013-08-13 05:19:50 +02:00
|
|
|
// Grab the entity player
|
2013-08-05 14:22:04 +02:00
|
|
|
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
|
|
|
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities.get(player
|
|
|
|
.getEntityId());
|
|
|
|
if (tracker == null) {
|
|
|
|
// A check incase the tracker is null.
|
|
|
|
// If it is, then this method will be run again in one tick. Which is when it should be constructed.
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
2013-08-13 10:29:25 +02:00
|
|
|
setupPlayerFakeDisguise(disguise);
|
2013-08-05 14:22:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Add himself to his own entity tracker
|
2013-08-05 14:22:04 +02:00
|
|
|
tracker.trackedPlayers.add(entityplayer);
|
2013-07-30 02:44:00 +02:00
|
|
|
try {
|
2013-08-13 05:19:50 +02:00
|
|
|
// Grab the entity ID the fake disguise will use
|
2013-09-20 05:59:28 +02:00
|
|
|
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
|
2013-07-30 02:44:00 +02:00
|
|
|
field.setAccessible(true);
|
2013-08-13 05:19:50 +02:00
|
|
|
int id = field.getInt(null);
|
|
|
|
// Set the entitycount plus one so we don't have the id being reused
|
2013-07-30 02:44:00 +02:00
|
|
|
field.set(null, id + 1);
|
2013-07-31 07:12:39 +02:00
|
|
|
selfDisguisesIds.put(player.getEntityId(), id);
|
2013-07-30 02:44:00 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Send the player a packet with himself being spawned
|
2013-07-30 02:44:00 +02:00
|
|
|
Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn((EntityHuman) entityplayer);
|
|
|
|
entityplayer.playerConnection.sendPacket(packet);
|
|
|
|
if (!tracker.tracker.getDataWatcher().d()) {
|
2013-07-31 07:12:39 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet40EntityMetadata(player.getEntityId(), tracker.tracker
|
|
|
|
.getDataWatcher(), true));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Send himself some entity attributes
|
2013-07-30 02:44:00 +02:00
|
|
|
if (tracker.tracker instanceof EntityLiving) {
|
2013-09-20 05:59:28 +02:00
|
|
|
AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) tracker.tracker).aX();
|
2013-07-30 02:44:00 +02:00
|
|
|
Collection collection = attributemapserver.c();
|
|
|
|
|
|
|
|
if (!collection.isEmpty()) {
|
|
|
|
entityplayer.playerConnection.sendPacket(new Packet44UpdateAttributes(player.getEntityId(), collection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
// Why do we even have this?
|
2013-07-30 02:44:00 +02:00
|
|
|
tracker.j = tracker.tracker.motX;
|
|
|
|
tracker.k = tracker.tracker.motY;
|
|
|
|
tracker.l = tracker.tracker.motZ;
|
|
|
|
boolean isMoving = false;
|
|
|
|
try {
|
|
|
|
Field field = EntityTrackerEntry.class.getDeclaredField("isMoving");
|
|
|
|
field.setAccessible(true);
|
|
|
|
isMoving = field.getBoolean(tracker);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Send the velocity packets
|
2013-07-30 02:44:00 +02:00
|
|
|
if (isMoving) {
|
2013-07-31 07:12:39 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet28EntityVelocity(player.getEntityId(), tracker.tracker.motX,
|
|
|
|
tracker.tracker.motY, tracker.tracker.motZ));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
// Why the hell would he even need this. Meh.
|
2013-07-30 05:31:07 +02:00
|
|
|
if (tracker.tracker.vehicle != null && player.getEntityId() > tracker.tracker.vehicle.id) {
|
2013-07-30 02:44:00 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker, tracker.tracker.vehicle));
|
2013-07-30 05:31:07 +02:00
|
|
|
} else if (tracker.tracker.passenger != null && player.getEntityId() > tracker.tracker.passenger.id) {
|
2013-07-30 02:44:00 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker.passenger, tracker.tracker));
|
|
|
|
}
|
|
|
|
|
2013-09-20 05:59:28 +02:00
|
|
|
if (tracker.tracker instanceof EntityInsentient && ((EntityInsentient) tracker.tracker).getLeashHolder() != null) {
|
2013-07-30 02:44:00 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(1, tracker.tracker,
|
2013-09-20 05:59:28 +02:00
|
|
|
((EntityInsentient) tracker.tracker).getLeashHolder()));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
// Resend the armor
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
2013-07-30 02:44:00 +02:00
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
if (itemstack != null) {
|
|
|
|
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguised is sleeping for w/e reason
|
|
|
|
if (entityplayer.isSleeping()) {
|
|
|
|
entityplayer.playerConnection
|
|
|
|
.sendPacket(new Packet17EntityLocationAction(entityplayer, 0, (int) Math.floor(tracker.tracker.locX),
|
|
|
|
(int) Math.floor(tracker.tracker.locY), (int) Math.floor(tracker.tracker.locZ)));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start - Fix for nonsensical head yaw
|
|
|
|
tracker.i = (int) Math.floor(tracker.tracker.getHeadRotation() * 256.0F / 360.0F); // tracker.ao() should be
|
|
|
|
// getHeadRotation
|
2013-07-30 05:31:07 +02:00
|
|
|
tracker.broadcast(new Packet35EntityHeadRotation(player.getEntityId(), (byte) tracker.i));
|
2013-07-30 02:44:00 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
// Resend any active potion effects
|
|
|
|
Iterator iterator = entityplayer.getEffects().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
MobEffect mobeffect = (MobEffect) iterator.next();
|
2013-07-30 02:44:00 +02:00
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
entityplayer.playerConnection.sendPacket(new Packet41MobEffect(player.getEntityId(), mobeffect));
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
/**
|
|
|
|
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
|
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static void setVelocitySent(boolean sendVelocityPackets) {
|
|
|
|
sendVelocity = sendVelocityPackets;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:44:00 +02:00
|
|
|
public static void setViewDisguises(boolean seeOwnDisguise) {
|
2013-08-13 05:19:50 +02:00
|
|
|
PacketsManager.setViewDisguisesListener(seeOwnDisguise);
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
|
|
|
|
* the world.
|
2013-05-17 23:05:19 +02:00
|
|
|
*/
|
2013-05-29 00:29:36 +02:00
|
|
|
public static void undisguiseToAll(Entity entity) {
|
2013-07-21 05:17:21 +02:00
|
|
|
Disguise disguise = getDisguise(entity);
|
|
|
|
if (disguise == null)
|
|
|
|
return;
|
2013-08-11 21:25:48 +02:00
|
|
|
UndisguiseEvent event = new UndisguiseEvent(entity, disguise);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2013-08-13 11:44:54 +02:00
|
|
|
if (event.isCancelled())
|
2013-08-11 21:25:48 +02:00
|
|
|
return;
|
2013-08-13 11:57:21 +02:00
|
|
|
disguise.removeDisguise();
|
2013-08-13 11:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public HashMap<Integer, Disguise> getDisguises() {
|
|
|
|
return disguises;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void refreshWatchingPlayers(Entity entity) {
|
|
|
|
refreshTrackers(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeVisibleDisguise(Player player) {
|
|
|
|
removeSelfDisguise(player);
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
2013-08-14 22:57:30 +02:00
|
|
|
|
|
|
|
public void setupFakeDisguise(Disguise disguise) {
|
|
|
|
setupPlayerFakeDisguise(disguise);
|
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|