From 49d716f2852661813af028e4fb9dfafe916c3e8b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 5 Aug 2018 20:34:02 +1200 Subject: [PATCH] Update plugin to 1.13, bump maven version, bump java version to 1.8 --- plugin.yml | 2 + pom.xml | 10 +- .../disguise/DisguiseListener.java | 1 + .../libraryaddict/disguise/LibsDisguises.java | 48 +++++--- .../disguise/disguisetypes/DisguiseType.java | 13 +- .../disguise/disguisetypes/FlagWatcher.java | 38 ++++-- .../disguise/disguisetypes/MetaIndex.java | 92 +++++++------- .../disguise/disguisetypes/MiscDisguise.java | 52 +++++--- .../watchers/AbstractHorseWatcher.java | 7 +- .../watchers/AreaEffectCloudWatcher.java | 15 +-- .../disguisetypes/watchers/BoatWatcher.java | 13 +- .../watchers/EnderCrystalWatcher.java | 6 +- .../watchers/EndermanWatcher.java | 59 +++------ .../disguisetypes/watchers/HorseWatcher.java | 12 +- .../watchers/MinecartWatcher.java | 51 +++----- .../disguisetypes/watchers/PigWatcher.java | 11 +- .../watchers/ShulkerWatcher.java | 7 +- .../watchers/TameableWatcher.java | 7 +- .../disguisetypes/watchers/ZombieWatcher.java | 8 ++ .../disguise/utilities/DisguiseParser.java | 56 +++++---- .../disguise/utilities/DisguiseUtilities.java | 55 ++++++--- .../disguise/utilities/LibsPremium.java | 4 +- .../disguise/utilities/PacketsManager.java | 7 +- .../utilities/ReflectionFlagWatchers.java | 42 ++----- .../disguise/utilities/ReflectionManager.java | 115 ++++++++++++++---- .../utilities/backwards/BackwardMethods.java | 22 ---- .../utilities/backwards/BackwardsSupport.java | 108 ---------------- .../backwards/metadata/Version_1_10.java | 22 ---- .../backwards/metadata/Version_1_11.java | 18 --- .../backwards/metadata/Version_1_7.java | 7 -- .../backwards/metadata/Version_1_8.java | 7 -- .../backwards/metadata/Version_1_9.java | 9 -- .../PacketListenerClientInteract.java | 22 ++-- .../packetlisteners/PacketListenerSounds.java | 11 +- src/org/bukkit/inventory/EquipmentSlot.java | 10 -- src/org/bukkit/inventory/MainHand.java | 6 - 36 files changed, 425 insertions(+), 548 deletions(-) delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_11.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_7.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_8.java delete mode 100644 src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_9.java delete mode 100644 src/org/bukkit/inventory/EquipmentSlot.java delete mode 100644 src/org/bukkit/inventory/MainHand.java diff --git a/plugin.yml b/plugin.yml index 4b161982..14e448eb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -129,3 +129,5 @@ permissions: description: See the /disguisemodifyradius command in tab-completion libsdisguises.seecmd.disguisemodifyentity: description: See the /disguisemodifyentity command in tab-completion + +api-version: 1.13 \ No newline at end of file diff --git a/pom.xml b/pom.xml index da7a14b1..27c85c2c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 LibsDisguises LibsDisguises - 9.5.2-SNAPSHOT + 9.6.0-SNAPSHOT src @@ -28,8 +28,8 @@ - 1.7 - 1.7 + 1.8 + 1.8 UTF-8 @@ -43,12 +43,12 @@ org.spigotmc spigot-api - 1.12-pre6-SNAPSHOT + 1.13-R0.1-SNAPSHOT org.spigotmc spigot - 1.12-pre6-SNAPSHOT + 1.13-R0.1-SNAPSHOT diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 8f444f20..82b20b27 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -7,6 +7,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedGameProfile; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 024dbdc7..afebfca3 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -39,6 +39,18 @@ public class LibsDisguises extends JavaPlugin { LibsPremium.check(getDescription().getVersion()); + if (ReflectionManager.getMinecraftVersion().startsWith("1.13")) { + if (!LibsPremium.isPremium()) { + System.out.println("[LibsDisguises] You must purchase the plugin to use 1.13!"); + System.out.println( + "[LibsDisguises] This will be released free two weeks after all bugs have been fixed!"); + System.out.println( + "[LibsDisguises] If you've already purchased the plugin, place the purchased jar inside the " + + "Lib's Disguises plugin folder"); + return; + } + } + PacketsManager.init(this); DisguiseUtilities.init(this); @@ -426,6 +438,8 @@ public class LibsDisguises extends JavaPlugin { continue; } + disguiseType.setTypeId(ReflectionManager.getEntityType(nmsEntity)); + Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); int entitySize = 0; @@ -449,36 +463,34 @@ public class LibsDisguises extends JavaPlugin { MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); 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() + ") (" + - nmsEntity.getClass() + ") & " + watcherClass.getSimpleName()); - System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); + System.err.println("[LibsDisguises] MetaIndex not found for " + disguiseType + "! Index: " + + watch.getIndex()); + System.err.println("[LibsDisguises] Value: " + watch.getRawValue() + " (" + + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + + watcherClass.getSimpleName()); continue; } indexes.remove(flagType); - Object obj1 = ReflectionManager.convertInvalidItem(flagType.getDefault()); - Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue()); + Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault()); + Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getValue()); - if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) { - System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " + - watch.getIndex() + " has the wrong classtype!"); - System.err.println("MetaIndex has the " + "default of " + flagType.getDefault() + " (" + + if (ourValue != nmsValue && + ((ourValue == null || nmsValue == null) || ourValue.getClass() != nmsValue.getClass())) { + System.err.println("[LibsDisguises] MetaIndex mismatch for " + disguiseType + "! Index: " + + watch.getIndex()); + System.err.println("[LibsDisguises] MetaIndex: " + flagType.getDefault() + " (" + flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName()); - System.err.println("Where the internals is " + watch.getRawValue() + " (" + - watch.getRawValue().getClass()); - System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); + System.err.println("[LibsDisguises] Minecraft: " + watch.getRawValue() + " (" + + watch.getRawValue().getClass() + ")"); } } for (MetaIndex index : indexes) { - System.out.println( - disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + - " at index " + index.getIndex()); + System.out.println("[LibsDisguises] " + disguiseType + " has MetaIndex remaining! " + + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex()); } DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index dd67dc5d..1c29bab7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -181,7 +181,8 @@ public enum DisguiseType { ZOMBIE_VILLAGER; static { - // We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC. + // 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()) { @@ -191,7 +192,8 @@ public enum DisguiseType { String name; /* switch (type) { - // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being.. + // 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; @@ -231,6 +233,7 @@ public enum DisguiseType { private EntityType entityType; private int objectId = -1, defaultData = 0; + private int typeId; private Class watcherClass; @@ -284,7 +287,11 @@ public enum DisguiseType { * @return */ public int getTypeId() { - return (int) getEntityType().getTypeId(); + return typeId; + } + + public void setTypeId(int typeId) { + this.typeId = typeId; } public Class getWatcherClass() { diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index aa8cf2f9..fd523a3f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -4,12 +4,17 @@ import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.ComponentConverter; +import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedWatchableObject; +import com.google.common.base.Strings; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -152,8 +157,8 @@ public class FlagWatcher { } } // Here we check for if there is a health packet that says they died. - if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise() - .getEntity() instanceof Player) { + if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && + getDisguise().getEntity() instanceof Player) { for (WrappedWatchableObject watch : newList) { // Its a health packet if (watch.getIndex() == 6) { @@ -194,7 +199,15 @@ public class FlagWatcher { } public String getCustomName() { - return (String) getData(MetaIndex.ENTITY_CUSTOM_NAME); + Optional optional = getData(MetaIndex.ENTITY_CUSTOM_NAME); + + if (optional.isPresent()) { + BaseComponent[] base = ComponentConverter.fromWrapper(optional.get()); + + return TextComponent.toLegacyText(base); + } + + return null; } protected TargetedDisguise getDisguise() { @@ -329,8 +342,8 @@ public class FlagWatcher { Object value = entityValues.get(data.getIndex()); - if (isEntityAnimationsAdded() && DisguiseConfig - .isMetadataPacketsEnabled() && data == MetaIndex.ENTITY_META) { + if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && + data == MetaIndex.ENTITY_META) { value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); } @@ -391,11 +404,16 @@ public class FlagWatcher { } public void setCustomName(String name) { - if (name != null && name.length() > 64) { - name = name.substring(0, 64); + if (Strings.isNullOrEmpty(name)) { + setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); + } else { + if (name.length() > 64) { + name = name.substring(0, 64); + } + + setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name))); } - setData(MetaIndex.ENTITY_CUSTOM_NAME, name); sendData(MetaIndex.ENTITY_CUSTOM_NAME); } @@ -454,8 +472,8 @@ public class FlagWatcher { } protected void sendItemStack(EquipmentSlot slot, ItemStack itemStack) { - if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this || getDisguise() - .getEntity() == null) + if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this || + getDisguise().getEntity() == null) return; if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index 03897535..6722041d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -1,15 +1,14 @@ package me.libraryaddict.disguise.disguisetypes; -import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.EnumWrappers.Direction; -import com.comphenix.protocol.wrappers.Vector3F; -import com.comphenix.protocol.wrappers.WrappedBlockData; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; +import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import com.google.common.base.Optional; +import com.comphenix.protocol.wrappers.nbt.NbtType; import me.libraryaddict.disguise.disguisetypes.watchers.*; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.inventory.ItemStack; import java.lang.reflect.Field; @@ -27,11 +26,8 @@ public class MetaIndex { public static MetaIndex AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2, false); - public static MetaIndex AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, 0); - - public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_1 = new MetaIndex<>(AreaEffectCloudWatcher.class, 4, 0); - - public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_2 = new MetaIndex<>(AreaEffectCloudWatcher.class, 5, 0); + public static MetaIndex AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, + 3, Particle.SPELL_MOB); public static MetaIndex AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 0F); @@ -73,6 +69,8 @@ public class MetaIndex { public static MetaIndex BOAT_TYPE = new MetaIndex<>(BoatWatcher.class, 3, 0); + public static MetaIndex BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0); + public static MetaIndex CREEPER_IGNITED = new MetaIndex<>(CreeperWatcher.class, 2, false); public static MetaIndex CREEPER_POWERED = new MetaIndex<>(CreeperWatcher.class, 1, false); @@ -83,7 +81,7 @@ public class MetaIndex { new ItemStack(Material.STONE)); public static MetaIndex> ENDER_CRYSTAL_BEAM = new MetaIndex<>(EnderCrystalWatcher.class, 0, - Optional.absent()); + Optional.empty()); public static MetaIndex ENDER_CRYSTAL_PLATE = new MetaIndex<>(EnderCrystalWatcher.class, 1, false); @@ -92,11 +90,12 @@ public class MetaIndex { public static MetaIndex ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); public static MetaIndex> ENDERMAN_ITEM = new MetaIndex<>(EndermanWatcher.class, 0, - Optional.absent()); + Optional.empty()); public static MetaIndex ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 0); - public static MetaIndex ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, ""); + public static MetaIndex> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, + Optional.empty()); public static MetaIndex ENTITY_CUSTOM_NAME_VISIBLE = new MetaIndex<>(FlagWatcher.class, 3, false); @@ -132,7 +131,7 @@ public class MetaIndex { public static MetaIndex HORSE_META = new MetaIndex<>(AbstractHorseWatcher.class, 0, (byte) 0); public static MetaIndex> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1, - Optional.absent()); + Optional.empty()); public static MetaIndex ILLAGER_META = new MetaIndex<>(IllagerWatcher.class, 0, (byte) 0); @@ -181,7 +180,7 @@ public class MetaIndex { public static MetaIndex PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false); - public static MetaIndex PIG_UNKNOWN = new MetaIndex<>(PigWatcher.class, 1, 0); + public static MetaIndex PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0); public static MetaIndex PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F); @@ -191,11 +190,11 @@ public class MetaIndex { public static MetaIndex PLAYER_SKIN = new MetaIndex<>(PlayerWatcher.class, 2, (byte) 127); - public static MetaIndex PLAYER_LEFT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 4, - NbtFactory.ofCompound("None")); + public static MetaIndex PLAYER_LEFT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 4, + NbtFactory.ofWrapper(NbtType.TAG_COMPOUND, "None")); - public static MetaIndex PLAYER_RIGHT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 5, - NbtFactory.ofCompound("None")); + public static MetaIndex PLAYER_RIGHT_SHOULDER_ENTITY = new MetaIndex<>(PlayerWatcher.class, 5, + NbtFactory.ofWrapper(NbtType.TAG_COMPOUND, "None")); public static MetaIndex POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false); @@ -204,7 +203,7 @@ public class MetaIndex { public static MetaIndex SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0); public static MetaIndex> SHULKER_ATTACHED = new MetaIndex<>(ShulkerWatcher.class, 1, - Optional.absent()); + Optional.empty()); public static MetaIndex SHULKER_COLOR = new MetaIndex<>(ShulkerWatcher.class, 3, (byte) 10); @@ -225,7 +224,7 @@ public class MetaIndex { public static MetaIndex TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0); public static MetaIndex> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, - Optional.absent()); + Optional.empty()); public static MetaIndex TIPPED_ARROW_COLOR = new MetaIndex<>(ArrowWatcher.class, 1, Color.WHITE.asRGB()); @@ -259,6 +258,8 @@ public class MetaIndex { public static MetaIndex ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false); + public static MetaIndex ZOMBIE_CONVERTING_DROWNED = new MetaIndex<>(ZombieWatcher.class, 3, false); + public static MetaIndex ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0); public static MetaIndex ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, 0); @@ -273,10 +274,13 @@ public class MetaIndex { catch (Exception ex) { SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, new ItemStack(Material.POTION)); } + setValues(); + orderMetaIndexes(); } - public static void eliminateBlankIndexes() { + @Deprecated + private static void eliminateBlankIndexes() { ArrayList>> list = new ArrayList<>(); for (MetaIndex index : values()) { @@ -292,6 +296,7 @@ public class MetaIndex { if (entry == null) { entry = new AbstractMap.SimpleEntry(index.getFlagWatcher(), new ArrayList()); + list.add(entry); } @@ -299,12 +304,7 @@ public class MetaIndex { } for (Entry> entry : list) { - Collections.sort(entry.getValue(), new Comparator() { - @Override - public int compare(MetaIndex o1, MetaIndex o2) { - return o1.getIndex() - o2.getIndex(); - } - }); + entry.getValue().sort(Comparator.comparingInt(MetaIndex::getIndex)); for (MetaIndex ind : entry.getValue()) { ind._index = entry.getValue().indexOf(ind); @@ -312,7 +312,7 @@ public class MetaIndex { } } - public static void orderMetaIndexes() { + private static void orderMetaIndexes() { for (MetaIndex flagType : values()) { if (flagType.getFlagWatcher() == FlagWatcher.class) continue; @@ -349,10 +349,10 @@ public class MetaIndex { continue; if (found != null) { - System.err.println(entry.getKey() - .getSimpleName() + " has multiple FlagType's registered for the index " + i + " (" + type - .getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher() - .getSimpleName() + ")"); + System.err.println( + entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " + + i + " (" + type.getFlagWatcher().getSimpleName() + ", " + + found.getFlagWatcher().getSimpleName() + ")"); continue loop; } @@ -377,15 +377,16 @@ public class MetaIndex { MetaIndex index = (MetaIndex) field.get(null); - toPrint.add(index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index - .getIndex() + " " + index.getDefault().getClass().getSimpleName()); + toPrint.add( + index.getFlagWatcher().getSimpleName() + " " + field.getName() + " " + index.getIndex() + " " + + index.getDefault().getClass().getSimpleName()); } } catch (Exception ex) { ex.printStackTrace(); } - Collections.sort(toPrint, String.CASE_INSENSITIVE_ORDER); + toPrint.sort(String.CASE_INSENSITIVE_ORDER); for (String s : toPrint) { System.out.println(s); @@ -416,12 +417,7 @@ public class MetaIndex { list.add(type); } - Collections.sort(list, new Comparator() { - @Override - public int compare(MetaIndex o1, MetaIndex o2) { - return Integer.compare(o1.getIndex(), o2.getIndex()); - } - }); + list.sort(Comparator.comparingInt(MetaIndex::getIndex)); return list; } @@ -460,15 +456,15 @@ public class MetaIndex { } for (MetaIndex metaIndex : values()) { - if (metaIndex == null || metaIndex.getFlagWatcher() != index.getFlagWatcher() || metaIndex - .getIndex() != index.getIndex()) { + if (metaIndex == null || metaIndex.getFlagWatcher() != index.getFlagWatcher() || + metaIndex.getIndex() != index.getIndex()) { continue; } - System.err.println("[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher() - .getSimpleName() + " at index " + metaIndex - .getIndex() + " has already registered this! (" + metaIndex.getDefault() + "," + index - .getDefault() + ")"); + System.err.println( + "[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " + + metaIndex.getIndex() + " has already registered this! (" + metaIndex.getDefault() + + "," + index.getDefault() + ")"); } values()[i] = metaIndexes[a]; diff --git a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java index 0323f88a..cedb8a5d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java @@ -1,16 +1,16 @@ package me.libraryaddict.disguise.disguisetypes; -import java.security.InvalidParameterException; - -import org.bukkit.Art; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; +import org.bukkit.Art; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.security.InvalidParameterException; public class MiscDisguise extends TargetedDisguise { private int id = -1, data = 0; @@ -19,6 +19,18 @@ public class MiscDisguise extends TargetedDisguise { this(disguiseType, -1, disguiseType.getDefaultData()); } + public MiscDisguise(Material material, int data) { + super(DisguiseType.DROPPED_ITEM); + + apply(0, 0, new ItemStack(material, 1, (short) data)); + } + + public MiscDisguise(ItemStack itemStack) { + super(DisguiseType.DROPPED_ITEM); + + apply(0, 0, itemStack); +} + public MiscDisguise(DisguiseType disguiseType, int id) { this(disguiseType, id, disguiseType.getDefaultData()); } @@ -28,34 +40,37 @@ public class MiscDisguise extends TargetedDisguise { if (!disguiseType.isMisc()) { throw new InvalidParameterException( - "Expected a non-living DisguiseType while constructing MiscDisguise. Received " + disguiseType + " instead. Please use " + ( - disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") + " instead"); + "Expected a non-living DisguiseType while constructing MiscDisguise. Received " + disguiseType + + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") + + " instead"); } + apply(id, data, new ItemStack(Material.STONE)); + } + + private void apply(int id, int data, ItemStack itemStack) { createDisguise(); this.id = getType().getTypeId(); this.data = getType().getDefaultData(); - switch (disguiseType) { + + switch (getType()) { // The only disguises which should use a custom data. case PAINTING: ((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, id) % Art.values().length]); break; case FALLING_BLOCK: - ((FallingBlockWatcher) getWatcher()).setBlock( - new ItemStack(Math.max(1, id), 1, (short) Math.max(0, data))); + ((FallingBlockWatcher) getWatcher()).setBlock(itemStack); break; case SPLASH_POTION: ((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id)); break; case DROPPED_ITEM: - - if (id > 0) { - ((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(1, data))); - } + ((DroppedItemWatcher) getWatcher()).setItemStack(itemStack); break; case FISHING_HOOK: // Entity ID of whoever is holding fishing rod - case ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving through his body?" + case ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving + // through his body?" case TIPPED_ARROW: case SPECTRAL_ARROW: case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter @@ -116,8 +131,9 @@ public class MiscDisguise extends TargetedDisguise { */ public int getId() { if (getType() == DisguiseType.FALLING_BLOCK) { - return ((FallingBlockWatcher) getWatcher()).getBlock().getTypeId(); + return ((FallingBlockWatcher) getWatcher()).getBlock().getType().ordinal(); } + return id; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java index d134ec77..cd4b0b00 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AbstractHorseWatcher.java @@ -1,12 +1,11 @@ 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.MetaIndex; +import java.util.Optional; +import java.util.UUID; + public abstract class AbstractHorseWatcher extends AgeableWatcher { public AbstractHorseWatcher(Disguise disguise) { super(disguise); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index 64b9e18d..c6be1090 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -1,8 +1,9 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import org.bukkit.Particle; /** * @author Navid @@ -27,10 +28,6 @@ public class AreaEffectCloudWatcher extends FlagWatcher { return getData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); } - public int getParticleId() { - return getData(MetaIndex.AREA_EFFECT_PARTICLE); - } - public void setRadius(float radius) { if (radius > 30) radius = 30; @@ -49,8 +46,12 @@ public class AreaEffectCloudWatcher extends FlagWatcher { sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); } - public void setParticleId(int particleId) { - setData(MetaIndex.AREA_EFFECT_PARTICLE, particleId); + public void setParticleType(Particle particle) { + setData(MetaIndex.AREA_EFFECT_PARTICLE, particle); sendData(MetaIndex.AREA_EFFECT_PARTICLE); } + + public Particle getParticleType() { + return getData(MetaIndex.AREA_EFFECT_PARTICLE); + } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java index bd598305..1fb35ce0 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java @@ -1,10 +1,9 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.TreeSpecies; - import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import org.bukkit.TreeSpecies; public class BoatWatcher extends FlagWatcher { public BoatWatcher(Disguise disguise) { @@ -45,8 +44,16 @@ public class BoatWatcher extends FlagWatcher { sendData(MetaIndex.BOAT_TYPE); } + public void setBoatShake(int number) { + setData(MetaIndex.BOAT_SHAKE, number); + sendData(MetaIndex.BOAT_SHAKE); + } + + public int getBoatShake() { + return getData(MetaIndex.BOAT_SHAKE); + } + public TreeSpecies getBoatType() { return TreeSpecies.getByData(getData(MetaIndex.BOAT_TYPE).byteValue()); } - } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java index 1f80ff32..372cb30d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java @@ -1,11 +1,11 @@ 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.MetaIndex; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; + +import java.util.Optional; /** * @author Navid diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index c2b501ea..92a03adb 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -1,85 +1,60 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import com.comphenix.protocol.wrappers.WrappedBlockData; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import com.comphenix.protocol.wrappers.WrappedBlockData; -import com.google.common.base.Optional; +import java.util.Optional; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; +public class EndermanWatcher extends InsentientWatcher { -public class EndermanWatcher extends InsentientWatcher -{ - - public EndermanWatcher(Disguise disguise) - { + public EndermanWatcher(Disguise disguise) { super(disguise); } @Override - public ItemStack getItemInMainHand() - { + public ItemStack getItemInMainHand() { Optional value = getData(MetaIndex.ENDERMAN_ITEM); - if (value.isPresent()) - { + if (value.isPresent()) { WrappedBlockData pair = value.get(); Material id = pair.getType(); int data = pair.getData(); return new ItemStack(id, 1, (short) data); - } - else - { + } else { return null; } } @Override - public void setItemInMainHand(ItemStack itemstack) - { - setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability()); + public void setItemInMainHand(ItemStack itemstack) { + setItemInMainHand(itemstack.getType(), itemstack.getDurability()); } - @Deprecated - public void setItemInMainHand(int typeId) - { - setItemInMainHand(typeId, 0); - } - - public void setItemInMainHand(Material type) - { + public void setItemInMainHand(Material type) { setItemInMainHand(type, 0); } - public void setItemInMainHand(Material type, int data) - { + public void setItemInMainHand(Material type, int data) { Optional optional; if (type == null) - optional = Optional. absent(); + optional = Optional.empty(); else - optional = Optional. of(WrappedBlockData.createData(type, data)); + optional = Optional.of(WrappedBlockData.createData(type, data)); setData(MetaIndex.ENDERMAN_ITEM, optional); } - @Deprecated - public void setItemInMainHand(int typeId, int data) - { - setItemInMainHand(Material.getMaterial(typeId), data); - } - - public boolean isAggressive() - { + public boolean isAggressive() { return getData(MetaIndex.ENDERMAN_AGRESSIVE); } - public void setAggressive(boolean isAggressive) - { + public void setAggressive(boolean isAggressive) { setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive); sendData(MetaIndex.ENDERMAN_AGRESSIVE); } - } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java index d8a0f57b..46f602ec 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java @@ -26,11 +26,11 @@ public class HorseWatcher extends AbstractHorseWatcher { switch (horseValue) { case 1: - return new ItemStack(Material.IRON_BARDING); + return new ItemStack(Material.IRON_HORSE_ARMOR); case 2: - return new ItemStack(Material.GOLD_BARDING); + return new ItemStack(Material.GOLDEN_HORSE_ARMOR); case 3: - return new ItemStack(Material.DIAMOND_BARDING); + return new ItemStack(Material.DIAMOND_HORSE_ARMOR); default: break; } @@ -67,13 +67,13 @@ public class HorseWatcher extends AbstractHorseWatcher { if (item != null) { Material mat = item.getType(); - if (mat == Material.IRON_BARDING) { + if (mat == Material.IRON_HORSE_ARMOR) { value = 1; } - else if (mat == Material.GOLD_BARDING) { + else if (mat == Material.GOLDEN_HORSE_ARMOR) { value = 2; } - else if (mat == Material.DIAMOND_BARDING) { + else if (mat == Material.DIAMOND_HORSE_ARMOR) { value = 3; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index e2284b18..e75f6c02 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -1,56 +1,43 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.ReflectionManager; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +public class MinecartWatcher extends FlagWatcher { -public class MinecartWatcher extends FlagWatcher -{ - - public MinecartWatcher(Disguise disguise) - { + public MinecartWatcher(Disguise disguise) { super(disguise); } - public ItemStack getBlockInCart() - { - int id = (int) getData(MetaIndex.MINECART_BLOCK) & 0xffff; - int data = (int) getData(MetaIndex.MINECART_BLOCK) >> 16; - - return new ItemStack(id, 1, (short) data); + public ItemStack getBlockInCart() { + return ReflectionManager.getItemStackByCombinedId(getData(MetaIndex.MINECART_BLOCK)); } - public int getBlockYOffset() - { - return (int) getData(MetaIndex.MINECART_BLOCK_Y); + public int getBlockYOffset() { + return getData(MetaIndex.MINECART_BLOCK_Y); } - public boolean isViewBlockInCart() - { - return (boolean) getData(MetaIndex.MINECART_BLOCK_VISIBLE); + public boolean isViewBlockInCart() { + return getData(MetaIndex.MINECART_BLOCK_VISIBLE); } - public void setBlockInCart(ItemStack item) - { - int id = item.getTypeId(); - int data = item.getDurability(); + public void setBlockInCart(ItemStack item) { + setData(MetaIndex.MINECART_BLOCK, ReflectionManager.getCombinedIdByItemStack(item)); + setData(MetaIndex.MINECART_BLOCK_VISIBLE, item != null && item.getType() != Material.AIR); - setData(MetaIndex.MINECART_BLOCK, id & 0xffff | data << 16); - setData(MetaIndex.MINECART_BLOCK_VISIBLE, true); // Show block - - sendData(MetaIndex.MINECART_BLOCK); + sendData(MetaIndex.MINECART_BLOCK, MetaIndex.MINECART_BLOCK_VISIBLE); } - public void setBlockOffset(int i) - { + public void setBlockOffset(int i) { setData(MetaIndex.MINECART_BLOCK_Y, i); sendData(MetaIndex.MINECART_BLOCK_Y); } - public void setViewBlockInCart(boolean viewBlock) - { + public void setViewBlockInCart(boolean viewBlock) { setData(MetaIndex.MINECART_BLOCK_VISIBLE, viewBlock); sendData(MetaIndex.MINECART_BLOCK_VISIBLE); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java index df69585e..4c150a61 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java @@ -10,20 +10,11 @@ public class PigWatcher extends AgeableWatcher { } public boolean isSaddled() { - return (boolean) getData(MetaIndex.PIG_SADDLED); + return getData(MetaIndex.PIG_SADDLED); } public void setSaddled(boolean isSaddled) { setData(MetaIndex.PIG_SADDLED, isSaddled); sendData(MetaIndex.PIG_SADDLED); } - - /* public int getUnknown() { - return getData(FlagType.PIG_UNKNOWN); - } - - public void setUnknown(int unknown) { - setData(FlagType.PIG_UNKNOWN, unknown); - sendData(FlagType.PIG_UNKNOWN); - }*/ } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java index c8a3e635..7d7b5c03 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java @@ -1,14 +1,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.block.BlockFace; - 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.MetaIndex; +import org.bukkit.block.BlockFace; + +import java.util.Optional; /** * @author Navid diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index 0e41606f..dc4593b5 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -1,12 +1,11 @@ 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.MetaIndex; +import java.util.Optional; +import java.util.UUID; + public class TameableWatcher extends AgeableWatcher { public TameableWatcher(Disguise disguise) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index 3799a1fa..4cb41fc7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -39,4 +39,12 @@ public class ZombieWatcher extends InsentientWatcher { sendData(MetaIndex.ZOMBIE_AGGRESSIVE); } + public boolean isConverting() { + return getData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); + } + + public void setConverting(boolean converting) { + setData(MetaIndex.ZOMBIE_CONVERTING_DROWNED, converting); + sendData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); + } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index d62039a8..ed41fcdf 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -7,6 +7,7 @@ import me.libraryaddict.disguise.disguisetypes.*; import org.bukkit.Art; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.block.BlockFace; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; @@ -22,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; +import java.util.Objects; public class DisguiseParser { public static class DisguiseParseException extends Exception { @@ -110,13 +112,7 @@ public class DisguiseParser { if (disguiseType != other.disguiseType) return false; - if (permName == null) { - if (other.permName != null) - return false; - } else if (!permName.equals(other.permName)) - return false; - - return true; + return Objects.equals(permName, other.permName); } } @@ -585,6 +581,7 @@ public class DisguiseParser { disguise = new MobDisguise(disguisePerm.getType(), adult); } else if (disguisePerm.isMisc()) { // Its a misc, we are going to use the MiscDisguise constructor. + ItemStack itemStack = new ItemStack(Material.STONE); int miscId = -1; int miscData = -1; String secondArg = null; @@ -607,6 +604,7 @@ public class DisguiseParser { disguisePerm.getType() == DisguiseType.DROPPED_ITEM) { for (Material mat : Material.values()) { if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) { + itemStack = new ItemStack(mat); miscId = mat.getId(); break; } @@ -681,8 +679,13 @@ public class DisguiseParser { doCheck(sender, optionPermissions, usedOptions); } } + // Construct the disguise - disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData); + if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM) { + disguise = new MiscDisguise(itemStack); + } else { + disguise = new MiscDisguise(disguisePerm.getType(), miscId, miscData); + } } } } @@ -888,6 +891,7 @@ public class DisguiseParser { break; } } + if (value == null) { throw new Exception(); } @@ -907,8 +911,26 @@ public class DisguiseParser { catch (Exception ex) { throw parseToException(param, valueString, methodName); } - } else if (param.getName().equals("org.bukkit.entity.Parrot$Variant")) { + } else if (param == Parrot.Variant.class) { value = callValueOf(param, valueString, methodName); + } else if (param == Particle.class) { + try { + for (Particle type : Particle.values()) { + if (type.name().replace("_", "") + .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) { + value = type; + + break; + } + } + + if (value == null) { + throw new Exception(); + } + } + catch (Exception ex) { + throw parseToException(param, valueString, methodName); + } } } @@ -979,21 +1001,13 @@ public class DisguiseParser { private static ItemStack parseToItemstack(Class param, String method, String string) throws DisguiseParseException { String[] split = string.split(":", -1); - int itemId = -1; - if (split[0].isEmpty() || split[0].equalsIgnoreCase("null")) { return null; - } else if (isInteger(split[0])) { - itemId = Integer.parseInt(split[0]); - } else { - try { - itemId = Material.valueOf(split[0].toUpperCase()).getId(); - } - catch (Exception ignored) { - } } - if (itemId != -1) { + Material material = Material.getMaterial(split[0]); + + if (material != null) { short itemDura = 0; int amount = 1; boolean enchanted = false; @@ -1018,7 +1032,7 @@ public class DisguiseParser { } } - ItemStack itemStack = new ItemStack(itemId, amount, itemDura); + ItemStack itemStack = new ItemStack(material, amount, itemDura); if (enchanted) { itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 66be84c5..59c11b81 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -23,8 +23,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; -import me.libraryaddict.disguise.utilities.backwards.BackwardMethods; -import me.libraryaddict.disguise.utilities.backwards.BackwardsSupport; import me.libraryaddict.disguise.utilities.json.*; import org.apache.logging.log4j.util.Strings; import org.bukkit.Bukkit; @@ -50,10 +48,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.lang.reflect.*; import java.util.*; import java.util.regex.Pattern; @@ -81,7 +76,6 @@ public class DisguiseUtilities { private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File( "plugins/LibsDisguises/SavedDisguises"); private static Gson gson; - private static BackwardMethods methods; private static boolean pluginsUsed, commandsUsed; private static long libsDisguisesCalled; @@ -851,7 +845,6 @@ public class DisguiseUtilities { public static void init(LibsDisguises disguises) { libsDisguises = disguises; - methods = BackwardsSupport.getMethods(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex()); @@ -867,21 +860,43 @@ public class DisguiseUtilities { try { Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null); Object world = ((List) server.getClass().getField("worlds").get(server)).get(0); + Class chunkClass = ReflectionManager.getNmsClass("Chunk"); + Object bedChunk = null; - Object bedChunk = ReflectionManager.getNmsClass("Chunk") - .getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class) - .newInstance(world, 0, 0); + for (Constructor constructor : chunkClass.getConstructors()) { + if (constructor.getParameterTypes().length != 8) + continue; - Field cSection = bedChunk.getClass().getDeclaredField("sections"); + bedChunk = constructor + .newInstance(world, 0, 0, Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 0), + null, null, null, 0L); + break; + } + + if (bedChunk == null) { + throw new IllegalStateException("[LibsDisguises] Cannot find constructor to create world chunk"); + } + + Field cSection = chunkClass.getDeclaredField("sections"); cSection.setAccessible(true); Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class) .newInstance(0, true); - Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) - .invoke(null, Material.BED_BLOCK.getId()); + Class blockClass = ReflectionManager.getNmsClass("Block"); + + Object block = blockClass.getMethod("getByName", String.class).invoke(null, "white_bed"); + Object blockData = ReflectionManager.getNmsMethod(blockClass, "getBlockData").invoke(block); + Method method = null; + + for (Method method1 : blockData.getClass().getMethods()) { + if (!method1.getName().equals("set") || method1.getParameterTypes().length != 2) + continue; + + method = method1; + break; + } - Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class); Method setType = chunkSection.getClass() .getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData")); Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class); @@ -889,10 +904,12 @@ public class DisguiseUtilities { for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}) { int x = 1 + face.getModX(); - int z = 1 + face.getModZ(); - setType.invoke(chunkSection, x, 0, z, fromLegacyData.invoke(block, face.ordinal())); + Object data = method.invoke(blockData, block.getClass().getField("FACING").get(null), + ReflectionManager.getEnumDirection(face.ordinal())); + + setType.invoke(chunkSection, x, 0, z, data); } Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16); @@ -1018,9 +1035,7 @@ public class DisguiseUtilities { } catch ( - Exception ex) - - { + Exception ex) { ex.printStackTrace(); } } diff --git a/src/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/me/libraryaddict/disguise/utilities/LibsPremium.java index bac6a3ae..201b7ff4 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -38,7 +38,7 @@ public class LibsPremium { public static void check(String version) { thisPluginIsPaidFor = isPremium(); - if (!isPremium() && version.contains("SNAPSHOT")) { + if (!isPremium()) { File[] files = new File("plugins/LibsDisguises/").listFiles(); if (files == null) @@ -58,7 +58,7 @@ public class LibsPremium { thisPluginIsPaidFor = (Boolean) m.invoke(null); if (isPremium()) { - System.out.println("[LibsDisguises] Found a premium Lib's Disguises jar"); + System.out.println("[LibsDisguises] Found a premium Lib's Disguises jar, premium enabled!"); break; } else { diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index e83d02d7..a0c8c893 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -501,11 +501,8 @@ public class PacketsManager { if (watchableObject.getValue() == null) continue; - if (Registry.get(watchableObject.getValue().getClass()) == null) - continue; - - WrappedDataWatcherObject obj = new WrappedDataWatcherObject(watchableObject.getIndex(), - Registry.get(watchableObject.getValue().getClass())); + WrappedDataWatcherObject obj = ReflectionManager + .createDataWatcherObject(watchableObject.getIndex(), watchableObject.getValue()); newWatcher.setObject(obj, watchableObject.getValue()); } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index c44201b9..e5d7ad17 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -7,12 +7,12 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import org.apache.commons.lang.StringUtils; import org.bukkit.Art; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.TreeSpecies; import org.bukkit.block.BlockFace; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Ocelot; -import org.bukkit.entity.Villager; +import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MainHand; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.EulerAngle; @@ -49,10 +49,6 @@ public class ReflectionFlagWatchers { this.description = description; } - public ParamInfo(String className, String name, String description) throws ClassNotFoundException { - this(Class.forName(className), name, description); - } - public ParamInfo(Class paramClass, Enum[] enums, String name, String description) { this(name, description); this.enums = new String[enums.length]; @@ -143,14 +139,6 @@ public class ReflectionFlagWatchers { static { new ParamInfo(AnimalColor.class, "Animal Color", "View all the colors you can use for an animal color"); new ParamInfo(Art.class, "Art", "View all the paintings you can use for a painting disguise"); - - try { - new ParamInfo("org.bukkit.entity.Llama.Color", "Llama Color", - "View all the colors you can use for a llama color"); - } - catch (Exception ex) { - } - new ParamInfo(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color"); new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots"); @@ -162,21 +150,10 @@ public class ReflectionFlagWatchers { new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"); new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species"); new ParamInfo(EulerAngle.class, "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand"); - - try { - new ParamInfo("org.bukkit.inventory.MainHand", "Main Hand", "Set the main hand for an entity"); - new ParamInfo("org.bukkit.entity.Llama.Color", "Llama Color", - "View all the colors you can use for a llama color"); - } - catch (Exception ex) { - } - - try { - new ParamInfo("org.bukkit.entity.Parrot$Variant", "Parrot Variant", - "View the different colors a parrot can be"); - } - catch (ClassNotFoundException ex) {// Dont handle - } + new ParamInfo(MainHand.class, "Main Hand", "Set the main hand for an entity"); + new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color"); + new ParamInfo(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be"); + new ParamInfo(Particle.class, "Particle", "The different particles of Minecraft"); ArrayList potionEnums = new ArrayList<>(); @@ -229,9 +206,8 @@ public class ReflectionFlagWatchers { new ParamInfo(int[].class, "number,number,number..", "Numbers separated by an ,"); new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers separated by a ,"); - new ParamInfo(WrappedGameProfile.class, "GameProfile", - "Get the gameprofile here https://sessionserver.mojang" + - ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"); + new ParamInfo(WrappedGameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang" + + ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"); Collections.sort(paramList, new Comparator() { @Override diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 5a792a46..f6016275 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -5,11 +5,8 @@ import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtWrapper; -import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -import org.apache.commons.lang3.tuple.ImmutablePair; import org.bukkit.*; import org.bukkit.entity.*; import org.bukkit.inventory.EquipmentSlot; @@ -17,6 +14,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import java.lang.reflect.*; +import java.util.Optional; import java.util.UUID; public class ReflectionManager { @@ -780,7 +778,7 @@ public class ReflectionManager { return null; } - public static Object convertInvalidItem(Object value) { + public static Object convertInvalidMeta(Object value) { if (value instanceof Optional) { Optional opt = (Optional) value; @@ -810,7 +808,7 @@ public class ReflectionManager { val = getNmsItem((ItemStack) val); if (val == null) - return Optional.absent(); + return Optional.empty(); else return Optional.of(val); } @@ -844,32 +842,39 @@ public class ReflectionManager { } } else if (value instanceof ItemStack) { return getNmsItem((ItemStack) value); - } else if (value instanceof Double) + } else if (value instanceof Double) { return ((Double) value).floatValue(); - else if (value instanceof NbtCompound) + } else if (value instanceof NbtWrapper) { return ((NbtWrapper) value).getHandle(); + } else if (value instanceof Particle) { + return getParticleType((Particle) value); + } return value; } + private static Object getParticleType(Particle particle) { + try { + return getCraftClass("CraftParticle").getMethod("toNMS", Particle.class).invoke(null, particle); + } + catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + public static String getMinecraftVersion() { String version = Bukkit.getVersion(); version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1); return version; } - /** - * This creates a DataWatcherItem usable with WrappedWatchableObject - * - * @param id - * @param value - * @return - */ - private static Object createDataWatcherItem(int id, Object value) { + public static WrappedDataWatcherObject createDataWatcherObject(int id, Object value) { if (value == null) return null; - value = convertInvalidItem(value); + value = convertInvalidMeta(value); Serializer serializer; @@ -880,7 +885,8 @@ public class ReflectionManager { getNmsClass("IBlockData").isInstance(opt.get()) ? getNmsClass("IBlockData") : opt.get().getClass() : UUID.class), true); } else { - serializer = Registry.get(value.getClass()); + serializer = Registry.get(getNmsClass("ParticleParam").isInstance(value) ? getNmsClass("ParticleParam") : + value.getClass()); } if (serializer == null) { @@ -894,12 +900,23 @@ public class ReflectionManager { "! Are you running " + "the latest " + "version of " + "ProtocolLib?"); } - WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer); + return new WrappedDataWatcherObject(id, serializer); + } + + /** + * This creates a DataWatcherItem usable with WrappedWatchableObject + * + * @param id + * @param value + * @return + */ + public static Object createDataWatcherItem(int id, Object value) { + WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value); Constructor construct = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class); try { - return construct.newInstance(watcherObject.getHandle(), value); + return construct.newInstance(watcherObject.getHandle(), convertInvalidMeta(value)); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); @@ -908,6 +925,28 @@ public class ReflectionManager { return null; } + public static int getEntityType(Object nmsEntity) { + try { + Class classType = getNmsClass("EntityTypes"); + + for (Method m : getNmsClass("Entity").getMethods()) { + if (m.getReturnType() != classType) { + continue; + } + + Object entityType = m.invoke(nmsEntity); + Object registry = classType.getField("REGISTRY").get(null); + + return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType); + } + } + catch (Exception ex) { + ex.printStackTrace(); + } + + return 0; + } + public static WrappedWatchableObject createWatchable(int index, Object obj) { Object watcherItem = createDataWatcherItem(index, obj); @@ -921,11 +960,41 @@ public class ReflectionManager { return id + (data << 12); } - public static ImmutablePair getFromCombinedId(int combinedId) { - int j = combinedId & 4095; - int k = combinedId >> 12 & 15; + public static int getCombinedIdByItemStack(ItemStack itemStack) { + try { + Object nmsItem = getNmsItem(itemStack); + Object item = getNmsMethod("ItemStack", "getItem").invoke(nmsItem); + Class blockClass = getNmsClass("Block"); - return new ImmutablePair<>(j, k); + Object nmsBlock = getNmsMethod(blockClass, "asBlock", getNmsClass("Item")).invoke(null, item); + + return (int) getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock); + } + catch (Exception ex) { + ex.printStackTrace(); + } + + return 0; + } + + public static ItemStack getItemStackByCombinedId(int id) { + try { + Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class); + Object iBlockData = idMethod.invoke(null, id); + Class iBlockClass = getNmsClass("IBlockData"); + + Method getBlock = getNmsMethod(iBlockClass, "getBlock"); + Object block = getBlock.invoke(iBlockData); + + Method getItem = getNmsMethod("Block", "t", iBlockClass); + + return getBukkitItem(getItem.invoke(block, iBlockData)); + } + catch (Exception ex) { + ex.printStackTrace(); + } + + return null; } public static Object getWorldServer(World w) { diff --git a/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java b/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java deleted file mode 100644 index 285b3db2..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards; - -import me.libraryaddict.disguise.utilities.DisguiseSound; - -import java.util.HashMap; - -/** - * Created by libraryaddict on 8/06/2017. - */ -public class BackwardMethods { - - public boolean isOrderedIndexes() { - return true; - } - - public void doReplaceSounds() { - } - - public void replace(String old, String newString) { - DisguiseSound.replace(old, newString); - } -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java b/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java deleted file mode 100644 index 8e9abb94..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java +++ /dev/null @@ -1,108 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards; - -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.ReflectionManager; -import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_10; -import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_11; -import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_9; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - -/** - * Created by libraryaddict on 8/06/2017. - */ -public class BackwardsSupport { - public static BackwardMethods getMethods() { - try { - String version = ReflectionManager.getMinecraftVersion(); - - Class methods = BackwardMethods.class; - - if (version.equals("1.9") || version.equals("1.9.1") || version.equals("1.9.2") || version - .equals("1.9.3") || version.equals("1.9.4")) { - methods = Version_1_9.class; - } else if (version.equals("1.10") || version.equals("1.10.1") || version.equals("1.10.2")) { - methods = Version_1_10.class; - } else if (version.equals("1.11") || version.equals("1.11.1") || version.equals("1.11.2")) { - methods = Version_1_11.class; - } - - if (methods != BackwardMethods.class) { - if (!LibsPremium.isPremium()) { - System.out.println("[LibsDisguises] You must purchase the plugin to use backwards compatibility!"); - methods = BackwardMethods.class; - } else { - System.out.println("[LibsDisguises] Enabled backwards support for " + version); - } - } - - return setupMetadata(methods); - } - catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - - private static void getIndexes(Class backwardsClass, BackwardMethods backwards, - HashMap newIndexes) throws IllegalAccessException { - for (Field field : backwardsClass.getDeclaredFields()) { - if (field.getType() != MetaIndex.class) - continue; - - field.setAccessible(true); - - if (newIndexes.containsKey(field.getName())) - continue; - - if (MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards))) { - newIndexes.put(field.getName(), MetaIndex.ENTITY_META); - continue; - } - - newIndexes.put(field.getName(), (MetaIndex) field.get(backwards)); - } - - backwardsClass = backwardsClass.getSuperclass(); - - if (backwardsClass.getSimpleName().contains("Version_")) - getIndexes(backwardsClass, backwards, newIndexes); - } - - private static BackwardMethods setupMetadata(Class backwardsClass) { - try { - BackwardMethods backwards = backwardsClass.newInstance(); - - HashMap newIndexes = new HashMap<>(); - - getIndexes(backwardsClass, backwards, newIndexes); - - MetaIndex.setValues(); - - HashSet indexes = new HashSet<>(newIndexes.values()); - indexes.remove(MetaIndex.ENTITY_META); // We do the hashmap stuff to prevent multiple versions - // registering the same meta index - - MetaIndex.addMetaIndexes(indexes.toArray(new MetaIndex[0])); - - if (backwards.isOrderedIndexes()) { - MetaIndex.eliminateBlankIndexes(); - MetaIndex.orderMetaIndexes(); - } - - backwards.doReplaceSounds(); - - return backwards; - } - catch (Exception ex) { - ex.printStackTrace(); - } - - return null; - } -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java deleted file mode 100644 index 6af7929b..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards.metadata; - -import com.google.common.base.Optional; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -/** - * Created by libraryaddict on 9/06/2017. - *

- * Supports 1.10.0 1.10.1 and 1.10.2 - */ -public class Version_1_10 extends Version_1_11 { - private MetaIndex ILLAGER_META; - private MetaIndex ILLAGER_SPELL_TICKS; - private MetaIndex HORSE_VARIANT = new MetaIndex<>(HorseWatcher.class, 1, 0); - private MetaIndex SHULKER_COLOR; - private MetaIndex> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, - Optional.of(new ItemStack(Material.STONE))); -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_11.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_11.java deleted file mode 100644 index 7eb88ce2..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_11.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards.metadata; - -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; -import me.libraryaddict.disguise.utilities.backwards.BackwardMethods; - -/** - * Created by libraryaddict on 8/06/2017. - * Supports 1.11.0 1.11.1 and 1.11.2 - */ -public class Version_1_11 extends BackwardMethods { - private MetaIndex ILLAGER_META; - private MetaIndex PARROT_VARIANT; - private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY; - private MetaIndex PLAYER_RIGHT_SHOULDER_ENTITY; -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_7.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_7.java deleted file mode 100644 index aa2953f9..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_7.java +++ /dev/null @@ -1,7 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards.metadata; - -/** - * Created by libraryaddict on 24/06/2017. - */ -public class Version_1_7 { -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_8.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_8.java deleted file mode 100644 index c85d8fcc..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_8.java +++ /dev/null @@ -1,7 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards.metadata; - -/** - * Created by libraryaddict on 24/06/2017. - */ -public class Version_1_8 { -} diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_9.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_9.java deleted file mode 100644 index 70d0fd54..00000000 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_9.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.libraryaddict.disguise.utilities.backwards.metadata; - -/** - * Created by libraryaddict on 24/06/2017. - *

- * Intended for 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4 - */ -public class Version_1_9 extends Version_1_10 { -} diff --git a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerClientInteract.java b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerClientInteract.java index 714edc4d..bf855823 100644 --- a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerClientInteract.java +++ b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerClientInteract.java @@ -1,19 +1,10 @@ package me.libraryaddict.disguise.utilities.packetlisteners; -import org.bukkit.Material; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.ExperienceOrb; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.StructureModifier; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; @@ -22,6 +13,10 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import org.bukkit.Material; +import org.bukkit.entity.*; +import org.bukkit.inventory.ItemStack; public class PacketListenerClientInteract extends PacketAdapter { public PacketListenerClientInteract(LibsDisguises plugin) { @@ -43,19 +38,20 @@ public class PacketListenerClientInteract extends PacketAdapter { Entity entity = entityModifer.read(0); - if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || entity == observer) { + if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || + entity == observer) { event.setCancelled(true); } for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()}) { - if (item == null || item.getType() != Material.INK_SACK) + if (item == null || item.getType() != Material.INK_SAC) continue; Disguise disguise = DisguiseAPI.getDisguise(observer, entity); - if (disguise == null || (disguise.getType() != DisguiseType.SHEEP && disguise - .getType() != DisguiseType.WOLF)) + if (disguise == null || + (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF)) continue; AnimalColor color = AnimalColor.getColor(item.getDurability()); diff --git a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerSounds.java b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerSounds.java index cff324e3..24abfbb3 100644 --- a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerSounds.java +++ b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerSounds.java @@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.entity.*; import java.lang.reflect.InvocationTargetException; @@ -153,14 +154,14 @@ public class PacketListenerSounds extends PacketAdapter { } else { if (sound.equals("step.grass")) { try { - int typeId = observer.getWorld().getBlockTypeIdAt((int) Math.floor(soundCords[0] / 8D), + Block block = observer.getWorld().getBlockAt((int) Math.floor(soundCords[0] / 8D), (int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D)); - Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId", int.class) - .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId); - if (block != null) { - Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); + Object nmsBlock = ReflectionManager.getCraftMethod("block.CraftBlock", "getNMSBlock") + .invoke(block); + + Object step = ReflectionManager.getNmsMethod("Block", "getStepSound").invoke(nmsBlock); mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step)); mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); diff --git a/src/org/bukkit/inventory/EquipmentSlot.java b/src/org/bukkit/inventory/EquipmentSlot.java deleted file mode 100644 index 44ca0374..00000000 --- a/src/org/bukkit/inventory/EquipmentSlot.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.bukkit.inventory; - -public enum EquipmentSlot { - HAND, - OFF_HAND, - FEET, - LEGS, - CHEST, - HEAD -} diff --git a/src/org/bukkit/inventory/MainHand.java b/src/org/bukkit/inventory/MainHand.java deleted file mode 100644 index 180fb33c..00000000 --- a/src/org/bukkit/inventory/MainHand.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.bukkit.inventory; - -public enum MainHand { - LEFT, - RIGHT -}