2013-11-22 21:10:20 +01:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
2013-11-22 20:52:15 +01:00
|
|
|
|
2014-09-14 16:22:29 +02:00
|
|
|
import java.lang.reflect.Array;
|
2013-11-22 20:52:15 +01:00
|
|
|
import java.lang.reflect.Field;
|
2014-01-31 10:56:05 +01:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2013-11-22 20:52:15 +01:00
|
|
|
import java.lang.reflect.Method;
|
2013-12-05 09:05:58 +01:00
|
|
|
import java.util.ArrayList;
|
2014-09-14 16:22:29 +02:00
|
|
|
import java.util.Arrays;
|
2013-11-22 20:52:15 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
2013-11-22 21:04:31 +01:00
|
|
|
import java.util.Iterator;
|
2014-06-02 00:03:59 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2014-09-03 03:30:11 +02:00
|
|
|
import java.util.List;
|
2014-04-02 14:49:48 +02:00
|
|
|
import java.util.UUID;
|
2014-08-26 04:39:24 +02:00
|
|
|
import java.util.regex.Pattern;
|
2013-11-22 20:52:15 +01:00
|
|
|
|
2013-12-01 16:37:07 +01:00
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
2014-06-02 00:03:59 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
2013-11-22 21:04:31 +01:00
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
2013-11-22 20:52:15 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
2013-12-22 01:03:47 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
2014-09-03 03:30:11 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
2014-04-16 06:26:19 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
2013-12-01 16:37:07 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
2013-12-22 01:03:47 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
2014-09-03 03:30:11 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher;
|
2014-09-16 18:01:48 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
|
2014-09-14 16:22:29 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
2013-12-22 01:03:47 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
2013-12-01 16:37:07 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
2014-07-26 01:10:48 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
|
2014-06-02 00:03:59 +02:00
|
|
|
|
2013-11-22 21:04:31 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2014-06-04 04:12:09 +02:00
|
|
|
import org.bukkit.World;
|
2014-09-14 16:22:29 +02:00
|
|
|
import org.bukkit.block.BlockFace;
|
2013-12-22 01:03:47 +01:00
|
|
|
import org.bukkit.entity.Ageable;
|
2013-11-22 20:52:15 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-12-22 01:03:47 +01:00
|
|
|
import org.bukkit.entity.Zombie;
|
2013-11-22 21:04:31 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2014-06-04 04:12:09 +02:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2013-11-22 21:04:31 +01:00
|
|
|
import org.bukkit.util.Vector;
|
2013-11-22 20:52:15 +01:00
|
|
|
|
2013-12-07 15:30:30 +01:00
|
|
|
import com.comphenix.protocol.PacketType;
|
2013-11-22 20:52:15 +01:00
|
|
|
import com.comphenix.protocol.ProtocolLibrary;
|
2013-11-22 21:04:31 +01:00
|
|
|
import com.comphenix.protocol.ProtocolManager;
|
2013-11-22 20:52:15 +01:00
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
2014-09-14 16:22:29 +02:00
|
|
|
import com.comphenix.protocol.reflect.StructureModifier;
|
2013-11-22 20:52:15 +01:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
2014-06-04 22:40:15 +02:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
2014-09-03 03:30:11 +02:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
2013-11-22 20:52:15 +01:00
|
|
|
|
|
|
|
public class DisguiseUtilities {
|
2014-05-13 12:26:10 +02:00
|
|
|
/**
|
|
|
|
* This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of
|
|
|
|
* the plugin to do that.
|
|
|
|
*/
|
2014-04-23 01:44:12 +02:00
|
|
|
private static HashSet<String> addedByPlugins = new HashSet<String>();
|
2014-09-14 16:22:29 +02:00
|
|
|
private static Object bedChunk;
|
2014-06-02 00:03:59 +02:00
|
|
|
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<String, Disguise>();
|
2014-05-22 22:14:46 +02:00
|
|
|
/**
|
|
|
|
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
|
|
|
|
**/
|
|
|
|
private static HashMap<UUID, HashSet<TargetedDisguise>> disguisesInUse = new HashMap<UUID, HashSet<TargetedDisguise>>();
|
2014-05-13 12:26:10 +02:00
|
|
|
/**
|
|
|
|
* Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only stay in for
|
|
|
|
* a max of a second.
|
|
|
|
*/
|
2014-04-02 15:39:52 +02:00
|
|
|
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
|
2014-05-13 12:26:10 +02:00
|
|
|
/**
|
|
|
|
* A hashmap storing the uuid and skin of a playername
|
|
|
|
*/
|
2014-06-04 22:40:15 +02:00
|
|
|
private static HashMap<String, WrappedGameProfile> gameProfiles = new HashMap<String, WrappedGameProfile>();
|
2013-11-22 21:04:31 +01:00
|
|
|
private static LibsDisguises libsDisguises;
|
2014-05-31 20:47:05 +02:00
|
|
|
private static HashMap<String, ArrayList<Object>> runnables = new HashMap<String, ArrayList<Object>>();
|
2014-06-15 10:12:07 +02:00
|
|
|
private static HashSet<UUID> selfDisguised = new HashSet<UUID>();
|
2014-09-14 16:22:29 +02:00
|
|
|
private static Field xChunk, zChunk;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
2014-12-07 16:59:38 +01:00
|
|
|
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
|
|
|
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
|
2014-09-14 16:22:29 +02:00
|
|
|
bedChunk = ReflectionManager.getNmsClass("Chunk")
|
2014-12-07 16:59:38 +01:00
|
|
|
.getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class).newInstance(world, 0, 0);
|
2014-09-14 16:22:29 +02:00
|
|
|
Field cSection = bedChunk.getClass().getDeclaredField("sections");
|
|
|
|
cSection.setAccessible(true);
|
|
|
|
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class)
|
2014-12-07 16:59:38 +01:00
|
|
|
.newInstance(0, true);
|
2014-09-23 16:52:38 +02:00
|
|
|
Object block;
|
|
|
|
try {
|
|
|
|
block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class)
|
2014-09-29 05:29:13 +02:00
|
|
|
.invoke(null, Material.BED_BLOCK.getId());
|
2014-09-23 16:52:38 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK
|
|
|
|
.getId()];
|
|
|
|
}
|
2014-12-07 16:59:38 +01:00
|
|
|
|
|
|
|
if (LibVersion.is1_8()) {
|
|
|
|
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
|
|
|
|
Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class,
|
|
|
|
ReflectionManager.getNmsClass("IBlockData"));
|
|
|
|
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
|
|
|
|
Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class);
|
|
|
|
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
|
|
|
|
setType.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), fromLegacyData.invoke(block, face.ordinal()));
|
|
|
|
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
|
|
|
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Method setId = chunkSection.getClass().getMethod("setTypeId", int.class, int.class, int.class,
|
|
|
|
ReflectionManager.getNmsClass("Block"));
|
|
|
|
Method setData = chunkSection.getClass().getMethod("setData", int.class, int.class, int.class, int.class);
|
|
|
|
Method setSky = chunkSection.getClass().getMethod("setSkyLight", int.class, int.class, int.class, int.class);
|
|
|
|
Method setEmitted = chunkSection.getClass().getMethod("setEmittedLight", int.class, int.class, int.class, int.class);
|
|
|
|
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
|
|
|
|
setId.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), block);
|
|
|
|
setData.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), face.ordinal());
|
|
|
|
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
|
|
|
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
|
|
|
|
}
|
2014-09-14 16:22:29 +02:00
|
|
|
}
|
2014-12-07 16:59:38 +01:00
|
|
|
|
2014-09-14 16:22:29 +02:00
|
|
|
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
|
|
|
|
array[0] = chunkSection;
|
|
|
|
cSection.set(bedChunk, array);
|
|
|
|
xChunk = bedChunk.getClass().getField("locX");
|
|
|
|
xChunk.setAccessible(true);
|
|
|
|
zChunk = bedChunk.getClass().getField("locZ");
|
|
|
|
zChunk.setAccessible(true);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2013-12-01 17:10:38 +01:00
|
|
|
|
2014-06-02 00:03:59 +02:00
|
|
|
public static boolean addClonedDisguise(String key, Disguise disguise) {
|
|
|
|
if (DisguiseConfig.getMaxClonedDisguises() > 0) {
|
|
|
|
if (clonedDisguises.containsKey(key)) {
|
|
|
|
clonedDisguises.remove(key);
|
|
|
|
} else if (DisguiseConfig.getMaxClonedDisguises() == clonedDisguises.size()) {
|
|
|
|
clonedDisguises.remove(clonedDisguises.keySet().iterator().next());
|
|
|
|
}
|
|
|
|
if (DisguiseConfig.getMaxClonedDisguises() > clonedDisguises.size()) {
|
|
|
|
clonedDisguises.put(key, disguise);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:54:36 +02:00
|
|
|
public static void addDisguise(UUID entityId, TargetedDisguise disguise) {
|
2013-12-01 17:10:38 +01:00
|
|
|
if (!getDisguises().containsKey(entityId)) {
|
|
|
|
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
|
|
|
|
}
|
|
|
|
getDisguises().get(entityId).add(disguise);
|
|
|
|
checkConflicts(disguise, null);
|
2013-12-22 01:03:47 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) {
|
|
|
|
doBoundingBox(disguise);
|
|
|
|
}
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
|
2014-06-04 04:12:09 +02:00
|
|
|
public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) {
|
2014-04-02 15:39:52 +02:00
|
|
|
if (!futureDisguises.containsKey(entityId)) {
|
|
|
|
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
|
|
|
|
}
|
|
|
|
futureDisguises.get(entityId).add(disguise);
|
2014-06-04 04:12:09 +02:00
|
|
|
final BukkitRunnable runnable = new BukkitRunnable() {
|
|
|
|
public void run() {
|
|
|
|
if (futureDisguises.containsKey(entityId) && futureDisguises.get(entityId).contains(disguise)) {
|
|
|
|
for (World world : Bukkit.getWorlds()) {
|
|
|
|
for (Entity entity : world.getEntities()) {
|
|
|
|
if (entity.getEntityId() == entityId) {
|
|
|
|
UUID uniqueId = entity.getUniqueId();
|
|
|
|
for (TargetedDisguise disguise : futureDisguises.remove(entityId)) {
|
|
|
|
addDisguise(uniqueId, disguise);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
futureDisguises.get(entityId).remove(disguise);
|
|
|
|
if (futureDisguises.get(entityId).isEmpty()) {
|
|
|
|
futureDisguises.remove(entityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
runnable.runTaskLater(libsDisguises, 20);
|
2014-04-02 15:39:52 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 22:40:15 +02:00
|
|
|
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
|
2014-05-31 20:47:05 +02:00
|
|
|
getGameProfiles().put(string, gameProfile);
|
2014-06-20 16:12:32 +02:00
|
|
|
getAddedByPlugins().add(string.toLowerCase());
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
|
|
|
|
2013-12-01 17:10:38 +01:00
|
|
|
/**
|
|
|
|
* If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the
|
|
|
|
* observers in the disguise don't see any other disguise.
|
|
|
|
*/
|
|
|
|
public static void checkConflicts(TargetedDisguise disguise, String name) {
|
2013-12-03 19:38:10 +01:00
|
|
|
// If the disguise is being used.. Else we may accidentally undisguise something else
|
2013-12-01 17:10:38 +01:00
|
|
|
if (DisguiseAPI.isDisguiseInUse(disguise)) {
|
2014-04-02 14:54:36 +02:00
|
|
|
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getUniqueId()).iterator();
|
2013-12-03 19:38:10 +01:00
|
|
|
// Iterate through the disguises
|
2013-12-01 17:10:38 +01:00
|
|
|
while (disguiseItel.hasNext()) {
|
|
|
|
TargetedDisguise d = disguiseItel.next();
|
2013-12-03 19:38:10 +01:00
|
|
|
// Make sure the disguise isn't the same thing
|
2013-12-01 17:10:38 +01:00
|
|
|
if (d != disguise) {
|
2013-12-03 19:38:10 +01:00
|
|
|
// If the loop'd disguise is hiding the disguise to everyone in its list
|
|
|
|
if (d.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// If player is a observer in the loop
|
2013-12-03 19:38:10 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// If player is a observer in the disguise
|
|
|
|
// Remove them from the loop
|
|
|
|
if (name != null) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.removePlayer(name);
|
2013-12-01 17:10:38 +01:00
|
|
|
} else {
|
|
|
|
for (String playername : disguise.getObservers()) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.silentlyRemovePlayer(playername);
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-03 19:38:10 +01:00
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// If player is not a observer in the loop
|
|
|
|
if (name != null) {
|
|
|
|
if (!disguise.getObservers().contains(name)) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.removePlayer(name);
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-01-15 10:40:33 +01:00
|
|
|
for (String playername : new ArrayList<String>(d.getObservers())) {
|
2013-12-01 17:10:38 +01:00
|
|
|
if (!disguise.getObservers().contains(playername)) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.silentlyRemovePlayer(playername);
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-03 19:38:10 +01:00
|
|
|
} else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// Here you add it to the loop if they see the disguise
|
2013-12-03 19:38:10 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// Everyone who is in the disguise needs to be added to the loop
|
|
|
|
if (name != null) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.addPlayer(name);
|
2013-12-01 17:10:38 +01:00
|
|
|
} else {
|
|
|
|
for (String playername : disguise.getObservers()) {
|
2013-12-03 19:38:10 +01:00
|
|
|
d.silentlyAddPlayer(playername);
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-03 19:38:10 +01:00
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2013-12-01 17:10:38 +01:00
|
|
|
// This here is a paradox.
|
|
|
|
// If fed a name. I can do this.
|
|
|
|
// But the rest of the time.. Its going to conflict.
|
2013-12-03 19:38:10 +01:00
|
|
|
// The below is debug output. Most people wouldn't care for it.
|
2013-12-05 09:05:58 +01:00
|
|
|
|
|
|
|
// System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
|
|
|
|
// + " on a entity. Removed the old disguise.");
|
|
|
|
|
2013-12-01 17:10:38 +01:00
|
|
|
disguiseItel.remove();
|
2014-05-29 12:16:04 +02:00
|
|
|
d.removeDisguise();
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 07:54:40 +02:00
|
|
|
/**
|
2014-06-04 03:18:43 +02:00
|
|
|
* Sends entity removal packets, as this disguise was removed
|
2014-04-04 07:54:40 +02:00
|
|
|
*/
|
|
|
|
public static void destroyEntity(TargetedDisguise disguise) {
|
|
|
|
try {
|
2014-06-15 01:06:02 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
2014-04-04 07:54:40 +02:00
|
|
|
if (entityTrackerEntry != null) {
|
2014-06-15 09:35:47 +02:00
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
|
|
|
entityTrackerEntry);
|
2014-04-04 07:54:40 +02:00
|
|
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
|
|
|
PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
|
|
|
destroyPacket.getIntegerArrays().write(0, new int[] { disguise.getEntity().getEntityId() });
|
|
|
|
for (Object p : cloned) {
|
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
2014-09-27 02:18:54 +02:00
|
|
|
if (player == disguise.getEntity() || disguise.canSee(player)) {
|
2014-04-04 07:54:40 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-22 01:03:47 +01:00
|
|
|
public static void doBoundingBox(TargetedDisguise disguise) {
|
|
|
|
// TODO Slimes
|
|
|
|
Entity entity = disguise.getEntity();
|
|
|
|
if (entity != null) {
|
2013-12-22 02:30:15 +01:00
|
|
|
if (isDisguiseInUse(disguise)) {
|
2013-12-31 08:08:14 +01:00
|
|
|
DisguiseValues disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType());
|
|
|
|
FakeBoundingBox disguiseBox = disguiseValues.getAdultBox();
|
|
|
|
if (disguiseValues.getBabyBox() != null) {
|
|
|
|
if ((disguise.getWatcher() instanceof AgeableWatcher && ((AgeableWatcher) disguise.getWatcher()).isBaby())
|
|
|
|
|| (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise.getWatcher())
|
|
|
|
.isBaby())) {
|
|
|
|
disguiseBox = disguiseValues.getBabyBox();
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 03:21:10 +02:00
|
|
|
ReflectionManager.setBoundingBox(entity, disguiseBox);
|
2013-12-22 02:30:15 +01:00
|
|
|
} else {
|
2013-12-31 08:08:14 +01:00
|
|
|
DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType()));
|
|
|
|
FakeBoundingBox entityBox = entityValues.getAdultBox();
|
|
|
|
if (entityValues.getBabyBox() != null) {
|
|
|
|
if ((entity instanceof Ageable && !((Ageable) entity).isAdult())
|
|
|
|
|| (entity instanceof Zombie && ((Zombie) entity).isBaby())) {
|
|
|
|
entityBox = entityValues.getBabyBox();
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 03:21:10 +02:00
|
|
|
ReflectionManager.setBoundingBox(entity, entityBox);
|
2013-12-22 01:03:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 01:44:12 +02:00
|
|
|
public static HashSet<String> getAddedByPlugins() {
|
|
|
|
return addedByPlugins;
|
|
|
|
}
|
|
|
|
|
2014-09-14 16:22:29 +02:00
|
|
|
public static PacketContainer[] getBedChunkPacket(Player player, Location newLoc, Location oldLoc) {
|
|
|
|
int i = 0;
|
|
|
|
PacketContainer[] packets = new PacketContainer[newLoc != null ? 2 + (oldLoc != null ? 1 : 0) : 1];
|
|
|
|
for (Location loc : new Location[] { oldLoc, newLoc }) {
|
|
|
|
if (loc == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
2014-09-29 05:29:13 +02:00
|
|
|
int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17;
|
|
|
|
chunkX -= chunkX % 8;
|
|
|
|
chunkZ -= chunkZ % 8;
|
2014-09-14 16:22:29 +02:00
|
|
|
xChunk.set(bedChunk, chunkX);
|
|
|
|
zChunk.set(bedChunk, chunkZ);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2014-09-29 03:09:13 +02:00
|
|
|
// Make unload packets
|
2014-09-14 16:22:29 +02:00
|
|
|
try {
|
2014-09-29 05:29:13 +02:00
|
|
|
packets[i] = ProtocolLibrary.getProtocolManager()
|
2014-09-14 16:22:29 +02:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0, 40)
|
2014-12-07 16:59:38 +01:00
|
|
|
.createPacket(bedChunk, true, 0, LibVersion.is1_8() ? 48 : 0);
|
2014-09-14 16:22:29 +02:00
|
|
|
} catch (IllegalArgumentException ex) {
|
2014-09-29 05:29:13 +02:00
|
|
|
packets[i] = ProtocolLibrary.getProtocolManager()
|
2014-09-14 16:22:29 +02:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0)
|
|
|
|
.createPacket(bedChunk, true, 0);
|
|
|
|
}
|
2014-09-29 05:29:13 +02:00
|
|
|
i++;
|
2014-09-29 03:09:13 +02:00
|
|
|
// Make load packets
|
2014-09-14 16:22:29 +02:00
|
|
|
if (oldLoc == null || i > 1) {
|
|
|
|
try {
|
2014-09-29 05:29:13 +02:00
|
|
|
packets[i] = ProtocolLibrary.getProtocolManager()
|
2014-09-14 16:22:29 +02:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk), 40)
|
2014-12-07 16:59:38 +01:00
|
|
|
.createPacket(Arrays.asList(bedChunk), LibVersion.is1_8() ? 48 : 0);
|
2014-09-14 16:22:29 +02:00
|
|
|
} catch (IllegalArgumentException ex) {
|
2014-09-29 05:29:13 +02:00
|
|
|
packets[i] = ProtocolLibrary.getProtocolManager()
|
2014-12-07 16:59:38 +01:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, List.class)
|
2014-09-14 16:22:29 +02:00
|
|
|
.createPacket(Arrays.asList(bedChunk));
|
|
|
|
}
|
2014-09-29 05:29:13 +02:00
|
|
|
i++;
|
2014-09-14 16:22:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PacketContainer[] getBedPackets(Player player, Location loc, Location playerLocation, PlayerDisguise disguise) {
|
|
|
|
Entity entity = disguise.getEntity();
|
|
|
|
PacketContainer setBed = new PacketContainer(PacketType.Play.Server.BED);
|
|
|
|
StructureModifier<Integer> bedInts = setBed.getIntegers();
|
|
|
|
bedInts.write(0, entity.getEntityId());
|
2014-12-07 16:59:38 +01:00
|
|
|
if (LibVersion.is1_8()) {
|
2014-09-14 16:22:29 +02:00
|
|
|
PlayerWatcher watcher = disguise.getWatcher();
|
2014-09-29 05:29:13 +02:00
|
|
|
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math
|
|
|
|
.floor(playerLocation.getZ() / 16D) - 17;
|
|
|
|
chunkX -= chunkX % 8;
|
|
|
|
chunkZ -= chunkZ % 8;
|
2014-09-14 16:22:29 +02:00
|
|
|
bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX());
|
|
|
|
bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ());
|
|
|
|
} else {
|
|
|
|
bedInts.write(1, loc.getBlockX());
|
|
|
|
bedInts.write(2, loc.getBlockY());
|
|
|
|
bedInts.write(3, loc.getBlockZ());
|
|
|
|
}
|
|
|
|
PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
|
|
|
StructureModifier<Integer> ints = teleport.getIntegers();
|
|
|
|
ints.write(0, entity.getEntityId());
|
|
|
|
ints.write(1, (int) Math.floor(loc.getX() * 32));
|
|
|
|
ints.write(2, (int) Math.floor((PacketsManager.getYModifier(disguise.getEntity(), disguise) + loc.getY()) * 32));
|
|
|
|
ints.write(3, (int) Math.floor(loc.getZ() * 32));
|
|
|
|
return new PacketContainer[] { setBed, teleport };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-02 00:03:59 +02:00
|
|
|
public static Disguise getClonedDisguise(String key) {
|
|
|
|
if (clonedDisguises.containsKey(key)) {
|
2014-06-02 00:06:30 +02:00
|
|
|
return clonedDisguises.get(key).clone();
|
2014-06-02 00:03:59 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-06-04 22:40:15 +02:00
|
|
|
|
2014-09-14 16:22:29 +02:00
|
|
|
public static PacketContainer getDestroyPacket(int... ids) {
|
|
|
|
PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
|
|
|
destroyPacket.getIntegerArrays().write(0, ids);
|
|
|
|
return destroyPacket;
|
|
|
|
}
|
|
|
|
|
2014-04-02 15:02:58 +02:00
|
|
|
public static TargetedDisguise getDisguise(Player observer, Entity entity) {
|
|
|
|
UUID entityId = entity.getUniqueId();
|
|
|
|
if (futureDisguises.containsKey(entity.getEntityId())) {
|
|
|
|
for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) {
|
|
|
|
addDisguise(entityId, disguise);
|
|
|
|
}
|
|
|
|
}
|
2013-12-01 17:10:38 +01:00
|
|
|
if (getDisguises().containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
|
|
|
if (disguise.canSee(observer)) {
|
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2013-11-22 20:52:15 +01:00
|
|
|
|
2014-04-02 14:54:36 +02:00
|
|
|
public static HashMap<UUID, HashSet<TargetedDisguise>> getDisguises() {
|
2014-05-13 12:26:10 +02:00
|
|
|
return disguisesInUse;
|
2013-11-22 20:52:15 +01:00
|
|
|
}
|
|
|
|
|
2014-04-02 14:54:36 +02:00
|
|
|
public static TargetedDisguise[] getDisguises(UUID entityId) {
|
2013-12-01 17:10:38 +01:00
|
|
|
if (getDisguises().containsKey(entityId)) {
|
2014-05-23 19:24:55 +02:00
|
|
|
HashSet<TargetedDisguise> disguises = getDisguises().get(entityId);
|
|
|
|
return disguises.toArray(new TargetedDisguise[disguises.size()]);
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
return new TargetedDisguise[0];
|
|
|
|
}
|
|
|
|
|
2014-06-04 04:20:02 +02:00
|
|
|
public static HashMap<Integer, HashSet<TargetedDisguise>> getFutureDisguises() {
|
|
|
|
return futureDisguises;
|
|
|
|
}
|
|
|
|
|
2014-06-04 22:40:15 +02:00
|
|
|
public static WrappedGameProfile getGameProfile(String playerName) {
|
2014-06-20 16:12:32 +02:00
|
|
|
return gameProfiles.get(playerName.toLowerCase());
|
2014-04-18 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 22:40:15 +02:00
|
|
|
public static HashMap<String, WrappedGameProfile> getGameProfiles() {
|
2014-05-31 20:47:05 +02:00
|
|
|
return gameProfiles;
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:54:36 +02:00
|
|
|
public static TargetedDisguise getMainDisguise(UUID entityId) {
|
2014-01-21 02:05:32 +01:00
|
|
|
TargetedDisguise toReturn = null;
|
|
|
|
if (getDisguises().containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
toReturn = disguise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2013-12-24 05:30:39 +01:00
|
|
|
/**
|
|
|
|
* Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise.
|
|
|
|
*/
|
|
|
|
public static ArrayList<Player> getPerverts(Disguise disguise) {
|
|
|
|
ArrayList<Player> players = new ArrayList<Player>();
|
|
|
|
try {
|
2014-06-15 01:06:02 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
2013-12-24 05:30:39 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2014-06-15 09:35:47 +02:00
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
|
|
|
entityTrackerEntry);
|
2013-12-24 05:30:39 +01:00
|
|
|
for (Object p : trackedPlayers) {
|
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
|
|
|
if (((TargetedDisguise) disguise).canSee(player)) {
|
|
|
|
players.add(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2014-06-04 22:40:15 +02:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) {
|
2014-08-26 18:25:02 +02:00
|
|
|
final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName();
|
|
|
|
final boolean remove = getAddedByPlugins().contains(nameToFetch.toLowerCase());
|
|
|
|
return getProfileFromMojang(nameToFetch, new LibsProfileLookup() {
|
2014-05-31 20:47:05 +02:00
|
|
|
|
|
|
|
@Override
|
2014-06-04 22:40:15 +02:00
|
|
|
public void onLookup(WrappedGameProfile gameProfile) {
|
2014-06-20 16:12:32 +02:00
|
|
|
if (remove) {
|
2014-08-26 18:25:02 +02:00
|
|
|
getAddedByPlugins().remove(nameToFetch.toLowerCase());
|
2014-06-20 16:12:32 +02:00
|
|
|
}
|
2014-07-03 11:30:09 +02:00
|
|
|
if (DisguiseAPI.isDisguiseInUse(disguise)
|
2014-08-26 18:25:02 +02:00
|
|
|
&& (!gameProfile.getName().equals(
|
|
|
|
disguise.getSkin() != null && LibVersion.is1_7_6() ? disguise.getSkin() : disguise.getName()) || (LibVersion
|
|
|
|
.is1_7_6() && !gameProfile.getProperties().isEmpty()))) {
|
2014-09-29 06:05:04 +02:00
|
|
|
disguise.setGameProfile(gameProfile);
|
2014-06-04 03:21:10 +02:00
|
|
|
DisguiseUtilities.refreshTrackers(disguise);
|
2014-04-19 13:11:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-04-19 08:22:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup
|
2014-04-19 13:11:56 +02:00
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
2014-04-19 08:22:27 +02:00
|
|
|
*/
|
2014-06-04 22:40:15 +02:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) {
|
2014-05-31 20:47:05 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn);
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:21:40 +02:00
|
|
|
private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable) {
|
2014-06-20 16:12:32 +02:00
|
|
|
final String playerName = origName.toLowerCase();
|
2014-04-18 22:14:02 +02:00
|
|
|
if (gameProfiles.containsKey(playerName)) {
|
|
|
|
if (gameProfiles.get(playerName) != null) {
|
|
|
|
return gameProfiles.get(playerName);
|
|
|
|
}
|
2014-08-26 04:39:24 +02:00
|
|
|
} else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
|
2014-04-23 01:44:12 +02:00
|
|
|
getAddedByPlugins().add(playerName);
|
2014-04-18 22:14:02 +02:00
|
|
|
Player player = Bukkit.getPlayerExact(playerName);
|
|
|
|
if (player != null) {
|
2014-06-04 22:40:15 +02:00
|
|
|
WrappedGameProfile gameProfile = ReflectionManager.getGameProfile(player);
|
2014-07-26 01:10:48 +02:00
|
|
|
if (!LibVersion.is1_7_6() || !gameProfile.getProperties().isEmpty()) {
|
2014-04-18 22:14:02 +02:00
|
|
|
gameProfiles.put(playerName, gameProfile);
|
|
|
|
return gameProfile;
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
2014-04-18 22:14:02 +02:00
|
|
|
}
|
|
|
|
// Add null so that if this is called again. I already know I'm doing something about it
|
|
|
|
gameProfiles.put(playerName, null);
|
2014-06-14 08:19:23 +02:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(libsDisguises, new Runnable() {
|
2014-04-18 22:14:02 +02:00
|
|
|
public void run() {
|
|
|
|
try {
|
2014-07-03 11:21:40 +02:00
|
|
|
final WrappedGameProfile gameProfile = lookupGameProfile(origName);
|
2014-06-14 08:19:23 +02:00
|
|
|
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
2014-04-18 22:14:02 +02:00
|
|
|
public void run() {
|
2014-09-02 10:32:52 +02:00
|
|
|
if (!LibVersion.is1_7_6() || !gameProfile.getProperties().isEmpty()) {
|
|
|
|
if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) {
|
|
|
|
gameProfiles.put(playerName, gameProfile);
|
|
|
|
}
|
|
|
|
if (runnables.containsKey(playerName)) {
|
|
|
|
for (Object obj : runnables.remove(playerName)) {
|
|
|
|
if (obj instanceof Runnable) {
|
|
|
|
((Runnable) obj).run();
|
|
|
|
} else if (obj instanceof LibsProfileLookup) {
|
|
|
|
((LibsProfileLookup) obj).onLookup(gameProfile);
|
|
|
|
}
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
2014-04-18 22:14:02 +02:00
|
|
|
}
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
2014-04-18 22:14:02 +02:00
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) {
|
|
|
|
gameProfiles.remove(playerName);
|
2014-04-23 01:44:12 +02:00
|
|
|
getAddedByPlugins().remove(playerName);
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
2014-04-18 22:14:02 +02:00
|
|
|
System.out.print("[LibsDisguises] Error when fetching " + playerName + "'s uuid from mojang: "
|
|
|
|
+ e.getMessage());
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
2014-04-18 22:14:02 +02:00
|
|
|
}
|
|
|
|
});
|
2014-08-26 18:25:02 +02:00
|
|
|
} else {
|
|
|
|
return ReflectionManager.getGameProfile(null, origName);
|
|
|
|
}
|
|
|
|
if (runnable != null) {
|
|
|
|
if (!runnables.containsKey(playerName)) {
|
|
|
|
runnables.put(playerName, new ArrayList<Object>());
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
2014-08-26 18:25:02 +02:00
|
|
|
runnables.get(playerName).add(runnable);
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
2014-06-20 16:12:32 +02:00
|
|
|
return ReflectionManager.getGameProfile(null, origName);
|
2014-04-14 16:26:31 +02:00
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
/**
|
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup
|
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
|
|
|
*/
|
2014-06-04 22:40:15 +02:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) {
|
2014-05-31 20:47:05 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn);
|
|
|
|
}
|
|
|
|
|
2014-06-15 10:12:07 +02:00
|
|
|
public static HashSet<UUID> getSelfDisguised() {
|
|
|
|
return selfDisguised;
|
2013-11-22 20:52:15 +01:00
|
|
|
}
|
|
|
|
|
2014-04-18 22:14:02 +02:00
|
|
|
public static boolean hasGameProfile(String playerName) {
|
|
|
|
return getGameProfile(playerName) != null;
|
|
|
|
}
|
|
|
|
|
2013-11-22 21:04:31 +01:00
|
|
|
public static void init(LibsDisguises disguises) {
|
|
|
|
libsDisguises = disguises;
|
|
|
|
}
|
|
|
|
|
2013-12-01 14:36:42 +01:00
|
|
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
2014-06-04 03:20:46 +02:00
|
|
|
return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId())
|
|
|
|
&& getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise);
|
2013-12-01 14:36:42 +01:00
|
|
|
}
|
|
|
|
|
2014-04-18 22:14:02 +02:00
|
|
|
/**
|
|
|
|
* This is called on a thread as it is thread blocking
|
|
|
|
*/
|
2014-06-04 22:40:15 +02:00
|
|
|
public static WrappedGameProfile lookupGameProfile(String playerName) {
|
2014-09-29 06:19:07 +02:00
|
|
|
return ReflectionManager.getSkullBlob(ReflectionManager.grabProfileAddUUID(playerName));
|
2014-04-18 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 18:01:48 +02:00
|
|
|
/**
|
2014-09-21 18:36:54 +02:00
|
|
|
* Please note that in the future when 'DualInt' and the like are removed. This should break.. However, that should be negated
|
|
|
|
* in the future as I'd be able to set the watcher index's as per the spigot version. Instead of checking on the player's
|
|
|
|
* version every single packet..
|
2014-09-16 18:01:48 +02:00
|
|
|
*/
|
2014-09-03 03:30:11 +02:00
|
|
|
public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher,
|
|
|
|
List<WrappedWatchableObject> list) {
|
2014-12-07 16:59:38 +01:00
|
|
|
if (!LibVersion.is1_8())
|
2014-09-03 03:30:11 +02:00
|
|
|
return list;
|
|
|
|
ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<WrappedWatchableObject>();
|
|
|
|
ArrayList<WrappedWatchableObject> backups = new ArrayList<WrappedWatchableObject>();
|
|
|
|
// TODO Player and Minecart
|
|
|
|
for (WrappedWatchableObject obj : list) {
|
|
|
|
if (obj.getValue().getClass().getName().startsWith("org.")) {
|
|
|
|
backups.add(obj);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (obj.getIndex()) {
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
if (watcher instanceof ItemFrameWatcher) {
|
|
|
|
rebuiltList.add(new WrappedWatchableObject(obj.getIndex() + 6, obj.getValue()));
|
|
|
|
} else {
|
|
|
|
backups.add(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
rebuiltList.add(new WrappedWatchableObject(obj.getIndex() - 8, obj.getValue()));
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (watcher instanceof AgeableWatcher) {
|
|
|
|
int i = (Integer) obj.getValue();
|
|
|
|
rebuiltList.add(new WrappedWatchableObject(obj.getIndex(), (byte) (i < 0 ? -1 : (i >= 6000 ? 1 : 0))));
|
|
|
|
} else {
|
|
|
|
backups.add(obj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
if (watcher instanceof EndermanWatcher) {
|
2014-11-17 02:48:43 +01:00
|
|
|
rebuiltList.add(new WrappedWatchableObject(obj.getIndex(), ((Byte) obj.getValue()).shortValue()));
|
2014-09-03 03:30:11 +02:00
|
|
|
} else {
|
|
|
|
backups.add(obj);
|
|
|
|
}
|
|
|
|
break;
|
2014-09-16 18:01:48 +02:00
|
|
|
case 20:
|
|
|
|
if (watcher instanceof MinecartWatcher) {
|
|
|
|
// TODO
|
|
|
|
backups.add(obj);
|
|
|
|
} else {
|
|
|
|
backups.add(obj);
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
default:
|
|
|
|
backups.add(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Iterator<WrappedWatchableObject> itel = backups.iterator();
|
|
|
|
while (itel.hasNext()) {
|
|
|
|
int index = itel.next().getIndex();
|
|
|
|
for (WrappedWatchableObject obj2 : rebuiltList) {
|
|
|
|
if (index == obj2.getIndex()) {
|
|
|
|
itel.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuiltList.addAll(backups);
|
|
|
|
return rebuiltList;
|
|
|
|
}
|
|
|
|
|
2013-12-01 17:10:38 +01:00
|
|
|
/**
|
2014-06-04 03:18:43 +02:00
|
|
|
* Resends the entity to this specific player
|
2013-12-01 17:10:38 +01:00
|
|
|
*/
|
2014-09-03 01:38:28 +02:00
|
|
|
public static void refreshTracker(final TargetedDisguise disguise, String player) {
|
2014-04-19 13:14:58 +02:00
|
|
|
if (disguise.getEntity() != null && disguise.getEntity().isValid()) {
|
|
|
|
try {
|
2014-09-04 05:08:17 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
2014-06-20 22:01:42 +02:00
|
|
|
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player
|
|
|
|
&& ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
|
2014-09-03 01:38:28 +02:00
|
|
|
removeSelfDisguise((Player) disguise.getEntity());
|
2014-09-04 05:08:17 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
|
2014-09-03 01:38:28 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
}, 2);
|
2014-06-20 22:01:42 +02:00
|
|
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
|
|
|
} else {
|
2014-09-03 01:38:28 +02:00
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
2014-06-20 22:01:42 +02:00
|
|
|
if (entityTrackerEntry != null) {
|
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
|
|
|
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2014-09-03 01:38:28 +02:00
|
|
|
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
2014-06-20 22:01:42 +02:00
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
|
|
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
2014-09-03 01:38:28 +02:00
|
|
|
for (final Object p : cloned) {
|
2014-09-04 05:08:17 +02:00
|
|
|
Player pl = (Player) ReflectionManager.getBukkitEntity(p);
|
|
|
|
if (player.equalsIgnoreCase((pl).getName())) {
|
2014-06-20 22:01:42 +02:00
|
|
|
clear.invoke(entityTrackerEntry, p);
|
2014-09-04 05:08:17 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket);
|
2014-09-03 01:38:28 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
}, 2);
|
2014-06-20 22:01:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-04-19 13:14:58 +02:00
|
|
|
}
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-19 13:14:58 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:59:22 +01:00
|
|
|
/**
|
2014-06-04 03:18:43 +02:00
|
|
|
* A convenience method for me to refresh trackers in other plugins
|
2014-02-27 22:59:22 +01:00
|
|
|
*/
|
|
|
|
public static void refreshTrackers(Entity entity) {
|
2014-04-19 13:14:58 +02:00
|
|
|
if (entity.isValid()) {
|
|
|
|
try {
|
2014-09-04 05:08:17 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(entity.getEntityId());
|
2014-09-03 01:38:28 +02:00
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity);
|
2014-04-19 13:14:58 +02:00
|
|
|
if (entityTrackerEntry != null) {
|
2014-06-15 09:35:47 +02:00
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
|
|
|
entityTrackerEntry);
|
2014-06-15 01:06:02 +02:00
|
|
|
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2014-09-03 01:38:28 +02:00
|
|
|
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
2014-04-19 13:14:58 +02:00
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
|
|
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
2014-09-03 01:38:28 +02:00
|
|
|
for (final Object p : cloned) {
|
2014-04-19 13:14:58 +02:00
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
2014-06-20 23:37:38 +02:00
|
|
|
if (player != entity) {
|
2014-04-19 13:14:58 +02:00
|
|
|
clear.invoke(entityTrackerEntry, p);
|
2014-09-04 05:08:17 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
2014-09-03 01:38:28 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
}, 2);
|
2014-04-19 13:14:58 +02:00
|
|
|
}
|
2014-02-27 22:59:22 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-19 13:14:58 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2014-02-27 22:59:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
/**
|
2014-06-04 03:18:43 +02:00
|
|
|
* Resends the entity to all the watching players, which is where the magic begins
|
2013-11-22 20:52:15 +01:00
|
|
|
*/
|
2014-09-03 01:38:28 +02:00
|
|
|
public static void refreshTrackers(final TargetedDisguise disguise) {
|
2014-06-20 22:01:42 +02:00
|
|
|
if (disguise.getEntity().isValid()) {
|
2014-09-04 05:08:17 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
2014-06-20 22:01:42 +02:00
|
|
|
try {
|
2014-06-20 23:37:38 +02:00
|
|
|
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
|
2014-09-03 01:38:28 +02:00
|
|
|
removeSelfDisguise((Player) disguise.getEntity());
|
2014-09-04 05:08:17 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
|
2014-09-03 01:38:28 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
}, 2);
|
2014-06-20 22:01:42 +02:00
|
|
|
}
|
2014-09-03 01:38:28 +02:00
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
2014-06-20 22:01:42 +02:00
|
|
|
if (entityTrackerEntry != null) {
|
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
|
|
|
entityTrackerEntry);
|
|
|
|
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2014-09-03 01:38:28 +02:00
|
|
|
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
|
2014-06-20 22:01:42 +02:00
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
|
|
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
2014-09-03 01:38:28 +02:00
|
|
|
for (final Object p : cloned) {
|
2014-06-20 22:01:42 +02:00
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
2014-09-27 02:18:54 +02:00
|
|
|
if (disguise.getEntity() != player && disguise.canSee(player)) {
|
2014-06-20 22:01:42 +02:00
|
|
|
clear.invoke(entityTrackerEntry, p);
|
2014-09-04 05:08:17 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
2014-09-03 01:38:28 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 03:30:11 +02:00
|
|
|
}, 2);
|
2014-06-20 22:01:42 +02:00
|
|
|
}
|
2013-12-01 16:37:07 +01:00
|
|
|
}
|
2013-11-22 20:52:15 +01:00
|
|
|
}
|
2014-06-20 22:01:42 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2013-11-22 20:52:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-01 17:10:38 +01:00
|
|
|
public static boolean removeDisguise(TargetedDisguise disguise) {
|
2014-04-02 14:54:36 +02:00
|
|
|
UUID entityId = disguise.getEntity().getUniqueId();
|
2013-12-01 17:10:38 +01:00
|
|
|
if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
|
|
|
|
if (getDisguises().get(entityId).isEmpty()) {
|
|
|
|
getDisguises().remove(entityId);
|
|
|
|
}
|
2013-12-22 01:03:47 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) {
|
|
|
|
doBoundingBox(disguise);
|
|
|
|
}
|
2013-12-01 17:10:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
@Deprecated
|
2014-04-23 01:44:12 +02:00
|
|
|
public static void removeGameprofile(String string) {
|
2014-06-20 16:12:32 +02:00
|
|
|
removeGameProfile(string);
|
2014-04-23 01:44:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-31 20:47:05 +02:00
|
|
|
public static void removeGameProfile(String string) {
|
2014-06-20 16:12:32 +02:00
|
|
|
gameProfiles.remove(string.toLowerCase());
|
2014-05-31 20:47:05 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
public static void removeSelfDisguise(Player player) {
|
2014-06-15 10:12:07 +02:00
|
|
|
if (selfDisguised.contains(player.getUniqueId())) {
|
2013-11-22 20:52:15 +01:00
|
|
|
// Send a packet to destroy the fake entity
|
2013-12-07 15:30:30 +01:00
|
|
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
2014-06-15 10:12:07 +02:00
|
|
|
packet.getModifier().write(0, new int[] { DisguiseAPI.getSelfDisguiseId() });
|
2013-11-22 20:52:15 +01:00
|
|
|
try {
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
// Remove the fake entity ID from the disguise bin
|
2014-06-15 10:12:07 +02:00
|
|
|
selfDisguised.remove(player.getUniqueId());
|
2013-11-22 20:52:15 +01:00
|
|
|
// Get the entity tracker
|
|
|
|
try {
|
2014-06-15 01:06:02 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
|
2013-11-22 20:52:15 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2014-06-15 09:35:47 +02:00
|
|
|
HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(
|
|
|
|
entityTrackerEntry);
|
2013-11-22 20:52:15 +01:00
|
|
|
// If the tracker exists. Remove himself from his tracker
|
|
|
|
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
// Resend entity metadata else he will be invisible to himself until its resent
|
2013-11-22 20:52:15 +01:00
|
|
|
try {
|
2013-11-22 21:04:31 +01:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(
|
|
|
|
player,
|
2013-11-23 03:50:10 +01:00
|
|
|
ProtocolLibrary
|
|
|
|
.getProtocolManager()
|
2013-12-07 15:30:30 +01:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(),
|
2013-11-23 03:50:10 +01:00
|
|
|
WrappedDataWatcher.getEntityWatcher(player), true)
|
|
|
|
.createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true));
|
2013-11-22 20:52:15 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
player.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 21:04:31 +01:00
|
|
|
/**
|
|
|
|
* Sends the self disguise to the player
|
|
|
|
*/
|
2014-06-20 21:58:37 +02:00
|
|
|
public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
|
2013-11-22 21:04:31 +01:00
|
|
|
try {
|
2014-06-20 21:58:37 +02:00
|
|
|
if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible()
|
|
|
|
|| !disguise.canSee(player)) {
|
2013-11-23 03:21:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-15 01:06:02 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
|
2013-11-22 21:04:31 +01:00
|
|
|
if (entityTrackerEntry == 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.
|
|
|
|
// Else its going to run in a infinite loop hue hue hue..
|
2014-04-13 03:15:04 +02:00
|
|
|
// At least until this disguise is discarded
|
2014-06-14 08:19:23 +02:00
|
|
|
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
2013-11-22 21:04:31 +01:00
|
|
|
public void run() {
|
2014-04-13 03:15:04 +02:00
|
|
|
if (DisguiseAPI.getDisguise(player, player) == disguise) {
|
|
|
|
sendSelfDisguise(player, disguise);
|
|
|
|
}
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Add himself to his own entity tracker
|
2014-06-15 09:35:47 +02:00
|
|
|
((HashSet<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry))
|
|
|
|
.add(ReflectionManager.getNmsEntity(player));
|
2013-11-22 21:04:31 +01:00
|
|
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
|
|
|
// Send the player a packet with himself being spawned
|
2014-01-31 11:00:24 +01:00
|
|
|
manager.sendServerPacket(player, manager.createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
|
|
|
|
.createPacket(player));
|
2014-05-28 11:53:08 +02:00
|
|
|
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
|
2014-01-31 11:00:24 +01:00
|
|
|
sendSelfPacket(
|
2013-11-22 21:04:31 +01:00
|
|
|
player,
|
2014-05-28 11:53:08 +02:00
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), dataWatcher,
|
2014-06-15 10:12:07 +02:00
|
|
|
true).createPacket(player.getEntityId(), dataWatcher, true));
|
2013-11-22 21:04:31 +01:00
|
|
|
|
|
|
|
boolean isMoving = false;
|
|
|
|
try {
|
|
|
|
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
|
|
|
|
field.setAccessible(true);
|
|
|
|
isMoving = field.getBoolean(entityTrackerEntry);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
// Send the velocity packets
|
|
|
|
if (isMoving) {
|
|
|
|
Vector velocity = player.getVelocity();
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(
|
2013-11-22 21:04:31 +01:00
|
|
|
player,
|
2014-01-31 10:56:05 +01:00
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(),
|
|
|
|
velocity.getX(), velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(),
|
2014-06-15 10:12:07 +02:00
|
|
|
velocity.getX(), velocity.getY(), velocity.getZ()));
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Why the hell would he even need this. Meh.
|
|
|
|
if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(player,
|
2013-12-07 15:30:30 +01:00
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
|
2014-06-15 10:12:07 +02:00
|
|
|
.createPacket(0, player, player.getVehicle()));
|
2013-11-22 21:04:31 +01:00
|
|
|
} else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) {
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(player,
|
2013-12-07 15:30:30 +01:00
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
|
2014-06-15 10:12:07 +02:00
|
|
|
.createPacket(0, player.getPassenger(), player));
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resend the armor
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
ItemStack item;
|
|
|
|
if (i == 0) {
|
|
|
|
item = player.getItemInHand();
|
|
|
|
} else {
|
|
|
|
item = player.getInventory().getArmorContents()[i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item != null && item.getType() != Material.AIR) {
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(
|
|
|
|
player,
|
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i,
|
2014-06-15 10:12:07 +02:00
|
|
|
item).createPacket(player.getEntityId(), i, item));
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
// If the disguised is sleeping for w/e reason
|
|
|
|
if (player.isSleeping()) {
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(
|
2013-11-22 21:04:31 +01:00
|
|
|
player,
|
2014-01-04 23:05:19 +01:00
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.BED, player, loc.getBlockX(), loc.getBlockY(),
|
2014-06-15 10:12:07 +02:00
|
|
|
loc.getBlockZ()).createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resend any active potion effects
|
2014-06-04 03:21:10 +02:00
|
|
|
for (Object potionEffect : player.getActivePotionEffects()) {
|
2014-01-31 10:56:05 +01:00
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
|
2014-06-15 10:12:07 +02:00
|
|
|
.createPacket(player.getEntityId(), potionEffect));
|
2013-11-22 21:04:31 +01:00
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:59:22 +01:00
|
|
|
/**
|
|
|
|
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
|
|
|
*/
|
2014-09-21 18:57:46 +02:00
|
|
|
private static void sendSelfPacket(final Player player, PacketContainer packet) {
|
|
|
|
PacketContainer[][] transformed = PacketsManager.transformPacket(packet, player, player);
|
|
|
|
PacketContainer[] packets = transformed == null ? null : transformed[0];
|
|
|
|
final PacketContainer[] delayed = transformed == null ? null : transformed[1];
|
2014-02-27 22:59:22 +01:00
|
|
|
try {
|
2014-03-23 13:45:02 +01:00
|
|
|
if (packets == null) {
|
|
|
|
packets = new PacketContainer[] { packet };
|
|
|
|
}
|
2014-02-27 22:59:22 +01:00
|
|
|
for (PacketContainer p : packets) {
|
|
|
|
p = p.deepClone();
|
2014-06-15 10:12:07 +02:00
|
|
|
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
2014-02-27 22:59:22 +01:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
|
|
|
}
|
2014-09-21 18:57:46 +02:00
|
|
|
if (delayed != null && delayed.length > 0) {
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
for (PacketContainer packet : delayed) {
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
|
|
|
}
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-02-27 22:59:22 +01:00
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
/**
|
|
|
|
* Setup it so he can see himself when disguised
|
|
|
|
*/
|
|
|
|
public static void setupFakeDisguise(final Disguise disguise) {
|
2013-12-01 13:32:38 +01:00
|
|
|
Entity e = disguise.getEntity();
|
2013-11-22 20:52:15 +01:00
|
|
|
// If the disguises entity is null, or the disguised entity isn't a player return
|
2014-04-02 14:54:36 +02:00
|
|
|
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId())
|
|
|
|
|| !getDisguises().get(e.getUniqueId()).contains(disguise)) {
|
2013-11-22 20:52:15 +01:00
|
|
|
return;
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
2013-12-01 13:32:38 +01:00
|
|
|
Player player = (Player) e;
|
2013-12-01 17:10:38 +01:00
|
|
|
// Check if he can even see this..
|
|
|
|
if (!((TargetedDisguise) disguise).canSee(player)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-22 20:52:15 +01:00
|
|
|
// Remove the old disguise, else we have weird disguises around the place
|
|
|
|
DisguiseUtilities.removeSelfDisguise(player);
|
|
|
|
// If the disguised player can't see himself. Return
|
2013-12-01 17:10:38 +01:00
|
|
|
if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null) {
|
2013-11-22 20:52:15 +01:00
|
|
|
return;
|
2013-12-01 17:10:38 +01:00
|
|
|
}
|
2014-06-15 10:12:07 +02:00
|
|
|
selfDisguised.add(player.getUniqueId());
|
2014-06-20 21:58:37 +02:00
|
|
|
sendSelfDisguise(player, (TargetedDisguise) disguise);
|
2013-11-22 20:52:15 +01:00
|
|
|
if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
|
|
|
|
if (PacketsManager.isInventoryListenerEnabled()) {
|
|
|
|
player.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|