Deny async
This commit is contained in:
		| @@ -11,7 +11,6 @@ import org.bukkit.entity.Zombie; | |||||||
|  |  | ||||||
| public enum DisguiseType | public enum DisguiseType | ||||||
| { | { | ||||||
|  |  | ||||||
|     AREA_EFFECT_CLOUD(3, 0), |     AREA_EFFECT_CLOUD(3, 0), | ||||||
|  |  | ||||||
|     ARMOR_STAND(78), |     ARMOR_STAND(78), | ||||||
|   | |||||||
| @@ -34,6 +34,7 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|     public PlayerDisguise(String name, String skinToUse) |     public PlayerDisguise(String name, String skinToUse) | ||||||
|     { |     { | ||||||
|         this(name); |         this(name); | ||||||
|  |  | ||||||
|         setSkin(skinToUse); |         setSkin(skinToUse); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -42,6 +43,11 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         this(ReflectionManager.getGameProfile(player)); |         this(ReflectionManager.getGameProfile(player)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public PlayerDisguise(Player player, Player skinToUse) | ||||||
|  |     { | ||||||
|  |         this(ReflectionManager.getGameProfile(player), ReflectionManager.getGameProfile(skinToUse)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public PlayerDisguise(WrappedGameProfile gameProfile) |     public PlayerDisguise(WrappedGameProfile gameProfile) | ||||||
|     { |     { | ||||||
|         this(gameProfile.getName()); |         this(gameProfile.getName()); | ||||||
| @@ -49,6 +55,13 @@ public class PlayerDisguise extends TargetedDisguise | |||||||
|         this.gameProfile = gameProfile; |         this.gameProfile = gameProfile; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public PlayerDisguise(WrappedGameProfile gameProfile, WrappedGameProfile skinToUse) | ||||||
|  |     { | ||||||
|  |         this(gameProfile); | ||||||
|  |  | ||||||
|  |         setSkin(skinToUse); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerDisguise addPlayer(Player player) |     public PlayerDisguise addPlayer(Player player) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -15,35 +15,41 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  |  | ||||||
| public class PlayerWatcher extends LivingWatcher { | public class PlayerWatcher extends LivingWatcher | ||||||
|  | { | ||||||
|     private boolean isInBed; |     private boolean isInBed; | ||||||
|     private BlockFace sleepingDirection; |     private BlockFace sleepingDirection; | ||||||
|  |  | ||||||
|     public PlayerWatcher(Disguise disguise) { |     public PlayerWatcher(Disguise disguise) | ||||||
|  |     { | ||||||
|         super(disguise); |         super(disguise); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PlayerWatcher clone(Disguise disguise) { |     public PlayerWatcher clone(Disguise disguise) | ||||||
|  |     { | ||||||
|         PlayerWatcher watcher = (PlayerWatcher) super.clone(disguise); |         PlayerWatcher watcher = (PlayerWatcher) super.clone(disguise); | ||||||
|         watcher.isInBed = isInBed; |         watcher.isInBed = isInBed; | ||||||
|         return watcher; |         return watcher; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public BlockFace getSleepingDirection() { |     public BlockFace getSleepingDirection() | ||||||
|         if (sleepingDirection == null) { |     { | ||||||
|             if (this.getDisguise().getEntity() != null && isSleeping()) { |         if (sleepingDirection == null) | ||||||
|                 this.sleepingDirection = BlockFace.values()[Math |         { | ||||||
|                         .round(this.getDisguise().getEntity().getLocation().getYaw() / 90F) & 0x3]; |             if (this.getDisguise().getEntity() != null && isSleeping()) | ||||||
|             } else { |             { | ||||||
|  |                 this.sleepingDirection = BlockFace | ||||||
|  |                         .values()[Math.round(this.getDisguise().getEntity().getLocation().getYaw() / 90F) & 0x3]; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|                 return BlockFace.EAST; |                 return BlockFace.EAST; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return sleepingDirection; |         return sleepingDirection; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     // Bit 0 (0x01): Cape enabled |     // Bit 0 (0x01): Cape enabled | ||||||
|     // Bit 1 (0x02): Jacket enabled |     // Bit 1 (0x02): Jacket enabled | ||||||
|     // Bit 2 (0x04): Left Sleeve enabled |     // Bit 2 (0x04): Left Sleeve enabled | ||||||
| @@ -52,91 +58,110 @@ public class PlayerWatcher extends LivingWatcher { | |||||||
|     // Bit 5 (0x20): Right Pants Leg enabled |     // Bit 5 (0x20): Right Pants Leg enabled | ||||||
|     // Bit 6 (0x40): Hat enabled |     // Bit 6 (0x40): Hat enabled | ||||||
|  |  | ||||||
|     private boolean isSkinFlag(int i) { |     private boolean isSkinFlag(int i) | ||||||
|  |     { | ||||||
|         return ((byte) getValue(12, (byte) 0) & 1 << i) != 0; |         return ((byte) getValue(12, (byte) 0) & 1 << i) != 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isCapeEnabled() { |     public boolean isCapeEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(1); |         return isSkinFlag(1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isJackedEnabled() { |     public boolean isJackedEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(2); |         return isSkinFlag(2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isLeftSleeveEnabled() { |     public boolean isLeftSleeveEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(3); |         return isSkinFlag(3); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isRightSleeveEnabled() { |     public boolean isRightSleeveEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(4); |         return isSkinFlag(4); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isLeftPantsEnabled() { |     public boolean isLeftPantsEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(5); |         return isSkinFlag(5); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isRightPantsEnabled() { |     public boolean isRightPantsEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(6); |         return isSkinFlag(6); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isHatEnabled() { |     public boolean isHatEnabled() | ||||||
|  |     { | ||||||
|         return isSkinFlag(7); |         return isSkinFlag(7); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setCapeEnabled(boolean enabled) { |     public void setCapeEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(1, enabled); |         setSkinFlags(1, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setJackedEnabled(boolean enabled) { |     public void setJackedEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(2, enabled); |         setSkinFlags(2, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setLeftSleeveEnabled(boolean enabled) { |     public void setLeftSleeveEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(3, enabled); |         setSkinFlags(3, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setRightSleeveEnabled(boolean enabled) { |     public void setRightSleeveEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(4, enabled); |         setSkinFlags(4, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setLeftPantsEnabled(boolean enabled) { |     public void setLeftPantsEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(5, enabled); |         setSkinFlags(5, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setRightPantsEnabled(boolean enabled) { |     public void setRightPantsEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(6, enabled); |         setSkinFlags(6, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setHatEnabled(boolean enabled) { |     public void setHatEnabled(boolean enabled) | ||||||
|  |     { | ||||||
|         setSkinFlags(7, enabled); |         setSkinFlags(7, enabled); | ||||||
|         sendData(12); |         sendData(12); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isSleeping() | ||||||
|     public boolean isSleeping() { |     { | ||||||
|         return isInBed; |         return isInBed; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSkin(String playerName) { |     public void setSkin(String playerName) | ||||||
|  |     { | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(playerName); |         ((PlayerDisguise) getDisguise()).setSkin(playerName); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSkin(WrappedGameProfile profile) { |     public void setSkin(WrappedGameProfile profile) | ||||||
|  |     { | ||||||
|         ((PlayerDisguise) getDisguise()).setSkin(profile); |         ((PlayerDisguise) getDisguise()).setSkin(profile); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSleeping(BlockFace sleepingDirection) { |     public void setSleeping(BlockFace sleepingDirection) | ||||||
|  |     { | ||||||
|         setSleeping(true, sleepingDirection); |         setSleeping(true, sleepingDirection); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSleeping(boolean sleep) { |     public void setSleeping(boolean sleep) | ||||||
|  |     { | ||||||
|         setSleeping(sleep, null); |         setSleeping(sleep, null); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -146,52 +171,74 @@ public class PlayerWatcher extends LivingWatcher { | |||||||
|      * @param sleeping |      * @param sleeping | ||||||
|      * @param sleepingDirection |      * @param sleepingDirection | ||||||
|      */ |      */ | ||||||
|     public void setSleeping(boolean sleeping, BlockFace sleepingDirection) { |     public void setSleeping(boolean sleeping, BlockFace sleepingDirection) | ||||||
|         if (sleepingDirection != null) { |     { | ||||||
|  |         if (sleepingDirection != null) | ||||||
|  |         { | ||||||
|             this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4]; |             this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4]; | ||||||
|         } |         } | ||||||
|         if (sleeping != isSleeping()) { |         if (sleeping != isSleeping()) | ||||||
|  |         { | ||||||
|             isInBed = sleeping; |             isInBed = sleeping; | ||||||
|             if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise())) { |             if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise())) | ||||||
|                 try { |             { | ||||||
|                     if (isSleeping()) { |                 try | ||||||
|                         for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { |                 { | ||||||
|                             PacketContainer[] packets = DisguiseUtilities.getBedPackets(player, this.getDisguise().getEntity() |                     if (isSleeping()) | ||||||
|                                     .getLocation(), player.getLocation(), (PlayerDisguise) this.getDisguise()); |                     { | ||||||
|                             if (getDisguise().getEntity() == player) { |                         for (Player player : DisguiseUtilities.getPerverts(getDisguise())) | ||||||
|                                 for (PacketContainer packet : packets) { |                         { | ||||||
|  |                             PacketContainer[] packets = DisguiseUtilities.getBedPackets(player, | ||||||
|  |                                     this.getDisguise().getEntity().getLocation(), player.getLocation(), | ||||||
|  |                                     (PlayerDisguise) this.getDisguise()); | ||||||
|  |                             if (getDisguise().getEntity() == player) | ||||||
|  |                             { | ||||||
|  |                                 for (PacketContainer packet : packets) | ||||||
|  |                                 { | ||||||
|                                     packet = packet.shallowClone(); |                                     packet = packet.shallowClone(); | ||||||
|                                     packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); |                                     packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); | ||||||
|                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                                 } |                                 } | ||||||
|                             } else { |                             } | ||||||
|                                 for (PacketContainer packet : packets) { |                             else | ||||||
|  |                             { | ||||||
|  |                                 for (PacketContainer packet : packets) | ||||||
|  |                                 { | ||||||
|                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } else { |                     } | ||||||
|  |                     else | ||||||
|  |                     { | ||||||
|                         PacketContainer packet = new PacketContainer(Server.ANIMATION); |                         PacketContainer packet = new PacketContainer(Server.ANIMATION); | ||||||
|                         StructureModifier<Integer> mods = packet.getIntegers(); |                         StructureModifier<Integer> mods = packet.getIntegers(); | ||||||
|                         mods.write(0, getDisguise().getEntity().getEntityId()); |                         mods.write(0, getDisguise().getEntity().getEntityId()); | ||||||
|                         mods.write(1, 3); |                         mods.write(1, 3); | ||||||
|                         for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { |                         for (Player player : DisguiseUtilities.getPerverts(getDisguise())) | ||||||
|  |                         { | ||||||
|                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|  |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } catch (Exception ex) { |                 } | ||||||
|  |                 catch (Exception ex) | ||||||
|  |                 { | ||||||
|                     ex.printStackTrace(System.out); |                     ex.printStackTrace(System.out); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void setSkinFlags(int i, boolean flag) { |     private void setSkinFlags(int i, boolean flag) | ||||||
|  |     { | ||||||
|         byte b0 = (byte) getValue(12, (byte) 0); |         byte b0 = (byte) getValue(12, (byte) 0); | ||||||
|         if (flag) { |         if (flag) | ||||||
|  |         { | ||||||
|             setValue(12, (byte) (b0 | 1 << i)); |             setValue(12, (byte) (b0 | 1 << i)); | ||||||
|         } else { |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|             setValue(12, (byte) (b0 & (~1 << i))); |             setValue(12, (byte) (b0 & (~1 << i))); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -83,6 +83,7 @@ public class DisguiseUtilities | |||||||
|     private static HashMap<String, ArrayList<Object>> runnables = new HashMap<>(); |     private static HashMap<String, ArrayList<Object>> runnables = new HashMap<>(); | ||||||
|     private static HashSet<UUID> selfDisguised = new HashSet<>(); |     private static HashSet<UUID> selfDisguised = new HashSet<>(); | ||||||
|     private static Field xChunk, zChunk; |     private static Field xChunk, zChunk; | ||||||
|  |     private static Thread mainThread; | ||||||
|  |  | ||||||
|     static |     static | ||||||
|     { |     { | ||||||
| @@ -146,6 +147,11 @@ public class DisguiseUtilities | |||||||
|  |  | ||||||
|             zChunk = bedChunk.getClass().getField("locZ"); |             zChunk = bedChunk.getClass().getField("locZ"); | ||||||
|             zChunk.setAccessible(true); |             zChunk.setAccessible(true); | ||||||
|  |  | ||||||
|  |             Field threadField = ReflectionManager.getNmsField("MinecraftServer", "primaryThread"); | ||||||
|  |             threadField.setAccessible(true); | ||||||
|  |  | ||||||
|  |             mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer()); | ||||||
|         } |         } | ||||||
|         catch (Exception ex) |         catch (Exception ex) | ||||||
|         { |         { | ||||||
| @@ -346,6 +352,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static void destroyEntity(TargetedDisguise disguise) |     public static void destroyEntity(TargetedDisguise disguise) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); |             Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); | ||||||
| @@ -637,6 +646,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static List<Player> getPerverts(Disguise disguise) |     public static List<Player> getPerverts(Disguise disguise) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         List<Player> players = new ArrayList<>(); |         List<Player> players = new ArrayList<>(); | ||||||
|  |  | ||||||
|         try |         try | ||||||
| @@ -865,6 +877,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static void refreshTracker(final TargetedDisguise disguise, String player) |     public static void refreshTracker(final TargetedDisguise disguise, String player) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         if (disguise.getEntity() != null && disguise.getEntity().isValid()) |         if (disguise.getEntity() != null && disguise.getEntity().isValid()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
| @@ -959,6 +974,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static void refreshTrackers(Entity entity) |     public static void refreshTrackers(Entity entity) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         if (entity.isValid()) |         if (entity.isValid()) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
| @@ -1021,6 +1039,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static void refreshTrackers(final TargetedDisguise disguise) |     public static void refreshTrackers(final TargetedDisguise disguise) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         if (disguise.getEntity().isValid()) |         if (disguise.getEntity().isValid()) | ||||||
|         { |         { | ||||||
|             PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); |             PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); | ||||||
| @@ -1131,6 +1152,9 @@ public class DisguiseUtilities | |||||||
|  |  | ||||||
|     public static void removeSelfDisguise(Player player) |     public static void removeSelfDisguise(Player player) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         if (selfDisguised.contains(player.getUniqueId())) |         if (selfDisguised.contains(player.getUniqueId())) | ||||||
|         { |         { | ||||||
|             // Send a packet to destroy the fake entity |             // Send a packet to destroy the fake entity | ||||||
| @@ -1212,6 +1236,9 @@ public class DisguiseUtilities | |||||||
|      */ |      */ | ||||||
|     public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) |     public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) | ||||||
|     { |     { | ||||||
|  |         if (mainThread != Thread.currentThread()) | ||||||
|  |             throw new IllegalStateException("Cannot modify disguises on an async thread"); | ||||||
|  |  | ||||||
|         try |         try | ||||||
|         { |         { | ||||||
|             if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible() |             if (!disguise.isDisguiseInUse() || !player.isValid() || !player.isOnline() || !disguise.isSelfDisguiseVisible() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user