Player disguises no longer hang around in tab
Fix setSkin not working on active disguises Fixed tab names not displaying
This commit is contained in:
		| @@ -415,7 +415,7 @@ public class DisguiseConfig { | |||||||
|         setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); |         setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); | ||||||
|         setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible")); |         setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible")); | ||||||
|         setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises")); |         setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises")); | ||||||
|         setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpires")); |         setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpiry")); | ||||||
|         setPlayerHideArmor(config.getBoolean("PlayerHideArmor")); |         setPlayerHideArmor(config.getBoolean("PlayerHideArmor")); | ||||||
|         setRetaliationCombat(config.getBoolean("RetaliationCombat")); |         setRetaliationCombat(config.getBoolean("RetaliationCombat")); | ||||||
|         setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities")); |         setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities")); | ||||||
|   | |||||||
| @@ -420,14 +420,8 @@ public class DisguiseListener implements Listener { | |||||||
|  |  | ||||||
|                 if (disguise.isDisplayedInTab()) { |                 if (disguise.isDisplayedInTab()) { | ||||||
|                     try { |                     try { | ||||||
|                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |                         ProtocolLibrary.getProtocolManager().sendServerPacket(p, | ||||||
|  |                                 DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER)); | ||||||
|                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); |  | ||||||
|                         addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( |  | ||||||
|                                 new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, |  | ||||||
|                                         WrappedChatComponent.fromText(disguise.getGameProfile().getName())))); |  | ||||||
|  |  | ||||||
|                         ProtocolLibrary.getProtocolManager().sendServerPacket(p, addTab); |  | ||||||
|                     } |                     } | ||||||
|                     catch (InvocationTargetException e) { |                     catch (InvocationTargetException e) { | ||||||
|                         e.printStackTrace(); |                         e.printStackTrace(); | ||||||
|   | |||||||
| @@ -155,6 +155,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements | |||||||
|             else |             else | ||||||
|                 disguise = DisguiseAPI.getDisguise(entity); |                 disguise = DisguiseAPI.getDisguise(entity); | ||||||
|  |  | ||||||
|  |             if (disguise == null) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); |             DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); | ||||||
|  |  | ||||||
|             if (!permissions.isAllowedDisguise(disguisePerm)) { |             if (!permissions.isAllowedDisguise(disguisePerm)) { | ||||||
|   | |||||||
| @@ -962,11 +962,7 @@ public abstract class Disguise { | |||||||
|             PlayerDisguise disguise = (PlayerDisguise) this; |             PlayerDisguise disguise = (PlayerDisguise) this; | ||||||
|  |  | ||||||
|             if (disguise.isDisplayedInTab()) { |             if (disguise.isDisplayedInTab()) { | ||||||
|                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |                 PacketContainer addTab = DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER); | ||||||
|                 addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); |  | ||||||
|                 addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( |  | ||||||
|                         new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, |  | ||||||
|                                 WrappedChatComponent.fromText(disguise.getProfileName())))); |  | ||||||
|  |  | ||||||
|                 try { |                 try { | ||||||
|                     for (Player player : Bukkit.getOnlinePlayers()) { |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent; | |||||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
| import lombok.Setter; | import lombok.Setter; | ||||||
|  | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||||
| @@ -98,6 +99,10 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|         return scoreboardName; |         return scoreboardName; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private void setScoreboardName(String[] split) { | ||||||
|  |         getScoreboardName().setSplit(split); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private boolean isStaticName(String name) { |     private boolean isStaticName(String name) { | ||||||
|         return name != null && (name.equalsIgnoreCase("Dinnerbone") || name.equalsIgnoreCase("Grumm")); |         return name != null && (name.equalsIgnoreCase("Dinnerbone") || name.equalsIgnoreCase("Grumm")); | ||||||
|     } |     } | ||||||
| @@ -229,7 +234,7 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|                 String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); |                 String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); | ||||||
|  |  | ||||||
|                 resendDisguise = !split[1].equals(team.getPlayer()); |                 resendDisguise = !split[1].equals(team.getPlayer()); | ||||||
|                 team.setSplit(split); |                 setScoreboardName(split); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             resendDisguise = |             resendDisguise = | ||||||
| @@ -268,12 +273,28 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|  |  | ||||||
|                 playerName = name; |                 playerName = name; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (isDisplayedInTab()) { | ||||||
|  |                 PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME); | ||||||
|  |  | ||||||
|  |                 try { | ||||||
|  |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                         if (!canSee(player)) | ||||||
|  |                             continue; | ||||||
|  |  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 catch (InvocationTargetException e) { | ||||||
|  |                     e.printStackTrace(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             if (scoreboardName != null) { |             if (scoreboardName != null) { | ||||||
|                 DisguiseUtilities.DScoreTeam team = getScoreboardName(); |                 DisguiseUtilities.DScoreTeam team = getScoreboardName(); | ||||||
|                 String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); |                 String[] split = DisguiseUtilities.getExtendedNameSplit(team.getPlayer(), name); | ||||||
|  |  | ||||||
|                 team.setSplit(split); |                 setScoreboardName(split); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (name.isEmpty()) { |             if (name.isEmpty()) { | ||||||
| @@ -308,6 +329,7 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         String oldSkin = skinToUse; | ||||||
|         skinToUse = newSkin; |         skinToUse = newSkin; | ||||||
|  |  | ||||||
|         if (newSkin == null) { |         if (newSkin == null) { | ||||||
| @@ -317,6 +339,31 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|             if (newSkin.length() > 16) { |             if (newSkin.length() > 16) { | ||||||
|                 skinToUse = newSkin.substring(0, 16); |                 skinToUse = newSkin.substring(0, 16); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (newSkin.equals(oldSkin)) { | ||||||
|  |                 return this; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (isDisguiseInUse()) { | ||||||
|  |                 currentLookup = new LibsProfileLookup() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onLookup(WrappedGameProfile gameProfile) { | ||||||
|  |                         if (currentLookup != this || gameProfile == null || gameProfile.getProperties().isEmpty()) | ||||||
|  |                             return; | ||||||
|  |  | ||||||
|  |                         setSkin(gameProfile); | ||||||
|  |  | ||||||
|  |                         currentLookup = null; | ||||||
|  |                     } | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, | ||||||
|  |                         LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); | ||||||
|  |  | ||||||
|  |                 if (gameProfile != null) { | ||||||
|  |                     setSkin(gameProfile); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
| @@ -342,13 +389,15 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|         this.skinToUse = gameProfile.getName(); |         this.skinToUse = gameProfile.getName(); | ||||||
|         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), gameProfile); |         this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), gameProfile); | ||||||
|  |  | ||||||
|  |         refreshDisguise(); | ||||||
|  |  | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void refreshDisguise() { | ||||||
|         if (DisguiseUtilities.isDisguiseInUse(this)) { |         if (DisguiseUtilities.isDisguiseInUse(this)) { | ||||||
|             if (isDisplayedInTab()) { |             if (isDisplayedInTab()) { | ||||||
|                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |                 PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.ADD_PLAYER); | ||||||
|                 addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); |  | ||||||
|                 addTab.getPlayerInfoDataLists().write(0, Arrays.asList( |  | ||||||
|                         new PlayerInfoData(getGameProfile(), 0, NativeGameMode.SURVIVAL, |  | ||||||
|                                 WrappedChatComponent.fromText(getProfileName())))); |  | ||||||
|  |  | ||||||
|                 PacketContainer deleteTab = addTab.shallowClone(); |                 PacketContainer deleteTab = addTab.shallowClone(); | ||||||
|                 deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); |                 deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
| @@ -369,8 +418,6 @@ public class PlayerDisguise extends TargetedDisguise { | |||||||
|  |  | ||||||
|             DisguiseUtilities.refreshTrackers(this); |             DisguiseUtilities.refreshTrackers(this); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package me.libraryaddict.disguise.utilities; | package me.libraryaddict.disguise.utilities; | ||||||
|  |  | ||||||
|  | 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.ProtocolManager; | import com.comphenix.protocol.ProtocolManager; | ||||||
| @@ -35,7 +36,6 @@ import org.apache.commons.lang.StringUtils; | |||||||
| import org.apache.commons.lang.math.RandomUtils; | import org.apache.commons.lang.math.RandomUtils; | ||||||
| import org.apache.logging.log4j.util.Strings; | import org.apache.logging.log4j.util.Strings; | ||||||
| import org.bukkit.*; | import org.bukkit.*; | ||||||
| import org.bukkit.boss.BossBar; |  | ||||||
| import org.bukkit.boss.KeyedBossBar; | import org.bukkit.boss.KeyedBossBar; | ||||||
| import org.bukkit.entity.*; | import org.bukkit.entity.*; | ||||||
| import org.bukkit.inventory.EquipmentSlot; | import org.bukkit.inventory.EquipmentSlot; | ||||||
| @@ -1943,8 +1943,6 @@ public class DisguiseUtilities { | |||||||
|             if (transformed.isUnhandled()) |             if (transformed.isUnhandled()) | ||||||
|                 transformed.addPacket(packet); |                 transformed.addPacket(packet); | ||||||
|  |  | ||||||
|             transformed.setSpawnPacketCheck(packet.getType()); |  | ||||||
|  |  | ||||||
|             for (PacketContainer p : transformed.getPackets()) { |             for (PacketContainer p : transformed.getPackets()) { | ||||||
|                 p = p.deepClone(); |                 p = p.deepClone(); | ||||||
|                 p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                 p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
| @@ -1958,6 +1956,17 @@ public class DisguiseUtilities { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static PacketContainer getTabPacket(PlayerDisguise disguise, EnumWrappers.PlayerInfoAction action) { | ||||||
|  |         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |  | ||||||
|  |         addTab.getPlayerInfoAction().write(0, action); | ||||||
|  |         addTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||||
|  |                 new PlayerInfoData(disguise.getGameProfile(), 0, EnumWrappers.NativeGameMode.SURVIVAL, | ||||||
|  |                         WrappedChatComponent.fromText(disguise.getName())))); | ||||||
|  |  | ||||||
|  |         return addTab; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Setup it so he can see himself when disguised |      * Setup it so he can see himself when disguised | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -24,13 +24,8 @@ import java.util.*; | |||||||
| public class LibsPackets { | public class LibsPackets { | ||||||
|     private ArrayList<PacketContainer> packets = new ArrayList<>(); |     private ArrayList<PacketContainer> packets = new ArrayList<>(); | ||||||
|     private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>(); |     private HashMap<Integer, ArrayList<PacketContainer>> delayedPackets = new HashMap<>(); | ||||||
|     private boolean isSpawnPacket; |  | ||||||
|     private Disguise disguise; |     private Disguise disguise; | ||||||
|     private boolean doNothing; |     private boolean doNothing; | ||||||
|     private int removeMetaAt = -1; |  | ||||||
|     @Getter |  | ||||||
|     @Setter |  | ||||||
|     private boolean sendArmor; |  | ||||||
|  |  | ||||||
|     public LibsPackets(Disguise disguise) { |     public LibsPackets(Disguise disguise) { | ||||||
|         this.disguise = disguise; |         this.disguise = disguise; | ||||||
| @@ -40,10 +35,6 @@ public class LibsPackets { | |||||||
|         doNothing = true; |         doNothing = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setRemoveMetaAt(int tick) { |  | ||||||
|         removeMetaAt = tick; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean isUnhandled() { |     public boolean isUnhandled() { | ||||||
|         return doNothing; |         return doNothing; | ||||||
|     } |     } | ||||||
| @@ -52,10 +43,6 @@ public class LibsPackets { | |||||||
|         return disguise; |         return disguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSpawnPacketCheck(PacketType type) { |  | ||||||
|         isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void addPacket(PacketContainer packet) { |     public void addPacket(PacketContainer packet) { | ||||||
|         packets.add(packet); |         packets.add(packet); | ||||||
|     } |     } | ||||||
| @@ -84,19 +71,8 @@ public class LibsPackets { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void sendDelayed(final Player observer) { |     public void sendDelayed(final Player observer) { | ||||||
|         Iterator<Map.Entry<Integer, ArrayList<PacketContainer>>> itel = delayedPackets.entrySet().iterator(); |         for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : delayedPackets.entrySet()) { | ||||||
|  |  | ||||||
|         while (itel.hasNext()) { |  | ||||||
|             Map.Entry<Integer, ArrayList<PacketContainer>> entry = itel.next(); |  | ||||||
|             // If this is the last delayed packet |  | ||||||
|             final boolean isRemoveCancel = isSpawnPacket && entry.getKey() >= removeMetaAt && removeMetaAt >= 0; |  | ||||||
|  |  | ||||||
|             Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> { |             Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> { | ||||||
|  |  | ||||||
|                 if (isRemoveCancel && "%%__USER__%%".equals("%%__USER__%%") && !"%%__USER__%%".equals("12345")) { |  | ||||||
|                     PacketsManager.getPacketsHandler().removeCancel(disguise, observer); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (!disguise.isDisguiseInUse()) { |                 if (!disguise.isDisguiseInUse()) { | ||||||
|                     ArrayList<PacketContainer> packets = entry.getValue(); |                     ArrayList<PacketContainer> packets = entry.getValue(); | ||||||
|  |  | ||||||
| @@ -107,25 +83,6 @@ public class LibsPackets { | |||||||
|                     packets.removeIf(p -> p.getType() != PacketType.Play.Server.PLAYER_INFO); |                     packets.removeIf(p -> p.getType() != PacketType.Play.Server.PLAYER_INFO); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if (isRemoveCancel) { |  | ||||||
|                     if (isSendArmor()) { |  | ||||||
|                         for (EquipmentSlot slot : EquipmentSlot.values()) { |  | ||||||
|                             PacketContainer packet = createPacket(slot); |  | ||||||
|  |  | ||||||
|                             if (packet == null) { |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|  |  | ||||||
|                             try { |  | ||||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); |  | ||||||
|                             } |  | ||||||
|                             catch (InvocationTargetException e) { |  | ||||||
|                                 e.printStackTrace(); |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 try { |                 try { | ||||||
|                     for (PacketContainer packet : entry.getValue()) { |                     for (PacketContainer packet : entry.getValue()) { | ||||||
|                         ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); |                         ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); | ||||||
|   | |||||||
| @@ -19,7 +19,6 @@ import java.util.UUID; | |||||||
|  * Created by libraryaddict on 3/01/2019. |  * Created by libraryaddict on 3/01/2019. | ||||||
|  */ |  */ | ||||||
| public class PacketsHandler { | public class PacketsHandler { | ||||||
|     private HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<>(); |  | ||||||
|     private Collection<IPacketHandler> packetHandlers; |     private Collection<IPacketHandler> packetHandlers; | ||||||
|  |  | ||||||
|     public PacketsHandler() { |     public PacketsHandler() { | ||||||
| @@ -38,7 +37,8 @@ public class PacketsHandler { | |||||||
|         packetHandlers.add(new PacketHandlerHeadRotation()); |         packetHandlers.add(new PacketHandlerHeadRotation()); | ||||||
|  |  | ||||||
|         // If not prem, if build is from jenkins, else its a custom and needs paid info |         // If not prem, if build is from jenkins, else its a custom and needs paid info | ||||||
|         if (!LibsPremium.isPremium() || LibsDisguises.getInstance().getBuildNo().matches("[0-9]+") || LibsPremium.getPaidInformation() != null) { |         if (!LibsPremium.isPremium() || LibsDisguises.getInstance().getBuildNo().matches("[0-9]+") || | ||||||
|  |                 LibsPremium.getPaidInformation() != null) { | ||||||
|             packetHandlers.add(new PacketHandlerMetadata(this)); |             packetHandlers.add(new PacketHandlerMetadata(this)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -47,32 +47,6 @@ public class PacketsHandler { | |||||||
|         packetHandlers.add(new PacketHandlerVelocity()); |         packetHandlers.add(new PacketHandlerVelocity()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isCancelMeta(Disguise disguise, Player observer) { |  | ||||||
|         return cancelMeta.containsKey(disguise) && cancelMeta.get(disguise).contains(observer.getUniqueId()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void addCancel(Disguise disguise, Player observer) { |  | ||||||
|         if (!cancelMeta.containsKey(disguise)) { |  | ||||||
|             cancelMeta.put(disguise, new ArrayList<UUID>()); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         cancelMeta.get(disguise).add(observer.getUniqueId()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void removeCancel(Disguise disguise, Player observer) { |  | ||||||
|         ArrayList<UUID> cancel; |  | ||||||
|  |  | ||||||
|         if ((cancel = cancelMeta.get(disguise)) == null) |  | ||||||
|             return; |  | ||||||
|  |  | ||||||
|         cancel.remove(observer.getUniqueId()); |  | ||||||
|  |  | ||||||
|         if (!cancel.isEmpty()) |  | ||||||
|             return; |  | ||||||
|  |  | ||||||
|         cancelMeta.remove(disguise); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if |      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if | ||||||
|      * its not |      * its not | ||||||
|   | |||||||
| @@ -38,17 +38,6 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|     @Override |     @Override | ||||||
|     public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, |     public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, | ||||||
|             Entity entity) { |             Entity entity) { | ||||||
|         if (DisguiseConfig.isPlayerHideArmor() && packetsHandler.isCancelMeta(disguise, observer)) { |  | ||||||
|             packets.clear(); |  | ||||||
|  |  | ||||||
|             PacketContainer equipPacket = sentPacket.shallowClone(); |  | ||||||
|  |  | ||||||
|             packets.addPacket(equipPacket); |  | ||||||
|  |  | ||||||
|             equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(new ItemStack(Material.AIR))); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // Else if the disguise is updating equipment |         // Else if the disguise is updating equipment | ||||||
|  |  | ||||||
|         EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1)); |         EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1)); | ||||||
|   | |||||||
| @@ -35,19 +35,22 @@ public class PacketHandlerMetadata implements IPacketHandler { | |||||||
|  |  | ||||||
|         packets.clear(); |         packets.clear(); | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isMetaPacketsEnabled() && !packetsHandler.isCancelMeta(disguise, observer)) { |         if (!DisguiseConfig.isMetaPacketsEnabled()) { | ||||||
|             List<WrappedWatchableObject> watchableObjects = disguise.getWatcher() |             return; | ||||||
|                     .convert(sentPacket.getWatchableCollectionModifier().read(0)); |  | ||||||
|  |  | ||||||
|             PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); |  | ||||||
|  |  | ||||||
|             packets.addPacket(metaPacket); |  | ||||||
|  |  | ||||||
|             StructureModifier<Object> newMods = metaPacket.getModifier(); |  | ||||||
|  |  | ||||||
|             newMods.write(0, entity.getEntityId()); |  | ||||||
|  |  | ||||||
|             metaPacket.getWatchableCollectionModifier().write(0, watchableObjects); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         List<WrappedWatchableObject> watchableObjects = disguise.getWatcher() | ||||||
|  |                 .convert(sentPacket.getWatchableCollectionModifier().read(0)); | ||||||
|  |  | ||||||
|  |         PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); | ||||||
|  |  | ||||||
|  |         packets.addPacket(metaPacket); | ||||||
|  |  | ||||||
|  |         StructureModifier<Object> newMods = metaPacket.getModifier(); | ||||||
|  |  | ||||||
|  |         newMods.write(0, entity.getEntityId()); | ||||||
|  |  | ||||||
|  |         metaPacket.getWatchableCollectionModifier().write(0, watchableObjects); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -159,7 +159,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|  |  | ||||||
|             WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager |             WrappedGameProfile spawnProfile = visibleOrNewCompat ? playerDisguise.getGameProfile() : ReflectionManager | ||||||
|                     .getGameProfileWithThisSkin(UUID.randomUUID(), |                     .getGameProfileWithThisSkin(UUID.randomUUID(), | ||||||
|                             visibleOrNewCompat ? playerDisguise.getProfileName() : "", playerDisguise.getGameProfile()); |                             visibleOrNewCompat ? playerDisguise.getName() : "", playerDisguise.getGameProfile()); | ||||||
|  |  | ||||||
|             int entityId = disguisedEntity.getEntityId(); |             int entityId = disguisedEntity.getEntityId(); | ||||||
|  |  | ||||||
| @@ -182,7 +182,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|  |  | ||||||
|                 if (LibsPremium.getPaidInformation() == null || |                 if (LibsPremium.getPaidInformation() == null || | ||||||
|                         LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { |                         LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { | ||||||
|                     packets.addDelayedPacket(deleteTab, DisguiseConfig.getPlayerDisguisesTablistExpires()); |                     packets.addDelayedPacket(deleteTab, 2); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -196,18 +196,9 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|  |  | ||||||
|             boolean selfDisguise = observer == disguisedEntity; |             boolean selfDisguise = observer == disguisedEntity; | ||||||
|  |  | ||||||
|             WrappedDataWatcher newWatcher; |             WrappedDataWatcher newWatcher = DisguiseUtilities | ||||||
|  |                     .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), | ||||||
|             if (selfDisguise) { |                             disguise.getWatcher()); | ||||||
|                 newWatcher = DisguiseUtilities |  | ||||||
|                         .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), |  | ||||||
|                                 disguise.getWatcher()); |  | ||||||
|             } else { |  | ||||||
|                 newWatcher = new WrappedDataWatcher(); |  | ||||||
|  |  | ||||||
|                 spawnAt = observer.getLocation(); |  | ||||||
|                 spawnAt.add(spawnAt.getDirection().normalize().multiply(20)); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             // Spawn him in front of the observer |             // Spawn him in front of the observer | ||||||
|             StructureModifier<Double> doubles = spawnPlayer.getDoubles(); |             StructureModifier<Double> doubles = spawnPlayer.getDoubles(); | ||||||
| @@ -219,10 +210,6 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|             bytes.write(0, yaw); |             bytes.write(0, yaw); | ||||||
|             bytes.write(1, pitch); |             bytes.write(1, pitch); | ||||||
|  |  | ||||||
|             // Make him invisible |  | ||||||
|             newWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), |  | ||||||
|                     WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32); |  | ||||||
|  |  | ||||||
|             packets.addPacket(spawnPlayer); |             packets.addPacket(spawnPlayer); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_15.isSupported()) { |             if (NmsVersion.v1_15.isSupported()) { | ||||||
| @@ -234,41 +221,6 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|             } else { |             } else { | ||||||
|                 spawnPlayer.getDataWatcherModifier().write(0, newWatcher); |                 spawnPlayer.getDataWatcherModifier().write(0, newWatcher); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!selfDisguise) { |  | ||||||
|                 // Teleport the player back to where he's supposed to be |  | ||||||
|                 PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); |  | ||||||
|  |  | ||||||
|                 doubles = teleportPacket.getDoubles(); |  | ||||||
|  |  | ||||||
|                 teleportPacket.getIntegers().write(0, entityId); // Id |  | ||||||
|                 doubles.write(0, loc.getX()); |  | ||||||
|                 doubles.write(1, loc.getY()); |  | ||||||
|                 doubles.write(2, loc.getZ()); |  | ||||||
|  |  | ||||||
|                 bytes = teleportPacket.getBytes(); |  | ||||||
|                 bytes.write(0, yaw); |  | ||||||
|                 bytes.write(1, pitch); |  | ||||||
|  |  | ||||||
|                 packets.addDelayedPacket(teleportPacket, 3); |  | ||||||
|  |  | ||||||
|                 // Send a metadata packet |  | ||||||
|                 PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); |  | ||||||
|  |  | ||||||
|                 newWatcher = DisguiseUtilities |  | ||||||
|                         .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), |  | ||||||
|                                 disguise.getWatcher()); |  | ||||||
|  |  | ||||||
|                 metaPacket.getIntegers().write(0, entityId); // Id |  | ||||||
|                 metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects()); |  | ||||||
|  |  | ||||||
|                 packetsHandler.addCancel(disguise, observer); |  | ||||||
|  |  | ||||||
|                 // Add a delay to remove the entry from 'cancelMeta' |  | ||||||
|  |  | ||||||
|                 packets.addDelayedPacket(metaPacket, 7); |  | ||||||
|                 packets.setRemoveMetaAt(7); |  | ||||||
|             } |  | ||||||
|         } 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(); | ||||||
|  |  | ||||||
| @@ -420,37 +372,24 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // If armor must be sent because its currently not displayed and would've been sent normally |         // If armor must be sent because its currently not displayed and would've been sent normally | ||||||
|         boolean delayedArmor = |  | ||||||
|                 DisguiseConfig.isPlayerHideArmor() && (disguise.isPlayerDisguise() && disguisedEntity != observer) && |  | ||||||
|                         disguisedEntity instanceof LivingEntity; |  | ||||||
|  |  | ||||||
|         if (delayedArmor) { |  | ||||||
|             packets.setSendArmor(true); |  | ||||||
|             packets.setRemoveMetaAt(7); |  | ||||||
|         } |  | ||||||
|         // This sends the armor packets so that the player isn't naked. |         // This sends the armor packets so that the player isn't naked. | ||||||
|         if (DisguiseConfig.isEquipmentPacketsEnabled() || delayedArmor) { |         if (DisguiseConfig.isEquipmentPacketsEnabled()) { | ||||||
|             for (EquipmentSlot slot : EquipmentSlot.values()) { |             for (EquipmentSlot slot : EquipmentSlot.values()) { | ||||||
|                 // Get what the disguise wants to show for its armor |                 // Get what the disguise wants to show for its armor | ||||||
|                 ItemStack itemToSend; |                 ItemStack itemToSend = disguise.getWatcher().getItemStack(slot); | ||||||
|  |  | ||||||
|                 if (delayedArmor) { |                 // If the disguise armor isn't visible | ||||||
|                     itemToSend = new ItemStack(Material.AIR); |                 if (itemToSend == null) { | ||||||
|                 } else { |                     itemToSend = ReflectionManager.getEquipment(slot, disguisedEntity); | ||||||
|                     itemToSend = disguise.getWatcher().getItemStack(slot); |  | ||||||
|  |  | ||||||
|                     // If the disguise armor isn't visible |                     // If natural armor isn't sent either | ||||||
|                     if (itemToSend == null) { |                     if (itemToSend == null || itemToSend.getType() == Material.AIR) { | ||||||
|                         itemToSend = ReflectionManager.getEquipment(slot, disguisedEntity); |  | ||||||
|  |  | ||||||
|                         // If natural armor isn't sent either |  | ||||||
|                         if (itemToSend == null || itemToSend.getType() == Material.AIR) { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
|                     } else if (itemToSend.getType() == Material.AIR) { |  | ||||||
|                         // Its air which shouldn't be sent |  | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|  |                 } else if (itemToSend.getType() == Material.AIR) { | ||||||
|  |                     // Its air which shouldn't be sent | ||||||
|  |                     continue; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT); |                 PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT); | ||||||
|   | |||||||
| @@ -61,8 +61,6 @@ public class PacketListenerMain extends PacketAdapter { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         packets.setSpawnPacketCheck(event.getPacketType()); |  | ||||||
|  |  | ||||||
|         event.setCancelled(true); |         event.setCancelled(true); | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|   | |||||||
| @@ -77,8 +77,6 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter { | |||||||
|                 transformed.getPackets().add(packet); |                 transformed.getPackets().add(packet); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             transformed.setSpawnPacketCheck(event.getPacketType()); |  | ||||||
|  |  | ||||||
|             for (PacketContainer newPacket : transformed.getPackets()) { |             for (PacketContainer newPacket : transformed.getPackets()) { | ||||||
|                 if (newPacket.getType() != Server.PLAYER_INFO) { |                 if (newPacket.getType() != Server.PLAYER_INFO) { | ||||||
|                     if (newPacket == packet) { |                     if (newPacket == packet) { | ||||||
|   | |||||||
| @@ -253,11 +253,9 @@ HideDisguisedPlayersFromTab: false | |||||||
| ShowPlayerDisguisesInTab: false | ShowPlayerDisguisesInTab: false | ||||||
|  |  | ||||||
| # On player disguise, a fake player is added to tablist so the skin can load properly. | # On player disguise, a fake player is added to tablist so the skin can load properly. | ||||||
| # If the viewer sees the player disguise but there's no tablist name, they won't see a skin. |  | ||||||
| # 3 seconds is normally long enough to load the skin properly, but sometimes the server needs longer |  | ||||||
| # This is in ticks, there are 20 ticks in every second. 60 ticks = 3 seconds. 200 ticks = 10 seconds. |  | ||||||
| # This option is ignored if 'ShowPlayerDisguisesInTab' is enabled. | # This option is ignored if 'ShowPlayerDisguisesInTab' is enabled. | ||||||
| PlayerDisguisesTablistExpires: 60 | # 2 ticks should easily be enough. | ||||||
|  | PlayerDisguisesTablistExpires: 2 | ||||||
|  |  | ||||||
| # Don't like players able to set themselves invisible when using the disguise commands? Toggle this to true and no one can use setInvisible! Plugins can still use this however. | # Don't like players able to set themselves invisible when using the disguise commands? Toggle this to true and no one can use setInvisible! Plugins can still use this however. | ||||||
| DisableInvisibility: false | DisableInvisibility: false | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user