Improve tablist handling
This commit is contained in:
		| @@ -43,7 +43,7 @@ import org.bukkit.scoreboard.Team; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
|  | ||||
| @@ -291,8 +291,8 @@ public class DisguiseListener implements Listener { | ||||
|             chunkMove(p, p.getLocation(), null); | ||||
|         } | ||||
|  | ||||
|         if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && DisguiseUtilities | ||||
|                 .hasGameProfile(p.getName())) { | ||||
|         if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && | ||||
|                 DisguiseUtilities.hasGameProfile(p.getName())) { | ||||
|             WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p); | ||||
|  | ||||
|             if (!profile.getProperties().isEmpty()) { | ||||
| @@ -331,7 +331,7 @@ public class DisguiseListener implements Listener { | ||||
|                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||
|  | ||||
|                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||
|                         addTab.getPlayerInfoDataLists().write(0, Arrays.asList( | ||||
|                         addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||
|                                 new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, | ||||
|                                         WrappedChatComponent.fromText(disguise.getGameProfile().getName())))); | ||||
|  | ||||
| @@ -354,9 +354,9 @@ public class DisguiseListener implements Listener { | ||||
|             Location to = event.getTo(); | ||||
|             Location from = event.getFrom(); | ||||
|  | ||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities | ||||
|                     .getChunkCord(from.getBlockX()) || DisguiseUtilities | ||||
|                     .getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) || | ||||
|                     DisguiseUtilities.getChunkCord(to.getBlockZ()) != | ||||
|                             DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||
|                 chunkMove(event.getPlayer(), to, from); | ||||
|             } | ||||
|         } | ||||
| @@ -365,8 +365,8 @@ public class DisguiseListener implements Listener { | ||||
|             Disguise disguise; | ||||
|  | ||||
|             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 to = event.getTo(); | ||||
|  | ||||
| @@ -422,8 +422,8 @@ public class DisguiseListener implements Listener { | ||||
|     public void onRightClick(PlayerInteractEntityEvent event) { | ||||
|         Player p = event.getPlayer(); | ||||
|  | ||||
|         if (!disguiseEntity.containsKey(p.getName()) && !disguiseClone.containsKey(p.getName()) && !disguiseModify | ||||
|                 .containsKey(p.getName())) { | ||||
|         if (!disguiseEntity.containsKey(p.getName()) && !disguiseClone.containsKey(p.getName()) && | ||||
|                 !disguiseModify.containsKey(p.getName())) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @@ -447,8 +447,8 @@ public class DisguiseListener implements Listener { | ||||
|             Disguise disguise = disguiseEntity.remove(p.getName()); | ||||
|  | ||||
|             if (disguise != null) { | ||||
|                 if (disguise.isMiscDisguise() && !DisguiseConfig | ||||
|                         .isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { | ||||
|                 if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && | ||||
|                         entity instanceof LivingEntity) { | ||||
|                     p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get()); | ||||
|                 } else { | ||||
|                     if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||
| @@ -456,8 +456,8 @@ public class DisguiseListener implements Listener { | ||||
|                             Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName()); | ||||
|  | ||||
|                             disguise.getWatcher().setCustomName( | ||||
|                                     (team == null ? "" : team.getPrefix()) + entity.getName() + (team == null ? "" : | ||||
|                                             team.getSuffix())); | ||||
|                                     (team == null ? "" : team.getPrefix()) + entity.getName() + | ||||
|                                             (team == null ? "" : team.getSuffix())); | ||||
|  | ||||
|                             if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||
|                                 disguise.getWatcher().setCustomNameVisible(true); | ||||
| @@ -561,8 +561,8 @@ public class DisguiseListener implements Listener { | ||||
|  | ||||
|     @EventHandler | ||||
|     public void onTarget(EntityTargetEvent event) { | ||||
|         if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event | ||||
|                 .getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) { | ||||
|         if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && | ||||
|                 event.getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) { | ||||
|             switch (event.getReason()) { | ||||
|                 case TARGET_ATTACKED_ENTITY: | ||||
|                 case TARGET_ATTACKED_OWNER: | ||||
| @@ -583,9 +583,9 @@ public class DisguiseListener implements Listener { | ||||
|         Location from = event.getFrom(); | ||||
|  | ||||
|         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities | ||||
|                     .getChunkCord(from.getBlockX()) || DisguiseUtilities | ||||
|                     .getChunkCord(to.getBlockZ()) != DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||
|             if (DisguiseUtilities.getChunkCord(to.getBlockX()) != DisguiseUtilities.getChunkCord(from.getBlockX()) || | ||||
|                     DisguiseUtilities.getChunkCord(to.getBlockZ()) != | ||||
|                             DisguiseUtilities.getChunkCord(from.getBlockZ())) { | ||||
|                 chunkMove(player, null, from); | ||||
|  | ||||
|                 Bukkit.getScheduler().runTask(plugin, new Runnable() { | ||||
| @@ -601,8 +601,8 @@ public class DisguiseListener implements Listener { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && to | ||||
|                 .getWorld() != from.getWorld()) { | ||||
|         if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null && | ||||
|                 to.getWorld() != from.getWorld()) { | ||||
|             for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { | ||||
|                 disguise.removeDisguise(); | ||||
|             } | ||||
| @@ -611,8 +611,8 @@ public class DisguiseListener implements Listener { | ||||
|  | ||||
|     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||||
|     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()); | ||||
|  | ||||
|             ((Player) event.getEntered()).updateInventory(); | ||||
|   | ||||
| @@ -29,7 +29,6 @@ import org.bukkit.entity.Player; | ||||
| import org.bukkit.scheduler.BukkitTask; | ||||
| import org.bukkit.util.Vector; | ||||
|  | ||||
| import java.io.Serializable; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.*; | ||||
|  | ||||
| @@ -74,8 +73,9 @@ public abstract class Disguise { | ||||
|      */ | ||||
|     protected void createDisguise() { | ||||
|         if (getType().getEntityType() == null) { | ||||
|             throw new RuntimeException( | ||||
|                     "DisguiseType " + getType() + " was used in a futile attempt to construct a disguise, but this Minecraft version does not have that entity"); | ||||
|             throw new RuntimeException("DisguiseType " + getType() + | ||||
|                     " was used in a futile attempt to construct a disguise, but this Minecraft version does not have " + | ||||
|                     "that entity"); | ||||
|         } | ||||
|  | ||||
|         // Get if they are a adult now.. | ||||
| @@ -193,7 +193,8 @@ public abstract class Disguise { | ||||
|                 if (!getEntity().isValid()) { | ||||
|                     // If it has been dead for 30+ ticks | ||||
|                     // This is to ensure that this disguise isn't removed while clients think its the real entity | ||||
|                     // The delay is because if it sends the destroy entity packets straight away, then it means no death animation | ||||
|                     // The delay is because if it sends the destroy entity packets straight away, then it means no | ||||
|                     // death animation | ||||
|                     // This is probably still a problem for wither and enderdragon deaths. | ||||
|                     if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) { | ||||
|                         deadTicks = 0; | ||||
| @@ -232,8 +233,8 @@ public abstract class Disguise { | ||||
|  | ||||
|                         int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4; | ||||
|  | ||||
|                         if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc | ||||
|                                 .getBlockZ() != blockZ || newFacing != facing) { | ||||
|                         if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc.getBlockZ() != blockZ || | ||||
|                                 newFacing != facing) { | ||||
|                             blockX = loc.getBlockX(); | ||||
|                             blockY = loc.getBlockY(); | ||||
|                             blockZ = loc.getBlockZ(); | ||||
| @@ -256,11 +257,12 @@ public abstract class Disguise { | ||||
|                     if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) { | ||||
|                         Vector vector = getEntity().getVelocity(); | ||||
|  | ||||
|                         // If the entity doesn't have velocity changes already - You know. I really can't wrap my head about the | ||||
|                         // If the entity doesn't have velocity changes already - You know. I really can't wrap my | ||||
|                         // head about the | ||||
|                         // if statement. | ||||
|                         // But it doesn't seem to do anything wrong.. | ||||
|                         if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity() | ||||
|                                 .isOnGround())) { | ||||
|                         if (vector.getY() != 0 && | ||||
|                                 !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) { | ||||
|                             return; | ||||
|                         } | ||||
|  | ||||
| @@ -268,8 +270,8 @@ public abstract class Disguise { | ||||
|                         if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) { | ||||
|                             PacketContainer lookPacket = null; | ||||
|  | ||||
|                             if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig | ||||
|                                     .isWitherSkullPacketsEnabled()) { | ||||
|                             if (getType() == DisguiseType.WITHER_SKULL && | ||||
|                                     DisguiseConfig.isWitherSkullPacketsEnabled()) { | ||||
|                                 lookPacket = new PacketContainer(Server.ENTITY_LOOK); | ||||
|  | ||||
|                                 StructureModifier<Object> mods = lookPacket.getModifier(); | ||||
| @@ -332,7 +334,8 @@ public abstract class Disguise { | ||||
|                                 e.printStackTrace(); | ||||
|                             } | ||||
|                         } | ||||
|                         // If we need to send a packet to update the exp position as it likes to gravitate client sided to | ||||
|                         // If we need to send a packet to update the exp position as it likes to gravitate client | ||||
|                         // sided to | ||||
|                         // players. | ||||
|                     } | ||||
|                     if (getType() == DisguiseType.EXPERIENCE_ORB) { | ||||
| @@ -395,7 +398,8 @@ public abstract class Disguise { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise. | ||||
|      * In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to | ||||
|      * the disguise. | ||||
|      * getEntity() can still return null if this disguise is active after despawn, logout, etc. | ||||
|      * | ||||
|      * @return isDisguiseInUse | ||||
| @@ -443,8 +447,8 @@ public abstract class Disguise { | ||||
|      * Internal use | ||||
|      */ | ||||
|     public boolean isRemoveDisguiseOnDeath() { | ||||
|         return getEntity() == null || (getEntity() instanceof Player ? !isKeepDisguiseOnPlayerDeath() : | ||||
|                 getEntity().isDead()); | ||||
|         return getEntity() == null || | ||||
|                 (getEntity() instanceof Player ? !isKeepDisguiseOnPlayerDeath() : getEntity().isDead()); | ||||
|     } | ||||
|  | ||||
|     public boolean isSelfDisguiseSoundsReplaced() { | ||||
| @@ -488,7 +492,7 @@ public abstract class Disguise { | ||||
|  | ||||
|             Bukkit.getPluginManager().callEvent(event); | ||||
|  | ||||
|             if (!event.isCancelled()) { | ||||
|             if (!event.isCancelled() || (getEntity() instanceof Player && !((Player) getEntity()).isOnline())) { | ||||
|                 disguiseInUse = false; | ||||
|  | ||||
|                 if (task != null) { | ||||
| @@ -506,7 +510,7 @@ public abstract class Disguise { | ||||
|                         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( | ||||
|                             deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||
|                                     new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, | ||||
|                                             WrappedChatComponent.fromText(disguise.getName())))); | ||||
|  | ||||
| @@ -524,20 +528,23 @@ public abstract class Disguise { | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     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(DisguiseUtilities.getPlayerListName((Player) getEntity()))))); | ||||
|                     if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) { | ||||
|                         PlayerInfoData playerInfo = new PlayerInfoData( | ||||
|                                 ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||
|                                 NativeGameMode.SURVIVAL, WrappedChatComponent | ||||
|                                 .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))); | ||||
|  | ||||
|                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||
|  | ||||
|                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||
|                         addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfo)); | ||||
|  | ||||
|                         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) { | ||||
| @@ -598,7 +605,8 @@ public abstract class Disguise { | ||||
|  | ||||
|         if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { | ||||
|             throw new RuntimeException( | ||||
|                     "Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the config to do this"); | ||||
|                     "Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the " + | ||||
|                             "config to do this"); | ||||
|         } | ||||
|  | ||||
|         this.entity = entity; | ||||
| @@ -651,8 +659,8 @@ public abstract class Disguise { | ||||
|  | ||||
|     public Disguise setModifyBoundingBox(boolean modifyBox) { | ||||
|         if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { | ||||
|             throw new RuntimeException( | ||||
|                     "Cannot modify the bounding box of a disguise which is not TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS"); | ||||
|             throw new RuntimeException("Cannot modify the bounding box of a disguise which is not TargetType" + | ||||
|                     ".SHOW_TO_EVERYONE_BUT_THESE_PLAYERS"); | ||||
|         } | ||||
|  | ||||
|         if (isModifyBoundingBox() != modifyBox) { | ||||
| @@ -679,7 +687,8 @@ public abstract class Disguise { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 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. | ||||
|      */ | ||||
|     private void setupWatcher() { | ||||
| @@ -736,9 +745,8 @@ public abstract class Disguise { | ||||
|  | ||||
|     public Disguise setWatcher(FlagWatcher newWatcher) { | ||||
|         if (!getType().getWatcherClass().isInstance(newWatcher)) { | ||||
|             throw new IllegalArgumentException( | ||||
|                     newWatcher.getClass().getSimpleName() + " is not a instance of " + getType().getWatcherClass() | ||||
|                             .getSimpleName() + " for DisguiseType " + getType().name()); | ||||
|             throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of " + | ||||
|                     getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name()); | ||||
|         } | ||||
|  | ||||
|         watcher = newWatcher; | ||||
| @@ -788,7 +796,7 @@ public abstract class Disguise { | ||||
|             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( | ||||
|                 addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||
|                         new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, | ||||
|                                 WrappedChatComponent.fromText(disguise.getName())))); | ||||
|  | ||||
| @@ -828,7 +836,7 @@ public abstract class Disguise { | ||||
|         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( | ||||
|             addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||
|                     new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, | ||||
|                             NativeGameMode.SURVIVAL, WrappedChatComponent.fromText("")))); | ||||
|  | ||||
|   | ||||
| @@ -1,27 +1,5 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map.Entry; | ||||
| import java.util.UUID; | ||||
|  | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.entity.Damageable; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.EntityType; | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.inventory.EquipmentSlot; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.metadata.FixedMetadataValue; | ||||
| import org.bukkit.util.Vector; | ||||
|  | ||||
| import com.comphenix.protocol.PacketType; | ||||
| import com.comphenix.protocol.PacketType.Play; | ||||
| import com.comphenix.protocol.PacketType.Play.Server; | ||||
| @@ -36,24 +14,26 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; | ||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; | ||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
| import me.libraryaddict.disguise.LibsDisguises; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.MiscDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.*; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerClientInteract; | ||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerInventory; | ||||
| import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerMain; | ||||
| 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.*; | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.entity.*; | ||||
| import org.bukkit.inventory.EquipmentSlot; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.metadata.FixedMetadataValue; | ||||
| import org.bukkit.util.Vector; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.*; | ||||
| import java.util.Map.Entry; | ||||
|  | ||||
| public class PacketsManager { | ||||
|     public static class LibsPackets { | ||||
| @@ -222,8 +202,8 @@ public class PacketsManager { | ||||
|  | ||||
|                 if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { | ||||
|                     builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); | ||||
|                 } else if (DisguiseConfig | ||||
|                         .isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) { | ||||
|                 } else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && | ||||
|                         disguisedEntity instanceof Damageable) { | ||||
|                     builder.baseValue(((Damageable) disguisedEntity).getMaxHealth()); | ||||
|                 } else { | ||||
|                     builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); | ||||
| @@ -294,22 +274,23 @@ public class PacketsManager { | ||||
|             PlayerDisguise playerDisguise = (PlayerDisguise) disguise; | ||||
|  | ||||
|             String name = playerDisguise.getName(); | ||||
|             WrappedGameProfile gameProfile = playerDisguise.getGameProfile(); | ||||
|  | ||||
|             int entityId = disguisedEntity.getEntityId(); | ||||
|  | ||||
|             // Send player info along with the disguise | ||||
|             PacketContainer sendTab = new PacketContainer(Server.PLAYER_INFO); | ||||
|  | ||||
|             if (!((PlayerDisguise) disguise).isDisplayedInTab()) | ||||
|             if (!((PlayerDisguise) disguise).isDisplayedInTab()) { | ||||
|                 // Add player to the list, necessary to spawn them | ||||
|                 sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0)); | ||||
|  | ||||
|                 List playerList = Collections | ||||
|                         .singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), gameProfile)); | ||||
|                 sendTab.getModifier().write(1, playerList); | ||||
|  | ||||
|                 packets.addPacket(sendTab); | ||||
|  | ||||
|             // Add player to the list, necessary to spawn them | ||||
|             sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0)); | ||||
|  | ||||
|             WrappedGameProfile gameProfile = playerDisguise.getGameProfile(); | ||||
|             List playerList = new ArrayList(); | ||||
|  | ||||
|             playerList.add(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), gameProfile)); | ||||
|             sendTab.getModifier().write(1, playerList); | ||||
|             } | ||||
|  | ||||
|             // Spawn the player | ||||
|             PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN); | ||||
| @@ -453,7 +434,8 @@ public class PacketsManager { | ||||
|             if (disguise.getType() == DisguiseType.FALLING_BLOCK) { | ||||
|                 data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data); | ||||
|             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { | ||||
|                 // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id | ||||
|                 // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners | ||||
|                 // entity id | ||||
|                 data = observer.getEntityId(); | ||||
|             } else if (disguise.getType() == DisguiseType.ITEM_FRAME) { | ||||
|                 data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4; | ||||
| @@ -637,8 +619,8 @@ public class PacketsManager { | ||||
|     public static double getYModifier(Entity entity, Disguise disguise) { | ||||
|         double yMod = 0; | ||||
|  | ||||
|         if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()) | ||||
|                 .isSleeping()) && entity.getType() == EntityType.DROPPED_ITEM) { | ||||
|         if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) && | ||||
|                 entity.getType() == EntityType.DROPPED_ITEM) { | ||||
|             yMod -= 0.13; | ||||
|         } | ||||
|  | ||||
| @@ -743,8 +725,8 @@ public class PacketsManager { | ||||
|                 Disguise disguise = DisguiseAPI.getDisguise(player, player); | ||||
|  | ||||
|                 if (disguise != null) { | ||||
|                     if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && (disguise | ||||
|                             .isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { | ||||
|                     if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && | ||||
|                             (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { | ||||
|                         player.updateInventory(); | ||||
|                     } | ||||
|                 } | ||||
| @@ -838,8 +820,8 @@ public class PacketsManager { | ||||
|                             DisguiseUtilities.removeSelfDisguise(player); | ||||
|                         } | ||||
|  | ||||
|                         if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise | ||||
|                                 .isHidingHeldItemFromSelf())) { | ||||
|                         if (inventoryModifierEnabled && | ||||
|                                 (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { | ||||
|                             player.updateInventory(); | ||||
|                         } | ||||
|                     } | ||||
| @@ -849,7 +831,8 @@ public class PacketsManager { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not | ||||
|      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if | ||||
|      * its not | ||||
|      * transformed | ||||
|      */ | ||||
|     public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, | ||||
| @@ -907,8 +890,8 @@ public class PacketsManager { | ||||
|             else if (sentPacket.getType() == Server.ENTITY_METADATA) { | ||||
|                 packets.clear(); | ||||
|  | ||||
|                 if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) || !cancelMeta | ||||
|                         .get(disguise).contains(observer.getUniqueId()))) { | ||||
|                 if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) || | ||||
|                         !cancelMeta.get(disguise).contains(observer.getUniqueId()))) { | ||||
|                     List<WrappedWatchableObject> watchableObjects = disguise.getWatcher() | ||||
|                             .convert(sentPacket.getWatchableCollectionModifier().read(0)); | ||||
|  | ||||
| @@ -925,10 +908,11 @@ public class PacketsManager { | ||||
|             } | ||||
|  | ||||
|             // Else if the packet is spawning.. | ||||
|             else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket | ||||
|                     .getType() == Server.SPAWN_ENTITY_LIVING || sentPacket | ||||
|                     .getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket | ||||
|                     .getType() == Server.SPAWN_ENTITY || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) { | ||||
|             else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || | ||||
|                     sentPacket.getType() == Server.SPAWN_ENTITY_LIVING || | ||||
|                     sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || | ||||
|                     sentPacket.getType() == Server.SPAWN_ENTITY || | ||||
|                     sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) { | ||||
|                 packets.clear(); | ||||
|  | ||||
|                 constructSpawnPackets(observer, packets, entity); | ||||
| @@ -936,9 +920,9 @@ public class PacketsManager { | ||||
|  | ||||
|             // Else if the disguise is attempting to send players a forbidden packet | ||||
|             else if (sentPacket.getType() == Server.ANIMATION) { | ||||
|                 if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType() | ||||
|                         .isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()) | ||||
|                         .isSleeping())))) { | ||||
|                 if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && | ||||
|                         (!disguise.getType().isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && | ||||
|                                 ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) { | ||||
|                     packets.clear(); | ||||
|                 } | ||||
|             } | ||||
| @@ -947,8 +931,8 @@ public class PacketsManager { | ||||
|             else if (sentPacket.getType() == Server.COLLECT) { | ||||
|                 if (disguise.getType().isMisc()) { | ||||
|                     packets.clear(); | ||||
|                 } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType() | ||||
|                         .isPlayer() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { | ||||
|                 } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() && | ||||
|                         ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { | ||||
|                     PacketContainer newPacket = new PacketContainer(Server.ANIMATION); | ||||
|  | ||||
|                     StructureModifier<Integer> mods = newPacket.getIntegers(); | ||||
| @@ -963,17 +947,18 @@ public class PacketsManager { | ||||
|             } | ||||
|  | ||||
|             // Else if the disguise is moving. | ||||
|             else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket | ||||
|                     .getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket | ||||
|                     .getType() == Server.REL_ENTITY_MOVE) { | ||||
|                 if (disguise.getType() == DisguiseType.RABBIT && (sentPacket | ||||
|                         .getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { | ||||
|             else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || | ||||
|                     sentPacket.getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT || | ||||
|                     sentPacket.getType() == Server.REL_ENTITY_MOVE) { | ||||
|                 if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || | ||||
|                         sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { | ||||
|                     // Rabbit robbing... | ||||
|                     if (entity.getMetadata("LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity | ||||
|                             .getMetadata("LibsRabbitHop").get(0).asLong() < 100 || System.currentTimeMillis() - entity | ||||
|                             .getMetadata("LibsRabbitHop").get(0).asLong() > 500) { | ||||
|                         if (entity.getMetadata("LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity | ||||
|                                 .getMetadata("LibsRabbitHop").get(0).asLong() > 500) { | ||||
|                     if (entity.getMetadata("LibsRabbitHop").isEmpty() || | ||||
|                             System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 || | ||||
|                             System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { | ||||
|                         if (entity.getMetadata("LibsRabbitHop").isEmpty() || | ||||
|                                 System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > | ||||
|                                         500) { | ||||
|                             entity.removeMetadata("LibsRabbitHop", libsDisguises); | ||||
|                             entity.setMetadata("LibsRabbitHop", | ||||
|                                     new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); | ||||
| @@ -1005,8 +990,8 @@ public class PacketsManager { | ||||
|                     bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue)); | ||||
|                     bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); | ||||
|  | ||||
|                     if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise | ||||
|                             .getType() == DisguiseType.ITEM_FRAME) { | ||||
|                     if (sentPacket.getType() == Server.ENTITY_TELEPORT && | ||||
|                             disguise.getType() == DisguiseType.ITEM_FRAME) { | ||||
|                         StructureModifier<Double> doubles = movePacket.getDoubles(); | ||||
|  | ||||
|                         Location loc = entity.getLocation(); | ||||
| @@ -1084,7 +1069,8 @@ public class PacketsManager { | ||||
|                             watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); | ||||
|                         } | ||||
|  | ||||
|                         // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler | ||||
|                         // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? | ||||
|                         // Scheduler | ||||
|                         // delay. | ||||
|  | ||||
|                         PacketContainer packet1 = packets.getPackets().get(0); | ||||
| @@ -1094,7 +1080,8 @@ public class PacketsManager { | ||||
|                         packets.addPacket(packetUnblock); | ||||
|                         packets.addPacket(packet1); | ||||
|                         packets.addPacket(packetBlock); | ||||
|                         // Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset | ||||
|                         // Silly mojang made the right clicking datawatcher value only valid for one use. So I have | ||||
|                         // to reset | ||||
|                         // it. | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user