Small code cleanup
This commit is contained in:
		| @@ -1268,122 +1268,131 @@ public class DisguiseUtilities { | |||||||
|         String originalTeam = preDisguiseTeam.remove(player.getUniqueId()); |         String originalTeam = preDisguiseTeam.remove(player.getUniqueId()); | ||||||
|         String teamDisguise = disguiseTeam.remove(player.getUniqueId()); |         String teamDisguise = disguiseTeam.remove(player.getUniqueId()); | ||||||
|  |  | ||||||
|         if (teamDisguise != null && DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) { |         if (teamDisguise == null || DisguiseConfig.getPushingOption() == DisguisePushing.IGNORE_SCOREBOARD) { | ||||||
|             // Code replace them back onto their original scoreboard team |             return; | ||||||
|             Scoreboard scoreboard = player.getScoreboard(); |         } | ||||||
|             Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam); |  | ||||||
|             Team ldTeam = null; |  | ||||||
|  |  | ||||||
|             for (Team t : scoreboard.getTeams()) { |         // Code replace them back onto their original scoreboard team | ||||||
|                 if (!t.hasEntry(player.getName())) |         Scoreboard scoreboard = player.getScoreboard(); | ||||||
|                     continue; |         Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam); | ||||||
|  |         Team ldTeam = null; | ||||||
|  |  | ||||||
|                 ldTeam = t; |         for (Team t : scoreboard.getTeams()) { | ||||||
|                 break; |             if (!t.hasEntry(player.getName())) | ||||||
|             } |                 continue; | ||||||
|  |  | ||||||
|             if (DisguiseConfig.isWarnScoreboardConflict()) { |             ldTeam = t; | ||||||
|                 if (ldTeam == null || !ldTeam.getName().equals(teamDisguise)) { |             break; | ||||||
|                     getLogger().warning("Scoreboard conflict, the self disguise player was not on the expected team!"); |         } | ||||||
|                 } else { |  | ||||||
|                     OptionStatus collisions = ldTeam.getOption(Option.COLLISION_RULE); |  | ||||||
|  |  | ||||||
|                     if (collisions != OptionStatus.NEVER && collisions != OptionStatus.FOR_OTHER_TEAMS) { |         if (DisguiseConfig.isWarnScoreboardConflict()) { | ||||||
|                         getLogger().warning( |             if (ldTeam == null || !ldTeam.getName().equals(teamDisguise)) { | ||||||
|                                 "Scoreboard conflict, the collisions for a self disguise player team has been " + |                 getLogger().warning("Scoreboard conflict, the self disguise player was not on the expected team!"); | ||||||
|                                         "unexpectedly modifed!"); |             } else { | ||||||
|                     } |                 OptionStatus collisions = ldTeam.getOption(Option.COLLISION_RULE); | ||||||
|  |  | ||||||
|  |                 if (collisions != OptionStatus.NEVER && collisions != OptionStatus.FOR_OTHER_TEAMS) { | ||||||
|  |                     getLogger().warning( | ||||||
|  |                             "Scoreboard conflict, the collisions for a self disguise player team has been " + | ||||||
|  |                                     "unexpectedly modifed!"); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|             if (ldTeam != null) { |         if (ldTeam != null) { | ||||||
|                 if (!ldTeam.getName().equals("LD_Pushing") && !ldTeam.getName().endsWith("_LDP")) { |             if (!ldTeam.getName().equals("LD_Pushing") && !ldTeam.getName().endsWith("_LDP")) { | ||||||
|                     // Its not a team assigned by Lib's Disguises |                 // Its not a team assigned by Lib's Disguises | ||||||
|                     ldTeam = null; |                 ldTeam = null; | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|             if (team != null) { |         if (team != null) { | ||||||
|                 team.addEntry(player.getName()); |             team.addEntry(player.getName()); | ||||||
|             } else if (ldTeam != null) { |         } else if (ldTeam != null) { | ||||||
|                 ldTeam.removeEntry(player.getName()); |             ldTeam.removeEntry(player.getName()); | ||||||
|             } |         } | ||||||
|  |  | ||||||
|             if (ldTeam != null && ldTeam.getEntries().isEmpty()) { |         if (ldTeam != null && ldTeam.getEntries().isEmpty()) { | ||||||
|                 ldTeam.unregister(); |             ldTeam.unregister(); | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setupSelfDisguiseScoreboard(Player player) { |     public static void setupSelfDisguiseScoreboard(Player player) { | ||||||
|  |         // They're already in a disguise team | ||||||
|  |         if (disguiseTeam.containsKey(player.getUniqueId())) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         DisguisePushing pOption = DisguiseConfig.getPushingOption(); |         DisguisePushing pOption = DisguiseConfig.getPushingOption(); | ||||||
|  |  | ||||||
|         if (pOption != DisguisePushing.IGNORE_SCOREBOARD) { |         if (pOption == DisguisePushing.IGNORE_SCOREBOARD) { | ||||||
|             // Code to stop player pushing |             return; | ||||||
|             Scoreboard scoreboard = player.getScoreboard(); |         } | ||||||
|             Team prevTeam = null; |  | ||||||
|             Team ldTeam = null; |  | ||||||
|             String ldTeamName = "LD_Pushing"; |  | ||||||
|  |  | ||||||
|             for (Team t : scoreboard.getTeams()) { |         // Code to stop player pushing | ||||||
|                 if (!t.hasEntry(player.getName())) |         Scoreboard scoreboard = player.getScoreboard(); | ||||||
|                     continue; |         Team prevTeam = null; | ||||||
|  |         Team ldTeam = null; | ||||||
|  |         String ldTeamName = "LD_Pushing"; | ||||||
|  |  | ||||||
|                 prevTeam = t; |         for (Team t : scoreboard.getTeams()) { | ||||||
|                 break; |             if (!t.hasEntry(player.getName())) | ||||||
|             } |                 continue; | ||||||
|  |  | ||||||
|             // If the player is in a team already and the team isn't one controlled by Lib's Disguises |             prevTeam = t; | ||||||
|             if (prevTeam != null && !(prevTeam.getName().equals("LD_Pushing") || prevTeam.getName().endsWith("_LDP"))) { |             break; | ||||||
|                 // If we're creating a scoreboard |         } | ||||||
|                 if (pOption == DisguisePushing.CREATE_SCOREBOARD) { |  | ||||||
|                     // Remember his old team so we can give him it back later |  | ||||||
|                     preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName()); |  | ||||||
|                 } else { |  | ||||||
|                     // We're modifying the scoreboard |  | ||||||
|                     ldTeam = prevTeam; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 prevTeam = null; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             // If we are creating a new scoreboard because the current one must not be modified |         // If the player is in a team already and the team isn't one controlled by Lib's Disguises | ||||||
|  |         if (prevTeam != null && !(prevTeam.getName().equals("LD_Pushing") || prevTeam.getName().endsWith("_LDP"))) { | ||||||
|  |             // If we're creating a scoreboard | ||||||
|             if (pOption == DisguisePushing.CREATE_SCOREBOARD) { |             if (pOption == DisguisePushing.CREATE_SCOREBOARD) { | ||||||
|                 // If they have a team, we'll reuse that name. Otherwise go for another name |                 // Remember his old team so we can give him it back later | ||||||
|                 ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName()); |                 preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName()); | ||||||
|  |             } else { | ||||||
|                 // Give the teamname a custom name |                 // We're modifying the scoreboard | ||||||
|                 ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP"; |                 ldTeam = prevTeam; | ||||||
|             } |             } | ||||||
|  |         } else { | ||||||
|  |             prevTeam = null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|             if (ldTeam == null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) { |         // If we are creating a new scoreboard because the current one must not be modified | ||||||
|                 ldTeam = scoreboard.registerNewTeam(ldTeamName); |         if (pOption == DisguisePushing.CREATE_SCOREBOARD) { | ||||||
|  |             // If they have a team, we'll reuse that name. Otherwise go for another name | ||||||
|  |             ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName()); | ||||||
|  |  | ||||||
|  |             // Give the teamname a custom name | ||||||
|  |             ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (ldTeam == null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) { | ||||||
|  |             ldTeam = scoreboard.registerNewTeam(ldTeamName); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         disguiseTeam.put(player.getUniqueId(), ldTeam.getName()); | ||||||
|  |  | ||||||
|  |         if (!ldTeam.hasEntry(player.getName())) | ||||||
|  |             ldTeam.addEntry(player.getName()); | ||||||
|  |  | ||||||
|  |         if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) { | ||||||
|  |             ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire()); | ||||||
|  |             ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles()); | ||||||
|  |             ldTeam.setDisplayName(prevTeam.getDisplayName()); | ||||||
|  |             ldTeam.setPrefix(prevTeam.getPrefix()); | ||||||
|  |             ldTeam.setSuffix(prevTeam.getSuffix()); | ||||||
|  |  | ||||||
|  |             for (Option option : Team.Option.values()) { | ||||||
|  |                 ldTeam.setOption(option, prevTeam.getOption(option)); | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|             disguiseTeam.put(player.getUniqueId(), ldTeam.getName()); |         if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER && DisguiseConfig.isModifyCollisions()) { | ||||||
|  |             ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); | ||||||
|  |         } | ||||||
|  |  | ||||||
|             if (!ldTeam.hasEntry(player.getName())) |         if (ldTeam.canSeeFriendlyInvisibles() && DisguiseConfig.isDisableFriendlyInvisibles()) { | ||||||
|                 ldTeam.addEntry(player.getName()); |             ldTeam.setCanSeeFriendlyInvisibles(false); | ||||||
|  |  | ||||||
|             if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) { |  | ||||||
|                 ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire()); |  | ||||||
|                 ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles()); |  | ||||||
|                 ldTeam.setDisplayName(prevTeam.getDisplayName()); |  | ||||||
|                 ldTeam.setPrefix(prevTeam.getPrefix()); |  | ||||||
|                 ldTeam.setSuffix(prevTeam.getSuffix()); |  | ||||||
|  |  | ||||||
|                 for (Option option : Team.Option.values()) { |  | ||||||
|                     ldTeam.setOption(option, prevTeam.getOption(option)); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER && DisguiseConfig.isModifyCollisions()) { |  | ||||||
|                 ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (ldTeam.canSeeFriendlyInvisibles() && DisguiseConfig.isDisableFriendlyInvisibles()) { |  | ||||||
|                 ldTeam.setCanSeeFriendlyInvisibles(false); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -1645,7 +1654,7 @@ public class DisguiseUtilities { | |||||||
|             if (transformed.isUnhandled()) |             if (transformed.isUnhandled()) | ||||||
|                 transformed.addPacket(packet); |                 transformed.addPacket(packet); | ||||||
|  |  | ||||||
|             transformed.setPacketType(packet.getType()); |             transformed.setSpawnPacketCheck(packet.getType()); | ||||||
|  |  | ||||||
|             for (PacketContainer p : transformed.getPackets()) { |             for (PacketContainer p : transformed.getPackets()) { | ||||||
|                 p = p.deepClone(); |                 p = p.deepClone(); | ||||||
| @@ -1668,7 +1677,7 @@ public class DisguiseUtilities { | |||||||
|     public static void setupFakeDisguise(final Disguise disguise) { |     public static void setupFakeDisguise(final Disguise disguise) { | ||||||
|         Entity e = disguise.getEntity(); |         Entity e = disguise.getEntity(); | ||||||
|  |  | ||||||
|         // If the disguises entity is null, or the disguised entity isn't a player return |         // If the disguises entity is null, or the disguised entity isn't a player; return | ||||||
|         if (!(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) || |         if (!(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) || | ||||||
|                 !getDisguises().get(e.getUniqueId()).contains(disguise)) { |                 !getDisguises().get(e.getUniqueId()).contains(disguise)) { | ||||||
|             return; |             return; | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ public class PacketsManager { | |||||||
|             return disguise; |             return disguise; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public void setPacketType(PacketType type) { |         public void setSpawnPacketCheck(PacketType type) { | ||||||
|             isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY"); |             isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -78,7 +78,7 @@ public class PacketsManager { | |||||||
|  |  | ||||||
|         public void addDelayedPacket(PacketContainer packet, int ticksDelayed) { |         public void addDelayedPacket(PacketContainer packet, int ticksDelayed) { | ||||||
|             if (!delayedPackets.containsKey(ticksDelayed)) |             if (!delayedPackets.containsKey(ticksDelayed)) | ||||||
|                 delayedPackets.put(ticksDelayed, new ArrayList<PacketContainer>()); |                 delayedPackets.put(ticksDelayed, new ArrayList<>()); | ||||||
|  |  | ||||||
|             delayedPackets.get(ticksDelayed).add(packet); |             delayedPackets.get(ticksDelayed).add(packet); | ||||||
|         } |         } | ||||||
| @@ -681,7 +681,7 @@ public class PacketsManager { | |||||||
|         soundsListener = new PacketListenerSounds(libsDisguises); |         soundsListener = new PacketListenerSounds(libsDisguises); | ||||||
|  |  | ||||||
|         // Self disguise (/vsd) listener |         // Self disguise (/vsd) listener | ||||||
|         viewDisguisesListener = new PacketListenerViewDisguises(libsDisguises); |         viewDisguisesListener = new PacketListenerViewSelfDisguise(libsDisguises); | ||||||
|  |  | ||||||
|         inventoryListener = new PacketListenerInventory(libsDisguises); |         inventoryListener = new PacketListenerInventory(libsDisguises); | ||||||
|     } |     } | ||||||
| @@ -951,13 +951,19 @@ public class PacketsManager { | |||||||
|                     sentPacket.getType() == Server.REL_ENTITY_MOVE) { |                     sentPacket.getType() == Server.REL_ENTITY_MOVE) { | ||||||
|                 if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || |                 if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || | ||||||
|                         sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { |                         sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { | ||||||
|                     // Rabbit robbing... |                     // When did the rabbit disguise last hop | ||||||
|                     if (entity.getMetadata("LibsRabbitHop").isEmpty() || |                     long lastHop = 999999; | ||||||
|                             System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 || |  | ||||||
|                             System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { |                     // If hop meta exists, set the last hop time | ||||||
|                         if (entity.getMetadata("LibsRabbitHop").isEmpty() || |                     if (!entity.getMetadata("LibsRabbitHop").isEmpty()) { | ||||||
|                                 System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > |                         // Last hop was 3 minutes ago, so subtract current time with the last hop time and get 3 | ||||||
|                                         500) { |                         // minutes ago in milliseconds | ||||||
|  |                         lastHop = System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong(); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     // If last hop was less than 0.1 or more than 0.5 seconds ago | ||||||
|  |                     if (lastHop < 100 || lastHop > 500) { | ||||||
|  |                         if (lastHop > 500) { | ||||||
|                             entity.removeMetadata("LibsRabbitHop", libsDisguises); |                             entity.removeMetadata("LibsRabbitHop", libsDisguises); | ||||||
|                             entity.setMetadata("LibsRabbitHop", |                             entity.setMetadata("LibsRabbitHop", | ||||||
|                                     new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); |                                     new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); | ||||||
|   | |||||||
| @@ -66,7 +66,7 @@ public class PacketListenerMain extends PacketAdapter { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         packets.setPacketType(event.getPacketType()); |         packets.setSpawnPacketCheck(event.getPacketType()); | ||||||
|  |  | ||||||
|         event.setCancelled(true); |         event.setCancelled(true); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,172 +1,177 @@ | |||||||
| package me.libraryaddict.disguise.utilities.packetlisteners; | package me.libraryaddict.disguise.utilities.packetlisteners; | ||||||
| 
 | 
 | ||||||
| import java.lang.reflect.InvocationTargetException; | import com.comphenix.protocol.PacketType; | ||||||
| import java.util.ArrayList; | import com.comphenix.protocol.PacketType.Play.Server; | ||||||
| import java.util.List; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| 
 | import com.comphenix.protocol.events.ListenerPriority; | ||||||
| import org.bukkit.entity.Player; | import com.comphenix.protocol.events.PacketAdapter; | ||||||
| 
 | import com.comphenix.protocol.events.PacketContainer; | ||||||
| import com.comphenix.protocol.PacketType; | import com.comphenix.protocol.events.PacketEvent; | ||||||
| import com.comphenix.protocol.PacketType.Play.Server; | import com.comphenix.protocol.reflect.StructureModifier; | ||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||||
| import com.comphenix.protocol.events.ListenerPriority; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import com.comphenix.protocol.events.PacketAdapter; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import com.comphenix.protocol.events.PacketEvent; | import me.libraryaddict.disguise.utilities.PacketsManager; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; | import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; | ||||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
| 
 | import org.bukkit.entity.Player; | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | 
 | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import java.lang.reflect.InvocationTargetException; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import java.util.ArrayList; | ||||||
| import me.libraryaddict.disguise.utilities.PacketsManager; | import java.util.List; | ||||||
| import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; | 
 | ||||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | public class PacketListenerViewSelfDisguise extends PacketAdapter { | ||||||
| 
 |     public PacketListenerViewSelfDisguise(LibsDisguises plugin) { | ||||||
| public class PacketListenerViewDisguises extends PacketAdapter { |         super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, | ||||||
|     public PacketListenerViewDisguises(LibsDisguises plugin) { |                 Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION, | ||||||
|         super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, |                 Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT, | ||||||
|                 Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION, |                 Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS); | ||||||
|                 Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT, |     } | ||||||
|                 Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS); | 
 | ||||||
|     } |     @Override | ||||||
| 
 |     public void onPacketSending(final PacketEvent event) { | ||||||
|     @Override |         if (event.isCancelled()) | ||||||
|     public void onPacketSending(final PacketEvent event) { |             return; | ||||||
|         if (event.isCancelled()) | 
 | ||||||
|             return; |         try { | ||||||
| 
 |             final Player observer = event.getPlayer(); | ||||||
|         try { | 
 | ||||||
|             final Player observer = event.getPlayer(); |             if (observer.getName().contains("UNKNOWN[")) {// If the player is temporary | ||||||
| 
 |                 return; | ||||||
|             if (observer.getName().contains("UNKNOWN[")) // If the player is temporary |             } | ||||||
|                 return; | 
 | ||||||
| 
 |             PacketContainer packet = event.getPacket(); | ||||||
|             if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) { | 
 | ||||||
|                 return; |             // If packet isn't meant for the disguised player's self disguise | ||||||
|             } |             if (packet.getIntegers().read(0) != observer.getEntityId()) { | ||||||
| 
 |                 return; | ||||||
|             if (!DisguiseAPI.isSelfDisguised(observer)) { |             } | ||||||
|                 if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) { | 
 | ||||||
|                     Disguise disguise = DisguiseAPI.getDisguise(observer, observer); |             if (!DisguiseAPI.isSelfDisguised(observer)) { | ||||||
| 
 |                 if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) { | ||||||
|                     if (disguise != null && disguise.isSelfDisguiseVisible()) { |                     Disguise disguise = DisguiseAPI.getDisguise(observer, observer); | ||||||
|                         event.setCancelled(true); | 
 | ||||||
|                     } |                     if (disguise != null && disguise.isSelfDisguiseVisible()) { | ||||||
|                 } |                         event.setCancelled(true); | ||||||
| 
 |                     } | ||||||
|                 return; |                 } | ||||||
|             } | 
 | ||||||
| 
 |                 return; | ||||||
|             final Disguise disguise = DisguiseAPI.getDisguise(observer, observer); |             } | ||||||
| 
 | 
 | ||||||
|             if (disguise == null) |             final Disguise disguise = DisguiseAPI.getDisguise(observer, observer); | ||||||
|                 return; | 
 | ||||||
| 
 |             if (disguise == null) { | ||||||
|             // Here I grab the packets to convert them to, So I can display them as if the disguise sent them. |                 return; | ||||||
|             LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer); |             } | ||||||
| 
 | 
 | ||||||
|             if (transformed.isUnhandled()) { |             // Here I grab the packets to convert them to, So I can display them as if the disguise sent them. | ||||||
|                 transformed.getPackets().add(event.getPacket()); |             LibsPackets transformed = PacketsManager.transformPacket(packet, disguise, observer, observer); | ||||||
|             } | 
 | ||||||
| 
 |             if (transformed.isUnhandled()) { | ||||||
|             transformed.setPacketType(event.getPacketType()); |                 transformed.getPackets().add(packet); | ||||||
| 
 |             } | ||||||
|             for (PacketContainer packet : transformed.getPackets()) { | 
 | ||||||
|                 if (packet.getType() != Server.PLAYER_INFO) { |             transformed.setSpawnPacketCheck(event.getPacketType()); | ||||||
|                     if (packet.equals(event.getPacket())) { | 
 | ||||||
|                         packet = packet.shallowClone(); |             for (PacketContainer newPacket : transformed.getPackets()) { | ||||||
|                     } |                 if (newPacket.getType() != Server.PLAYER_INFO) { | ||||||
| 
 |                     if (newPacket.equals(packet)) { | ||||||
|                     packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                         newPacket = newPacket.shallowClone(); | ||||||
|                 } |                     } | ||||||
| 
 | 
 | ||||||
|                 try { |                     newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); |                 } | ||||||
|                 } | 
 | ||||||
|                 catch (InvocationTargetException e) { |                 try { | ||||||
|                     e.printStackTrace(); |                     ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false); | ||||||
|                 } |                 } | ||||||
|             } |                 catch (InvocationTargetException e) { | ||||||
| 
 |                     e.printStackTrace(); | ||||||
|             for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) { |                 } | ||||||
|                 for (PacketContainer packet : packets) { |             } | ||||||
|                     if (packet.getType() != Server.PLAYER_INFO) { | 
 | ||||||
|                         if (packet.equals(event.getPacket())) { |             for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) { | ||||||
|                             packet = packet.shallowClone(); |                 for (PacketContainer newPacket : packets) { | ||||||
|                         } |                     if (newPacket.getType() == Server.PLAYER_INFO) { | ||||||
| 
 |                         continue; | ||||||
|                         packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                     } | ||||||
|                     } | 
 | ||||||
|                 } |                     if (newPacket.equals(packet)) { | ||||||
|             } |                         newPacket = newPacket.shallowClone(); | ||||||
| 
 |                     } | ||||||
|             transformed.sendDelayed(observer); | 
 | ||||||
| 
 |                     newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
|             if (event.getPacketType() == Server.ENTITY_METADATA) { |                 } | ||||||
|                 event.setPacket(event.getPacket().deepClone()); |             } | ||||||
| 
 | 
 | ||||||
|                 for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) { |             transformed.sendDelayed(observer); | ||||||
|                     if (watch.getIndex() == 0) { | 
 | ||||||
|                         byte b = (byte) watch.getValue(); |             if (event.getPacketType() == Server.ENTITY_METADATA) { | ||||||
| 
 |                 event.setPacket(packet.deepClone()); | ||||||
|                         byte a = (byte) (b | 1 << 5); | 
 | ||||||
| 
 |                 for (WrappedWatchableObject watch : packet.getWatchableCollectionModifier().read(0)) { | ||||||
|                         if ((b & 1 << 3) != 0) |                     if (watch.getIndex() == 0) { | ||||||
|                             a = (byte) (a | 1 << 3); |                         byte b = (byte) watch.getValue(); | ||||||
| 
 | 
 | ||||||
|                         watch.setValue(a); |                         byte a = (byte) (b | 1 << 5); | ||||||
|                     } | 
 | ||||||
|                 } |                         if ((b & 1 << 3) != 0) | ||||||
|             } else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) { |                             a = (byte) (a | 1 << 3); | ||||||
|                 event.setCancelled(true); | 
 | ||||||
| 
 |                         watch.setValue(a); | ||||||
|                 PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); |                     } | ||||||
| 
 |                 } | ||||||
|                 StructureModifier<Object> mods = packet.getModifier(); |             } else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) { | ||||||
| 
 |                 event.setCancelled(true); | ||||||
|                 mods.write(0, observer.getEntityId()); | 
 | ||||||
| 
 |                 PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA); | ||||||
|                 List<WrappedWatchableObject> watchableList = new ArrayList<>(); | 
 | ||||||
|                 Byte b = 1 << 5; |                 StructureModifier<Object> mods = metaPacket.getModifier(); | ||||||
| 
 | 
 | ||||||
|                 if (observer.isSprinting()) |                 mods.write(0, observer.getEntityId()); | ||||||
|                     b = (byte) (b | 1 << 3); | 
 | ||||||
| 
 |                 List<WrappedWatchableObject> watchableList = new ArrayList<>(); | ||||||
|                 WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b); |                 byte b = 1 << 5; | ||||||
| 
 | 
 | ||||||
|                 if (watch != null) |                 if (observer.isSprinting()) | ||||||
|                     watchableList.add(watch); |                     b = (byte) (b | 1 << 3); | ||||||
| 
 | 
 | ||||||
|                 packet.getWatchableCollectionModifier().write(0, watchableList); |                 WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b); | ||||||
| 
 | 
 | ||||||
|                 try { |                 if (watch != null) | ||||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); |                     watchableList.add(watch); | ||||||
|                 } | 
 | ||||||
|                 catch (InvocationTargetException e) { |                 metaPacket.getWatchableCollectionModifier().write(0, watchableList); | ||||||
|                     e.printStackTrace(); | 
 | ||||||
|                 } |                 try { | ||||||
|             } else if (event.getPacketType() == Server.ANIMATION) { |                     ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket); | ||||||
|                 if (event.getPacket().getIntegers().read(1) != 2) { |                 } | ||||||
|                     event.setCancelled(true); |                 catch (InvocationTargetException e) { | ||||||
|                 } |                     e.printStackTrace(); | ||||||
|             } else if (event.getPacketType() == Server.ATTACH_ENTITY || event |                 } | ||||||
|                     .getPacketType() == Server.REL_ENTITY_MOVE || event |             } else if (event.getPacketType() == Server.ANIMATION) { | ||||||
|                     .getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event |                 if (packet.getIntegers().read(1) != 2) { | ||||||
|                     .getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || event |                     event.setCancelled(true); | ||||||
|                     .getPacketType() == Server.ENTITY_HEAD_ROTATION || event |                 } | ||||||
|                     .getPacketType() == Server.ENTITY_EQUIPMENT) { |             } else if (event.getPacketType() == Server.ATTACH_ENTITY || | ||||||
|                 event.setCancelled(true); |                     event.getPacketType() == Server.REL_ENTITY_MOVE || | ||||||
|             } else if (event.getPacketType() == Server.ENTITY_STATUS) { |                     event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || | ||||||
|                 if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() && event.getPacket() |                     event.getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || | ||||||
|                         .getBytes().read(0) == 2) { |                     event.getPacketType() == Server.ENTITY_HEAD_ROTATION || | ||||||
|                     event.setCancelled(true); |                     event.getPacketType() == Server.ENTITY_EQUIPMENT) { | ||||||
|                 } |                 event.setCancelled(true); | ||||||
|             } |             } else if (event.getPacketType() == Server.ENTITY_STATUS) { | ||||||
|         } |                 if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() && | ||||||
|         catch (Exception ex) { |                         packet.getBytes().read(0) == 2) { | ||||||
|             event.setCancelled(true); |                     event.setCancelled(true); | ||||||
|             ex.printStackTrace(); |                 } | ||||||
|         } |             } | ||||||
|     } |         } | ||||||
| } |         catch (Exception ex) { | ||||||
|  |             event.setCancelled(true); | ||||||
|  |             ex.printStackTrace(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user