From ce134af4faf1bbb6cb3cf6052cd8ff0bb7b7a000 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 29 Nov 2016 10:47:48 +1300 Subject: [PATCH] Renaming commands, fixing evoker fangs --- .../libraryaddict/disguise/LibsDisguises.java | 20 +- ...eCommand.java => DisguiseBaseCommand.java} | 26 +- ...Command.java => DisguiseCloneCommand.java} | 2 +- .../disguise/commands/DisguiseCommand.java | 2 +- ...ommand.java => DisguiseEntityCommand.java} | 2 +- .../commands/DisguiseHelpCommand.java | 3 +- ...ommand.java => DisguisePlayerCommand.java} | 2 +- ...ommand.java => DisguiseRadiusCommand.java} | 4 +- ...Self.java => DisguiseViewSelfCommand.java} | 2 +- .../disguise/disguisetypes/Disguise.java | 10 +- .../disguise/utilities/DisguiseUtilities.java | 670 ++++++------------ .../disguise/utilities/PacketsManager.java | 1 - 12 files changed, 277 insertions(+), 467 deletions(-) rename src/me/libraryaddict/disguise/commands/{BaseDisguiseCommand.java => DisguiseBaseCommand.java} (95%) rename src/me/libraryaddict/disguise/commands/{CloneDisguiseCommand.java => DisguiseCloneCommand.java} (95%) rename src/me/libraryaddict/disguise/commands/{EntityDisguiseCommand.java => DisguiseEntityCommand.java} (96%) rename src/me/libraryaddict/disguise/commands/{PlayerDisguiseCommand.java => DisguisePlayerCommand.java} (96%) rename src/me/libraryaddict/disguise/commands/{RadiusDisguiseCommand.java => DisguiseRadiusCommand.java} (96%) rename src/me/libraryaddict/disguise/commands/{DisguiseViewSelf.java => DisguiseViewSelfCommand.java} (91%) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index f1f0c312..ddf76e44 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -21,14 +21,14 @@ import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedWatchableObject; -import me.libraryaddict.disguise.commands.CloneDisguiseCommand; +import me.libraryaddict.disguise.commands.DisguiseCloneCommand; import me.libraryaddict.disguise.commands.DisguiseCommand; import me.libraryaddict.disguise.commands.DisguiseHelpCommand; -import me.libraryaddict.disguise.commands.DisguiseViewSelf; -import me.libraryaddict.disguise.commands.EntityDisguiseCommand; +import me.libraryaddict.disguise.commands.DisguiseViewSelfCommand; +import me.libraryaddict.disguise.commands.DisguiseEntityCommand; import me.libraryaddict.disguise.commands.LibsDisguisesCommand; -import me.libraryaddict.disguise.commands.PlayerDisguiseCommand; -import me.libraryaddict.disguise.commands.RadiusDisguiseCommand; +import me.libraryaddict.disguise.commands.DisguisePlayerCommand; +import me.libraryaddict.disguise.commands.DisguiseRadiusCommand; import me.libraryaddict.disguise.commands.UndisguiseCommand; import me.libraryaddict.disguise.commands.UndisguiseEntityCommand; import me.libraryaddict.disguise.commands.UndisguisePlayerCommand; @@ -98,16 +98,16 @@ public class LibsDisguises extends JavaPlugin { registerCommand("disguise", new DisguiseCommand()); registerCommand("undisguise", new UndisguiseCommand()); - registerCommand("disguiseplayer", new PlayerDisguiseCommand()); + registerCommand("disguiseplayer", new DisguisePlayerCommand()); registerCommand("undisguiseplayer", new UndisguisePlayerCommand()); registerCommand("undisguiseentity", new UndisguiseEntityCommand()); - registerCommand("disguiseentity", new EntityDisguiseCommand()); - registerCommand("disguiseradius", new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax"))); + registerCommand("disguiseentity", new DisguiseEntityCommand()); + registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax"))); registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax"))); registerCommand("disguisehelp", new DisguiseHelpCommand()); - registerCommand("disguiseclone", new CloneDisguiseCommand()); + registerCommand("disguiseclone", new DisguiseCloneCommand()); registerCommand("libsdisguises", new LibsDisguisesCommand()); - registerCommand("disguiseviewself", new DisguiseViewSelf()); + registerCommand("disguiseviewself", new DisguiseViewSelfCommand()); registerValues(); diff --git a/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java similarity index 95% rename from src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java rename to src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 0ba43e76..c409dd81 100644 --- a/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -43,7 +43,7 @@ import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; /** * @author libraryaddict */ -public abstract class BaseDisguiseCommand implements CommandExecutor { +public abstract class DisguiseBaseCommand implements CommandExecutor { public class DisguiseParseException extends Exception { private static final long serialVersionUID = 1276971370793124510L; @@ -123,6 +123,23 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { return newArgs.toArray(new String[0]); } + public String getPermNode() { + if (this instanceof DisguiseCommand) { + return "disguise"; + } + else if (this instanceof DisguiseEntityCommand) { + return "disguiseentity"; + } + else if (this instanceof DisguisePlayerCommand) { + return "disguiseplayer"; + } + else if (this instanceof DisguiseRadiusCommand) { + return "disguiseradius"; + } + else + throw new UnsupportedOperationException("Unknown disguise command, perm node not found"); + } + protected HashMap getDisguiseOptions(CommandSender sender, DisguiseType type) { switch (type) { case PLAYER: @@ -133,7 +150,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { case DROPPED_ITEM: HashMap returns = new HashMap<>(); - String beginning = "libsdisguises.options." + getClass().getSimpleName().toLowerCase().replace("command", "") + "."; + String beginning = "libsdisguises.options." + getPermNode() + "."; for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String lowerPerm = permission.getPermission().toLowerCase(); @@ -192,7 +209,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { } protected HashMap, Boolean>> getPermissions(CommandSender sender) { - return getPermissions(sender, "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + "."); + return getPermissions(sender, "libsdisguises." + getPermNode() + "."); } /** @@ -309,6 +326,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { for (String perm : perms.keySet()) { if (!perms.get(perm)) { perm = perm.substring(permissionNode.length()); + String disguiseType = perm.split("\\.")[0]; DisguiseType dType = null; @@ -424,7 +442,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { * @param args * @param map * @return - * @throws BaseDisguiseCommand.DisguiseParseException + * @throws DisguiseBaseCommand.DisguiseParseException * @throws java.lang.IllegalAccessException * @throws java.lang.reflect.InvocationTargetException */ diff --git a/src/me/libraryaddict/disguise/commands/CloneDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java similarity index 95% rename from src/me/libraryaddict/disguise/commands/CloneDisguiseCommand.java rename to src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index 1094c438..8ee3845a 100644 --- a/src/me/libraryaddict/disguise/commands/CloneDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -14,7 +14,7 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -public class CloneDisguiseCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index fa7fee89..50632868 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -21,7 +21,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -public class DisguiseCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { diff --git a/src/me/libraryaddict/disguise/commands/EntityDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java similarity index 96% rename from src/me/libraryaddict/disguise/commands/EntityDisguiseCommand.java rename to src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index fcc5e0ec..db505096 100644 --- a/src/me/libraryaddict/disguise/commands/EntityDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -21,7 +21,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -public class EntityDisguiseCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.getName().equals("CONSOLE")) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 305ecd37..da4497e4 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -18,7 +18,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -public class DisguiseHelpCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { @@ -149,6 +149,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand implements TabCompl } } } + sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); return true; } diff --git a/src/me/libraryaddict/disguise/commands/PlayerDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java similarity index 96% rename from src/me/libraryaddict/disguise/commands/PlayerDisguiseCommand.java rename to src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 460b4406..035ee62a 100644 --- a/src/me/libraryaddict/disguise/commands/PlayerDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -21,7 +21,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -public class PlayerDisguiseCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { diff --git a/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java similarity index 96% rename from src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java rename to src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index be17167a..ba270e77 100644 --- a/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -26,11 +26,11 @@ import me.libraryaddict.disguise.utilities.ClassGetter; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -public class RadiusDisguiseCommand extends BaseDisguiseCommand implements TabCompleter { +public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { private int maxRadius = 30; private ArrayList> validClasses = new ArrayList<>(); - public RadiusDisguiseCommand(int maxRadius) { + public DisguiseRadiusCommand(int maxRadius) { this.maxRadius = maxRadius; for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) { if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseViewSelf.java b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java similarity index 91% rename from src/me/libraryaddict/disguise/commands/DisguiseViewSelf.java rename to src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java index 91ddc1c5..84d0ecf3 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseViewSelf.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java @@ -11,7 +11,7 @@ import me.libraryaddict.disguise.DisguiseAPI; /** * @author Navid */ -public class DisguiseViewSelf implements CommandExecutor { +public class DisguiseViewSelfCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 15d7b980..fdbbf93c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -215,8 +215,16 @@ public abstract class Disguise { DisguiseUtilities.refreshTrackers(disguise); } } + else if (getType() == DisguiseType.EVOKER_FANGS) { + refreshDisguise++; - if (getType() == DisguiseType.ITEM_FRAME) { + if (refreshDisguise % 20 == 0) { + refreshDisguise = 0; + + DisguiseUtilities.refreshTrackers(disguise); + } + } + else if (getType() == DisguiseType.ITEM_FRAME) { Location loc = getEntity().getLocation(); int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4; diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 2a6e85b2..701153f6 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -58,8 +58,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; -public class DisguiseUtilities -{ +public class DisguiseUtilities { public static final Random random = new Random(); /** * This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of @@ -86,10 +85,8 @@ public class DisguiseUtilities private static Thread mainThread; private static PacketContainer spawnChunk; - static - { - try - { + static { + try { Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null); Object world = ((List) server.getClass().getField("worlds").get(server)).get(0); @@ -111,11 +108,9 @@ public class DisguiseUtilities Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class); Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class); - for (BlockFace face : new BlockFace[] - { - BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH - }) - { + for (BlockFace face : new BlockFace[] { + BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH + }) { int x = 1 + face.getModX(); int z = 1 + face.getModZ(); @@ -141,27 +136,21 @@ public class DisguiseUtilities mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer()); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } - public static boolean addClonedDisguise(String key, Disguise disguise) - { - if (DisguiseConfig.getMaxClonedDisguises() > 0) - { - if (clonedDisguises.containsKey(key)) - { + public static boolean addClonedDisguise(String key, Disguise disguise) { + if (DisguiseConfig.getMaxClonedDisguises() > 0) { + if (clonedDisguises.containsKey(key)) { clonedDisguises.remove(key); } - else if (DisguiseConfig.getMaxClonedDisguises() == clonedDisguises.size()) - { + else if (DisguiseConfig.getMaxClonedDisguises() == clonedDisguises.size()) { clonedDisguises.remove(clonedDisguises.keySet().iterator().next()); } - if (DisguiseConfig.getMaxClonedDisguises() > clonedDisguises.size()) - { + if (DisguiseConfig.getMaxClonedDisguises() > clonedDisguises.size()) { clonedDisguises.put(key, disguise); return true; } @@ -170,10 +159,8 @@ public class DisguiseUtilities return false; } - public static void addDisguise(UUID entityId, TargetedDisguise disguise) - { - if (!getDisguises().containsKey(entityId)) - { + public static void addDisguise(UUID entityId, TargetedDisguise disguise) { + if (!getDisguises().containsKey(entityId)) { getDisguises().put(entityId, new HashSet()); } @@ -181,38 +168,28 @@ public class DisguiseUtilities checkConflicts(disguise, null); - if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) - { + if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) { doBoundingBox(disguise); } } - public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) - { - if (!futureDisguises.containsKey(entityId)) - { + public static void addFutureDisguise(final int entityId, final TargetedDisguise disguise) { + if (!futureDisguises.containsKey(entityId)) { futureDisguises.put(entityId, new HashSet()); } futureDisguises.get(entityId).add(disguise); - final BukkitRunnable runnable = new BukkitRunnable() - { + final BukkitRunnable runnable = new BukkitRunnable() { @Override - public void run() - { - if (futureDisguises.containsKey(entityId) && futureDisguises.get(entityId).contains(disguise)) - { - for (World world : Bukkit.getWorlds()) - { - for (Entity entity : world.getEntities()) - { - if (entity.getEntityId() == entityId) - { + public void run() { + if (futureDisguises.containsKey(entityId) && futureDisguises.get(entityId).contains(disguise)) { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getEntityId() == entityId) { UUID uniqueId = entity.getUniqueId(); - for (TargetedDisguise disguise : futureDisguises.remove(entityId)) - { + for (TargetedDisguise disguise : futureDisguises.remove(entityId)) { addDisguise(uniqueId, disguise); } @@ -223,8 +200,7 @@ public class DisguiseUtilities futureDisguises.get(entityId).remove(disguise); - if (futureDisguises.get(entityId).isEmpty()) - { + if (futureDisguises.get(entityId).isEmpty()) { futureDisguises.remove(entityId); } } @@ -234,8 +210,7 @@ public class DisguiseUtilities runnable.runTaskLater(libsDisguises, 20); } - public static void addGameProfile(String string, WrappedGameProfile gameProfile) - { + public static void addGameProfile(String string, WrappedGameProfile gameProfile) { getGameProfiles().put(string, gameProfile); getAddedByPlugins().add(string.toLowerCase()); } @@ -244,81 +219,60 @@ public class DisguiseUtilities * If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the * observers in the disguise don't see any other disguise. */ - public static void checkConflicts(TargetedDisguise disguise, String name) - { + public static void checkConflicts(TargetedDisguise disguise, String name) { // If the disguise is being used.. Else we may accidentally undisguise something else - if (DisguiseAPI.isDisguiseInUse(disguise)) - { + if (DisguiseAPI.isDisguiseInUse(disguise)) { Iterator disguiseItel = getDisguises().get(disguise.getEntity().getUniqueId()).iterator(); // Iterate through the disguises - while (disguiseItel.hasNext()) - { + while (disguiseItel.hasNext()) { TargetedDisguise d = disguiseItel.next(); // Make sure the disguise isn't the same thing - if (d != disguise) - { + if (d != disguise) { // 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 (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 (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) - { + if (name != null) { d.removePlayer(name); } - else - { - for (String playername : disguise.getObservers()) - { + else { + for (String playername : disguise.getObservers()) { d.silentlyRemovePlayer(playername); } } } - else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) - { + 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)) - { + if (name != null) { + if (!disguise.getObservers().contains(name)) { d.removePlayer(name); } } - else - { - for (String playername : new ArrayList<>(d.getObservers())) - { - if (!disguise.getObservers().contains(playername)) - { + else { + for (String playername : new ArrayList<>(d.getObservers())) { + if (!disguise.getObservers().contains(playername)) { d.silentlyRemovePlayer(playername); } } } } } - else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) - { + 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) - { + 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) - { + if (name != null) { d.addPlayer(name); } - else - { - for (String playername : disguise.getObservers()) - { + else { + for (String playername : disguise.getObservers()) { d.silentlyAddPlayer(playername); } } } - else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) - { + 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. @@ -338,13 +292,11 @@ public class DisguiseUtilities /** * Sends entity removal packets, as this disguise was removed */ - public static void destroyEntity(TargetedDisguise disguise) - { + public static void destroyEntity(TargetedDisguise disguise) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); - try - { + try { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry == null) @@ -359,61 +311,49 @@ public class DisguiseUtilities PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); - destroyPacket.getIntegerArrays().write(0, new int[] - { - disguise.getEntity().getEntityId() - }); + destroyPacket.getIntegerArrays().write(0, new int[] { + disguise.getEntity().getEntityId() + }); - for (Object p : trackedPlayers) - { + for (Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); - if (player == disguise.getEntity() || disguise.canSee(player)) - { + if (player == disguise.getEntity() || disguise.canSee(player)) { ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); } } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } - public static void doBoundingBox(TargetedDisguise disguise) - { + public static void doBoundingBox(TargetedDisguise disguise) { Entity entity = disguise.getEntity(); - if (entity != null) - { - if (isDisguiseInUse(disguise)) - { + if (entity != null) { + if (isDisguiseInUse(disguise)) { DisguiseValues disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType()); FakeBoundingBox disguiseBox = disguiseValues.getAdultBox(); - if (disguiseValues.getBabyBox() != null) - { + if (disguiseValues.getBabyBox() != null) { if ((disguise.getWatcher() instanceof AgeableWatcher && ((AgeableWatcher) disguise.getWatcher()).isBaby()) || (disguise.getWatcher() instanceof ZombieWatcher - && ((ZombieWatcher) disguise.getWatcher()).isBaby())) - { + && ((ZombieWatcher) disguise.getWatcher()).isBaby())) { disguiseBox = disguiseValues.getBabyBox(); } } ReflectionManager.setBoundingBox(entity, disguiseBox); } - else - { + else { DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); FakeBoundingBox entityBox = entityValues.getAdultBox(); - if (entityValues.getBabyBox() != null) - { + if (entityValues.getBabyBox() != null) { if ((entity instanceof Ageable && !((Ageable) entity).isAdult()) - || (entity instanceof Zombie && ((Zombie) entity).isBaby())) - { + || (entity instanceof Zombie && ((Zombie) entity).isBaby())) { entityBox = entityValues.getBabyBox(); } } @@ -423,13 +363,11 @@ public class DisguiseUtilities } } - public static HashSet getAddedByPlugins() - { + public static HashSet getAddedByPlugins() { return addedByPlugins; } - public static int getChunkCord(int blockCord) - { + public static int getChunkCord(int blockCord) { int cord = (int) Math.floor(blockCord / 16D) - 17; cord -= (cord % 8); @@ -437,14 +375,12 @@ public class DisguiseUtilities return cord; } - public static PacketContainer[] getBedChunkPacket(Location newLoc, Location oldLoc) - { + public static PacketContainer[] getBedChunkPacket(Location newLoc, Location oldLoc) { int i = 0; PacketContainer[] packets = new PacketContainer[(newLoc != null ? 1 : 0) + (oldLoc != null ? 1 : 0)]; - if (oldLoc != null) - { + if (oldLoc != null) { PacketContainer despawn = new PacketContainer(Server.UNLOAD_CHUNK); StructureModifier modifier = despawn.getModifier(); @@ -455,8 +391,7 @@ public class DisguiseUtilities packets[i++] = despawn; } - if (newLoc != null) - { + if (newLoc != null) { PacketContainer spawn = spawnChunk.shallowClone(); StructureModifier modifier = spawn.getModifier(); @@ -470,8 +405,7 @@ public class DisguiseUtilities return packets; } - public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation, PlayerDisguise disguise) - { + public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation, PlayerDisguise disguise) { int entity = disguise.getEntity().getEntityId(); PlayerWatcher watcher = disguise.getWatcher(); @@ -493,24 +427,20 @@ public class DisguiseUtilities doubles.write(1, PacketsManager.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY()); doubles.write(2, sleepingLocation.getZ()); - return new PacketContainer[] - { - setBed, teleport - }; + return new PacketContainer[] { + setBed, teleport + }; } - public static Disguise getClonedDisguise(String key) - { - if (clonedDisguises.containsKey(key)) - { + public static Disguise getClonedDisguise(String key) { + if (clonedDisguises.containsKey(key)) { return clonedDisguises.get(key).clone(); } return null; } - public static PacketContainer getDestroyPacket(int... ids) - { + public static PacketContainer getDestroyPacket(int... ids) { PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); destroyPacket.getIntegerArrays().write(0, ids); @@ -518,24 +448,18 @@ public class DisguiseUtilities return destroyPacket; } - public static TargetedDisguise getDisguise(Player observer, Entity entity) - { + public static TargetedDisguise getDisguise(Player observer, Entity entity) { UUID entityId = entity.getUniqueId(); - if (futureDisguises.containsKey(entity.getEntityId())) - { - for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) - { + if (futureDisguises.containsKey(entity.getEntityId())) { + for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) { addDisguise(entityId, disguise); } } - if (getDisguises().containsKey(entityId)) - { - for (TargetedDisguise disguise : getDisguises().get(entityId)) - { - if (disguise.canSee(observer)) - { + if (getDisguises().containsKey(entityId)) { + for (TargetedDisguise disguise : getDisguises().get(entityId)) { + if (disguise.canSee(observer)) { return disguise; } } @@ -544,15 +468,12 @@ public class DisguiseUtilities return null; } - public static HashMap> getDisguises() - { + public static HashMap> getDisguises() { return disguisesInUse; } - public static TargetedDisguise[] getDisguises(UUID entityId) - { - if (getDisguises().containsKey(entityId)) - { + public static TargetedDisguise[] getDisguises(UUID entityId) { + if (getDisguises().containsKey(entityId)) { HashSet disguises = getDisguises().get(entityId); return disguises.toArray(new TargetedDisguise[disguises.size()]); @@ -561,31 +482,24 @@ public class DisguiseUtilities return new TargetedDisguise[0]; } - public static HashMap> getFutureDisguises() - { + public static HashMap> getFutureDisguises() { return futureDisguises; } - public static WrappedGameProfile getGameProfile(String playerName) - { + public static WrappedGameProfile getGameProfile(String playerName) { return gameProfiles.get(playerName.toLowerCase()); } - public static HashMap getGameProfiles() - { + public static HashMap getGameProfiles() { return gameProfiles; } - public static TargetedDisguise getMainDisguise(UUID entityId) - { + public static TargetedDisguise getMainDisguise(UUID entityId) { TargetedDisguise toReturn = null; - if (getDisguises().containsKey(entityId)) - { - for (TargetedDisguise disguise : getDisguises().get(entityId)) - { - if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) - { + if (getDisguises().containsKey(entityId)) { + for (TargetedDisguise disguise : getDisguises().get(entityId)) { + if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { return disguise; } @@ -602,8 +516,7 @@ public class DisguiseUtilities * @param disguise * @return */ - public static List getPerverts(Disguise disguise) - { + public static List getPerverts(Disguise disguise) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); @@ -612,56 +525,46 @@ public class DisguiseUtilities List players = new ArrayList<>(); - try - { + try { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); - if (entityTrackerEntry != null) - { + if (entityTrackerEntry != null) { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException - for (Object p : trackedPlayers) - { + for (Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); - if (((TargetedDisguise) disguise).canSee(player)) - { + if (((TargetedDisguise) disguise).canSee(player)) { players.add(player); } } } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } return players; } - public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) - { + public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) { final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName(); final boolean remove = getAddedByPlugins().contains(nameToFetch.toLowerCase()); - return getProfileFromMojang(nameToFetch, new LibsProfileLookup() - { + return getProfileFromMojang(nameToFetch, new LibsProfileLookup() { @Override - public void onLookup(WrappedGameProfile gameProfile) - { - if (remove) - { + public void onLookup(WrappedGameProfile gameProfile) { + if (remove) { getAddedByPlugins().remove(nameToFetch.toLowerCase()); } if (DisguiseAPI.isDisguiseInUse(disguise) && (!gameProfile.getName().equals(disguise.getSkin() != null ? disguise.getSkin() : disguise.getName()) - || !gameProfile.getProperties().isEmpty())) - { + || !gameProfile.getProperties().isEmpty())) { disguise.setGameProfile(gameProfile); DisguiseUtilities.refreshTrackers(disguise); @@ -676,8 +579,7 @@ public class DisguiseUtilities * @param obj * @return */ - private static boolean isHashSet(Object obj) - { + private static boolean isHashSet(Object obj) { if (obj instanceof HashSet) return true; // It's Spigot/Bukkit @@ -691,8 +593,7 @@ public class DisguiseUtilities * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup * using schedulers. The runnable is run once the GameProfile has been successfully dealt with */ - public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) - { + public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) { return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, true); } @@ -701,79 +602,60 @@ public class DisguiseUtilities * using schedulers. The runnable is run once the GameProfile has been successfully dealt with */ public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn, - boolean contactMojang) - { + boolean contactMojang) { return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang); } - private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable, boolean contactMojang) - { + private static WrappedGameProfile getProfileFromMojang(final String origName, final Object runnable, boolean contactMojang) { final String playerName = origName.toLowerCase(); - if (gameProfiles.containsKey(playerName)) - { - if (gameProfiles.get(playerName) != null) - { + if (gameProfiles.containsKey(playerName)) { + if (gameProfiles.get(playerName) != null) { return gameProfiles.get(playerName); } } - else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) - { + else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) { getAddedByPlugins().add(playerName); Player player = Bukkit.getPlayerExact(playerName); - if (player != null) - { + if (player != null) { WrappedGameProfile gameProfile = ReflectionManager.getGameProfile(player); - if (!gameProfile.getProperties().isEmpty()) - { + if (!gameProfile.getProperties().isEmpty()) { gameProfiles.put(playerName, gameProfile); return gameProfile; } } - if (contactMojang) - { + if (contactMojang) { // Add null so that if this is called again. I already know I'm doing something about it gameProfiles.put(playerName, null); - Bukkit.getScheduler().runTaskAsynchronously(libsDisguises, new Runnable() - { + Bukkit.getScheduler().runTaskAsynchronously(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { final WrappedGameProfile gameProfile = lookupGameProfile(origName); - Bukkit.getScheduler().runTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { @Override - public void run() - { - if (gameProfile.getProperties().isEmpty()) - { + public void run() { + if (gameProfile.getProperties().isEmpty()) { return; } - if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) - { + if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { gameProfiles.put(playerName, gameProfile); } - if (runnables.containsKey(playerName)) - { - for (Object obj : runnables.remove(playerName)) - { - if (obj instanceof Runnable) - { + if (runnables.containsKey(playerName)) { + for (Object obj : runnables.remove(playerName)) { + if (obj instanceof Runnable) { ((Runnable) obj).run(); } - else if (obj instanceof LibsProfileLookup) - { + else if (obj instanceof LibsProfileLookup) { ((LibsProfileLookup) obj).onLookup(gameProfile); } } @@ -781,10 +663,8 @@ public class DisguiseUtilities } }); } - catch (Exception e) - { - if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) - { + catch (Exception e) { + if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) { gameProfiles.remove(playerName); getAddedByPlugins().remove(playerName); } @@ -796,15 +676,12 @@ public class DisguiseUtilities }); } } - else - { + else { return ReflectionManager.getGameProfile(null, origName); } - if (runnable != null) - { - if (!runnables.containsKey(playerName)) - { + if (runnable != null) { + if (!runnables.containsKey(playerName)) { runnables.put(playerName, new ArrayList<>()); } @@ -818,8 +695,7 @@ public class DisguiseUtilities * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup * using schedulers. The runnable is run once the GameProfile has been successfully dealt with */ - public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) - { + public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) { return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, true); } @@ -827,28 +703,24 @@ public class DisguiseUtilities * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup * using schedulers. The runnable is run once the GameProfile has been successfully dealt with */ - public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn, boolean contactMojang) - { + public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn, + boolean contactMojang) { return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang); } - public static HashSet getSelfDisguised() - { + public static HashSet getSelfDisguised() { return selfDisguised; } - public static boolean hasGameProfile(String playerName) - { + public static boolean hasGameProfile(String playerName) { return getGameProfile(playerName) != null; } - public static void init(LibsDisguises disguises) - { + public static void init(LibsDisguises disguises) { libsDisguises = disguises; } - public static boolean isDisguiseInUse(Disguise disguise) - { + public static boolean isDisguiseInUse(Disguise disguise) { return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId()) && getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise); } @@ -856,56 +728,46 @@ public class DisguiseUtilities /** * This is called on a thread as it is thread blocking */ - public static WrappedGameProfile lookupGameProfile(String playerName) - { + public static WrappedGameProfile lookupGameProfile(String playerName) { return ReflectionManager.getSkullBlob(ReflectionManager.grabProfileAddUUID(playerName)); } /** * Resends the entity to this specific player */ - public static void refreshTracker(final TargetedDisguise disguise, String player) - { + public static void refreshTracker(final TargetedDisguise disguise, String player) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (disguise.getEntity() == null || !disguise.getEntity().isValid()) return; - try - { + try { PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player - && disguise.getEntity().getName().equalsIgnoreCase(player)) - { + && disguise.getEntity().getName().equalsIgnoreCase(player)) { removeSelfDisguise((Player) disguise.getEntity()); - if (disguise.isSelfDisguiseVisible()) - { + if (disguise.isSelfDisguiseVisible()) { selfDisguised.add(disguise.getEntity().getUniqueId()); } ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } }, 2); } - else - { + else { final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); if (entityTrackerEntry == null) @@ -922,8 +784,7 @@ public class DisguiseUtilities trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException - for (final Object p : trackedPlayers) - { + for (final Object p : trackedPlayers) { Player pl = (Player) ReflectionManager.getBukkitEntity(p); if (!player.equalsIgnoreCase((pl).getName())) @@ -933,18 +794,14 @@ public class DisguiseUtilities ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { updatePlayer.invoke(entityTrackerEntry, p); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -965,21 +822,17 @@ public class DisguiseUtilities /** * A convenience method for me to refresh trackers in other plugins */ - public static void refreshTrackers(Entity entity) - { + public static void refreshTrackers(Entity entity) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); - if (entity.isValid()) - { - try - { + if (entity.isValid()) { + try { PacketContainer destroyPacket = getDestroyPacket(entity.getEntityId()); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity); - if (entityTrackerEntry != null) - { + if (entityTrackerEntry != null) { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); @@ -991,27 +844,21 @@ public class DisguiseUtilities trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException - for (final Object p : trackedPlayers) - { + for (final Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); - if (player != entity) - { + if (player != entity) { clear.invoke(entityTrackerEntry, p); ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { updatePlayer.invoke(entityTrackerEntry, p); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -1020,8 +867,7 @@ public class DisguiseUtilities } } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -1030,35 +876,28 @@ public class DisguiseUtilities /** * Resends the entity to all the watching players, which is where the magic begins */ - public static void refreshTrackers(final TargetedDisguise disguise) - { + public static void refreshTrackers(final TargetedDisguise disguise) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); - if (disguise.getEntity().isValid()) - { + if (disguise.getEntity().isValid()) { PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); - try - { - if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) - { + + try { + if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) { removeSelfDisguise((Player) disguise.getEntity()); selfDisguised.add(disguise.getEntity().getUniqueId()); ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -1067,8 +906,7 @@ public class DisguiseUtilities final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); - if (entityTrackerEntry != null) - { + if (entityTrackerEntry != null) { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); @@ -1080,28 +918,22 @@ public class DisguiseUtilities trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); - for (final Object p : trackedPlayers) - { + for (final Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); - if (disguise.getEntity() != player && disguise.canSee(player)) - { + if (disguise.getEntity() != player && disguise.canSee(player)) { clear.invoke(entityTrackerEntry, p); ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { updatePlayer.invoke(entityTrackerEntry, p); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -1112,27 +944,22 @@ public class DisguiseUtilities } catch ( - Exception ex) - { + Exception ex) { ex.printStackTrace(); } } } - public static boolean removeDisguise(TargetedDisguise disguise) - { + public static boolean removeDisguise(TargetedDisguise disguise) { UUID entityId = disguise.getEntity().getUniqueId(); - if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) - { - if (getDisguises().get(entityId).isEmpty()) - { + if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) { + if (getDisguises().get(entityId).isEmpty()) { getDisguises().remove(entityId); } - if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) - { + if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) { doBoundingBox(disguise); } @@ -1142,30 +969,25 @@ public class DisguiseUtilities return false; } - public static void removeGameProfile(String string) - { + public static void removeGameProfile(String string) { gameProfiles.remove(string.toLowerCase()); } - public static void removeSelfDisguise(Player player) - { + public static void removeSelfDisguise(Player player) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); - if (!selfDisguised.contains(player.getUniqueId())) - { + if (!selfDisguised.contains(player.getUniqueId())) { return; } // Send a packet to destroy the fake entity PacketContainer packet = getDestroyPacket(DisguiseAPI.getSelfDisguiseId()); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } @@ -1173,8 +995,7 @@ public class DisguiseUtilities Scoreboard scoreboard = player.getScoreboard(); Team t; - if ((t = scoreboard.getTeam("LDPushing")) != null) - { + if ((t = scoreboard.getTeam("LDPushing")) != null) { t.removeEntry(player.getName()); } @@ -1184,44 +1005,37 @@ public class DisguiseUtilities selfDisguised.remove(player.getUniqueId()); // Get the entity tracker - try - { + try { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); - if (entityTrackerEntry != null) - { + if (entityTrackerEntry != null) { Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") .get(entityTrackerEntry); // If the tracker exists. Remove himself from his tracker - if (isHashSet(trackedPlayersObj)) - { + if (isHashSet(trackedPlayersObj)) { ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry)) .remove(ReflectionManager.getNmsEntity(player)); } - else - { + else { ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") .get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); } } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } // Resend entity metadata else he will be invisible to himself until its resent - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, ProtocolLibrary.getProtocolManager() .createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true) .createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true)); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } @@ -1231,34 +1045,27 @@ public class DisguiseUtilities /** * Sends the self disguise to the player */ - public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) - { + public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) { if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); - try - { + try { if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible() - || !disguise.canSee(player)) - { + || !disguise.canSee(player)) { return; } Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player); - if (entityTrackerEntry == null) - { + if (entityTrackerEntry == null) { // A check incase the tracker is null. // If it is, then this method will be run again in one tick. Which is when it should be constructed. // Else its going to run in a infinite loop hue hue hue.. // At least until this disguise is discarded - Bukkit.getScheduler().runTask(libsDisguises, new Runnable() - { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { @Override - public void run() - { - if (DisguiseAPI.getDisguise(player, player) == disguise) - { + public void run() { + if (DisguiseAPI.getDisguise(player, player) == disguise) { sendSelfDisguise(player, disguise); } } @@ -1271,13 +1078,11 @@ public class DisguiseUtilities Scoreboard scoreboard = player.getScoreboard(); Team t; - if ((t = scoreboard.getTeam("LDPushing")) == null) - { + if ((t = scoreboard.getTeam("LDPushing")) == null) { t = scoreboard.registerNewTeam("LDPushing"); } - if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) - { + if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) { t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); t.setCanSeeFriendlyInvisibles(false); } @@ -1290,13 +1095,11 @@ public class DisguiseUtilities .get(entityTrackerEntry); // Check for code differences in PaperSpigot vs Spigot - if (isHashSet(trackedPlayersObj)) - { + if (isHashSet(trackedPlayersObj)) { ((Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry)) .add(ReflectionManager.getNmsEntity(player)); } - else - { + else { ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") .get(entityTrackerEntry)).put(ReflectionManager.getNmsEntity(player), true); } @@ -1314,20 +1117,17 @@ public class DisguiseUtilities boolean isMoving = false; - try - { + try { Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving"); field.setAccessible(true); isMoving = field.getBoolean(entityTrackerEntry); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } // Send the velocity packets - if (isMoving) - { + if (isMoving) { Vector velocity = player.getVelocity(); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(), @@ -1336,13 +1136,11 @@ public class DisguiseUtilities } // Why the hell would he even need this. Meh. - if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) - { + if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) { sendSelfPacket(player, manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player, player.getVehicle()) .createPacket(0, player, player.getVehicle())); } - else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) - { + else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) { sendSelfPacket(player, manager.createPacketConstructor(Server.ATTACH_ENTITY, 0, player.getPassenger(), player) .createPacket(0, player.getPassenger(), player)); } @@ -1387,8 +1185,7 @@ public class DisguiseUtilities Location loc = player.getLocation(); // If the disguised is sleeping for w/e reason - if (player.isSleeping()) - { + if (player.isSleeping()) { sendSelfPacket(player, manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0)) .createPacket(player, @@ -1396,48 +1193,41 @@ public class DisguiseUtilities } // Resend any active potion effects - for (PotionEffect potionEffect : player.getActivePotionEffects()) - { + for (PotionEffect potionEffect : player.getActivePotionEffects()) { Object mobEffect = ReflectionManager.createMobEffect(potionEffect); sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EFFECT, player.getEntityId(), mobEffect) .createPacket(player.getEntityId(), mobEffect)); } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } - public static LibsDisguises getPlugin() - { + public static LibsDisguises getPlugin() { return libsDisguises; } /** * Method to send a packet to the self disguise, translate his entity ID to the fake id. */ - private static void sendSelfPacket(final Player player, final PacketContainer packet) - { + private static void sendSelfPacket(final Player player, final PacketContainer packet) { final Disguise disguise = DisguiseAPI.getDisguise(player, player); // If disguised. - if (disguise == null) - { + if (disguise == null) { return; } LibsPackets transformed = PacketsManager.transformPacket(packet, disguise, player, player); - try - { + try { if (transformed.isUnhandled()) transformed.addPacket(packet); transformed.setPacketType(packet.getType()); - for (PacketContainer p : transformed.getPackets()) - { + for (PacketContainer p : transformed.getPackets()) { p = p.deepClone(); p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false); @@ -1445,8 +1235,7 @@ public class DisguiseUtilities transformed.sendDelayed(player); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } @@ -1456,22 +1245,19 @@ public class DisguiseUtilities * * @param disguise */ - public static void setupFakeDisguise(final Disguise disguise) - { + public static void setupFakeDisguise(final Disguise disguise) { Entity e = disguise.getEntity(); // If the disguises entity is null, or the disguised entity isn't a player return if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) - || !getDisguises().get(e.getUniqueId()).contains(disguise)) - { + || !getDisguises().get(e.getUniqueId()).contains(disguise)) { return; } Player player = (Player) e; // Check if he can even see this.. - if (!((TargetedDisguise) disguise).canSee(player)) - { + if (!((TargetedDisguise) disguise).canSee(player)) { return; } @@ -1479,8 +1265,8 @@ public class DisguiseUtilities DisguiseUtilities.removeSelfDisguise(player); // If the disguised player can't see himself. Return - if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null) - { + if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() + || player.getVehicle() != null) { return; } @@ -1490,10 +1276,8 @@ public class DisguiseUtilities sendSelfDisguise(player, (TargetedDisguise) disguise); - if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) - { - if (PacketsManager.isInventoryListenerEnabled()) - { + if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) { + if (PacketsManager.isInventoryListenerEnabled()) { player.updateInventory(); } } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index c3ebc3d7..3f12abd0 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -186,7 +186,6 @@ public class PacketsManager { ItemStack itemstack = disguise.getWatcher().getItemStack(slot); if (itemstack == null || itemstack.getType() == Material.AIR) { - System.out.println("Not wearing anything for " + slot.name()); continue; }