2016-05-11 23:47:08 +02:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
|
|
|
|
2016-06-14 20:40:45 +02:00
|
|
|
import com.comphenix.protocol.PacketType.Play.Server;
|
2016-05-11 23:47:08 +02:00
|
|
|
import com.comphenix.protocol.ProtocolLibrary;
|
|
|
|
import com.comphenix.protocol.ProtocolManager;
|
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
2019-01-03 03:13:03 +01:00
|
|
|
import com.comphenix.protocol.wrappers.*;
|
2017-06-02 15:51:03 +02:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
2019-12-31 07:35:21 +01:00
|
|
|
import com.google.gson.JsonSyntaxException;
|
2020-01-02 05:10:36 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2017-06-02 15:51:03 +02:00
|
|
|
import com.mojang.authlib.properties.PropertyMap;
|
2016-05-11 23:47:08 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
2016-12-21 04:25:28 +01:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig.DisguisePushing;
|
2016-05-11 23:47:08 +02:00
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
2017-06-02 15:51:03 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.*;
|
2016-05-11 23:47:08 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
2017-06-02 15:51:03 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.json.*;
|
2020-01-02 05:10:36 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
|
|
|
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
2018-01-09 06:13:03 +01:00
|
|
|
import org.apache.logging.log4j.util.Strings;
|
2019-12-31 07:35:21 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
2019-05-18 08:54:51 +02:00
|
|
|
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
|
2019-01-03 03:13:03 +01:00
|
|
|
import org.bukkit.entity.*;
|
2017-05-28 00:23:15 +02:00
|
|
|
import org.bukkit.inventory.EquipmentSlot;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
import org.bukkit.scoreboard.Team;
|
|
|
|
import org.bukkit.scoreboard.Team.Option;
|
|
|
|
import org.bukkit.scoreboard.Team.OptionStatus;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.PrintWriter;
|
2018-08-05 10:34:02 +02:00
|
|
|
import java.lang.reflect.*;
|
2017-05-28 00:23:15 +02:00
|
|
|
import java.util.*;
|
2019-10-22 00:29:03 +02:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2018-08-14 02:42:35 +02:00
|
|
|
import java.util.logging.Logger;
|
2018-10-25 15:03:00 +02:00
|
|
|
import java.util.regex.Matcher;
|
2017-05-28 00:23:15 +02:00
|
|
|
import java.util.regex.Pattern;
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public class DisguiseUtilities {
|
2016-05-11 23:47:08 +02:00
|
|
|
public static final Random random = new Random();
|
|
|
|
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
|
|
|
|
/**
|
|
|
|
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
|
|
|
|
*/
|
2019-10-22 00:29:03 +02:00
|
|
|
private static Map<UUID, Set<TargetedDisguise>> disguisesInUse = new ConcurrentHashMap<>();
|
2016-05-11 23:47:08 +02:00
|
|
|
/**
|
2018-01-09 06:13:03 +01:00
|
|
|
* Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only
|
|
|
|
* stay in for
|
2016-05-11 23:47:08 +02:00
|
|
|
* a max of a second.
|
|
|
|
*/
|
|
|
|
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>();
|
2017-05-28 00:23:15 +02:00
|
|
|
private static HashSet<UUID> savedDisguiseList = new HashSet<>();
|
|
|
|
private static HashSet<String> cachedNames = new HashSet<>();
|
2020-01-02 05:10:36 +01:00
|
|
|
private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
|
2016-05-11 23:47:08 +02:00
|
|
|
private static HashSet<UUID> selfDisguised = new HashSet<>();
|
2016-06-05 15:31:34 +02:00
|
|
|
private static Thread mainThread;
|
2016-06-13 22:55:30 +02:00
|
|
|
private static PacketContainer spawnChunk;
|
2017-05-28 00:23:15 +02:00
|
|
|
private static HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
|
2018-08-24 00:01:01 +02:00
|
|
|
private static HashMap<UUID, String> disguiseTeam = new HashMap<>();
|
2017-05-28 00:23:15 +02:00
|
|
|
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File(
|
|
|
|
"plugins/LibsDisguises/SavedDisguises");
|
2017-06-02 15:51:03 +02:00
|
|
|
private static Gson gson;
|
2017-06-22 18:14:19 +02:00
|
|
|
private static boolean pluginsUsed, commandsUsed;
|
|
|
|
private static long libsDisguisesCalled;
|
2019-01-16 07:58:53 +01:00
|
|
|
/**
|
|
|
|
* Keeps track of what tick this occured
|
|
|
|
*/
|
|
|
|
private static long velocityTime;
|
|
|
|
private static int velocityID;
|
2019-10-13 07:22:39 +02:00
|
|
|
private static HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>();
|
2019-11-10 10:45:46 +01:00
|
|
|
private static boolean runningPaper;
|
2020-01-02 05:10:36 +01:00
|
|
|
private static MineSkinAPI mineSkinAPI = new MineSkinAPI();
|
|
|
|
|
|
|
|
public static MineSkinAPI getMineSkinAPI() {
|
|
|
|
return mineSkinAPI;
|
|
|
|
}
|
2019-01-16 07:58:53 +01:00
|
|
|
|
|
|
|
public static void setPlayerVelocity(Player player) {
|
|
|
|
velocityID = player.getEntityId();
|
|
|
|
velocityTime = player.getWorld().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if this velocity is due to a PlayerVelocityEvent
|
|
|
|
*/
|
|
|
|
public static boolean isPlayerVelocity(Player player) {
|
|
|
|
// Be generous with how many ticks they have until they jump, the server could be lagging and the player
|
|
|
|
// would effectively have anti-knockback
|
|
|
|
return player.getEntityId() == velocityID && (player.getWorld().getTime() - velocityTime) < 3;
|
|
|
|
}
|
2017-06-22 18:14:19 +02:00
|
|
|
|
|
|
|
public static void setPluginsUsed() {
|
|
|
|
if (libsDisguisesCalled > System.currentTimeMillis()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginsUsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void resetPluginTimer() {
|
|
|
|
libsDisguisesCalled = System.currentTimeMillis() + 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCommandsUsed() {
|
|
|
|
resetPluginTimer();
|
|
|
|
commandsUsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPluginsUsed() {
|
|
|
|
return pluginsUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isCommandsUsed() {
|
|
|
|
return commandsUsed;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
public static void saveDisguises() {
|
2017-07-23 20:28:14 +02:00
|
|
|
if (!LibsPremium.isPremium())
|
|
|
|
return;
|
|
|
|
|
2017-07-23 20:31:09 +02:00
|
|
|
if (!DisguiseConfig.isSaveEntityDisguises() && !DisguiseConfig.isSavePlayerDisguises())
|
|
|
|
return;
|
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().info("Now saving disguises..");
|
2017-07-23 20:31:09 +02:00
|
|
|
|
2019-10-22 00:29:03 +02:00
|
|
|
for (Set<TargetedDisguise> list : getDisguises().values()) {
|
2017-06-09 16:33:50 +02:00
|
|
|
for (TargetedDisguise disg : list) {
|
|
|
|
if (disg.getEntity() == null)
|
|
|
|
continue;
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-04-21 00:57:47 +02:00
|
|
|
if (disg.getEntity() instanceof Player ? !DisguiseConfig.isSavePlayerDisguises() :
|
|
|
|
!DisguiseConfig.isSaveEntityDisguises())
|
2017-07-23 20:28:14 +02:00
|
|
|
continue;
|
|
|
|
|
2017-06-09 16:33:50 +02:00
|
|
|
saveDisguises(disg.getEntity().getUniqueId(), list.toArray(new Disguise[0]));
|
|
|
|
break;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2017-07-23 20:31:09 +02:00
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().info("Saved disguises.");
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
public static boolean hasGameProfile(String playername) {
|
2017-05-28 00:23:15 +02:00
|
|
|
return cachedNames.contains(playername.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
public static void createClonedDisguise(Player player, Entity toClone, Boolean[] options) {
|
|
|
|
Disguise disguise = DisguiseAPI.getDisguise(player, toClone);
|
|
|
|
|
|
|
|
if (disguise == null) {
|
|
|
|
disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1], options[2]);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2017-01-20 19:58:51 +01:00
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
|
|
|
|
|
|
|
|
String reference = null;
|
|
|
|
int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D));
|
|
|
|
int attempts = 0;
|
|
|
|
|
|
|
|
while (reference == null && attempts++ < 1000) {
|
|
|
|
reference = "@";
|
|
|
|
|
|
|
|
for (int i = 0; i < referenceLength; i++) {
|
|
|
|
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
|
|
|
|
reference = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) {
|
|
|
|
String entityName = DisguiseType.getType(toClone).toReadable();
|
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
player.sendMessage(LibsMsg.MADE_REF.get(entityName, reference));
|
|
|
|
player.sendMessage(LibsMsg.MADE_REF_EXAMPLE.get(reference));
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2017-06-19 19:06:35 +02:00
|
|
|
player.sendMessage(LibsMsg.REF_TOO_MANY.get());
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-28 00:23:15 +02:00
|
|
|
public static void saveDisguises(UUID owningEntity, Disguise[] disguise) {
|
2017-06-08 17:09:28 +02:00
|
|
|
if (!LibsPremium.isPremium())
|
2017-06-02 15:51:03 +02:00
|
|
|
return;
|
|
|
|
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!savedDisguises.exists())
|
|
|
|
savedDisguises.mkdirs();
|
|
|
|
|
2017-05-28 00:23:15 +02:00
|
|
|
try {
|
|
|
|
File disguiseFile = new File(savedDisguises, owningEntity.toString());
|
|
|
|
|
|
|
|
if (disguise == null || disguise.length == 0) {
|
|
|
|
if (savedDisguiseList.contains(owningEntity)) {
|
|
|
|
disguiseFile.delete();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Disguise[] disguises = new Disguise[disguise.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < disguise.length; i++) {
|
|
|
|
Disguise dis = disguise[i].clone();
|
|
|
|
dis.setEntity(null);
|
|
|
|
|
|
|
|
disguises[i] = dis;
|
|
|
|
}
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
PrintWriter writer = new PrintWriter(disguiseFile);
|
|
|
|
writer.write(gson.toJson(disguises));
|
|
|
|
writer.close();
|
2017-05-28 00:23:15 +02:00
|
|
|
|
|
|
|
savedDisguiseList.add(owningEntity);
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 20:28:14 +02:00
|
|
|
catch (StackOverflowError | Exception e) {
|
2017-05-28 00:23:15 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Disguise[] getSavedDisguises(UUID entityUUID) {
|
|
|
|
return getSavedDisguises(entityUUID, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Disguise[] getSavedDisguises(UUID entityUUID, boolean remove) {
|
2018-11-19 04:55:32 +01:00
|
|
|
if (!isSavedDisguise(entityUUID) || !LibsPremium.isPremium()) {
|
2017-05-28 00:23:15 +02:00
|
|
|
return new Disguise[0];
|
2018-11-19 04:55:32 +01:00
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2018-11-19 04:55:32 +01:00
|
|
|
if (!savedDisguises.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
savedDisguises.mkdirs();
|
2018-11-19 04:55:32 +01:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
File disguiseFile = new File(savedDisguises, entityUUID.toString());
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
if (!disguiseFile.exists()) {
|
|
|
|
savedDisguiseList.remove(entityUUID);
|
2017-05-28 00:23:15 +02:00
|
|
|
return new Disguise[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-11-19 04:55:32 +01:00
|
|
|
String cached = FileUtils.readFileToString(disguiseFile, "UTF-8");
|
2017-05-28 00:23:15 +02:00
|
|
|
|
|
|
|
if (remove) {
|
|
|
|
removeSavedDisguise(entityUUID);
|
|
|
|
}
|
|
|
|
|
2018-11-19 04:55:32 +01:00
|
|
|
Disguise[] disguises = gson.fromJson(cached, Disguise[].class);
|
|
|
|
|
|
|
|
if (disguises == null) {
|
|
|
|
return new Disguise[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return disguises;
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("Malformed disguise for " + entityUUID);
|
2017-05-28 00:23:15 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Disguise[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeSavedDisguise(UUID entityUUID) {
|
|
|
|
if (!savedDisguiseList.remove(entityUUID))
|
|
|
|
return;
|
|
|
|
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!savedDisguises.exists())
|
|
|
|
savedDisguises.mkdirs();
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
File disguiseFile = new File(savedDisguises, entityUUID.toString());
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
disguiseFile.delete();
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSavedDisguise(UUID entityUUID) {
|
|
|
|
return savedDisguiseList.contains(entityUUID);
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static boolean addClonedDisguise(String key, Disguise disguise) {
|
|
|
|
if (DisguiseConfig.getMaxClonedDisguises() > 0) {
|
|
|
|
if (clonedDisguises.containsKey(key)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
clonedDisguises.remove(key);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else if (DisguiseConfig.getMaxClonedDisguises() == clonedDisguises.size()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
clonedDisguises.remove(clonedDisguises.keySet().iterator().next());
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (DisguiseConfig.getMaxClonedDisguises() > clonedDisguises.size()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
clonedDisguises.put(key, disguise);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void addDisguise(UUID entityId, TargetedDisguise disguise) {
|
|
|
|
if (!getDisguises().containsKey(entityId)) {
|
2019-10-22 00:29:03 +02:00
|
|
|
getDisguises().put(entityId, Collections.synchronizedSet(new HashSet<>()));
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getDisguises().get(entityId).add(disguise);
|
|
|
|
|
|
|
|
checkConflicts(disguise, null);
|
|
|
|
|
2018-01-09 06:13:03 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS &&
|
|
|
|
disguise.isModifyBoundingBox()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
doBoundingBox(disguise);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) {
|
|
|
|
if (!futureDisguises.containsKey(entityId)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
|
|
|
|
}
|
|
|
|
|
|
|
|
futureDisguises.get(entityId).add(disguise);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
final BukkitRunnable runnable = new BukkitRunnable() {
|
2016-05-11 23:47:08 +02:00
|
|
|
@Override
|
2016-11-28 22:47:48 +01:00
|
|
|
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) {
|
2016-05-11 23:47:08 +02:00
|
|
|
UUID uniqueId = entity.getUniqueId();
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
for (TargetedDisguise disguise : futureDisguises.remove(entityId)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
addDisguise(uniqueId, disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
futureDisguises.get(entityId).remove(disguise);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (futureDisguises.get(entityId).isEmpty()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
futureDisguises.remove(entityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
runnable.runTaskLater(LibsDisguises.getInstance(), 20);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
|
2017-05-28 00:23:15 +02:00
|
|
|
try {
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!profileCache.exists())
|
|
|
|
profileCache.mkdirs();
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
File file = new File(profileCache, string.toLowerCase());
|
|
|
|
PrintWriter writer = new PrintWriter(file);
|
|
|
|
writer.write(gson.toJson(gameProfile));
|
|
|
|
writer.close();
|
2017-05-28 00:23:15 +02:00
|
|
|
|
|
|
|
cachedNames.add(string.toLowerCase());
|
|
|
|
}
|
2017-07-23 20:28:14 +02:00
|
|
|
catch (StackOverflowError | Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-09 06:13:03 +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
|
2016-05-11 23:47:08 +02:00
|
|
|
* observers in the disguise don't see any other disguise.
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void checkConflicts(TargetedDisguise disguise, String name) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// If the disguise is being used.. Else we may accidentally undisguise something else
|
2016-11-28 22:47:48 +01:00
|
|
|
if (DisguiseAPI.isDisguiseInUse(disguise)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getUniqueId()).iterator();
|
|
|
|
// Iterate through the disguises
|
2016-11-28 22:47:48 +01:00
|
|
|
while (disguiseItel.hasNext()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
TargetedDisguise d = disguiseItel.next();
|
|
|
|
// Make sure the disguise isn't the same thing
|
2016-11-28 22:47:48 +01:00
|
|
|
if (d != disguise) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// If the loop'd disguise is hiding the disguise to everyone in its list
|
2016-11-28 22:47:48 +01:00
|
|
|
if (d.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// If player is a observer in the loop
|
2016-11-28 22:47:48 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// If player is a observer in the disguise
|
|
|
|
// Remove them from the loop
|
2016-11-28 22:47:48 +01:00
|
|
|
if (name != null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.removePlayer(name);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2016-11-28 22:47:48 +01:00
|
|
|
for (String playername : disguise.getObservers()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.silentlyRemovePlayer(playername);
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 17:22:07 +01:00
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// If player is not a observer in the loop
|
2016-11-28 22:47:48 +01:00
|
|
|
if (name != null) {
|
|
|
|
if (!disguise.getObservers().contains(name)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.removePlayer(name);
|
|
|
|
}
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2016-11-28 22:47:48 +01:00
|
|
|
for (String playername : new ArrayList<>(d.getObservers())) {
|
|
|
|
if (!disguise.getObservers().contains(playername)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.silentlyRemovePlayer(playername);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 17:22:07 +01:00
|
|
|
} else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// Here you add it to the loop if they see the disguise
|
2016-11-28 22:47:48 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// Everyone who is in the disguise needs to be added to the loop
|
2016-11-28 22:47:48 +01:00
|
|
|
if (name != null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.addPlayer(name);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2016-11-28 22:47:48 +01:00
|
|
|
for (String playername : disguise.getObservers()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
d.silentlyAddPlayer(playername);
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 17:22:07 +01:00
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// This here is a paradox.
|
|
|
|
// If fed a name. I can do this.
|
|
|
|
// But the rest of the time.. Its going to conflict.
|
|
|
|
|
|
|
|
disguiseItel.remove();
|
2018-10-14 00:26:17 +02:00
|
|
|
d.removeDisguise(true);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends entity removal packets, as this disguise was removed
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void destroyEntity(TargetedDisguise disguise) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-05-11 23:47:08 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
if (entityTrackerEntry == null)
|
|
|
|
return;
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
// If the tracker exists. Remove himself from his tracker
|
|
|
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
2017-03-15 17:22:07 +01:00
|
|
|
// ConcurrentModificationException
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-03-15 17:22:07 +01:00
|
|
|
destroyPacket.getIntegerArrays().write(0, new int[]{disguise.getEntity().getEntityId()});
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
for (Object p : trackedPlayers) {
|
2016-06-12 16:22:56 +02:00
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (player == disguise.getEntity() || disguise.canSee(player)) {
|
2016-06-12 16:22:56 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void doBoundingBox(TargetedDisguise disguise) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Entity entity = disguise.getEntity();
|
|
|
|
|
2018-10-24 00:09:16 +02:00
|
|
|
if (entity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDisguiseInUse(disguise)) {
|
|
|
|
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();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2018-10-24 00:09:16 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-10-24 00:09:16 +02:00
|
|
|
ReflectionManager.setBoundingBox(entity, disguiseBox);
|
|
|
|
} else {
|
|
|
|
DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType()));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-10-24 00:09:16 +02:00
|
|
|
FakeBoundingBox entityBox = entityValues.getAdultBox();
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-10-24 00:09:16 +02:00
|
|
|
if (entityValues.getBabyBox() != null) {
|
|
|
|
if ((entity instanceof Ageable && !((Ageable) entity).isAdult()) ||
|
|
|
|
(entity instanceof Zombie && ((Zombie) entity).isBaby())) {
|
|
|
|
entityBox = entityValues.getBabyBox();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-24 00:09:16 +02:00
|
|
|
|
|
|
|
ReflectionManager.setBoundingBox(entity, entityBox);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static int getChunkCord(int blockCord) {
|
2016-06-13 22:55:30 +02:00
|
|
|
int cord = (int) Math.floor(blockCord / 16D) - 17;
|
|
|
|
|
|
|
|
cord -= (cord % 8);
|
|
|
|
|
|
|
|
return cord;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static Disguise getClonedDisguise(String key) {
|
|
|
|
if (clonedDisguises.containsKey(key)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return clonedDisguises.get(key).clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static PacketContainer getDestroyPacket(int... ids) {
|
2016-05-11 23:47:08 +02:00
|
|
|
PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY);
|
|
|
|
|
|
|
|
destroyPacket.getIntegerArrays().write(0, ids);
|
|
|
|
|
|
|
|
return destroyPacket;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static TargetedDisguise getDisguise(Player observer, Entity entity) {
|
2016-05-11 23:47:08 +02:00
|
|
|
UUID entityId = entity.getUniqueId();
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (futureDisguises.containsKey(entity.getEntityId())) {
|
|
|
|
for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) {
|
2016-05-11 23:47:08 +02:00
|
|
|
addDisguise(entityId, disguise);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (getDisguises().containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
|
|
|
if (disguise.canSee(observer)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-10-22 00:29:03 +02:00
|
|
|
public static Map<UUID, Set<TargetedDisguise>> getDisguises() {
|
2016-05-11 23:47:08 +02:00
|
|
|
return disguisesInUse;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static TargetedDisguise[] getDisguises(UUID entityId) {
|
|
|
|
if (getDisguises().containsKey(entityId)) {
|
2019-10-22 00:29:03 +02:00
|
|
|
Set<TargetedDisguise> disguises = getDisguises().get(entityId);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
return disguises.toArray(new TargetedDisguise[disguises.size()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TargetedDisguise[0];
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static HashMap<Integer, HashSet<TargetedDisguise>> getFutureDisguises() {
|
2016-05-11 23:47:08 +02:00
|
|
|
return futureDisguises;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile getGameProfile(String playerName) {
|
2017-07-10 16:38:28 +02:00
|
|
|
if (!hasGameProfile(playerName))
|
2017-05-28 00:23:15 +02:00
|
|
|
return null;
|
|
|
|
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!profileCache.exists())
|
|
|
|
profileCache.mkdirs();
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
File file = new File(profileCache, playerName.toLowerCase());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
if (!file.exists()) {
|
2017-05-28 00:23:15 +02:00
|
|
|
cachedNames.remove(playerName.toLowerCase());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-06-02 15:51:03 +02:00
|
|
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
|
|
String cached = reader.readLine();
|
|
|
|
reader.close();
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
return gson.fromJson(cached, WrappedGameProfile.class);
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
2019-12-31 07:35:21 +01:00
|
|
|
catch (JsonSyntaxException ex) {
|
|
|
|
DisguiseUtilities.getLogger()
|
|
|
|
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
|
|
|
|
cachedNames.remove(playerName.toLowerCase());
|
|
|
|
file.delete();
|
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static TargetedDisguise getMainDisguise(UUID entityId) {
|
2016-05-11 23:47:08 +02:00
|
|
|
TargetedDisguise toReturn = null;
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (getDisguises().containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
|
|
|
|
toReturn = disguise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targeted disguise.
|
|
|
|
*
|
|
|
|
* @param disguise
|
|
|
|
* @return
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static List<Player> getPerverts(Disguise disguise) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-07-05 07:01:51 +02:00
|
|
|
if (disguise.getEntity() == null)
|
2017-03-15 17:22:07 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"The entity for the disguisetype " + disguise.getType().name() + " is null!");
|
2016-07-05 07:01:51 +02:00
|
|
|
|
2016-05-11 23:47:08 +02:00
|
|
|
List<Player> players = new ArrayList<>();
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-05-11 23:47:08 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2017-06-19 19:06:35 +02:00
|
|
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
2016-05-11 23:47:08 +02:00
|
|
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
2017-03-15 17:22:07 +01:00
|
|
|
// ConcurrentModificationException
|
2016-11-28 22:47:48 +01:00
|
|
|
for (Object p : trackedPlayers) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
2016-06-12 16:22:56 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (((TargetedDisguise) disguise).canSee(player)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
players.add(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) {
|
2016-05-11 23:47:08 +02:00
|
|
|
final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName();
|
2016-06-14 11:08:53 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
return getProfileFromMojang(nameToFetch, new LibsProfileLookup() {
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
@Override
|
2016-11-28 22:47:48 +01:00
|
|
|
public void onLookup(WrappedGameProfile gameProfile) {
|
2020-01-02 05:10:36 +01:00
|
|
|
if (gameProfile == null || gameProfile.getProperties().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName()
|
2018-01-09 06:13:03 +01:00
|
|
|
.equals(disguise.getSkin() != null ? disguise.getSkin() : disguise.getName()) ||
|
|
|
|
!gameProfile.getProperties().isEmpty())) {
|
2016-05-11 23:47:08 +02:00
|
|
|
disguise.setGameProfile(gameProfile);
|
|
|
|
|
|
|
|
DisguiseUtilities.refreshTrackers(disguise);
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 11:08:53 +02:00
|
|
|
}, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-09 06:13:03 +01:00
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does
|
|
|
|
* a lookup
|
2016-05-11 23:47:08 +02:00
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) {
|
2016-06-14 11:08:53 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, true);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 11:08:53 +02:00
|
|
|
/**
|
2018-01-09 06:13:03 +01:00
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does
|
|
|
|
* a lookup
|
2016-06-14 11:08:53 +02:00
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
|
|
|
*/
|
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn,
|
2016-11-28 22:47:48 +01:00
|
|
|
boolean contactMojang) {
|
2016-06-14 11:08:53 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
|
|
|
}
|
|
|
|
|
2017-03-15 17:22:07 +01:00
|
|
|
private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable,
|
|
|
|
boolean contactMojang) {
|
2016-05-11 23:47:08 +02:00
|
|
|
final String playerName = origName.toLowerCase();
|
|
|
|
|
2017-07-10 16:38:28 +02:00
|
|
|
if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) {
|
2019-12-31 07:35:21 +01:00
|
|
|
WrappedGameProfile profile = getGameProfile(playerName);
|
|
|
|
|
|
|
|
if (profile != null) {
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
|
2017-05-28 00:23:15 +02:00
|
|
|
final Player player = Bukkit.getPlayerExact(playerName);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (player != null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
WrappedGameProfile gameProfile = ReflectionManager.getGameProfile(player);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (!gameProfile.getProperties().isEmpty()) {
|
2017-07-10 18:41:04 +02:00
|
|
|
if (DisguiseConfig.isSaveGameProfiles()) {
|
|
|
|
addGameProfile(playerName, gameProfile);
|
|
|
|
}
|
2016-06-14 11:08:53 +02:00
|
|
|
|
2016-05-11 23:47:08 +02:00
|
|
|
return gameProfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
synchronized (runnables) {
|
|
|
|
if (contactMojang && !runnables.containsKey(playerName)) {
|
|
|
|
runnables.put(playerName, new ArrayList<>());
|
2016-06-14 20:40:45 +02:00
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
if (runnable != null) {
|
|
|
|
runnables.get(playerName).add(runnable);
|
|
|
|
}
|
2016-06-14 11:08:53 +02:00
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(LibsDisguises.getInstance(), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
final WrappedGameProfile gameProfile = lookupGameProfile(origName);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (DisguiseConfig.isSaveGameProfiles()) {
|
|
|
|
addGameProfile(playerName, gameProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized (runnables) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 20:40:45 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
synchronized (runnables) {
|
|
|
|
runnables.remove(playerName);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
getLogger().severe("Error when fetching " + playerName + "'s uuid from mojang: " +
|
|
|
|
e.getMessage());
|
|
|
|
}
|
2016-06-14 20:40:45 +02:00
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
});
|
|
|
|
} else if (runnable != null && contactMojang) {
|
2017-05-28 00:23:15 +02:00
|
|
|
runnables.get(playerName).add(runnable);
|
|
|
|
}
|
2016-06-14 20:40:45 +02:00
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
|
|
|
|
return null;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 17:22:07 +01:00
|
|
|
return ReflectionManager.getGameProfile(null, origName);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-09 06:13:03 +01:00
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does
|
|
|
|
* a lookup
|
2016-05-11 23:47:08 +02:00
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) {
|
2016-06-14 11:08:53 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-09 06:13:03 +01:00
|
|
|
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does
|
|
|
|
* a lookup
|
2016-06-14 11:08:53 +02:00
|
|
|
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn,
|
|
|
|
boolean contactMojang) {
|
2016-06-14 11:08:53 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static HashSet<UUID> getSelfDisguised() {
|
2016-05-11 23:47:08 +02:00
|
|
|
return selfDisguised;
|
|
|
|
}
|
|
|
|
|
2017-07-01 00:44:33 +02:00
|
|
|
public static Gson getGson() {
|
|
|
|
return gson;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void init(LibsDisguises disguises) {
|
2019-11-10 10:54:32 +01:00
|
|
|
try {
|
|
|
|
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
2019-11-10 10:45:46 +01:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
2020-01-02 05:10:36 +01:00
|
|
|
gsonBuilder.disableHtmlEscaping();
|
2019-12-21 07:12:22 +01:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex());
|
|
|
|
gsonBuilder.registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile());
|
|
|
|
gsonBuilder.registerTypeAdapter(WrappedBlockData.class, new SerializerWrappedBlockData());
|
2019-04-15 07:44:23 +02:00
|
|
|
gsonBuilder.registerTypeAdapter(WrappedChatComponent.class, new SerializerChatComponent());
|
2017-06-02 15:51:03 +02:00
|
|
|
gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer());
|
2019-12-21 07:12:22 +01:00
|
|
|
gsonBuilder.registerTypeHierarchyAdapter(ItemStack.class, new SerializerItemStack());
|
|
|
|
|
|
|
|
gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create()));
|
|
|
|
gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise());
|
2017-06-02 15:51:03 +02:00
|
|
|
|
|
|
|
gson = gsonBuilder.create();
|
|
|
|
|
|
|
|
try {
|
2019-05-18 08:54:51 +02:00
|
|
|
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread");
|
2017-06-02 15:51:03 +02:00
|
|
|
threadField.setAccessible(true);
|
|
|
|
|
|
|
|
mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer());
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!profileCache.exists())
|
|
|
|
profileCache.mkdirs();
|
|
|
|
|
|
|
|
if (!savedDisguises.exists())
|
|
|
|
savedDisguises.mkdirs();
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
cachedNames.addAll(Arrays.asList(profileCache.list()));
|
|
|
|
|
|
|
|
for (String key : savedDisguises.list()) {
|
2019-11-20 08:08:19 +01:00
|
|
|
try {
|
|
|
|
savedDisguiseList.add(UUID.fromString(key));
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
getLogger().warning("The file '" + key + "' does not belong in " + savedDisguises.getAbsolutePath());
|
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
2018-01-09 06:13:03 +01:00
|
|
|
return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId()) &&
|
|
|
|
getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called on a thread as it is thread blocking
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static WrappedGameProfile lookupGameProfile(String playerName) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return ReflectionManager.getSkullBlob(ReflectionManager.grabProfileAddUUID(playerName));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resends the entity to this specific player
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void refreshTracker(final TargetedDisguise disguise, String player) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
if (disguise.getEntity() == null || !disguise.getEntity().isValid())
|
|
|
|
return;
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-06-07 04:42:38 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
|
|
|
|
2018-01-09 06:13:03 +01:00
|
|
|
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player &&
|
2018-08-24 00:01:01 +02:00
|
|
|
disguise.getEntity().getName().equalsIgnoreCase(player)) {
|
2016-06-07 04:42:38 +02:00
|
|
|
removeSelfDisguise((Player) disguise.getEntity());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (disguise.isSelfDisguiseVisible()) {
|
2016-06-07 04:42:38 +02:00
|
|
|
selfDisguised.add(disguise.getEntity().getUniqueId());
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
|
|
|
}, 2);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2016-06-07 04:42:38 +02:00
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
if (entityTrackerEntry == null)
|
|
|
|
return;
|
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
2016-06-12 16:22:56 +02:00
|
|
|
|
2019-07-25 05:06:01 +02:00
|
|
|
Method clear = ReflectionManager
|
|
|
|
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-06-12 16:22:56 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
|
|
|
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-06-12 16:22:56 +02:00
|
|
|
|
|
|
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
2017-03-15 17:22:07 +01:00
|
|
|
// ConcurrentModificationException
|
2016-11-28 22:47:48 +01:00
|
|
|
for (final Object p : trackedPlayers) {
|
2016-06-12 16:22:56 +02:00
|
|
|
Player pl = (Player) ReflectionManager.getBukkitEntity(p);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-05-28 00:23:15 +02:00
|
|
|
if (pl == null || !player.equalsIgnoreCase((pl).getName()))
|
2016-06-12 16:22:56 +02:00
|
|
|
continue;
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
clear.invoke(entityTrackerEntry, p);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-12 16:22:56 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket);
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2016-06-12 16:22:56 +02:00
|
|
|
}, 2);
|
|
|
|
break;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
|
|
|
catch (
|
|
|
|
|
2018-08-05 10:34:02 +02:00
|
|
|
Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A convenience method for me to refresh trackers in other plugins
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void refreshTrackers(Entity entity) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (entity.isValid()) {
|
|
|
|
try {
|
2016-05-11 23:47:08 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(entity.getEntityId());
|
|
|
|
|
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2017-06-19 19:06:35 +02:00
|
|
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
Method clear = ReflectionManager
|
2019-05-18 08:54:51 +02:00
|
|
|
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
|
|
|
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
2017-03-15 17:22:07 +01:00
|
|
|
// ConcurrentModificationException
|
2016-11-28 22:47:48 +01:00
|
|
|
for (final Object p : trackedPlayers) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (player != entity) {
|
2016-05-11 23:47:08 +02:00
|
|
|
clear.invoke(entityTrackerEntry, p);
|
|
|
|
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resends the entity to all the watching players, which is where the magic begins
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void refreshTrackers(final TargetedDisguise disguise) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
if (!disguise.getEntity().isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
try {
|
|
|
|
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
|
|
|
|
removeSelfDisguise((Player) disguise.getEntity());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
selfDisguised.add(disguise.getEntity().getUniqueId());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-08-13 10:32:13 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
|
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-11-29 01:07:33 +01:00
|
|
|
}
|
|
|
|
}, 2);
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2017-06-19 19:06:35 +02:00
|
|
|
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-19 19:06:35 +02:00
|
|
|
final Method clear = ReflectionManager
|
2019-05-18 08:54:51 +02:00
|
|
|
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
|
|
|
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
|
2019-08-13 10:32:13 +02:00
|
|
|
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
for (final Object p : trackedPlayers) {
|
|
|
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
if (disguise.getEntity() != player && disguise.canSee(player)) {
|
|
|
|
clear.invoke(entityTrackerEntry, p);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-29 01:07:33 +01:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
updatePlayer.invoke(entityTrackerEntry, p);
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-11-29 01:07:33 +01:00
|
|
|
}
|
|
|
|
}, 2);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-29 01:07:33 +01:00
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static boolean removeDisguise(TargetedDisguise disguise) {
|
2016-05-11 23:47:08 +02:00
|
|
|
UUID entityId = disguise.getEntity().getUniqueId();
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
|
|
|
|
if (getDisguises().get(entityId).isEmpty()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
getDisguises().remove(entityId);
|
|
|
|
}
|
|
|
|
|
2018-01-09 06:13:03 +01:00
|
|
|
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS &&
|
|
|
|
disguise.isModifyBoundingBox()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
doBoundingBox(disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void removeGameProfile(String string) {
|
2017-05-28 00:23:15 +02:00
|
|
|
cachedNames.remove(string.toLowerCase());
|
|
|
|
|
2017-06-09 16:29:28 +02:00
|
|
|
if (!profileCache.exists())
|
|
|
|
profileCache.mkdirs();
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
File file = new File(profileCache, string.toLowerCase());
|
|
|
|
|
|
|
|
file.delete();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void removeSelfDisguise(Player player) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (!selfDisguised.contains(player.getUniqueId())) {
|
2016-06-07 04:42:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
// Send a packet to destroy the fake entity
|
|
|
|
PacketContainer packet = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-06-07 04:42:38 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
removeSelfDisguiseScoreboard(player);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
// player.spigot().setCollidesWithEntities(true);
|
|
|
|
// Finish up
|
|
|
|
// Remove the fake entity ID from the disguise bin
|
|
|
|
selfDisguised.remove(player.getUniqueId());
|
|
|
|
// Get the entity tracker
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-06-07 04:42:38 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (entityTrackerEntry != null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
// If the tracker exists. Remove himself from his tracker
|
2019-11-10 11:08:55 +01:00
|
|
|
if (!runningPaper) {
|
2019-11-10 10:44:02 +01:00
|
|
|
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
|
|
|
|
2019-08-13 10:32:13 +02:00
|
|
|
((Set<Object>) trackedPlayersObj).remove(ReflectionManager.getNmsEntity(player));
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2017-06-19 19:06:35 +02:00
|
|
|
((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap")
|
|
|
|
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
// Resend entity metadata else he will be invisible to himself until its resent
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2017-06-19 19:06:35 +02:00
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, ProtocolLibrary.getProtocolManager()
|
|
|
|
.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(),
|
|
|
|
WrappedDataWatcher.getEntityWatcher(player), true)
|
|
|
|
.createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true));
|
2016-06-07 04:42:38 +02:00
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2016-06-07 04:42:38 +02:00
|
|
|
|
|
|
|
player.updateInventory();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
public static void removeSelfDisguiseScoreboard(Player player) {
|
|
|
|
String originalTeam = preDisguiseTeam.remove(player.getUniqueId());
|
|
|
|
String teamDisguise = disguiseTeam.remove(player.getUniqueId());
|
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (teamDisguise == null || DisguiseConfig.getPushingOption() == DisguisePushing.IGNORE_SCOREBOARD) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
// Code replace them back onto their original scoreboard team
|
|
|
|
Scoreboard scoreboard = player.getScoreboard();
|
|
|
|
Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam);
|
|
|
|
Team ldTeam = null;
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
for (Team t : scoreboard.getTeams()) {
|
|
|
|
if (!t.hasEntry(player.getName()))
|
|
|
|
continue;
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
ldTeam = t;
|
|
|
|
break;
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (DisguiseConfig.isWarnScoreboardConflict()) {
|
|
|
|
if (ldTeam == null || !ldTeam.getName().equals(teamDisguise)) {
|
|
|
|
getLogger().warning("Scoreboard conflict, the self disguise player was not on the expected team!");
|
|
|
|
} else {
|
|
|
|
OptionStatus collisions = ldTeam.getOption(Option.COLLISION_RULE);
|
|
|
|
|
|
|
|
if (collisions != OptionStatus.NEVER && collisions != OptionStatus.FOR_OTHER_TEAMS) {
|
|
|
|
getLogger().warning(
|
|
|
|
"Scoreboard conflict, the collisions for a self disguise player team has been " +
|
|
|
|
"unexpectedly modifed!");
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-23 01:27:12 +01:00
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (ldTeam != null) {
|
|
|
|
if (!ldTeam.getName().equals("LD_Pushing") && !ldTeam.getName().endsWith("_LDP")) {
|
|
|
|
// Its not a team assigned by Lib's Disguises
|
|
|
|
ldTeam = null;
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
2018-11-23 01:27:12 +01:00
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (team != null) {
|
|
|
|
team.addEntry(player.getName());
|
|
|
|
} else if (ldTeam != null) {
|
|
|
|
ldTeam.removeEntry(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ldTeam != null && ldTeam.getEntries().isEmpty()) {
|
|
|
|
ldTeam.unregister();
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setupSelfDisguiseScoreboard(Player player) {
|
2018-11-23 01:27:12 +01:00
|
|
|
// They're already in a disguise team
|
|
|
|
if (disguiseTeam.containsKey(player.getUniqueId())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-28 01:10:52 +01:00
|
|
|
if ((LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() &&
|
|
|
|
!LibsPremium.getPluginInformation().isLegit()) ||
|
|
|
|
(LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isLegit() &&
|
|
|
|
!LibsPremium.getPaidInformation().isLegit())) {
|
2019-07-25 05:06:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
DisguisePushing pOption = DisguiseConfig.getPushingOption();
|
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (pOption == DisguisePushing.IGNORE_SCOREBOARD) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Code to stop player pushing
|
|
|
|
Scoreboard scoreboard = player.getScoreboard();
|
|
|
|
Team prevTeam = null;
|
|
|
|
Team ldTeam = null;
|
|
|
|
String ldTeamName = "LD_Pushing";
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
for (Team t : scoreboard.getTeams()) {
|
|
|
|
if (!t.hasEntry(player.getName()))
|
|
|
|
continue;
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
prevTeam = t;
|
|
|
|
break;
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
// If the player is in a team already and the team isn't one controlled by Lib's Disguises
|
|
|
|
if (prevTeam != null && !(prevTeam.getName().equals("LD_Pushing") || prevTeam.getName().endsWith("_LDP"))) {
|
|
|
|
// If we're creating a scoreboard
|
|
|
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
|
|
|
// Remember his old team so we can give him it back later
|
|
|
|
preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName());
|
2018-08-24 00:01:01 +02:00
|
|
|
} else {
|
2018-11-23 01:27:12 +01:00
|
|
|
// We're modifying the scoreboard
|
|
|
|
ldTeam = prevTeam;
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
2018-11-23 01:27:12 +01:00
|
|
|
} else {
|
|
|
|
prevTeam = null;
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
// If we are creating a new scoreboard because the current one must not be modified
|
|
|
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
|
|
|
// If they have a team, we'll reuse that name. Otherwise go for another name
|
2019-02-03 01:47:05 +01:00
|
|
|
ldTeamName = (prevTeam == null ? "NoTeam" : prevTeam.getName());
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
// Give the teamname a custom name
|
|
|
|
ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP";
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (ldTeam == null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) {
|
|
|
|
ldTeam = scoreboard.registerNewTeam(ldTeamName);
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
disguiseTeam.put(player.getUniqueId(), ldTeam.getName());
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (!ldTeam.hasEntry(player.getName()))
|
|
|
|
ldTeam.addEntry(player.getName());
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
|
|
|
|
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
|
|
|
|
ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles());
|
|
|
|
ldTeam.setDisplayName(prevTeam.getDisplayName());
|
|
|
|
ldTeam.setPrefix(prevTeam.getPrefix());
|
|
|
|
ldTeam.setSuffix(prevTeam.getSuffix());
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
for (Option option : Team.Option.values()) {
|
|
|
|
ldTeam.setOption(option, prevTeam.getOption(option));
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
2018-11-23 01:27:12 +01:00
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER && DisguiseConfig.isModifyCollisions()) {
|
|
|
|
ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
if (ldTeam.canSeeFriendlyInvisibles() && DisguiseConfig.isDisableFriendlyInvisibles()) {
|
|
|
|
ldTeam.setCanSeeFriendlyInvisibles(false);
|
2018-08-24 00:01:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 15:03:00 +02:00
|
|
|
/**
|
|
|
|
* Splits a string while respecting quotes.
|
|
|
|
* <p>
|
|
|
|
* Re
|
|
|
|
*/
|
|
|
|
/*public static String[] split(String string) {
|
|
|
|
Matcher matcher = Pattern.compile("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\"(?=\\s|$))|\\S+").matcher(string);
|
|
|
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
String match = matcher.group();
|
|
|
|
|
|
|
|
// If the match was quoted, then remove quotes and escapes
|
|
|
|
if (match.matches("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\")")) {
|
|
|
|
// Replace the match by removing first and last quote
|
|
|
|
// Then remove escaped slashes from the trailing with regex
|
|
|
|
match = match.substring(1, match.length() - 1).replaceAll("\\\\\\\\(?=(\\\\\\\\)*$)", "\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
list.add(matcher.group());
|
|
|
|
}
|
|
|
|
|
|
|
|
return list.toArray(new String[0]);
|
|
|
|
}*/
|
2020-01-02 05:10:36 +01:00
|
|
|
public static String quote(String string) {
|
|
|
|
if (!string.contains(" ") && !string.startsWith("\"") && !string.endsWith("\"")) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "\"" + string.replaceAll("\\B\"", "\\\"").replaceAll("\\\\(?=\\\\*\"\\B)", "\\\\")
|
|
|
|
.replaceAll("(?=\"\\B)", "\\") + "\"";
|
|
|
|
}
|
|
|
|
|
2018-10-25 15:03:00 +02:00
|
|
|
public static String[] split(String string) {
|
|
|
|
// Regex where we first match any character that isn't a slash, if it is a slash then it must not have more
|
|
|
|
// slashes until it hits the quote
|
|
|
|
// If any slashes before the quote, they must be escaped. That is, two of them.
|
|
|
|
// Must end with a quote
|
|
|
|
Pattern endsWithQuote = Pattern.compile("^([^\\\\]|\\\\(?!\\\\*\"$))*(\\\\\\\\)*\"$");
|
|
|
|
// Matches \"message quote, and
|
|
|
|
Pattern removeSlashes = Pattern.compile("^\\\\(\")|\\\\(?:(\\\\)(?=\\\\*\"$)|(\")$)");
|
|
|
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
String[] split = string.split(" ");
|
|
|
|
String[] unescapedSplit = new String[split.length];
|
|
|
|
|
|
|
|
loop:
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
// If the word starts with a quote
|
|
|
|
if (split[i].startsWith("\"")) {
|
|
|
|
// Look for a word with an ending quote
|
|
|
|
for (int a = i; a < split.length; a++) {
|
|
|
|
// If it's the same word, but only one possible quote
|
|
|
|
if (a == i && split[i].length() == 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does not end with a valid quote
|
|
|
|
if (!endsWithQuote.matcher(split[a]).matches()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found a sentence, build it
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
for (int b = i; b <= a; b++) {
|
|
|
|
Matcher matcher = removeSlashes.matcher(split[b]);
|
|
|
|
|
|
|
|
// Remove any escapes for escaped quotes
|
|
|
|
String word = matcher.replaceAll("$1$2$3");
|
|
|
|
|
|
|
|
// If this is the beginning or end of a quote
|
|
|
|
if (b == i || b == a) {
|
|
|
|
// Remove the quote
|
|
|
|
word = word.substring(b == i ? 1 : 0, word.length() - (b == a ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b > i) {
|
|
|
|
builder.append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.append(word);
|
|
|
|
}
|
|
|
|
|
|
|
|
list.add(builder.toString());
|
|
|
|
i = a;
|
|
|
|
continue loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove escapes if there, and add as a single word
|
|
|
|
Matcher matcher = removeSlashes.matcher(split[i]);
|
|
|
|
|
|
|
|
String word = matcher.replaceAll("$1$2$3");
|
|
|
|
|
|
|
|
list.add(word);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list.toArray(new String[0]);
|
|
|
|
}
|
|
|
|
|
2016-05-11 23:47:08 +02:00
|
|
|
/**
|
|
|
|
* Sends the self disguise to the player
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
|
2016-06-05 15:31:34 +02:00
|
|
|
if (mainThread != Thread.currentThread())
|
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2018-01-09 06:13:03 +01:00
|
|
|
if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() ||
|
|
|
|
!disguise.isSelfDisguiseVisible() || !disguise.canSee(player)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (entityTrackerEntry == null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
// 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..
|
|
|
|
// At least until this disguise is discarded
|
2018-08-24 00:01:01 +02:00
|
|
|
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
if (DisguiseAPI.getDisguise(player, player) == disguise) {
|
|
|
|
sendSelfDisguise(player, disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
setupSelfDisguiseScoreboard(player);
|
2016-06-12 20:24:14 +02:00
|
|
|
|
2016-05-11 23:47:08 +02:00
|
|
|
// Check for code differences in PaperSpigot vs Spigot
|
2019-11-10 11:08:55 +01:00
|
|
|
if (!runningPaper) {
|
2019-11-10 10:44:02 +01:00
|
|
|
// Add himself to his own entity tracker
|
|
|
|
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
|
|
|
|
.get(entityTrackerEntry);
|
|
|
|
|
2019-08-13 10:32:13 +02:00
|
|
|
((Set<Object>) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player));
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2019-11-12 23:07:53 +01:00
|
|
|
Field field = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap");
|
|
|
|
Object nmsEntity = ReflectionManager.getNmsEntity(player);
|
|
|
|
Map<Object, Object> map = ((Map<Object, Object>) field.get(entityTrackerEntry));
|
|
|
|
map.put(nmsEntity, true);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
|
|
|
// Send the player a packet with himself being spawned
|
|
|
|
manager.sendServerPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.NAMED_ENTITY_SPAWN, player).createPacket(player));
|
|
|
|
|
|
|
|
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
|
|
|
|
|
|
|
|
sendSelfPacket(player,
|
2017-06-19 19:06:35 +02:00
|
|
|
manager.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true)
|
|
|
|
.createPacket(player.getEntityId(), dataWatcher, true));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
boolean isMoving = false;
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2019-05-18 08:54:51 +02:00
|
|
|
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("q");
|
2016-05-11 23:47:08 +02:00
|
|
|
field.setAccessible(true);
|
|
|
|
isMoving = field.getBoolean(entityTrackerEntry);
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send the velocity packets
|
2016-11-28 22:47:48 +01:00
|
|
|
if (isMoving) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Vector velocity = player.getVelocity();
|
2018-01-09 06:13:03 +01:00
|
|
|
sendSelfPacket(player, manager
|
|
|
|
.createPacketConstructor(Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(),
|
2017-06-19 19:06:35 +02:00
|
|
|
velocity.getY(), velocity.getZ())
|
2018-01-09 06:13:03 +01:00
|
|
|
.createPacket(player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()));
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Why the hell would he even need this. Meh.
|
2016-11-28 22:47:48 +01:00
|
|
|
if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
|
2017-06-19 19:06:35 +02:00
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player, player.getVehicle())
|
|
|
|
.createPacket(0, player, player.getVehicle()));
|
2017-03-15 17:22:07 +01:00
|
|
|
} else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) {
|
2017-06-19 19:06:35 +02:00
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
|
|
|
|
.createPacket(0, player.getPassenger(), player));
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2019-11-18 04:57:00 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
2017-03-15 17:22:07 +01:00
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getHelmet())));
|
2017-03-15 17:22:07 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.CHEST),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getChestplate())));
|
2017-03-15 17:22:07 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.LEGS),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getLeggings())));
|
2017-03-15 17:22:07 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.FEET),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getBoots())));
|
2017-03-15 17:22:07 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HAND),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getItemInMainHand())));
|
2017-03-15 17:22:07 +01:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
|
|
|
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
2017-06-19 19:06:35 +02:00
|
|
|
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND),
|
2019-11-18 04:57:00 +01:00
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand())));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
|
|
|
|
// If the disguised is sleeping for w/e reason
|
2016-11-28 22:47:48 +01:00
|
|
|
if (player.isSleeping()) {
|
2019-05-18 08:54:51 +02:00
|
|
|
/* sendSelfPacket(player,
|
2017-06-19 19:06:35 +02:00
|
|
|
manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0))
|
|
|
|
.createPacket(player, ReflectionManager
|
2019-05-18 08:54:51 +02:00
|
|
|
.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));*/
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resend any active potion effects
|
2016-11-28 22:47:48 +01:00
|
|
|
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Object mobEffect = ReflectionManager.createMobEffect(potionEffect);
|
2017-06-19 19:06:35 +02:00
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), mobEffect)
|
|
|
|
.createPacket(player.getEntityId(), mobEffect));
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (Exception ex) {
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 06:13:03 +01:00
|
|
|
public static String getPlayerListName(Player player) {
|
|
|
|
return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName();
|
|
|
|
}
|
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
public static Logger getLogger() {
|
2018-08-24 00:01:01 +02:00
|
|
|
return LibsDisguises.getInstance().getLogger();
|
2018-08-14 02:42:35 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 23:47:08 +02:00
|
|
|
/**
|
|
|
|
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
private static void sendSelfPacket(final Player player, final PacketContainer packet) {
|
2016-10-04 15:11:50 +02:00
|
|
|
final Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
// If disguised.
|
2016-11-28 22:47:48 +01:00
|
|
|
if (disguise == null) {
|
2016-10-04 15:11:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
LibsPackets transformed = PacketsManager.getPacketsHandler().transformPacket(packet, disguise, player, player);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-10-04 15:11:50 +02:00
|
|
|
if (transformed.isUnhandled())
|
|
|
|
transformed.addPacket(packet);
|
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
transformed.setSpawnPacketCheck(packet.getType());
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
for (PacketContainer p : transformed.getPackets()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
p = p.deepClone();
|
|
|
|
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
|
|
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:11:50 +02:00
|
|
|
transformed.sendDelayed(player);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2016-11-28 22:47:48 +01:00
|
|
|
catch (InvocationTargetException e) {
|
2016-06-18 17:16:32 +02:00
|
|
|
e.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup it so he can see himself when disguised
|
|
|
|
*
|
|
|
|
* @param disguise
|
|
|
|
*/
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void setupFakeDisguise(final Disguise disguise) {
|
2016-05-11 23:47:08 +02:00
|
|
|
Entity e = disguise.getEntity();
|
|
|
|
|
2018-11-23 01:27:12 +01:00
|
|
|
// If the disguises entity is null, or the disguised entity isn't a player; return
|
2018-08-24 00:01:01 +02:00
|
|
|
if (!(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) ||
|
2018-01-09 06:13:03 +01:00
|
|
|
!getDisguises().get(e.getUniqueId()).contains(disguise)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) e;
|
|
|
|
|
|
|
|
// Check if he can even see this..
|
2016-11-28 22:47:48 +01:00
|
|
|
if (!((TargetedDisguise) disguise).canSee(player)) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the old disguise, else we have weird disguises around the place
|
|
|
|
DisguiseUtilities.removeSelfDisguise(player);
|
|
|
|
|
|
|
|
// If the disguised player can't see himself. Return
|
2018-01-09 06:13:03 +01:00
|
|
|
if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() ||
|
|
|
|
player.getVehicle() != null) {
|
2016-05-11 23:47:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish up
|
|
|
|
selfDisguised.add(player.getUniqueId());
|
|
|
|
|
|
|
|
sendSelfDisguise(player, (TargetedDisguise) disguise);
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
|
|
|
|
if (PacketsManager.isInventoryListenerEnabled()) {
|
2016-05-11 23:47:08 +02:00
|
|
|
player.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-07-09 10:52:00 +02:00
|
|
|
public static WrappedDataWatcher.Serializer getSerializer(MetaIndex index) {
|
|
|
|
if (index.getSerializer() != null) {
|
|
|
|
return index.getSerializer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index.getDefault() instanceof Optional) {
|
|
|
|
for (Field f : MetaIndex.class.getFields()) {
|
|
|
|
try {
|
|
|
|
if (f.get(null) != index) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
Type type = f.getGenericType();
|
|
|
|
Type opt = ((ParameterizedType) type).getActualTypeArguments()[0];
|
|
|
|
|
|
|
|
if (opt instanceof ParameterizedType) {
|
|
|
|
Type val = ((ParameterizedType) opt).getActualTypeArguments()[0];
|
|
|
|
|
|
|
|
return WrappedDataWatcher.Registry.get(ReflectionManager.getNmsClass((Class) val), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return WrappedDataWatcher.Registry.get(ReflectionManager.getNmsClass(index.getDefault().getClass()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Object value = index.getDefault();
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Unable to find Serializer for " + value +
|
|
|
|
(value instanceof Optional && ((Optional) value).isPresent() ?
|
|
|
|
" (" + ((Optional) value).get().getClass().getName() + ")" :
|
|
|
|
value instanceof Optional || value == null ? "" : " " + value.getClass().getName()) +
|
|
|
|
"! Are you running " + "the latest " + "version of " + "ProtocolLib?");
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
/**
|
|
|
|
* Create a new datawatcher but with the 'correct' values
|
|
|
|
*/
|
|
|
|
public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher,
|
|
|
|
FlagWatcher disguiseWatcher) {
|
|
|
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
|
|
|
|
|
|
|
try {
|
|
|
|
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ?
|
|
|
|
disguiseWatcher.convert(entityWatcher.getWatchableObjects()) :
|
|
|
|
disguiseWatcher.getWatchableObjects();
|
|
|
|
|
|
|
|
for (WrappedWatchableObject watchableObject : list) {
|
|
|
|
if (watchableObject == null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (watchableObject.getValue() == null)
|
|
|
|
continue;
|
|
|
|
|
2019-09-16 04:30:16 +02:00
|
|
|
MetaIndex metaIndex = MetaIndex.getMetaIndex(disguiseWatcher, watchableObject.getIndex());
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager
|
2019-09-16 04:30:16 +02:00
|
|
|
.createDataWatcherObject(metaIndex, watchableObject.getValue());
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
newWatcher.setObject(obj, watchableObject.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return newWatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getPitch(DisguiseType disguiseType, EntityType entityType, byte value) {
|
|
|
|
return getPitch(disguiseType, getPitch(DisguiseType.getType(entityType), value));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getPitch(DisguiseType disguiseType, DisguiseType entityType, byte value) {
|
|
|
|
return getPitch(disguiseType, getPitch(entityType, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getPitch(DisguiseType disguiseType, byte value) {
|
|
|
|
if (disguiseType.isMisc()) {
|
|
|
|
return (byte) -value;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (disguiseType) {
|
|
|
|
case PHANTOM:
|
|
|
|
return (byte) -value;
|
|
|
|
default:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) {
|
|
|
|
return getYaw(disguiseType, getYaw(DisguiseType.getType(entityType), value));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getYaw(DisguiseType disguiseType, DisguiseType entityType, byte value) {
|
|
|
|
return getYaw(disguiseType, getYaw(entityType, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the yaw for the disguises
|
|
|
|
*/
|
|
|
|
public static byte getYaw(DisguiseType disguiseType, byte value) {
|
|
|
|
switch (disguiseType) {
|
|
|
|
case MINECART:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
return (byte) (value + 64);
|
|
|
|
case BOAT:
|
|
|
|
case ENDER_DRAGON:
|
|
|
|
case WITHER_SKULL:
|
|
|
|
return (byte) (value - 128);
|
|
|
|
case ARROW:
|
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
return (byte) -value;
|
|
|
|
case PAINTING:
|
|
|
|
case ITEM_FRAME:
|
|
|
|
return (byte) -(value + 128);
|
|
|
|
default:
|
|
|
|
if (disguiseType.isMisc() && disguiseType != DisguiseType.ARMOR_STAND) {
|
|
|
|
return (byte) (value - 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
2019-06-22 12:06:59 +02:00
|
|
|
|
|
|
|
public static Disguise getDisguise(Player observer, int entityId) {
|
|
|
|
// If the entity ID is the same as self disguises id, then it needs to be set to the observers id
|
|
|
|
if (entityId == DisguiseAPI.getSelfDisguiseId()) {
|
|
|
|
entityId = observer.getEntityId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getFutureDisguises().containsKey(entityId)) {
|
|
|
|
HashSet<TargetedDisguise> hashSet = getFutureDisguises().get(entityId);
|
|
|
|
|
|
|
|
for (TargetedDisguise dis : hashSet) {
|
|
|
|
if (!dis.canSee(observer) || !dis.isDisguiseInUse()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 00:29:03 +02:00
|
|
|
for (Set<TargetedDisguise> disguises : getDisguises().values()) {
|
2019-06-22 12:06:59 +02:00
|
|
|
for (TargetedDisguise dis : disguises) {
|
|
|
|
if (dis.getEntity() == null || !dis.isDisguiseInUse()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dis.getEntity().getEntityId() != entityId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dis.canSee(observer)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-06-01 02:13:36 +02:00
|
|
|
public static Entity getEntity(World world, int entityId) {
|
|
|
|
for (Entity e : world.getEntities()) {
|
|
|
|
if (e.getEntityId() != entityId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
/**
|
|
|
|
* Get the Y level to add to the disguise for realism.
|
|
|
|
*/
|
|
|
|
public static double getYModifier(Entity entity, Disguise disguise) {
|
|
|
|
double yMod = 0;
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
if (disguise.getType() != DisguiseType.PLAYER && entity.getType() == EntityType.DROPPED_ITEM) {
|
2019-01-03 03:13:03 +01:00
|
|
|
yMod -= 0.13;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (disguise.getType()) {
|
|
|
|
case BAT:
|
|
|
|
if (entity instanceof LivingEntity)
|
|
|
|
return yMod + ((LivingEntity) entity).getEyeHeight();
|
|
|
|
case MINECART:
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
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;
|
|
|
|
}
|
2019-05-18 08:54:51 +02:00
|
|
|
case ARROW:
|
2019-01-03 03:13:03 +01:00
|
|
|
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 DROPPED_ITEM:
|
|
|
|
return yMod + 0.13;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return yMod;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|