| @@ -83,6 +83,7 @@ public class DisguiseConfig { | ||||
|         setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire")); | ||||
|         setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire")); | ||||
|         setMaxClonedDisguises(config.getInt("DisguiseCloneSize")); | ||||
|         setUnusedDisguisesRemoved(config.getBoolean("RemoveUnusedDisguises")); | ||||
|     } | ||||
|  | ||||
|     public static boolean isAnimationPacketsEnabled() { | ||||
|   | ||||
| @@ -105,7 +105,8 @@ public class DisguiseListener implements Listener { | ||||
|     public void onQuit(PlayerQuitEvent event) { | ||||
|         if (DisguiseConfig.isUnusedDisguisesRemoved()) { | ||||
|             for (TargetedDisguise disguise : DisguiseUtilities.getSeenDisguises(event.getPlayer().getName())) { | ||||
|                 disguise.removeDisguise(); | ||||
|                 // TODO fix | ||||
|                 // disguise.removeDisguise(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -68,20 +68,8 @@ public class LibsDisguises extends JavaPlugin { | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } finally { | ||||
|             try { | ||||
|                 if (stream != null) { | ||||
|                     stream.close(); | ||||
|                 } | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|             try { | ||||
|                 if (reader != null) { | ||||
|                     reader.close(); | ||||
|                 } | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|             tryClose(stream); | ||||
|             tryClose(reader); | ||||
|         } | ||||
|  | ||||
|         PacketsManager.init(this); | ||||
| @@ -149,20 +137,8 @@ public class LibsDisguises extends JavaPlugin { | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } finally { | ||||
|             try { | ||||
|                 if (input != null) { | ||||
|                     input.close(); | ||||
|                 } | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|             try { | ||||
|                 if (reader != null) { | ||||
|                     reader.close(); | ||||
|                 } | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|             tryClose(input); | ||||
|             tryClose(reader); | ||||
|         } | ||||
|         return toWrite; | ||||
|     } | ||||
| @@ -314,9 +290,19 @@ public class LibsDisguises extends JavaPlugin { | ||||
|     private String toReadable(String string) { | ||||
|         StringBuilder builder = new StringBuilder(); | ||||
|         for (String s : string.split("_")) { | ||||
|             builder.append(s.substring(0, 1) + s.substring(1).toLowerCase()); | ||||
|             builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase()); | ||||
|         } | ||||
|         return builder.toString(); | ||||
|     } | ||||
|  | ||||
|     private void tryClose(Closeable input) { | ||||
|         if (input != null) { | ||||
|             try { | ||||
|                 input.close(); | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -22,7 +22,7 @@ public class DisguiseCommand extends BaseDisguiseCommand { | ||||
|             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); | ||||
|             return true; | ||||
|         } | ||||
|         Disguise disguise = null; | ||||
|         Disguise disguise; | ||||
|         try { | ||||
|             disguise = parseDisguise(sender, args); | ||||
|         } catch (Exception ex) { | ||||
|   | ||||
| @@ -38,9 +38,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | ||||
|             return true; | ||||
|         } | ||||
|         String[] newArgs = new String[args.length - 1]; | ||||
|         for (int i = 0; i < newArgs.length; i++) { | ||||
|             newArgs[i] = args[i + 1]; | ||||
|         } | ||||
|         System.arraycopy(args, 1, newArgs, 0, newArgs.length); | ||||
|         Disguise disguise; | ||||
|         try { | ||||
|             disguise = parseDisguise(sender, newArgs); | ||||
| @@ -59,7 +57,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | ||||
|         } | ||||
|         if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||
|             if (disguise.getWatcher() instanceof LivingWatcher) { | ||||
|                 ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName()); | ||||
|                 ((LivingWatcher) disguise.getWatcher()).setCustomName(player.getDisplayName()); | ||||
|                 if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||
|                     ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); | ||||
|                 } | ||||
|   | ||||
| @@ -86,9 +86,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | ||||
|             radius = maxRadius; | ||||
|         } | ||||
|         String[] newArgs = new String[args.length - (starting + 1)]; | ||||
|         for (int i = 0; i < newArgs.length; i++) { | ||||
|             newArgs[i] = args[i + (starting + 1)]; | ||||
|         } | ||||
|         System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); | ||||
|         Disguise disguise; | ||||
|         try { | ||||
|             disguise = parseDisguise(sender, newArgs); | ||||
|   | ||||
| @@ -181,6 +181,7 @@ public abstract class Disguise { | ||||
|             private int deadTicks = 0; | ||||
|             private int refreshDisguise = 0; | ||||
|  | ||||
|             // TODO refactor | ||||
|             public void run() { | ||||
|                 // If entity is no longer valid. Remove it. | ||||
|                 if (!getEntity().isValid()) { | ||||
|   | ||||
| @@ -70,6 +70,7 @@ public class FlagWatcher { | ||||
|         try { | ||||
|             cloned = getClass().getConstructor(Disguise.class).newInstance(owningDisguise); | ||||
|         } catch (Exception e) { | ||||
|             // TODO: This will throw NPE | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); | ||||
| @@ -152,9 +153,7 @@ public class FlagWatcher { | ||||
|  | ||||
|     public ItemStack[] getArmor() { | ||||
|         ItemStack[] armor = new ItemStack[4]; | ||||
|         for (int i = 0; i < 4; i++) { | ||||
|             armor[i] = items[i]; | ||||
|         } | ||||
|         System.arraycopy(items, 0, armor, 0, 4); | ||||
|         return armor; | ||||
|     } | ||||
|  | ||||
| @@ -305,11 +304,11 @@ public class FlagWatcher { | ||||
|         if (itemStack == null) { | ||||
|             // Find the item to replace it with | ||||
|             if (getDisguise().getEntity() instanceof LivingEntity) { | ||||
|                 EntityEquipment enquipment = ((LivingEntity) getDisguise().getEntity()).getEquipment(); | ||||
|                 EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment(); | ||||
|                 if (slot == 4) { | ||||
|                     itemStack = enquipment.getItemInHand(); | ||||
|                     itemStack = equipment.getItemInHand(); | ||||
|                 } else { | ||||
|                     itemStack = enquipment.getArmorContents()[slot]; | ||||
|                     itemStack = equipment.getArmorContents()[slot]; | ||||
|                 } | ||||
|                 if (itemStack != null && itemStack.getTypeId() == 0) { | ||||
|                     itemStack = null; | ||||
|   | ||||
| @@ -62,11 +62,8 @@ public class MobDisguise extends TargetedDisguise { | ||||
|     } | ||||
|  | ||||
|     public boolean doesDisguiseAge() { | ||||
|         if (getWatcher() != null) { | ||||
|             return getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher; | ||||
|         } | ||||
|         return false; | ||||
|  | ||||
|         return getWatcher() != null && | ||||
|                 (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher); | ||||
|     } | ||||
|  | ||||
|     public boolean isAdult() { | ||||
|   | ||||
| @@ -265,9 +265,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||
|         } | ||||
|         // Copy strings to their new range | ||||
|         String[] newArgs = new String[args.length - toSkip]; | ||||
|         for (int i = toSkip; i < args.length; i++) { | ||||
|             newArgs[i - toSkip] = args[i]; | ||||
|         } | ||||
|         System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip); | ||||
|         args = newArgs; | ||||
|         for (int i = 0; i < args.length; i += 2) { | ||||
|             String methodName = args[i]; | ||||
| @@ -350,7 +348,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||
|                             // Parse to horse color | ||||
|                         } else if (param.getSimpleName().equals("Color")) { | ||||
|                             try { | ||||
|  | ||||
|                                 value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); | ||||
|                             } catch (Exception ex) { | ||||
|                                 throw parseToException("a horse color", valueString, methodName); | ||||
|   | ||||
| @@ -30,7 +30,6 @@ import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.entity.Zombie; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.potion.PotionEffect; | ||||
| import org.bukkit.util.Vector; | ||||
|  | ||||
| import com.comphenix.protocol.PacketType; | ||||
| @@ -175,8 +174,7 @@ public class DisguiseUtilities { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Sends | ||||
|      *            entity removal packets, as this disguise was removed | ||||
|      * Sends entity removal packets, as this disguise was removed | ||||
|      */ | ||||
|     public static void destroyEntity(TargetedDisguise disguise) { | ||||
|         try { | ||||
| @@ -217,7 +215,7 @@ public class DisguiseUtilities { | ||||
|                         disguiseBox = disguiseValues.getBabyBox(); | ||||
|                     } | ||||
|                 } | ||||
|                 ReflectionManager.setBoundingBox(entity, disguiseBox, disguiseValues.getEntitySize()); | ||||
|                 ReflectionManager.setBoundingBox(entity, disguiseBox); | ||||
|             } else { | ||||
|                 DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); | ||||
|                 FakeBoundingBox entityBox = entityValues.getAdultBox(); | ||||
| @@ -227,7 +225,7 @@ public class DisguiseUtilities { | ||||
|                         entityBox = entityValues.getBabyBox(); | ||||
|                     } | ||||
|                 } | ||||
|                 ReflectionManager.setBoundingBox(entity, entityBox, entityValues.getEntitySize()); | ||||
|                 ReflectionManager.setBoundingBox(entity, entityBox); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -327,7 +325,7 @@ public class DisguiseUtilities { | ||||
|             public void onLookup(Object gameProfile) { | ||||
|                 getAddedByPlugins().remove(disguise.getName()); | ||||
|                 if (DisguiseAPI.isDisguiseInUse(disguise)) { | ||||
|                     DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise); | ||||
|                     DisguiseUtilities.refreshTrackers(disguise); | ||||
|                     if (disguise.getEntity() instanceof Player && disguise.isSelfDisguiseVisible()) { | ||||
|                         DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise); | ||||
|                     } | ||||
| @@ -445,11 +443,8 @@ public class DisguiseUtilities { | ||||
|     } | ||||
|  | ||||
|     public static boolean isDisguiseInUse(Disguise disguise) { | ||||
|         if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId()) | ||||
|                 && getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise)) { | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|         return disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getUniqueId()) | ||||
|                 && getDisguises().get(disguise.getEntity().getUniqueId()).contains(disguise); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -461,8 +456,7 @@ public class DisguiseUtilities { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Resends | ||||
|      *            the entity to this specific player | ||||
|      * Resends the entity to this specific player | ||||
|      */ | ||||
|     public static void refreshTracker(TargetedDisguise disguise, String player) { | ||||
|         if (disguise.getEntity() != null && disguise.getEntity().isValid()) { | ||||
| @@ -495,8 +489,7 @@ public class DisguiseUtilities { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param A | ||||
|      *            convidence method for me to refresh trackers in other plugins | ||||
|      * A convenience method for me to refresh trackers in other plugins | ||||
|      */ | ||||
|     public static void refreshTrackers(Entity entity) { | ||||
|         if (entity.isValid()) { | ||||
| @@ -532,8 +525,7 @@ public class DisguiseUtilities { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Resends | ||||
|      *            the entity to all the watching players, which is where the magic begins | ||||
|      * Resends the entity to all the watching players, which is where the magic begins | ||||
|      */ | ||||
|     public static void refreshTrackers(TargetedDisguise disguise) { | ||||
|         try { | ||||
| @@ -728,9 +720,7 @@ public class DisguiseUtilities { | ||||
|             } | ||||
|  | ||||
|             // Resend any active potion effects | ||||
|             Iterator iterator = player.getActivePotionEffects().iterator(); | ||||
|             while (iterator.hasNext()) { | ||||
|                 PotionEffect potionEffect = (PotionEffect) iterator.next(); | ||||
|             for (Object potionEffect : player.getActivePotionEffects()) { | ||||
|                 sendSelfPacket(player, | ||||
|                         manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect) | ||||
|                                 .createPacket(player.getEntityId(), potionEffect), fakeId); | ||||
|   | ||||
| @@ -94,7 +94,7 @@ public class PacketsManager { | ||||
|     /** | ||||
|      * Construct the packets I need to spawn in the disguise | ||||
|      */ | ||||
|     public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity, Player observer) { | ||||
|     public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) { | ||||
|         if (disguise.getEntity() == null) | ||||
|             disguise.setEntity(disguisedEntity); | ||||
|         Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); | ||||
| @@ -179,7 +179,7 @@ public class PacketsManager { | ||||
|                     stringMods.write(i, ((PlayerDisguise) disguise).getName()); | ||||
|                 } | ||||
|             } else { | ||||
|                 Object gameProfile = null; | ||||
|                 Object gameProfile; | ||||
|                 String name = ((PlayerDisguise) disguise).getName(); | ||||
|                 boolean removeName = false; | ||||
|                 if (!DisguiseUtilities.hasGameProfile(name)) { | ||||
| @@ -529,8 +529,9 @@ public class PacketsManager { | ||||
|                             if (disguise.isSoundsReplaced()) { | ||||
|                                 String sound = null; | ||||
|                                 DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); | ||||
|                                 if (dSound != null && soundType != null) | ||||
|                                 if (dSound != null) | ||||
|                                     sound = dSound.getSound(soundType); | ||||
|  | ||||
|                                 if (sound == null) { | ||||
|                                     event.setCancelled(true); | ||||
|                                 } else { | ||||
| @@ -563,7 +564,7 @@ public class PacketsManager { | ||||
|                                         if (soundType == SoundType.HURT || soundType == SoundType.DEATH | ||||
|                                                 || soundType == SoundType.IDLE) { | ||||
|                                             // If the volume is the default | ||||
|                                             if (((Float) mods.read(4)).equals(entitySound.getDamageAndIdleSoundVolume())) { | ||||
|                                             if (mods.read(4).equals(entitySound.getDamageAndIdleSoundVolume())) { | ||||
|                                                 mods.write(4, dSound.getDamageAndIdleSoundVolume()); | ||||
|                                             } | ||||
|                                             // Here I assume its the default pitch as I can't calculate if its real. | ||||
| @@ -702,8 +703,7 @@ public class PacketsManager { | ||||
|                         if (packets == null) { | ||||
|                             packets = new PacketContainer[] { event.getPacket() }; | ||||
|                         } | ||||
|                         for (int i = 0; i < packets.length; i++) { | ||||
|                             PacketContainer packet = packets[i]; | ||||
|                         for (PacketContainer packet : packets) { | ||||
|                             if (packet.equals(event.getPacket())) { | ||||
|                                 packet = packet.deepClone(); | ||||
|                             } | ||||
| @@ -716,10 +716,7 @@ public class PacketsManager { | ||||
|                         } | ||||
|                         if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) { | ||||
|                             event.setPacket(event.getPacket().deepClone()); | ||||
|                             Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0) | ||||
|                                     .iterator(); | ||||
|                             while (itel.hasNext()) { | ||||
|                                 WrappedWatchableObject watch = itel.next(); | ||||
|                             for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) { | ||||
|                                 if (watch.getIndex() == 0) { | ||||
|                                     byte b = (Byte) watch.getValue(); | ||||
|                                     byte a = (byte) (b | 1 << 5); | ||||
| @@ -1231,7 +1228,7 @@ public class PacketsManager { | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_PAINTING) { | ||||
|                     packets = constructSpawnPackets(disguise, entity, observer); | ||||
|                     packets = constructSpawnPackets(disguise, entity); | ||||
|                 } | ||||
|  | ||||
|                 // Else if the disguise is attempting to send players a forbidden packet | ||||
|   | ||||
| @@ -151,8 +151,7 @@ public class ReflectionManager { | ||||
|  | ||||
|     public static Entity getBukkitEntity(Object nmsEntity) { | ||||
|         try { | ||||
|             Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity").invoke(nmsEntity); | ||||
|             return bukkitEntity; | ||||
|             return (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity").invoke(nmsEntity); | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
| @@ -385,7 +384,7 @@ public class ReflectionManager { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static void setBoundingBox(Entity entity, FakeBoundingBox newBox, float[] entitySize) { | ||||
|     public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) { | ||||
|         try { | ||||
|             Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity)); | ||||
|             int stage = 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user