From bb303ac96b6bf52b33e519739efb349a03c54a27 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 26 Nov 2016 01:07:02 +1300 Subject: [PATCH] Added new disguises, added new disguisetypes, fixed the horse/lama/whatever changes, fixed a boat 'facing' bug, renamed a few internal methods, still dont know why some disguises are invisible. --- pom.xml | 6 +- .../libraryaddict/disguise/DisguiseAPI.java | 264 +++---- .../libraryaddict/disguise/LibsDisguises.java | 133 ++-- .../commands/BaseDisguiseCommand.java | 671 ++++++------------ .../commands/HelpDisguiseCommand.java | 244 +++---- .../disguise/disguisetypes/Disguise.java | 398 ++++------- .../disguise/disguisetypes/DisguiseType.java | 114 ++- .../disguise/disguisetypes/FlagType.java | 104 +-- .../disguise/disguisetypes/FlagWatcher.java | 24 +- .../watchers/AgeableWatcher.java | 4 +- .../watchers/AreaEffectCloudWatcher.java | 16 +- .../watchers/ArmorStandWatcher.java | 10 +- .../disguisetypes/watchers/ArrowWatcher.java | 4 +- .../disguisetypes/watchers/BatWatcher.java | 4 +- .../disguisetypes/watchers/BlazeWatcher.java | 4 +- .../disguisetypes/watchers/BoatWatcher.java | 16 +- .../watchers/CreeperWatcher.java | 8 +- .../disguisetypes/watchers/DonkeyWatcher.java | 11 + .../watchers/DroppedItemWatcher.java | 4 +- .../watchers/EnderCrystalWatcher.java | 84 +-- .../watchers/EnderDragonWatcher.java | 4 +- .../watchers/EndermanWatcher.java | 8 +- .../disguisetypes/watchers/EvokerWatcher.java | 20 + .../watchers/FireworkWatcher.java | 6 +- .../watchers/FishingHookWatcher.java | 4 +- .../disguisetypes/watchers/GhastWatcher.java | 4 +- .../watchers/GuardianWatcher.java | 14 +- .../watchers/HorseAbstractWatcher.java | 101 +++ .../watchers/HorseChestedWatcher.java | 20 + .../disguisetypes/watchers/HorseWatcher.java | 196 +---- .../watchers/InsentientWatcher.java | 8 +- .../watchers/ItemFrameWatcher.java | 10 +- .../disguisetypes/watchers/LivingWatcher.java | 14 +- .../disguisetypes/watchers/LlamaWatcher.java | 42 ++ .../watchers/MinecartWatcher.java | 16 +- .../disguisetypes/watchers/MuleWatcher.java | 11 + .../disguisetypes/watchers/OcelotWatcher.java | 54 +- .../disguisetypes/watchers/PigWatcher.java | 48 +- .../disguisetypes/watchers/PlayerWatcher.java | 14 +- .../watchers/PolarBearWatcher.java | 4 +- .../disguisetypes/watchers/RabbitWatcher.java | 56 +- .../disguisetypes/watchers/SheepWatcher.java | 114 +-- .../watchers/ShulkerWatcher.java | 41 +- .../watchers/SkeletonHorseWatcher.java | 11 + .../watchers/SkeletonWatcher.java | 8 +- .../disguisetypes/watchers/SlimeWatcher.java | 4 +- .../watchers/SnowmanWatcher.java | 4 +- .../disguisetypes/watchers/SpiderWatcher.java | 4 +- .../watchers/SplashPotionWatcher.java | 4 +- .../watchers/TameableWatcher.java | 138 ++-- .../watchers/TippedArrowWatcher.java | 4 +- .../disguisetypes/watchers/VexWatcher.java | 21 + .../watchers/VillagerWatcher.java | 66 +- .../watchers/VindicatorWatcher.java | 17 + .../disguisetypes/watchers/WitchWatcher.java | 4 +- .../watchers/WitherSkullWatcher.java | 52 +- .../disguisetypes/watchers/WitherWatcher.java | 12 +- .../disguisetypes/watchers/WolfWatcher.java | 170 ++--- .../watchers/ZombieHorseWatcher.java | 11 + .../disguisetypes/watchers/ZombieWatcher.java | 20 +- .../disguise/utilities/DisguiseSound.java | 117 ++- .../disguise/utilities/PacketsManager.java | 472 +++++------- .../PacketListenerInventory.java | 199 ++---- 63 files changed, 1785 insertions(+), 2485 deletions(-) create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/DonkeyWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/EvokerWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/HorseAbstractWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/MuleWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonHorseWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/VexWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieHorseWatcher.java diff --git a/pom.xml b/pom.xml index 2aaf5e30..65eaeeea 100644 --- a/pom.xml +++ b/pom.xml @@ -37,17 +37,17 @@ com.comphenix.protocol ProtocolLib - 4.1.0-SNAPSHOT + 4.2.0-SNAPSHOT org.spigotmc spigot-api - 1.10-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT org.spigotmc spigot - 1.10-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index f320b363..892a326f 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -27,158 +27,126 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; +import me.libraryaddict.disguise.disguisetypes.watchers.HorseAbstractWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class DisguiseAPI -{ - public static Disguise constructDisguise(Entity entity) - { +public class DisguiseAPI { + public static Disguise constructDisguise(Entity entity) { return constructDisguise(entity, true, true, true); } - public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) - { + public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) { DisguiseType disguiseType = DisguiseType.getType(entity); Disguise disguise; - if (disguiseType.isMisc()) - { + if (disguiseType.isMisc()) { disguise = new MiscDisguise(disguiseType); } - else if (disguiseType.isMob()) - { + else if (disguiseType.isMob()) { disguise = new MobDisguise(disguiseType); } - else - { + else { disguise = new PlayerDisguise(entity.getName()); } FlagWatcher watcher = disguise.getWatcher(); - if (entity instanceof LivingEntity) - { - for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) - { + if (entity instanceof LivingEntity) { + for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) { ((LivingWatcher) watcher).addPotionEffect(effect.getType()); - if (effect.getType() == PotionEffectType.INVISIBILITY) - { + if (effect.getType() == PotionEffectType.INVISIBILITY) { watcher.setInvisible(true); } - else if (effect.getType() == PotionEffectType.GLOWING) - { + else if (effect.getType() == PotionEffectType.GLOWING) { watcher.setGlowing(true); } } } - if (entity.getFireTicks() > 0) - { + if (entity.getFireTicks() > 0) { watcher.setBurning(true); } - if (doEquipment && entity instanceof LivingEntity) - { + if (doEquipment && entity instanceof LivingEntity) { EntityEquipment equip = ((LivingEntity) entity).getEquipment(); watcher.setArmor(equip.getArmorContents()); watcher.setItemInMainHand(equip.getItemInMainHand()); - if (disguiseType.getEntityType() == EntityType.HORSE) - { + if (disguiseType.getEntityType() == EntityType.HORSE) { Horse horse = (Horse) entity; HorseInventory horseInventory = horse.getInventory(); ItemStack saddle = horseInventory.getSaddle(); - if (saddle != null && saddle.getType() == Material.SADDLE) - { - ((HorseWatcher) watcher).setSaddled(true); + if (saddle != null && saddle.getType() == Material.SADDLE) { + ((HorseAbstractWatcher) watcher).setSaddled(true); } - ((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor()); + if (watcher instanceof HorseWatcher) + ((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor()); } } - for (Method method : entity.getClass().getMethods()) - { + for (Method method : entity.getClass().getMethods()) { if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting")) - && method.getParameterTypes().length == 0 && method.getReturnType() != void.class) - { + && method.getParameterTypes().length == 0 && method.getReturnType() != void.class) { Class methodReturn = method.getReturnType(); - if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) - { + if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) { methodReturn = double.class; } int firstCapitalMethod = firstCapital(method.getName()); - if (firstCapitalMethod > 0) - { - for (Method watcherMethod : watcher.getClass().getMethods()) - { + if (firstCapitalMethod > 0) { + for (Method watcherMethod : watcher.getClass().getMethods()) { if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class - && watcherMethod.getParameterTypes().length == 1) - { + && watcherMethod.getParameterTypes().length == 1) { int firstCapitalWatcher = firstCapital(watcherMethod.getName()); if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod) - .equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) - { + .equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) { Class methodParam = watcherMethod.getParameterTypes()[0]; - if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) - { + if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) { methodParam = double.class; } - else if (methodParam == AnimalColor.class) - { + else if (methodParam == AnimalColor.class) { methodParam = DyeColor.class; } - if (methodReturn == methodParam) - { - try - { + if (methodReturn == methodParam) { + try { Object value = method.invoke(entity); - if (value != null) - { + if (value != null) { Class toCast = watcherMethod.getParameterTypes()[0]; - if (!(toCast.isInstance(value))) - { - if (toCast == float.class) - { - if (!(value instanceof Float)) - { + if (!(toCast.isInstance(value))) { + if (toCast == float.class) { + if (!(value instanceof Float)) { double d = (Double) value; value = (float) d; } } - else if (toCast == double.class) - { - if (!(value instanceof Double)) - { + else if (toCast == double.class) { + if (!(value instanceof Double)) { float d = (Float) value; value = (double) d; } } - else if (toCast == AnimalColor.class) - { + else if (toCast == AnimalColor.class) { value = AnimalColor.valueOf(((DyeColor) value).name()); } } if (value instanceof Boolean && !(Boolean) value - && watcherMethod.getDeclaringClass() == FlagWatcher.class) - { + && watcherMethod.getDeclaringClass() == FlagWatcher.class) { continue; } } watcherMethod.invoke(watcher, value); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -191,21 +159,17 @@ public class DisguiseAPI return disguise; } - public static void disguiseEntity(Entity entity, Disguise disguise) - { + public static void disguiseEntity(Entity entity, Disguise disguise) { // If they are trying to disguise a null entity or use a null disguise // Just return. - if (entity == null || disguise == null) - { + if (entity == null || disguise == null) { return; } // The event wasn't cancelled. // If the disguise entity isn't the same as the one we are disguising - if (disguise.getEntity() != entity) - { + if (disguise.getEntity() != entity) { // If the disguise entity actually exists - if (disguise.getEntity() != null) - { + if (disguise.getEntity() != null) { // Clone the disguise disguise = disguise.clone(); } @@ -213,31 +177,25 @@ public class DisguiseAPI disguise.setEntity(entity); } - if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) - { + if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) { disguise.setViewSelfDisguise(true); } disguise.startDisguise(); } - public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) - { - if (disguise.getEntity() != null) - { + public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) { + if (disguise.getEntity() != null) { disguise = disguise.clone(); } ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); - for (Object obj : playersToNotSeeDisguise) - { - if (obj instanceof String) - { + for (Object obj : playersToNotSeeDisguise) { + if (obj instanceof String) { ((TargetedDisguise) disguise).addPlayer((String) obj); } - else if (obj instanceof Player) - { + else if (obj instanceof Player) { ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); } } @@ -246,18 +204,15 @@ public class DisguiseAPI } @Deprecated - public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List playersToNotSeeDisguise) - { + public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List playersToNotSeeDisguise) { disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise); } - public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) - { + public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) { disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise)); } - public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) - { + public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) { disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise)); } @@ -267,27 +222,22 @@ public class DisguiseAPI * @param disguise * @return */ - public static int disguiseNextEntity(Disguise disguise) - { - if (disguise == null) - { + public static int disguiseNextEntity(Disguise disguise) { + if (disguise == null) { return -1; } - if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) - { + if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) { disguise = disguise.clone(); } - try - { + try { int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null); DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise); return id; } - catch (IllegalAccessException e) - { + catch (IllegalAccessException e) { e.printStackTrace(); } @@ -300,40 +250,32 @@ public class DisguiseAPI * @param entity * @param disguise */ - public static void disguiseToAll(Entity entity, Disguise disguise) - { - if (disguise.getEntity() != null) - { + public static void disguiseToAll(Entity entity, Disguise disguise) { + if (disguise.getEntity() != null) { disguise = disguise.clone(); } // You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!! ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); - for (String observer : ((TargetedDisguise) disguise).getObservers()) - { + for (String observer : ((TargetedDisguise) disguise).getObservers()) { ((TargetedDisguise) disguise).removePlayer(observer); } disguiseEntity(entity, disguise); } - public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) - { - if (disguise.getEntity() != null) - { + public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) { + if (disguise.getEntity() != null) { disguise = disguise.clone(); } ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); - for (Object obj : playersToViewDisguise) - { - if (obj instanceof String) - { + for (Object obj : playersToViewDisguise) { + if (obj instanceof String) { ((TargetedDisguise) disguise).addPlayer((String) obj); } - else if (obj instanceof Player) - { + else if (obj instanceof Player) { ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); } } @@ -342,27 +284,21 @@ public class DisguiseAPI } @Deprecated - public static void disguiseToPlayers(Entity entity, Disguise disguise, List playersToViewDisguise) - { + public static void disguiseToPlayers(Entity entity, Disguise disguise, List playersToViewDisguise) { disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise); } - public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) - { + public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) { disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise)); } - public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) - { + public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) { disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise)); } - private static int firstCapital(String str) - { - for (int i = 0; i < str.length(); i++) - { - if (Character.isUpperCase(str.charAt(i))) - { + private static int firstCapital(String str) { + for (int i = 0; i < str.length(); i++) { + if (Character.isUpperCase(str.charAt(i))) { return i; } } @@ -376,10 +312,8 @@ public class DisguiseAPI * @param disguised * @return */ - public static Disguise getDisguise(Entity disguised) - { - if (disguised == null) - { + public static Disguise getDisguise(Entity disguised) { + if (disguised == null) { return null; } @@ -393,10 +327,8 @@ public class DisguiseAPI * @param disguised * @return */ - public static Disguise getDisguise(Player observer, Entity disguised) - { - if (disguised == null || observer == null) - { + public static Disguise getDisguise(Player observer, Entity disguised) { + if (disguised == null || observer == null) { return null; } @@ -409,18 +341,15 @@ public class DisguiseAPI * @param disguised * @return */ - public static Disguise[] getDisguises(Entity disguised) - { - if (disguised == null) - { + public static Disguise[] getDisguises(Entity disguised) { + if (disguised == null) { return null; } return DisguiseUtilities.getDisguises(disguised.getUniqueId()); } - public static int getSelfDisguiseId() - { + public static int getSelfDisguiseId() { return -10; } @@ -430,8 +359,7 @@ public class DisguiseAPI * @param disguised * @return */ - public static boolean isDisguised(Entity disguised) - { + public static boolean isDisguised(Entity disguised) { return getDisguise(disguised) != null; } @@ -442,18 +370,15 @@ public class DisguiseAPI * @param disguised * @return */ - public static boolean isDisguised(Player observer, Entity disguised) - { + public static boolean isDisguised(Player observer, Entity disguised) { return getDisguise(observer, disguised) != null; } - public static boolean isDisguiseInUse(Disguise disguise) - { + public static boolean isDisguiseInUse(Disguise disguise) { return disguise.isDisguiseInUse(); } - public static boolean isSelfDisguised(Player player) - { + public static boolean isSelfDisguised(Player player) { return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId()); } @@ -463,8 +388,7 @@ public class DisguiseAPI * @param entity * @return */ - public static boolean isViewSelfToggled(Entity entity) - { + public static boolean isViewSelfToggled(Entity entity) { return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() : Disguise.getViewSelf().contains(entity.getUniqueId()); } @@ -475,12 +399,10 @@ public class DisguiseAPI * * @param entity */ - public static void undisguiseToAll(Entity entity) - { + public static void undisguiseToAll(Entity entity) { Disguise[] disguises = getDisguises(entity); - for (Disguise disguise : disguises) - { + for (Disguise disguise : disguises) { disguise.removeDisguise(); } } @@ -491,28 +413,22 @@ public class DisguiseAPI * @param entity * @param toggled */ - public static void setViewDisguiseToggled(Entity entity, boolean toggled) - { - if (isDisguised(entity)) - { + public static void setViewDisguiseToggled(Entity entity, boolean toggled) { + if (isDisguised(entity)) { Disguise disguise = getDisguise(entity); disguise.setViewSelfDisguise(toggled); } - if (toggled) - { - if (!Disguise.getViewSelf().contains(entity.getUniqueId())) - { + if (toggled) { + if (!Disguise.getViewSelf().contains(entity.getUniqueId())) { Disguise.getViewSelf().add(entity.getUniqueId()); } } - else - { + else { Disguise.getViewSelf().remove(entity.getUniqueId()); } } - private DisguiseAPI() - { + private DisguiseAPI() { } } diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 55a364c3..81780e35 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -36,7 +36,6 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher; @@ -54,32 +53,26 @@ import me.libraryaddict.disguise.utilities.Metrics; import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class LibsDisguises extends JavaPlugin -{ +public class LibsDisguises extends JavaPlugin { private static LibsDisguises instance; private DisguiseListener listener; @Override - public void onEnable() - { - try - { + public void onEnable() { + try { Class.forName("com.comphenix.protocol.wrappers.Vector3F").getName(); } - catch (Exception ex) - { + catch (Exception ex) { System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated ProtocolLib!"); System.err.println( "[LibsDisguises] You need to update ProtocolLib, please try this build http://ci.dmulloy2.net/job/ProtocolLib/lastStableBuild/artifact/modules/ProtocolLib/target/ProtocolLib.jar"); return; } - try - { + try { ReflectionManager.getNmsClass("EntityShulker").getName(); } - catch (Exception ex) - { + catch (Exception ex) { System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!"); System.err.println("[LibsDisguises] This plugin does not offer backwards support!"); return; @@ -117,21 +110,18 @@ public class LibsDisguises extends JavaPlugin instance = this; - try - { + try { Metrics metrics = new Metrics(this); metrics.start(); } - catch (IOException e) - { + catch (IOException e) { } } /** * Reloads the config with new config options. */ - public void reload() - { + public void reload() { HandlerList.unregisterAll(listener); reloadConfig(); @@ -142,21 +132,16 @@ public class LibsDisguises extends JavaPlugin * Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume * for mob noises. As well as setting their watcher class and entity size. */ - private void registerValues() - { - for (DisguiseType disguiseType : DisguiseType.values()) - { - if (disguiseType.getEntityType() == null) - { + private void registerValues() { + for (DisguiseType disguiseType : DisguiseType.values()) { + if (disguiseType.getEntityType() == null) { continue; } Class watcherClass = null; - try - { - switch (disguiseType) - { + try { + switch (disguiseType) { case SPECTRAL_ARROW: watcherClass = ArrowWatcher.class; break; @@ -175,12 +160,6 @@ public class LibsDisguises extends JavaPlugin case CAVE_SPIDER: watcherClass = SpiderWatcher.class; break; - case DONKEY: - case MULE: - case UNDEAD_HORSE: - case SKELETON_HORSE: - watcherClass = HorseWatcher.class; - break; case ZOMBIE_VILLAGER: case PIG_ZOMBIE: case HUSK: @@ -202,57 +181,46 @@ public class LibsDisguises extends JavaPlugin break; } } - catch (ClassNotFoundException ex) - { + catch (ClassNotFoundException ex) { // There is no explicit watcher for this entity. Class entityClass = disguiseType.getEntityType().getEntityClass(); - if (entityClass != null) - { - if (Tameable.class.isAssignableFrom(entityClass)) - { + if (entityClass != null) { + if (Tameable.class.isAssignableFrom(entityClass)) { watcherClass = TameableWatcher.class; } - else if (Ageable.class.isAssignableFrom(entityClass)) - { + else if (Ageable.class.isAssignableFrom(entityClass)) { watcherClass = AgeableWatcher.class; } - else if (Creature.class.isAssignableFrom(entityClass)) - { + else if (Creature.class.isAssignableFrom(entityClass)) { watcherClass = InsentientWatcher.class; } - else if (LivingEntity.class.isAssignableFrom(entityClass)) - { + else if (LivingEntity.class.isAssignableFrom(entityClass)) { watcherClass = LivingWatcher.class; } - else - { + else { watcherClass = FlagWatcher.class; } } - else - { + else { watcherClass = FlagWatcher.class; // Disguise is unknown type } } - if (watcherClass == null) - { + if (watcherClass == null) { System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned"); continue; } disguiseType.setWatcherClass(watcherClass); - if (DisguiseValues.getDisguiseValues(disguiseType) != null) - { + if (DisguiseValues.getDisguiseValues(disguiseType) != null) { continue; } String nmsEntityName = toReadable(disguiseType.name()); - switch (disguiseType) - { + switch (disguiseType) { case WITHER_SKELETON: case ZOMBIE_VILLAGER: case DONKEY: @@ -299,18 +267,15 @@ public class LibsDisguises extends JavaPlugin break; } - try - { - if (nmsEntityName.equalsIgnoreCase("Unknown")) - { + try { + if (nmsEntityName.equalsIgnoreCase("Unknown")) { DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); - if (sound != null) - { + if (sound != null) { sound.setDamageAndIdleSoundVolume(1f); } @@ -319,8 +284,7 @@ public class LibsDisguises extends JavaPlugin Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); - if (nmsEntity == null) - { + if (nmsEntity == null) { getLogger().warning("Entity not found! (" + nmsEntityName + ")"); continue; @@ -329,10 +293,8 @@ public class LibsDisguises extends JavaPlugin Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); int entitySize = 0; - for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) - { - if (field.getType().getName().equals("EnumEntitySize")) - { + for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { + if (field.getType().getName().equals("EnumEntitySize")) { Enum enumEntitySize = (Enum) field.get(nmsEntity); entitySize = enumEntitySize.ordinal(); @@ -346,12 +308,10 @@ public class LibsDisguises extends JavaPlugin WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); - for (WrappedWatchableObject watch : watcher.getWatchableObjects()) - { + for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex()); - if (flagType == null) - { + if (flagType == null) { System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex() + " can't be found!"); System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" @@ -363,12 +323,10 @@ public class LibsDisguises extends JavaPlugin DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); - if (sound != null) - { + if (sound != null) { Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); - if (soundStrength != null) - { + if (soundStrength != null) { sound.setDamageAndIdleSoundVolume(soundStrength); } } @@ -376,14 +334,12 @@ public class LibsDisguises extends JavaPlugin // Get the bounding box disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity)); - if (bukkitEntity instanceof Ageable) - { + if (bukkitEntity instanceof Ageable) { ((Ageable) bukkitEntity).setBaby(); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); } - else if (bukkitEntity instanceof Zombie) - { + else if (bukkitEntity instanceof Zombie) { ((Zombie) bukkitEntity).setBaby(true); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); @@ -391,8 +347,7 @@ public class LibsDisguises extends JavaPlugin disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity)); } - catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) - { + catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) { System.out.print( "[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!"); System.out.print("[LibsDisguises] Before reporting this error, " @@ -405,20 +360,17 @@ public class LibsDisguises extends JavaPlugin } } - private String toReadable(String string) - { + private String toReadable(String string) { StringBuilder builder = new StringBuilder(); - for (String s : string.split("_")) - { + for (String s : string.split("_")) { builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase()); } return builder.toString(); } - public DisguiseListener getListener() - { + public DisguiseListener getListener() { return listener; } @@ -427,8 +379,7 @@ public class LibsDisguises extends JavaPlugin * * @return The instance of this plugin */ - public static LibsDisguises getInstance() - { + public static LibsDisguises getInstance() { return instance; } } diff --git a/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java index cdc06b16..556b6b31 100644 --- a/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java @@ -18,6 +18,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Ageable; import org.bukkit.entity.Animals; +import org.bukkit.entity.Llama; import org.bukkit.entity.Monster; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; @@ -41,29 +42,23 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; /** * @author libraryaddict */ -public abstract class BaseDisguiseCommand implements CommandExecutor -{ - public class DisguiseParseException extends Exception - { +public abstract class BaseDisguiseCommand implements CommandExecutor { + public class DisguiseParseException extends Exception { private static final long serialVersionUID = 1276971370793124510L; - public DisguiseParseException() - { + public DisguiseParseException() { super(); } - public DisguiseParseException(String string) - { + public DisguiseParseException(String string) { super(string); } } - protected ArrayList getAllowedDisguises(HashMap, Boolean>> hashMap) - { + protected ArrayList getAllowedDisguises(HashMap, Boolean>> hashMap) { ArrayList allowedDisguises = new ArrayList<>(); - for (DisguiseType type : hashMap.keySet()) - { + for (DisguiseType type : hashMap.keySet()) { allowedDisguises.add(type.toReadable().replace(" ", "_")); } @@ -72,15 +67,12 @@ public abstract class BaseDisguiseCommand implements CommandExecutor return allowedDisguises; } - protected HashMap, Boolean>> getPermissions(CommandSender sender) - { + protected HashMap, Boolean>> getPermissions(CommandSender sender) { return getPermissions(sender, "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + "."); } - protected HashMap getDisguiseOptions(CommandSender sender, DisguiseType type) - { - switch (type) - { + protected HashMap getDisguiseOptions(CommandSender sender, DisguiseType type) { + switch (type) { case PLAYER: case FALLING_BLOCK: case PAINTING: @@ -91,20 +83,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor String beginning = "libsdisguises.options." + getClass().getSimpleName().toLowerCase().replace("command", "") + "."; - for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) - { + for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String lowerPerm = permission.getPermission().toLowerCase(); - if (lowerPerm.startsWith(beginning)) - { + if (lowerPerm.startsWith(beginning)) { String[] split = lowerPerm.substring(beginning.length()).split("\\."); - if (split.length > 1) - { - if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) - { - for (int i = 1; i < split.length; i++) - { + if (split.length > 1) { + if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) { + for (int i = 1; i < split.length; i++) { returns.put(split[i], permission.getValue()); } } @@ -118,24 +105,19 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } } - protected Method[] getDisguiseWatcherMethods(Class watcherClass) - { + protected Method[] getDisguiseWatcherMethods(Class watcherClass) { Method[] methods = watcherClass.getMethods(); methods = Arrays.copyOf(methods, methods.length + 4); int i = 4; - for (String methodName : new String[] - { - "setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise" - }) - { - try - { + for (String methodName : new String[] { + "setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise" + }) { + try { methods[methods.length - i--] = Disguise.class.getMethod(methodName, boolean.class); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } @@ -151,60 +133,48 @@ public abstract class BaseDisguiseCommand implements CommandExecutor * @return */ protected HashMap, Boolean>> getPermissions(CommandSender sender, - String permissionNode) - { + String permissionNode) { HashMap, Boolean>> singleDisguises = new HashMap<>(); HashMap, Boolean>> rangeDisguises = new HashMap<>(); HashMap perms = new HashMap<>(); - for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) - { + for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String perm = permission.getPermission().toLowerCase(); - if (perm.startsWith(permissionNode) && (!perms.containsKey(perm) || !permission.getValue())) - { + if (perm.startsWith(permissionNode) && (!perms.containsKey(perm) || !permission.getValue())) { perms.put(perm, permission.getValue()); } } - if (!perms.containsKey(permissionNode + "*") && sender.hasPermission(permissionNode + "*")) - { + if (!perms.containsKey(permissionNode + "*") && sender.hasPermission(permissionNode + "*")) { perms.put(permissionNode + "*", true); } - if (!perms.containsKey(permissionNode + "*.*") && sender.hasPermission(permissionNode + "*.*")) - { + if (!perms.containsKey(permissionNode + "*.*") && sender.hasPermission(permissionNode + "*.*")) { perms.put(permissionNode + "*.*", true); } - for (String perm : perms.keySet()) - { - if (perms.get(perm)) - { + for (String perm : perms.keySet()) { + if (perms.get(perm)) { perm = perm.substring(permissionNode.length()); String disguiseType = perm.split("\\.")[0]; DisguiseType dType = null; - for (DisguiseType t : DisguiseType.values()) - { - if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) - { + for (DisguiseType t : DisguiseType.values()) { + if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) { dType = t; break; } } - if (dType != null) - { + if (dType != null) { HashMap, Boolean> list; - if (singleDisguises.containsKey(dType)) - { + if (singleDisguises.containsKey(dType)) { list = singleDisguises.get(dType); } - else - { + else { list = new HashMap<>(); singleDisguises.put(dType, list); } @@ -212,63 +182,47 @@ public abstract class BaseDisguiseCommand implements CommandExecutor HashMap, Boolean> map1 = getOptions(perm); list.put(map1.keySet().iterator().next(), map1.values().iterator().next()); } - else - { - for (DisguiseType type : DisguiseType.values()) - { + else { + for (DisguiseType type : DisguiseType.values()) { HashMap, Boolean> options = null; Class entityClass = type.getEntityClass(); - if (disguiseType.equals("mob")) - { - if (type.isMob()) - { + if (disguiseType.equals("mob")) { + if (type.isMob()) { options = getOptions(perm); } } - else if (disguiseType.equals("animal") || disguiseType.equals("animals")) - { - if (Animals.class.isAssignableFrom(entityClass)) - { + else if (disguiseType.equals("animal") || disguiseType.equals("animals")) { + if (Animals.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } - else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) - { - if (Monster.class.isAssignableFrom(entityClass)) - { + else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) { + if (Monster.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } - else if (disguiseType.equals("misc")) - { - if (type.isMisc()) - { + else if (disguiseType.equals("misc")) { + if (type.isMisc()) { options = getOptions(perm); } } - else if (disguiseType.equals("ageable")) - { - if (Ageable.class.isAssignableFrom(entityClass)) - { + else if (disguiseType.equals("ageable")) { + if (Ageable.class.isAssignableFrom(entityClass)) { options = getOptions(perm); } } - else if (disguiseType.equals("*")) - { + else if (disguiseType.equals("*")) { options = getOptions(perm); } - if (options != null) - { + if (options != null) { HashMap, Boolean> list; - if (rangeDisguises.containsKey(type)) - { + if (rangeDisguises.containsKey(type)) { list = rangeDisguises.get(type); } - else - { + else { list = new HashMap<>(); rangeDisguises.put(type, list); } @@ -282,70 +236,57 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } } - for (String perm : perms.keySet()) - { - if (!perms.get(perm)) - { + for (String perm : perms.keySet()) { + if (!perms.get(perm)) { perm = perm.substring(permissionNode.length()); String disguiseType = perm.split("\\.")[0]; DisguiseType dType = null; - for (DisguiseType t : DisguiseType.values()) - { - if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) - { + for (DisguiseType t : DisguiseType.values()) { + if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) { dType = t; break; } } - if (dType != null) - { + if (dType != null) { singleDisguises.remove(dType); rangeDisguises.remove(dType); } - else - { - for (DisguiseType type : DisguiseType.values()) - { + else { + for (DisguiseType type : DisguiseType.values()) { boolean foundHim = false; Class entityClass = type.getEntityClass(); - switch (disguiseType) - { + switch (disguiseType) { case "mob": - if (type.isMob()) - { + if (type.isMob()) { foundHim = true; } break; case "animal": case "animals": - if (Animals.class.isAssignableFrom(entityClass)) - { + if (Animals.class.isAssignableFrom(entityClass)) { foundHim = true; } break; case "monster": case "monsters": - if (Monster.class.isAssignableFrom(entityClass)) - { + if (Monster.class.isAssignableFrom(entityClass)) { foundHim = true; } break; case "misc": - if (type.isMisc()) - { + if (type.isMisc()) { foundHim = true; } break; case "ageable": - if (Ageable.class.isAssignableFrom(entityClass)) - { + if (Ageable.class.isAssignableFrom(entityClass)) { foundHim = true; } @@ -355,8 +296,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor break; } - if (foundHim) - { + if (foundHim) { rangeDisguises.remove(type); } } @@ -366,22 +306,18 @@ public abstract class BaseDisguiseCommand implements CommandExecutor HashMap, Boolean>> map = new HashMap<>(); - for (DisguiseType type : DisguiseType.values()) - { + for (DisguiseType type : DisguiseType.values()) { HashMap, Boolean> temp = new HashMap<>(); - if (singleDisguises.containsKey(type)) - { + if (singleDisguises.containsKey(type)) { temp.putAll(singleDisguises.get(type)); } - if (rangeDisguises.containsKey(type)) - { + if (rangeDisguises.containsKey(type)) { temp.putAll(rangeDisguises.get(type)); } - if (!temp.isEmpty()) - { + if (!temp.isEmpty()) { map.put(type, temp); } } @@ -389,22 +325,18 @@ public abstract class BaseDisguiseCommand implements CommandExecutor return map; } - private HashMap, Boolean> getOptions(String perm) - { + private HashMap, Boolean> getOptions(String perm) { ArrayList list = new ArrayList<>(); boolean isRemove = true; String[] split = perm.split("\\."); - for (int i = 1; i < split.length; i++) - { + for (int i = 1; i < split.length; i++) { String option = split[i]; boolean value = option.startsWith("-"); - if (value) - { + if (value) { option = option.substring(1); isRemove = false; } - if (option.equals("baby")) - { + if (option.equals("baby")) { option = "setbaby"; } list.add(option); @@ -416,28 +348,22 @@ public abstract class BaseDisguiseCommand implements CommandExecutor return options; } - protected boolean isDouble(String string) - { - try - { + protected boolean isDouble(String string) { + try { Float.parseFloat(string); return true; } - catch (Exception ex) - { + catch (Exception ex) { return false; } } - protected boolean isNumeric(String string) - { - try - { + protected boolean isNumeric(String string) { + try { Integer.parseInt(string); return true; } - catch (Exception ex) - { + catch (Exception ex) { return false; } } @@ -457,14 +383,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor */ protected Disguise parseDisguise(CommandSender sender, String[] args, HashMap, Boolean>> map) - throws DisguiseParseException, IllegalAccessException, InvocationTargetException - { - if (map.isEmpty()) - { + throws DisguiseParseException, IllegalAccessException, InvocationTargetException { + if (map.isEmpty()) { throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command."); } - if (args.length == 0) - { + if (args.length == 0) { sendCommandUsage(sender, map); throw new DisguiseParseException(); } @@ -477,61 +400,48 @@ public abstract class BaseDisguiseCommand implements CommandExecutor Disguise disguise = null; HashMap, Boolean> optionPermissions; - if (args[0].startsWith("@")) - { - if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) - { + if (args[0].startsWith("@")) { + if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase()); - if (disguise == null) - { + if (disguise == null) { throw new DisguiseParseException(ChatColor.RED + "Cannot find a disguise under the reference " + args[0]); } } - else - { + else { throw new DisguiseParseException(ChatColor.RED + "You do not have perimssion to use disguise references!"); } optionPermissions = (map.containsKey(disguise.getType()) ? map.get(disguise.getType()) : new HashMap, Boolean>()); } - else - { + else { DisguiseType disguiseType = null; - if (args[0].equalsIgnoreCase("p")) - { + if (args[0].equalsIgnoreCase("p")) { disguiseType = DisguiseType.PLAYER; } - else - { - for (DisguiseType type : DisguiseType.values()) - { - if (args[0].equalsIgnoreCase(type.name()) || args[0].equalsIgnoreCase(type.name().replace("_", ""))) - { + else { + for (DisguiseType type : DisguiseType.values()) { + if (args[0].equalsIgnoreCase(type.name()) || args[0].equalsIgnoreCase(type.name().replace("_", ""))) { disguiseType = type; break; } } } - if (disguiseType == null) - { + if (disguiseType == null) { throw new DisguiseParseException( ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED + " doesn't exist!"); } - if (disguiseType.isUnknown()) - { + if (disguiseType.isUnknown()) { throw new DisguiseParseException(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"); } - if (disguiseType.getEntityType() == null) - { + if (disguiseType.getEntityType() == null) { throw new DisguiseParseException(ChatColor.RED + "Error! This version of minecraft does not have that disguise!"); } - if (!map.containsKey(disguiseType)) - { + if (!map.containsKey(disguiseType)) { throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this disguise."); } @@ -539,19 +449,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor HashMap disguiseOptions = this.getDisguiseOptions(sender, disguiseType); - if (disguiseType.isPlayer()) - { + if (disguiseType.isPlayer()) { // If he is doing a player disguise - if (args.length == 1) - { + if (args.length == 1) { // He needs to give the player name throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!"); } - else - { + else { if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey(args[1].toLowerCase()) - || !disguiseOptions.get(args[1].toLowerCase()))) - { + || !disguiseOptions.get(args[1].toLowerCase()))) { throw new DisguiseParseException(ChatColor.RED + "Error! You don't have permission to use that name!"); } @@ -562,16 +468,12 @@ public abstract class BaseDisguiseCommand implements CommandExecutor toSkip++; } } - else - { - if (disguiseType.isMob()) - { // Its a mob, use the mob constructor + else { + if (disguiseType.isMob()) { // Its a mob, use the mob constructor boolean adult = true; - if (args.length > 1) - { - if (args[1].equalsIgnoreCase("baby") || args[1].equalsIgnoreCase("adult")) - { + if (args.length > 1) { + if (args[1].equalsIgnoreCase("baby") || args[1].equalsIgnoreCase("adult")) { usedOptions.add("setbaby"); doCheck(optionPermissions, usedOptions); adult = args[1].equalsIgnoreCase("adult"); @@ -581,47 +483,36 @@ public abstract class BaseDisguiseCommand implements CommandExecutor disguise = new MobDisguise(disguiseType, adult); } - else if (disguiseType.isMisc()) - { + else if (disguiseType.isMisc()) { // Its a misc, we are going to use the MiscDisguise constructor. int miscId = -1; int miscData = -1; String secondArg = null; - if (args.length > 1) - { + if (args.length > 1) { // They have defined more arguments! // If the first arg is a number - if (args[1].contains(":")) - { + if (args[1].contains(":")) { String[] split = args[1].split(":"); - if (isNumeric(split[1])) - { + if (isNumeric(split[1])) { secondArg = split[1]; } args[1] = split[0]; } - if (isNumeric(args[1])) - { + if (isNumeric(args[1])) { miscId = Integer.parseInt(args[1]); } - else - { - if (disguiseType == DisguiseType.FALLING_BLOCK || disguiseType == DisguiseType.DROPPED_ITEM) - { - for (Material mat : Material.values()) - { - if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) - { + else { + if (disguiseType == DisguiseType.FALLING_BLOCK || disguiseType == DisguiseType.DROPPED_ITEM) { + for (Material mat : Material.values()) { + if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) { miscId = mat.getId(); break; } } } } - if (miscId != -1) - { - switch (disguiseType) - { + if (miscId != -1) { + switch (disguiseType) { case PAINTING: case FALLING_BLOCK: case SPLASH_POTION: @@ -640,15 +531,12 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } toSkip++; // If they also defined a data value - if (args.length > 2 && secondArg == null && isNumeric(args[2])) - { + if (args.length > 2 && secondArg == null && isNumeric(args[2])) { secondArg = args[2]; toSkip++; } - if (secondArg != null) - { - if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) - { + if (secondArg != null) { + if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) { throw new DisguiseParseException(ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"); @@ -657,43 +545,34 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } } } - if (!disguiseOptions.isEmpty() && miscId != -1) - { + if (!disguiseOptions.isEmpty() && miscId != -1) { String toCheck = "" + miscId; - if (miscData == 0 || miscData == -1) - { - if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) - { + if (miscData == 0 || miscData == -1) { + if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { toCheck += ":0"; } } - else - { + else { toCheck += ":" + miscData; } - if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) - { + if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { throw new DisguiseParseException( ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck + " on the " + disguiseType.toReadable() + " disguise!"); } } - if (miscId != -1) - { - if (disguiseType == DisguiseType.FALLING_BLOCK) - { + if (miscId != -1) { + if (disguiseType == DisguiseType.FALLING_BLOCK) { usedOptions.add("setblock"); doCheck(optionPermissions, usedOptions); } - else if (disguiseType == DisguiseType.PAINTING) - { + else if (disguiseType == DisguiseType.PAINTING) { usedOptions.add("setpainting"); doCheck(optionPermissions, usedOptions); } - else if (disguiseType == DisguiseType.SPLASH_POTION) - { + else if (disguiseType == DisguiseType.SPLASH_POTION) { usedOptions.add("setpotionid"); doCheck(optionPermissions, usedOptions); } @@ -710,8 +589,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor Method[] methods = this.getDisguiseWatcherMethods(disguise.getWatcher().getClass()); - for (int i = 0; i < args.length; i += 2) - { + for (int i = 0; i < args.length; i += 2) { String methodName = args[i]; String valueString = (args.length - 1 == i ? null : args[i + 1]); Method methodToUse = null; @@ -719,14 +597,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor DisguiseParseException storedEx = null; int c = 0; - while (c < methods.length) - { - try - { + while (c < methods.length) { + try { Entry entry = getMethod(methods, methodName, c); - if (entry == null) - { + if (entry == null) { break; } @@ -736,30 +611,23 @@ public abstract class BaseDisguiseCommand implements CommandExecutor Class[] types = methodToUse.getParameterTypes(); Class param = types[0]; - if (valueString != null) - { - if (int.class == param) - { + if (valueString != null) { + if (int.class == param) { // Parse to integer - if (isNumeric(valueString)) - { + if (isNumeric(valueString)) { value = Integer.parseInt(valueString); } - else - { + else { throw parseToException("number", valueString, methodName); } } - else if (WrappedGameProfile.class == param && valueString.length() > 20) - { - try - { + else if (WrappedGameProfile.class == param && valueString.length() > 20) { + try { Map response = new Gson().fromJson(valueString, Map.class); String id = (String) response.get("id"); - if (!id.contains("-")) - { + if (!id.contains("-")) { id = Pattern .compile( "([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)") @@ -769,12 +637,10 @@ public abstract class BaseDisguiseCommand implements CommandExecutor WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.fromString(id), (String) response.get("name")); - if (response.containsKey("properties")) - { + if (response.containsKey("properties")) { ArrayList> properties = (ArrayList) response.get("properties"); - for (Map s : properties) - { + for (Map s : properties) { String gName = null; String gValue = null; String gSigned = null; @@ -794,206 +660,169 @@ public abstract class BaseDisguiseCommand implements CommandExecutor value = gameProfile; } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("gameprofile", valueString, methodName); } } - else if (float.class == param || double.class == param) - { + else if (float.class == param || double.class == param) { // Parse to number - if (isDouble(valueString)) - { + if (isDouble(valueString)) { float obj = Float.parseFloat(valueString); - if (param == float.class) - { + if (param == float.class) { value = obj; } - else if (param == double.class) - { + else if (param == double.class) { value = (double) obj; } } - else - { + else { throw parseToException("number.0", valueString, methodName); } } - else if (param == String.class) - { + else if (param == String.class) { if (methodName.equalsIgnoreCase("setskin") && valueString.length() > 20) continue; // Parse to string value = ChatColor.translateAlternateColorCodes('&', valueString); } - else if (param == AnimalColor.class) - { + else if (param == AnimalColor.class) { // Parse to animal color - try - { + try { value = AnimalColor.valueOf(valueString.toUpperCase()); } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("animal color", valueString, methodName); } } - else if (param == ItemStack.class) - { + else if (param == Llama.Color.class) { + try { + value = Llama.Color.valueOf(valueString.toUpperCase()); + } + catch (Exception ex) { + throw parseToException("llama color", valueString, methodName); + } + } + else if (param == ItemStack.class) { // Parse to itemstack - try - { + try { value = parseToItemstack(valueString); } - catch (Exception ex) - { + catch (Exception ex) { throw new DisguiseParseException(String.format(ex.getMessage(), methodName)); } } - else if (param == ItemStack[].class) - { + else if (param == ItemStack[].class) { // Parse to itemstack array ItemStack[] items = new ItemStack[4]; String[] split = valueString.split(","); - if (split.length == 4) - { - for (int a = 0; a < 4; a++) - { - try - { + if (split.length == 4) { + for (int a = 0; a < 4; a++) { + try { items[a] = parseToItemstack(split[a]); } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); } } } - else - { + else { throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName); } value = items; } - else if (param.getSimpleName().equals("Color")) - { + else if (param.getSimpleName().equals("Color")) { // Parse to horse color value = callValueOf(param, valueString, methodName, "a horse color"); } - else if (param.getSimpleName().equals("Style")) - { + else if (param.getSimpleName().equals("Style")) { // Parse to horse style value = callValueOf(param, valueString, methodName, "a horse style"); } - else if (param.getSimpleName().equals("Profession")) - { + else if (param.getSimpleName().equals("Profession")) { // Parse to villager profession value = callValueOf(param, valueString, methodName, "a villager profession"); } - else if (param.getSimpleName().equals("Art")) - { + else if (param.getSimpleName().equals("Art")) { // Parse to art type value = callValueOf(param, valueString, methodName, "a painting art"); } - else if (param.getSimpleName().equals("Type")) - { + else if (param.getSimpleName().equals("Type")) { // Parse to ocelot type value = callValueOf(param, valueString, methodName, "a ocelot type"); } - else if (param == PotionEffectType.class) - { + else if (param == PotionEffectType.class) { // Parse to potion effect - try - { + try { PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase()); - if (potionType == null && isNumeric(valueString)) - { + if (potionType == null && isNumeric(valueString)) { potionType = PotionEffectType.getById(Integer.parseInt(valueString)); } - if (potionType == null) - { + if (potionType == null) { throw new DisguiseParseException(); } value = potionType; } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("a potioneffect type", valueString, methodName); } } - else if (param == int[].class) - { + else if (param == int[].class) { String[] split = valueString.split(","); int[] values = new int[split.length]; - for (int b = 0; b < values.length; b++) - { - try - { + for (int b = 0; b < values.length; b++) { + try { values[b] = Integer.parseInt(split[b]); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex) { throw parseToException("Number,Number,Number...", valueString, methodName); } } value = values; } - else if (param == BlockFace.class) - { - try - { + else if (param == BlockFace.class) { + try { BlockFace face = BlockFace.valueOf(valueString.toUpperCase()); - if (face.ordinal() > 5) - { + if (face.ordinal() > 5) { throw new DisguiseParseException(); } value = face; } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("a direction (north, east, south, west, up, down)", valueString, methodName); } } - else if (param == RabbitType.class) - { - try - { - for (RabbitType type : RabbitType.values()) - { + else if (param == RabbitType.class) { + try { + for (RabbitType type : RabbitType.values()) { if (type.name().replace("_", "") - .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) - { + .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) { value = type; break; } } - if (value == null) - { + if (value == null) { throw new Exception(); } } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException("rabbit type (white, brown, patches...)", valueString, methodName); } } - else if (param == BlockPosition.class) - { - try - { + else if (param == BlockPosition.class) { + try { String[] split = valueString.split(","); assert split.length == 3; @@ -1001,86 +830,68 @@ public abstract class BaseDisguiseCommand implements CommandExecutor value = new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); } - catch (Exception ex) - { - throw parseToException("three numbers Number,Number,Number", valueString, - methodName); + catch (Exception ex) { + throw parseToException("three numbers Number,Number,Number", valueString, methodName); } } } - if (value == null && boolean.class == param) - { - if (valueString == null) - { + if (value == null && boolean.class == param) { + if (valueString == null) { value = true; i--; } - else if (valueString.equalsIgnoreCase("true")) - { + else if (valueString.equalsIgnoreCase("true")) { value = true; } - else if (valueString.equalsIgnoreCase("false")) - { + else if (valueString.equalsIgnoreCase("false")) { value = false; } - else - { - if (getMethod(methods, valueString, 0) == null) - { + else { + if (getMethod(methods, valueString, 0) == null) { throw parseToException("true/false", valueString, methodName); } - else - { + else { value = true; i--; } } } - if (value != null) - { + if (value != null) { break; } } - catch (DisguiseParseException ex) - { + catch (DisguiseParseException ex) { storedEx = ex; methodToUse = null; } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); methodToUse = null; } } - if (methodToUse == null) - { - if (storedEx != null) - { + if (methodToUse == null) { + if (storedEx != null) { throw storedEx; } throw new DisguiseParseException(ChatColor.RED + "Cannot find the option " + methodName); } - if (value == null) - { + if (value == null) { throw new DisguiseParseException(ChatColor.RED + "No value was given for the option " + methodName); } - if (!usedOptions.contains(methodName.toLowerCase())) - { + if (!usedOptions.contains(methodName.toLowerCase())) { usedOptions.add(methodName.toLowerCase()); } doCheck(optionPermissions, usedOptions); - if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) - { + if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) { methodToUse.invoke(disguise.getWatcher(), value); } - else - { + else { methodToUse.invoke(disguise, value); } } @@ -1088,14 +899,11 @@ public abstract class BaseDisguiseCommand implements CommandExecutor return disguise; } - private Entry getMethod(Method[] methods, String methodName, int toStart) - { - for (int i = toStart; i < methods.length; i++) - { + private Entry getMethod(Method[] methods, String methodName, int toStart) { + for (int i = toStart; i < methods.length; i++) { Method method = methods[i]; if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName) - && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) - { + && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) { return new HashMap.SimpleEntry(method, ++i); } } @@ -1103,36 +911,28 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } private Object callValueOf(Class param, String valueString, String methodName, String description) - throws DisguiseParseException - { + throws DisguiseParseException { Object value; - try - { + try { value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase()); } - catch (Exception ex) - { + catch (Exception ex) { throw parseToException(description, valueString, methodName); } return value; } - private boolean passesCheck(HashMap, Boolean> map1, ArrayList usedOptions) - { + private boolean passesCheck(HashMap, Boolean> map1, ArrayList usedOptions) { boolean hasPermission = false; - for (ArrayList list : map1.keySet()) - { + for (ArrayList list : map1.keySet()) { boolean myPerms = true; - for (String option : usedOptions) - { - if (!(map1.get(list) && list.contains("*")) && (list.contains(option) != map1.get(list))) - { + for (String option : usedOptions) { + if (!(map1.get(list) && list.contains("*")) && (list.contains(option) != map1.get(list))) { myPerms = false; break; } } - if (myPerms) - { + if (myPerms) { hasPermission = true; } } @@ -1140,50 +940,39 @@ public abstract class BaseDisguiseCommand implements CommandExecutor } private void doCheck(HashMap, Boolean> optionPermissions, ArrayList usedOptions) - throws DisguiseParseException - { - if (!passesCheck(optionPermissions, usedOptions)) - { + throws DisguiseParseException { + if (!passesCheck(optionPermissions, usedOptions)) { throw new DisguiseParseException(ChatColor.RED + "You do not have the permission to use the option " + usedOptions.get(usedOptions.size() - 1)); } } - private DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) - { + private DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) { return new DisguiseParseException( ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received " + ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName); } - private ItemStack parseToItemstack(String string) throws Exception - { + private ItemStack parseToItemstack(String string) throws Exception { String[] split = string.split(":", -1); - if (isNumeric(split[0])) - { + if (isNumeric(split[0])) { int itemId = Integer.parseInt(split[0]); short itemDura = 0; - if (split.length > 1) - { - if (isNumeric(split[1])) - { + if (split.length > 1) { + if (isNumeric(split[1])) { itemDura = Short.parseShort(split[1]); } - else - { + else { throw parseToException("item ID:Durability combo", string, "%s"); } } return new ItemStack(itemId, 1, itemDura); } - else - { - if (split.length == 1) - { + else { + if (split.length == 1) { throw parseToException("item ID", string, "%s"); } - else - { + else { throw parseToException("item ID:Durability combo", string, "%s"); } } diff --git a/src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java index 2a42efd4..8b19baf9 100644 --- a/src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java @@ -23,22 +23,18 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -public class HelpDisguiseCommand extends BaseDisguiseCommand -{ +public class HelpDisguiseCommand extends BaseDisguiseCommand { - private class EnumHelp - { + private class EnumHelp { private String enumDescription; private String enumName; private String[] enums; private String readableEnum; - public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) - { + public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) { String[] strings = new String[enums.length]; - for (int i = 0; i < strings.length; i++) - { + for (int i = 0; i < strings.length; i++) { strings[i] = toReadable(enums[i].name()); } this.enumName = enumName; @@ -47,95 +43,84 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand this.readableEnum = enumReadable; } - public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) - { + public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) { this.enumName = enumName; this.enumDescription = enumDescription; this.enums = enums; this.readableEnum = enumReadable; } - public String getEnumDescription() - { + public String getEnumDescription() { return enumDescription; } - public String getEnumName() - { + public String getEnumName() { return enumName; } - public String[] getEnums() - { + public String[] getEnums() { return enums; } - public String getReadableEnum() - { + public String getReadableEnum() { return readableEnum; } } private ArrayList enumHelp = new ArrayList<>(); - public HelpDisguiseCommand() - { - try - { + public HelpDisguiseCommand() { + try { enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors " + ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values())); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } - try - { + try { enumHelp.add(new EnumHelp("Art", "Arts", ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN + "- View all the painting arts you can use on a painting disguise", (Enum[]) Class.forName("org.bukkit.Art").getEnumConstants())); } - catch (Exception ex) - { + catch (Exception ex) { } - try - { - enumHelp.add(new EnumHelp("HorseColor", "Horse colors", + try { + enumHelp.add(new EnumHelp("LlamaColors", "Llama Colors", + ChatColor.RED + "/disguisehelp LlamaColors " + ChatColor.GREEN + + "- View all the colors you can use for a llama color", + (Enum[]) Class.forName("org.bukkit.entity.Llama$Color").getEnumConstants())); + } + catch (Exception ex) { + } + try { + enumHelp.add(new EnumHelp("HorseColors", "Horse colors", ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN + "- View all the colors you can use for a horses color", (Enum[]) Class.forName("org.bukkit.entity.Horse$Color").getEnumConstants())); } - catch (Exception ex) - { + catch (Exception ex) { } - try - { - enumHelp.add(new EnumHelp("HorseStyle", "Horse styles", + try { + enumHelp.add(new EnumHelp("HorseStyles", "Horse styles", ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN + "- View all the styles you can use for a horses style", (Enum[]) Class.forName("org.bukkit.entity.Horse$Style").getEnumConstants())); } - catch (Exception ex) - { + catch (Exception ex) { } - try - { - enumHelp.add(new EnumHelp("OcelotType", "Ocelot types", + try { + enumHelp.add(new EnumHelp("OcelotTypes", "Ocelot types", ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN + "- View all the ocelot types you can use for ocelots", (Enum[]) Class.forName("org.bukkit.entity.Ocelot$Type").getEnumConstants())); } - catch (Exception ex) - { + catch (Exception ex) { } - try - { + try { ArrayList enumReturns = new ArrayList<>(); - for (PotionEffectType potionType : PotionEffectType.values()) - { - if (potionType != null) - { + for (PotionEffectType potionType : PotionEffectType.values()) { + if (potionType != null) { enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId() + ChatColor.RED + ")"); } @@ -144,19 +129,16 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns.size()]))); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } - try - { + try { enumHelp.add(new EnumHelp("Profession", "Villager professions", ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN + "- View all the professions you can set on a villager", (Enum[]) Class.forName("org.bukkit.entity.Villager$Profession").getEnumConstants())); } - catch (Exception ex) - { + catch (Exception ex) { } enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN @@ -168,56 +150,43 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand } @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) - { - for (String node : new String[] - { - "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" - }) - { + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + for (String node : new String[] { + "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" + }) { HashMap, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node + "."); - if (!permMap.isEmpty()) - { - if (args.length == 0) - { + if (!permMap.isEmpty()) { + if (args.length == 0) { sendCommandUsage(sender, null); return true; } - else - { + else { EnumHelp help = null; - for (EnumHelp s : enumHelp) - { - if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) - { + for (EnumHelp s : enumHelp) { + if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) { help = s; break; } } - if (help != null) - { + if (help != null) { sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN + StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN)); return true; } DisguiseType type = null; - for (DisguiseType disguiseType : DisguiseType.values()) - { + for (DisguiseType disguiseType : DisguiseType.values()) { if (args[0].equalsIgnoreCase(disguiseType.name()) - || disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) - { + || disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) { type = disguiseType; break; } } - if (type == null) - { + if (type == null) { sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]); return true; } - if (!permMap.containsKey(type)) - { + if (!permMap.containsKey(type)) { sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!"); return true; } @@ -225,119 +194,90 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand HashMap map = new HashMap<>(); Class watcher = type.getWatcherClass(); int ignored = 0; - try - { - for (Method method : this.getDisguiseWatcherMethods(watcher)) - { + try { + for (Method method : this.getDisguiseWatcherMethods(watcher)) { if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1 - && method.getAnnotation(Deprecated.class) == null) - { - if (args.length < 2 || !args[1].equalsIgnoreCase("show")) - { + && method.getAnnotation(Deprecated.class) == null) { + if (args.length < 2 || !args[1].equalsIgnoreCase("show")) { boolean allowed = false; - for (ArrayList key : permMap.get(type).keySet()) - { - if (permMap.get(type).get(key)) - { - if (key.contains("*") || key.contains(method.getName().toLowerCase())) - { + for (ArrayList key : permMap.get(type).keySet()) { + if (permMap.get(type).get(key)) { + if (key.contains("*") || key.contains(method.getName().toLowerCase())) { allowed = true; break; } } - else if (!key.contains(method.getName().toLowerCase())) - { + else if (!key.contains(method.getName().toLowerCase())) { allowed = true; break; } } - if (!allowed) - { + if (!allowed) { ignored++; continue; } } Class c = method.getParameterTypes()[0]; String valueType = null; - if (c == String.class) - { + if (c == String.class) { valueType = "String"; } - else if (boolean.class == c) - { + else if (boolean.class == c) { valueType = "True/False"; } - else if (int.class == c) - { + else if (int.class == c) { valueType = "Number"; } - else if (float.class == c || double.class == c) - { + else if (float.class == c || double.class == c) { valueType = "Decimal"; } - else if (AnimalColor.class == c) - { + else if (AnimalColor.class == c) { valueType = "Color"; } - else if (ItemStack.class == c) - { + else if (ItemStack.class == c) { valueType = "Item (id:damage)"; } - else if (ItemStack[].class == c) - { + else if (ItemStack[].class == c) { valueType = "4 items (id:damage,id,...)"; } - else if (c.getSimpleName().equals("Style")) - { + else if (c.getSimpleName().equals("Style")) { valueType = "Horse Style"; } - else if (c.getSimpleName().equals("Color")) - { + else if (c.getSimpleName().equals("Color")) { valueType = "Horse Color"; } - else if (c.getSimpleName().equals("Type")) - { + else if (c.getSimpleName().equals("Type")) { valueType = "Ocelot type"; } - else if (c.getSimpleName().equals("Profession")) - { + else if (c.getSimpleName().equals("Profession")) { valueType = "Villager Profession"; } - else if (PotionEffectType.class == c) - { + else if (PotionEffectType.class == c) { valueType = "Potion effect"; } - else if (c == int[].class) - { + else if (c == int[].class) { valueType = "number,number,number..."; } - else if (c == BlockFace.class) - { + else if (c == BlockFace.class) { valueType = "direction"; } - else if (c == RabbitType.class) - { + else if (c == RabbitType.class) { valueType = "rabbit type"; } - else if (c == BlockPosition.class) - { + else if (c == BlockPosition.class) { valueType = "three numbers"; } - else if (c == WrappedGameProfile.class) - { + else if (c == WrappedGameProfile.class) { valueType = "gameprofile"; } - if (valueType != null) - { + if (valueType != null) { ChatColor methodColor = ChatColor.YELLOW; Class declaring = method.getDeclaringClass(); - if (declaring == LivingWatcher.class) - { + if (declaring == LivingWatcher.class) { methodColor = ChatColor.AQUA; } - else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) - { + else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) { methodColor = ChatColor.GRAY; } String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType @@ -348,23 +288,19 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand } } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } Collections.sort(methods, String.CASE_INSENSITIVE_ORDER); - for (int i = 0; i < methods.size(); i++) - { + for (int i = 0; i < methods.size(); i++) { methods.set(i, map.get(methods.get(i)) + methods.get(i)); } - if (methods.isEmpty()) - { + if (methods.isEmpty()) { methods.add(ChatColor.RED + "No options with permission to use"); } sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: " + StringUtils.join(methods, ChatColor.DARK_RED + ", ")); - if (ignored > 0) - { + if (ignored > 0) { sender.sendMessage(ChatColor.RED + "Ignored " + ignored + " options you do not have permission to view. Add 'show' to view unusable options."); } @@ -380,21 +316,17 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand * Send the player the information */ @Override - protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) - { + protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { sender.sendMessage(ChatColor.RED + "/disguisehelp " + ChatColor.GREEN + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"); - for (EnumHelp s : enumHelp) - { + for (EnumHelp s : enumHelp) { sender.sendMessage(s.getEnumDescription()); } } - public String toReadable(String string) - { + public String toReadable(String string) { String[] split = string.split("_"); - for (int i = 0; i < split.length; i++) - { + for (int i = 0; i < split.length; i++) { split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); } return StringUtils.join(split, "_"); diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index be940ee5..2dd42c97 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -11,7 +11,6 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; -import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton.SkeletonType; @@ -31,7 +30,6 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.events.DisguiseEvent; @@ -40,8 +38,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; -public abstract class Disguise -{ +public abstract class Disguise { private boolean disguiseInUse; private DisguiseType disguiseType; private Entity entity; @@ -71,15 +68,12 @@ public abstract class Disguise * @param newType * The disguise */ - protected void createDisguise(DisguiseType newType) - { - if (getWatcher() != null) - { + protected void createDisguise(DisguiseType newType) { + if (getWatcher() != null) { return; } - if (newType.getEntityType() == null) - { + if (newType.getEntityType() == null) { throw new RuntimeException("DisguiseType " + newType + " was used in a futile attempt to construct a disguise, but this Minecraft version does not have that entity"); } @@ -90,45 +84,36 @@ public abstract class Disguise boolean isAdult = true; - if (isMobDisguise()) - { + if (isMobDisguise()) { isAdult = ((MobDisguise) this).isAdult(); } - try - { + try { // Construct the FlagWatcher from the stored class setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this)); } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } // Set the disguise if its a baby or not - if (!isAdult) - { - if (getWatcher() instanceof AgeableWatcher) - { + if (!isAdult) { + if (getWatcher() instanceof AgeableWatcher) { ((AgeableWatcher) getWatcher()).setBaby(true); } - else if (getWatcher() instanceof ZombieWatcher) - { + else if (getWatcher() instanceof ZombieWatcher) { ((ZombieWatcher) getWatcher()).setBaby(true); } } // If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton - if (getType() == DisguiseType.WITHER_SKELETON) - { + if (getType() == DisguiseType.WITHER_SKELETON) { ((SkeletonWatcher) getWatcher()).setType(SkeletonType.WITHER); } - else if (getType() == DisguiseType.STRAY) - { + else if (getType() == DisguiseType.STRAY) { ((SkeletonWatcher) getWatcher()).setType(SkeletonType.STRAY); } // Else if its a zombie, but the disguise type is a zombie villager. Set the value. - else if (getType() == DisguiseType.ZOMBIE_VILLAGER) - { + else if (getType() == DisguiseType.ZOMBIE_VILLAGER) { Profession profession = null; while (profession == null || profession == Profession.NORMAL || profession == Profession.HUSK) @@ -136,31 +121,16 @@ public abstract class Disguise ((ZombieWatcher) getWatcher()).setProfession(profession); } - else if (getType() == DisguiseType.HUSK) - { + else if (getType() == DisguiseType.HUSK) { ((ZombieWatcher) getWatcher()).setProfession(Profession.HUSK); } - else if (getType() == DisguiseType.ELDER_GUARDIAN) - { + else if (getType() == DisguiseType.ELDER_GUARDIAN) { ((GuardianWatcher) getWatcher()).setElder(true); - } // Else if its a horse. Set the horse watcher type - else if (getWatcher() instanceof HorseWatcher) - { - try - { - Variant horseType = Variant.valueOf(getType().name()); - ((HorseWatcher) getWatcher()).setVariant(horseType); - } - catch (Exception ex) - { - // Ok.. So it aint a horse - } } final boolean alwaysSendVelocity; - switch (getType()) - { + switch (getType()) { case EGG: case ENDER_PEARL: case BAT: @@ -181,8 +151,7 @@ public abstract class Disguise double velocitySpeed = 0.0005; - switch (getType()) - { + switch (getType()) { case FIREWORK: velocitySpeed = -0.040; break; @@ -232,32 +201,26 @@ public abstract class Disguise final TargetedDisguise disguise = (TargetedDisguise) this; // A scheduler to clean up any unused disguises. - velocityRunnable = new Runnable() - { + velocityRunnable = new Runnable() { private int blockX, blockY, blockZ, facing; private int deadTicks = 0; private int refreshDisguise = 0; @Override - public void run() - { + public void run() { // If entity is no longer valid. Remove it. - if (!getEntity().isValid()) - { + if (!getEntity().isValid()) { // If it has been dead for 30+ ticks // This is to ensure that this disguise isn't removed while clients think its the real entity // The delay is because if it sends the destroy entity packets straight away, then it means no death animation // This is probably still a problem for wither and enderdragon deaths. - if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) - { + if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) { deadTicks = 0; - if (isRemoveDisguiseOnDeath()) - { + if (isRemoveDisguiseOnDeath()) { removeDisguise(); } - else - { + else { entity = null; watcher = getWatcher().clone(disguise); task.cancel(); @@ -265,32 +228,27 @@ public abstract class Disguise } } } - else - { + else { deadTicks = 0; // If the disguise type is tnt, we need to resend the entity packet else it will turn invisible - if (getType() == DisguiseType.FIREWORK) - { + if (getType() == DisguiseType.FIREWORK) { refreshDisguise++; - if (refreshDisguise % 40 == 0) - { + if (refreshDisguise % 40 == 0) { refreshDisguise = 0; DisguiseUtilities.refreshTrackers(disguise); } } - if (getType() == DisguiseType.ITEM_FRAME) - { + if (getType() == DisguiseType.ITEM_FRAME) { Location loc = getEntity().getLocation(); int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4; if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc.getBlockZ() != blockZ - || newFacing != facing) - { + || newFacing != facing) { blockX = loc.getBlockX(); blockY = loc.getBlockY(); blockZ = loc.getBlockZ(); @@ -300,37 +258,31 @@ public abstract class Disguise } } - if (isModifyBoundingBox()) - { + if (isModifyBoundingBox()) { DisguiseUtilities.doBoundingBox(disguise); } - if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isHanging()) - { + if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isHanging()) { return; } // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. // If this disguise has velocity sending enabled and the entity is flying. - if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) - { + if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) { Vector vector = getEntity().getVelocity(); // If the entity doesn't have velocity changes already - You know. I really can't wrap my head about the // if statement. // But it doesn't seem to do anything wrong.. - if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) - { + if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) { return; } // If disguise isn't a experience orb, or the entity isn't standing on the ground - if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) - { + if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) { PacketContainer lookPacket = null; - if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) - { + if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) { lookPacket = new PacketContainer(Server.ENTITY_LOOK); StructureModifier mods = lookPacket.getModifier(); @@ -342,26 +294,22 @@ public abstract class Disguise mods.write(5, PacketsManager.getPitch(getType(), DisguiseType.getType(getEntity().getType()), (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F))); - if (isSelfDisguiseVisible() && getEntity() instanceof Player) - { + if (isSelfDisguiseVisible() && getEntity() instanceof Player) { PacketContainer selfLookPacket = lookPacket.shallowClone(); selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfLookPacket, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } - try - { + try { PacketContainer velocityPacket = new PacketContainer(Server.ENTITY_VELOCITY); StructureModifier mods = velocityPacket.getIntegers(); @@ -369,26 +317,21 @@ public abstract class Disguise mods.write(1, (int) (vector.getX() * 8000)); mods.write(3, (int) (vector.getZ() * 8000)); - for (Player player : DisguiseUtilities.getPerverts(disguise)) - { - if (getEntity() == player) - { - if (!isSelfDisguiseVisible()) - { + for (Player player : DisguiseUtilities.getPerverts(disguise)) { + if (getEntity() == player) { + if (!isSelfDisguiseVisible()) { continue; } mods.write(0, DisguiseAPI.getSelfDisguiseId()); } - else - { + else { mods.write(0, getEntity().getEntityId()); } mods.write(2, (int) (8000D * (vectorY * ReflectionManager.getPing(player)) * 0.069D)); - if (lookPacket != null && player != getEntity()) - { + if (lookPacket != null && player != getEntity()) { ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false); } @@ -396,47 +339,38 @@ public abstract class Disguise false); } } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } } // If we need to send a packet to update the exp position as it likes to gravitate client sided to // players. } - if (getType() == DisguiseType.EXPERIENCE_ORB) - { + if (getType() == DisguiseType.EXPERIENCE_ORB) { PacketContainer packet = new PacketContainer(Server.REL_ENTITY_MOVE); packet.getIntegers().write(0, getEntity().getEntityId()); - try - { - for (Player player : DisguiseUtilities.getPerverts(disguise)) - { - if (getEntity() != player) - { + try { + for (Player player : DisguiseUtilities.getPerverts(disguise)) { + if (getEntity() != player) { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); } - else if (isSelfDisguiseVisible()) - { + else if (isSelfDisguiseVisible()) { PacketContainer selfPacket = packet.shallowClone(); selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId()); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } @@ -450,8 +384,7 @@ public abstract class Disguise * * @return entity */ - public Entity getEntity() - { + public Entity getEntity() { return entity; } @@ -460,8 +393,7 @@ public abstract class Disguise * * @return disguiseType */ - public DisguiseType getType() - { + public DisguiseType getType() { return disguiseType; } @@ -470,8 +402,7 @@ public abstract class Disguise * * @return flagWatcher */ - public FlagWatcher getWatcher() - { + public FlagWatcher getWatcher() { return watcher; } @@ -481,68 +412,56 @@ public abstract class Disguise * * @return isDisguiseInUse */ - public boolean isDisguiseInUse() - { + public boolean isDisguiseInUse() { return disguiseInUse; } - public boolean isHidingArmorFromSelf() - { + public boolean isHidingArmorFromSelf() { return hideArmorFromSelf; } - public boolean isHidingHeldItemFromSelf() - { + public boolean isHidingHeldItemFromSelf() { return hideHeldItemFromSelf; } - public boolean isKeepDisguiseOnEntityDespawn() - { + public boolean isKeepDisguiseOnEntityDespawn() { return this.keepDisguiseEntityDespawn; } - public boolean isKeepDisguiseOnPlayerDeath() - { + public boolean isKeepDisguiseOnPlayerDeath() { return this.keepDisguisePlayerDeath; } - public boolean isKeepDisguiseOnPlayerLogout() - { + public boolean isKeepDisguiseOnPlayerLogout() { return this.keepDisguisePlayerLogout; } - public boolean isMiscDisguise() - { + public boolean isMiscDisguise() { return false; } - public boolean isMobDisguise() - { + public boolean isMobDisguise() { return false; } - public boolean isModifyBoundingBox() - { + public boolean isModifyBoundingBox() { return modifyBoundingBox; } - public boolean isPlayerDisguise() - { + public boolean isPlayerDisguise() { return false; } /** * Internal use */ - public boolean isRemoveDisguiseOnDeath() - { + public boolean isRemoveDisguiseOnDeath() { return getEntity() == null || (getEntity() instanceof Player ? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())); } - public boolean isSelfDisguiseSoundsReplaced() - { + public boolean isSelfDisguiseSoundsReplaced() { return hearSelfDisguise; } @@ -551,18 +470,15 @@ public abstract class Disguise * * @return viewSelfDisguise */ - public boolean isSelfDisguiseVisible() - { + public boolean isSelfDisguiseVisible() { return viewSelfDisguise; } - public boolean isSoundsReplaced() - { + public boolean isSoundsReplaced() { return replaceSounds; } - public boolean isVelocitySent() - { + public boolean isVelocitySent() { return velocitySent; } @@ -571,8 +487,7 @@ public abstract class Disguise * * @return */ - public boolean isShowName() - { + public boolean isShowName() { return showName; } @@ -581,20 +496,16 @@ public abstract class Disguise * * @return removeDiguise */ - public boolean removeDisguise() - { - if (disguiseInUse) - { + public boolean removeDisguise() { + if (disguiseInUse) { UndisguiseEvent event = new UndisguiseEvent(entity, this); Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) - { + if (!event.isCancelled()) { disguiseInUse = false; - if (task != null) - { + if (task != null) { task.cancel(); task = null; } @@ -602,58 +513,45 @@ public abstract class Disguise HashMap> disguises = DisguiseUtilities.getDisguises(); // If this disguise has a entity set - if (getEntity() != null) - { + if (getEntity() != null) { // If this disguise is active // Remove the disguise from the current disguises. - if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) - { - if (getEntity() instanceof Player) - { + if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) { + if (getEntity() instanceof Player) { DisguiseUtilities.removeSelfDisguise((Player) getEntity()); } // Better refresh the entity to undisguise it - if (getEntity().isValid()) - { + if (getEntity().isValid()) { DisguiseUtilities.refreshTrackers((TargetedDisguise) this); } - else - { + else { DisguiseUtilities.destroyEntity((TargetedDisguise) this); } } } - else - { + else { // Loop through the disguises because it could be used with a unknown entity id. HashMap> future = DisguiseUtilities.getFutureDisguises(); Iterator itel = DisguiseUtilities.getFutureDisguises().keySet().iterator(); - while (itel.hasNext()) - { + while (itel.hasNext()) { int id = itel.next(); - if (future.get(id).remove(this) && future.get(id).isEmpty()) - { + if (future.get(id).remove(this) && future.get(id).isEmpty()) { itel.remove(); } } } - if (isPlayerDisguise()) - { + if (isPlayerDisguise()) { String name = ((PlayerDisguise) this).getName(); - if (!DisguiseUtilities.getAddedByPlugins().contains(name.toLowerCase())) - { - for (HashSet disguise : disguises.values()) - { - for (Disguise d : disguise) - { - if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name)) - { + if (!DisguiseUtilities.getAddedByPlugins().contains(name.toLowerCase())) { + for (HashSet disguise : disguises.values()) { + for (Disguise d : disguise) { + if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name)) { return true; } } @@ -675,20 +573,16 @@ public abstract class Disguise * @param entity * @return disguise */ - public Disguise setEntity(Entity entity) - { - if (this.getEntity() != null) - { - if (getEntity() == entity) - { + public Disguise setEntity(Entity entity) { + if (this.getEntity() != null) { + if (getEntity() == entity) { return this; } throw new RuntimeException("This disguise is already in use! Try .clone()"); } - if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) - { + if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { throw new RuntimeException( "Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the config to do this"); } @@ -700,79 +594,66 @@ public abstract class Disguise return this; } - public Disguise setShowName(boolean showName) - { + public Disguise setShowName(boolean showName) { this.showName = showName; return this; } - public Disguise setHearSelfDisguise(boolean hearSelfDisguise) - { + public Disguise setHearSelfDisguise(boolean hearSelfDisguise) { this.hearSelfDisguise = hearSelfDisguise; return this; } - public Disguise setHideArmorFromSelf(boolean hideArmor) - { + public Disguise setHideArmorFromSelf(boolean hideArmor) { this.hideArmorFromSelf = hideArmor; - if (getEntity() instanceof Player) - { + if (getEntity() instanceof Player) { ((Player) getEntity()).updateInventory(); } return this; } - public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) - { + public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) { this.hideHeldItemFromSelf = hideHeldItem; - if (getEntity() instanceof Player) - { + if (getEntity() instanceof Player) { ((Player) getEntity()).updateInventory(); } return this; } - public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) - { + public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { this.keepDisguiseEntityDespawn = keepDisguise; return this; } - public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) - { + public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { this.keepDisguisePlayerDeath = keepDisguise; return this; } - public Disguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) - { + public Disguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { this.keepDisguisePlayerLogout = keepDisguise; return this; } - public Disguise setModifyBoundingBox(boolean modifyBox) - { - if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) - { + public Disguise setModifyBoundingBox(boolean modifyBox) { + if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { throw new RuntimeException( "Cannot modify the bounding box of a disguise which is not TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS"); } - if (isModifyBoundingBox() != modifyBox) - { + if (isModifyBoundingBox() != modifyBox) { this.modifyBoundingBox = modifyBox; - if (DisguiseUtilities.isDisguiseInUse(this)) - { + if (DisguiseUtilities.isDisguiseInUse(this)) { DisguiseUtilities.doBoundingBox((TargetedDisguise) this); } } @@ -780,8 +661,7 @@ public abstract class Disguise return this; } - public Disguise setReplaceSounds(boolean areSoundsReplaced) - { + public Disguise setReplaceSounds(boolean areSoundsReplaced) { replaceSounds = areSoundsReplaced; return this; @@ -791,20 +671,17 @@ public abstract class Disguise * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the * datawatcher. */ - private void setupWatcher() - { + private void setupWatcher() { ArrayList disguiseFlags = FlagType.getFlags(getType().getWatcherClass()); ArrayList entityFlags = FlagType.getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass()); - for (FlagType flag : entityFlags) - { + for (FlagType flag : entityFlags) { if (disguiseFlags.contains(flag)) continue; FlagType backup = null; - for (FlagType flagType : disguiseFlags) - { + for (FlagType flagType : disguiseFlags) { if (flagType.getIndex() == flag.getIndex()) backup = flagType; } @@ -815,8 +692,7 @@ public abstract class Disguise getWatcher().setNoGravity(true); } - public Disguise setVelocitySent(boolean sendVelocity) - { + public Disguise setVelocitySent(boolean sendVelocity) { this.velocitySent = sendVelocity; return this; @@ -828,22 +704,16 @@ public abstract class Disguise * @param viewSelfDisguise * @return */ - public Disguise setViewSelfDisguise(boolean viewSelfDisguise) - { - if (isSelfDisguiseVisible() != viewSelfDisguise) - { + public Disguise setViewSelfDisguise(boolean viewSelfDisguise) { + if (isSelfDisguiseVisible() != viewSelfDisguise) { this.viewSelfDisguise = viewSelfDisguise; - if (getEntity() != null && getEntity() instanceof Player) - { - if (DisguiseAPI.getDisguise((Player) getEntity(), getEntity()) == this) - { - if (isSelfDisguiseVisible()) - { + if (getEntity() != null && getEntity() instanceof Player) { + if (DisguiseAPI.getDisguise((Player) getEntity(), getEntity()) == this) { + if (isSelfDisguiseVisible()) { DisguiseUtilities.setupFakeDisguise(this); } - else - { + else { DisguiseUtilities.removeSelfDisguise((Player) getEntity()); } } @@ -853,30 +723,24 @@ public abstract class Disguise return this; } - public Disguise setWatcher(FlagWatcher newWatcher) - { - if (!getType().getWatcherClass().isInstance(newWatcher)) - { + public Disguise setWatcher(FlagWatcher newWatcher) { + if (!getType().getWatcherClass().isInstance(newWatcher)) { throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of " + getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name()); } watcher = newWatcher; - if (getEntity() != null) - { + if (getEntity() != null) { setupWatcher(); } return this; } - public boolean startDisguise() - { - if (!isDisguiseInUse()) - { - if (getEntity() == null) - { + public boolean startDisguise() { + if (!isDisguiseInUse()) { + if (getEntity() == null) { throw new RuntimeException("No entity is assigned to this disguise!"); } @@ -887,8 +751,7 @@ public abstract class Disguise // If they cancelled this disguise event. No idea why. // Just return. - if (!event.isCancelled()) - { + if (!event.isCancelled()) { disguiseInUse = true; task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1); @@ -896,8 +759,7 @@ public abstract class Disguise // Stick the disguise in the disguises bin DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); - if (isSelfDisguiseVisible() && getEntity() instanceof Player) - { + if (isSelfDisguiseVisible() && getEntity() instanceof Player) { DisguiseUtilities.removeSelfDisguise((Player) getEntity()); } @@ -905,11 +767,9 @@ public abstract class Disguise DisguiseUtilities.refreshTrackers((TargetedDisguise) this); // If he is a player, then self disguise himself - Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() { @Override - public void run() - { + public void run() { DisguiseUtilities.setupFakeDisguise(Disguise.this); } }, 2); @@ -919,8 +779,7 @@ public abstract class Disguise return false; } - public boolean stopDisguise() - { + public boolean stopDisguise() { return removeDisguise(); } @@ -929,8 +788,7 @@ public abstract class Disguise * * @return */ - public static List getViewSelf() - { + public static List getViewSelf() { return viewSelf; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 288b4d42..a86664be 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -9,8 +9,7 @@ import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Zombie; -public enum DisguiseType -{ +public enum DisguiseType { AREA_EFFECT_CLOUD(3, 0), ARMOR_STAND(78), @@ -53,6 +52,10 @@ public enum DisguiseType ENDERMITE, + EVOKER, + + EVOKER_FANGS(79), + EXPERIENCE_ORB, FALLING_BLOCK(70, 1), @@ -77,6 +80,10 @@ public enum DisguiseType ITEM_FRAME(71), + LLAMA, + + LLAMA_SPIT(68), + LEASH_HITCH(77), MAGMA_CUBE, @@ -153,8 +160,12 @@ public enum DisguiseType UNKNOWN, + VEX, + VILLAGER, + VINDICATOR, + WITCH, WITHER, @@ -169,31 +180,21 @@ public enum DisguiseType ZOMBIE_VILLAGER; - static - { + static { // We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC. // Without erroring up everything. - for (DisguiseType type : values()) - { + for (DisguiseType type : values()) { - try - { + try { DisguiseType toUse = type; String name; - switch (type) - { + switch (type) { // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being.. // Usable. case ITEM_FRAME: break; - case DONKEY: - case MULE: - case UNDEAD_HORSE: - case SKELETON_HORSE: - toUse = DisguiseType.HORSE; - break; case ZOMBIE_VILLAGER: case HUSK: toUse = DisguiseType.ZOMBIE; @@ -213,23 +214,19 @@ public enum DisguiseType type.setEntityType(EntityType.valueOf(name)); } - catch (Throwable ex) - { + catch (Throwable ex) { // This version of Spigot doesn't have the disguise. } } } - public static DisguiseType getType(Entity entity) - { + public static DisguiseType getType(Entity entity) { DisguiseType disguiseType = getType(entity.getType()); - switch (disguiseType) - { + switch (disguiseType) { case ZOMBIE: - if (((Zombie) entity).isVillager()) - { + if (((Zombie) entity).isVillager()) { disguiseType = DisguiseType.ZOMBIE_VILLAGER; } @@ -243,16 +240,14 @@ public enum DisguiseType case SKELETON: - if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) - { + if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) { disguiseType = DisguiseType.WITHER_SKELETON; } break; case GUARDIAN: - if (((Guardian) entity).isElder()) - { + if (((Guardian) entity).isElder()) { disguiseType = DisguiseType.ELDER_GUARDIAN; } @@ -265,14 +260,11 @@ public enum DisguiseType } - public static DisguiseType getType(EntityType entityType) - { - try - { + public static DisguiseType getType(EntityType entityType) { + try { return valueOf(entityType.name().toUpperCase()); } - catch (Throwable ex) - { + catch (Throwable ex) { return DisguiseType.UNKNOWN; } } @@ -283,14 +275,11 @@ public enum DisguiseType private Class watcherClass; - DisguiseType(int... ints) - { - for (int i = 0; i < ints.length; i++) - { + DisguiseType(int... ints) { + for (int i = 0; i < ints.length; i++) { int value = ints[i]; - switch (i) - { + switch (i) { case 0: objectId = value; @@ -305,23 +294,19 @@ public enum DisguiseType } } - public int getDefaultData() - { + public int getDefaultData() { return defaultData; } - public Class getEntityClass() - { - if (entityType != null) - { + public Class getEntityClass() { + if (entityType != null) { return getEntityType().getEntityClass(); } return Entity.class; } - public EntityType getEntityType() - { + public EntityType getEntityType() { return entityType; } @@ -330,8 +315,7 @@ public enum DisguiseType * * @return */ - public int getObjectId() - { + public int getObjectId() { return objectId; } @@ -340,52 +324,42 @@ public enum DisguiseType * * @return */ - public int getTypeId() - { + public int getTypeId() { return (int) getEntityType().getTypeId(); } - public Class getWatcherClass() - { + public Class getWatcherClass() { return watcherClass; } - public boolean isMisc() - { + public boolean isMisc() { return getEntityType() != null && !getEntityType().isAlive(); } - public boolean isMob() - { + public boolean isMob() { return getEntityType() != null && getEntityType().isAlive() && !isPlayer(); } - public boolean isPlayer() - { + public boolean isPlayer() { return this == DisguiseType.PLAYER; } - public boolean isUnknown() - { + public boolean isUnknown() { return this == DisguiseType.UNKNOWN; } - private void setEntityType(EntityType entityType) - { + private void setEntityType(EntityType entityType) { this.entityType = entityType; } - public void setWatcherClass(Class c) - { + public void setWatcherClass(Class c) { watcherClass = c; } - public String toReadable() - { + public String toReadable() { String[] split = name().split("_"); - for (int i = 0; i < split.length; i++) - { + for (int i = 0; i < split.length; i++) { split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java index 626161cd..0d5530cb 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java @@ -28,16 +28,20 @@ import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EnderCrystalWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EnderDragonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.EvokerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FireworkWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FishingHookWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GhastWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.HorseAbstractWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.HorseChestedWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.IronGolemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.LlamaWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PigWatcher; @@ -53,15 +57,16 @@ import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.VexWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.VillagerWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.VindicatorWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; -public class FlagType -{ +public class FlagType { private static FlagType[] _values = new FlagType[0]; public static FlagType AGEABLE_BABY = new FlagType(AgeableWatcher.class, 0, false); @@ -79,11 +84,9 @@ public class FlagType public static FlagType AREA_EFFECT_RADIUS = new FlagType(AreaEffectCloudWatcher.class, 0, 0F); - public static FlagType ARMORSTAND_BODY = new FlagType(ArmorStandWatcher.class, 2, - new Vector3F(0, 0, 0)); + public static FlagType ARMORSTAND_BODY = new FlagType(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0)); - public static FlagType ARMORSTAND_HEAD = new FlagType(ArmorStandWatcher.class, 1, - new Vector3F(0, 0, 0)); + public static FlagType ARMORSTAND_HEAD = new FlagType(ArmorStandWatcher.class, 1, new Vector3F(0, 0, 0)); public static FlagType ARMORSTAND_LEFT_ARM = new FlagType(ArmorStandWatcher.class, 3, new Vector3F(0, 0, 0)); @@ -93,9 +96,11 @@ public class FlagType public static FlagType ARMORSTAND_META = new FlagType(ArmorStandWatcher.class, 0, (byte) 0); - public static FlagType ARMORSTAND_RIGHT_ARM = new FlagType(ArmorStandWatcher.class, 4, new Vector3F(0,0,0)); + public static FlagType ARMORSTAND_RIGHT_ARM = new FlagType(ArmorStandWatcher.class, 4, + new Vector3F(0, 0, 0)); - public static FlagType ARMORSTAND_RIGHT_LEG = new FlagType(ArmorStandWatcher.class, 6, new Vector3F(0,0,0)); + public static FlagType ARMORSTAND_RIGHT_LEG = new FlagType(ArmorStandWatcher.class, 6, + new Vector3F(0, 0, 0)); public static FlagType ARROW_CRITICAL = new FlagType(ArrowWatcher.class, 0, (byte) 0); @@ -148,6 +153,8 @@ public class FlagType public static FlagType ENTITY_SILENT = new FlagType(FlagWatcher.class, 4, false); + public static FlagType EVOKER_SPELL_TICKS = new FlagType(EvokerWatcher.class, 0, (byte) 0); + public static FlagType FALLING_BLOCK_POSITION = new FlagType(FallingBlockWatcher.class, 0, BlockPosition.ORIGIN); @@ -162,16 +169,18 @@ public class FlagType public static FlagType GUARDIAN_TARGET = new FlagType(GuardianWatcher.class, 1, 0); - public static FlagType HORSE_ARMOR = new FlagType(HorseWatcher.class, 4, 0); + public static FlagType HORSE_ARMOR = new FlagType(HorseWatcher.class, 1, 0); - public static FlagType HORSE_COLOR = new FlagType(HorseWatcher.class, 2, 0); + public static FlagType HORSE_COLOR = new FlagType(HorseWatcher.class, 0, 0); - public static FlagType HORSE_META = new FlagType(HorseWatcher.class, 0, (byte) 0); + public static FlagType HORSE_META = new FlagType(HorseAbstractWatcher.class, 0, (byte) 0); - public static FlagType> HORSE_OWNER = new FlagType>(HorseWatcher.class, 3, + public static FlagType HORSE_CARRYING_CHEST = new FlagType(HorseChestedWatcher.class, 0, false); + + public static FlagType> HORSE_OWNER = new FlagType>(HorseAbstractWatcher.class, 1, Optional. absent()); - public static FlagType HORSE_VARIANT = new FlagType(HorseWatcher.class, 1, 0); + // public static FlagType HORSE_VARIANT = new FlagType(HorseWatcher.class, 0, 0); public static FlagType INSENTIENT_META = new FlagType(InsentientWatcher.class, 0, (byte) 0); @@ -182,6 +191,12 @@ public class FlagType public static FlagType ITEMFRAME_ROTATION = new FlagType(ItemFrameWatcher.class, 1, 0); + public static FlagType LLAMA_STRENGTH = new FlagType(LlamaWatcher.class, 0, 0); + + public static FlagType LLAMA_COLOR = new FlagType(LlamaWatcher.class, 1, -1); + + public static FlagType LLAMA_CARPET = new FlagType(LlamaWatcher.class, 2, 0); + public static FlagType LIVING_ARROWS = new FlagType(LivingWatcher.class, 4, 0); public static FlagType LIVING_HAND = new FlagType(LivingWatcher.class, 0, (byte) 0); @@ -229,6 +244,8 @@ public class FlagType public static FlagType SHULKER_PEEKING = new FlagType(ShulkerWatcher.class, 2, (byte) 0); + public static FlagType SHULKER_COLOR = new FlagType(ShulkerWatcher.class, 3, (byte) 10); + public static FlagType SKELETON_SWING_ARMS = new FlagType(SkeletonWatcher.class, 1, false); public static FlagType SKELETON_TYPE = new FlagType(SkeletonWatcher.class, 0, 0); @@ -257,8 +274,12 @@ public class FlagType public static FlagType TNT_FUSE_TICKS = new FlagType(TNTWatcher.class, 0, Integer.MAX_VALUE); + public static FlagType VEX_ANGRY = new FlagType(VexWatcher.class, 0, false); + public static FlagType VILLAGER_PROFESSION = new FlagType(VillagerWatcher.class, 0, 0); + public static FlagType VINDICATOR_JOHNNY = new FlagType(VindicatorWatcher.class, 0, (byte) 0); + public static FlagType WITCH_AGGRESSIVE = new FlagType(WitchWatcher.class, 0, false); public static FlagType WITHER_INVUL = new FlagType(WitherWatcher.class, 3, 0); @@ -285,10 +306,8 @@ public class FlagType public static FlagType ZOMBIE_SHAKING = new FlagType(ZombieWatcher.class, 2, false); - static - { - for (FlagType flagType : values()) - { + static { + for (FlagType flagType : values()) { if (flagType.getFlagWatcher() == FlagWatcher.class) continue; @@ -302,32 +321,27 @@ public class FlagType HashMap maxValues = new HashMap(); - for (FlagType type : values()) - { + for (FlagType type : values()) { if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex()) continue; maxValues.put(type.getFlagWatcher(), type.getIndex()); } - for (Entry entry : maxValues.entrySet()) - { + for (Entry entry : maxValues.entrySet()) { loop: - for (int i = 0; i < entry.getValue(); i++) - { + for (int i = 0; i < entry.getValue(); i++) { FlagType found = null; - for (FlagType type : values()) - { + for (FlagType type : values()) { if (type.getIndex() != i) continue; if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) continue; - if (found != null) - { + if (found != null) { System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " + i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() + ")"); @@ -345,10 +359,8 @@ public class FlagType } } - public static FlagType getFlag(Class watcherClass, int flagNo) - { - for (FlagType type : values()) - { + public static FlagType getFlag(Class watcherClass, int flagNo) { + for (FlagType type : values()) { if (type.getIndex() != flagNo) continue; @@ -361,12 +373,10 @@ public class FlagType return null; } - public static ArrayList getFlags(Class watcherClass) - { + public static ArrayList getFlags(Class watcherClass) { ArrayList list = new ArrayList(); - for (FlagType type : values()) - { + for (FlagType type : values()) { if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) continue; @@ -376,28 +386,24 @@ public class FlagType return list; } - private static int getNoIndexes(Class c) - { + private static int getNoIndexes(Class c) { int found = 0; - for (FlagType type : values()) - { + for (FlagType type : values()) { if (type.getFlagWatcher() != c) continue; found++; } - if (c != FlagWatcher.class) - { + if (c != FlagWatcher.class) { found += getNoIndexes(c.getSuperclass()); } return found; } - public static FlagType[] values() - { + public static FlagType[] values() { return _values; } @@ -405,8 +411,7 @@ public class FlagType private int _index; private Class _watcher; - private FlagType(Class watcher, int index, Y defaultValue) - { + private FlagType(Class watcher, int index, Y defaultValue) { _index = index; _watcher = watcher; _defaultValue = defaultValue; @@ -415,18 +420,15 @@ public class FlagType _values[_values.length - 1] = this; } - public Y getDefault() - { + public Y getDefault() { return _defaultValue; } - public Class getFlagWatcher() - { + public Class getFlagWatcher() { return _watcher; } - public int getIndex() - { + public int getIndex() { return _index; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index a19f237d..0fe03c7b 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -243,7 +243,7 @@ public class FlagWatcher public String getCustomName() { - return (String) getValue(FlagType.ENTITY_CUSTOM_NAME); + return (String) getData(FlagType.ENTITY_CUSTOM_NAME); } protected TargetedDisguise getDisguise() @@ -253,7 +253,7 @@ public class FlagWatcher private boolean getEntityFlag(int byteValue) { - return (getValue(FlagType.ENTITY_META) & 1 << byteValue) != 0; + return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0; } public EntityEquipment getEquipment() @@ -301,7 +301,7 @@ public class FlagWatcher return null; } - protected Y getValue(FlagType flagType) + protected Y getData(FlagType flagType) { if (_entityValues.containsKey(flagType.getIndex())) { @@ -338,7 +338,7 @@ public class FlagWatcher public boolean isCustomNameVisible() { - return getValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); + return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } public boolean isEntityAnimationsAdded() @@ -363,7 +363,7 @@ public class FlagWatcher public boolean isNoGravity() { - return getValue(FlagType.ENTITY_NO_GRAVITY); + return getData(FlagType.ENTITY_NO_GRAVITY); } public boolean isRightClicking() @@ -509,13 +509,13 @@ public class FlagWatcher name = name.substring(0, 64); } - setValue(FlagType.ENTITY_CUSTOM_NAME, name); + setData(FlagType.ENTITY_CUSTOM_NAME, name); sendData(FlagType.ENTITY_CUSTOM_NAME); } public void setCustomNameVisible(boolean display) { - setValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); + setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } @@ -523,15 +523,15 @@ public class FlagWatcher { _modifiedEntityAnimations.add(byteValue); - byte b0 = (byte) getValue(FlagType.ENTITY_META); + byte b0 = (byte) getData(FlagType.ENTITY_META); if (flag) { - setValue(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); + setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); } else { - setValue(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); + setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); } } @@ -653,7 +653,7 @@ public class FlagWatcher public void setNoGravity(boolean noGravity) { - setValue(FlagType.ENTITY_NO_GRAVITY, noGravity); + setData(FlagType.ENTITY_NO_GRAVITY, noGravity); sendData(FlagType.ENTITY_NO_GRAVITY); } @@ -675,7 +675,7 @@ public class FlagWatcher sendData(FlagType.ENTITY_META); } - protected void setValue(FlagType id, Y value) + protected void setData(FlagType id, Y value) { _entityValues.put(id.getIndex(), value); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java index 09b354ed..4d079570 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java @@ -17,7 +17,7 @@ public class AgeableWatcher extends InsentientWatcher public boolean isBaby() { - return getValue(FlagType.AGEABLE_BABY); + return getData(FlagType.AGEABLE_BABY); } public void setAdult() @@ -32,7 +32,7 @@ public class AgeableWatcher extends InsentientWatcher public void setBaby(boolean isBaby) { - setValue(FlagType.AGEABLE_BABY, isBaby); + setData(FlagType.AGEABLE_BABY, isBaby); sendData(FlagType.AGEABLE_BABY); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index a15a854c..a0d908a7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -17,42 +17,42 @@ public class AreaEffectCloudWatcher extends FlagWatcher public float getRadius() { - return getValue(FlagType.AREA_EFFECT_RADIUS); + return getData(FlagType.AREA_EFFECT_RADIUS); } public int getColor() { - return getValue(FlagType.AREA_EFFECT_COLOR); + return getData(FlagType.AREA_EFFECT_COLOR); } public boolean isIgnoreRadius() { - return getValue(FlagType.AREA_EFFECT_IGNORE_RADIUS); + return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS); } public int getParticleId() { - return getValue(FlagType.AREA_EFFECT_PARTICLE); + return getData(FlagType.AREA_EFFECT_PARTICLE); } public void setRadius(float radius) { - setValue(FlagType.AREA_EFFECT_RADIUS, radius); + setData(FlagType.AREA_EFFECT_RADIUS, radius); } public void setColor(int color) { - setValue(FlagType.AREA_EFFECT_COLOR, color); + setData(FlagType.AREA_EFFECT_COLOR, color); } public void setIgnoreRadius(boolean ignore) { - setValue(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); + setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); } public void setParticleId(int particleId) { - setValue(FlagType.AREA_EFFECT_PARTICLE, particleId); + setData(FlagType.AREA_EFFECT_PARTICLE, particleId); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java index 51fba717..d727805a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java @@ -16,7 +16,7 @@ public class ArmorStandWatcher extends LivingWatcher private boolean getArmorStandFlag(int value) { - return (getValue(FlagType.ARMORSTAND_META) & value) != 0; + return (getData(FlagType.ARMORSTAND_META) & value) != 0; } public EulerAngle getBody() @@ -44,7 +44,7 @@ public class ArmorStandWatcher extends LivingWatcher if (!hasValue(type)) return new EulerAngle(0, 0, 0); - Vector3F vec = getValue(type); + Vector3F vec = getData(type); return new EulerAngle(vec.getX(), vec.getY(), vec.getZ()); } @@ -86,7 +86,7 @@ public class ArmorStandWatcher extends LivingWatcher private void setArmorStandFlag(int value, boolean isTrue) { - byte b1 = (byte) getValue(FlagType.ARMORSTAND_META); + byte b1 = (byte) getData(FlagType.ARMORSTAND_META); if (isTrue) { @@ -97,7 +97,7 @@ public class ArmorStandWatcher extends LivingWatcher b1 = (byte) (b1 & value); } - setValue(FlagType.ARMORSTAND_META, b1); + setData(FlagType.ARMORSTAND_META, b1); sendData(FlagType.ARMORSTAND_META); } @@ -141,7 +141,7 @@ public class ArmorStandWatcher extends LivingWatcher private void setPose(FlagType type, EulerAngle vector) { - setValue(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ())); + setData(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ())); sendData(type); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 557edfe8..5cb77f0c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -13,12 +13,12 @@ public class ArrowWatcher extends FlagWatcher public boolean isCritical() { - return (byte) getValue(FlagType.ARROW_CRITICAL) == 1; + return (byte) getData(FlagType.ARROW_CRITICAL) == 1; } public void setCritical(boolean critical) { - setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); + setData(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); sendData(FlagType.ARROW_CRITICAL); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java index 92de7089..5101bd40 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java @@ -15,12 +15,12 @@ public class BatWatcher extends InsentientWatcher public boolean isHanging() { - return ((byte) getValue(FlagType.BAT_HANGING)) == 1; + return ((byte) getData(FlagType.BAT_HANGING)) == 1; } public void setHanging(boolean hanging) { - setValue(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); + setData(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); sendData(FlagType.BAT_HANGING); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java index 70dd4aec..8ccfbfcf 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java @@ -12,12 +12,12 @@ public class BlazeWatcher extends InsentientWatcher public boolean isBlazing() { - return getValue(FlagType.BLAZE_BLAZING) == 1; + return getData(FlagType.BLAZE_BLAZING) == 1; } public void setBlazing(boolean isBlazing) { - setValue(FlagType.BLAZE_BLAZING, (byte) (isBlazing ? 1 : 0)); + setData(FlagType.BLAZE_BLAZING, (byte) (isBlazing ? 1 : 0)); sendData(FlagType.BLAZE_BLAZING); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java index ded624f5..bbc25760 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java @@ -19,46 +19,46 @@ public class BoatWatcher extends FlagWatcher public float getDamage() { - return getValue(FlagType.BOAT_DAMAGE); + return getData(FlagType.BOAT_DAMAGE); } public void setDamage(float dmg) { - setValue(FlagType.BOAT_DAMAGE, dmg); + setData(FlagType.BOAT_DAMAGE, dmg); sendData(FlagType.BOAT_DAMAGE); } public void setRightPaddling(boolean rightPaddling) { - setValue(FlagType.BOAT_RIGHT_PADDLING, rightPaddling); + setData(FlagType.BOAT_RIGHT_PADDLING, rightPaddling); sendData(FlagType.BOAT_RIGHT_PADDLING); } public void setLeftPaddling(boolean leftPaddling) { - setValue(FlagType.BOAT_LEFT_PADDLING, leftPaddling); + setData(FlagType.BOAT_LEFT_PADDLING, leftPaddling); sendData(FlagType.BOAT_LEFT_PADDLING); } public boolean isRightPaddling() { - return getValue(FlagType.BOAT_RIGHT_PADDLING); + return getData(FlagType.BOAT_RIGHT_PADDLING); } public boolean isLeftPaddling() { - return getValue(FlagType.BOAT_LEFT_PADDLING); + return getData(FlagType.BOAT_LEFT_PADDLING); } public void setBoatType(TreeSpecies boatType) { - setValue(FlagType.BOAT_TYPE, (int) boatType.getData()); + setData(FlagType.BOAT_TYPE, (int) boatType.getData()); sendData(FlagType.BOAT_TYPE); } public TreeSpecies getBoatType() { - return TreeSpecies.getByData(getValue(FlagType.BOAT_TYPE).byteValue()); + return TreeSpecies.getByData(getData(FlagType.BOAT_TYPE).byteValue()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java index 4be31cb6..b17dc251 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java @@ -13,23 +13,23 @@ public class CreeperWatcher extends InsentientWatcher public boolean isIgnited() { - return (boolean) getValue(FlagType.CREEPER_IGNITED); + return (boolean) getData(FlagType.CREEPER_IGNITED); } public boolean isPowered() { - return (boolean) getValue(FlagType.CREEPER_POWERED); + return (boolean) getData(FlagType.CREEPER_POWERED); } public void setIgnited(boolean ignited) { - setValue(FlagType.CREEPER_IGNITED, ignited); + setData(FlagType.CREEPER_IGNITED, ignited); sendData(FlagType.CREEPER_IGNITED); } public void setPowered(boolean powered) { - setValue(FlagType.CREEPER_POWERED, powered); + setData(FlagType.CREEPER_POWERED, powered); sendData(FlagType.CREEPER_POWERED); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/DonkeyWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/DonkeyWatcher.java new file mode 100644 index 00000000..7fbaad49 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/DonkeyWatcher.java @@ -0,0 +1,11 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +public class DonkeyWatcher extends HorseChestedWatcher { + + public DonkeyWatcher(Disguise disguise) { + super(disguise); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java index 94436d0f..3b6e484e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java @@ -17,12 +17,12 @@ public class DroppedItemWatcher extends FlagWatcher public ItemStack getItemStack() { - return getValue(FlagType.DROPPED_ITEM).get(); + return getData(FlagType.DROPPED_ITEM).get(); } public void setItemStack(ItemStack item) { - setValue(FlagType.DROPPED_ITEM, Optional. of(item)); + setData(FlagType.DROPPED_ITEM, Optional. of(item)); sendData(FlagType.DROPPED_ITEM); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java index 94f91856..7e69b80a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java @@ -1,42 +1,42 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import com.comphenix.protocol.wrappers.BlockPosition; -import com.google.common.base.Optional; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; -import me.libraryaddict.disguise.disguisetypes.FlagWatcher; - -/** - * @author Navid - */ -public class EnderCrystalWatcher extends FlagWatcher -{ - public EnderCrystalWatcher(Disguise disguise) - { - super(disguise); - } - - public void setBeamTarget(BlockPosition position) - { - setValue(FlagType.ENDER_CRYSTAL_BEAM, Optional.of(position)); - sendData(FlagType.ENDER_CRYSTAL_BEAM); - } - - public Optional getBeamTarget() - { - return getValue(FlagType.ENDER_CRYSTAL_BEAM); - } - - public void setShowBottom(boolean bool) - { - setValue(FlagType.ENDER_CRYSTAL_PLATE, bool); - sendData(FlagType.ENDER_CRYSTAL_PLATE); - } - - public boolean isShowBottom() - { - return getValue(FlagType.ENDER_CRYSTAL_PLATE); - } - -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import com.comphenix.protocol.wrappers.BlockPosition; +import com.google.common.base.Optional; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; + +/** + * @author Navid + */ +public class EnderCrystalWatcher extends FlagWatcher +{ + public EnderCrystalWatcher(Disguise disguise) + { + super(disguise); + } + + public void setBeamTarget(BlockPosition position) + { + setData(FlagType.ENDER_CRYSTAL_BEAM, Optional.of(position)); + sendData(FlagType.ENDER_CRYSTAL_BEAM); + } + + public Optional getBeamTarget() + { + return getData(FlagType.ENDER_CRYSTAL_BEAM); + } + + public void setShowBottom(boolean bool) + { + setData(FlagType.ENDER_CRYSTAL_PLATE, bool); + sendData(FlagType.ENDER_CRYSTAL_PLATE); + } + + public boolean isShowBottom() + { + return getData(FlagType.ENDER_CRYSTAL_PLATE); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java index ad9cbadb..5bb62a3e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java @@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher public int getPhase() { - return getValue(FlagType.ENDERDRAGON_PHASE); + return getData(FlagType.ENDERDRAGON_PHASE); } public void setPhase(int phase) { - setValue(FlagType.ENDERDRAGON_PHASE, phase); + setData(FlagType.ENDERDRAGON_PHASE, phase); sendData(FlagType.ENDERDRAGON_PHASE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index ecb0d84b..5388cfad 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -20,7 +20,7 @@ public class EndermanWatcher extends InsentientWatcher @Override public ItemStack getItemInMainHand() { - Optional value = getValue(FlagType.ENDERMAN_ITEM); + Optional value = getData(FlagType.ENDERMAN_ITEM); if (value.isPresent()) { @@ -62,7 +62,7 @@ public class EndermanWatcher extends InsentientWatcher else optional = Optional. of(WrappedBlockData.createData(type, data)); - setValue(FlagType.ENDERMAN_ITEM, optional); + setData(FlagType.ENDERMAN_ITEM, optional); } @Deprecated @@ -73,12 +73,12 @@ public class EndermanWatcher extends InsentientWatcher public boolean isAggressive() { - return getValue(FlagType.ENDERMAN_AGRESSIVE); + return getData(FlagType.ENDERMAN_AGRESSIVE); } public void setAggressive(boolean isAggressive) { - setValue(FlagType.ENDERMAN_AGRESSIVE, isAggressive); + setData(FlagType.ENDERMAN_AGRESSIVE, isAggressive); sendData(FlagType.ENDERMAN_AGRESSIVE); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EvokerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EvokerWatcher.java new file mode 100644 index 00000000..c4b0d954 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EvokerWatcher.java @@ -0,0 +1,20 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class EvokerWatcher extends InsentientWatcher { + + public EvokerWatcher(Disguise disguise) { + super(disguise); + } + + public void setSpellTicks(int spellTicks) { + setData(FlagType.EVOKER_SPELL_TICKS, (byte) spellTicks); + sendData(FlagType.EVOKER_SPELL_TICKS); + } + + public int getSpellTicks() { + return getData(FlagType.EVOKER_SPELL_TICKS); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java index b54bb007..433dc3a3 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java @@ -18,12 +18,12 @@ public class FireworkWatcher extends FlagWatcher public ItemStack getFirework() { - if (getValue(FlagType.FIREWORK_ITEM) == null) + if (getData(FlagType.FIREWORK_ITEM) == null) { return new ItemStack(Material.AIR); } - return (ItemStack) getValue(FlagType.FIREWORK_ITEM).get(); + return (ItemStack) getData(FlagType.FIREWORK_ITEM).get(); } public void setFirework(ItemStack newItem) @@ -36,7 +36,7 @@ public class FireworkWatcher extends FlagWatcher newItem = newItem.clone(); newItem.setAmount(1); - setValue(FlagType.FIREWORK_ITEM, Optional. of(newItem)); + setData(FlagType.FIREWORK_ITEM, Optional. of(newItem)); sendData(FlagType.FIREWORK_ITEM); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java index 8a8aa7c1..490da6dc 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java @@ -13,13 +13,13 @@ public class FishingHookWatcher extends FlagWatcher public void setHooked(int hookedId) { - setValue(FlagType.FISHING_HOOK, hookedId + 1); + setData(FlagType.FISHING_HOOK, hookedId + 1); sendData(FlagType.FISHING_HOOK); } public int getHooked() { - int hooked = getValue(FlagType.FISHING_HOOK); + int hooked = getData(FlagType.FISHING_HOOK); if (hooked > 0) hooked--; diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java index 4d21b5de..46cd3eb6 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java @@ -13,12 +13,12 @@ public class GhastWatcher extends InsentientWatcher public boolean isAggressive() { - return getValue(FlagType.GHAST_AGRESSIVE); + return getData(FlagType.GHAST_AGRESSIVE); } public void setAggressive(boolean isAggressive) { - setValue(FlagType.GHAST_AGRESSIVE, isAggressive); + setData(FlagType.GHAST_AGRESSIVE, isAggressive); sendData(FlagType.GHAST_AGRESSIVE); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java index aeb64d9d..4034c31e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java @@ -22,7 +22,7 @@ public class GuardianWatcher extends InsentientWatcher */ public boolean isTarget() { - return ((int) getValue(FlagType.GUARDIAN_TARGET)) != 0; + return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0; } /** @@ -32,7 +32,7 @@ public class GuardianWatcher extends InsentientWatcher */ public void setTarget(int entityId) { - setValue(FlagType.GUARDIAN_TARGET, entityId); + setData(FlagType.GUARDIAN_TARGET, entityId); sendData(FlagType.GUARDIAN_TARGET); } @@ -53,7 +53,7 @@ public class GuardianWatcher extends InsentientWatcher if (player == null) return; - setValue(FlagType.GUARDIAN_TARGET, player.getEntityId()); + setData(FlagType.GUARDIAN_TARGET, player.getEntityId()); sendData(FlagType.GUARDIAN_TARGET); } @@ -79,20 +79,20 @@ public class GuardianWatcher extends InsentientWatcher protected boolean isGuardianFlag(int no) { - return (getValue(FlagType.GUARDIAN_FLAG) & no) != 0; + return (getData(FlagType.GUARDIAN_FLAG) & no) != 0; } protected void setGuardianFlag(int no, boolean flag) { - byte b0 = getValue(FlagType.GUARDIAN_FLAG); + byte b0 = getData(FlagType.GUARDIAN_FLAG); if (flag) { - setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); + setData(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); } else { - setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); + setData(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); } sendData(FlagType.GUARDIAN_FLAG); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseAbstractWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseAbstractWatcher.java new file mode 100644 index 00000000..eaa58b2c --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseAbstractWatcher.java @@ -0,0 +1,101 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import java.util.UUID; + +import com.google.common.base.Optional; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class HorseAbstractWatcher extends AgeableWatcher { + public HorseAbstractWatcher(Disguise disguise) { + super(disguise); + } + + public Optional getOwner() { + return getData(FlagType.HORSE_OWNER); + } + + public boolean hasChest() { + return isHorseFlag(8); + } + + public boolean isBreedable() { + return isHorseFlag(16); + } + + public boolean isGrazing() { + return isHorseFlag(32); + } + + public boolean isMouthOpen() { + return isHorseFlag(128); + } + + public boolean isRearing() { + return isHorseFlag(64); + } + + public boolean isSaddled() { + return isHorseFlag(4); + } + + public boolean isTamed() { + return isHorseFlag(2); + } + + private boolean isHorseFlag(int i) { + return (getHorseFlag() & i) != 0; + } + + private byte getHorseFlag() { + return getData(FlagType.HORSE_META); + } + + public void setCanBreed(boolean breed) { + setHorseFlag(16, breed); + } + + public void setCarryingChest(boolean chest) { + setHorseFlag(8, chest); + } + + private void setHorseFlag(int i, boolean flag) { + byte j = getData(FlagType.HORSE_META); + + if (flag) { + setData(FlagType.HORSE_META, (byte) (j | i)); + } + else { + setData(FlagType.HORSE_META, (byte) (j & ~i)); + } + + sendData(FlagType.HORSE_META); + } + + public void setGrazing(boolean grazing) { + setHorseFlag(32, grazing); + } + + public void setMouthOpen(boolean mouthOpen) { + setHorseFlag(128, mouthOpen); + } + + public void setOwner(UUID uuid) { + setData(FlagType.HORSE_OWNER, Optional.of(uuid)); + sendData(FlagType.HORSE_OWNER); + } + + public void setRearing(boolean rear) { + setHorseFlag(64, rear); + } + + public void setSaddled(boolean saddled) { + setHorseFlag(4, saddled); + } + + public void setTamed(boolean tamed) { + setHorseFlag(2, tamed); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java new file mode 100644 index 00000000..5153909a --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java @@ -0,0 +1,20 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class HorseChestedWatcher extends HorseAbstractWatcher { + + public HorseChestedWatcher(Disguise disguise) { + super(disguise); + } + + public void setCarryingChest(boolean carryingChest) { + setData(FlagType.HORSE_CARRYING_CHEST, carryingChest); + sendData(FlagType.HORSE_CARRYING_CHEST); + } + + public boolean isCarryingChest() { + return getData(FlagType.HORSE_CARRYING_CHEST); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java index c0015e5f..04dc028c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java @@ -1,61 +1,30 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import java.util.UUID; - import org.bukkit.Material; import org.bukkit.entity.Horse.Color; import org.bukkit.entity.Horse.Style; -import org.bukkit.entity.Horse.Variant; import org.bukkit.inventory.ItemStack; -import com.google.common.base.Optional; - import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class HorseWatcher extends AgeableWatcher -{ - public HorseWatcher(Disguise disguise) - { +public class HorseWatcher extends HorseAbstractWatcher { + public HorseWatcher(Disguise disguise) { super(disguise); setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]); setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]); } - public Variant getVariant() - { - return Variant.values()[getValue(FlagType.HORSE_VARIANT)]; + public Color getColor() { + return Color.values()[((Integer) getData(FlagType.HORSE_COLOR) & 0xFF)]; } - public void setVariant(Variant variant) - { - setVariant(variant.ordinal()); - } - - public void setVariant(int variant) - { - if (variant < 0 || variant > 4) - { - variant = 0; // Crashing people is mean - } - - setValue(FlagType.HORSE_VARIANT, variant); - sendData(FlagType.HORSE_VARIANT); - } - - public Color getColor() - { - return Color.values()[((Integer) getValue(FlagType.HORSE_COLOR) & 0xFF)]; - } - - public ItemStack getHorseArmor() - { + public ItemStack getHorseArmor() { int horseValue = getHorseArmorAsInt(); - switch (horseValue) - { + switch (horseValue) { case 1: return new ItemStack(Material.IRON_BARDING); case 2: @@ -69,127 +38,42 @@ public class HorseWatcher extends AgeableWatcher return null; } - protected int getHorseArmorAsInt() - { - return getValue(FlagType.HORSE_ARMOR); + public Style getStyle() { + return Style.values()[(getData(FlagType.HORSE_COLOR) >>> 8)]; } - public Optional getOwner() - { - return getValue(FlagType.HORSE_OWNER); - } - - public Style getStyle() - { - return Style.values()[(getValue(FlagType.HORSE_COLOR) >>> 8)]; - } - - public boolean hasChest() - { - return isHorseFlag(8); - } - - public boolean isBreedable() - { - return isHorseFlag(16); - } - - public boolean isGrazing() - { - return isHorseFlag(32); - } - - public boolean isMouthOpen() - { - return isHorseFlag(128); - } - - public boolean isRearing() - { - return isHorseFlag(64); - } - - public boolean isSaddled() - { - return isHorseFlag(4); - } - - public boolean isTamed() - { - return isHorseFlag(2); - } - - private boolean isHorseFlag(int i) - { - return (getHorseFlag() & i) != 0; - } - - private byte getHorseFlag() - { - return getValue(FlagType.HORSE_META); - } - - public void setCanBreed(boolean breed) - { - setHorseFlag(16, breed); - } - - public void setCarryingChest(boolean chest) - { - setHorseFlag(8, chest); - } - - public void setColor(Color color) - { - setValue(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); + public void setColor(Color color) { + setData(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); sendData(FlagType.HORSE_COLOR); } - private void setHorseFlag(int i, boolean flag) - { - byte j = getValue(FlagType.HORSE_META); - - if (flag) - { - setValue(FlagType.HORSE_META, (byte) (j | i)); - } - else - { - setValue(FlagType.HORSE_META, (byte) (j & ~i)); - } - - sendData(FlagType.HORSE_META); + protected int getHorseArmorAsInt() { + return getData(FlagType.HORSE_ARMOR); } - public void setGrazing(boolean grazing) - { - setHorseFlag(32, grazing); - } - - protected void setHorseArmor(int armor) - { - setValue(FlagType.HORSE_ARMOR, armor); + protected void setHorseArmor(int armor) { + setData(FlagType.HORSE_ARMOR, armor); sendData(FlagType.HORSE_ARMOR); } - public void setHorseArmor(ItemStack item) - { + public void setStyle(Style style) { + setData(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); + sendData(FlagType.HORSE_COLOR); + } + + public void setHorseArmor(ItemStack item) { int value = 0; - if (item != null) - { + if (item != null) { Material mat = item.getType(); - if (mat == Material.IRON_BARDING) - { + if (mat == Material.IRON_BARDING) { value = 1; } - else if (mat == Material.GOLD_BARDING) - { + else if (mat == Material.GOLD_BARDING) { value = 2; } - else if (mat == Material.DIAMOND_BARDING) - { + else if (mat == Material.DIAMOND_BARDING) { value = 3; } } @@ -197,36 +81,4 @@ public class HorseWatcher extends AgeableWatcher setHorseArmor(value); } - public void setMouthOpen(boolean mouthOpen) - { - setHorseFlag(128, mouthOpen); - } - - public void setOwner(UUID uuid) - { - setValue(FlagType.HORSE_OWNER, Optional.of(uuid)); - sendData(FlagType.HORSE_OWNER); - } - - public void setRearing(boolean rear) - { - setHorseFlag(64, rear); - } - - public void setSaddled(boolean saddled) - { - setHorseFlag(4, saddled); - } - - public void setStyle(Style style) - { - setValue(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); - sendData(FlagType.HORSE_COLOR); - } - - public void setTamed(boolean tamed) - { - setHorseFlag(2, tamed); - } - } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java index b559ec43..5a6dadae 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java @@ -36,20 +36,20 @@ public class InsentientWatcher extends LivingWatcher private void setInsentientFlag(int i, boolean flag) { - byte b0 = (byte) getValue(FlagType.INSENTIENT_META); + byte b0 = (byte) getData(FlagType.INSENTIENT_META); if (flag) { - setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i)); + setData(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i)); } else { - setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i))); + setData(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i))); } } private boolean getInsentientFlag(int i) { - return ((byte) getValue(FlagType.INSENTIENT_META) & 1 << i) != 0; + return ((byte) getData(FlagType.INSENTIENT_META) & 1 << i) != 0; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java index 2dd5e6cd..a8b0f337 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java @@ -18,17 +18,17 @@ public class ItemFrameWatcher extends FlagWatcher public ItemStack getItem() { - if (getValue(FlagType.ITEMFRAME_ITEM) == null) + if (getData(FlagType.ITEMFRAME_ITEM) == null) { return new ItemStack(Material.AIR); } - return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM).get(); + return (ItemStack) getData(FlagType.ITEMFRAME_ITEM).get(); } public int getRotation() { - return getValue(FlagType.ITEMFRAME_ROTATION); + return getData(FlagType.ITEMFRAME_ROTATION); } public void setItem(ItemStack newItem) @@ -41,13 +41,13 @@ public class ItemFrameWatcher extends FlagWatcher newItem = newItem.clone(); newItem.setAmount(1); - setValue(FlagType.ITEMFRAME_ITEM, Optional. of(newItem)); + setData(FlagType.ITEMFRAME_ITEM, Optional. of(newItem)); sendData(FlagType.ITEMFRAME_ITEM); } public void setRotation(int rotation) { - setValue(FlagType.ITEMFRAME_ROTATION, rotation % 4); + setData(FlagType.ITEMFRAME_ROTATION, rotation % 4); sendData(FlagType.ITEMFRAME_ROTATION); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 972b7774..241ab06f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -82,7 +82,7 @@ public class LivingWatcher extends FlagWatcher public float getHealth() { - return (float) getValue(FlagType.LIVING_HEALTH); + return (float) getData(FlagType.LIVING_HEALTH); } public double getMaxHealth() @@ -92,7 +92,7 @@ public class LivingWatcher extends FlagWatcher public boolean isPotionParticlesAmbient() { - return (boolean) getValue(FlagType.LIVING_POTION_AMBIENT); + return (boolean) getData(FlagType.LIVING_POTION_AMBIENT); } private int getPotions() @@ -152,30 +152,30 @@ public class LivingWatcher extends FlagWatcher public void setPotionParticlesAmbient(boolean particles) { - setValue(FlagType.LIVING_POTION_AMBIENT, particles); + setData(FlagType.LIVING_POTION_AMBIENT, particles); sendData(FlagType.LIVING_POTION_AMBIENT); } private void sendPotionEffects() { - setValue(FlagType.LIVING_POTIONS, getPotions()); + setData(FlagType.LIVING_POTIONS, getPotions()); sendData(FlagType.LIVING_POTIONS); } public void setHealth(float health) { - setValue(FlagType.LIVING_HEALTH, health); + setData(FlagType.LIVING_HEALTH, health); sendData(FlagType.LIVING_HEALTH); } public int getArrowsSticking() { - return (int) getValue(FlagType.LIVING_ARROWS); + return (int) getData(FlagType.LIVING_ARROWS); } public void setArrowsSticking(int arrowsNo) { - setValue(FlagType.LIVING_ARROWS, arrowsNo); + setData(FlagType.LIVING_ARROWS, arrowsNo); sendData(FlagType.LIVING_ARROWS); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java new file mode 100644 index 00000000..3fbaddc9 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LlamaWatcher.java @@ -0,0 +1,42 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import org.bukkit.entity.Llama; + +import me.libraryaddict.disguise.disguisetypes.AnimalColor; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class LlamaWatcher extends HorseChestedWatcher { + + public LlamaWatcher(Disguise disguise) { + super(disguise); + } + + public void setColor(Llama.Color color) { + setData(FlagType.LLAMA_COLOR, color.ordinal()); + sendData(FlagType.LLAMA_COLOR); + } + + public Llama.Color getColor() { + return Llama.Color.values()[getData(FlagType.LLAMA_COLOR)]; + } + + public void setCarpet(AnimalColor color) { + setData(FlagType.LLAMA_CARPET, color.ordinal()); + sendData(FlagType.LLAMA_CARPET); + } + + public AnimalColor getCarpet() { + return AnimalColor.getColor(getData(FlagType.LLAMA_CARPET)); + } + + public void setStrength(int strength) { + setData(FlagType.LLAMA_STRENGTH, strength); + sendData(FlagType.LLAMA_STRENGTH); + } + + public int getStrength() { + return getData(FlagType.LLAMA_STRENGTH); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index 091d9120..4597c618 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -16,20 +16,20 @@ public class MinecartWatcher extends FlagWatcher public ItemStack getBlockInCart() { - int id = (int) getValue(FlagType.MINECART_BLOCK) & 0xffff; - int data = (int) getValue(FlagType.MINECART_BLOCK) >> 16; + int id = (int) getData(FlagType.MINECART_BLOCK) & 0xffff; + int data = (int) getData(FlagType.MINECART_BLOCK) >> 16; return new ItemStack(id, 1, (short) data); } public int getBlockYOffset() { - return (int) getValue(FlagType.MINECART_BLOCK_Y); + return (int) getData(FlagType.MINECART_BLOCK_Y); } public boolean isViewBlockInCart() { - return (boolean) getValue(FlagType.MINECART_BLOCK_VISIBLE); + return (boolean) getData(FlagType.MINECART_BLOCK_VISIBLE); } public void setBlockInCart(ItemStack item) @@ -37,21 +37,21 @@ public class MinecartWatcher extends FlagWatcher int id = item.getTypeId(); int data = item.getDurability(); - setValue(FlagType.MINECART_BLOCK, id & 0xffff | data << 16); - setValue(FlagType.MINECART_BLOCK_VISIBLE, true); // Show block + setData(FlagType.MINECART_BLOCK, id & 0xffff | data << 16); + setData(FlagType.MINECART_BLOCK_VISIBLE, true); // Show block sendData(FlagType.MINECART_BLOCK); } public void setBlockOffset(int i) { - setValue(FlagType.MINECART_BLOCK_Y, i); + setData(FlagType.MINECART_BLOCK_Y, i); sendData(FlagType.MINECART_BLOCK_Y); } public void setViewBlockInCart(boolean viewBlock) { - setValue(FlagType.MINECART_BLOCK_VISIBLE, viewBlock); + setData(FlagType.MINECART_BLOCK_VISIBLE, viewBlock); sendData(FlagType.MINECART_BLOCK_VISIBLE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MuleWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/MuleWatcher.java new file mode 100644 index 00000000..fe57446b --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/MuleWatcher.java @@ -0,0 +1,11 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +public class MuleWatcher extends HorseChestedWatcher { + + public MuleWatcher(Disguise disguise) { + super(disguise); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java index c7a7828a..4c1e2cc3 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java @@ -1,27 +1,27 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import org.bukkit.entity.Ocelot; -import org.bukkit.entity.Ocelot.Type; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; - -public class OcelotWatcher extends TameableWatcher -{ - - public OcelotWatcher(Disguise disguise) - { - super(disguise); - } - - public Type getType() - { - return Ocelot.Type.getType(getValue(FlagType.OCELOT_TYPE)); - } - - public void setType(Type newType) - { - setValue(FlagType.OCELOT_TYPE, newType.getId()); - sendData(FlagType.OCELOT_TYPE); - } -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import org.bukkit.entity.Ocelot; +import org.bukkit.entity.Ocelot.Type; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class OcelotWatcher extends TameableWatcher +{ + + public OcelotWatcher(Disguise disguise) + { + super(disguise); + } + + public Type getType() + { + return Ocelot.Type.getType(getData(FlagType.OCELOT_TYPE)); + } + + public void setType(Type newType) + { + setData(FlagType.OCELOT_TYPE, newType.getId()); + sendData(FlagType.OCELOT_TYPE); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java index 8e0cbc80..798bd19c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java @@ -1,24 +1,24 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; - -public class PigWatcher extends AgeableWatcher -{ - - public PigWatcher(Disguise disguise) - { - super(disguise); - } - - public boolean isSaddled() - { - return (boolean) getValue(FlagType.PIG_SADDLED); - } - - public void setSaddled(boolean isSaddled) - { - setValue(FlagType.PIG_SADDLED, isSaddled); - sendData(FlagType.PIG_SADDLED); - } -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class PigWatcher extends AgeableWatcher +{ + + public PigWatcher(Disguise disguise) + { + super(disguise); + } + + public boolean isSaddled() + { + return (boolean) getData(FlagType.PIG_SADDLED); + } + + public void setSaddled(boolean isSaddled) + { + setData(FlagType.PIG_SADDLED, isSaddled); + sendData(FlagType.PIG_SADDLED); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java index fff75f7d..15e2b2c3 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java @@ -26,7 +26,7 @@ public class PlayerWatcher extends LivingWatcher { super(disguise); - setValue(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault()); + setData(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault()); } @Override @@ -39,13 +39,13 @@ public class PlayerWatcher extends LivingWatcher public void setMainHand(MainHand mainHand) { - setValue(FlagType.PLAYER_HAND, (byte) mainHand.ordinal()); + setData(FlagType.PLAYER_HAND, (byte) mainHand.ordinal()); sendData(FlagType.PLAYER_HAND); } public MainHand getMainHand() { - return MainHand.values()[getValue(FlagType.PLAYER_HAND)]; + return MainHand.values()[getData(FlagType.PLAYER_HAND)]; } public BlockFace getSleepingDirection() @@ -75,7 +75,7 @@ public class PlayerWatcher extends LivingWatcher private boolean isSkinFlag(int i) { - return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0; + return ((byte) getData(FlagType.PLAYER_SKIN) & 1 << i) != 0; } public boolean isCapeEnabled() @@ -257,15 +257,15 @@ public class PlayerWatcher extends LivingWatcher private void setSkinFlags(int i, boolean flag) { - byte b0 = (byte) getValue(FlagType.PLAYER_SKIN); + byte b0 = (byte) getData(FlagType.PLAYER_SKIN); if (flag) { - setValue(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); + setData(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); } else { - setValue(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); + setData(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PolarBearWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PolarBearWatcher.java index 42f4ab1f..9201cefe 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PolarBearWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PolarBearWatcher.java @@ -12,12 +12,12 @@ public class PolarBearWatcher extends AgeableWatcher public void setStanding(boolean standing) { - setValue(FlagType.POLAR_BEAR_STANDING, standing); + setData(FlagType.POLAR_BEAR_STANDING, standing); sendData(FlagType.POLAR_BEAR_STANDING); } public boolean isStanding() { - return getValue(FlagType.POLAR_BEAR_STANDING); + return getData(FlagType.POLAR_BEAR_STANDING); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java index 1415db11..6837d3b8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java @@ -1,28 +1,28 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; -import me.libraryaddict.disguise.disguisetypes.RabbitType; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; - -public class RabbitWatcher extends AgeableWatcher -{ - - public RabbitWatcher(Disguise disguise) - { - super(disguise); - setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]); - } - - public RabbitType getType() - { - return RabbitType.getType((int) getValue(FlagType.RABBIT_TYPE)); - } - - public void setType(RabbitType type) - { - setValue(FlagType.RABBIT_TYPE, type.getTypeId()); - sendData(FlagType.RABBIT_TYPE); - } - -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; +import me.libraryaddict.disguise.disguisetypes.RabbitType; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; + +public class RabbitWatcher extends AgeableWatcher +{ + + public RabbitWatcher(Disguise disguise) + { + super(disguise); + setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]); + } + + public RabbitType getType() + { + return RabbitType.getType((int) getData(FlagType.RABBIT_TYPE)); + } + + public void setType(RabbitType type) + { + setData(FlagType.RABBIT_TYPE, type.getTypeId()); + sendData(FlagType.RABBIT_TYPE); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java index 63b44789..c4d57e3f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java @@ -1,57 +1,57 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import org.bukkit.DyeColor; - -import me.libraryaddict.disguise.disguisetypes.AnimalColor; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; - -public class SheepWatcher extends AgeableWatcher -{ - - public SheepWatcher(Disguise disguise) - { - super(disguise); - - setValue(FlagType.SHEEP_WOOL, (byte) 0); - } - - public AnimalColor getColor() - { - return AnimalColor.getColor(((int) getValue(FlagType.SHEEP_WOOL) & 15)); - } - - public boolean isSheared() - { - return ((byte) getValue(FlagType.SHEEP_WOOL) & 16) != 0; - } - - public void setColor(AnimalColor color) - { - setColor(DyeColor.getByWoolData((byte) color.getId())); - } - - public void setColor(DyeColor color) - { - byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); - - setValue(FlagType.SHEEP_WOOL, (byte) (b0 & 240 | color.getWoolData() & 15)); - sendData(FlagType.SHEEP_WOOL); - } - - public void setSheared(boolean flag) - { - byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); - - if (flag) - { - setValue(FlagType.SHEEP_WOOL, (byte) (b0 | 16)); - } - else - { - setValue(FlagType.SHEEP_WOOL, (byte) (b0 & -17)); - } - - sendData(FlagType.SHEEP_WOOL); - } -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import org.bukkit.DyeColor; + +import me.libraryaddict.disguise.disguisetypes.AnimalColor; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class SheepWatcher extends AgeableWatcher +{ + + public SheepWatcher(Disguise disguise) + { + super(disguise); + + setData(FlagType.SHEEP_WOOL, (byte) 0); + } + + public AnimalColor getColor() + { + return AnimalColor.getColor(((int) getData(FlagType.SHEEP_WOOL) & 15)); + } + + public boolean isSheared() + { + return ((byte) getData(FlagType.SHEEP_WOOL) & 16) != 0; + } + + public void setColor(AnimalColor color) + { + setColor(DyeColor.getByWoolData((byte) color.getId())); + } + + public void setColor(DyeColor color) + { + byte b0 = (byte) getData(FlagType.SHEEP_WOOL); + + setData(FlagType.SHEEP_WOOL, (byte) (b0 & 240 | color.getWoolData() & 15)); + sendData(FlagType.SHEEP_WOOL); + } + + public void setSheared(boolean flag) + { + byte b0 = (byte) getData(FlagType.SHEEP_WOOL); + + if (flag) + { + setData(FlagType.SHEEP_WOOL, (byte) (b0 | 16)); + } + else + { + setData(FlagType.SHEEP_WOOL, (byte) (b0 & -17)); + } + + sendData(FlagType.SHEEP_WOOL); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java index e3a80167..b42e5a17 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java @@ -6,57 +6,54 @@ import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.google.common.base.Optional; +import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType; /** * @author Navid */ -public class ShulkerWatcher extends InsentientWatcher -{ +public class ShulkerWatcher extends InsentientWatcher { - public ShulkerWatcher(Disguise disguise) - { + public ShulkerWatcher(Disguise disguise) { super(disguise); } - public BlockFace getFacingDirection() - { - return BlockFace.valueOf(getValue(FlagType.SHULKER_FACING).name()); + public BlockFace getFacingDirection() { + return BlockFace.valueOf(getData(FlagType.SHULKER_FACING).name()); } - public void setFacingDirection(BlockFace face) - { - setValue(FlagType.SHULKER_FACING, Direction.valueOf(face.name())); + public void setFacingDirection(BlockFace face) { + setData(FlagType.SHULKER_FACING, Direction.valueOf(face.name())); sendData(FlagType.SHULKER_FACING); } - public BlockPosition getAttachmentPosition() - { - return getValue(FlagType.SHULKER_ATTACHED).get(); + public BlockPosition getAttachmentPosition() { + return getData(FlagType.SHULKER_ATTACHED).get(); } - public void setAttachmentPosition(BlockPosition pos) - { - setValue(FlagType.SHULKER_ATTACHED, Optional.of(pos)); + public void setAttachmentPosition(BlockPosition pos) { + setData(FlagType.SHULKER_ATTACHED, Optional.of(pos)); sendData(FlagType.SHULKER_ATTACHED); } - public int getShieldHeight() - { - return getValue(FlagType.SHULKER_PEEKING); + public int getShieldHeight() { + return getData(FlagType.SHULKER_PEEKING); } - public void setShieldHeight(int newHeight) - { + public void setShieldHeight(int newHeight) { if (newHeight < 0) newHeight = 0; if (newHeight > 127) newHeight = 127; - setValue(FlagType.SHULKER_PEEKING, (byte) newHeight); + setData(FlagType.SHULKER_PEEKING, (byte) newHeight); sendData(FlagType.SHULKER_PEEKING); } + public void setColor(AnimalColor color) { + setData(FlagType.SHULKER_COLOR, (byte) color.getId()); + sendData(FlagType.SHULKER_COLOR); + } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonHorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonHorseWatcher.java new file mode 100644 index 00000000..b75a4bd9 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonHorseWatcher.java @@ -0,0 +1,11 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +public class SkeletonHorseWatcher extends HorseAbstractWatcher { + + public SkeletonHorseWatcher(Disguise disguise) { + super(disguise); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index 5bbcd639..a8a96a1f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -17,23 +17,23 @@ public class SkeletonWatcher extends InsentientWatcher public void setSwingArms(boolean swingingArms) { - setValue(FlagType.SKELETON_SWING_ARMS, swingingArms); + setData(FlagType.SKELETON_SWING_ARMS, swingingArms); sendData(FlagType.SKELETON_SWING_ARMS); } public boolean isSwingArms() { - return getValue(FlagType.SKELETON_SWING_ARMS); + return getData(FlagType.SKELETON_SWING_ARMS); } public void setType(SkeletonType type) { - setValue(FlagType.SKELETON_TYPE, type.ordinal()); + setData(FlagType.SKELETON_TYPE, type.ordinal()); sendData(FlagType.SKELETON_TYPE); } public SkeletonType getType() { - return SkeletonType.values()[getValue(FlagType.SKELETON_TYPE)]; + return SkeletonType.values()[getData(FlagType.SKELETON_TYPE)]; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java index c783ae12..e3b94dca 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java @@ -15,7 +15,7 @@ public class SlimeWatcher extends InsentientWatcher public int getSize() { - return (int) getValue(FlagType.SLIME_SIZE); + return (int) getData(FlagType.SLIME_SIZE); } public void setSize(int size) @@ -25,7 +25,7 @@ public class SlimeWatcher extends InsentientWatcher size = 1; } - setValue(FlagType.SLIME_SIZE, size); + setData(FlagType.SLIME_SIZE, size); sendData(FlagType.SLIME_SIZE); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SnowmanWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SnowmanWatcher.java index c00bba80..ee64ef75 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SnowmanWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SnowmanWatcher.java @@ -12,12 +12,12 @@ public class SnowmanWatcher extends InsentientWatcher public void setHat(boolean hat) { - setValue(FlagType.SNOWMAN_HAT, (byte) (hat ? 0 : 16)); + setData(FlagType.SNOWMAN_HAT, (byte) (hat ? 0 : 16)); sendData(FlagType.SNOWMAN_HAT); } public boolean isHat() { - return getValue(FlagType.SNOWMAN_HAT) == 0; + return getData(FlagType.SNOWMAN_HAT) == 0; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SpiderWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SpiderWatcher.java index 94cf37c4..f032ab4c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SpiderWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SpiderWatcher.java @@ -12,12 +12,12 @@ public class SpiderWatcher extends InsentientWatcher public void setClimbing(boolean climbing) { - setValue(FlagType.SPIDER_CLIMB, (byte) (climbing ? 1 : 0)); + setData(FlagType.SPIDER_CLIMB, (byte) (climbing ? 1 : 0)); sendData(FlagType.SPIDER_CLIMB); } public boolean isClimbing() { - return getValue(FlagType.SPIDER_CLIMB) == (byte) 1; + return getData(FlagType.SPIDER_CLIMB) == (byte) 1; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java index 32c00a4b..971fc1e8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java @@ -34,13 +34,13 @@ public class SplashPotionWatcher extends FlagWatcher public void setSplashPotion(ItemStack item) { - setValue(FlagType.SPLASH_POTION_ITEM, Optional.of(item)); + setData(FlagType.SPLASH_POTION_ITEM, Optional.of(item)); sendData(FlagType.SPLASH_POTION_ITEM); } public ItemStack getSplashPotion() { - return getValue(FlagType.SPLASH_POTION_ITEM).get(); + return getData(FlagType.SPLASH_POTION_ITEM).get(); } public void setPotionId(int newPotionId) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index 76643235..46d10520 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -1,69 +1,69 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import java.util.UUID; - -import com.google.common.base.Optional; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; - -public class TameableWatcher extends AgeableWatcher -{ - public TameableWatcher(Disguise disguise) - { - super(disguise); - } - - public Optional getOwner() - { - return getValue(FlagType.TAMEABLE_OWNER); - } - - public boolean isSitting() - { - return isTameableFlag(1); - } - - public boolean isTamed() - { - return isTameableFlag(4); - } - - protected boolean isTameableFlag(int no) - { - return ((byte) getValue(FlagType.TAMEABLE_META) & no) != 0; - } - - protected void setTameableFlag(int no, boolean flag) - { - byte value = (byte) getValue(FlagType.TAMEABLE_META); - - if (flag) - { - setValue(FlagType.TAMEABLE_META, (byte) (value | no)); - } - else - { - setValue(FlagType.TAMEABLE_META, (byte) (value & -(no + 1))); - } - - sendData(FlagType.TAMEABLE_META); - } - - public void setOwner(UUID owner) - { - setValue(FlagType.TAMEABLE_OWNER, Optional.of(owner)); - sendData(FlagType.TAMEABLE_OWNER); - } - - public void setSitting(boolean sitting) - { - setTameableFlag(1, sitting); - } - - public void setTamed(boolean tamed) - { - setTameableFlag(4, tamed); - } - -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import java.util.UUID; + +import com.google.common.base.Optional; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class TameableWatcher extends AgeableWatcher +{ + public TameableWatcher(Disguise disguise) + { + super(disguise); + } + + public Optional getOwner() + { + return getData(FlagType.TAMEABLE_OWNER); + } + + public boolean isSitting() + { + return isTameableFlag(1); + } + + public boolean isTamed() + { + return isTameableFlag(4); + } + + protected boolean isTameableFlag(int no) + { + return ((byte) getData(FlagType.TAMEABLE_META) & no) != 0; + } + + protected void setTameableFlag(int no, boolean flag) + { + byte value = (byte) getData(FlagType.TAMEABLE_META); + + if (flag) + { + setData(FlagType.TAMEABLE_META, (byte) (value | no)); + } + else + { + setData(FlagType.TAMEABLE_META, (byte) (value & -(no + 1))); + } + + sendData(FlagType.TAMEABLE_META); + } + + public void setOwner(UUID owner) + { + setData(FlagType.TAMEABLE_OWNER, Optional.of(owner)); + sendData(FlagType.TAMEABLE_OWNER); + } + + public void setSitting(boolean sitting) + { + setTameableFlag(1, sitting); + } + + public void setTamed(boolean tamed) + { + setTameableFlag(4, tamed); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java index a033ab4b..484aebc0 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java @@ -25,13 +25,13 @@ public class TippedArrowWatcher extends ArrowWatcher public Color getColor() { - int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR); + int color = (int) getData(FlagType.TIPPED_ARROW_COLOR); return Color.fromRGB(color); } public void setColor(Color color) { - setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB()); + setData(FlagType.TIPPED_ARROW_COLOR, color.asRGB()); sendData(FlagType.TIPPED_ARROW_COLOR); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VexWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/VexWatcher.java new file mode 100644 index 00000000..e1e2341f --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/VexWatcher.java @@ -0,0 +1,21 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class VexWatcher extends InsentientWatcher { + + public VexWatcher(Disguise disguise) { + super(disguise); + } + + public void setAngry(boolean angry) { + setData(FlagType.VEX_ANGRY, angry); + sendData(FlagType.VEX_ANGRY); + } + + public boolean isAngry() { + return getData(FlagType.VEX_ANGRY); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java index d982d3af..3c51941c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java @@ -1,33 +1,33 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import org.bukkit.entity.Villager.Profession; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; - -public class VillagerWatcher extends AgeableWatcher -{ - - public VillagerWatcher(Disguise disguise) - { - super(disguise); - setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); - } - - public Profession getProfession() - { - return Profession.values()[getValue(FlagType.VILLAGER_PROFESSION)]; - } - - public void setProfession(int professionId) - { - setValue(FlagType.VILLAGER_PROFESSION, professionId); - sendData(FlagType.VILLAGER_PROFESSION); - } - - public void setProfession(Profession newProfession) - { - setProfession(newProfession.ordinal()); - } -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import org.bukkit.entity.Villager.Profession; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; + +public class VillagerWatcher extends AgeableWatcher +{ + + public VillagerWatcher(Disguise disguise) + { + super(disguise); + setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); + } + + public Profession getProfession() + { + return Profession.values()[getData(FlagType.VILLAGER_PROFESSION)]; + } + + public void setProfession(int professionId) + { + setData(FlagType.VILLAGER_PROFESSION, professionId); + sendData(FlagType.VILLAGER_PROFESSION); + } + + public void setProfession(Profession newProfession) + { + setProfession(newProfession.ordinal()); + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java new file mode 100644 index 00000000..cfcba3ba --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java @@ -0,0 +1,17 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class VindicatorWatcher extends InsentientWatcher { + + public VindicatorWatcher(Disguise disguise) { + super(disguise); + } + + public void setJohnny(boolean isJohnny) { + setData(FlagType.VINDICATOR_JOHNNY, (byte) (isJohnny ? 1 : 0)); + sendData(FlagType.VINDICATOR_JOHNNY); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java index 0303e49f..4f0a9319 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java @@ -16,12 +16,12 @@ public class WitchWatcher extends InsentientWatcher public boolean isAggressive() { - return (boolean) getValue(FlagType.WITCH_AGGRESSIVE); + return (boolean) getData(FlagType.WITCH_AGGRESSIVE); } public void setAggressive(boolean aggressive) { - setValue(FlagType.WITCH_AGGRESSIVE, aggressive); + setData(FlagType.WITCH_AGGRESSIVE, aggressive); sendData(FlagType.WITCH_AGGRESSIVE); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java index 26d84d32..677e3f56 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java @@ -1,26 +1,26 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; -import me.libraryaddict.disguise.disguisetypes.FlagWatcher; - -public class WitherSkullWatcher extends FlagWatcher -{ - - public WitherSkullWatcher(Disguise disguise) - { - super(disguise); - } - - public boolean isBlue() - { - return (boolean) getValue(FlagType.WITHERSKULL_BLUE); - } - - public void setBlue(boolean blue) - { - setValue(FlagType.WITHERSKULL_BLUE, blue); - sendData(FlagType.WITHERSKULL_BLUE); - } - -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; + +public class WitherSkullWatcher extends FlagWatcher +{ + + public WitherSkullWatcher(Disguise disguise) + { + super(disguise); + } + + public boolean isBlue() + { + return (boolean) getData(FlagType.WITHERSKULL_BLUE); + } + + public void setBlue(boolean blue) + { + setData(FlagType.WITHERSKULL_BLUE, blue); + sendData(FlagType.WITHERSKULL_BLUE); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java index b7020b9f..6245cbc9 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java @@ -22,14 +22,14 @@ public class WitherWatcher extends InsentientWatcher */ public int getInvulnerability() { - return (int) getValue(FlagType.WITHER_INVUL); + return (int) getData(FlagType.WITHER_INVUL); } public int[] getTargets() { return new int[] { - getValue(FlagType.WITHER_TARGET_1), getValue(FlagType.WITHER_TARGET_2), getValue(FlagType.WITHER_TARGET_3) + getData(FlagType.WITHER_TARGET_1), getData(FlagType.WITHER_TARGET_2), getData(FlagType.WITHER_TARGET_3) }; } @@ -38,7 +38,7 @@ public class WitherWatcher extends InsentientWatcher */ public void setInvulnerability(int invulnerability) { - setValue(FlagType.WITHER_INVUL, invulnerability); + setData(FlagType.WITHER_INVUL, invulnerability); sendData(FlagType.WITHER_INVUL); } @@ -49,9 +49,9 @@ public class WitherWatcher extends InsentientWatcher throw new InvalidParameterException( ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length); } - setValue(FlagType.WITHER_TARGET_1, targets[0]); - setValue(FlagType.WITHER_TARGET_2, targets[1]); - setValue(FlagType.WITHER_TARGET_3, targets[2]); + setData(FlagType.WITHER_TARGET_1, targets[0]); + setData(FlagType.WITHER_TARGET_2, targets[1]); + setData(FlagType.WITHER_TARGET_3, targets[2]); sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index 8a7689e8..1b266956 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -1,85 +1,85 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import org.bukkit.DyeColor; - -import me.libraryaddict.disguise.disguisetypes.AnimalColor; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagType; - -public class WolfWatcher extends TameableWatcher -{ - - public WolfWatcher(Disguise disguise) - { - super(disguise); - } - - public AnimalColor getCollarColor() - { - return AnimalColor.getColor(getValue(FlagType.WOLF_COLLAR)); - } - - /** - * Used for tail rotation. - * - * @return - */ - public float getDamageTaken() - { - return (float) getValue(FlagType.WOLF_DAMAGE); - } - - /** - * Used for tail rotation. - * - * @param damage - */ - public void setDamageTaken(float damage) - { - setValue(FlagType.WOLF_DAMAGE, damage); - sendData(FlagType.WOLF_DAMAGE); - } - - public boolean isBegging() - { - return (boolean) getValue(FlagType.WOLF_BEGGING); - } - - public void setBegging(boolean begging) - { - setValue(FlagType.WOLF_BEGGING, begging); - sendData(FlagType.WOLF_BEGGING); - } - - public boolean isAngry() - { - return isTameableFlag(2); - } - - public void setAngry(boolean angry) - { - setTameableFlag(2, angry); - } - - public void setCollarColor(AnimalColor color) - { - setCollarColor(DyeColor.getByWoolData((byte) color.getId())); - } - - public void setCollarColor(DyeColor newColor) - { - if (!isTamed()) - { - setTamed(true); - } - - if (newColor.getWoolData() == getCollarColor().getId()) - { - return; - } - - setValue(FlagType.WOLF_COLLAR, (int) newColor.getDyeData()); - sendData(FlagType.WOLF_COLLAR); - } - -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import org.bukkit.DyeColor; + +import me.libraryaddict.disguise.disguisetypes.AnimalColor; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class WolfWatcher extends TameableWatcher +{ + + public WolfWatcher(Disguise disguise) + { + super(disguise); + } + + public AnimalColor getCollarColor() + { + return AnimalColor.getColor(getData(FlagType.WOLF_COLLAR)); + } + + /** + * Used for tail rotation. + * + * @return + */ + public float getDamageTaken() + { + return (float) getData(FlagType.WOLF_DAMAGE); + } + + /** + * Used for tail rotation. + * + * @param damage + */ + public void setDamageTaken(float damage) + { + setData(FlagType.WOLF_DAMAGE, damage); + sendData(FlagType.WOLF_DAMAGE); + } + + public boolean isBegging() + { + return (boolean) getData(FlagType.WOLF_BEGGING); + } + + public void setBegging(boolean begging) + { + setData(FlagType.WOLF_BEGGING, begging); + sendData(FlagType.WOLF_BEGGING); + } + + public boolean isAngry() + { + return isTameableFlag(2); + } + + public void setAngry(boolean angry) + { + setTameableFlag(2, angry); + } + + public void setCollarColor(AnimalColor color) + { + setCollarColor(DyeColor.getByWoolData((byte) color.getId())); + } + + public void setCollarColor(DyeColor newColor) + { + if (!isTamed()) + { + setTamed(true); + } + + if (newColor.getWoolData() == getCollarColor().getId()) + { + return; + } + + setData(FlagType.WOLF_COLLAR, (int) newColor.getDyeData()); + sendData(FlagType.WOLF_COLLAR); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieHorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieHorseWatcher.java new file mode 100644 index 00000000..39dc5967 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieHorseWatcher.java @@ -0,0 +1,11 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +public class ZombieHorseWatcher extends HorseAbstractWatcher { + + public ZombieHorseWatcher(Disguise disguise) { + super(disguise); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index f2575aa5..3a4bf157 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -20,12 +20,12 @@ public class ZombieWatcher extends InsentientWatcher public boolean isBaby() { - return getValue(FlagType.ZOMBIE_BABY); + return getData(FlagType.ZOMBIE_BABY); } public boolean isShaking() { - return getValue(FlagType.ZOMBIE_SHAKING); + return getData(FlagType.ZOMBIE_SHAKING); } /** @@ -35,12 +35,12 @@ public class ZombieWatcher extends InsentientWatcher */ public boolean isVillager() { - return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0; + return ((int) getData(FlagType.ZOMBIE_PROFESSION)) != 0; } public boolean isAggressive() { - return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE); + return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE); } /** @@ -50,7 +50,7 @@ public class ZombieWatcher extends InsentientWatcher */ public Profession getProfession() { - return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)]; + return Profession.values()[getData(FlagType.ZOMBIE_PROFESSION)]; } public void setAdult() @@ -65,13 +65,13 @@ public class ZombieWatcher extends InsentientWatcher public void setBaby(boolean baby) { - setValue(FlagType.ZOMBIE_BABY, baby); + setData(FlagType.ZOMBIE_BABY, baby); sendData(FlagType.ZOMBIE_BABY); } public void setShaking(boolean shaking) { - setValue(FlagType.ZOMBIE_SHAKING, shaking); + setData(FlagType.ZOMBIE_SHAKING, shaking); sendData(FlagType.ZOMBIE_SHAKING); } @@ -82,7 +82,7 @@ public class ZombieWatcher extends InsentientWatcher */ public void setProfession(int id) { - setValue(FlagType.ZOMBIE_PROFESSION, id); + setData(FlagType.ZOMBIE_PROFESSION, id); sendData(FlagType.ZOMBIE_PROFESSION); } @@ -93,13 +93,13 @@ public class ZombieWatcher extends InsentientWatcher */ public void setProfession(Profession profession) { - setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); + setData(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); sendData(FlagType.ZOMBIE_PROFESSION); } public void setAggressive(boolean handsup) { - setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup); + setData(FlagType.ZOMBIE_AGGRESSIVE, handsup); sendData(FlagType.ZOMBIE_AGGRESSIVE); } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java index 2ff19526..7d90a1ed 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java @@ -8,8 +8,7 @@ import org.bukkit.Sound; /** * Only living disguises go in here! */ -public enum DisguiseSound -{ +public enum DisguiseSound { ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT), @@ -44,6 +43,13 @@ public enum DisguiseSound ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH, Sound.ENTITY_ENDERMITE_AMBIENT), + EVOKER(Sound.ENTITY_EVOCATION_ILLAGER_HURT, null, Sound.ENTITY_EVOCATION_ILLAGER_DEATH, + Sound.ENTITY_EVOCATION_ILLAGER_AMBIENT, Sound.ENTITY_EVOCATION_ILLAGER_CAST_SPELL, + Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_ATTACK, Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON, + Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_WOLOLO), + + EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOCATION_FANGS_ATTACK), + GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN), @@ -58,6 +64,9 @@ public enum DisguiseSound IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH, Sound.ENTITY_IRONGOLEM_ATTACK), + LLAMA(Sound.ENTITY_LLAMA_HURT, Sound.ENTITY_LLAMA_STEP, Sound.ENTITY_LLAMA_DEATH, Sound.ENTITY_LLAMA_AMBIENT, + Sound.ENTITY_LLAMA_ANGRY, Sound.ENTITY_LLAMA_CHEST, Sound.ENTITY_LLAMA_EAT, Sound.ENTITY_LLAMA_SWAG), + MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null), MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT), @@ -104,9 +113,14 @@ public enum DisguiseSound Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY), + VEX(Sound.ENTITY_VEX_HURT, null, Sound.ENTITY_VEX_DEATH, Sound.ENTITY_VEX_AMBIENT, Sound.ENTITY_VEX_CHARGE), + VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT, Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES), + VINDICATOR(Sound.ENTITY_VINDICATION_ILLAGER_HURT, null, Sound.ENTITY_VINDICATION_ILLAGER_DEATH, + Sound.ENTITY_VINDICATION_ILLAGER_AMBIENT), + WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT), WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, @@ -126,19 +140,15 @@ public enum DisguiseSound Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR); - public enum SoundType - { + public enum SoundType { CANCEL, DEATH, HURT, IDLE, STEP } - public static DisguiseSound getType(String name) - { - try - { + public static DisguiseSound getType(String name) { + try { return valueOf(name); } - catch (Exception ex) - { + catch (Exception ex) { return null; } } @@ -147,43 +157,35 @@ public enum DisguiseSound private float damageSoundVolume = 1F; private HashMap disguiseSounds = new HashMap<>(); - DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) - { + DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) { addSound(hurt, SoundType.HURT); addSound(step, SoundType.STEP); addSound(death, SoundType.DEATH); addSound(idle, SoundType.IDLE); - for (Object obj : sounds) - { + for (Object obj : sounds) { addSound(obj, SoundType.CANCEL); } } - private void addSound(Object sound, SoundType type) - { + private void addSound(Object sound, SoundType type) { String s; - if (sound == null) - { + if (sound == null) { return; } - else if (sound instanceof String) - { + else if (sound instanceof String) { s = (String) sound; } - else if (sound instanceof Sound) - { + else if (sound instanceof Sound) { s = ReflectionManager.getCraftSound((Sound) sound); } - else - { + else { throw new RuntimeException("Was given a unknown object " + sound); } - switch (type) - { + switch (type) { case HURT: disguiseSounds.put(SoundType.HURT, s); break; @@ -201,58 +203,47 @@ public enum DisguiseSound } } - public float getDamageAndIdleSoundVolume() - { + public float getDamageAndIdleSoundVolume() { return damageSoundVolume; } - public String getSound(SoundType type) - { - if (type == null || !disguiseSounds.containsKey(type)) - { + public String getSound(SoundType type) { + if (type == null || !disguiseSounds.containsKey(type)) { return null; } return disguiseSounds.get(type); } - public HashSet getSoundsToCancel() - { + public HashSet getSoundsToCancel() { return cancelSounds; } /** * Used to check if this sound name is owned by this disguise sound. */ - public SoundType getType(String sound, boolean ignoreDamage) - { + public SoundType getType(String sound, boolean ignoreDamage) { if (sound == null) return SoundType.CANCEL; - if (isCancelSound(sound)) - { + if (isCancelSound(sound)) { return SoundType.CANCEL; } if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.") - && sound.startsWith("step.")) - { + && sound.startsWith("step.")) { return SoundType.STEP; } - for (SoundType type : SoundType.values()) - { - if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) - { + for (SoundType type : SoundType.values()) { + if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) { continue; } String s = disguiseSounds.get(type); - if (s != null) - { - if (s.equals(sound)) - { + if (s != null) { + if (s.equals(sound)) { return type; } } @@ -261,46 +252,36 @@ public enum DisguiseSound return null; } - public boolean isCancelSound(String sound) - { + public boolean isCancelSound(String sound) { return getSoundsToCancel().contains(sound); } - public void removeSound(SoundType type, Sound sound) - { + public void removeSound(SoundType type, Sound sound) { removeSound(type, ReflectionManager.getCraftSound(sound)); } - public void removeSound(SoundType type, String sound) - { - if (type == SoundType.CANCEL) - { + public void removeSound(SoundType type, String sound) { + if (type == SoundType.CANCEL) { cancelSounds.remove(sound); } - else - { + else { disguiseSounds.remove(type); } } - public void setDamageAndIdleSoundVolume(float strength) - { + public void setDamageAndIdleSoundVolume(float strength) { this.damageSoundVolume = strength; } - public void setSound(SoundType type, Sound sound) - { + public void setSound(SoundType type, Sound sound) { setSound(type, ReflectionManager.getCraftSound(sound)); } - public void setSound(SoundType type, String sound) - { - if (type == SoundType.CANCEL) - { + public void setSound(SoundType type, String sound) { + if (type == SoundType.CANCEL) { cancelSounds.add(sound); } - else - { + else { disguiseSounds.put(type, sound); } } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 4be0285e..a5738f1d 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -53,91 +53,71 @@ import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerMain; import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerSounds; import me.libraryaddict.disguise.utilities.packetlisteners.PacketListenerViewDisguises; -public class PacketsManager -{ - public static class LibsPackets - { +public class PacketsManager { + public static class LibsPackets { private ArrayList packets = new ArrayList(); private HashMap> delayedPackets = new HashMap>(); private boolean isSpawnPlayer; private Disguise disguise; private boolean doNothing; - public void setUnhandled() - { + public void setUnhandled() { doNothing = true; } - public boolean isUnhandled() - { + public boolean isUnhandled() { return doNothing; } - private LibsPackets(Disguise disguise) - { + private LibsPackets(Disguise disguise) { this.disguise = disguise; } - public Disguise getDisguise() - { + public Disguise getDisguise() { return disguise; } - public void setPacketType(PacketType type) - { + public void setPacketType(PacketType type) { isSpawnPlayer = type.name().contains("SPAWN_"); } - public void addPacket(PacketContainer packet) - { + public void addPacket(PacketContainer packet) { packets.add(packet); } - public void addDelayedPacket(PacketContainer packet) - { + public void addDelayedPacket(PacketContainer packet) { addDelayedPacket(packet, 2); } - public void clear() - { + public void clear() { getPackets().clear(); } - public void addDelayedPacket(PacketContainer packet, int ticksDelayed) - { + public void addDelayedPacket(PacketContainer packet, int ticksDelayed) { if (!delayedPackets.containsKey(ticksDelayed)) delayedPackets.put(ticksDelayed, new ArrayList()); delayedPackets.get(ticksDelayed).add(packet); } - public ArrayList getPackets() - { + public ArrayList getPackets() { return packets; } - public void sendDelayed(final Player observer) - { - for (final Entry> entry : delayedPackets.entrySet()) - { - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() - { - public void run() - { - try - { - for (PacketContainer packet : entry.getValue()) - { + public void sendDelayed(final Player observer) { + for (final Entry> entry : delayedPackets.entrySet()) { + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { + public void run() { + try { + for (PacketContainer packet : entry.getValue()) { ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); } } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } - if (isSpawnPlayer) - { + if (isSpawnPlayer) { PacketsManager.removeCancel(disguise, observer); } } @@ -157,8 +137,7 @@ public class PacketsManager private static boolean viewDisguisesListenerEnabled; private static HashMap> _cancelMeta = new HashMap>(); - public static void addPacketListeners() - { + public static void addPacketListeners() { // Add a client listener to cancel them interacting with uninteractable disguised entitys. // You ain't supposed to be allowed to 'interact' with a item that cannot be clicked. // Because it kicks you for hacking. @@ -171,8 +150,7 @@ public class PacketsManager setupMainPacketsListener(); } - public static void removeCancel(Disguise disguise, Player observer) - { + public static void removeCancel(Disguise disguise, Player observer) { ArrayList cancel; if ((cancel = _cancelMeta.get(disguise)) == null) @@ -189,37 +167,30 @@ public class PacketsManager /** * Construct the packets I need to spawn in the disguise */ - private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) - { + private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) { Disguise disguise = packets.getDisguise(); - if (disguise.getEntity() == null) - { + if (disguise.getEntity() == null) { disguise.setEntity(disguisedEntity); } // This sends the armor packets so that the player isn't naked. // Please note it only sends the packets that wouldn't be sent normally - if (DisguiseConfig.isEquipmentPacketsEnabled()) - { - for (EquipmentSlot slot : EquipmentSlot.values()) - { + if (DisguiseConfig.isEquipmentPacketsEnabled()) { + for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemstack = disguise.getWatcher().getItemStack(slot); - if (itemstack == null || itemstack.getType() == Material.AIR) - { + if (itemstack == null || itemstack.getType() == Material.AIR) { continue; } ItemStack item = null; - if (disguisedEntity instanceof LivingEntity) - { + if (disguisedEntity instanceof LivingEntity) { item = ReflectionManager.getEquipment(slot, disguisedEntity); } - if (item != null && item.getType() != Material.AIR) - { + if (item != null && item.getType() != Material.AIR) { continue; } @@ -235,25 +206,20 @@ public class PacketsManager } } - if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) - { - if (disguise.getWatcher() instanceof LivingWatcher) - { + if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { + if (disguise.getWatcher() instanceof LivingWatcher) { ArrayList attributes = new ArrayList(); Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth"); - if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) - { + if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); } - else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) - { + else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) { builder.baseValue(((Damageable) disguisedEntity).getMaxHealth()); } - else - { + else { builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); } @@ -275,14 +241,12 @@ public class PacketsManager byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F); byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F); - if (DisguiseConfig.isMovementPacketsEnabled()) - { + if (DisguiseConfig.isMovementPacketsEnabled()) { yaw = getYaw(disguise.getType(), disguisedEntity.getType(), yaw); pitch = getPitch(disguise.getType(), DisguiseType.getType(disguisedEntity.getType()), pitch); } - if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) - { + if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) { PacketContainer spawnOrb = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB); packets.addPacket(spawnOrb); @@ -294,8 +258,7 @@ public class PacketsManager mods.write(3, loc.getZ()); mods.write(4, 1); } - else if (disguise.getType() == DisguiseType.PAINTING) - { + else if (disguise.getType() == DisguiseType.PAINTING) { PacketContainer spawnPainting = new PacketContainer(Server.SPAWN_ENTITY_PAINTING); packets.addPacket(spawnPainting); @@ -323,23 +286,20 @@ public class PacketsManager mods.write(4, yaw); mods.write(5, pitch); } - else if (disguise.getType().isPlayer()) - { + else if (disguise.getType().isPlayer()) { PlayerDisguise playerDisguise = (PlayerDisguise) disguise; String name = playerDisguise.getName(); int entityId = disguisedEntity.getEntityId(); boolean removeName = false; - if (!DisguiseUtilities.hasGameProfile(name)) - { + if (!DisguiseUtilities.hasGameProfile(name)) { removeName = !DisguiseUtilities.getAddedByPlugins().contains(name); } WrappedGameProfile gameProfile = playerDisguise.getGameProfile(); - if (removeName) - { + if (removeName) { DisguiseUtilities.getAddedByPlugins().remove(name); } @@ -367,12 +327,10 @@ public class PacketsManager WrappedDataWatcher newWatcher; - if (selfDisguise) - { + if (selfDisguise) { newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); } - else - { + else { newWatcher = new WrappedDataWatcher(); spawnAt = observer.getLocation(); @@ -397,19 +355,16 @@ public class PacketsManager packets.addPacket(spawnPlayer); - if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) - { + if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets( loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0), observer.getLocation(), ((PlayerDisguise) disguise)); - for (PacketContainer packet : bedPackets) - { + for (PacketContainer packet : bedPackets) { packets.addPacket(packet); } } - else if (!selfDisguise) - { + else if (!selfDisguise) { // Teleport the player back to where he's supposed to be PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); @@ -427,8 +382,7 @@ public class PacketsManager packets.addPacket(teleportPacket); } - if (!selfDisguise) - { + if (!selfDisguise) { // Send a metadata packet PacketContainer metaPacket = new PacketContainer(Play.Server.ENTITY_METADATA); @@ -452,8 +406,7 @@ public class PacketsManager deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); } - else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) - { + else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { Vector vec = disguisedEntity.getVelocity(); PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING); @@ -496,22 +449,18 @@ public class PacketsManager spawnEntity.getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); } - else if (disguise.getType().isMisc()) - { + else if (disguise.getType().isMisc()) { int objectId = disguise.getType().getObjectId(); int data = ((MiscDisguise) disguise).getData(); - if (disguise.getType() == DisguiseType.FALLING_BLOCK) - { + if (disguise.getType() == DisguiseType.FALLING_BLOCK) { data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data); } - else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) - { + else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) { // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id data = disguisedEntity.getEntityId(); } - else if (disguise.getType() == DisguiseType.ITEM_FRAME) - { + else if (disguise.getType() == DisguiseType.ITEM_FRAME) { data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4; } @@ -525,21 +474,17 @@ public class PacketsManager spawnEntity.getModifier().write(8, pitch); spawnEntity.getModifier().write(9, yaw); - if (disguise.getType() == DisguiseType.ITEM_FRAME) - { - if (data % 2 == 0) - { + if (disguise.getType() == DisguiseType.ITEM_FRAME) { + if (data % 2 == 0) { spawnEntity.getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1)); } - else - { + else { spawnEntity.getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1)); } } } - if (packets.getPackets().size() <= 1 || disguise.isPlayerDisguise()) - { + if (packets.getPackets().size() <= 1 || disguise.isPlayerDisguise()) { PacketContainer rotateHead = new PacketContainer(Server.ENTITY_HEAD_ROTATION); packets.addPacket(rotateHead); @@ -555,17 +500,14 @@ public class PacketsManager /** * Create a new datawatcher but with the 'correct' values */ - private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) - { + private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { WrappedDataWatcher newWatcher = new WrappedDataWatcher(); - try - { + try { List list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects(); - for (WrappedWatchableObject watchableObject : list) - { + for (WrappedWatchableObject watchableObject : list) { if (watchableObject == null) continue; @@ -581,18 +523,15 @@ public class PacketsManager newWatcher.setObject(obj, watchableObject.getValue()); } } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } return newWatcher; } - public static byte getPitch(DisguiseType disguiseType, DisguiseType entityType, byte value) - { - switch (disguiseType) - { + public static byte getPitch(DisguiseType disguiseType, DisguiseType entityType, byte value) { + switch (disguiseType) { case MINECART: case MINECART_CHEST: case MINECART_COMMAND: @@ -605,8 +544,7 @@ public class PacketsManager default: break; } - switch (entityType) - { + switch (entityType) { case MINECART: case MINECART_CHEST: case MINECART_FURNACE: @@ -625,10 +563,8 @@ public class PacketsManager /** * Add the yaw for the disguises */ - public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) - { - switch (disguiseType) - { + public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) { + switch (disguiseType) { case MINECART: case MINECART_CHEST: case MINECART_COMMAND: @@ -638,9 +574,8 @@ public class PacketsManager case MINECART_TNT: value += 64; break; + case BOAT: case ENDER_DRAGON: - value -= 128; - break; case WITHER_SKULL: value -= 128; break; @@ -654,15 +589,13 @@ public class PacketsManager value = (byte) -(value + 128); break; default: - if (disguiseType.isMisc() && disguiseType != DisguiseType.ARMOR_STAND) - { + if (disguiseType.isMisc() && disguiseType != DisguiseType.ARMOR_STAND) { value -= 64; } break; } - switch (entityType) - { + switch (entityType) { case MINECART: case MINECART_CHEST: case MINECART_FURNACE: @@ -683,8 +616,7 @@ public class PacketsManager value = (byte) -(value - 128); break; default: - if (!entityType.isAlive()) - { + if (!entityType.isAlive()) { value += 64; } @@ -697,18 +629,15 @@ public class PacketsManager /** * Get the Y level to add to the disguise for realism. */ - public static double getYModifier(Entity entity, Disguise disguise) - { + public static double getYModifier(Entity entity, Disguise disguise) { double yMod = 0; if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) - && entity.getType() == EntityType.DROPPED_ITEM) - { + && entity.getType() == EntityType.DROPPED_ITEM) { yMod -= 0.13; } - switch (disguise.getType()) - { + switch (disguise.getType()) { case BAT: if (entity instanceof LivingEntity) return yMod + ((LivingEntity) entity).getEyeHeight(); @@ -719,8 +648,7 @@ public class PacketsManager case MINECART_HOPPER: case MINECART_MOB_SPAWNER: case MINECART_TNT: - switch (entity.getType()) - { + switch (entity.getType()) { case MINECART: case MINECART_CHEST: case MINECART_FURNACE: @@ -746,8 +674,7 @@ public class PacketsManager case WITHER_SKULL: return yMod + 0.7; case PLAYER: - if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) - { + if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { return yMod + 0.35; } @@ -763,8 +690,7 @@ public class PacketsManager /** * Creates the packet listeners */ - public static void init(LibsDisguises plugin) - { + public static void init(LibsDisguises plugin) { libsDisguises = plugin; soundsListener = new PacketListenerSounds(libsDisguises); @@ -774,62 +700,48 @@ public class PacketsManager inventoryListener = new PacketListenerInventory(libsDisguises); } - public static boolean isHearDisguisesEnabled() - { + public static boolean isHearDisguisesEnabled() { return soundsListenerEnabled; } - public static boolean isInventoryListenerEnabled() - { + public static boolean isInventoryListenerEnabled() { return inventoryModifierEnabled; } - public static boolean isViewDisguisesListenerEnabled() - { + public static boolean isViewDisguisesListenerEnabled() { return viewDisguisesListenerEnabled; } - public static void setHearDisguisesListener(boolean enabled) - { - if (soundsListenerEnabled != enabled) - { + public static void setHearDisguisesListener(boolean enabled) { + if (soundsListenerEnabled != enabled) { soundsListenerEnabled = enabled; - if (soundsListenerEnabled) - { + if (soundsListenerEnabled) { ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener); } - else - { + else { ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener); } } } - public static void setInventoryListenerEnabled(boolean enabled) - { - if (inventoryModifierEnabled != enabled) - { + public static void setInventoryListenerEnabled(boolean enabled) { + if (inventoryModifierEnabled != enabled) { inventoryModifierEnabled = enabled; - if (inventoryModifierEnabled) - { + if (inventoryModifierEnabled) { ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener); } - else - { + else { ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener); } - for (Player player : Bukkit.getOnlinePlayers()) - { + for (Player player : Bukkit.getOnlinePlayers()) { Disguise disguise = DisguiseAPI.getDisguise(player, player); - if (disguise != null) - { + if (disguise != null) { if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() - && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) - { + && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { player.updateInventory(); } } @@ -837,12 +749,9 @@ public class PacketsManager } } - public static void setupMainPacketsListener() - { - if (clientInteractEntityListener != null) - { - if (mainListener != null) - { + public static void setupMainPacketsListener() { + if (clientInteractEntityListener != null) { + if (mainListener != null) { ProtocolLibrary.getProtocolManager().removePacketListener(mainListener); } @@ -861,25 +770,21 @@ public class PacketsManager packetsToListen.add(Server.ENTITY_METADATA); } - if (DisguiseConfig.isCollectPacketsEnabled()) - { + if (DisguiseConfig.isCollectPacketsEnabled()) { packetsToListen.add(Server.COLLECT); } - if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) - { + if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { packetsToListen.add(Server.UPDATE_ATTRIBUTES); } // The bed packet. - if (DisguiseConfig.isBedPacketsEnabled()) - { + if (DisguiseConfig.isBedPacketsEnabled()) { packetsToListen.add(Server.BED); } // Add movement packets - if (DisguiseConfig.isMovementPacketsEnabled()) - { + if (DisguiseConfig.isMovementPacketsEnabled()) { packetsToListen.add(Server.ENTITY_LOOK); packetsToListen.add(Server.REL_ENTITY_MOVE_LOOK); packetsToListen.add(Server.ENTITY_HEAD_ROTATION); @@ -888,20 +793,17 @@ public class PacketsManager } // Add equipment packet - if (DisguiseConfig.isEquipmentPacketsEnabled()) - { + if (DisguiseConfig.isEquipmentPacketsEnabled()) { packetsToListen.add(Server.ENTITY_EQUIPMENT); } // Add the packet that ensures if they are sleeping or not - if (DisguiseConfig.isAnimationPacketsEnabled()) - { + if (DisguiseConfig.isAnimationPacketsEnabled()) { packetsToListen.add(Server.ANIMATION); } // Add the packet that makes sure that entities with armor do not send unpickupable armor on death - if (DisguiseConfig.isEntityStatusPacketsEnabled()) - { + if (DisguiseConfig.isEntityStatusPacketsEnabled()) { packetsToListen.add(Server.ENTITY_STATUS); } @@ -911,40 +813,31 @@ public class PacketsManager } } - public static void setViewDisguisesListener(boolean enabled) - { - if (viewDisguisesListenerEnabled != enabled) - { + public static void setViewDisguisesListener(boolean enabled) { + if (viewDisguisesListenerEnabled != enabled) { viewDisguisesListenerEnabled = enabled; - if (viewDisguisesListenerEnabled) - { + if (viewDisguisesListenerEnabled) { ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener); } - else - { + else { ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener); } - for (Player player : Bukkit.getOnlinePlayers()) - { + for (Player player : Bukkit.getOnlinePlayers()) { Disguise disguise = DisguiseAPI.getDisguise(player, player); - if (disguise != null) - { - if (disguise.isSelfDisguiseVisible()) - { - if (enabled) - { + if (disguise != null) { + if (disguise.isSelfDisguiseVisible()) { + if (enabled) { DisguiseUtilities.setupFakeDisguise(disguise); } - else - { + else { DisguiseUtilities.removeSelfDisguise(player); } - if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) - { + if (inventoryModifierEnabled + && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { player.updateInventory(); } } @@ -957,29 +850,22 @@ public class PacketsManager * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not * transformed */ - public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, Entity entity) - { + public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, Entity entity) { LibsPackets packets = new LibsPackets(disguise); - try - { + try { packets.addPacket(sentPacket); // This packet sends attributes - if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES) - { - if (disguise.isMiscDisguise()) - { + if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES) { + if (disguise.isMiscDisguise()) { packets.clear(); } - else - { + else { List attributes = new ArrayList<>(); - for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) - { - if (attribute.getAttributeKey().equals("generic.maxHealth")) - { + for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) { + if (attribute.getAttributeKey().equals("generic.maxHealth")) { packets.clear(); PacketContainer updateAttributes = new PacketContainer(Server.UPDATE_ATTRIBUTES); @@ -987,18 +873,15 @@ public class PacketsManager Builder builder; - if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) - { + if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { builder = WrappedAttribute.newBuilder(); builder.attributeKey("generic.maxHealth"); builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); } - else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity()) - { + else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity()) { builder = WrappedAttribute.newBuilder(attribute); } - else - { + else { builder = WrappedAttribute.newBuilder(); builder.attributeKey("generic.maxHealth"); builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth()); @@ -1011,26 +894,22 @@ public class PacketsManager } } - if (!attributes.isEmpty()) - { + if (!attributes.isEmpty()) { packets.getPackets().get(0).getIntegers().write(0, entity.getEntityId()); packets.getPackets().get(0).getAttributeCollectionModifier().write(0, attributes); } - else - { + else { packets.clear(); } } } // Else if the packet is sending entity metadata - else if (sentPacket.getType() == Server.ENTITY_METADATA) - { + else if (sentPacket.getType() == Server.ENTITY_METADATA) { packets.clear(); if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise) - && (!_cancelMeta.containsKey(disguise) || !_cancelMeta.get(disguise).contains(observer.getUniqueId()))) - { + && (!_cancelMeta.containsKey(disguise) || !_cancelMeta.get(disguise).contains(observer.getUniqueId()))) { List watchableObjects = disguise.getWatcher() .convert(sentPacket.getWatchableCollectionModifier().read(0)); @@ -1049,34 +928,28 @@ public class PacketsManager // Else if the packet is spawning.. else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING || sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == Server.SPAWN_ENTITY - || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) - { + || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) { packets.clear(); constructSpawnPackets(observer, packets, entity); } // Else if the disguise is attempting to send players a forbidden packet - else if (sentPacket.getType() == Server.ANIMATION) - { + else if (sentPacket.getType() == Server.ANIMATION) { if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType().isPlayer() - || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) - { + || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) { packets.clear(); } } // Else if the disguise is collecting stuff - else if (sentPacket.getType() == Server.COLLECT) - { - if (disguise.getType().isMisc()) - { + else if (sentPacket.getType() == Server.COLLECT) { + if (disguise.getType().isMisc()) { packets.clear(); } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() - && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) - { + && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { PacketContainer newPacket = new PacketContainer(Server.ANIMATION); StructureModifier mods = newPacket.getIntegers(); @@ -1092,19 +965,15 @@ public class PacketsManager // Else if the disguise is moving. else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket.getType() == Server.ENTITY_LOOK - || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.REL_ENTITY_MOVE) - { + || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.REL_ENTITY_MOVE) { if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE - || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) - { + || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) { // Rabbit robbing... if (entity.getMetadata("LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 - || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) - { + || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { if (entity.getMetadata("LibsRabbitHop").isEmpty() - || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) - { + || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { entity.removeMetadata("LibsRabbitHop", libsDisguises); entity.setMetadata("LibsRabbitHop", new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); @@ -1119,12 +988,10 @@ public class PacketsManager } // Stop wither skulls from looking - if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) - { + if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) { packets.clear(); } - else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) - { + else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) { packets.clear(); PacketContainer movePacket = sentPacket.shallowClone(); @@ -1139,30 +1006,25 @@ public class PacketsManager bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue)); bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); - if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) - { + if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) { StructureModifier doubles = movePacket.getDoubles(); Location loc = entity.getLocation(); double data = (((loc.getYaw() % 360) + 720 + 45) / 90) % 4; - if (data % 2 == 0) - { - if (data % 2 == 0) - { + if (data % 2 == 0) { + if (data % 2 == 0) { doubles.write(3, loc.getZ()); } - else - { + else { doubles.write(1, loc.getZ()); } } double y = getYModifier(entity, disguise); - if (y != 0) - { + if (y != 0) { doubles.write(2, doubles.read(2) + y); } } @@ -1170,14 +1032,12 @@ public class PacketsManager } // Else if the disguise is updating equipment - else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) - { + else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) { EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1)); org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot); - if (itemStack != null) - { + if (itemStack != null) { packets.clear(); PacketContainer equipPacket = sentPacket.shallowClone(); @@ -1188,17 +1048,14 @@ public class PacketsManager (itemStack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemStack))); } - if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) - { + if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) { ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0); - if (heldItem != null && heldItem.getType() != Material.AIR) - { + if (heldItem != null && heldItem.getType() != Material.AIR) { // Convert the datawatcher List list = new ArrayList<>(); - if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) - { + if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) { WrappedWatchableObject watch = ReflectionManager.createWatchable(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)); @@ -1206,12 +1063,9 @@ public class PacketsManager list = disguise.getWatcher().convert(list); } - else - { - for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) - { - if (obj.getIndex() == 0) - { + else { + for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { + if (obj.getIndex() == 0) { list.add(obj); break; } @@ -1226,8 +1080,7 @@ public class PacketsManager PacketContainer packetUnblock = packetBlock.deepClone(); // Make a packet to send the 'unblock' - for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) - { + for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); } @@ -1248,28 +1101,22 @@ public class PacketsManager } // If the entity is going into a bed, stop everything but players from doing this - else if (sentPacket.getType() == Server.BED) - { - if (!disguise.getType().isPlayer()) - { + else if (sentPacket.getType() == Server.BED) { + if (!disguise.getType().isPlayer()) { packets.clear(); } } // If the entity is updating their Facebook status, stop them from showing death - else if (sentPacket.getType() == Server.ENTITY_STATUS) - { - if (packets.getPackets().get(0).getBytes().read(0) == (byte) 3) - { + else if (sentPacket.getType() == Server.ENTITY_STATUS) { + if (packets.getPackets().get(0).getBytes().read(0) == (byte) 3) { packets.clear(); } } // If the entity is rotating his head - else if (sentPacket.getType() == Server.ENTITY_HEAD_ROTATION) - { - if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) - { + else if (sentPacket.getType() == Server.ENTITY_HEAD_ROTATION) { + if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) { Location loc = entity.getLocation(); byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), @@ -1295,13 +1142,11 @@ public class PacketsManager packets.addPacket(rotation); } } - else - { + else { packets.setUnhandled(); } } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } @@ -1314,8 +1159,7 @@ public class PacketsManager * @param disguise * @return */ - public static boolean isStaticMetadataDisguiseType(Disguise disguise) - { + public static boolean isStaticMetadataDisguiseType(Disguise disguise) { return false; /* return (disguise.getType() == DisguiseType.WOLF || disguise.getType() == DisguiseType.OCELOT || disguise.getType() == DisguiseType.ENDERMAN || disguise.getType() == DisguiseType.SHULKER diff --git a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerInventory.java b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerInventory.java index 49057c09..f84c3b61 100644 --- a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerInventory.java +++ b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerInventory.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.utilities.packetlisteners; import java.lang.reflect.InvocationTargetException; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -20,12 +21,10 @@ import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class PacketListenerInventory extends PacketAdapter -{ +public class PacketListenerInventory extends PacketAdapter { private LibsDisguises libsDisguises; - public PacketListenerInventory(LibsDisguises plugin) - { + public PacketListenerInventory(LibsDisguises plugin) { super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT, PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK); @@ -33,16 +32,14 @@ public class PacketListenerInventory extends PacketAdapter } @Override - public void onPacketReceiving(final PacketEvent event) - { + public void onPacketReceiving(final PacketEvent event) { if (event.isCancelled()) return; if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary return; - if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) - { + if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) { return; } @@ -50,23 +47,18 @@ public class PacketListenerInventory extends PacketAdapter // If player is disguised, views self disguises and has a inventory modifier if (disguise != null && disguise.isSelfDisguiseVisible() - && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) - { + && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { // If they are in creative and clicked on a slot - if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) - { + if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) { int slot = event.getPacket().getIntegers().read(0); - if (slot >= 5 && slot <= 8) - { - if (disguise.isHidingArmorFromSelf()) - { + if (slot >= 5 && slot <= 8) { + if (disguise.isHidingArmorFromSelf()) { int armorSlot = Math.abs((slot - 5) - 3); org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; - if (item != null && item.getType() != Material.AIR) - { + if (item != null && item.getType() != Material.AIR) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -75,29 +67,23 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, slot); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } } - else if (slot >= 36 && slot <= 44) - { - if (disguise.isHidingHeldItemFromSelf()) - { + else if (slot >= 36 && slot <= 44) { + if (disguise.isHidingHeldItemFromSelf()) { int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); - if (slot + 36 == currentSlot) - { + if (slot + 36 == currentSlot) { org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); - if (item != null && item.getType() != Material.AIR) - { + if (item != null && item.getType() != Material.AIR) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -105,12 +91,10 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, slot); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } @@ -119,18 +103,15 @@ public class PacketListenerInventory extends PacketAdapter } } // If the player switched item, aka he moved from slot 1 to slot 2 - else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) - { - if (disguise.isHidingHeldItemFromSelf()) - { + else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) { + if (disguise.isHidingHeldItemFromSelf()) { // From logging, it seems that both bukkit and nms uses the same thing for the slot switching. // 0 1 2 3 - 8 // If the packet is coming, then I need to replace the item they are switching to // As for the old item, I need to restore it. org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand(); // If his old weapon isn't air - if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) - { + if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -139,12 +120,10 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36); mods.write(2, ReflectionManager.getNmsItem(currentlyHeld)); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } @@ -153,8 +132,7 @@ public class PacketListenerInventory extends PacketAdapter .getItem(event.getPacket().getIntegers().read(0)); // If his new weapon isn't air either! - if (newHeld != null && newHeld.getType() != Material.AIR) - { + if (newHeld != null && newHeld.getType() != Material.AIR) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -163,36 +141,29 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, event.getPacket().getIntegers().read(0) + 36); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } } - else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) - { + else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) { int slot = event.getPacket().getIntegers().read(1); org.bukkit.inventory.ItemStack clickedItem; - if (event.getPacket().getShorts().read(0) == 1) - { + if (event.getPacket().getShorts().read(0) == 1) { // Its a shift click clickedItem = event.getPacket().getItemModifier().read(0); - if (clickedItem != null && clickedItem.getType() != Material.AIR) - { + if (clickedItem != null && clickedItem.getType() != Material.AIR) { // Rather than predict the clients actions // Lets just update the entire inventory.. - Bukkit.getScheduler().runTask(libsDisguises, new Runnable() - { - public void run() - { + Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { + public void run() { event.getPlayer().updateInventory(); } }); @@ -200,25 +171,20 @@ public class PacketListenerInventory extends PacketAdapter return; } - else - { + else { // If its not a player inventory click // Shift clicking is exempted for the item in hand.. - if (event.getPacket().getIntegers().read(0) != 0) - { + if (event.getPacket().getIntegers().read(0) != 0) { return; } clickedItem = event.getPlayer().getItemOnCursor(); } - if (clickedItem != null && clickedItem.getType() != Material.AIR) - { + if (clickedItem != null && clickedItem.getType() != Material.AIR) { // If the slot is a armor slot - if (slot >= 5 && slot <= 8) - { - if (disguise.isHidingArmorFromSelf()) - { + if (slot >= 5 && slot <= 8) { + if (disguise.isHidingArmorFromSelf()) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -227,26 +193,21 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, slot); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } // Else if its a hotbar slot } - else if (slot >= 36 && slot <= 44) - { - if (disguise.isHidingHeldItemFromSelf()) - { + else if (slot >= 36 && slot <= 44) { + if (disguise.isHidingHeldItemFromSelf()) { int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); // Check if the player is on the same slot as the slot that its setting - if (slot == currentSlot + 36) - { + if (slot == currentSlot + 36) { PacketContainer packet = new PacketContainer(Server.SET_SLOT); StructureModifier mods = packet.getModifier(); @@ -254,12 +215,10 @@ public class PacketListenerInventory extends PacketAdapter mods.write(1, slot); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } @@ -272,20 +231,17 @@ public class PacketListenerInventory extends PacketAdapter } @Override - public void onPacketSending(PacketEvent event) - { + public void onPacketSending(PacketEvent event) { // If the inventory is the players inventory if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null - || event.getPacket().getIntegers().read(0) != 0) - { + || event.getPacket().getIntegers().read(0) != 0) { return; } Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); if (disguise == null || !disguise.isSelfDisguiseVisible() - || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) - { + || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) { return; } @@ -297,24 +253,20 @@ public class PacketListenerInventory extends PacketAdapter /** * Done */ - if (event.getPacketType() == Server.SET_SLOT) - { + if (event.getPacketType() == Server.SET_SLOT) { // The raw slot // nms code has the start of the hotbar being 36. int slot = event.getPacket().getIntegers().read(1); // If the slot is a armor slot - if (slot >= 5 && slot <= 8) - { - if (disguise.isHidingArmorFromSelf()) - { + if (slot >= 5 && slot <= 8) { + if (disguise.isHidingArmorFromSelf()) { // Get the bukkit armor slot! int armorSlot = Math.abs((slot - 5) - 3); org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; - if (item != null && item.getType() != Material.AIR) - { + if (item != null && item.getType() != Material.AIR) { event.setPacket(event.getPacket().shallowClone()); event.getPacket().getModifier().write(2, @@ -323,19 +275,15 @@ public class PacketListenerInventory extends PacketAdapter } // Else if its a hotbar slot } - else if (slot >= 36 && slot <= 44) - { - if (disguise.isHidingHeldItemFromSelf()) - { + else if (slot >= 36 && slot <= 44) { + if (disguise.isHidingHeldItemFromSelf()) { int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); // Check if the player is on the same slot as the slot that its setting - if (slot == currentSlot + 36) - { + if (slot == currentSlot + 36) { org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); - if (item != null && item.getType() != Material.AIR) - { + if (item != null && item.getType() != Material.AIR) { event.setPacket(event.getPacket().shallowClone()); event.getPacket().getModifier().write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); @@ -344,45 +292,36 @@ public class PacketListenerInventory extends PacketAdapter } } } - else if (event.getPacketType() == Server.WINDOW_ITEMS) - { + else if (event.getPacketType() == Server.WINDOW_ITEMS) { event.setPacket(event.getPacket().deepClone()); - StructureModifier mods = event.getPacket().getItemArrayModifier(); - ItemStack[] items = mods.read(0); + StructureModifier> mods = event.getPacket().getItemListModifier(); + List items = mods.read(0); - for (int slot = 0; slot < items.length; slot++) - { - if (slot >= 5 && slot <= 8) - { - if (disguise.isHidingArmorFromSelf()) - { + for (int slot = 0; slot < items.size(); slot++) { + if (slot >= 5 && slot <= 8) { + if (disguise.isHidingArmorFromSelf()) { // Get the bukkit armor slot! int armorSlot = Math.abs((slot - 5) - 3); - org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; + ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; - if (item != null && item.getType() != Material.AIR) - { - items[slot] = new org.bukkit.inventory.ItemStack(0); + if (item != null && item.getType() != Material.AIR) { + items.set(slot, new ItemStack(Material.AIR)); } } // Else if its a hotbar slot } - else if (slot >= 36 && slot <= 44) - { - if (disguise.isHidingHeldItemFromSelf()) - { + else if (slot >= 36 && slot <= 44) { + if (disguise.isHidingHeldItemFromSelf()) { int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); // Check if the player is on the same slot as the slot that its setting - if (slot == currentSlot + 36) - { - org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); + if (slot == currentSlot + 36) { + ItemStack item = event.getPlayer().getItemInHand(); - if (item != null && item.getType() != Material.AIR) - { - items[slot] = new org.bukkit.inventory.ItemStack(0); + if (item != null && item.getType() != Material.AIR) { + items.set(slot, new ItemStack(Material.AIR)); } } }