2016-05-11 23:47:08 +02:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
import com.comphenix.protocol.PacketType;
|
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.*;
|
2020-02-19 00:57:39 +01:00
|
|
|
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
|
|
|
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
|
|
|
import com.comphenix.protocol.wrappers.nbt.NbtList;
|
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;
|
2017-06-02 15:51:03 +02:00
|
|
|
import com.mojang.authlib.properties.PropertyMap;
|
2020-06-25 05:33:28 +02:00
|
|
|
import com.mojang.datafixers.util.Pair;
|
2020-02-01 23:59:18 +01:00
|
|
|
import lombok.Getter;
|
2020-03-30 09:22:33 +02:00
|
|
|
import lombok.Setter;
|
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;
|
2020-05-09 11:57:07 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.ArmorStandWatcher;
|
2016-05-11 23:47:08 +02:00
|
|
|
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;
|
2020-03-08 21:00:58 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
2020-05-08 06:35:25 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.watchers.CompileMethods;
|
2020-06-30 06:06:27 +02:00
|
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
2020-07-03 07:08:58 +02:00
|
|
|
import net.md_5.bungee.api.chat.ClickEvent;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
|
|
import net.md_5.bungee.chat.ComponentSerializer;
|
2020-02-19 00:57:39 +01:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2020-04-06 16:23:55 +02:00
|
|
|
import org.apache.commons.lang.math.RandomUtils;
|
2018-01-09 06:13:03 +01:00
|
|
|
import org.apache.logging.log4j.util.Strings;
|
2020-01-20 01:35:55 +01:00
|
|
|
import org.bukkit.*;
|
2020-08-11 23:36:13 +02:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2020-04-06 03:21:16 +02:00
|
|
|
import org.bukkit.boss.KeyedBossBar;
|
2020-06-27 11:01:58 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
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;
|
2020-07-04 08:01:30 +02:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2020-04-06 16:23:55 +02:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2017-05-28 00:23:15 +02:00
|
|
|
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;
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.io.*;
|
2018-08-05 10:34:02 +02:00
|
|
|
import java.lang.reflect.*;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2020-07-03 07:08:58 +02:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
2017-05-28 00:23:15 +02:00
|
|
|
import java.util.*;
|
2020-07-03 07:08:58 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
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;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.util.stream.Collectors;
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public class DisguiseUtilities {
|
2020-03-30 09:22:33 +02:00
|
|
|
@Setter
|
2020-04-04 08:58:21 +02:00
|
|
|
public static class DScoreTeam {
|
|
|
|
public DScoreTeam(String[] name) {
|
2020-03-30 09:22:33 +02:00
|
|
|
this.split = name;
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
@Getter
|
2020-01-22 06:46:57 +01:00
|
|
|
private String teamName;
|
2020-03-30 09:22:33 +02:00
|
|
|
private String[] split;
|
|
|
|
private PlayerDisguise disguise;
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public String getPlayer() {
|
|
|
|
return split[1];
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public String getPrefix() {
|
|
|
|
return split[0];
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public String getSuffix() {
|
|
|
|
return split[2];
|
|
|
|
}
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public void handleTeam(Scoreboard board, boolean nameVisible) {
|
2020-05-07 11:27:07 +02:00
|
|
|
nameVisible = !DisguiseConfig.isArmorstandsName() && nameVisible;
|
2020-03-30 09:22:33 +02:00
|
|
|
Team team = board.getTeam(getTeamName());
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (team == null) {
|
|
|
|
team = board.registerNewTeam(getTeamName());
|
|
|
|
team.addEntry(getPlayer());
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (!nameVisible) {
|
|
|
|
team.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
|
|
|
|
}
|
|
|
|
} else if (team.getOption(Option.NAME_TAG_VISIBILITY) !=
|
|
|
|
(nameVisible ? OptionStatus.ALWAYS : OptionStatus.NEVER)) {
|
|
|
|
team.setOption(Option.NAME_TAG_VISIBILITY, nameVisible ? OptionStatus.ALWAYS : OptionStatus.NEVER);
|
|
|
|
}
|
|
|
|
|
2020-07-05 00:38:44 +02:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
team.setPrefix("Colorize");
|
|
|
|
team.setSuffix("Colorize");
|
|
|
|
} else {
|
|
|
|
team.setPrefix(getPrefix());
|
|
|
|
team.setSuffix(getSuffix());
|
|
|
|
}
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2016-05-11 23:47:08 +02:00
|
|
|
public static final Random random = new Random();
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
|
2020-06-26 04:24:48 +02:00
|
|
|
private static final List<Integer> isNoInteract = new ArrayList<>();
|
2016-05-11 23:47:08 +02:00
|
|
|
/**
|
|
|
|
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
|
|
|
|
*/
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2020-08-12 09:28:41 +02:00
|
|
|
private static final Map<Integer, Set<TargetedDisguise>> disguises = new HashMap<>();
|
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.
|
|
|
|
*/
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>();
|
|
|
|
private static final HashSet<UUID> savedDisguiseList = new HashSet<>();
|
|
|
|
private static final HashSet<String> cachedNames = new HashSet<>();
|
2020-01-02 05:10:36 +01:00
|
|
|
private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final HashSet<UUID> selfDisguised = new HashSet<>();
|
|
|
|
private static final HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
|
|
|
|
private static final HashMap<UUID, String> disguiseTeam = new HashMap<>();
|
|
|
|
private static final File profileCache = new File("plugins/LibsDisguises/GameProfiles");
|
|
|
|
private static final File savedDisguises = new File("plugins/LibsDisguises/SavedDisguises");
|
2020-02-02 02:11:36 +01:00
|
|
|
@Getter
|
2017-06-02 15:51:03 +02:00
|
|
|
private static Gson gson;
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2020-01-06 04:01:05 +01:00
|
|
|
private static boolean pluginsUsed, commandsUsed, copyDisguiseCommandUsed, grabSkinCommandUsed,
|
2020-06-19 23:26:48 +02:00
|
|
|
saveDisguiseCommandUsed, grabHeadCommandUsed;
|
2017-06-22 18:14:19 +02:00
|
|
|
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;
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>();
|
2020-05-20 02:45:17 +02:00
|
|
|
@Getter
|
2019-11-10 10:45:46 +01:00
|
|
|
private static boolean runningPaper;
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final MineSkinAPI mineSkinAPI = new MineSkinAPI();
|
2020-02-20 06:13:43 +01:00
|
|
|
@Getter
|
|
|
|
private static boolean invalidFile;
|
2020-03-30 09:22:33 +02:00
|
|
|
@Getter
|
2020-07-03 07:08:58 +02:00
|
|
|
private static final char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
|
|
|
|
private static final Pattern urlMatcher = Pattern.compile("^(?:(https?)://)?([-\\w_.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
|
|
|
|
private final static List<UUID> viewSelf = new ArrayList<>();
|
|
|
|
private final static List<UUID> viewBar = new ArrayList<>();
|
|
|
|
private static long lastSavedPreferences;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only allow saves every 2 minutes
|
|
|
|
*/
|
|
|
|
public static void addSaveAttempt() {
|
|
|
|
if (lastSavedPreferences + TimeUnit.SECONDS.toMillis(120) > System.currentTimeMillis()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastSavedPreferences = System.currentTimeMillis();
|
|
|
|
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
saveViewPreferances();
|
|
|
|
}
|
|
|
|
}.runTaskLater(LibsDisguises.getInstance(), 20 * TimeUnit.SECONDS.toMillis(120));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list of people who have /disguiseViewSelf toggled
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static List<UUID> getViewSelf() {
|
|
|
|
return viewSelf;
|
|
|
|
}
|
|
|
|
|
2020-08-10 22:28:43 +02:00
|
|
|
public static String getDisplayName(CommandSender player) {
|
2020-08-11 02:21:09 +02:00
|
|
|
if (player == null) {
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
|
2020-08-10 23:04:43 +02:00
|
|
|
if (!(player instanceof Player)) {
|
|
|
|
return player.getName();
|
|
|
|
}
|
|
|
|
|
2020-08-10 22:28:43 +02:00
|
|
|
Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName());
|
|
|
|
|
|
|
|
if (team == null) {
|
|
|
|
team = ((Player) player).getScoreboard().getEntryTeam(((Player) player).getUniqueId().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (team == null || (StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) {
|
|
|
|
String name = ((Player) player).getDisplayName();
|
|
|
|
|
|
|
|
if (name.equals(player.getName())) {
|
|
|
|
return ((Player) player).getPlayerListName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return team.getPrefix() + team.getColor() + player.getName() + team.getSuffix();
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
public static void saveViewPreferances() {
|
|
|
|
if (!DisguiseConfig.isSaveUserPreferences()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
|
|
|
|
|
|
|
|
HashMap<String, List<UUID>> map = new HashMap<>();
|
|
|
|
map.put("selfdisguise", getViewSelf());
|
|
|
|
map.put("notifybar", getViewBar());
|
|
|
|
|
|
|
|
String json = getGson().toJson(map);
|
|
|
|
|
|
|
|
try {
|
2020-07-04 04:29:04 +02:00
|
|
|
viewPreferences.delete();
|
2020-07-03 07:08:58 +02:00
|
|
|
Files.write(viewPreferences.toPath(), json.getBytes(), StandardOpenOption.CREATE);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (IOException e) {
|
2020-07-03 07:08:58 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void loadViewPreferences() {
|
|
|
|
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
|
|
|
|
|
|
|
|
if (!viewPreferences.exists()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap<String, Collection<String>> map;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String disguiseText = new String(Files.readAllBytes(viewPreferences.toPath()));
|
|
|
|
map = getGson().fromJson(disguiseText, HashMap.class);
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (map == null) {
|
|
|
|
viewPreferences.delete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (map.containsKey("selfdisguise")) {
|
|
|
|
getViewSelf().clear();
|
|
|
|
map.get("selfdisguise").forEach(uuid -> getViewSelf().add(UUID.fromString(uuid)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map.containsKey("notifybar")) {
|
|
|
|
getViewBar().clear();
|
|
|
|
map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid)));
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (IOException e) {
|
2020-07-03 07:08:58 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list of people who have /disguiseviewbar toggled
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static List<UUID> getViewBar() {
|
|
|
|
return viewBar;
|
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
|
2019-01-16 07:58:53 +01:00
|
|
|
public static void setPlayerVelocity(Player player) {
|
2020-01-06 04:01:05 +01:00
|
|
|
if (player == null) {
|
|
|
|
velocityID = 0;
|
|
|
|
velocityTime = 0;
|
|
|
|
} else {
|
|
|
|
velocityID = player.getEntityId();
|
|
|
|
velocityTime = player.getWorld().getTime();
|
|
|
|
}
|
2019-01-16 07:58:53 +01:00
|
|
|
}
|
|
|
|
|
2020-06-30 06:06:27 +02:00
|
|
|
public static String getProtocolLibRequiredVersion() {
|
2020-07-23 07:56:54 +02:00
|
|
|
return !NmsVersion.v1_13.isSupported() ? "4.4.0" : NmsVersion.v1_16.isSupported() ? "4.6.0" : "4.5.1";
|
2020-06-30 06:06:27 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 07:58:53 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2020-01-03 19:46:02 +01:00
|
|
|
public static void setGrabSkinCommandUsed() {
|
|
|
|
grabSkinCommandUsed = true;
|
|
|
|
}
|
|
|
|
|
2020-06-19 23:26:48 +02:00
|
|
|
public static void setGrabHeadCommandUsed() {
|
|
|
|
grabHeadCommandUsed = true;
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:46:02 +01:00
|
|
|
public static void setCopyDisguiseCommandUsed() {
|
|
|
|
copyDisguiseCommandUsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSaveDisguiseCommandUsed() {
|
|
|
|
saveDisguiseCommandUsed = true;
|
|
|
|
}
|
|
|
|
|
2020-06-26 04:24:48 +02:00
|
|
|
public static boolean isNotInteractable(int entityId) {
|
|
|
|
synchronized (isNoInteract) {
|
|
|
|
return isNoInteract.contains(entityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:46:02 +01:00
|
|
|
public static boolean isGrabSkinCommandUsed() {
|
|
|
|
return grabSkinCommandUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isCopyDisguiseCommandUsed() {
|
|
|
|
return copyDisguiseCommandUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSaveDisguiseCommandUsed() {
|
|
|
|
return saveDisguiseCommandUsed;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
public static void saveDisguises() {
|
2020-07-03 07:08:58 +02:00
|
|
|
saveViewPreferances();
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!LibsPremium.isPremium()) {
|
2017-07-23 20:28:14 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-07-23 20:28:14 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!DisguiseConfig.isSaveEntityDisguises() && !DisguiseConfig.isSavePlayerDisguises()) {
|
2017-07-23 20:31:09 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-07-23 20:31:09 +02:00
|
|
|
|
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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (disg.getEntity() == null) {
|
2017-06-09 16:33:50 +02:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-04-21 00:57:47 +02:00
|
|
|
if (disg.getEntity() instanceof Player ? !DisguiseConfig.isSavePlayerDisguises() :
|
2020-08-18 00:07:46 +02:00
|
|
|
!DisguiseConfig.isSaveEntityDisguises()) {
|
2017-07-23 20:28:14 +02:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-07-23 20:28:14 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-07-03 14:44:22 +02:00
|
|
|
LibsMsg.MADE_REF.send(player, entityName, reference);
|
|
|
|
LibsMsg.MADE_REF_EXAMPLE.send(player, reference);
|
2017-03-15 17:22:07 +01:00
|
|
|
} else {
|
2020-07-03 14:44:22 +02:00
|
|
|
LibsMsg.REF_TOO_MANY.send(player);
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-28 00:23:15 +02:00
|
|
|
public static void saveDisguises(UUID owningEntity, Disguise[] disguise) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!LibsPremium.isPremium()) {
|
2017-06-02 15:51:03 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-02 15:51:03 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!savedDisguises.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
savedDisguises.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
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 {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-22 06:46:57 +01:00
|
|
|
// I hear pirates don't obey standards
|
2020-08-18 00:07:46 +02:00
|
|
|
@SuppressWarnings("MismatchedStringCase")
|
|
|
|
PrintWriter writer =
|
|
|
|
new PrintWriter(disguiseFile, "12345".equals("%%__USER__%%") ? "US-ASCII" : "UTF-8");
|
2017-06-02 15:51:03 +02:00
|
|
|
writer.write(gson.toJson(disguises));
|
|
|
|
writer.close();
|
2017-05-28 00:23:15 +02:00
|
|
|
|
|
|
|
savedDisguiseList.add(owningEntity);
|
|
|
|
}
|
2020-08-18 00:07:46 +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 {
|
2020-07-03 07:08:58 +02:00
|
|
|
String cached;
|
2020-02-13 07:47:02 +01:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
try (FileInputStream input = new FileInputStream(disguiseFile);
|
|
|
|
InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8);
|
|
|
|
BufferedReader reader = new BufferedReader(inputReader)) {
|
2020-02-13 07:47:02 +01:00
|
|
|
cached = reader.lines().collect(Collectors.joining("\n"));
|
|
|
|
}
|
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;
|
2020-08-18 00:07:46 +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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!savedDisguiseList.remove(entityUUID)) {
|
2017-05-28 00:23:15 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!savedDisguises.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
savedDisguises.mkdirs();
|
2020-08-18 00:07:46 +02: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
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
public static void addDisguise(Integer entityId, TargetedDisguise disguise) {
|
|
|
|
if (!getDisguises().containsKey(entityId)) {
|
|
|
|
getDisguises().put(entityId, new HashSet<>());
|
2020-06-26 04:24:48 +02:00
|
|
|
|
|
|
|
synchronized (isNoInteract) {
|
|
|
|
Entity entity = disguise.getEntity();
|
|
|
|
|
|
|
|
switch (entity.getType()) {
|
|
|
|
case EXPERIENCE_ORB:
|
|
|
|
case DROPPED_ITEM:
|
|
|
|
case ARROW:
|
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
isNoInteract.add(entity.getEntityId());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2020-05-02 11:05:39 +02:00
|
|
|
if ("a%%__USER__%%a".equals("a12345a") || (LibsPremium.getUserID().matches("[0-9]+") &&
|
|
|
|
!("" + Integer.parseInt(LibsPremium.getUserID())).equals(LibsPremium.getUserID()))) {
|
2020-04-06 16:23:55 +02:00
|
|
|
if (Bukkit.getOnlinePlayers().stream().noneMatch(p -> p.isOp() || p.hasPermission("*"))) {
|
|
|
|
World world = Bukkit.getWorlds().get(0);
|
|
|
|
|
|
|
|
if (!world.getPlayers().isEmpty()) {
|
|
|
|
Player p = world.getPlayers().get(RandomUtils.nextInt(world.getPlayers().size()));
|
|
|
|
|
|
|
|
ItemStack stack = new ItemStack(Material.GOLD_INGOT);
|
|
|
|
ItemMeta meta = stack.getItemMeta();
|
|
|
|
meta.setDisplayName(ChatColor.GOLD + "Pirate's Treasure");
|
|
|
|
meta.setLore(Arrays.asList(ChatColor.GRAY + "Dis be pirate loot",
|
|
|
|
ChatColor.GRAY + "for a pirate server"));
|
|
|
|
stack.setItemMeta(meta);
|
|
|
|
|
|
|
|
Item item = p.getWorld().dropItemNaturally(p.getLocation(), stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
getDisguises().get(entityId).add(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 04:20:52 +02:00
|
|
|
public static void onFutureDisguise(Entity entity) {
|
|
|
|
if (!getFutureDisguises().containsKey(entity.getEntityId())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TargetedDisguise disguise : getFutureDisguises().remove(entity.getEntityId())) {
|
2020-08-12 09:28:41 +02:00
|
|
|
addDisguise(entity.getEntityId(), disguise);
|
2020-04-22 04:20:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) {
|
2020-04-22 04:20:52 +02:00
|
|
|
if (!getFutureDisguises().containsKey(entityId)) {
|
|
|
|
getFutureDisguises().put(entityId, new HashSet<>());
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 04:20:52 +02:00
|
|
|
getFutureDisguises().get(entityId).add(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
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() {
|
2020-04-22 04:20:52 +02:00
|
|
|
if (!getFutureDisguises().containsKey(entityId) ||
|
|
|
|
!getFutureDisguises().get(entityId).contains(disguise)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-04-22 04:20:52 +02:00
|
|
|
for (World world : Bukkit.getWorlds()) {
|
|
|
|
for (Entity entity : world.getEntities()) {
|
|
|
|
if (entity.getEntityId() != entityId) {
|
|
|
|
continue;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2020-04-22 04:20:52 +02:00
|
|
|
|
|
|
|
onFutureDisguise(entity);
|
|
|
|
return;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2020-04-22 04:20:52 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-04-22 04:20:52 +02:00
|
|
|
getFutureDisguises().get(entityId).remove(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-04-22 04:20:52 +02:00
|
|
|
if (getFutureDisguises().get(entityId).isEmpty()) {
|
|
|
|
getFutureDisguises().remove(entityId);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!profileCache.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
profileCache.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
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());
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (StackOverflowError | Exception e) {
|
2017-07-23 20:28:14 +02:00
|
|
|
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
|
2020-04-20 13:03:54 +02:00
|
|
|
if (!DisguiseAPI.isDisguiseInUse(disguise)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getEntityId()).iterator();
|
2020-04-20 13:03:54 +02:00
|
|
|
|
|
|
|
// Iterate through the disguises
|
|
|
|
while (disguiseItel.hasNext()) {
|
|
|
|
TargetedDisguise d = disguiseItel.next();
|
|
|
|
// Make sure the disguise isn't the same thing
|
|
|
|
if (d == disguise) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
// If player is a observer in the loop
|
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
// If player is a observer in the disguise
|
|
|
|
// Remove them from the loop
|
|
|
|
if (name != null) {
|
|
|
|
d.removePlayer(name);
|
|
|
|
} else {
|
|
|
|
for (String playername : disguise.getObservers()) {
|
|
|
|
d.silentlyRemovePlayer(playername);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2020-04-20 13:03:54 +02:00
|
|
|
}
|
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
// If player is not a observer in the loop
|
|
|
|
if (name != null) {
|
|
|
|
if (!disguise.getObservers().contains(name)) {
|
|
|
|
d.removePlayer(name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (String playername : new ArrayList<>(d.getObservers())) {
|
|
|
|
if (!disguise.getObservers().contains(playername)) {
|
|
|
|
d.silentlyRemovePlayer(playername);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-20 13:03:54 +02:00
|
|
|
} else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
// Here you add it to the loop if they see the disguise
|
|
|
|
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
// Everyone who is in the disguise needs to be added to the loop
|
|
|
|
if (name != null) {
|
|
|
|
d.addPlayer(name);
|
|
|
|
} else {
|
|
|
|
for (String playername : disguise.getObservers()) {
|
|
|
|
d.silentlyAddPlayer(playername);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
|
|
|
// 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();
|
|
|
|
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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
try {
|
2016-05-11 23:47:08 +02:00
|
|
|
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (entityTrackerEntry == null) {
|
2016-06-12 16:22:56 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-08-18 00:07:46 +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
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:07:46 +02: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) {
|
2020-08-12 09:28:41 +02:00
|
|
|
int entityId = entity.getEntityId();
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
if (futureDisguises.containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : futureDisguises.remove(entityId)) {
|
|
|
|
addDisguise(entity.getEntityId(), disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
if (getDisguises().containsKey(entityId)) {
|
|
|
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
2020-06-11 01:47:46 +02:00
|
|
|
if (!disguise.canSee(observer)) {
|
|
|
|
continue;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
2020-06-11 01:47:46 +02:00
|
|
|
|
|
|
|
return disguise;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
public static TargetedDisguise[] getDisguises(Integer entityId) {
|
2016-11-28 22:47:48 +01:00
|
|
|
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 WrappedGameProfile getGameProfile(String playerName) {
|
2020-06-22 09:32:41 +02:00
|
|
|
playerName = playerName.toLowerCase();
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!hasGameProfile(playerName)) {
|
2017-05-28 00:23:15 +02:00
|
|
|
return null;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!profileCache.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
profileCache.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
2020-06-22 09:32:41 +02:00
|
|
|
File file = new File(profileCache, playerName);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
if (!file.exists()) {
|
2020-06-22 09:32:41 +02:00
|
|
|
cachedNames.remove(playerName);
|
2017-05-28 00:23:15 +02:00
|
|
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (JsonSyntaxException ex) {
|
2019-12-31 07:35:21 +01:00
|
|
|
DisguiseUtilities.getLogger()
|
|
|
|
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
|
|
|
|
cachedNames.remove(playerName.toLowerCase());
|
|
|
|
file.delete();
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception e) {
|
2017-05-28 00:23:15 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
public static TargetedDisguise getMainDisguise(Integer 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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
2020-08-18 00:07:46 +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!");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:07:46 +02: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
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
return getProfileFromMojang(nameToFetch, gameProfile -> {
|
|
|
|
if (gameProfile == null || gameProfile.getProperties().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName()
|
|
|
|
.equals(disguise.getSkin() != null ? disguise.getSkin() : disguise.getName()) ||
|
|
|
|
!gameProfile.getProperties().isEmpty())) {
|
|
|
|
disguise.setGameProfile(gameProfile);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
DisguiseUtilities.refreshTrackers(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
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,
|
2020-08-18 00:07:46 +02: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,
|
2020-08-18 00:07:46 +02:00
|
|
|
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-07-03 07:08:58 +02:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(LibsDisguises.getInstance(), () -> {
|
|
|
|
try {
|
|
|
|
final WrappedGameProfile gameProfile = lookupGameProfile(origName);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), () -> {
|
|
|
|
if (DisguiseConfig.isSaveGameProfiles()) {
|
|
|
|
addGameProfile(playerName, gameProfile);
|
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
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-07-03 07:08:58 +02:00
|
|
|
});
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception e) {
|
2020-07-03 07:08:58 +02:00
|
|
|
synchronized (runnables) {
|
|
|
|
runnables.remove(playerName);
|
2020-01-02 05:10:36 +01:00
|
|
|
}
|
2020-07-03 07:08:58 +02: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,
|
2020-08-18 00:07:46 +02:00
|
|
|
boolean contactMojang) {
|
2016-06-14 11:08:53 +02:00
|
|
|
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
public static void init() {
|
2019-11-10 10:54:32 +01:00
|
|
|
try {
|
2020-04-21 04:42:25 +02:00
|
|
|
// Force an exception to be thrown if it doesn't contain trackedPlayerMap
|
|
|
|
Class tracker = ReflectionManager.getNmsClass("EntityTrackerEntry");
|
|
|
|
tracker.getDeclaredField("trackedPlayerMap");
|
|
|
|
|
|
|
|
// Don't really need this here, but it's insurance!
|
2019-11-10 10:54:32 +01:00
|
|
|
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ignored) {
|
2019-11-10 10:54:32 +01:00
|
|
|
}
|
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
|
|
|
|
2020-08-11 23:36:13 +02:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
gsonBuilder.registerTypeAdapter(BlockData.class, new SerializerBlockData());
|
|
|
|
}
|
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
gson = gsonBuilder.create();
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!profileCache.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
profileCache.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!savedDisguises.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
savedDisguises.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
cachedNames.addAll(Arrays.asList(profileCache.list()));
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
invalidFile =
|
|
|
|
LibsDisguises.getInstance().getFile().getName().toLowerCase().matches(".*((crack)|(null)|(leak)).*");
|
2020-02-20 06:13:43 +01:00
|
|
|
|
2017-06-02 15:51:03 +02:00
|
|
|
for (String key : savedDisguises.list()) {
|
2019-11-20 08:08:19 +01:00
|
|
|
try {
|
|
|
|
savedDisguiseList.add(UUID.fromString(key));
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2019-11-20 08:08:19 +01:00
|
|
|
getLogger().warning("The file '" + key + "' does not belong in " + savedDisguises.getAbsolutePath());
|
|
|
|
}
|
2017-05-28 00:23:15 +02:00
|
|
|
}
|
2020-01-19 03:48:52 +01:00
|
|
|
|
2020-01-20 01:35:55 +01:00
|
|
|
// Clear the old scoreboard teams for extended names!
|
|
|
|
for (Scoreboard board : getAllScoreboards()) {
|
|
|
|
for (Team team : board.getTeams()) {
|
2020-03-30 09:22:33 +02:00
|
|
|
if (!team.getName().startsWith("LD_")) {
|
2020-01-20 01:35:55 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-01-19 03:48:52 +01:00
|
|
|
|
2020-01-20 01:35:55 +01:00
|
|
|
team.unregister();
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
registerAllExtendedNames(board);
|
2020-01-20 01:35:55 +01:00
|
|
|
registerNoName(board);
|
2020-01-19 03:48:52 +01:00
|
|
|
}
|
2020-04-06 03:21:16 +02:00
|
|
|
|
2020-04-07 04:08:17 +02:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
Iterator<KeyedBossBar> bars = Bukkit.getBossBars();
|
|
|
|
ArrayList<KeyedBossBar> barList = new ArrayList<>();
|
|
|
|
bars.forEachRemaining(barList::add);
|
2020-04-06 03:21:16 +02:00
|
|
|
|
2020-04-07 04:08:17 +02:00
|
|
|
for (KeyedBossBar bar : barList) {
|
2020-04-15 14:55:35 +02:00
|
|
|
// Catch error incase someone added an invalid bossbar name
|
|
|
|
try {
|
|
|
|
if (!bar.getKey().getNamespace().equalsIgnoreCase("libsdisguises")) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-06 03:21:16 +02:00
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
bar.removeAll();
|
|
|
|
Bukkit.removeBossBar(bar.getKey());
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (IllegalArgumentException ignored) {
|
2020-04-15 14:55:35 +02:00
|
|
|
}
|
2020-04-07 04:08:17 +02:00
|
|
|
}
|
2020-04-06 03:21:16 +02:00
|
|
|
}
|
2020-05-08 06:35:25 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
Method m = CompileMethods.class.getMethod("main", String[].class);
|
|
|
|
|
|
|
|
if ((!m.isAnnotationPresent(CompileMethods.CompileMethodsIntfer.class) ||
|
|
|
|
m.getAnnotation(CompileMethods.CompileMethodsIntfer.class).user().matches("[0-9]+")) &&
|
|
|
|
!DisguiseConfig.doOutput(LibsDisguises.getInstance().getConfig(), true, false).isEmpty()) {
|
|
|
|
/*File f = new File(LibsDisguises.getInstance().getDataFolder(), "config.yml");
|
|
|
|
File f2 = new File(f.getParentFile(), "config-older.yml");
|
|
|
|
f2.delete();
|
|
|
|
f.renameTo(f2);
|
|
|
|
LibsDisguises.getInstance().saveDefaultConfig();*/
|
|
|
|
DisguiseConfig.setViewDisguises(false);
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (NoSuchMethodException e) {
|
2020-05-08 06:35:25 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-07-03 07:08:58 +02:00
|
|
|
|
|
|
|
loadViewPreferences();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
2020-08-12 09:28:41 +02:00
|
|
|
return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getEntityId()) &&
|
|
|
|
getDisguises().get(disguise.getEntity().getEntityId()).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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (disguise.getEntity() == null || !disguise.getEntity().isValid()) {
|
2016-06-07 04:42:38 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-07 04:42:38 +02:00
|
|
|
|
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)) {
|
2020-05-07 11:27:07 +02:00
|
|
|
removeSelfDisguise(disguise);
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2018-08-24 00:01:01 +02:00
|
|
|
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());
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (entityTrackerEntry == null) {
|
2016-06-12 16:22:56 +02:00
|
|
|
return;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-12 16:22:56 +02:00
|
|
|
|
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
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-06-12 16:22:56 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
|
|
|
|
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
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (pl == null || !player.equalsIgnoreCase((pl).getName())) {
|
2016-06-12 16:22:56 +02:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2018-08-24 00:01:01 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (
|
2016-06-07 04:42:38 +02:00
|
|
|
|
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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
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
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
|
|
|
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2018-08-24 00:01:01 +02:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:07:46 +02: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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
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()) {
|
2020-05-07 11:27:07 +02:00
|
|
|
removeSelfDisguise(disguise);
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2018-08-24 00:01:01 +02:00
|
|
|
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
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
|
|
|
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
2016-05-11 23:47:08 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
final Method updatePlayer = ReflectionManager
|
2020-02-13 07:47:02 +01:00
|
|
|
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
|
|
|
|
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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2018-08-24 00:01:01 +02:00
|
|
|
ex.printStackTrace();
|
2016-11-29 01:07:33 +01:00
|
|
|
}
|
|
|
|
}, 2);
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2016-11-29 01:07:33 +01:00
|
|
|
ex.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public static boolean removeDisguise(TargetedDisguise disguise) {
|
2020-08-12 09:28:41 +02:00
|
|
|
int entityId = disguise.getEntity().getEntityId();
|
2016-05-11 23:47:08 +02:00
|
|
|
|
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);
|
2020-06-26 04:24:48 +02:00
|
|
|
|
|
|
|
if (disguise.getEntity() != null) {
|
|
|
|
synchronized (isNoInteract) {
|
2020-06-26 06:03:50 +02:00
|
|
|
isNoInteract.remove((Object) disguise.getEntity().getEntityId());
|
2020-06-26 04:24:48 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!profileCache.exists()) {
|
2017-06-09 16:29:28 +02:00
|
|
|
profileCache.mkdirs();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2017-06-09 16:29:28 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
public static void removeSelfDisguise(Disguise disguise) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
Player player = (Player) disguise.getEntity();
|
|
|
|
|
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
|
|
|
|
2020-05-07 16:34:43 +02:00
|
|
|
int[] ids = Arrays.copyOf(disguise.getArmorstandIds(), 1 + disguise.getMultiNameLength());
|
2020-05-07 11:27:07 +02:00
|
|
|
ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId();
|
|
|
|
|
2016-06-07 04:42:38 +02:00
|
|
|
// Send a packet to destroy the fake entity
|
2020-05-07 11:27:07 +02:00
|
|
|
PacketContainer packet = getDestroyPacket(ids);
|
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);
|
2020-08-18 00:07:46 +02: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
|
|
|
}
|
2020-08-18 00:07:46 +02: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));
|
2020-08-18 00:07:46 +02: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
|
|
|
}
|
|
|
|
|
2020-01-20 01:35:55 +01:00
|
|
|
public static List<Scoreboard> getAllScoreboards() {
|
|
|
|
List<Scoreboard> boards = new ArrayList<>();
|
|
|
|
|
|
|
|
boards.add(Bukkit.getScoreboardManager().getMainScoreboard());
|
|
|
|
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (boards.contains(player.getScoreboard())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
boards.add(player.getScoreboard());
|
|
|
|
}
|
|
|
|
|
|
|
|
return boards;
|
|
|
|
}
|
|
|
|
|
2020-04-04 08:58:21 +02:00
|
|
|
public static DScoreTeam createExtendedName(String name) {
|
2020-03-30 09:22:33 +02:00
|
|
|
String[] split = getExtendedNameSplit(null, name);
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-04-04 08:58:21 +02:00
|
|
|
return new DScoreTeam(split);
|
2020-03-30 09:22:33 +02:00
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static String getUniqueTeam() {
|
2020-04-24 06:28:31 +02:00
|
|
|
return getUniqueTeam("LD_");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getUniqueTeam(String prefix) {
|
2020-03-30 09:22:33 +02:00
|
|
|
Scoreboard mainBoard = Bukkit.getScoreboardManager().getMainScoreboard();
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
String teamName = encode(System.nanoTime() / 100 % 100000) + "";
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (teamName.length() > 13) {
|
|
|
|
teamName = teamName.substring(teamName.length() - 13);
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-04-24 06:28:31 +02:00
|
|
|
teamName = prefix + teamName;
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (mainBoard.getTeam(teamName) != null) {
|
|
|
|
continue;
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
2020-03-30 09:22:33 +02:00
|
|
|
|
|
|
|
return teamName;
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
throw new IllegalStateException("Lib's Disguises unable to find a unique team name!");
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static void updateExtendedName(PlayerDisguise disguise) {
|
2020-04-04 08:58:21 +02:00
|
|
|
DScoreTeam exName = disguise.getScoreboardName();
|
2020-03-30 09:22:33 +02:00
|
|
|
|
2020-04-04 15:24:02 +02:00
|
|
|
if (exName.getTeamName() == null) {
|
|
|
|
exName.setTeamName(getUniqueTeam());
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
for (Scoreboard board : getAllScoreboards()) {
|
|
|
|
exName.handleTeam(board, disguise.isNameVisible());
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static void registerExtendedName(PlayerDisguise disguise) {
|
2020-04-04 08:58:21 +02:00
|
|
|
DScoreTeam exName = disguise.getScoreboardName();
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (exName.getTeamName() == null) {
|
|
|
|
exName.setTeamName(getUniqueTeam());
|
|
|
|
}
|
2020-01-22 06:46:57 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
for (Scoreboard board : getAllScoreboards()) {
|
|
|
|
exName.handleTeam(board, disguise.isNameVisible());
|
|
|
|
}
|
2020-01-22 06:46:57 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static void registerAllExtendedNames(Scoreboard scoreboard) {
|
|
|
|
for (Set<TargetedDisguise> disguises : getDisguises().values()) {
|
|
|
|
for (Disguise disguise : disguises) {
|
|
|
|
if (!disguise.isPlayerDisguise() || !disguise.isDisguiseInUse()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-04-04 08:58:21 +02:00
|
|
|
DScoreTeam name = ((PlayerDisguise) disguise).getScoreboardName();
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-04-04 15:24:02 +02:00
|
|
|
if (name.getTeamName() == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
name.handleTeam(scoreboard, ((PlayerDisguise) disguise).isNameVisible());
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static void unregisterExtendedName(PlayerDisguise removed) {
|
|
|
|
if (removed.getScoreboardName().getTeamName() == null) {
|
2020-01-22 06:46:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
for (Scoreboard board : getAllScoreboards()) {
|
|
|
|
Team t = board.getTeam(removed.getScoreboardName().getTeamName());
|
2020-01-20 01:35:55 +01:00
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if (t == null) {
|
2020-01-20 01:35:55 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
t.unregister();
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
2020-03-30 09:22:33 +02:00
|
|
|
|
|
|
|
removed.getScoreboardName().setTeamName(null);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:52 +01:00
|
|
|
public static void registerNoName(Scoreboard scoreboard) {
|
|
|
|
Team mainTeam = scoreboard.getTeam("LD_NoName");
|
|
|
|
|
|
|
|
if (mainTeam == null) {
|
|
|
|
mainTeam = scoreboard.registerNewTeam("LD_NoName");
|
|
|
|
mainTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
|
|
|
|
mainTeam.addEntry("");
|
|
|
|
} else if (!mainTeam.hasEntry("")) {
|
|
|
|
mainTeam.addEntry("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
public static String[] getExtendedNameSplit(String playerName, String name) {
|
2020-05-07 11:27:07 +02:00
|
|
|
if (name.length() <= 16 && !DisguiseConfig.isScoreboardNames()) {
|
2020-01-20 01:35:55 +01:00
|
|
|
throw new IllegalStateException("This can only be used for names longer than 16 characters!");
|
|
|
|
}
|
|
|
|
|
2020-07-05 00:38:44 +02:00
|
|
|
int limit = NmsVersion.v1_13.isSupported() ? 1024 : 16;
|
2020-07-04 10:33:22 +02:00
|
|
|
|
|
|
|
if (name.length() > (16 + (limit * 2))) {
|
|
|
|
name = name.substring(0, (16 + (limit * 2)));
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
// If name is short enough to be used outside of player name
|
2020-07-04 10:33:22 +02:00
|
|
|
if (DisguiseConfig.isScoreboardNames() && name.length() <= limit * 2) {
|
2020-03-30 09:22:33 +02:00
|
|
|
String[] newName = new String[]{name, playerName, ""};
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
if (name.length() > limit) {
|
|
|
|
if (name.charAt(limit - 1) == ChatColor.COLOR_CHAR) {
|
|
|
|
newName[0] = name.substring(0, limit - 1);
|
2020-03-30 09:22:33 +02:00
|
|
|
} else {
|
2020-07-04 10:33:22 +02:00
|
|
|
newName[0] = name.substring(0, limit);
|
2020-03-30 09:22:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String suffix = ChatColor.getLastColors(newName[0]) + name.substring(newName[0].length());
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
if (suffix.length() > limit) {
|
|
|
|
suffix = suffix.substring(0, limit);
|
2020-03-30 09:22:33 +02:00
|
|
|
}
|
|
|
|
// Don't allow second name to hit 17 chars
|
|
|
|
newName[2] = suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
String namePrefix = colorize("LD");
|
|
|
|
|
|
|
|
if (playerName == null || !playerName.startsWith(namePrefix)) {
|
|
|
|
String nameSuffix = "" + ChatColor.RESET;
|
|
|
|
long time = System.nanoTime() / 100 % 10000;
|
|
|
|
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
String testName = namePrefix + colorize(encode(time + i)) + nameSuffix;
|
|
|
|
|
|
|
|
if (testName.length() > 16) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isValidPlayerName(board, testName)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
newName[1] = testName;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newName;
|
|
|
|
}
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
for (int prefixLen = limit; prefixLen >= 0; prefixLen--) {
|
2020-01-20 01:35:55 +01:00
|
|
|
String prefix = name.substring(0, prefixLen);
|
|
|
|
|
|
|
|
if (prefix.endsWith("" + ChatColor.COLOR_CHAR)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String colors = ChatColor.getLastColors(prefix);
|
|
|
|
|
|
|
|
// We found our prefix. Now we check about seperating it between name and suffix
|
2020-07-04 10:33:22 +02:00
|
|
|
for (int nameLen = Math.min(name.length() - (prefixLen + colors.length()), limit - colors.length());
|
2020-01-20 01:35:55 +01:00
|
|
|
nameLen > 0; nameLen--) {
|
|
|
|
String nName = colors + name.substring(prefixLen, nameLen + prefixLen);
|
|
|
|
|
|
|
|
if (nName.endsWith("" + ChatColor.COLOR_CHAR)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String suffix = name.substring(nameLen + prefixLen);
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
if (suffix.length() > limit) {
|
|
|
|
suffix = suffix.substring(0, limit);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String[] extended = new String[]{prefix, nName, suffix};
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
if ((playerName == null || !playerName.equals(extended[1])) && !isValidPlayerName(board, extended[1])) {
|
2020-01-20 01:35:55 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return extended;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Failed to find a unique name.. Ah well.
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
String prefix = name.substring(0, limit);
|
2020-01-20 01:35:55 +01:00
|
|
|
|
|
|
|
if (prefix.endsWith(ChatColor.COLOR_CHAR + "")) {
|
2020-07-04 10:33:22 +02:00
|
|
|
prefix = prefix.substring(0, limit - 1);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String nName = name.substring(prefix.length(), prefix.length() + Math.min(16, prefix.length()));
|
|
|
|
|
|
|
|
if (nName.endsWith(ChatColor.COLOR_CHAR + "") && nName.length() > 1) {
|
|
|
|
nName = nName.substring(0, nName.length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
String suffix = name.substring(prefix.length() + nName.length());
|
|
|
|
|
2020-07-04 10:33:22 +02:00
|
|
|
if (suffix.length() > limit) {
|
|
|
|
suffix = suffix.substring(0, limit);
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new String[]{prefix, nName, suffix};
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
private static String colorize(String s) {
|
|
|
|
StringBuilder builder = new StringBuilder(s.length() * 2);
|
|
|
|
|
|
|
|
for (char c : s.toCharArray()) {
|
|
|
|
builder.append(ChatColor.COLOR_CHAR).append(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String encode(long toConvert) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
while (toConvert != 0) {
|
|
|
|
builder.append(alphabet[(int) (toConvert % alphabet.length)]);
|
|
|
|
toConvert /= alphabet.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.reverse().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isValidPlayerName(Scoreboard board, String name) {
|
|
|
|
return board.getEntryTeam(name) == null && Bukkit.getPlayerExact(name) == null;
|
2020-01-20 01:35:55 +01: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()) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!t.hasEntry(player.getName())) {
|
2018-11-23 01:27:12 +01:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
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()) ||
|
2020-01-22 06:46:57 +01:00
|
|
|
(LibsPremium.getPaidInformation() != null && !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()) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!t.hasEntry(player.getName())) {
|
2018-11-23 01:27:12 +01:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
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
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!ldTeam.hasEntry(player.getName())) {
|
2018-11-23 01:27:12 +01:00
|
|
|
ldTeam.addEntry(player.getName());
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:22:33 +02:00
|
|
|
return "\"" +
|
|
|
|
string.replaceAll("\\\\(?=\\\\*\"( |$))", "\\\\\\\\").replaceAll("((?<= )\")|(\"(?= ))", "\\\\\"") +
|
|
|
|
"\"";
|
2020-01-02 05:10:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
public static String quoteNewLine(String string) {
|
|
|
|
return string.replaceAll("\\\\(?=\\\\+n)", "\\\\\\\\");
|
|
|
|
}
|
|
|
|
|
2020-05-07 16:34:43 +02:00
|
|
|
public static String[] reverse(String[] array) {
|
2020-06-22 09:39:02 +02:00
|
|
|
if (array == null) {
|
|
|
|
return new String[0];
|
|
|
|
}
|
|
|
|
|
2020-05-07 16:34:43 +02:00
|
|
|
String[] newArray = new String[array.length];
|
|
|
|
|
|
|
|
for (int i = 1; i <= array.length; i++) {
|
|
|
|
newArray[array.length - i] = array[i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return newArray;
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
public static String[] splitNewLine(String string) {
|
2020-05-07 12:38:10 +02:00
|
|
|
if (string.contains("\n")) {
|
|
|
|
return string.split("\n");
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
Pattern regex = Pattern.compile("\\\\+n");
|
|
|
|
Matcher result = regex.matcher(string);
|
|
|
|
|
|
|
|
ArrayList<String> lines = new ArrayList<>();
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
int last = 0;
|
|
|
|
|
|
|
|
while (result.find()) {
|
|
|
|
builder.append(string, last, result.start());
|
|
|
|
last = result.end();
|
|
|
|
|
|
|
|
if (result.group().matches("(\\\\\\\\)+n")) {
|
|
|
|
builder.append(result.group().replace("\\\\", "\\"));
|
|
|
|
} else {
|
|
|
|
String group = result.group().replace("\\\\", "\\");
|
|
|
|
|
|
|
|
builder.append(group, 0, group.length() - 2);
|
|
|
|
|
|
|
|
lines.add(builder.toString());
|
|
|
|
builder = new StringBuilder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lines.add(builder.toString() + string.substring(last));
|
|
|
|
|
|
|
|
return lines.toArray(new String[0]);
|
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2020-07-04 08:01:30 +02:00
|
|
|
public static ItemStack getSlot(PlayerInventory equip, EquipmentSlot slot) {
|
|
|
|
switch (slot) {
|
|
|
|
case HAND:
|
|
|
|
return equip.getItemInMainHand();
|
|
|
|
case OFF_HAND:
|
|
|
|
return equip.getItemInOffHand();
|
|
|
|
case HEAD:
|
|
|
|
return equip.getHelmet();
|
|
|
|
case CHEST:
|
|
|
|
return equip.getChestplate();
|
|
|
|
case LEGS:
|
|
|
|
return equip.getLeggings();
|
|
|
|
case FEET:
|
|
|
|
return equip.getBoots();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
2016-06-05 15:31:34 +02:00
|
|
|
throw new IllegalStateException("Cannot modify disguises on an async thread");
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-06-05 15:31:34 +02:00
|
|
|
|
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
|
2020-08-18 00:07:46 +02:00
|
|
|
Object trackedPlayersObj =
|
|
|
|
ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
2019-11-10 10:44:02 +01:00
|
|
|
|
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 {
|
2020-02-13 07:47:02 +01:00
|
|
|
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry")
|
|
|
|
.getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
|
2016-05-11 23:47:08 +02:00
|
|
|
field.setAccessible(true);
|
|
|
|
isMoving = field.getBoolean(entityTrackerEntry);
|
2020-08-18 00:07:46 +02: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();
|
2020-03-13 01:00:55 +01:00
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.ENTITY_VELOCITY, player).createPacket(player));
|
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
|
|
|
}
|
|
|
|
|
2020-06-25 05:33:28 +02:00
|
|
|
if (NmsVersion.v1_16.isSupported()) {
|
|
|
|
List<Pair<Object, Object>> list = new ArrayList<>();
|
|
|
|
|
|
|
|
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
|
|
|
list.add(Pair.of(ReflectionManager.createEnumItemSlot(slot),
|
|
|
|
ReflectionManager.getNmsItem(player.getInventory().getItem(slot))));
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSelfPacket(player,
|
|
|
|
manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, list).createPacket(0, list));
|
|
|
|
} else {
|
|
|
|
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
2020-07-04 08:01:30 +02:00
|
|
|
Object item = ReflectionManager.getNmsItem(getSlot(player.getInventory(), slot));
|
|
|
|
|
2020-06-25 05:33:28 +02:00
|
|
|
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
|
2020-07-04 08:01:30 +02:00
|
|
|
ReflectionManager.createEnumItemSlot(slot), item)
|
|
|
|
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(slot), item));
|
2020-06-25 05:33:28 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2020-08-18 00:07:46 +02: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();
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
public static String quoteHex(String string) {
|
|
|
|
return string.replaceAll("(<)(#[0-9a-fA-F]{6}>)", "$1\\$2");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String unquoteHex(String string) {
|
|
|
|
return string.replaceAll("(<)\\\\(#[0-9a-fA-F]{6}>)", "$1$2");
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:36:29 +02:00
|
|
|
public static void sendMessage(CommandSender sender, String message) {
|
|
|
|
if (!NmsVersion.v1_16.isSupported()) {
|
|
|
|
if (!message.isEmpty()) {
|
|
|
|
sender.sendMessage(message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BaseComponent[] components = getColoredChat(message);
|
|
|
|
|
|
|
|
if (components.length > 0) {
|
|
|
|
sender.spigot().sendMessage(components);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:44:22 +02:00
|
|
|
@Deprecated
|
2020-06-27 11:01:58 +02:00
|
|
|
public static void sendMessage(CommandSender sender, LibsMsg msg, Object... args) {
|
|
|
|
if (!NmsVersion.v1_16.isSupported()) {
|
2020-07-03 07:36:29 +02:00
|
|
|
String message = msg.get(args);
|
|
|
|
|
|
|
|
if (!message.isEmpty()) {
|
|
|
|
sender.sendMessage(message);
|
|
|
|
}
|
2020-06-27 11:01:58 +02:00
|
|
|
} else {
|
2020-07-03 07:36:29 +02:00
|
|
|
BaseComponent[] components = msg.getChat(args);
|
|
|
|
|
|
|
|
if (components.length > 0) {
|
|
|
|
sender.spigot().sendMessage(components);
|
|
|
|
}
|
2020-06-27 11:01:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-27 11:20:03 +02:00
|
|
|
public static int[] getNumericVersion(String version) {
|
|
|
|
int[] v = new int[0];
|
2020-07-03 07:08:58 +02:00
|
|
|
for (String split : version.split("[.\\-]")) {
|
2020-06-27 11:20:03 +02:00
|
|
|
if (!split.matches("[0-9]+")) {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = Arrays.copyOf(v, v.length + 1);
|
|
|
|
v[v.length - 1] = Integer.parseInt(split);
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
public static String getSimpleString(BaseComponent[] components) {
|
2020-07-03 07:08:58 +02:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
for (BaseComponent component : components) {
|
|
|
|
net.md_5.bungee.api.ChatColor color = component.getColor();
|
|
|
|
String string = color.toString();
|
|
|
|
|
|
|
|
if (string.length() > 2) {
|
|
|
|
builder.append("<#")
|
|
|
|
.append(string.substring(2).replace(net.md_5.bungee.api.ChatColor.COLOR_CHAR + "", ""))
|
|
|
|
.append(">");
|
|
|
|
} else {
|
|
|
|
builder.append(string);
|
|
|
|
}
|
2020-06-30 06:06:27 +02:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (component.isBold()) {
|
|
|
|
builder.append(net.md_5.bungee.api.ChatColor.BOLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (component.isItalic()) {
|
|
|
|
builder.append(net.md_5.bungee.api.ChatColor.ITALIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (component.isUnderlined()) {
|
|
|
|
builder.append(net.md_5.bungee.api.ChatColor.UNDERLINE);
|
|
|
|
}
|
2020-06-30 06:06:27 +02:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (component.isStrikethrough()) {
|
|
|
|
builder.append(net.md_5.bungee.api.ChatColor.STRIKETHROUGH);
|
|
|
|
}
|
2020-06-30 06:06:27 +02:00
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (component.isObfuscated()) {
|
|
|
|
builder.append(net.md_5.bungee.api.ChatColor.MAGIC);
|
2020-06-30 06:06:27 +02:00
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (!(component instanceof TextComponent)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-30 06:06:27 +02:00
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
builder.append(quoteHex(((TextComponent) component).getText()));
|
2020-06-30 06:06:27 +02:00
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modification of TextComponent.fromLegacyText
|
|
|
|
*/
|
|
|
|
public static BaseComponent[] getColoredChat(String message) {
|
2020-07-03 07:36:29 +02:00
|
|
|
if (message.isEmpty()) {
|
|
|
|
return new BaseComponent[0];
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
ArrayList<BaseComponent> components = new ArrayList();
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
TextComponent component = new TextComponent();
|
|
|
|
Matcher matcher = urlMatcher.matcher(message);
|
|
|
|
|
|
|
|
for (int i = 0; i < message.length(); ++i) {
|
|
|
|
char c = message.charAt(i);
|
|
|
|
TextComponent old;
|
|
|
|
|
|
|
|
if (c == ChatColor.COLOR_CHAR || (c == '<' && i + 9 < message.length() && NmsVersion.v1_16.isSupported() &&
|
|
|
|
Pattern.matches("<#[0-9a-fA-F]{6}>", message.substring(i, i + 9)))) {
|
|
|
|
// If normal color char
|
|
|
|
if (c == ChatColor.COLOR_CHAR) {
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if (i >= message.length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
net.md_5.bungee.api.ChatColor format;
|
|
|
|
|
|
|
|
if (c != ChatColor.COLOR_CHAR) {
|
|
|
|
format = net.md_5.bungee.api.ChatColor.of(message.substring(i + 1, i + 8));
|
|
|
|
|
|
|
|
i += 8;
|
|
|
|
} else {
|
|
|
|
c = message.charAt(i);
|
|
|
|
|
|
|
|
if (c >= 'A' && c <= 'Z') {
|
|
|
|
c = (char) (c + 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
format = net.md_5.bungee.api.ChatColor.getByChar(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format != null) {
|
|
|
|
if (builder.length() > 0) {
|
|
|
|
old = component;
|
|
|
|
component = new TextComponent(component);
|
|
|
|
old.setText(builder.toString());
|
|
|
|
builder = new StringBuilder();
|
|
|
|
components.add(old);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == net.md_5.bungee.api.ChatColor.BOLD) {
|
|
|
|
component.setBold(true);
|
|
|
|
} else if (format == net.md_5.bungee.api.ChatColor.ITALIC) {
|
|
|
|
component.setItalic(true);
|
|
|
|
} else if (format == net.md_5.bungee.api.ChatColor.UNDERLINE) {
|
|
|
|
component.setUnderlined(true);
|
|
|
|
} else if (format == net.md_5.bungee.api.ChatColor.STRIKETHROUGH) {
|
|
|
|
component.setStrikethrough(true);
|
|
|
|
} else if (format == net.md_5.bungee.api.ChatColor.MAGIC) {
|
|
|
|
component.setObfuscated(true);
|
|
|
|
} else if (format == net.md_5.bungee.api.ChatColor.RESET) {
|
|
|
|
component = new TextComponent();
|
|
|
|
component.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
|
|
|
} else {
|
|
|
|
component = new TextComponent();
|
|
|
|
component.setColor(format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int pos = message.indexOf(32, i);
|
|
|
|
if (pos == -1) {
|
|
|
|
pos = message.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matcher.region(i, pos).find()) {
|
|
|
|
if (builder.length() > 0) {
|
|
|
|
old = component;
|
|
|
|
component = new TextComponent(component);
|
2020-07-03 13:45:48 +02:00
|
|
|
old.setText(unquoteHex(builder.toString()));
|
2020-07-03 07:08:58 +02:00
|
|
|
builder = new StringBuilder();
|
|
|
|
components.add(old);
|
|
|
|
}
|
|
|
|
|
|
|
|
old = component;
|
|
|
|
component = new TextComponent(component);
|
|
|
|
String urlString = message.substring(i, pos);
|
2020-07-03 13:45:48 +02:00
|
|
|
component.setText(unquoteHex(urlString));
|
2020-07-03 07:08:58 +02:00
|
|
|
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
|
|
|
|
urlString.startsWith("http") ? urlString : "http://" + urlString));
|
|
|
|
components.add(component);
|
|
|
|
i += pos - i - 1;
|
|
|
|
component = old;
|
|
|
|
} else {
|
|
|
|
builder.append(c);
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 06:06:27 +02:00
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
component.setText(unquoteHex(builder.toString()));
|
2020-07-03 07:08:58 +02:00
|
|
|
components.add(component);
|
2020-07-03 13:45:48 +02:00
|
|
|
return components.toArray(new BaseComponent[0]);
|
2020-06-30 06:06:27 +02:00
|
|
|
}
|
|
|
|
|
2020-06-27 11:20:03 +02:00
|
|
|
public static boolean isOlderThan(String requiredVersion, String theirVersion) {
|
2020-07-01 02:29:49 +02:00
|
|
|
int[] required = getNumericVersion(requiredVersion);
|
|
|
|
int[] has = getNumericVersion(theirVersion);
|
2020-06-27 11:20:03 +02:00
|
|
|
|
2020-07-01 02:29:49 +02:00
|
|
|
for (int i = 0; i < Math.min(required.length, has.length); i++) {
|
|
|
|
if (required[i] == has[i]) {
|
2020-06-27 11:20:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:29:49 +02:00
|
|
|
return required[i] >= has[i];
|
2020-06-27 11:20:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (transformed.isUnhandled()) {
|
2016-10-04 15:11:50 +02:00
|
|
|
transformed.addPacket(packet);
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2016-10-04 15:11:50 +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);
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (InvocationTargetException e) {
|
2016-06-18 17:16:32 +02:00
|
|
|
e.printStackTrace();
|
2016-05-11 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:14:17 +02:00
|
|
|
public static PacketContainer getTabPacket(PlayerDisguise disguise, EnumWrappers.PlayerInfoAction action) {
|
|
|
|
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
|
|
|
|
|
|
|
addTab.getPlayerInfoAction().write(0, action);
|
|
|
|
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
|
|
|
|
new PlayerInfoData(disguise.getGameProfile(), 0, EnumWrappers.NativeGameMode.SURVIVAL,
|
|
|
|
WrappedChatComponent.fromText(disguise.getName()))));
|
|
|
|
|
|
|
|
return addTab;
|
|
|
|
}
|
|
|
|
|
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
|
2020-08-12 09:28:41 +02:00
|
|
|
if (!(e instanceof Player) || !getDisguises().containsKey(e.getEntityId()) ||
|
|
|
|
!getDisguises().get(e.getEntityId()).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
|
2020-05-07 11:27:07 +02:00
|
|
|
DisguiseUtilities.removeSelfDisguise(disguise);
|
2016-05-11 23:47:08 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (IllegalAccessException e) {
|
2019-07-09 10:52:00 +02:00
|
|
|
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?");
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:57:39 +01:00
|
|
|
public static String serialize(NbtBase base) {
|
|
|
|
return serialize(0, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String serialize(int depth, NbtBase base) {
|
|
|
|
switch (base.getType()) {
|
|
|
|
case TAG_COMPOUND:
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
builder.append("{");
|
|
|
|
|
|
|
|
for (String key : ((NbtCompound) base).getKeys()) {
|
|
|
|
NbtBase<Object> nbt = ((NbtCompound) base).getValue(key);
|
|
|
|
String val = serialize(depth + 1, nbt);
|
|
|
|
|
|
|
|
// Skip root empty values
|
|
|
|
if (depth == 0 && val.matches("0(\\.0)?")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builder.length() != 1) {
|
|
|
|
builder.append(",");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.append(key).append(":").append(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.append("}");
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
case TAG_LIST:
|
|
|
|
Collection col = ((NbtList) base).asCollection();
|
|
|
|
|
|
|
|
return "[" + StringUtils.join(col.stream().map(b -> serialize(depth + 1, (NbtBase) b)).toArray(), ",") +
|
|
|
|
"]";
|
|
|
|
case TAG_BYTE_ARRAY:
|
|
|
|
case TAG_INT_ARRAY:
|
|
|
|
case TAG_LONG_ARRAY:
|
|
|
|
Object[] array = (Object[]) base.getValue();
|
|
|
|
String[] str = new String[array.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
str[i] = array[i].toString();//+ getChar(base.getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
return "[" + StringUtils.join(str, ",") + "]";
|
|
|
|
case TAG_BYTE:
|
|
|
|
case TAG_INT:
|
|
|
|
case TAG_LONG:
|
|
|
|
case TAG_FLOAT:
|
|
|
|
case TAG_SHORT:
|
|
|
|
case TAG_DOUBLE:
|
|
|
|
return base.getValue().toString();// + getChar(base.getType());
|
|
|
|
case TAG_STRING:
|
|
|
|
String val = (String) base.getValue();
|
|
|
|
|
|
|
|
return "\"" + val.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
|
|
|
|
case TAG_END:
|
|
|
|
return "";
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
/**
|
|
|
|
* Create a new datawatcher but with the 'correct' values
|
|
|
|
*/
|
|
|
|
public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher,
|
2020-08-18 00:07:46 +02:00
|
|
|
FlagWatcher disguiseWatcher) {
|
2019-01-03 03:13:03 +01:00
|
|
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
|
|
|
|
|
|
|
try {
|
2020-02-01 23:59:18 +01:00
|
|
|
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ?
|
2019-01-03 03:13:03 +01:00
|
|
|
disguiseWatcher.convert(entityWatcher.getWatchableObjects()) :
|
|
|
|
disguiseWatcher.getWatchableObjects();
|
|
|
|
|
|
|
|
for (WrappedWatchableObject watchableObject : list) {
|
2020-08-18 00:07:46 +02:00
|
|
|
if (watchableObject == null) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
if (watchableObject.getValue() == null) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-09-16 04:30:16 +02:00
|
|
|
MetaIndex metaIndex = MetaIndex.getMetaIndex(disguiseWatcher, watchableObject.getIndex());
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
|
|
|
ReflectionManager.createDataWatcherObject(metaIndex, watchableObject.getValue());
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
newWatcher.setObject(obj, watchableObject.getValue());
|
|
|
|
}
|
2020-08-18 00:07:46 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
if (disguiseType == DisguiseType.PHANTOM) {
|
|
|
|
return (byte) -value;
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
2020-07-03 07:08:58 +02:00
|
|
|
|
|
|
|
return value;
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-05-07 16:34:43 +02:00
|
|
|
public static ArrayList<PacketContainer> getNamePackets(Disguise disguise, String[] internalOldNames) {
|
2020-05-07 11:27:07 +02:00
|
|
|
ArrayList<PacketContainer> packets = new ArrayList<>();
|
2020-08-23 03:32:54 +02:00
|
|
|
String[] newNames = new String[0];
|
2020-05-07 11:27:07 +02:00
|
|
|
int[] standIds = disguise.getArmorstandIds();
|
|
|
|
int[] destroyIds = new int[0];
|
|
|
|
|
2020-08-23 03:32:54 +02:00
|
|
|
if (!LibsPremium.isPremium()) {
|
|
|
|
internalOldNames = new String[]{StringUtils.join(internalOldNames, "\\n")};
|
|
|
|
|
|
|
|
if (!disguise.isPlayerDisguise() || ((PlayerDisguise) disguise).isNameVisible()) {
|
|
|
|
newNames = new String[]{StringUtils.join(newNames, "\\n")};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newNames = (disguise instanceof PlayerDisguise && !((PlayerDisguise) disguise).isNameVisible()) ?
|
|
|
|
new String[0] : reverse(disguise.getMultiName());
|
|
|
|
}
|
|
|
|
|
2020-05-07 16:34:43 +02:00
|
|
|
if (internalOldNames.length > newNames.length) {
|
2020-05-07 11:27:07 +02:00
|
|
|
// Destroy packet
|
2020-05-07 16:34:43 +02:00
|
|
|
destroyIds = Arrays.copyOfRange(standIds, newNames.length, internalOldNames.length);
|
2020-05-07 11:27:07 +02:00
|
|
|
}
|
|
|
|
|
2020-05-09 11:57:07 +02:00
|
|
|
double height = disguise.getHeight();
|
|
|
|
|
2020-05-07 11:27:07 +02:00
|
|
|
for (int i = 0; i < newNames.length; i++) {
|
2020-05-07 16:34:43 +02:00
|
|
|
if (i < internalOldNames.length) {
|
2020-08-10 23:00:35 +02:00
|
|
|
if (newNames[i].equals(internalOldNames[i])) {
|
2020-05-07 11:27:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
|
|
|
|
2020-06-30 06:06:27 +02:00
|
|
|
Object name;
|
|
|
|
|
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
2020-07-03 07:08:58 +02:00
|
|
|
name = Optional.of(WrappedChatComponent
|
|
|
|
.fromJson(ComponentSerializer.toString(DisguiseUtilities.getColoredChat(newNames[i]))));
|
2020-06-30 06:06:27 +02:00
|
|
|
} else {
|
|
|
|
name = newNames[i];
|
|
|
|
}
|
2020-05-07 11:27:07 +02:00
|
|
|
|
|
|
|
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(
|
|
|
|
NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME :
|
|
|
|
MetaIndex.ENTITY_CUSTOM_NAME_OLD, name);
|
|
|
|
|
|
|
|
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(name));
|
|
|
|
|
|
|
|
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
|
|
|
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, 0, watcher, true)
|
|
|
|
.createPacket(standIds[i], watcher, true);
|
|
|
|
|
|
|
|
packets.add(metaPacket);
|
|
|
|
} else if (newNames[i].isEmpty()) {
|
|
|
|
destroyIds = Arrays.copyOf(destroyIds, destroyIds.length + 1);
|
|
|
|
destroyIds[destroyIds.length - 1] = standIds[i];
|
|
|
|
} else {
|
|
|
|
PacketContainer packet = new PacketContainer(Server.SPAWN_ENTITY_LIVING);
|
|
|
|
packet.getIntegers().write(0, standIds[i]);
|
|
|
|
packet.getIntegers().write(1, DisguiseType.ARMOR_STAND.getTypeId());
|
|
|
|
|
|
|
|
packet.getUUIDs().write(0, UUID.randomUUID());
|
|
|
|
|
|
|
|
Location loc = disguise.getEntity().getLocation();
|
|
|
|
|
|
|
|
packet.getDoubles().write(0, loc.getX());
|
2020-05-09 11:57:07 +02:00
|
|
|
packet.getDoubles().write(1, loc.getY() + height + (0.28 * i));
|
2020-05-07 11:27:07 +02:00
|
|
|
packet.getDoubles().write(2, loc.getZ());
|
|
|
|
packets.add(packet);
|
|
|
|
|
|
|
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
|
|
|
|
2020-05-09 11:57:07 +02:00
|
|
|
for (MetaIndex index : MetaIndex.getMetaIndexes(ArmorStandWatcher.class)) {
|
2020-05-07 11:27:07 +02:00
|
|
|
Object val = index.getDefault();
|
|
|
|
|
|
|
|
if (index == MetaIndex.ENTITY_META) {
|
|
|
|
val = (byte) 32;
|
|
|
|
} else if (index == MetaIndex.ARMORSTAND_META) {
|
2020-05-09 11:57:07 +02:00
|
|
|
val = (byte) 19;
|
2020-05-07 11:27:07 +02:00
|
|
|
} else if (index == MetaIndex.ENTITY_CUSTOM_NAME) {
|
|
|
|
val = Optional.of(WrappedChatComponent.fromText(newNames[i]));
|
|
|
|
} else if (index == MetaIndex.ENTITY_CUSTOM_NAME_OLD) {
|
|
|
|
val = newNames[i];
|
|
|
|
} else if (index == MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE) {
|
|
|
|
val = true;
|
|
|
|
}
|
|
|
|
|
2020-08-18 00:07:46 +02:00
|
|
|
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
|
|
|
ReflectionManager.createDataWatcherObject(index, val);
|
2020-05-07 11:27:07 +02:00
|
|
|
|
|
|
|
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NmsVersion.v1_15.isSupported()) {
|
|
|
|
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
2020-05-09 11:57:07 +02:00
|
|
|
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, standIds[i], watcher, true)
|
2020-05-07 11:27:07 +02:00
|
|
|
.createPacket(standIds[i], watcher, true);
|
|
|
|
|
|
|
|
packets.add(metaPacket);
|
|
|
|
} else {
|
|
|
|
packet.getDataWatcherModifier().write(0, watcher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destroyIds.length > 0) {
|
|
|
|
packets.add(getDestroyPacket(destroyIds));
|
|
|
|
}
|
|
|
|
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
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()) {
|
2020-08-12 09:28:41 +02:00
|
|
|
entityId = observer.getEntityId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getFutureDisguises().containsKey(entityId)) {
|
2020-08-11 01:03:12 +02:00
|
|
|
for (Entity e : observer.getWorld().getEntities()) {
|
|
|
|
if (e.getEntityId() != entityId) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-22 12:06:59 +02:00
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
onFutureDisguise(e);
|
2020-08-11 01:03:12 +02:00
|
|
|
}
|
2019-06-22 12:06:59 +02:00
|
|
|
|
2020-08-11 01:03:12 +02:00
|
|
|
}
|
2019-06-22 12:06:59 +02:00
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
TargetedDisguise[] disguises = getDisguises(entityId);
|
2019-06-22 12:06:59 +02:00
|
|
|
|
2020-08-11 01:03:12 +02:00
|
|
|
if (disguises == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TargetedDisguise dis : disguises) {
|
|
|
|
if (!dis.isDisguiseInUse()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-22 12:06:59 +02:00
|
|
|
|
2020-08-11 01:03:12 +02:00
|
|
|
if (!dis.canSee(observer)) {
|
|
|
|
continue;
|
2019-06-22 12:06:59 +02:00
|
|
|
}
|
2020-08-11 01:03:12 +02:00
|
|
|
|
|
|
|
return dis;
|
2019-06-22 12:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2020-08-18 00:07:46 +02:00
|
|
|
if (entity instanceof LivingEntity) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return yMod + ((LivingEntity) entity).getEyeHeight();
|
2020-08-18 00:07:46 +02:00
|
|
|
}
|
2020-04-06 03:21:16 +02:00
|
|
|
|
|
|
|
return yMod;
|
2019-01-03 03:13:03 +01:00
|
|
|
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
|
|
|
}
|