From 50623a9be29c30acdc286742ed63d09a5f93fc05 Mon Sep 17 00:00:00 2001 From: NavidK0 Date: Fri, 19 Feb 2016 15:29:53 -0500 Subject: [PATCH] Added new entities to DisguiseType Changed entity Ids to reflect new entity Ids in Spigot 1.9 Cleaned up code --- build.gradle | 2 +- .../disguise/disguisetypes/Disguise.java | 29 +++---- .../disguise/disguisetypes/DisguiseType.java | 18 +++-- .../disguise/disguisetypes/FlagWatcher.java | 10 +-- .../watchers/AgeableWatcher.java | 2 +- .../watchers/ArmorStandWatcher.java | 4 +- .../disguisetypes/watchers/ArrowWatcher.java | 2 +- .../disguisetypes/watchers/BatWatcher.java | 2 +- .../disguisetypes/watchers/BlazeWatcher.java | 2 +- .../watchers/CreeperWatcher.java | 4 +- .../watchers/EndermanWatcher.java | 7 +- .../disguisetypes/watchers/GhastWatcher.java | 2 +- .../disguisetypes/watchers/LivingWatcher.java | 34 ++++----- .../watchers/MinecartWatcher.java | 2 +- .../disguisetypes/watchers/OcelotWatcher.java | 3 +- .../disguisetypes/watchers/PigWatcher.java | 2 +- .../disguisetypes/watchers/PlayerWatcher.java | 15 ++-- .../disguisetypes/watchers/SheepWatcher.java | 8 +- .../disguisetypes/watchers/SlimeWatcher.java | 6 +- .../watchers/TameableWatcher.java | 4 +- .../watchers/WitherSkullWatcher.java | 2 +- .../disguisetypes/watchers/WolfWatcher.java | 2 +- .../disguisetypes/watchers/ZombieWatcher.java | 6 +- .../disguise/utilities/Metrics.java | 18 ++--- .../disguise/utilities/PacketsManager.java | 76 ++++++++----------- .../disguise/utilities/ReflectionManager.java | 18 +---- src/main/resources/plugin.yml | 2 +- 27 files changed, 121 insertions(+), 161 deletions(-) diff --git a/build.gradle b/build.gradle index 1d056ce5..7bcbadbc 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion sourceCompatibility = '1.7' ext.spigotVersion = '1.8.8-R0.1-SNAPSHOT' -ext.disguisesVersion = '8.6.8' +ext.disguisesVersion = '9.0.0' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 719e0073..e260bbe6 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -63,7 +63,7 @@ public abstract class Disguise { /** * Seems I do this method so I can make cleaner constructors on disguises.. * - * @param newType + * @param newType The disguise */ protected void createDisguise(DisguiseType newType) { if (getWatcher() != null) { @@ -73,7 +73,7 @@ public abstract class Disguise { throw new RuntimeException( "DisguiseType " + newType - + " was used in a futile attempt to construct a disguise, but this version of craftbukkit does not have that entity"); + + " was used in a futile attempt to construct a disguise, but this version of Spigot does not have that entity"); } // Set the disguise type disguiseType = newType; @@ -103,7 +103,7 @@ public abstract class Disguise { else if (getType() == DisguiseType.ZOMBIE_VILLAGER) { getWatcher().setValue(13, (byte) 1); } else if (getType() == DisguiseType.ELDER_GUARDIAN) { - getWatcher().setValue(16, 0 | 4); + getWatcher().setValue(16, 4); } // Else if its a horse. Set the horse watcher type else if (getWatcher() instanceof HorseWatcher) { try { @@ -325,7 +325,7 @@ public abstract class Disguise { /** * Get the disguised entity * - * @return + * @return entity */ public Entity getEntity() { return entity; @@ -334,7 +334,7 @@ public abstract class Disguise { /** * Get the disguise type * - * @return + * @return disguiseType */ public DisguiseType getType() { return disguiseType; @@ -343,7 +343,7 @@ public abstract class Disguise { /** * Get the flag watcher * - * @return + * @return flagWatcher */ public FlagWatcher getWatcher() { return watcher; @@ -352,7 +352,7 @@ public abstract class Disguise { /** * In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise. getEntity() can still return null if this disguise is active after despawn, logout, etc. * - * @return + * @return isDisguiseInUse */ public boolean isDisguiseInUse() { return disguiseInUse; @@ -396,16 +396,9 @@ public abstract class Disguise { /** * Internal use - * - * @return */ public boolean isRemoveDisguiseOnDeath() { - if (getEntity() == null) { - return true; - } - return getEntity() instanceof Player - ? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) - : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead()); + return getEntity() == null || (getEntity() instanceof Player ? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())); } public boolean isSelfDisguiseSoundsReplaced() { @@ -415,7 +408,7 @@ public abstract class Disguise { /** * Can the disguised view himself as the disguise * - * @return + * @return viewSelfDisguise */ public boolean isSelfDisguiseVisible() { return viewSelfDisguise; @@ -441,7 +434,7 @@ public abstract class Disguise { /** * Removes the disguise and undisguises the entity if its using this disguise. * - * @return + * @return removeDiguise */ public boolean removeDisguise() { if (disguiseInUse) { @@ -505,7 +498,7 @@ public abstract class Disguise { * Set the entity of the disguise. Only used for internal things. * * @param entity - * @return + * @return disguise */ public Disguise setEntity(Entity entity) { if (this.getEntity() != null) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index dc4d1f3f..3779f2e5 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -12,6 +12,7 @@ import java.lang.reflect.Method; public enum DisguiseType { + AREA_EFFECT_CLOUD, //Disguising as this would be something else. ARMOR_STAND(78), ARROW(60), BAT, @@ -22,8 +23,9 @@ public enum DisguiseType { COW, CREEPER, DONKEY, - DROPPED_ITEM(2, 1), - EGG(62), + DRAGON_FIREBALL(26), + DROPPED_ITEM(-1, 1), + EGG, ELDER_GUARDIAN, ENDER_CRYSTAL(51), ENDER_DRAGON, @@ -35,7 +37,7 @@ public enum DisguiseType { FALLING_BLOCK(70, 1), FIREBALL(63, 0), FIREWORK(76), - FISHING_HOOK(90), + FISHING_HOOK, GHAST, GIANT, GUARDIAN, @@ -43,6 +45,7 @@ public enum DisguiseType { IRON_GOLEM, ITEM_FRAME(71), LEASH_HITCH(77), + LIGHTING, MAGMA_CUBE, MINECART(10, 0), MINECART_CHEST(10, 1), @@ -61,6 +64,8 @@ public enum DisguiseType { PRIMED_TNT(50), RABBIT, SHEEP, + SHULKER, + SHULKER_BULLET(25), SILVERFISH, SKELETON, SKELETON_HORSE, @@ -68,12 +73,15 @@ public enum DisguiseType { SMALL_FIREBALL(64, 0), SNOWBALL(61), SNOWMAN, + SPECTRAL_ARROW(24), SPIDER, - SPLASH_POTION(73), + SPLASH_POTION(-1), SQUID, + TIPPED_ARROW(23), THROWN_EXP_BOTTLE(75), UNDEAD_HORSE, VILLAGER, + WEATHER, WITCH, WITHER, WITHER_SKELETON, @@ -116,7 +124,7 @@ public enum DisguiseType { } type.setEntityType(EntityType.valueOf(toUse.name())); } catch (Throwable ex) { - // This version of craftbukkit doesn't have the disguise. + // This version of Spigot doesn't have the disguise. } } try { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index f18e3632..463943cd 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -75,7 +75,7 @@ public class FlagWatcher { } cloned.entityValues = (HashMap) entityValues.clone(); cloned.items = items.clone(); - cloned.modifiedEntityAnimations = (HashSet) modifiedEntityAnimations.clone(); + cloned.modifiedEntityAnimations = (HashSet) modifiedEntityAnimations.clone(); cloned.addEntityAnimations = addEntityAnimations; return cloned; } @@ -106,7 +106,7 @@ public class FlagWatcher { } if (value != null) { if (isEntityAnimationsAdded() && dataType == 0) { - value = this.addEntityAnimations((Byte) value, (Byte) watch.getValue()); + value = this.addEntityAnimations((byte) value, (byte) watch.getValue()); } boolean isDirty = watch.getDirtyState(); watch = new WrappedWatchableObject(dataType, value); @@ -173,7 +173,7 @@ public class FlagWatcher { } private boolean getFlag(int byteValue) { - return ((Byte) getValue(0, (byte) 0) & 1 << byteValue) != 0; + return ((byte) getValue(0, (byte) 0) & 1 << byteValue) != 0; } public ItemStack getItemInHand() { @@ -264,7 +264,7 @@ public class FlagWatcher { } Object value = entityValues.get(data); if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) { - value = addEntityAnimations((Byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); + value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); } list.add(new WrappedWatchableObject(data, value)); } @@ -317,7 +317,7 @@ public class FlagWatcher { private void setFlag(int byteValue, boolean flag) { modifiedEntityAnimations.add(byteValue); - byte b0 = (Byte) getValue(0, (byte) 0); + byte b0 = (byte) getValue(0, (byte) 0); if (flag) { setValue(0, (byte) (b0 | 1 << byteValue)); } else { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java index b164717e..17123950 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java @@ -17,7 +17,7 @@ public class AgeableWatcher extends LivingWatcher { } public boolean isBaby() { - return ((Byte) getValue(12, (byte) 0)).intValue() < 0; + return ((byte) getValue(12, (byte) 0)) < 0; } public void setAdult() { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java index 982e8528..4630b4f6 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java @@ -9,7 +9,7 @@ public class ArmorStandWatcher extends LivingWatcher { } private boolean get10(int value) { - return ((Byte) getValue(10, 0) & value) != 0; + return ((byte) getValue(10, 0) & value) != 0; } public boolean isNoBasePlate() { @@ -29,7 +29,7 @@ public class ArmorStandWatcher extends LivingWatcher { } private void set10(int value, boolean isTrue) { - byte b1 = (Byte) getValue(10, (byte) 0); + byte b1 = (byte) getValue(10, (byte) 0); if (isTrue) { b1 = (byte) (b1 | value); } else { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 0a836d1c..e76b86ef 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -10,7 +10,7 @@ public class ArrowWatcher extends FlagWatcher { } public boolean isCritical() { - return (Byte) getValue(16, (byte) 0) == 1; + return (byte) getValue(16, (byte) 0) == 1; } public void setCritical(boolean critical) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java index 17d0d0c3..f9730652 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java @@ -10,7 +10,7 @@ public class BatWatcher extends LivingWatcher { } public boolean isFlying() { - return (Byte) getValue(16, (byte) 1) == 0; + return (byte) getValue(16, (byte) 1) == 0; } public void setFlying(boolean flying) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java index 28deb334..6277f1af 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java @@ -9,7 +9,7 @@ public class BlazeWatcher extends LivingWatcher { } public boolean isBlazing() { - return (Byte) getValue(16, (byte) 0) == 1; + return (byte) getValue(16, (byte) 0) == 1; } public void setBlazing(boolean isBlazing) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java index 1f6dda31..aa04fda4 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java @@ -9,11 +9,11 @@ public class CreeperWatcher extends LivingWatcher { } public boolean isIgnited() { - return (Byte) getValue(18, (byte) 0) == 1; + return (byte) getValue(18, (byte) 0) == 1; } public boolean isPowered() { - return (Byte) getValue(17, (byte) 0) == 1; + return (byte) getValue(17, (byte) 0) == 1; } public void setIgnited(boolean ignited) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index 23912f5a..a08e6554 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -1,8 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.inventory.ItemStack; - import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.inventory.ItemStack; public class EndermanWatcher extends LivingWatcher { @@ -12,11 +11,11 @@ public class EndermanWatcher extends LivingWatcher { @Override public ItemStack getItemInHand() { - return new ItemStack((Byte) getValue(16, (byte) 0), 1, ((Byte) getValue(17, (byte) 0))); + return new ItemStack((byte) getValue(16, (byte) 0), 1, ((byte) getValue(17, (byte) 0))); } public boolean isAggressive() { - return (Byte) getValue(18, (byte) 0) == 1; + return (byte) getValue(18, (byte) 0) == 1; } @Deprecated diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java index 52e7a748..8ea75400 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java @@ -9,7 +9,7 @@ public class GhastWatcher extends LivingWatcher { } public boolean isAggressive() { - return (Byte) getValue(16, (byte) 0) == 1; + return (byte) getValue(16, (byte) 0) == 1; } public void setAggressive(boolean isAggressive) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index fa419c49..8723ce8e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -1,26 +1,24 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.FlagWatcher; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.ReflectionManager; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.ReflectionManager; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; public class LivingWatcher extends FlagWatcher { @@ -80,7 +78,7 @@ public class LivingWatcher extends FlagWatcher { } public boolean getPotionParticlesRemoved() { - return (Byte) getValue(8, (byte) 0) == 1; + return (byte) getValue(8, (byte) 0) == 1; } private int getPotions() { @@ -99,7 +97,7 @@ public class LivingWatcher extends FlagWatcher { int n = (Integer) potionNo.invoke(list[localMobEffect]); f1 += (n >> 16 & 0xFF) / 255.0F; f2 += (n >> 8 & 0xFF) / 255.0F; - f3 += (n >> 0 & 0xFF) / 255.0F; + f3 += (n & 0xFF) / 255.0F; f4 += 1.0F; } } catch (Exception ex) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index b59c47e1..301b2cba 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -30,7 +30,7 @@ public class MinecartWatcher extends FlagWatcher { } public boolean getViewBlockInCart() { - return ((Byte) getValue(22, (byte) 0)) == (byte) 1; + return ((byte) getValue(22, (byte) 0)) == (byte) 1; } public void setBlockInCart(ItemStack item) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java index 27a0085b..a4b55887 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java @@ -1,7 +1,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; - import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot.Type; @@ -12,7 +11,7 @@ public class OcelotWatcher extends TameableWatcher { } public Type getType() { - return Ocelot.Type.getType((Byte) getValue(18, (byte) 0)); + return Ocelot.Type.getType((byte) getValue(18, (byte) 0)); } public void setType(Type newType) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java index 13215347..4b9c1fc0 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java @@ -9,7 +9,7 @@ public class PigWatcher extends AgeableWatcher { } public boolean isSaddled() { - return (Byte) getValue(16, (byte) 0) == 1; + return (byte) getValue(16, (byte) 0) == 1; } public void setSaddled(boolean isSaddled) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java index 70e7a9d9..0b21a85d 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java @@ -1,19 +1,16 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; public class PlayerWatcher extends LivingWatcher { @@ -32,7 +29,7 @@ public class PlayerWatcher extends LivingWatcher { } public int getArrowsSticking() { - return (Byte) getValue(9, (byte) 0); + return (byte) getValue(9, (byte) 0); } public BlockFace getSleepingDirection() { @@ -48,7 +45,7 @@ public class PlayerWatcher extends LivingWatcher { } private boolean getValue16(int i) { - return ((Byte) getValue(16, (byte) 0) & 1 << i) != 0; + return ((byte) getValue(16, (byte) 0) & 1 << i) != 0; } public boolean isHideCape() { @@ -129,11 +126,11 @@ public class PlayerWatcher extends LivingWatcher { } private void setValue16(int i, boolean flag) { - byte b0 = (Byte) getValue(16, (byte) 0); + byte b0 = (byte) getValue(16, (byte) 0); if (flag) { setValue(16, (byte) (b0 | 1 << i)); } else { - setValue(16, (byte) (b0 & (1 << i ^ 0xFFFFFFFF))); + setValue(16, (byte) (b0 & (~1 << i))); } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java index 8452e321..71476417 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java @@ -11,21 +11,21 @@ public class SheepWatcher extends AgeableWatcher { } public AnimalColor getColor() { - return AnimalColor.getColor((Byte) getValue(16, (byte) 0) & 15); + return AnimalColor.getColor((byte) getValue(16, (byte) 0) & 15); } public boolean isSheared() { - return ((Byte) getValue(16, (byte) 0) & 16) != 0; + return ((byte) getValue(16, (byte) 0) & 16) != 0; } public void setColor(AnimalColor color) { - byte b0 = (Byte) getValue(16, (byte) 0); + byte b0 = (byte) getValue(16, (byte) 0); setValue(16, (byte) (b0 & 240 | color.getId() & 15)); sendData(16); } public void setSheared(boolean flag) { - byte b0 = (Byte) getValue(16, (byte) 0); + byte b0 = (byte) getValue(16, (byte) 0); if (flag) { setValue(16, (byte) (b0 | 16)); } else { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java index a49c5ba9..fb2a40fb 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java @@ -1,9 +1,9 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import java.util.Random; - import me.libraryaddict.disguise.disguisetypes.Disguise; +import java.util.Random; + public class SlimeWatcher extends LivingWatcher { public SlimeWatcher(Disguise disguise) { @@ -12,7 +12,7 @@ public class SlimeWatcher extends LivingWatcher { } public int getSize() { - return (Byte) getValue(16, (byte) 1); + return (byte) getValue(16, (byte) 1); } public void setSize(int size) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index 551f3c7d..2381b90e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -26,11 +26,11 @@ public class TameableWatcher extends AgeableWatcher { } protected boolean isTrue(int no) { - return ((Byte) getValue(16, (byte) 0) & no) != 0; + return ((byte) getValue(16, (byte) 0) & no) != 0; } protected void setFlag(int no, boolean flag) { - byte b0 = (Byte) getValue(16, (byte) 0); + byte b0 = (byte) getValue(16, (byte) 0); if (flag) { setValue(16, (byte) (b0 | no)); } else { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java index 53a5044c..f2fa809f 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java @@ -10,7 +10,7 @@ public class WitherSkullWatcher extends FlagWatcher { } public boolean isBlue() { - return (Byte) getValue(10, (byte) 0) == 1; + return (byte) getValue(10, (byte) 0) == 1; } public void setBlue(boolean blue) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index 8f77f553..a440975d 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -10,7 +10,7 @@ public class WolfWatcher extends TameableWatcher { } public AnimalColor getCollarColor() { - return AnimalColor.getColor((Byte) getValue(20, (byte) 14)); + return AnimalColor.getColor((byte) getValue(20, (byte) 14)); } public boolean isAngry() { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index 0447f519..82a4d134 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -13,15 +13,15 @@ public class ZombieWatcher extends LivingWatcher { } public boolean isBaby() { - return (Byte) getValue(12, (byte) 0) == 1; + return (byte) getValue(12, (byte) 0) == 1; } public boolean isShaking() { - return (Byte) getValue(14, (byte) 0) == 1; + return (byte) getValue(14, (byte) 0) == 1; } public boolean isVillager() { - return (Byte) getValue(13, (byte) 0) == 1; + return (byte) getValue(13, (byte) 0) == 1; } public void setAdult() { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/Metrics.java b/src/main/java/me/libraryaddict/disguise/utilities/Metrics.java index 86e5ca95..b31601f3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/Metrics.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/Metrics.java @@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.scheduler.BukkitTask; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -46,7 +47,6 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import java.util.UUID; @@ -275,7 +275,7 @@ public class Metrics { * @return the File object for the config file */ public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use + // I believe the easiest way to get the base folder (e.g Spigot set via -P) for plugins to use // is to abuse the plugin object we already have // plugin.getDataFolder() => base/plugins/PluginA/ // pluginsFolder => base/plugins/ @@ -334,9 +334,7 @@ public class Metrics { json.append(':'); json.append('{'); boolean firstGraph = true; - final Iterator iter = graphs.iterator(); - while (iter.hasNext()) { - Graph graph = iter.next(); + for (Graph graph : graphs) { StringBuilder graphJson = new StringBuilder(); graphJson.append('{'); for (Plotter plotter : graph.getPlotters()) { @@ -402,9 +400,7 @@ public class Metrics { // Is this the first update this hour? if (response.equals("1") || response.contains("This is your first update this hour")) { synchronized (graphs) { - final Iterator iter = graphs.iterator(); - while (iter.hasNext()) { - final Graph graph = iter.next(); + for (Graph graph : graphs) { for (Plotter plotter : graph.getPlotters()) { plotter.reset(); } @@ -418,7 +414,7 @@ public class Metrics { * GZip compress a string of bytes * * @param input - * @return + * @return byte[] */ public static byte[] gzip(String input) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -487,7 +483,7 @@ public class Metrics { * Escape a string to create a valid JSON string * * @param text - * @return + * @return String */ private static String escapeJSON(String text) { StringBuilder builder = new StringBuilder(); @@ -515,7 +511,7 @@ public class Metrics { default: if (chr < ' ') { String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); + builder.append("\\u").append(t.substring(t.length() - 4)); } else { builder.append(chr); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java index b0c2634b..486ddfc7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -119,7 +119,7 @@ public class PacketsManager { if (disguise.getEntity() == null) disguise.setEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); - ArrayList packets = new ArrayList(); + ArrayList packets = new ArrayList<>(); // 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()) { @@ -151,7 +151,7 @@ public class PacketsManager { if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { if (disguise.getWatcher() instanceof LivingWatcher) { PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); - List attributes = new ArrayList(); + List attributes = new ArrayList<>(); Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth"); if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); @@ -257,16 +257,14 @@ public class PacketsManager { PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(player, loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0), player.getLocation(), ((PlayerDisguise) disguise)); - for (int i = 0; i < 2; i++) { - spawnPackets[i + 1] = bedPackets[i]; - } + System.arraycopy(bedPackets, 0, spawnPackets, 1, 2); } - ArrayList newPackets = new ArrayList(); + ArrayList newPackets = new ArrayList<>(); newPackets.add(null); - for (int i = 0; i < spawnPackets.length; i++) { - if (spawnPackets[i] != null) { // Get rid of empty packet '1' if it exists. - newPackets.add(spawnPackets[i]); + for (PacketContainer spawnPacket : spawnPackets) { + if (spawnPacket != null) { // Get rid of empty packet '1' if it exists. + newPackets.add(spawnPacket); } } spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]); @@ -278,7 +276,7 @@ public class PacketsManager { spawnPackets[0].getModifier().write(1, playerList); PacketContainer delayedPacket = spawnPackets[0].shallowClone(); delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); - delayedPackets = new PacketContainer[] { delayedPacket }; + delayedPackets = new PacketContainer[]{delayedPacket}; } else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { @@ -353,7 +351,7 @@ public class PacketsManager { mods.write(0, disguisedEntity.getEntityId()); mods.write(1, yaw); } - return new PacketContainer[][] { spawnPackets, delayedPackets }; + return new PacketContainer[][]{spawnPackets, delayedPackets}; } /** @@ -547,8 +545,7 @@ public class PacketsManager { DisguiseSound entitySound = null; Disguise disguise = null; Entity[] entities = soundLoc.getChunk().getEntities(); - for (int i = 0; i < entities.length; i++) { - Entity entity = entities[i]; + for (Entity entity : entities) { Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); if (entityDisguise != null) { Location loc = entity.getLocation(); @@ -618,8 +615,7 @@ public class PacketsManager { typeId); if (block != null) { Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); - mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound") - .invoke(step)); + mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step)); } } catch (Exception ex) { ex.printStackTrace(); @@ -682,7 +678,7 @@ public class PacketsManager { } } } else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) { - if ((Byte) mods.read(1) == 2) { + if ((byte) mods.read(1) == 2) { // It made a damage animation Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); Disguise disguise = DisguiseAPI.getDisguise(observer, entity); @@ -773,7 +769,7 @@ public class PacketsManager { PacketContainer[] packets = transformed == null ? null : transformed[0]; final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1]; if (packets == null) { - packets = new PacketContainer[] { event.getPacket() }; + packets = new PacketContainer[]{event.getPacket()}; } for (PacketContainer packet : packets) { if (packet.getType() != PacketType.Play.Server.PLAYER_INFO) { @@ -805,7 +801,7 @@ public class PacketsManager { event.setPacket(event.getPacket().deepClone()); for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) { if (watch.getIndex() == 0) { - byte b = (Byte) watch.getValue(); + byte b = (byte) watch.getValue(); byte a = (byte) (b | 1 << 5); if ((b & 1 << 3) != 0) a = (byte) (a | 1 << 3); @@ -817,7 +813,7 @@ public class PacketsManager { PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); StructureModifier mods = packet.getModifier(); mods.write(0, observer.getEntityId()); - List watchableList = new ArrayList(); + List watchableList = new ArrayList<>(); byte b = (byte) 1 << 5; if (observer.isSprinting()) b = (byte) (b | 1 << 3); @@ -1144,7 +1140,7 @@ public class PacketsManager { if (mainListener != null) { ProtocolLibrary.getProtocolManager().removePacketListener(mainListener); } - List packetsToListen = new ArrayList(); + List packetsToListen = new ArrayList<>(); // Add spawn packets { packetsToListen.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN); @@ -1269,14 +1265,14 @@ public class PacketsManager { Disguise disguise = DisguiseAPI.getDisguise(observer, entity); // If disguised. if (disguise != null) { - packets = new PacketContainer[] { sentPacket }; + packets = new PacketContainer[]{sentPacket}; // This packet sends attributes if (sentPacket.getType() == PacketType.Play.Server.UPDATE_ATTRIBUTES) { if (disguise.isMiscDisguise()) { packets = new PacketContainer[0]; } else { - List attributes = new ArrayList(); + List attributes = new ArrayList<>(); for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) { if (attribute.getAttributeKey().equals("generic.maxHealth")) { packets[0] = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); @@ -1340,9 +1336,7 @@ public class PacketsManager { .getWatcher()).isSleeping())))) { packets = new PacketContainer[0]; } - } - - else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) { + } else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) { if (disguise.getType().isMisc()) { packets = new PacketContainer[0]; } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() @@ -1351,7 +1345,7 @@ public class PacketsManager { StructureModifier mods = newPacket.getIntegers(); mods.write(0, disguise.getEntity().getEntityId()); mods.write(1, 3); - packets = new PacketContainer[] { newPacket, sentPacket }; + packets = new PacketContainer[]{newPacket, sentPacket}; } } @@ -1408,9 +1402,7 @@ public class PacketsManager { } } } - } - - else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) { + } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) { int slot = (Integer) packets[0].getModifier().read(1) - 1; if (slot < 0) slot = 4; @@ -1424,7 +1416,7 @@ public class PacketsManager { ItemStack heldItem = packets[0].getItemModifier().read(0); if (heldItem != null && heldItem.getType() != Material.AIR) { // Convert the datawatcher - List list = new ArrayList(); + List list = new ArrayList<>(); if (DisguiseConfig.isMetadataPacketsEnabled()) { list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); list = disguise.getWatcher().convert(list); @@ -1444,30 +1436,24 @@ public class PacketsManager { PacketContainer packetUnblock = packetBlock.deepClone(); // Make a packet to send the 'unblock' for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { - watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4))); + watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); } // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler // delay. - packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock }; + packets = new PacketContainer[]{packetUnblock, packets[0], packetBlock}; // Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset // it. } } - } - - else if (sentPacket.getType() == PacketType.Play.Server.BED) { + } else if (sentPacket.getType() == PacketType.Play.Server.BED) { if (!disguise.getType().isPlayer()) { packets = new PacketContainer[0]; } - } - - else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) { + } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) { if (packets[0].getBytes().read(0) == (byte) 3) { packets = new PacketContainer[0]; } - } - - else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) { + } else if (sentPacket.getType() == PacketType.Play.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()), @@ -1481,11 +1467,9 @@ public class PacketsManager { look.getIntegers().write(0, entity.getEntityId()); look.getBytes().write(3, yaw); look.getBytes().write(4, pitch); - packets = new PacketContainer[] { look, rotation }; + packets = new PacketContainer[]{look, rotation}; } - } - - else { + } else { packets = null; } @@ -1493,6 +1477,6 @@ public class PacketsManager { } catch (Exception e) { e.printStackTrace(); } - return packets == null ? null : new PacketContainer[][] { packets, delayedPackets }; + return packets == null ? null : new PacketContainer[][]{packets, delayedPackets}; } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java index 138ba74a..a43e7b57 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -28,21 +28,6 @@ import java.util.regex.Pattern; public class ReflectionManager { - public enum LibVersion { - - V1_8; - private static LibVersion currentVersion; - - static { - //String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", ""); - currentVersion = V1_8; - } - - public static LibVersion getGameVersion() { - return currentVersion; - } - } - private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static final Class craftItemClass; private static Method damageAndIdleSoundMethod; @@ -551,7 +536,7 @@ public class ReflectionManager { try { damageAndIdleSoundMethod.setAccessible(true); return (Float) damageAndIdleSoundMethod.invoke(entity); - } catch (Exception ex) { + } catch (Exception ignored) { } return null; } @@ -610,6 +595,7 @@ public class ReflectionManager { public static void setAllowSleep(Player player) { try { + //TODO: Fix this! /** * Object nmsEntity = getNmsEntity(player); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); Field check = getNmsField(connection.getClass(), "checkMovement"); check.setBoolean(connection, true); * */ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 00052701..2e6d345f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: LibsDisguises main: me.libraryaddict.disguise.LibsDisguises -version: 8.6.8 +version: 9.0.0 author: libraryaddict authors: [Byteflux, Navid K.] softdepend: [ProtocolLib]