Now able to hide disguised players from tab, show player disguises tab
This commit is contained in:
		| @@ -98,6 +98,12 @@ UndisguiseOnWorldChange: false | |||||||
| # Contact Mojang's servers? Disabling this option will disable player skin disguises! | # Contact Mojang's servers? Disabling this option will disable player skin disguises! | ||||||
| ContactMojangServers: true | ContactMojangServers: true | ||||||
|  |  | ||||||
|  | # Hide players in tab when disguised? This means a disguised player cannot be seen when you press tab! This can be toggled on/off per disguise | ||||||
|  | HideDisguisedPlayersTab: false | ||||||
|  |  | ||||||
|  | # Always show player disguises in tab? The names will continue to appear in tab until the disguise is removed. | ||||||
|  | ShowPlayerDisguisesTab: false | ||||||
|  |  | ||||||
| # This will help performance, especially with CPU | # This will help performance, especially with CPU | ||||||
| # Due to safety reasons, self disguises can never have their packets disabled. | # Due to safety reasons, self disguises can never have their packets disabled. | ||||||
| PacketsEnabled: | PacketsEnabled: | ||||||
|   | |||||||
| @@ -5,8 +5,7 @@ import org.bukkit.configuration.ConfigurationSection; | |||||||
|  |  | ||||||
| import me.libraryaddict.disguise.utilities.PacketsManager; | import me.libraryaddict.disguise.utilities.PacketsManager; | ||||||
|  |  | ||||||
| public class DisguiseConfig | public class DisguiseConfig { | ||||||
| { |  | ||||||
|  |  | ||||||
|     private static boolean animationEnabled; |     private static boolean animationEnabled; | ||||||
|     private static boolean bedEnabled; |     private static boolean bedEnabled; | ||||||
| @@ -44,40 +43,50 @@ public class DisguiseConfig | |||||||
|             + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; |             + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; | ||||||
|     private static String updateNotificationPermission; |     private static String updateNotificationPermission; | ||||||
|     private static boolean witherSkullEnabled; |     private static boolean witherSkullEnabled; | ||||||
|  |     private static boolean hideDisguisedPlayers; | ||||||
|  |     private static boolean displayPlayerDisguisesInTab; | ||||||
|  |  | ||||||
|     public static String getDisguiseBlownMessage() |     public static void setHideDisguisedPlayers(boolean hideDisguisedPlayersInTab) { | ||||||
|     { |         hideDisguisedPlayers = hideDisguisedPlayersInTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static void setShowDisguisedPlayersInTab(boolean displayPlayerDisguisesInTablist) { | ||||||
|  |         displayPlayerDisguisesInTab = displayPlayerDisguisesInTablist; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static boolean isHideDisguisedPlayers() { | ||||||
|  |         return hideDisguisedPlayers; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static boolean isShowDisguisedPlayersInTab() { | ||||||
|  |         return displayPlayerDisguisesInTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getDisguiseBlownMessage() { | ||||||
|         return disguiseBlownMessage; |         return disguiseBlownMessage; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getDisguiseCloneExpire() |     public static int getDisguiseCloneExpire() { | ||||||
|     { |  | ||||||
|         return disguiseCloneExpire; |         return disguiseCloneExpire; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getDisguiseEntityExpire() |     public static int getDisguiseEntityExpire() { | ||||||
|     { |  | ||||||
|         return disguiseEntityExpire; |         return disguiseEntityExpire; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getMaxClonedDisguises() |     public static int getMaxClonedDisguises() { | ||||||
|     { |  | ||||||
|         return maxClonedDisguises; |         return maxClonedDisguises; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String getUpdateMessage() |     public static String getUpdateMessage() { | ||||||
|     { |  | ||||||
|         return updateMessage; |         return updateMessage; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String getUpdateNotificationPermission() |     public static String getUpdateNotificationPermission() { | ||||||
|     { |  | ||||||
|         return updateNotificationPermission; |         return updateNotificationPermission; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void initConfig(ConfigurationSection config) |     public static void initConfig(ConfigurationSection config) { | ||||||
|     { |  | ||||||
|  |  | ||||||
|         setSoundsEnabled(config.getBoolean("DisguiseSounds")); |         setSoundsEnabled(config.getBoolean("DisguiseSounds")); | ||||||
|         setVelocitySent(config.getBoolean("SendVelocity")); |         setVelocitySent(config.getBoolean("SendVelocity")); | ||||||
|         setViewDisguises(config.getBoolean("ViewSelfDisguises")); // Since we can now toggle, the view disguises listener must |         setViewDisguises(config.getBoolean("ViewSelfDisguises")); // Since we can now toggle, the view disguises listener must | ||||||
| @@ -114,134 +123,112 @@ public class DisguiseConfig | |||||||
|         setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); |         setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); | ||||||
|         setUpdateNotificationPermission(config.getString("Permission")); |         setUpdateNotificationPermission(config.getString("Permission")); | ||||||
|         setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); |         setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); | ||||||
|  |         setHideDisguisedPlayers(config.getBoolean("HideDisguisedPlayersFromTab")); | ||||||
|  |         setShowDisguisedPlayersInTab(config.getBoolean("ShowPlayerDisguisesInTab")); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isAnimationPacketsEnabled() |     public static boolean isAnimationPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return animationEnabled; |         return animationEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isBedPacketsEnabled() |     public static boolean isBedPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return bedEnabled; |         return bedEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isCollectPacketsEnabled() |     public static boolean isCollectPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return collectEnabled; |         return collectEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isDisguiseBlownOnAttack() |     public static boolean isDisguiseBlownOnAttack() { | ||||||
|     { |  | ||||||
|         return blowDisguisesOnAttack; |         return blowDisguisesOnAttack; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isEntityAnimationsAdded() |     public static boolean isEntityAnimationsAdded() { | ||||||
|     { |  | ||||||
|         return entityAnimationsAdded; |         return entityAnimationsAdded; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isEntityStatusPacketsEnabled() |     public static boolean isEntityStatusPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return entityStatusEnabled; |         return entityStatusEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isEquipmentPacketsEnabled() |     public static boolean isEquipmentPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return equipmentEnabled; |         return equipmentEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around |      * Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around | ||||||
|      */ |      */ | ||||||
|     public static boolean isHidingArmorFromSelf() |     public static boolean isHidingArmorFromSelf() { | ||||||
|     { |  | ||||||
|         return hidingArmor; |         return hidingArmor; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise |      * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise | ||||||
|      */ |      */ | ||||||
|     public static boolean isHidingHeldItemFromSelf() |     public static boolean isHidingHeldItemFromSelf() { | ||||||
|     { |  | ||||||
|         return hidingHeldItem; |         return hidingHeldItem; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isKeepDisguiseOnEntityDespawn() |     public static boolean isKeepDisguiseOnEntityDespawn() { | ||||||
|     { |  | ||||||
|         return keepDisguiseEntityDespawn; |         return keepDisguiseEntityDespawn; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isKeepDisguiseOnPlayerDeath() |     public static boolean isKeepDisguiseOnPlayerDeath() { | ||||||
|     { |  | ||||||
|         return keepDisguisePlayerDeath; |         return keepDisguisePlayerDeath; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isKeepDisguiseOnPlayerLogout() |     public static boolean isKeepDisguiseOnPlayerLogout() { | ||||||
|     { |  | ||||||
|         return keepDisguisePlayerLogout; |         return keepDisguisePlayerLogout; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isMaxHealthDeterminedByDisguisedEntity() |     public static boolean isMaxHealthDeterminedByDisguisedEntity() { | ||||||
|     { |  | ||||||
|         return maxHealthIsDisguisedEntity; |         return maxHealthIsDisguisedEntity; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isMetadataPacketsEnabled() |     public static boolean isMetadataPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return sendsEntityMetadata; |         return sendsEntityMetadata; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isMiscDisguisesForLivingEnabled() |     public static boolean isMiscDisguisesForLivingEnabled() { | ||||||
|     { |  | ||||||
|         return miscDisguisesForLivingEnabled; |         return miscDisguisesForLivingEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isModifyBoundingBox() |     public static boolean isModifyBoundingBox() { | ||||||
|     { |  | ||||||
|         return modifyBoundingBox; |         return modifyBoundingBox; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isMonstersIgnoreDisguises() |     public static boolean isMonstersIgnoreDisguises() { | ||||||
|     { |  | ||||||
|         return targetDisguises; |         return targetDisguises; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isMovementPacketsEnabled() |     public static boolean isMovementPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return movementEnabled; |         return movementEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isNameAboveHeadAlwaysVisible() |     public static boolean isNameAboveHeadAlwaysVisible() { | ||||||
|     { |  | ||||||
|         return showNameAboveHeadAlwaysVisible; |         return showNameAboveHeadAlwaysVisible; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isNameOfPlayerShownAboveDisguise() |     public static boolean isNameOfPlayerShownAboveDisguise() { | ||||||
|     { |  | ||||||
|         return showNameAboveHead; |         return showNameAboveHead; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isSelfDisguisesSoundsReplaced() |     public static boolean isSelfDisguisesSoundsReplaced() { | ||||||
|     { |  | ||||||
|         return hearSelfDisguise; |         return hearSelfDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isSheepDyeable() |     public static boolean isSheepDyeable() { | ||||||
|     { |  | ||||||
|         return colorizeSheep; |         return colorizeSheep; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Is the sound packets caught and modified |      * Is the sound packets caught and modified | ||||||
|      */ |      */ | ||||||
|     public static boolean isSoundEnabled() |     public static boolean isSoundEnabled() { | ||||||
|     { |  | ||||||
|         return PacketsManager.isHearDisguisesEnabled(); |         return PacketsManager.isHearDisguisesEnabled(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isUndisguiseOnWorldChange() |     public static boolean isUndisguiseOnWorldChange() { | ||||||
|     { |  | ||||||
|         return undisguiseSwitchWorlds; |         return undisguiseSwitchWorlds; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -250,8 +237,7 @@ public class DisguiseConfig | |||||||
|      * |      * | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     public static boolean isVelocitySent() |     public static boolean isVelocitySent() { | ||||||
|     { |  | ||||||
|         return sendVelocity; |         return sendVelocity; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -260,90 +246,72 @@ public class DisguiseConfig | |||||||
|      * |      * | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     public static boolean isViewDisguises() |     public static boolean isViewDisguises() { | ||||||
|     { |  | ||||||
|         return viewSelfDisguise; |         return viewSelfDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isWitherSkullPacketsEnabled() |     public static boolean isWitherSkullPacketsEnabled() { | ||||||
|     { |  | ||||||
|         return witherSkullEnabled; |         return witherSkullEnabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isWolfDyeable() |     public static boolean isWolfDyeable() { | ||||||
|     { |  | ||||||
|         return colorizeWolf; |         return colorizeWolf; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) |     public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) { | ||||||
|     { |  | ||||||
|         entityAnimationsAdded = isEntityAnimationsAdded; |         entityAnimationsAdded = isEntityAnimationsAdded; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setAnimationPacketsEnabled(boolean enabled) |     public static void setAnimationPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isAnimationPacketsEnabled()) { | ||||||
|         if (enabled != isAnimationPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             animationEnabled = enabled; |             animationEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setBedPacketsEnabled(boolean enabled) |     public static void setBedPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isBedPacketsEnabled()) { | ||||||
|         if (enabled != isBedPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             bedEnabled = enabled; |             bedEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setCollectPacketsEnabled(boolean enabled) |     public static void setCollectPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isCollectPacketsEnabled()) { | ||||||
|         if (enabled != isCollectPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             collectEnabled = enabled; |             collectEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setDisguiseBlownMessage(String newMessage) |     public static void setDisguiseBlownMessage(String newMessage) { | ||||||
|     { |  | ||||||
|         disguiseBlownMessage = newMessage; |         disguiseBlownMessage = newMessage; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setDisguiseBlownOnAttack(boolean blowDisguise) |     public static void setDisguiseBlownOnAttack(boolean blowDisguise) { | ||||||
|     { |  | ||||||
|         blowDisguisesOnAttack = blowDisguise; |         blowDisguisesOnAttack = blowDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setDisguiseCloneExpire(int newExpires) |     public static void setDisguiseCloneExpire(int newExpires) { | ||||||
|     { |  | ||||||
|         disguiseCloneExpire = newExpires; |         disguiseCloneExpire = newExpires; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setDisguiseEntityExpire(int newExpires) |     public static void setDisguiseEntityExpire(int newExpires) { | ||||||
|     { |  | ||||||
|         disguiseEntityExpire = newExpires; |         disguiseEntityExpire = newExpires; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setEntityStatusPacketsEnabled(boolean enabled) |     public static void setEntityStatusPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isEntityStatusPacketsEnabled()) { | ||||||
|         if (enabled != isEntityStatusPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             entityStatusEnabled = enabled; |             entityStatusEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setEquipmentPacketsEnabled(boolean enabled) |     public static void setEquipmentPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isEquipmentPacketsEnabled()) { | ||||||
|         if (enabled != isEquipmentPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             equipmentEnabled = enabled; |             equipmentEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
| @@ -353,10 +321,8 @@ public class DisguiseConfig | |||||||
|     /** |     /** | ||||||
|      * Can players hear their own disguises |      * Can players hear their own disguises | ||||||
|      */ |      */ | ||||||
|     public static void setHearSelfDisguise(boolean replaceSound) |     public static void setHearSelfDisguise(boolean replaceSound) { | ||||||
|     { |         if (hearSelfDisguise != replaceSound) { | ||||||
|         if (hearSelfDisguise != replaceSound) |  | ||||||
|         { |  | ||||||
|             hearSelfDisguise = replaceSound; |             hearSelfDisguise = replaceSound; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -364,10 +330,8 @@ public class DisguiseConfig | |||||||
|     /** |     /** | ||||||
|      * Set the plugin to hide self disguises armor from theirselves |      * Set the plugin to hide self disguises armor from theirselves | ||||||
|      */ |      */ | ||||||
|     public static void setHideArmorFromSelf(boolean hideArmor) |     public static void setHideArmorFromSelf(boolean hideArmor) { | ||||||
|     { |         if (hidingArmor != hideArmor) { | ||||||
|         if (hidingArmor != hideArmor) |  | ||||||
|         { |  | ||||||
|             hidingArmor = hideArmor; |             hidingArmor = hideArmor; | ||||||
|  |  | ||||||
|             PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); |             PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); | ||||||
| @@ -377,121 +341,98 @@ public class DisguiseConfig | |||||||
|     /** |     /** | ||||||
|      * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise |      * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise | ||||||
|      */ |      */ | ||||||
|     public static void setHideHeldItemFromSelf(boolean hideHelditem) |     public static void setHideHeldItemFromSelf(boolean hideHelditem) { | ||||||
|     { |         if (hidingHeldItem != hideHelditem) { | ||||||
|         if (hidingHeldItem != hideHelditem) |  | ||||||
|         { |  | ||||||
|             hidingHeldItem = hideHelditem; |             hidingHeldItem = hideHelditem; | ||||||
|  |  | ||||||
|             PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); |             PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) |     public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         keepDisguiseEntityDespawn = keepDisguise; |         keepDisguiseEntityDespawn = keepDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) |     public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         keepDisguisePlayerDeath = keepDisguise; |         keepDisguisePlayerDeath = keepDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) |     public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         keepDisguisePlayerLogout = keepDisguise; |         keepDisguisePlayerLogout = keepDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMaxClonedDisguises(int newMax) |     public static void setMaxClonedDisguises(int newMax) { | ||||||
|     { |  | ||||||
|         maxClonedDisguises = newMax; |         maxClonedDisguises = newMax; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined) |     public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined) { | ||||||
|     { |  | ||||||
|         maxHealthIsDisguisedEntity = isDetermined; |         maxHealthIsDisguisedEntity = isDetermined; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMetadataPacketsEnabled(boolean enabled) |     public static void setMetadataPacketsEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         sendsEntityMetadata = enabled; |         sendsEntityMetadata = enabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMiscDisguisesForLivingEnabled(boolean enabled) |     public static void setMiscDisguisesForLivingEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isMiscDisguisesForLivingEnabled()) { | ||||||
|         if (enabled != isMiscDisguisesForLivingEnabled()) |  | ||||||
|         { |  | ||||||
|             miscDisguisesForLivingEnabled = enabled; |             miscDisguisesForLivingEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setModifyBoundingBox(boolean modifyBounding) |     public static void setModifyBoundingBox(boolean modifyBounding) { | ||||||
|     { |  | ||||||
|         modifyBoundingBox = modifyBounding; |         modifyBoundingBox = modifyBounding; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMonstersIgnoreDisguises(boolean ignore) |     public static void setMonstersIgnoreDisguises(boolean ignore) { | ||||||
|     { |  | ||||||
|         targetDisguises = ignore; |         targetDisguises = ignore; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMovementPacketsEnabled(boolean enabled) |     public static void setMovementPacketsEnabled(boolean enabled) { | ||||||
|     { |         if (enabled != isMovementPacketsEnabled()) { | ||||||
|         if (enabled != isMovementPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             movementEnabled = enabled; |             movementEnabled = enabled; | ||||||
|  |  | ||||||
|             PacketsManager.setupMainPacketsListener(); |             PacketsManager.setupMainPacketsListener(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) |     public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) { | ||||||
|     { |  | ||||||
|         showNameAboveHeadAlwaysVisible = alwaysVisible; |         showNameAboveHeadAlwaysVisible = alwaysVisible; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setNameOfPlayerShownAboveDisguise(boolean showNames) |     public static void setNameOfPlayerShownAboveDisguise(boolean showNames) { | ||||||
|     { |  | ||||||
|         showNameAboveHead = showNames; |         showNameAboveHead = showNames; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setSheepDyeable(boolean color) |     public static void setSheepDyeable(boolean color) { | ||||||
|     { |  | ||||||
|         colorizeSheep = color; |         colorizeSheep = color; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Set if the disguises play sounds when hurt |      * Set if the disguises play sounds when hurt | ||||||
|      */ |      */ | ||||||
|     public static void setSoundsEnabled(boolean isSoundsEnabled) |     public static void setSoundsEnabled(boolean isSoundsEnabled) { | ||||||
|     { |  | ||||||
|         PacketsManager.setHearDisguisesListener(isSoundsEnabled); |         PacketsManager.setHearDisguisesListener(isSoundsEnabled); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setUndisguiseOnWorldChange(boolean isUndisguise) |     public static void setUndisguiseOnWorldChange(boolean isUndisguise) { | ||||||
|     { |  | ||||||
|         undisguiseSwitchWorlds = isUndisguise; |         undisguiseSwitchWorlds = isUndisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setUpdateMessage(String newMessage) |     public static void setUpdateMessage(String newMessage) { | ||||||
|     { |  | ||||||
|         updateMessage = newMessage; |         updateMessage = newMessage; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setUpdateNotificationPermission(String newPermission) |     public static void setUpdateNotificationPermission(String newPermission) { | ||||||
|     { |  | ||||||
|         updateNotificationPermission = newPermission; |         updateNotificationPermission = newPermission; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving) |     public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving) { | ||||||
|     { |  | ||||||
|         DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving; |         DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean isStopShulkerDisguisesFromMoving() |     public static boolean isStopShulkerDisguisesFromMoving() { | ||||||
|     { |  | ||||||
|         return stopShulkerDisguisesFromMoving; |         return stopShulkerDisguisesFromMoving; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -500,27 +441,22 @@ public class DisguiseConfig | |||||||
|      * |      * | ||||||
|      * @param sendVelocityPackets |      * @param sendVelocityPackets | ||||||
|      */ |      */ | ||||||
|     public static void setVelocitySent(boolean sendVelocityPackets) |     public static void setVelocitySent(boolean sendVelocityPackets) { | ||||||
|     { |  | ||||||
|         sendVelocity = sendVelocityPackets; |         sendVelocity = sendVelocityPackets; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setViewDisguises(boolean seeOwnDisguise) |     public static void setViewDisguises(boolean seeOwnDisguise) { | ||||||
|     { |  | ||||||
|         viewSelfDisguise = seeOwnDisguise; |         viewSelfDisguise = seeOwnDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setWitherSkullPacketsEnabled(boolean enabled) |     public static void setWitherSkullPacketsEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         witherSkullEnabled = enabled; |         witherSkullEnabled = enabled; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setWolfDyeable(boolean color) |     public static void setWolfDyeable(boolean color) { | ||||||
|     { |  | ||||||
|         colorizeWolf = color; |         colorizeWolf = color; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private DisguiseConfig() |     private DisguiseConfig() { | ||||||
|     { |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package me.libraryaddict.disguise; | package me.libraryaddict.disguise; | ||||||
|  |  | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
|  | import java.util.Arrays; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
|  |  | ||||||
| @@ -27,8 +28,13 @@ import org.bukkit.event.vehicle.VehicleExitEvent; | |||||||
| import org.bukkit.scheduler.BukkitRunnable; | import org.bukkit.scheduler.BukkitRunnable; | ||||||
| import org.bukkit.scheduler.BukkitTask; | import org.bukkit.scheduler.BukkitTask; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.PacketType; | ||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; | ||||||
|  | import com.comphenix.protocol.wrappers.PlayerInfoData; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||||
| @@ -39,8 +45,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; | |||||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.utilities.UpdateChecker; | import me.libraryaddict.disguise.utilities.UpdateChecker; | ||||||
|  |  | ||||||
| public class DisguiseListener implements Listener | public class DisguiseListener implements Listener { | ||||||
| { |  | ||||||
|  |  | ||||||
|     private String currentVersion; |     private String currentVersion; | ||||||
|     private HashMap<String, Boolean[]> disguiseClone = new HashMap<>(); |     private HashMap<String, Boolean[]> disguiseClone = new HashMap<>(); | ||||||
| @@ -50,42 +55,32 @@ public class DisguiseListener implements Listener | |||||||
|     private LibsDisguises plugin; |     private LibsDisguises plugin; | ||||||
|     private BukkitTask updaterTask; |     private BukkitTask updaterTask; | ||||||
|  |  | ||||||
|     public DisguiseListener(LibsDisguises libsDisguises) |     public DisguiseListener(LibsDisguises libsDisguises) { | ||||||
|     { |  | ||||||
|         plugin = libsDisguises; |         plugin = libsDisguises; | ||||||
|  |  | ||||||
|         if (plugin.getConfig().getBoolean("NotifyUpdate")) |         if (plugin.getConfig().getBoolean("NotifyUpdate")) { | ||||||
|         { |  | ||||||
|             currentVersion = plugin.getDescription().getVersion(); |             currentVersion = plugin.getDescription().getVersion(); | ||||||
|  |  | ||||||
|             updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() |             updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { | ||||||
|             { |  | ||||||
|                 @Override |                 @Override | ||||||
|                 public void run() |                 public void run() { | ||||||
|                 { |                     try { | ||||||
|                     try |  | ||||||
|                     { |  | ||||||
|                         UpdateChecker updateChecker = new UpdateChecker(); |                         UpdateChecker updateChecker = new UpdateChecker(); | ||||||
|                         updateChecker.checkUpdate("v" + currentVersion); |                         updateChecker.checkUpdate("v" + currentVersion); | ||||||
|  |  | ||||||
|                         latestVersion = updateChecker.getLatestVersion(); |                         latestVersion = updateChecker.getLatestVersion(); | ||||||
|  |  | ||||||
|                         if (latestVersion == null) |                         if (latestVersion == null) { | ||||||
|                         { |  | ||||||
|                             return; |                             return; | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         latestVersion = "v" + latestVersion; |                         latestVersion = "v" + latestVersion; | ||||||
|  |  | ||||||
|                         Bukkit.getScheduler().runTask(plugin, new Runnable() |                         Bukkit.getScheduler().runTask(plugin, new Runnable() { | ||||||
|                         { |  | ||||||
|                             @Override |                             @Override | ||||||
|                             public void run() |                             public void run() { | ||||||
|                             { |                                 for (Player p : Bukkit.getOnlinePlayers()) { | ||||||
|                                 for (Player p : Bukkit.getOnlinePlayers()) |                                     if (!p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) { | ||||||
|                                 { |  | ||||||
|                                     if (!p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) |  | ||||||
|                                     { |  | ||||||
|                                         continue; |                                         continue; | ||||||
|                                     } |                                     } | ||||||
|  |  | ||||||
| @@ -95,8 +90,7 @@ public class DisguiseListener implements Listener | |||||||
|                             } |                             } | ||||||
|                         }); |                         }); | ||||||
|                     } |                     } | ||||||
|                     catch (Exception ex) |                     catch (Exception ex) { | ||||||
|                     { |  | ||||||
|                         System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage())); |                         System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage())); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @@ -105,15 +99,12 @@ public class DisguiseListener implements Listener | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void cleanup() |     public void cleanup() { | ||||||
|     { |         for (BukkitRunnable r : disguiseRunnable.values()) { | ||||||
|         for (BukkitRunnable r : disguiseRunnable.values()) |  | ||||||
|         { |  | ||||||
|             r.cancel(); |             r.cancel(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (Disguise d : disguiseEntity.values()) |         for (Disguise d : disguiseEntity.values()) { | ||||||
|         { |  | ||||||
|             d.removeDisguise(); |             d.removeDisguise(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -121,37 +112,28 @@ public class DisguiseListener implements Listener | |||||||
|         updaterTask.cancel(); |         updaterTask.cancel(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void checkPlayerCanBlowDisguise(Player entity) |     private void checkPlayerCanBlowDisguise(Player entity) { | ||||||
|     { |  | ||||||
|         Disguise[] disguises = DisguiseAPI.getDisguises(entity); |         Disguise[] disguises = DisguiseAPI.getDisguises(entity); | ||||||
|  |  | ||||||
|         if (disguises.length > 0) |         if (disguises.length > 0) { | ||||||
|         { |  | ||||||
|             DisguiseAPI.undisguiseToAll(entity); |             DisguiseAPI.undisguiseToAll(entity); | ||||||
|  |  | ||||||
|             if (DisguiseConfig.getDisguiseBlownMessage().length() > 0) |             if (DisguiseConfig.getDisguiseBlownMessage().length() > 0) { | ||||||
|             { |  | ||||||
|                 entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage()); |                 entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void chunkMove(Player player, Location newLoc, Location oldLoc) |     private void chunkMove(Player player, Location newLoc, Location oldLoc) { | ||||||
|     { |         try { | ||||||
|         try |  | ||||||
|         { |  | ||||||
|             // Resend the bed chunks |             // Resend the bed chunks | ||||||
|             for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc)) |             for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc)) { | ||||||
|             { |  | ||||||
|                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); |                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (newLoc != null) |             if (newLoc != null) { | ||||||
|             { |                 for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) { | ||||||
|                 for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) |                     for (TargetedDisguise disguise : list) { | ||||||
|                 { |  | ||||||
|                     for (TargetedDisguise disguise : list) |  | ||||||
|                     { |  | ||||||
|                         if (disguise.getEntity() == null) |                         if (disguise.getEntity() == null) | ||||||
|                             continue; |                             continue; | ||||||
|  |  | ||||||
| @@ -171,87 +153,120 @@ public class DisguiseListener implements Listener | |||||||
|                                 disguise.getEntity() == player ? newLoc : disguise.getEntity().getLocation(), newLoc, |                                 disguise.getEntity() == player ? newLoc : disguise.getEntity().getLocation(), newLoc, | ||||||
|                                 (PlayerDisguise) disguise); |                                 (PlayerDisguise) disguise); | ||||||
|  |  | ||||||
|                         if (disguise.getEntity() == player) |                         if (disguise.getEntity() == player) { | ||||||
|                         { |                             for (PacketContainer packet : packets) { | ||||||
|                             for (PacketContainer packet : packets) |  | ||||||
|                             { |  | ||||||
|                                 packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                                 packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         for (PacketContainer packet : packets) |                         for (PacketContainer packet : packets) { | ||||||
|                         { |  | ||||||
|                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         catch (InvocationTargetException e) |         catch (InvocationTargetException e) { | ||||||
|         { |  | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||||||
|     public void onAttack(EntityDamageByEntityEvent event) |     public void onAttack(EntityDamageByEntityEvent event) { | ||||||
|     { |         if (DisguiseConfig.isDisguiseBlownOnAttack()) { | ||||||
|         if (DisguiseConfig.isDisguiseBlownOnAttack()) |             if (event.getEntity() instanceof Player) { | ||||||
|         { |  | ||||||
|             if (event.getEntity() instanceof Player) |  | ||||||
|             { |  | ||||||
|                 checkPlayerCanBlowDisguise((Player) event.getEntity()); |                 checkPlayerCanBlowDisguise((Player) event.getEntity()); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (event.getDamager() instanceof Player) |             if (event.getDamager() instanceof Player) { | ||||||
|             { |  | ||||||
|                 checkPlayerCanBlowDisguise((Player) event.getDamager()); |                 checkPlayerCanBlowDisguise((Player) event.getDamager()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onJoin(PlayerJoinEvent event) |     public void onJoin(PlayerJoinEvent event) { | ||||||
|     { |  | ||||||
|         Player p = event.getPlayer(); |         Player p = event.getPlayer(); | ||||||
|  |  | ||||||
|         if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) |         if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) { | ||||||
|         { |  | ||||||
|             p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion)); |             p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|         { |  | ||||||
|             chunkMove(p, p.getLocation(), null); |             chunkMove(p, p.getLocation(), null); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         for (HashSet<TargetedDisguise> disguiseList : DisguiseUtilities.getDisguises().values()) { | ||||||
|  |             for (TargetedDisguise targetedDisguise : disguiseList) { | ||||||
|  |                 if (targetedDisguise.getEntity() == null) | ||||||
|  |                     continue; | ||||||
|  |  | ||||||
|  |                 if (!targetedDisguise.canSee(p)) | ||||||
|  |                     continue; | ||||||
|  |  | ||||||
|  |                 // Don't need this as we have a packet listener doing that for us | ||||||
|  |                 /*if (targetedDisguise.isPlayerHiddenInTab() && targetedDisguise.getEntity() instanceof Player) { | ||||||
|  |                     try { | ||||||
|  |                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                         Player player = (Player) targetedDisguise.getEntity(); | ||||||
|  |                  | ||||||
|  |                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |                         addTab.getPlayerInfoDataLists() | ||||||
|  |                                 .write(0, | ||||||
|  |                                         Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile(player), 0, | ||||||
|  |                                                 NativeGameMode.SURVIVAL, | ||||||
|  |                                                 WrappedChatComponent.fromText(player.getDisplayName())))); | ||||||
|  |                  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(p, addTab); | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 }*/ | ||||||
|  |  | ||||||
|  |                 if (!(targetedDisguise instanceof PlayerDisguise)) | ||||||
|  |                     continue; | ||||||
|  |  | ||||||
|  |                 PlayerDisguise disguise = (PlayerDisguise) targetedDisguise; | ||||||
|  |  | ||||||
|  |                 if (disguise.isDisplayedInTab()) { | ||||||
|  |                     try { | ||||||
|  |                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |  | ||||||
|  |                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||||
|  |                         addTab.getPlayerInfoDataLists().write(0, Arrays.asList(new PlayerInfoData(disguise.getGameProfile(), 0, | ||||||
|  |                                 NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getGameProfile().getName())))); | ||||||
|  |  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(p, addTab); | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Most likely faster if we don't bother doing checks if he sees a player disguise |      * Most likely faster if we don't bother doing checks if he sees a player disguise | ||||||
|      */ |      */ | ||||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||
|     public void onMove(PlayerMoveEvent event) |     public void onMove(PlayerMoveEvent event) { | ||||||
|     { |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             Location to = event.getTo(); |             Location to = event.getTo(); | ||||||
|             Location from = event.getFrom(); |             Location from = event.getFrom(); | ||||||
|  |  | ||||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) |             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) | ||||||
|                     || DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) |                     || DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||||
|             { |  | ||||||
|                 chunkMove(event.getPlayer(), to, from); |                 chunkMove(event.getPlayer(), to, from); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isStopShulkerDisguisesFromMoving()) |         if (DisguiseConfig.isStopShulkerDisguisesFromMoving()) { | ||||||
|         { |  | ||||||
|             Disguise disguise; |             Disguise disguise; | ||||||
|  |  | ||||||
|             if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) |             if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) { | ||||||
|             { |                 if (disguise.getType() == DisguiseType.SHULKER) { // Stop Shulker disguises from moving their coordinates | ||||||
|                 if (disguise.getType() == DisguiseType.SHULKER) |  | ||||||
|                 { // Stop Shulker disguises from moving their coordinates |  | ||||||
|                     Location from = event.getFrom(); |                     Location from = event.getFrom(); | ||||||
|                     Location to = event.getTo(); |                     Location to = event.getTo(); | ||||||
|  |  | ||||||
| @@ -265,35 +280,28 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onQuit(PlayerQuitEvent event) |     public void onQuit(PlayerQuitEvent event) { | ||||||
|     { |  | ||||||
|         ReflectionManager.removePlayer(event.getPlayer()); |         ReflectionManager.removePlayer(event.getPlayer()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onRespawn(PlayerRespawnEvent event) |     public void onRespawn(PlayerRespawnEvent event) { | ||||||
|     { |  | ||||||
|         Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); |         Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); | ||||||
|  |  | ||||||
|         for (Disguise disguise : disguises) |         for (Disguise disguise : disguises) { | ||||||
|         { |             if (disguise.isRemoveDisguiseOnDeath()) { | ||||||
|             if (disguise.isRemoveDisguiseOnDeath()) |  | ||||||
|             { |  | ||||||
|                 disguise.removeDisguise(); |                 disguise.removeDisguise(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|         { |  | ||||||
|             final Player player = event.getPlayer(); |             final Player player = event.getPlayer(); | ||||||
|  |  | ||||||
|             chunkMove(event.getPlayer(), null, player.getLocation()); |             chunkMove(event.getPlayer(), null, player.getLocation()); | ||||||
|  |  | ||||||
|             Bukkit.getScheduler().runTask(plugin, new Runnable() |             Bukkit.getScheduler().runTask(plugin, new Runnable() { | ||||||
|             { |  | ||||||
|                 @Override |                 @Override | ||||||
|                 public void run() |                 public void run() { | ||||||
|                 { |  | ||||||
|                     chunkMove(player, player.getLocation(), null); |                     chunkMove(player, player.getLocation(), null); | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
| @@ -301,10 +309,8 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onRightClick(PlayerInteractEntityEvent event) |     public void onRightClick(PlayerInteractEntityEvent event) { | ||||||
|     { |         if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) { | ||||||
|         if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) |  | ||||||
|         { |  | ||||||
|             Player p = event.getPlayer(); |             Player p = event.getPlayer(); | ||||||
|  |  | ||||||
|             event.setCancelled(true); |             event.setCancelled(true); | ||||||
| @@ -313,27 +319,22 @@ public class DisguiseListener implements Listener | |||||||
|             Entity entity = event.getRightClicked(); |             Entity entity = event.getRightClicked(); | ||||||
|             String entityName; |             String entityName; | ||||||
|  |  | ||||||
|             if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) |             if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) { | ||||||
|             { |  | ||||||
|                 entityName = entity.getName(); |                 entityName = entity.getName(); | ||||||
|             } |             } | ||||||
|             else |             else { | ||||||
|             { |  | ||||||
|                 entityName = DisguiseType.getType(entity).toReadable(); |                 entityName = DisguiseType.getType(entity).toReadable(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (disguiseClone.containsKey(p.getName())) |             if (disguiseClone.containsKey(p.getName())) { | ||||||
|             { |  | ||||||
|                 Boolean[] options = disguiseClone.remove(p.getName()); |                 Boolean[] options = disguiseClone.remove(p.getName()); | ||||||
|  |  | ||||||
|                 Disguise disguise = DisguiseAPI.getDisguise(p, entity); |                 Disguise disguise = DisguiseAPI.getDisguise(p, entity); | ||||||
|  |  | ||||||
|                 if (disguise == null) |                 if (disguise == null) { | ||||||
|                 { |  | ||||||
|                     disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]); |                     disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]); | ||||||
|                 } |                 } | ||||||
|                 else |                 else { | ||||||
|                 { |  | ||||||
|                     disguise = disguise.clone(); |                     disguise = disguise.clone(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -343,54 +344,42 @@ public class DisguiseListener implements Listener | |||||||
|                 int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D)); |                 int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D)); | ||||||
|                 int attempts = 0; |                 int attempts = 0; | ||||||
|  |  | ||||||
|                 while (reference == null && attempts++ < 1000) |                 while (reference == null && attempts++ < 1000) { | ||||||
|                 { |  | ||||||
|                     reference = "@"; |                     reference = "@"; | ||||||
|  |  | ||||||
|                     for (int i = 0; i < referenceLength; i++) |                     for (int i = 0; i < referenceLength; i++) { | ||||||
|                     { |  | ||||||
|                         reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)]; |                         reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)]; | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if (DisguiseUtilities.getClonedDisguise(reference) != null) |                     if (DisguiseUtilities.getClonedDisguise(reference) != null) { | ||||||
|                     { |  | ||||||
|                         reference = null; |                         reference = null; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) |                 if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) { | ||||||
|                 { |  | ||||||
|                     p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference); |                     p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference); | ||||||
|                     p.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference); |                     p.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference); | ||||||
|                 } |                 } | ||||||
|                 else |                 else { | ||||||
|                 { |  | ||||||
|                     p.sendMessage( |                     p.sendMessage( | ||||||
|                             ChatColor.RED + "Failed to store the reference due to lack of size. Please set this in the config"); |                             ChatColor.RED + "Failed to store the reference due to lack of size. Please set this in the config"); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             else if (disguiseEntity.containsKey(p.getName())) |             else if (disguiseEntity.containsKey(p.getName())) { | ||||||
|             { |  | ||||||
|                 Disguise disguise = disguiseEntity.remove(p.getName()); |                 Disguise disguise = disguiseEntity.remove(p.getName()); | ||||||
|  |  | ||||||
|                 if (disguise != null) |                 if (disguise != null) { | ||||||
|                 { |  | ||||||
|                     if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() |                     if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() | ||||||
|                             && entity instanceof LivingEntity) |                             && entity instanceof LivingEntity) { | ||||||
|                     { |  | ||||||
|                         p.sendMessage(ChatColor.RED |                         p.sendMessage(ChatColor.RED | ||||||
|                                 + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); |                                 + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); | ||||||
|                     } |                     } | ||||||
|                     else |                     else { | ||||||
|                     { |                         if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||||
|                         if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) |                             if (disguise.getWatcher() instanceof LivingWatcher) { | ||||||
|                         { |  | ||||||
|                             if (disguise.getWatcher() instanceof LivingWatcher) |  | ||||||
|                             { |  | ||||||
|                                 disguise.getWatcher().setCustomName(((Player) entity).getDisplayName()); |                                 disguise.getWatcher().setCustomName(((Player) entity).getDisplayName()); | ||||||
|  |  | ||||||
|                                 if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) |                                 if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||||
|                                 { |  | ||||||
|                                     disguise.getWatcher().setCustomNameVisible(true); |                                     disguise.getWatcher().setCustomNameVisible(true); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
| @@ -400,37 +389,30 @@ public class DisguiseListener implements Listener | |||||||
|  |  | ||||||
|                         String disguiseName = "a "; |                         String disguiseName = "a "; | ||||||
|  |  | ||||||
|                         if (disguise instanceof PlayerDisguise) |                         if (disguise instanceof PlayerDisguise) { | ||||||
|                         { |  | ||||||
|                             disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); |                             disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); | ||||||
|                         } |                         } | ||||||
|                         else |                         else { | ||||||
|                         { |  | ||||||
|                             disguiseName += disguise.getType().toReadable(); |                             disguiseName += disguise.getType().toReadable(); | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         if (disguise.isDisguiseInUse()) |                         if (disguise.isDisguiseInUse()) { | ||||||
|                         { |  | ||||||
|                             p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName |                             p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName | ||||||
|                                     + " as " + disguiseName + "!"); |                                     + " as " + disguiseName + "!"); | ||||||
|                         } |                         } | ||||||
|                         else |                         else { | ||||||
|                         { |  | ||||||
|                             p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ") |                             p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ") | ||||||
|                                     + entityName + " as " + disguiseName + "!"); |                                     + entityName + " as " + disguiseName + "!"); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else |                 else { | ||||||
|                 { |                     if (DisguiseAPI.isDisguised(entity)) { | ||||||
|                     if (DisguiseAPI.isDisguised(entity)) |  | ||||||
|                     { |  | ||||||
|                         DisguiseAPI.undisguiseToAll(entity); |                         DisguiseAPI.undisguiseToAll(entity); | ||||||
|  |  | ||||||
|                         p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); |                         p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); | ||||||
|                     } |                     } | ||||||
|                     else |                     else { | ||||||
|                     { |  | ||||||
|                         p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); |                         p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @@ -439,13 +421,10 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onTarget(EntityTargetEvent event) |     public void onTarget(EntityTargetEvent event) { | ||||||
|     { |  | ||||||
|         if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player |         if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player | ||||||
|                 && DisguiseAPI.isDisguised(event.getTarget())) |                 && DisguiseAPI.isDisguised(event.getTarget())) { | ||||||
|         { |             switch (event.getReason()) { | ||||||
|             switch (event.getReason()) |  | ||||||
|             { |  | ||||||
|             case TARGET_ATTACKED_ENTITY: |             case TARGET_ATTACKED_ENTITY: | ||||||
|             case TARGET_ATTACKED_OWNER: |             case TARGET_ATTACKED_OWNER: | ||||||
|             case OWNER_ATTACKED_TARGET: |             case OWNER_ATTACKED_TARGET: | ||||||
| @@ -459,50 +438,40 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||
|     public void onTeleport(PlayerTeleportEvent event) |     public void onTeleport(PlayerTeleportEvent event) { | ||||||
|     { |  | ||||||
|         final Player player = event.getPlayer(); |         final Player player = event.getPlayer(); | ||||||
|         Location to = event.getTo(); |         Location to = event.getTo(); | ||||||
|         Location from = event.getFrom(); |         Location from = event.getFrom(); | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|         { |  | ||||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) |             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) | ||||||
|                     || DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) |                     || DisguiseUtilities.getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||||
|             { |  | ||||||
|                 chunkMove(player, null, from); |                 chunkMove(player, null, from); | ||||||
|  |  | ||||||
|                 Bukkit.getScheduler().runTask(plugin, new Runnable() |                 Bukkit.getScheduler().runTask(plugin, new Runnable() { | ||||||
|                 { |  | ||||||
|                     @Override |                     @Override | ||||||
|                     public void run() |                     public void run() { | ||||||
|                     { |  | ||||||
|                         chunkMove(player, player.getLocation(), null); |                         chunkMove(player, player.getLocation(), null); | ||||||
|                     } |                     } | ||||||
|                 }); |                 }); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!DisguiseAPI.isDisguised(player)) |         if (!DisguiseAPI.isDisguised(player)) { | ||||||
|         { |  | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null |         if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null | ||||||
|                 && to.getWorld() != from.getWorld()) |                 && to.getWorld() != from.getWorld()) { | ||||||
|         { |             for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { | ||||||
|             for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) |  | ||||||
|             { |  | ||||||
|                 disguise.removeDisguise(); |                 disguise.removeDisguise(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||
|     public void onVehicleEnter(VehicleEnterEvent event) |     public void onVehicleEnter(VehicleEnterEvent event) { | ||||||
|     { |         if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered())) { | ||||||
|         if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered())) |  | ||||||
|         { |  | ||||||
|             DisguiseUtilities.removeSelfDisguise((Player) event.getEntered()); |             DisguiseUtilities.removeSelfDisguise((Player) event.getEntered()); | ||||||
|  |  | ||||||
|             ((Player) event.getEntered()).updateInventory(); |             ((Player) event.getEntered()).updateInventory(); | ||||||
| @@ -510,19 +479,14 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||
|     public void onVehicleLeave(VehicleExitEvent event) |     public void onVehicleLeave(VehicleExitEvent event) { | ||||||
|     { |         if (event.getExited() instanceof Player) { | ||||||
|         if (event.getExited() instanceof Player) |  | ||||||
|         { |  | ||||||
|             final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited()); |             final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited()); | ||||||
|  |  | ||||||
|             if (disguise != null) |             if (disguise != null) { | ||||||
|             { |                 Bukkit.getScheduler().runTask(plugin, new Runnable() { | ||||||
|                 Bukkit.getScheduler().runTask(plugin, new Runnable() |  | ||||||
|                 { |  | ||||||
|                     @Override |                     @Override | ||||||
|                     public void run() |                     public void run() { | ||||||
|                     { |  | ||||||
|                         DisguiseUtilities.setupFakeDisguise(disguise); |                         DisguiseUtilities.setupFakeDisguise(disguise); | ||||||
|  |  | ||||||
|                         ((Player) disguise.getEntity()).updateInventory(); |                         ((Player) disguise.getEntity()).updateInventory(); | ||||||
| @@ -533,41 +497,32 @@ public class DisguiseListener implements Listener | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||||
|     public void onWorldSwitch(final PlayerChangedWorldEvent event) |     public void onWorldSwitch(final PlayerChangedWorldEvent event) { | ||||||
|     { |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) |  | ||||||
|         { |  | ||||||
|             chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null); |             chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!DisguiseAPI.isDisguised(event.getPlayer())) |         if (!DisguiseAPI.isDisguised(event.getPlayer())) { | ||||||
|         { |  | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isUndisguiseOnWorldChange()) |         if (DisguiseConfig.isUndisguiseOnWorldChange()) { | ||||||
|         { |             for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { | ||||||
|             for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) |  | ||||||
|             { |  | ||||||
|                 disguise.removeDisguise(); |                 disguise.removeDisguise(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else |         else { | ||||||
|         { |  | ||||||
|             // Stupid hack to fix worldswitch invisibility bug |             // Stupid hack to fix worldswitch invisibility bug | ||||||
|             final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer()); |             final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer()); | ||||||
|  |  | ||||||
|             if (viewSelfToggled) |             if (viewSelfToggled) { | ||||||
|             { |  | ||||||
|                 final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer()); |                 final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer()); | ||||||
|  |  | ||||||
|                 disguise.setViewSelfDisguise(false); |                 disguise.setViewSelfDisguise(false); | ||||||
|  |  | ||||||
|                 Bukkit.getScheduler().runTaskLater(plugin, new Runnable() |                 Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { | ||||||
|                 { |  | ||||||
|                     @Override |                     @Override | ||||||
|                     public void run() |                     public void run() { | ||||||
|                     { |  | ||||||
|                         disguise.setViewSelfDisguise(true); |                         disguise.setViewSelfDisguise(true); | ||||||
|                     } |                     } | ||||||
|                 }, 20L); // I wish I could use lambdas here, so badly |                 }, 20L); // I wish I could use lambdas here, so badly | ||||||
| @@ -575,20 +530,16 @@ public class DisguiseListener implements Listener | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setDisguiseClone(final String player, Boolean[] options) |     public void setDisguiseClone(final String player, Boolean[] options) { | ||||||
|     { |         if (disguiseRunnable.containsKey(player)) { | ||||||
|         if (disguiseRunnable.containsKey(player)) |  | ||||||
|         { |  | ||||||
|             BukkitRunnable run = disguiseRunnable.remove(player); |             BukkitRunnable run = disguiseRunnable.remove(player); | ||||||
|             run.cancel(); |             run.cancel(); | ||||||
|             run.run(); |             run.run(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         BukkitRunnable runnable = new BukkitRunnable() |         BukkitRunnable runnable = new BukkitRunnable() { | ||||||
|         { |  | ||||||
|             @Override |             @Override | ||||||
|             public void run() |             public void run() { | ||||||
|             { |  | ||||||
|                 disguiseClone.remove(player); |                 disguiseClone.remove(player); | ||||||
|                 disguiseRunnable.remove(player); |                 disguiseRunnable.remove(player); | ||||||
|             } |             } | ||||||
| @@ -600,20 +551,16 @@ public class DisguiseListener implements Listener | |||||||
|         disguiseClone.put(player, options); |         disguiseClone.put(player, options); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setDisguiseEntity(final String player, Disguise disguise) |     public void setDisguiseEntity(final String player, Disguise disguise) { | ||||||
|     { |         if (disguiseRunnable.containsKey(player)) { | ||||||
|         if (disguiseRunnable.containsKey(player)) |  | ||||||
|         { |  | ||||||
|             BukkitRunnable run = disguiseRunnable.remove(player); |             BukkitRunnable run = disguiseRunnable.remove(player); | ||||||
|             run.cancel(); |             run.cancel(); | ||||||
|             run.run(); |             run.run(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         BukkitRunnable runnable = new BukkitRunnable() |         BukkitRunnable runnable = new BukkitRunnable() { | ||||||
|         { |  | ||||||
|             @Override |             @Override | ||||||
|             public void run() |             public void run() { | ||||||
|             { |  | ||||||
|                 disguiseEntity.remove(player); |                 disguiseEntity.remove(player); | ||||||
|                 disguiseRunnable.remove(player); |                 disguiseRunnable.remove(player); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -23,12 +23,12 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject; | |||||||
|  |  | ||||||
| import me.libraryaddict.disguise.commands.DisguiseCloneCommand; | import me.libraryaddict.disguise.commands.DisguiseCloneCommand; | ||||||
| import me.libraryaddict.disguise.commands.DisguiseCommand; | import me.libraryaddict.disguise.commands.DisguiseCommand; | ||||||
| import me.libraryaddict.disguise.commands.DisguiseHelpCommand; |  | ||||||
| import me.libraryaddict.disguise.commands.DisguiseViewSelfCommand; |  | ||||||
| import me.libraryaddict.disguise.commands.DisguiseEntityCommand; | import me.libraryaddict.disguise.commands.DisguiseEntityCommand; | ||||||
| import me.libraryaddict.disguise.commands.LibsDisguisesCommand; | import me.libraryaddict.disguise.commands.DisguiseHelpCommand; | ||||||
| import me.libraryaddict.disguise.commands.DisguisePlayerCommand; | import me.libraryaddict.disguise.commands.DisguisePlayerCommand; | ||||||
| import me.libraryaddict.disguise.commands.DisguiseRadiusCommand; | import me.libraryaddict.disguise.commands.DisguiseRadiusCommand; | ||||||
|  | import me.libraryaddict.disguise.commands.DisguiseViewSelfCommand; | ||||||
|  | import me.libraryaddict.disguise.commands.LibsDisguisesCommand; | ||||||
| import me.libraryaddict.disguise.commands.UndisguiseCommand; | import me.libraryaddict.disguise.commands.UndisguiseCommand; | ||||||
| import me.libraryaddict.disguise.commands.UndisguiseEntityCommand; | import me.libraryaddict.disguise.commands.UndisguiseEntityCommand; | ||||||
| import me.libraryaddict.disguise.commands.UndisguisePlayerCommand; | import me.libraryaddict.disguise.commands.UndisguisePlayerCommand; | ||||||
| @@ -73,7 +73,7 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             ReflectionManager.getNmsClass("EntityShulker").getName(); |             ReflectionManager.getNmsClass("EntityEvoker").getName(); | ||||||
|         } |         } | ||||||
|         catch (Exception ex) { |         catch (Exception ex) { | ||||||
|             System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!"); |             System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!"); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes; | |||||||
|  |  | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | import java.util.Arrays; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| @@ -16,10 +17,15 @@ import org.bukkit.entity.Player; | |||||||
| import org.bukkit.scheduler.BukkitTask; | import org.bukkit.scheduler.BukkitTask; | ||||||
| import org.bukkit.util.Vector; | import org.bukkit.util.Vector; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.PacketType; | ||||||
| import com.comphenix.protocol.PacketType.Play.Server; | import com.comphenix.protocol.PacketType.Play.Server; | ||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; | import com.comphenix.protocol.reflect.StructureModifier; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; | ||||||
|  | import com.comphenix.protocol.wrappers.PlayerInfoData; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| @@ -35,6 +41,17 @@ import me.libraryaddict.disguise.utilities.PacketsManager; | |||||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
|  |  | ||||||
| public abstract class Disguise { | public abstract class Disguise { | ||||||
|  |     private static List<UUID> viewSelf = new ArrayList<>(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Returns the list of people who have /disguiseViewSelf toggled on | ||||||
|  |      * | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     public static List<UUID> getViewSelf() { | ||||||
|  |         return viewSelf; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private boolean disguiseInUse; |     private boolean disguiseInUse; | ||||||
|     private DisguiseType disguiseType; |     private DisguiseType disguiseType; | ||||||
|     private Entity entity; |     private Entity entity; | ||||||
| @@ -45,15 +62,14 @@ public abstract class Disguise { | |||||||
|     private boolean keepDisguisePlayerDeath = DisguiseConfig.isKeepDisguiseOnPlayerDeath(); |     private boolean keepDisguisePlayerDeath = DisguiseConfig.isKeepDisguiseOnPlayerDeath(); | ||||||
|     private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout(); |     private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout(); | ||||||
|     private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); |     private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); | ||||||
|  |     private boolean playerHiddenFromTab = DisguiseConfig.isHideDisguisedPlayers(); | ||||||
|     private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); |     private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); | ||||||
|  |     private boolean showName; | ||||||
|     private BukkitTask task; |     private BukkitTask task; | ||||||
|     private Runnable velocityRunnable; |     private Runnable velocityRunnable; | ||||||
|     private boolean velocitySent = DisguiseConfig.isVelocitySent(); |     private boolean velocitySent = DisguiseConfig.isVelocitySent(); | ||||||
|     private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises(); |     private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises(); | ||||||
|     private FlagWatcher watcher; |     private FlagWatcher watcher; | ||||||
|     private boolean showName = false; |  | ||||||
|  |  | ||||||
|     private static List<UUID> viewSelf = new ArrayList<>(); |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public abstract Disguise clone(); |     public abstract Disguise clone(); | ||||||
| @@ -398,6 +414,13 @@ public abstract class Disguise { | |||||||
|         return disguiseInUse; |         return disguiseInUse; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Will a disguised player appear in tab | ||||||
|  |      */ | ||||||
|  |     public boolean isHidePlayer() { | ||||||
|  |         return playerHiddenFromTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public boolean isHidingArmorFromSelf() { |     public boolean isHidingArmorFromSelf() { | ||||||
|         return hideArmorFromSelf; |         return hideArmorFromSelf; | ||||||
|     } |     } | ||||||
| @@ -456,14 +479,6 @@ public abstract class Disguise { | |||||||
|         return viewSelfDisguise; |         return viewSelfDisguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isSoundsReplaced() { |  | ||||||
|         return replaceSounds; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean isVelocitySent() { |  | ||||||
|         return velocitySent; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Returns true if the entity's name is showing through the disguise |      * Returns true if the entity's name is showing through the disguise | ||||||
|      * |      * | ||||||
| @@ -473,6 +488,14 @@ public abstract class Disguise { | |||||||
|         return showName; |         return showName; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isSoundsReplaced() { | ||||||
|  |         return replaceSounds; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public boolean isVelocitySent() { | ||||||
|  |         return velocitySent; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Removes the disguise and undisguises the entity if its using this disguise. |      * Removes the disguise and undisguises the entity if its using this disguise. | ||||||
|      * |      * | ||||||
| @@ -496,6 +519,51 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|                 // If this disguise has a entity set |                 // If this disguise has a entity set | ||||||
|                 if (getEntity() != null) { |                 if (getEntity() != null) { | ||||||
|  |                     if (this instanceof PlayerDisguise) { | ||||||
|  |                         PlayerDisguise disguise = (PlayerDisguise) this; | ||||||
|  |  | ||||||
|  |                         if (disguise.isDisplayedInTab()) { | ||||||
|  |                             PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                             deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |                             deleteTab.getPlayerInfoDataLists().write(0, | ||||||
|  |                                     Arrays.asList(new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, | ||||||
|  |                                             WrappedChatComponent.fromText(disguise.getName())))); | ||||||
|  |  | ||||||
|  |                             try { | ||||||
|  |                                 for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                                     if (!((TargetedDisguise) this).canSee(player)) | ||||||
|  |                                         continue; | ||||||
|  |  | ||||||
|  |                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                             catch (InvocationTargetException e) { | ||||||
|  |                                 e.printStackTrace(); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     if (isHidePlayer() && getEntity() instanceof Player) { | ||||||
|  |                         PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                         deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||||
|  |                         deleteTab.getPlayerInfoDataLists().write(0, | ||||||
|  |                                 Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||||
|  |                                         NativeGameMode.SURVIVAL, | ||||||
|  |                                         WrappedChatComponent.fromText(((Player) getEntity()).getDisplayName())))); | ||||||
|  |  | ||||||
|  |                         try { | ||||||
|  |                             for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                                 if (!((TargetedDisguise) this).canSee(player)) | ||||||
|  |                                     continue; | ||||||
|  |  | ||||||
|  |                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         catch (InvocationTargetException e) { | ||||||
|  |                             e.printStackTrace(); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |  | ||||||
|                     // If this disguise is active |                     // If this disguise is active | ||||||
|                     // Remove the disguise from the current disguises. |                     // Remove the disguise from the current disguises. | ||||||
|                     if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) { |                     if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) { | ||||||
| @@ -546,6 +614,7 @@ public abstract class Disguise { | |||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -556,7 +625,7 @@ public abstract class Disguise { | |||||||
|      * @return disguise |      * @return disguise | ||||||
|      */ |      */ | ||||||
|     public Disguise setEntity(Entity entity) { |     public Disguise setEntity(Entity entity) { | ||||||
|         if (this.getEntity() != null) { |         if (getEntity() != null) { | ||||||
|             if (getEntity() == entity) { |             if (getEntity() == entity) { | ||||||
|                 return this; |                 return this; | ||||||
|             } |             } | ||||||
| @@ -576,12 +645,6 @@ public abstract class Disguise { | |||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Disguise setShowName(boolean showName) { |  | ||||||
|         this.showName = showName; |  | ||||||
|  |  | ||||||
|         return this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Disguise setHearSelfDisguise(boolean hearSelfDisguise) { |     public Disguise setHearSelfDisguise(boolean hearSelfDisguise) { | ||||||
|         this.hearSelfDisguise = hearSelfDisguise; |         this.hearSelfDisguise = hearSelfDisguise; | ||||||
|  |  | ||||||
| @@ -608,6 +671,13 @@ public abstract class Disguise { | |||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setHidePlayer(boolean hidePlayerInTab) { | ||||||
|  |         if (isDisguiseInUse()) | ||||||
|  |             throw new IllegalStateException("Cannot set this while disguise is in use!"); // Cos I'm lazy | ||||||
|  |  | ||||||
|  |         playerHiddenFromTab = hidePlayerInTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { |     public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { | ||||||
|         this.keepDisguiseEntityDespawn = keepDisguise; |         this.keepDisguiseEntityDespawn = keepDisguise; | ||||||
|  |  | ||||||
| @@ -649,6 +719,12 @@ public abstract class Disguise { | |||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public Disguise setShowName(boolean showName) { | ||||||
|  |         this.showName = showName; | ||||||
|  |  | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the |      * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the | ||||||
|      * datawatcher. |      * datawatcher. | ||||||
| @@ -733,11 +809,37 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|             // If they cancelled this disguise event. No idea why. |             // If they cancelled this disguise event. No idea why. | ||||||
|             // Just return. |             // Just return. | ||||||
|             if (!event.isCancelled()) { |             if (event.isCancelled()) { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             disguiseInUse = true; |             disguiseInUse = true; | ||||||
|  |  | ||||||
|             task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1); |             task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1); | ||||||
|  |  | ||||||
|  |             if (this instanceof PlayerDisguise) { | ||||||
|  |                 PlayerDisguise disguise = (PlayerDisguise) this; | ||||||
|  |  | ||||||
|  |                 if (disguise.isDisplayedInTab()) { | ||||||
|  |                     PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                     addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||||
|  |                     addTab.getPlayerInfoDataLists().write(0, Arrays.asList(new PlayerInfoData(disguise.getGameProfile(), 0, | ||||||
|  |                             NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName())))); | ||||||
|  |  | ||||||
|  |                     try { | ||||||
|  |                         for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                             if (!((TargetedDisguise) this).canSee(player)) | ||||||
|  |                                 continue; | ||||||
|  |  | ||||||
|  |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|             // Stick the disguise in the disguises bin |             // Stick the disguise in the disguises bin | ||||||
|             DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); |             DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); | ||||||
|  |  | ||||||
| @@ -755,22 +857,34 @@ public abstract class Disguise { | |||||||
|                     DisguiseUtilities.setupFakeDisguise(Disguise.this); |                     DisguiseUtilities.setupFakeDisguise(Disguise.this); | ||||||
|                 } |                 } | ||||||
|             }, 2); |             }, 2); | ||||||
|  |  | ||||||
|  |             if (isHidePlayer() && getEntity() instanceof Player) { | ||||||
|  |                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                 addTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |                 addTab.getPlayerInfoDataLists().write(0, | ||||||
|  |                         Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||||
|  |                                 NativeGameMode.SURVIVAL, WrappedChatComponent.fromText("")))); | ||||||
|  |  | ||||||
|  |                 try { | ||||||
|  |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                         if (!((TargetedDisguise) this).canSee(player)) | ||||||
|  |                             continue; | ||||||
|  |  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 catch (InvocationTargetException e) { | ||||||
|  |                     e.printStackTrace(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean stopDisguise() { |     public boolean stopDisguise() { | ||||||
|         return removeDisguise(); |         return removeDisguise(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Returns the list of people who have /disguiseViewSelf toggled on |  | ||||||
|      * |  | ||||||
|      * @return |  | ||||||
|      */ |  | ||||||
|     public static List<UUID> getViewSelf() { |  | ||||||
|         return viewSelf; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,9 +1,21 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes; | package me.libraryaddict.disguise.disguisetypes; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.InvocationTargetException; | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.UUID; | ||||||
|  |  | ||||||
| import org.apache.commons.lang.Validate; | import org.apache.commons.lang.Validate; | ||||||
|  | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.PacketType; | ||||||
|  | import com.comphenix.protocol.ProtocolLibrary; | ||||||
|  | import com.comphenix.protocol.events.PacketContainer; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; | ||||||
|  | import com.comphenix.protocol.wrappers.PlayerInfoData; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| @@ -12,58 +24,51 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; | |||||||
| import me.libraryaddict.disguise.utilities.LibsProfileLookup; | import me.libraryaddict.disguise.utilities.LibsProfileLookup; | ||||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
|  |  | ||||||
| public class PlayerDisguise extends TargetedDisguise | public class PlayerDisguise extends TargetedDisguise { | ||||||
| { |  | ||||||
|     private LibsProfileLookup currentLookup; |     private LibsProfileLookup currentLookup; | ||||||
|     private WrappedGameProfile gameProfile; |     private WrappedGameProfile gameProfile; | ||||||
|     private String playerName; |     private String playerName; | ||||||
|     private String skinToUse; |     private String skinToUse; | ||||||
|  |     private UUID uuid = UUID.randomUUID(); | ||||||
|  |  | ||||||
|     private PlayerDisguise() |     private PlayerDisguise() { | ||||||
|     { |  | ||||||
|         // Internal usage only |         // Internal usage only | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(Player player) |     public PlayerDisguise(Player player) { | ||||||
|     { |  | ||||||
|         this(ReflectionManager.getGameProfile(player)); |         this(ReflectionManager.getGameProfile(player)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(Player player, Player skinToUse) |     public PlayerDisguise(Player player, Player skinToUse) { | ||||||
|     { |  | ||||||
|         this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse)); |         this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(String name) |     public PlayerDisguise(String name) { | ||||||
|     { |  | ||||||
|         setName(name); |         setName(name); | ||||||
|         setSkin(name); |         setSkin(name); | ||||||
|  |  | ||||||
|         createDisguise(DisguiseType.PLAYER); |         createDisguise(DisguiseType.PLAYER); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(String name, String skinToUse) |     public PlayerDisguise(String name, String skinToUse) { | ||||||
|     { |  | ||||||
|         setName(name); |         setName(name); | ||||||
|         setSkin(skinToUse); |         setSkin(skinToUse); | ||||||
|  |  | ||||||
|         createDisguise(DisguiseType.PLAYER); |         createDisguise(DisguiseType.PLAYER); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(WrappedGameProfile gameProfile) |     public PlayerDisguise(WrappedGameProfile gameProfile) { | ||||||
|     { |  | ||||||
|         setName(gameProfile.getName()); |         setName(gameProfile.getName()); | ||||||
|  |  | ||||||
|         this.gameProfile = gameProfile; |         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile); | ||||||
|  |  | ||||||
|         createDisguise(DisguiseType.PLAYER); |         createDisguise(DisguiseType.PLAYER); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) |     public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) { | ||||||
|     { |  | ||||||
|         setName(gameProfile.getName()); |         setName(gameProfile.getName()); | ||||||
|  |  | ||||||
|         this.gameProfile = gameProfile; |         this.gameProfile = ReflectionManager.getGameProfile(uuid, gameProfile.getName()); | ||||||
|  |  | ||||||
|         setSkin(skinToUse); |         setSkin(skinToUse); | ||||||
|  |  | ||||||
| @@ -71,31 +76,27 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise addPlayer(Player player) |     public PlayerDisguise addPlayer(Player player) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.addPlayer(player); |         return (PlayerDisguise) super.addPlayer(player); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise addPlayer(String playername) |     public PlayerDisguise addPlayer(String playername) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.addPlayer(playername); |         return (PlayerDisguise) super.addPlayer(playername); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise clone() |     public PlayerDisguise clone() { | ||||||
|     { |  | ||||||
|         PlayerDisguise disguise = new PlayerDisguise(); |         PlayerDisguise disguise = new PlayerDisguise(); | ||||||
|  |  | ||||||
|         disguise.playerName = getName(); |         disguise.playerName = getName(); | ||||||
|  |  | ||||||
|         if (disguise.currentLookup == null && disguise.gameProfile != null) |         if (disguise.currentLookup == null && disguise.gameProfile != null) { | ||||||
|         { |  | ||||||
|             disguise.skinToUse = getSkin(); |             disguise.skinToUse = getSkin(); | ||||||
|             disguise.gameProfile = ReflectionManager.getClonedProfile(getGameProfile()); |             disguise.gameProfile = ReflectionManager.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), | ||||||
|  |                     getGameProfile()); | ||||||
|         } |         } | ||||||
|         else |         else { | ||||||
|         { |  | ||||||
|             disguise.setSkin(getSkin()); |             disguise.setSkin(getSkin()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -107,8 +108,7 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         disguise.setVelocitySent(isVelocitySent()); |         disguise.setVelocitySent(isVelocitySent()); | ||||||
|         disguise.setModifyBoundingBox(isModifyBoundingBox()); |         disguise.setModifyBoundingBox(isModifyBoundingBox()); | ||||||
|  |  | ||||||
|         if (getWatcher() != null) |         if (getWatcher() != null) { | ||||||
|         { |  | ||||||
|             disguise.setWatcher(getWatcher().clone(disguise)); |             disguise.setWatcher(getWatcher().clone(disguise)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -117,17 +117,13 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         return disguise; |         return disguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public WrappedGameProfile getGameProfile() |     public WrappedGameProfile getGameProfile() { | ||||||
|     { |         if (gameProfile == null) { | ||||||
|         if (gameProfile == null) |             if (getSkin() != null) { | ||||||
|         { |                 gameProfile = ReflectionManager.getGameProfile(uuid, getName()); | ||||||
|             if (getSkin() != null) |  | ||||||
|             { |  | ||||||
|                 gameProfile = ReflectionManager.getGameProfile(null, getName()); |  | ||||||
|             } |             } | ||||||
|             else |             else { | ||||||
|             { |                 gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getName(), | ||||||
|                 gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), |  | ||||||
|                         DisguiseUtilities.getProfileFromMojang(this)); |                         DisguiseUtilities.getProfileFromMojang(this)); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -135,103 +131,93 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         return gameProfile; |         return gameProfile; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getName() |     public String getName() { | ||||||
|     { |  | ||||||
|         return playerName; |         return playerName; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getSkin() |     public String getSkin() { | ||||||
|     { |  | ||||||
|         return skinToUse; |         return skinToUse; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerWatcher getWatcher() |     public PlayerWatcher getWatcher() { | ||||||
|     { |  | ||||||
|         return (PlayerWatcher) super.getWatcher(); |         return (PlayerWatcher) super.getWatcher(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isDisplayedInTab() { | ||||||
|  |         return getWatcher().isDisplayedInTab(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean isPlayerDisguise() |     public boolean isPlayerDisguise() { | ||||||
|     { |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise removePlayer(Player player) |     public PlayerDisguise removePlayer(Player player) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.removePlayer(player); |         return (PlayerDisguise) super.removePlayer(player); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise removePlayer(String playername) |     public PlayerDisguise removePlayer(String playername) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.removePlayer(playername); |         return (PlayerDisguise) super.removePlayer(playername); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setDisguiseTarget(TargetType newTargetType) |     public PlayerDisguise setDisguiseTarget(TargetType newTargetType) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setDisguiseTarget(newTargetType); |         return (PlayerDisguise) super.setDisguiseTarget(newTargetType); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setDisplayedInTab(boolean showPlayerInTab) { | ||||||
|  |         getWatcher().setDisplayedInTab(showPlayerInTab); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setEntity(Entity entity) |     public PlayerDisguise setEntity(Entity entity) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setEntity(entity); |         return (PlayerDisguise) super.setEntity(entity); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setGameProfile(WrappedGameProfile gameProfile) |     public void setGameProfile(WrappedGameProfile gameProfile) { | ||||||
|     { |         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, gameProfile.getName(), gameProfile); | ||||||
|         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) |     public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise); |         return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) |     public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor); |         return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) |     public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem); |         return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) |     public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise); |         return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) |     public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise); |         return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) |     public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise); |         return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setModifyBoundingBox(boolean modifyBox) |     public PlayerDisguise setModifyBoundingBox(boolean modifyBox) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setModifyBoundingBox(modifyBox); |         return (PlayerDisguise) super.setModifyBoundingBox(modifyBox); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void setName(String name) |     private void setName(String name) { | ||||||
|     { |         if (name.length() > 16) { | ||||||
|         if (name.length() > 16) |  | ||||||
|         { |  | ||||||
|             name = name.substring(0, 16); |             name = name.substring(0, 16); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -239,32 +225,25 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) |     public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced); |         return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise setSkin(String newSkin) |     public PlayerDisguise setSkin(String newSkin) { | ||||||
|     { |  | ||||||
|         skinToUse = newSkin; |         skinToUse = newSkin; | ||||||
|  |  | ||||||
|         if (newSkin == null) |         if (newSkin == null) { | ||||||
|         { |  | ||||||
|             currentLookup = null; |             currentLookup = null; | ||||||
|             gameProfile = null; |             gameProfile = null; | ||||||
|         } |         } | ||||||
|         else |         else { | ||||||
|         { |             if (newSkin.length() > 16) { | ||||||
|             if (newSkin.length() > 16) |  | ||||||
|             { |  | ||||||
|                 skinToUse = newSkin.substring(0, 16); |                 skinToUse = newSkin.substring(0, 16); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             currentLookup = new LibsProfileLookup() |             currentLookup = new LibsProfileLookup() { | ||||||
|             { |  | ||||||
|                 @Override |                 @Override | ||||||
|                 public void onLookup(WrappedGameProfile gameProfile) |                 public void onLookup(WrappedGameProfile gameProfile) { | ||||||
|                 { |  | ||||||
|                     if (currentLookup != this || gameProfile == null) |                     if (currentLookup != this || gameProfile == null) | ||||||
|                         return; |                         return; | ||||||
|  |  | ||||||
| @@ -277,8 +256,7 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|             WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, |             WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, | ||||||
|                     LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); |                     LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); | ||||||
|  |  | ||||||
|             if (gameProfile != null) |             if (gameProfile != null) { | ||||||
|             { |  | ||||||
|                 setSkin(gameProfile); |                 setSkin(gameProfile); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -293,10 +271,8 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|      *            GameProfile |      *            GameProfile | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     public PlayerDisguise setSkin(WrappedGameProfile gameProfile) |     public PlayerDisguise setSkin(WrappedGameProfile gameProfile) { | ||||||
|     { |         if (gameProfile == null) { | ||||||
|         if (gameProfile == null) |  | ||||||
|         { |  | ||||||
|             this.gameProfile = null; |             this.gameProfile = null; | ||||||
|             this.skinToUse = null; |             this.skinToUse = null; | ||||||
|             return this; |             return this; | ||||||
| @@ -307,10 +283,32 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         currentLookup = null; |         currentLookup = null; | ||||||
|  |  | ||||||
|         this.skinToUse = gameProfile.getName(); |         this.skinToUse = gameProfile.getName(); | ||||||
|         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile); |         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getName(), gameProfile); | ||||||
|  |  | ||||||
|  |         if (DisguiseUtilities.isDisguiseInUse(this)) { | ||||||
|  |             if (isDisplayedInTab()) { | ||||||
|  |                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                 addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||||
|  |                 addTab.getPlayerInfoDataLists().write(0, Arrays.asList(new PlayerInfoData(getGameProfile(), 0, | ||||||
|  |                         NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(getName())))); | ||||||
|  |  | ||||||
|  |                 PacketContainer deleteTab = addTab.shallowClone(); | ||||||
|  |                 deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |  | ||||||
|  |                 try { | ||||||
|  |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                         if (!((TargetedDisguise) this).canSee(player)) | ||||||
|  |                             continue; | ||||||
|  |  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 catch (InvocationTargetException e) { | ||||||
|  |                     e.printStackTrace(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|         if (DisguiseUtilities.isDisguiseInUse(this)) |  | ||||||
|         { |  | ||||||
|             DisguiseUtilities.refreshTrackers(this); |             DisguiseUtilities.refreshTrackers(this); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -318,32 +316,27 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setVelocitySent(boolean sendVelocity) |     public PlayerDisguise setVelocitySent(boolean sendVelocity) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setVelocitySent(sendVelocity); |         return (PlayerDisguise) super.setVelocitySent(sendVelocity); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) |     public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise); |         return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise setWatcher(FlagWatcher newWatcher) |     public PlayerDisguise setWatcher(FlagWatcher newWatcher) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.setWatcher(newWatcher); |         return (PlayerDisguise) super.setWatcher(newWatcher); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise silentlyAddPlayer(String playername) |     public PlayerDisguise silentlyAddPlayer(String playername) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.silentlyAddPlayer(playername); |         return (PlayerDisguise) super.silentlyAddPlayer(playername); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise silentlyRemovePlayer(String playername) |     public PlayerDisguise silentlyRemovePlayer(String playername) { | ||||||
|     { |  | ||||||
|         return (PlayerDisguise) super.silentlyRemovePlayer(playername); |         return (PlayerDisguise) super.silentlyRemovePlayer(playername); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,102 +1,141 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes; | package me.libraryaddict.disguise.disguisetypes; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.InvocationTargetException; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | import java.util.Arrays; | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
|  | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.PacketType; | ||||||
|  | import com.comphenix.protocol.ProtocolLibrary; | ||||||
|  | import com.comphenix.protocol.events.PacketContainer; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; | ||||||
|  | import com.comphenix.protocol.wrappers.PlayerInfoData; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
|  |  | ||||||
| public abstract class TargetedDisguise extends Disguise | public abstract class TargetedDisguise extends Disguise { | ||||||
| { |  | ||||||
|  |  | ||||||
|     public enum TargetType |     public enum TargetType { | ||||||
|     { |  | ||||||
|         HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS |         HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private List<String> disguiseViewers = new ArrayList<>(); |     private List<String> disguiseViewers = new ArrayList<>(); | ||||||
|     private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS; |     private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS; | ||||||
|  |  | ||||||
|     public TargetedDisguise addPlayer(Player player) |     public TargetedDisguise addPlayer(Player player) { | ||||||
|     { |  | ||||||
|         addPlayer(player.getName()); |         addPlayer(player.getName()); | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise addPlayer(String playername) |     public TargetedDisguise addPlayer(String playername) { | ||||||
|     { |         if (!disguiseViewers.contains(playername)) { | ||||||
|         if (!disguiseViewers.contains(playername)) |  | ||||||
|         { |  | ||||||
|             disguiseViewers.add(playername); |             disguiseViewers.add(playername); | ||||||
|  |  | ||||||
|             if (DisguiseAPI.isDisguiseInUse(this)) |             if (DisguiseAPI.isDisguiseInUse(this)) { | ||||||
|             { |  | ||||||
|                 DisguiseUtilities.checkConflicts(this, playername); |                 DisguiseUtilities.checkConflicts(this, playername); | ||||||
|                 DisguiseUtilities.refreshTracker(this, playername); |                 DisguiseUtilities.refreshTracker(this, playername); | ||||||
|  |  | ||||||
|  |                 if (isHidePlayer() && getEntity() instanceof Player) { | ||||||
|  |                     try { | ||||||
|  |                         Player player = Bukkit.getPlayerExact(playername); | ||||||
|  |  | ||||||
|  |                         if (player != null) { | ||||||
|  |                             PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |  | ||||||
|  |                             deleteTab.getPlayerInfoAction().write(0, | ||||||
|  |                                     canSee(player) ? PlayerInfoAction.REMOVE_PLAYER : PlayerInfoAction.ADD_PLAYER); | ||||||
|  |                             deleteTab.getPlayerInfoDataLists().write(0, | ||||||
|  |                                     Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||||
|  |                                             NativeGameMode.SURVIVAL, | ||||||
|  |                                             WrappedChatComponent.fromText(((Player) getEntity()).getDisplayName())))); | ||||||
|  |  | ||||||
|  |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean canSee(Player player) |     public boolean canSee(Player player) { | ||||||
|     { |  | ||||||
|         return canSee(player.getName()); |         return canSee(player.getName()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean canSee(String playername) |     public boolean canSee(String playername) { | ||||||
|     { |  | ||||||
|         boolean hasPlayer = disguiseViewers.contains(playername); |         boolean hasPlayer = disguiseViewers.contains(playername); | ||||||
|  |  | ||||||
|         if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) |         if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { | ||||||
|         { |  | ||||||
|             return !hasPlayer; |             return !hasPlayer; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return hasPlayer; |         return hasPlayer; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetType getDisguiseTarget() |     public TargetType getDisguiseTarget() { | ||||||
|     { |  | ||||||
|         return targetType; |         return targetType; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public List<String> getObservers() |     public List<String> getObservers() { | ||||||
|     { |  | ||||||
|         return Collections.unmodifiableList(disguiseViewers); |         return Collections.unmodifiableList(disguiseViewers); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise removePlayer(Player player) |     public TargetedDisguise removePlayer(Player player) { | ||||||
|     { |  | ||||||
|         removePlayer(player.getName()); |         removePlayer(player.getName()); | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise removePlayer(String playername) |     public TargetedDisguise removePlayer(String playername) { | ||||||
|     { |         if (disguiseViewers.contains(playername)) { | ||||||
|         if (disguiseViewers.contains(playername)) |  | ||||||
|         { |  | ||||||
|             disguiseViewers.remove(playername); |             disguiseViewers.remove(playername); | ||||||
|  |  | ||||||
|             if (DisguiseAPI.isDisguiseInUse(this)) |             if (DisguiseAPI.isDisguiseInUse(this)) { | ||||||
|             { |  | ||||||
|                 DisguiseUtilities.checkConflicts(this, playername); |                 DisguiseUtilities.checkConflicts(this, playername); | ||||||
|                 DisguiseUtilities.refreshTracker(this, playername); |                 DisguiseUtilities.refreshTracker(this, playername); | ||||||
|  |  | ||||||
|  |                 if (isHidePlayer() && getEntity() instanceof Player) { | ||||||
|  |                     try { | ||||||
|  |                         Player player = Bukkit.getPlayerExact(playername); | ||||||
|  |  | ||||||
|  |                         if (player != null) { | ||||||
|  |                             PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |  | ||||||
|  |                             deleteTab.getPlayerInfoAction().write(0, | ||||||
|  |                                     canSee(player) ? PlayerInfoAction.ADD_PLAYER : PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |                             deleteTab.getPlayerInfoDataLists().write(0, | ||||||
|  |                                     Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||||
|  |                                             NativeGameMode.SURVIVAL, | ||||||
|  |                                             WrappedChatComponent.fromText(((Player) getEntity()).getDisplayName())))); | ||||||
|  |  | ||||||
|  |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise setDisguiseTarget(TargetType newTargetType) |     public TargetedDisguise setDisguiseTarget(TargetType newTargetType) { | ||||||
|     { |         if (DisguiseUtilities.isDisguiseInUse(this)) { | ||||||
|         if (DisguiseUtilities.isDisguiseInUse(this)) |  | ||||||
|         { |  | ||||||
|             throw new RuntimeException("Cannot set the disguise target after the entity has been disguised"); |             throw new RuntimeException("Cannot set the disguise target after the entity has been disguised"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -105,20 +144,16 @@ public abstract class TargetedDisguise extends Disguise | |||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise silentlyAddPlayer(String playername) |     public TargetedDisguise silentlyAddPlayer(String playername) { | ||||||
|     { |         if (!disguiseViewers.contains(playername)) { | ||||||
|         if (!disguiseViewers.contains(playername)) |  | ||||||
|         { |  | ||||||
|             disguiseViewers.add(playername); |             disguiseViewers.add(playername); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public TargetedDisguise silentlyRemovePlayer(String playername) |     public TargetedDisguise silentlyRemovePlayer(String playername) { | ||||||
|     { |         if (disguiseViewers.contains(playername)) { | ||||||
|         if (disguiseViewers.contains(playername)) |  | ||||||
|         { |  | ||||||
|             disguiseViewers.remove(playername); |             disguiseViewers.remove(playername); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,48 +17,53 @@ import me.libraryaddict.disguise.disguisetypes.FlagType; | |||||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  |  | ||||||
| public class PlayerWatcher extends LivingWatcher | public class PlayerWatcher extends LivingWatcher { | ||||||
| { |  | ||||||
|     private boolean isInBed; |     private boolean isInBed; | ||||||
|     private BlockFace sleepingDirection; |     private BlockFace sleepingDirection; | ||||||
|  |     private boolean alwaysShowInTab = DisguiseConfig.isShowDisguisedPlayersInTab(); | ||||||
|  |  | ||||||
|     public PlayerWatcher(Disguise disguise) |     public PlayerWatcher(Disguise disguise) { | ||||||
|     { |  | ||||||
|         super(disguise); |         super(disguise); | ||||||
|  |  | ||||||
|         setData(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault()); |         setData(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isDisplayedInTab() { | ||||||
|  |         return alwaysShowInTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setDisplayedInTab(boolean showPlayerInTab) { | ||||||
|  |         if (getDisguise().isDisguiseInUse()) | ||||||
|  |             throw new IllegalStateException("Cannot set this while disguise is in use!"); | ||||||
|  |  | ||||||
|  |         alwaysShowInTab = showPlayerInTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerWatcher clone(Disguise disguise) |     public PlayerWatcher clone(Disguise disguise) { | ||||||
|     { |  | ||||||
|         PlayerWatcher watcher = (PlayerWatcher) super.clone(disguise); |         PlayerWatcher watcher = (PlayerWatcher) super.clone(disguise); | ||||||
|         watcher.isInBed = isInBed; |         watcher.isInBed = isInBed; | ||||||
|  |         watcher.sleepingDirection = sleepingDirection; | ||||||
|  |         watcher.alwaysShowInTab = alwaysShowInTab; | ||||||
|         return watcher; |         return watcher; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setMainHand(MainHand mainHand) |     public void setMainHand(MainHand mainHand) { | ||||||
|     { |  | ||||||
|         setData(FlagType.PLAYER_HAND, (byte) mainHand.ordinal()); |         setData(FlagType.PLAYER_HAND, (byte) mainHand.ordinal()); | ||||||
|         sendData(FlagType.PLAYER_HAND); |         sendData(FlagType.PLAYER_HAND); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public MainHand getMainHand() |     public MainHand getMainHand() { | ||||||
|     { |  | ||||||
|         return MainHand.values()[getData(FlagType.PLAYER_HAND)]; |         return MainHand.values()[getData(FlagType.PLAYER_HAND)]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public BlockFace getSleepingDirection() |     public BlockFace getSleepingDirection() { | ||||||
|     { |         if (sleepingDirection == null) { | ||||||
|         if (sleepingDirection == null) |             if (this.getDisguise().getEntity() != null && isSleeping()) { | ||||||
|         { |  | ||||||
|             if (this.getDisguise().getEntity() != null && isSleeping()) |  | ||||||
|             { |  | ||||||
|                 this.sleepingDirection = BlockFace |                 this.sleepingDirection = BlockFace | ||||||
|                         .values()[Math.round(this.getDisguise().getEntity().getLocation().getYaw() / 90F) & 0x3]; |                         .values()[Math.round(this.getDisguise().getEntity().getLocation().getYaw() / 90F) & 0x3]; | ||||||
|             } |             } | ||||||
|             else |             else { | ||||||
|             { |  | ||||||
|                 return BlockFace.EAST; |                 return BlockFace.EAST; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -73,117 +78,97 @@ public class PlayerWatcher extends LivingWatcher | |||||||
|     // Bit 5 (0x20): Right Pants Leg enabled |     // Bit 5 (0x20): Right Pants Leg enabled | ||||||
|     // Bit 6 (0x40): Hat enabled |     // Bit 6 (0x40): Hat enabled | ||||||
|  |  | ||||||
|     private boolean isSkinFlag(int i) |     private boolean isSkinFlag(int i) { | ||||||
|     { |  | ||||||
|         return ((byte) getData(FlagType.PLAYER_SKIN) & 1 << i) != 0; |         return ((byte) getData(FlagType.PLAYER_SKIN) & 1 << i) != 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isCapeEnabled() |     public boolean isCapeEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(1); |         return isSkinFlag(1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isJackedEnabled() |     public boolean isJackedEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(2); |         return isSkinFlag(2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isLeftSleeveEnabled() |     public boolean isLeftSleeveEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(3); |         return isSkinFlag(3); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isRightSleeveEnabled() |     public boolean isRightSleeveEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(4); |         return isSkinFlag(4); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isLeftPantsEnabled() |     public boolean isLeftPantsEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(5); |         return isSkinFlag(5); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isRightPantsEnabled() |     public boolean isRightPantsEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(6); |         return isSkinFlag(6); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isHatEnabled() |     public boolean isHatEnabled() { | ||||||
|     { |  | ||||||
|         return isSkinFlag(7); |         return isSkinFlag(7); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setCapeEnabled(boolean enabled) |     public void setCapeEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(1, enabled); |         setSkinFlags(1, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setJackedEnabled(boolean enabled) |     public void setJacketEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(2, enabled); |         setSkinFlags(2, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setLeftSleeveEnabled(boolean enabled) |     public void setLeftSleeveEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(3, enabled); |         setSkinFlags(3, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setRightSleeveEnabled(boolean enabled) |     public void setRightSleeveEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(4, enabled); |         setSkinFlags(4, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setLeftPantsEnabled(boolean enabled) |     public void setLeftPantsEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(5, enabled); |         setSkinFlags(5, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setRightPantsEnabled(boolean enabled) |     public void setRightPantsEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(6, enabled); |         setSkinFlags(6, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setHatEnabled(boolean enabled) |     public void setHatEnabled(boolean enabled) { | ||||||
|     { |  | ||||||
|         setSkinFlags(7, enabled); |         setSkinFlags(7, enabled); | ||||||
|  |  | ||||||
|         sendData(FlagType.PLAYER_SKIN); |         sendData(FlagType.PLAYER_SKIN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isSleeping() |     public boolean isSleeping() { | ||||||
|     { |  | ||||||
|         return isInBed; |         return isInBed; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSkin(String playerName) |     public void setSkin(String playerName) { | ||||||
|     { |  | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(playerName); |         ((PlayerDisguise) getDisguise()).setSkin(playerName); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSkin(WrappedGameProfile profile) |     public void setSkin(WrappedGameProfile profile) { | ||||||
|     { |  | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(profile); |         ((PlayerDisguise) getDisguise()).setSkin(profile); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSleeping(BlockFace sleepingDirection) |     public void setSleeping(BlockFace sleepingDirection) { | ||||||
|     { |  | ||||||
|         setSleeping(true, sleepingDirection); |         setSleeping(true, sleepingDirection); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSleeping(boolean sleep) |     public void setSleeping(boolean sleep) { | ||||||
|     { |  | ||||||
|         setSleeping(sleep, null); |         setSleeping(sleep, null); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -193,30 +178,22 @@ public class PlayerWatcher extends LivingWatcher | |||||||
|      * @param sleeping |      * @param sleeping | ||||||
|      * @param sleepingDirection |      * @param sleepingDirection | ||||||
|      */ |      */ | ||||||
|     public void setSleeping(boolean sleeping, BlockFace sleepingDirection) |     public void setSleeping(boolean sleeping, BlockFace sleepingDirection) { | ||||||
|     { |         if (sleepingDirection != null) { | ||||||
|         if (sleepingDirection != null) |  | ||||||
|         { |  | ||||||
|             this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4]; |             this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         isInBed = sleeping; |         isInBed = sleeping; | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise())) |         if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise())) { | ||||||
|         { |             try { | ||||||
|             try |                 if (isSleeping()) { | ||||||
|             { |                     for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { | ||||||
|                 if (isSleeping()) |  | ||||||
|                 { |  | ||||||
|                     for (Player player : DisguiseUtilities.getPerverts(getDisguise())) |  | ||||||
|                     { |  | ||||||
|                         PacketContainer[] packets = DisguiseUtilities.getBedPackets(getDisguise().getEntity().getLocation(), |                         PacketContainer[] packets = DisguiseUtilities.getBedPackets(getDisguise().getEntity().getLocation(), | ||||||
|                                 player.getLocation(), (PlayerDisguise) getDisguise()); |                                 player.getLocation(), (PlayerDisguise) getDisguise()); | ||||||
|  |  | ||||||
|                         if (getDisguise().getEntity() == player) |                         if (getDisguise().getEntity() == player) { | ||||||
|                         { |                             for (PacketContainer packet : packets) { | ||||||
|                             for (PacketContainer packet : packets) |  | ||||||
|                             { |  | ||||||
|                                 packet = packet.shallowClone(); |                                 packet = packet.shallowClone(); | ||||||
|  |  | ||||||
|                                 packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                                 packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
| @@ -224,17 +201,14 @@ public class PlayerWatcher extends LivingWatcher | |||||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                         else |                         else { | ||||||
|                         { |                             for (PacketContainer packet : packets) { | ||||||
|                             for (PacketContainer packet : packets) |  | ||||||
|                             { |  | ||||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else |                 else { | ||||||
|                 { |  | ||||||
|                     PacketContainer packet = new PacketContainer(Server.ANIMATION); |                     PacketContainer packet = new PacketContainer(Server.ANIMATION); | ||||||
|  |  | ||||||
|                     StructureModifier<Integer> mods = packet.getIntegers(); |                     StructureModifier<Integer> mods = packet.getIntegers(); | ||||||
| @@ -242,29 +216,24 @@ public class PlayerWatcher extends LivingWatcher | |||||||
|                     mods.write(0, getDisguise().getEntity().getEntityId()); |                     mods.write(0, getDisguise().getEntity().getEntityId()); | ||||||
|                     mods.write(1, 3); |                     mods.write(1, 3); | ||||||
|  |  | ||||||
|                     for (Player player : DisguiseUtilities.getPerverts(getDisguise())) |                     for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { | ||||||
|                     { |  | ||||||
|                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) { | ||||||
|             { |  | ||||||
|                 ex.printStackTrace(); |                 ex.printStackTrace(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void setSkinFlags(int i, boolean flag) |     private void setSkinFlags(int i, boolean flag) { | ||||||
|     { |  | ||||||
|         byte b0 = (byte) getData(FlagType.PLAYER_SKIN); |         byte b0 = (byte) getData(FlagType.PLAYER_SKIN); | ||||||
|  |  | ||||||
|         if (flag) |         if (flag) { | ||||||
|         { |  | ||||||
|             setData(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); |             setData(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); | ||||||
|         } |         } | ||||||
|         else |         else { | ||||||
|         { |  | ||||||
|             setData(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); |             setData(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -278,8 +278,6 @@ public class DisguiseUtilities { | |||||||
|                             // But the rest of the time.. Its going to conflict. |                             // But the rest of the time.. Its going to conflict. | ||||||
|                             // The below is debug output. Most people wouldn't care for it. |                             // The below is debug output. Most people wouldn't care for it. | ||||||
|  |  | ||||||
|                             // System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS |  | ||||||
|                             // + " on a entity. Removed the old disguise."); |  | ||||||
|                             disguiseItel.remove(); |                             disguiseItel.remove(); | ||||||
|                             d.removeDisguise(); |                             d.removeDisguise(); | ||||||
|                         } |                         } | ||||||
|   | |||||||
| @@ -52,6 +52,7 @@ import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerClientI | |||||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerInventory; | import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerInventory; | ||||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerMain; | import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerMain; | ||||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerSounds; | import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerSounds; | ||||||
|  | import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerTabList; | ||||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerViewDisguises; | import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerViewDisguises; | ||||||
|  |  | ||||||
| public class PacketsManager { | public class PacketsManager { | ||||||
| @@ -139,6 +140,7 @@ public class PacketsManager { | |||||||
|     private static PacketListener soundsListener; |     private static PacketListener soundsListener; | ||||||
|     private static boolean soundsListenerEnabled; |     private static boolean soundsListenerEnabled; | ||||||
|     private static PacketListener viewDisguisesListener; |     private static PacketListener viewDisguisesListener; | ||||||
|  |     private static PacketListener tabListListener; | ||||||
|     private static boolean viewDisguisesListenerEnabled; |     private static boolean viewDisguisesListenerEnabled; | ||||||
|     private static HashMap<Disguise, ArrayList<UUID>> _cancelMeta = new HashMap<Disguise, ArrayList<UUID>>(); |     private static HashMap<Disguise, ArrayList<UUID>> _cancelMeta = new HashMap<Disguise, ArrayList<UUID>>(); | ||||||
|  |  | ||||||
| @@ -148,8 +150,10 @@ public class PacketsManager { | |||||||
|         // Because it kicks you for hacking. |         // Because it kicks you for hacking. | ||||||
|  |  | ||||||
|         clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises); |         clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises); | ||||||
|  |         tabListListener = new PacketListenerTabList(libsDisguises); | ||||||
|  |  | ||||||
|         ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener); |         ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener); | ||||||
|  |         ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener); | ||||||
|  |  | ||||||
|         // Now I call this and the main listener is registered! |         // Now I call this and the main listener is registered! | ||||||
|         setupMainPacketsListener(); |         setupMainPacketsListener(); | ||||||
| @@ -310,6 +314,8 @@ public class PacketsManager { | |||||||
|  |  | ||||||
|             // Send player info along with the disguise |             // Send player info along with the disguise | ||||||
|             PacketContainer sendTab = new PacketContainer(Server.PLAYER_INFO); |             PacketContainer sendTab = new PacketContainer(Server.PLAYER_INFO); | ||||||
|  |  | ||||||
|  |             if (!((PlayerDisguise) disguise).isDisplayedInTab()) | ||||||
|                 packets.addPacket(sendTab); |                 packets.addPacket(sendTab); | ||||||
|  |  | ||||||
|             // Add player to the list, necessary to spawn them |             // Add player to the list, necessary to spawn them | ||||||
| @@ -405,9 +411,11 @@ public class PacketsManager { | |||||||
|  |  | ||||||
|             // Remove player from the list |             // Remove player from the list | ||||||
|             PacketContainer deleteTab = sendTab.shallowClone(); |             PacketContainer deleteTab = sendTab.shallowClone(); | ||||||
|             packets.addDelayedPacket(deleteTab, 40); |  | ||||||
|  |  | ||||||
|             deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); |             deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); | ||||||
|  |  | ||||||
|  |             if (!((PlayerDisguise) disguise).isDisplayedInTab()) { | ||||||
|  |                 packets.addDelayedPacket(deleteTab, 40); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { |         else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { | ||||||
|             Vector vec = disguisedEntity.getVelocity(); |             Vector vec = disguisedEntity.getVelocity(); | ||||||
|   | |||||||
| @@ -225,7 +225,7 @@ public class ReflectionFlagWatchers { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (String methodName : new String[] { |         for (String methodName : new String[] { | ||||||
|                 "setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise" |                 "setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer" | ||||||
|         }) { |         }) { | ||||||
|             try { |             try { | ||||||
|                 methods.add(Disguise.class.getMethod(methodName, boolean.class)); |                 methods.add(Disguise.class.getMethod(methodName, boolean.class)); | ||||||
|   | |||||||
| @@ -0,0 +1,65 @@ | |||||||
|  | package me.libraryaddict.disguise.utilities.packetlisteners; | ||||||
|  |  | ||||||
|  | import java.util.Iterator; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.PacketType; | ||||||
|  | import com.comphenix.protocol.events.ListenerPriority; | ||||||
|  | import com.comphenix.protocol.events.PacketAdapter; | ||||||
|  | import com.comphenix.protocol.events.PacketEvent; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; | ||||||
|  | import com.comphenix.protocol.wrappers.PlayerInfoData; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
|  | import me.libraryaddict.disguise.LibsDisguises; | ||||||
|  | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
|  |  | ||||||
|  | public class PacketListenerTabList extends PacketAdapter { | ||||||
|  |     public PacketListenerTabList(LibsDisguises plugin) { | ||||||
|  |         super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void onPacketSending(final PacketEvent event) { | ||||||
|  |         if (event.isCancelled()) | ||||||
|  |             return; | ||||||
|  |  | ||||||
|  |         Player observer = event.getPlayer(); | ||||||
|  |  | ||||||
|  |         if (event.getPacket().getPlayerInfoAction().read(0) != PlayerInfoAction.ADD_PLAYER) | ||||||
|  |             return; | ||||||
|  |  | ||||||
|  |         List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(0); | ||||||
|  |         Iterator<PlayerInfoData> itel = list.iterator(); | ||||||
|  |  | ||||||
|  |         while (itel.hasNext()) { | ||||||
|  |             PlayerInfoData data = itel.next(); | ||||||
|  |  | ||||||
|  |             Player player = Bukkit.getPlayer(data.getProfile().getUUID()); | ||||||
|  |  | ||||||
|  |             if (player == null) | ||||||
|  |                 continue; | ||||||
|  |  | ||||||
|  |             Disguise disguise = DisguiseAPI.getDisguise(observer, player); | ||||||
|  |  | ||||||
|  |             if (disguise == null) | ||||||
|  |                 continue; | ||||||
|  |  | ||||||
|  |             if (!disguise.isHidePlayer()) | ||||||
|  |                 continue; | ||||||
|  |  | ||||||
|  |             itel.remove(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (list.isEmpty()) { | ||||||
|  |             event.setCancelled(true); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             event.getPacket().getPlayerInfoDataLists().write(0, list); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user