diff --git a/pom.xml b/pom.xml index c6283de7..14cf9d06 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,7 @@ 9.0 1.18.16 master-SNAPSHOT - [1.16,1.16.5] + [1.17,] 4.13.1 [1.16,] 1.12-SNAPSHOT diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 8533895c..cfa0f1dc 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -105,7 +105,9 @@ public class LibsDisguises extends JavaPlugin { } } catch (Throwable throwable) { try { - getUpdateChecker().doUpdate(); + if (isNumberedBuild()) { + getUpdateChecker().doUpdate(); + } } catch (Throwable t) { getLogger().severe("Failed to even do a forced update"); } @@ -256,7 +258,9 @@ public class LibsDisguises extends JavaPlugin { new MetricsInitalizer(); } catch (Throwable throwable) { try { - getUpdateChecker().doUpdate(); + if (isNumberedBuild()) { + getUpdateChecker().doUpdate(); + } } catch (Throwable t) { getLogger().severe("Failed to even do a forced update"); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index b4e49c6f..c75187b8 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -738,13 +738,13 @@ public abstract class Disguise { } if (getInternalArmorstandIds().length > 0) { - PacketContainer packet = new PacketContainer(Server.ENTITY_DESTROY); - packet.getIntegerArrays().write(0, getInternalArmorstandIds()); - try { - for (Player player : getEntity().getWorld().getPlayers()) { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + for (PacketContainer packet : DisguiseUtilities.getDestroyPackets(getInternalArmorstandIds())) { + for (Player player : getEntity().getWorld().getPlayers()) { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + } } + } catch (InvocationTargetException e) { e.printStackTrace(); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 271c2586..09cf6d21 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -7,6 +7,7 @@ import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.omg.CORBA.UNKNOWN; import java.util.Locale; @@ -17,6 +18,8 @@ public enum DisguiseType { ARROW(60, 0), + @NmsAddedIn(NmsVersion.v1_17) AXOLOTL, + BAT, @NmsAddedIn(NmsVersion.v1_15) BEE, @@ -83,6 +86,12 @@ public enum DisguiseType { GIANT, + @NmsAddedIn(NmsVersion.v1_17) GLOW_ITEM_FRAME, + + @NmsAddedIn(NmsVersion.v1_17) GLOW_SQUID, + + @NmsAddedIn(NmsVersion.v1_17) GOAT, + GUARDIAN, @NmsAddedIn(NmsVersion.v1_16) HOGLIN, @@ -105,6 +114,8 @@ public enum DisguiseType { MAGMA_CUBE, + @NmsAddedIn(NmsVersion.v1_17) MARKER, + MINECART(10), MINECART_CHEST(10, 1), @@ -285,8 +296,7 @@ public enum DisguiseType { } else { setEntityType(EntityType.valueOf(name())); } - } - catch (Exception ex) { + } catch (Exception ex) { } } @@ -341,13 +351,11 @@ public enum DisguiseType { } public boolean isMisc() { - return this == DisguiseType.MODDED_MISC || - (!isCustom() && getEntityType() != null && !getEntityType().isAlive()); + return this == DisguiseType.MODDED_MISC || (!isCustom() && getEntityType() != null && !getEntityType().isAlive()); } public boolean isMob() { - return this == DisguiseType.MODDED_LIVING || - (!isCustom() && getEntityType() != null && getEntityType().isAlive() && !isPlayer()); + return this == DisguiseType.MODDED_LIVING || (!isCustom() && getEntityType() != null && getEntityType().isAlive() && !isPlayer()); } public boolean isPlayer() { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index 7b992bd6..944b7955 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -33,32 +33,28 @@ public class MetaIndex { /** * The color of the Area Effect Cloud as RGB integer */ - public static MetaIndex AREA_EFFECT_CLOUD_COLOR = - new MetaIndex<>(AreaEffectCloudWatcher.class, 1, Color.BLACK.asRGB()); + public static MetaIndex AREA_EFFECT_CLOUD_COLOR = new MetaIndex<>(AreaEffectCloudWatcher.class, 1, Color.BLACK.asRGB()); /** * Ignore radius and show effect as single point, not area */ - public static MetaIndex AREA_EFFECT_IGNORE_RADIUS = - new MetaIndex<>(AreaEffectCloudWatcher.class, 2, false); + public static MetaIndex AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2, false); /** * The type of particle to display */ @NmsAddedIn(NmsVersion.v1_13) - public static MetaIndex AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, - NmsVersion.v1_13.isSupported() ? WrappedParticle.create(Particle.SPELL_MOB, null) : null); + public static MetaIndex AREA_EFFECT_PARTICLE = + new MetaIndex<>(AreaEffectCloudWatcher.class, 3, NmsVersion.v1_13.isSupported() ? WrappedParticle.create(Particle.SPELL_MOB, null) : null); @NmsRemovedIn(NmsVersion.v1_13) public static MetaIndex AREA_EFFECT_PARTICLE_OLD = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, 0); @NmsRemovedIn(NmsVersion.v1_13) - public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_1_OLD = - new MetaIndex<>(AreaEffectCloudWatcher.class, 4, 0); + public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_1_OLD = new MetaIndex<>(AreaEffectCloudWatcher.class, 4, 0); @NmsRemovedIn(NmsVersion.v1_13) - public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_2_OLD = - new MetaIndex<>(AreaEffectCloudWatcher.class, 5, 0); + public static MetaIndex AREA_EFFECT_PARTICLE_PARAM_2_OLD = new MetaIndex<>(AreaEffectCloudWatcher.class, 5, 0); /** * The size of the area @@ -68,26 +64,22 @@ public class MetaIndex { /** * Armorstand body eular vector */ - public static MetaIndex ARMORSTAND_BODY = - new MetaIndex<>(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0)); + public static MetaIndex ARMORSTAND_BODY = new MetaIndex<>(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0)); /** * Armorstand head eular vector */ - public static MetaIndex ARMORSTAND_HEAD = - new MetaIndex<>(ArmorStandWatcher.class, 1, new Vector3F(0, 0, 0)); + public static MetaIndex ARMORSTAND_HEAD = new MetaIndex<>(ArmorStandWatcher.class, 1, new Vector3F(0, 0, 0)); /** * Armorstand left arm eular vector */ - public static MetaIndex ARMORSTAND_LEFT_ARM = - new MetaIndex<>(ArmorStandWatcher.class, 3, new Vector3F(-10, 0, -10)); + public static MetaIndex ARMORSTAND_LEFT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 3, new Vector3F(-10, 0, -10)); /** * Armorstand left leg eular vector */ - public static MetaIndex ARMORSTAND_LEFT_LEG = - new MetaIndex<>(ArmorStandWatcher.class, 5, new Vector3F(-1, 0, -1)); + public static MetaIndex ARMORSTAND_LEFT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 5, new Vector3F(-1, 0, -1)); /** * Armorstand metadata @@ -97,14 +89,12 @@ public class MetaIndex { /** * Armorstand right arm eular vector */ - public static MetaIndex ARMORSTAND_RIGHT_ARM = - new MetaIndex<>(ArmorStandWatcher.class, 4, new Vector3F(-15, 0, 10)); + public static MetaIndex ARMORSTAND_RIGHT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 4, new Vector3F(-15, 0, 10)); /** * Armorstand right leg eular vector */ - public static MetaIndex ARMORSTAND_RIGHT_LEG = - new MetaIndex<>(ArmorStandWatcher.class, 6, new Vector3F(1, 0, 1)); + public static MetaIndex ARMORSTAND_RIGHT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 6, new Vector3F(1, 0, 1)); /** * If the arrow is a critical strike @@ -121,6 +111,15 @@ public class MetaIndex { @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex ARROW_PIERCE_LEVEL = new MetaIndex<>(ArrowWatcher.class, 2, (byte) 0); + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex AXOLOTL_VARIENT = new MetaIndex<>(AxolotlWatcher.class, 0, 0); + + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex AXOLOTL_PLAYING_DEAD = new MetaIndex<>(AxolotlWatcher.class, 1, false); + + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex AXOLOTL_FROM_BUCKET = new MetaIndex<>(AxolotlWatcher.class, 2, false); + /** * If the bat is hanging, false/true state */ @@ -188,8 +187,7 @@ public class MetaIndex { /** * No visible effect */ - public static MetaIndex DOLPHIN_TREASURE_POS = - new MetaIndex<>(DolphinWatcher.class, 0, BlockPosition.ORIGIN); + public static MetaIndex DOLPHIN_TREASURE_POS = new MetaIndex<>(DolphinWatcher.class, 0, BlockPosition.ORIGIN); /** * No visible effect */ @@ -203,11 +201,9 @@ public class MetaIndex { /** * The itemstack of the dropped item, must be set */ - public static MetaIndex DROPPED_ITEM = - new MetaIndex<>(DroppedItemWatcher.class, 0, new ItemStack(Material.AIR)); + public static MetaIndex DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, new ItemStack(Material.AIR)); - public static MetaIndex> ENDER_CRYSTAL_BEAM = - new MetaIndex<>(EnderCrystalWatcher.class, 0, Optional.empty()); + public static MetaIndex> ENDER_CRYSTAL_BEAM = new MetaIndex<>(EnderCrystalWatcher.class, 0, Optional.empty()); /** * If the ender crystal has a plate @@ -217,8 +213,7 @@ public class MetaIndex { public static MetaIndex ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10); @NmsAddedIn(NmsVersion.v1_14) - public static MetaIndex ENDER_SIGNAL_ITEM = - new MetaIndex<>(EnderSignalWatcher.class, 0, new ItemStack(Material.AIR)); + public static MetaIndex ENDER_SIGNAL_ITEM = new MetaIndex<>(EnderSignalWatcher.class, 0, new ItemStack(Material.AIR)); /** * If the enderman is screaming @@ -231,8 +226,7 @@ public class MetaIndex { /** * What block the enderman is holding */ - public static MetaIndex> ENDERMAN_ITEM = - new MetaIndex<>(EndermanWatcher.class, 0, Optional.empty()); + public static MetaIndex> ENDERMAN_ITEM = new MetaIndex<>(EndermanWatcher.class, 0, Optional.empty()); public static MetaIndex ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 300); @@ -240,8 +234,7 @@ public class MetaIndex { * The custom name of the entity, empty if not set */ @NmsAddedIn(NmsVersion.v1_13) - public static MetaIndex> ENTITY_CUSTOM_NAME = - new MetaIndex<>(FlagWatcher.class, 2, Optional.empty()); + public static MetaIndex> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, Optional.empty()); /** * The custom name of the entity, empty if not set */ @@ -275,15 +268,16 @@ public class MetaIndex { @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex ENTITY_POSE = new MetaIndex<>(FlagWatcher.class, 6, EntityPose.STANDING); - public static MetaIndex FALLING_BLOCK_POSITION = - new MetaIndex<>(FallingBlockWatcher.class, 0, BlockPosition.ORIGIN); + @NmsAddedIn(NmsVersion.v1_16) + public static MetaIndex ENTITY_TICKS_FROZEN = new MetaIndex<>(FlagWatcher.class, 7, 0); + + public static MetaIndex FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0, BlockPosition.ORIGIN); @NmsAddedIn(NmsVersion.v1_14) - public static MetaIndex FIREBALL_ITEM = - new MetaIndex<>(FireballWatcher.class, 0, new ItemStack(Material.AIR)); + public static MetaIndex FIREBALL_ITEM = new MetaIndex<>(FireballWatcher.class, 0, new ItemStack(Material.AIR)); - public static MetaIndex FIREWORK_ITEM = new MetaIndex<>(FireworkWatcher.class, 0, - new ItemStack(NmsVersion.v1_13.isSupported() ? Material.FIREWORK_ROCKET : Material.AIR)); + public static MetaIndex FIREWORK_ITEM = + new MetaIndex<>(FireworkWatcher.class, 0, new ItemStack(NmsVersion.v1_13.isSupported() ? Material.FIREWORK_ROCKET : Material.AIR)); public static MetaIndex FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false); @@ -291,8 +285,7 @@ public class MetaIndex { public static MetaIndex FIREWORK_ATTACHED_ENTITY_OLD = new MetaIndex<>(FireworkWatcher.class, 1, 0); @NmsAddedIn(NmsVersion.v1_14) - public static MetaIndex FIREWORK_ATTACHED_ENTITY = - new MetaIndex<>(FireworkWatcher.class, 1, OptionalInt.empty()); + public static MetaIndex FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1, OptionalInt.empty()); @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex FIREWORK_SHOT_AT_ANGLE = new MetaIndex<>(FireworkWatcher.class, 2, false); @@ -322,6 +315,12 @@ public class MetaIndex { */ public static MetaIndex GHAST_AGRESSIVE = new MetaIndex<>(GhastWatcher.class, 0, false); + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex GLOW_SQUID_DARK_TICKS_REMAINING = new MetaIndex<>(GlowSquidWatcher.class, 0, 0); + + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex GOAT_SCREAMING = new MetaIndex<>(GoatWatcher.class, 0, false); + /** * Switch between the guardian spikes enabled/disabled */ @@ -338,8 +337,7 @@ public class MetaIndex { /** * If horse has chest, set for donkey */ - public static MetaIndex HORSE_CHESTED_CARRYING_CHEST = - new MetaIndex<>(ChestedHorseWatcher.class, 0, false); + public static MetaIndex HORSE_CHESTED_CARRYING_CHEST = new MetaIndex<>(ChestedHorseWatcher.class, 0, false); @NmsRemovedIn(NmsVersion.v1_14) public static MetaIndex HORSE_ARMOR = new MetaIndex<>(HorseWatcher.class, 1, 0); @@ -356,8 +354,7 @@ public class MetaIndex { /** * Owner of the horse, no visual effect */ - public static MetaIndex> HORSE_OWNER = - new MetaIndex<>(AbstractHorseWatcher.class, 1, Optional.empty()); + public static MetaIndex> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1, Optional.empty()); @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex ILLAGER_SPELL = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0); @@ -375,8 +372,7 @@ public class MetaIndex { /** * The itemstack inside the itemframe */ - public static MetaIndex ITEMFRAME_ITEM = - new MetaIndex<>(ItemFrameWatcher.class, 0, new ItemStack(Material.AIR)); + public static MetaIndex ITEMFRAME_ITEM = new MetaIndex<>(ItemFrameWatcher.class, 0, new ItemStack(Material.AIR)); /** * The itemstack rotation inside the itemframe @@ -415,8 +411,7 @@ public class MetaIndex { public static MetaIndex LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0); @NmsAddedIn(NmsVersion.v1_14) - public static MetaIndex> LIVING_BED_POSITION = - new MetaIndex<>(LivingWatcher.class, 6, Optional.empty()); + public static MetaIndex> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6, Optional.empty()); /** * If there is no carpet, -1. Otherwise it's a color enum value @@ -525,11 +520,9 @@ 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.ofWrapper(NbtType.TAG_COMPOUND, "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.ofWrapper(NbtType.TAG_COMPOUND, "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); @@ -542,8 +535,8 @@ 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.empty()); + @NmsRemovedIn(NmsVersion.v1_17) + public static MetaIndex> SHULKER_ATTACHED = new MetaIndex<>(ShulkerWatcher.class, 1, Optional.empty()); public static MetaIndex SHULKER_COLOR = new MetaIndex<>(ShulkerWatcher.class, 3, (byte) 16); @@ -552,7 +545,10 @@ public class MetaIndex { public static MetaIndex SHULKER_PEEKING = new MetaIndex<>(ShulkerWatcher.class, 2, (byte) 0); @NmsRemovedIn(NmsVersion.v1_14) - public static MetaIndex SKELETON_SWING_ARMS = new MetaIndex<>(SkeletonWatcher.class, 0, false); + public static MetaIndex SKELETON_SWING_ARMS = new MetaIndex<>(AbstractSkeletonWatcher.class, 0, false); + + @NmsAddedIn(NmsVersion.v1_17) + public static MetaIndex SKELETON_CONVERTING_STRAY = new MetaIndex<>(SkeletonWatcher.class, 0, false); public static MetaIndex SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 1); @@ -569,17 +565,14 @@ public class MetaIndex { public static MetaIndex SPIDER_CLIMB = new MetaIndex<>(SpiderWatcher.class, 0, (byte) 0); - public static MetaIndex SPLASH_POTION_ITEM = - new MetaIndex<>(SplashPotionWatcher.class, 0, new ItemStack(Material.SPLASH_POTION)); + public static MetaIndex SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, new ItemStack(Material.SPLASH_POTION)); public static MetaIndex TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0); - public static MetaIndex> TAMEABLE_OWNER = - new MetaIndex<>(TameableWatcher.class, 1, Optional.empty()); + public static MetaIndex> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, Optional.empty()); @NmsAddedIn(NmsVersion.v1_14) - public static MetaIndex THROWABLE_ITEM = - new MetaIndex<>(ThrowableWatcher.class, 0, new ItemStack(Material.AIR)); + public static MetaIndex THROWABLE_ITEM = new MetaIndex<>(ThrowableWatcher.class, 0, new ItemStack(Material.AIR)); public static MetaIndex TIPPED_ARROW_COLOR = new MetaIndex<>(TippedArrowWatcher.class, 0, -1); @@ -592,15 +585,13 @@ public class MetaIndex { public static MetaIndex TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0); - public static MetaIndex TURTLE_HOME_POSITION = - new MetaIndex<>(TurtleWatcher.class, 0, BlockPosition.ORIGIN); + public static MetaIndex TURTLE_HOME_POSITION = new MetaIndex<>(TurtleWatcher.class, 0, BlockPosition.ORIGIN); public static MetaIndex TURTLE_HAS_EGG = new MetaIndex<>(TurtleWatcher.class, 1, false); public static MetaIndex TURTLE_UNKNOWN_3 = new MetaIndex<>(TurtleWatcher.class, 2, false); - public static MetaIndex TURTLE_TRAVEL_POSITION = - new MetaIndex<>(TurtleWatcher.class, 3, BlockPosition.ORIGIN); + public static MetaIndex TURTLE_TRAVEL_POSITION = new MetaIndex<>(TurtleWatcher.class, 3, BlockPosition.ORIGIN); public static MetaIndex TURTLE_UNKNOWN_1 = new MetaIndex<>(TurtleWatcher.class, 4, false); @@ -616,8 +607,7 @@ public class MetaIndex { @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex VILLAGER_DATA = new MetaIndex<>(VillagerWatcher.class, 0, - NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : - null); + NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : null); public static MetaIndex WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false); @@ -655,13 +645,11 @@ public class MetaIndex { public static MetaIndex ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0); @NmsRemovedIn(NmsVersion.v1_14) - public static MetaIndex ZOMBIE_VILLAGER_PROFESSION_OLD = - new MetaIndex<>(ZombieVillagerWatcher.class, 1, 0); + public static MetaIndex ZOMBIE_VILLAGER_PROFESSION_OLD = new MetaIndex<>(ZombieVillagerWatcher.class, 1, 0); @NmsAddedIn(NmsVersion.v1_14) public static MetaIndex ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, - NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : - null); + NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : null); /** * Shown for villager conversion @@ -711,8 +699,7 @@ public class MetaIndex { HashMap maxValues = new HashMap<>(); for (MetaIndex type : values()) { - if (maxValues.containsKey(type.getFlagWatcher()) && - maxValues.get(type.getFlagWatcher()) > type.getIndex()) { + if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex()) { continue; } @@ -735,10 +722,8 @@ public class MetaIndex { } if (found != null) { - DisguiseUtilities.getLogger().severe(entry.getKey().getSimpleName() + - " has multiple FlagType's registered for the index " + i + " (" + - type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() + - ")"); + DisguiseUtilities.getLogger().severe(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " + i + " (" + + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() + ")"); continue loop; } @@ -749,15 +734,14 @@ public class MetaIndex { continue; } - DisguiseUtilities.getLogger() - .severe(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i); + DisguiseUtilities.getLogger().severe(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i); } } } public String toString() { - return LibsMsg.META_INFO.get(getName(this), getFlagWatcher().getSimpleName(), getIndex(), - getDefault().getClass().getSimpleName(), DisguiseUtilities.getGson().toJson(getDefault())); + return LibsMsg.META_INFO.get(getName(this), getFlagWatcher().getSimpleName(), getIndex(), getDefault().getClass().getSimpleName(), + DisguiseUtilities.getGson().toJson(getDefault())); } /** @@ -923,15 +907,12 @@ 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; } - DisguiseUtilities.getLogger() - .severe("MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " + - metaIndex.getIndex() + " has already registered this! (" + metaIndex.getDefault() + - "," + index.getDefault() + ")"); + DisguiseUtilities.getLogger().severe("MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " + metaIndex.getIndex() + + " has already registered this! (" + metaIndex.getDefault() + "," + index.getDefault() + ")"); } values()[i] = metaIndexes[a]; diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java new file mode 100644 index 00000000..789a076a --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractSkeletonWatcher.java @@ -0,0 +1,29 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; + +/** + * @author Navid + */ +public abstract class AbstractSkeletonWatcher extends InsentientWatcher { + public AbstractSkeletonWatcher(Disguise disguise) { + super(disguise); + } + + @Deprecated + @NmsRemovedIn(NmsVersion.v1_14) + public boolean isSwingArms() { + return getData(MetaIndex.SKELETON_SWING_ARMS); + } + + @Deprecated + @NmsRemovedIn(NmsVersion.v1_14) + public void setSwingArms(boolean swingingArms) { + setData(MetaIndex.SKELETON_SWING_ARMS, swingingArms); + sendData(MetaIndex.SKELETON_SWING_ARMS); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AxolotlWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AxolotlWatcher.java new file mode 100644 index 00000000..cf965cde --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AxolotlWatcher.java @@ -0,0 +1,32 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import org.bukkit.entity.Axolotl; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class AxolotlWatcher extends AgeableWatcher { + public AxolotlWatcher(Disguise disguise) { + super(disguise); + } + + public boolean isPlayingDead() { + return getData(MetaIndex.AXOLOTL_PLAYING_DEAD); + } + + public void setPlayingDead(boolean playingDead) { + setData(MetaIndex.AXOLOTL_PLAYING_DEAD, playingDead); + sendData(MetaIndex.AXOLOTL_PLAYING_DEAD); + } + + public Axolotl.Variant getVarient() { + return Axolotl.Variant.values()[getData(MetaIndex.AXOLOTL_VARIENT)]; + } + + public void setVarient(Axolotl.Variant varient) { + setData(MetaIndex.AXOLOTL_VARIENT, varient.ordinal()); + sendData(MetaIndex.AXOLOTL_VARIENT); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GlowSquidWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GlowSquidWatcher.java new file mode 100644 index 00000000..e51a6063 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GlowSquidWatcher.java @@ -0,0 +1,22 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class GlowSquidWatcher extends SquidWatcher { + public GlowSquidWatcher(Disguise disguise) { + super(disguise); + } + + public int getDarkTicksRemaining() { + return getData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING); + } + + public void setDarkTicksRemaining(int ticks) { + setData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING, ticks); + sendData(MetaIndex.GLOW_SQUID_DARK_TICKS_REMAINING); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GoatWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GoatWatcher.java new file mode 100644 index 00000000..35844440 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GoatWatcher.java @@ -0,0 +1,22 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class GoatWatcher extends AgeableWatcher { + public GoatWatcher(Disguise disguise) { + super(disguise); + } + + public boolean isScreaming() { + return getData(MetaIndex.GOAT_SCREAMING); + } + + public void setScreaming(boolean screaming) { + setData(MetaIndex.GOAT_SCREAMING, screaming); + sendData(MetaIndex.GOAT_SCREAMING); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index a4affdb6..06cf074e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -1,28 +1,26 @@ -package me.libraryaddict.disguise.disguisetypes.watchers; - -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; -import me.libraryaddict.disguise.utilities.reflection.NmsVersion; - -/** - * @author Navid - */ -public class SkeletonWatcher extends InsentientWatcher { - public SkeletonWatcher(Disguise disguise) { - super(disguise); - } - - @Deprecated - @NmsRemovedIn(NmsVersion.v1_14) - public boolean isSwingArms() { - return getData(MetaIndex.SKELETON_SWING_ARMS); - } - - @Deprecated - @NmsRemovedIn(NmsVersion.v1_14) - public void setSwingArms(boolean swingingArms) { - setData(MetaIndex.SKELETON_SWING_ARMS, swingingArms); - sendData(MetaIndex.SKELETON_SWING_ARMS); - } -} +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class SkeletonWatcher extends AbstractSkeletonWatcher { + public SkeletonWatcher(Disguise disguise) { + super(disguise); + } + + @NmsAddedIn(NmsVersion.v1_17) + public boolean isConvertingStray() { + return getData(MetaIndex.SKELETON_CONVERTING_STRAY); + } + + @NmsAddedIn(NmsVersion.v1_17) + public void setConvertingStray(boolean converting) { + setData(MetaIndex.SKELETON_CONVERTING_STRAY, converting); + sendData(MetaIndex.SKELETON_CONVERTING_STRAY); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/StrayWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/StrayWatcher.java new file mode 100644 index 00000000..44fd5c41 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/StrayWatcher.java @@ -0,0 +1,12 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class StrayWatcher extends AbstractSkeletonWatcher { + public StrayWatcher(Disguise disguise) { + super(disguise); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkeletonWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkeletonWatcher.java new file mode 100644 index 00000000..bdba3845 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkeletonWatcher.java @@ -0,0 +1,12 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; + +/** + * Created by libraryaddict on 15/06/2021. + */ +public class WitherSkeletonWatcher extends AbstractSkeletonWatcher { + public WitherSkeletonWatcher(Disguise disguise) { + super(disguise); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c2e98eff..051b850c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -41,6 +41,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.server.level.EntityTrackerEntry; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.RandomUtils; import org.apache.logging.log4j.util.Strings; @@ -349,11 +350,8 @@ public class DisguiseUtilities { } public static void removeInvisibleSlime(Player player) { - PacketContainer container = new PacketContainer(Server.ENTITY_DESTROY); - container.getIntegerArrays().write(0, new int[]{DisguiseAPI.getEntityAttachmentId()}); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, container, false); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, getDestroyPacket(DisguiseAPI.getEntityAttachmentId()), false); } catch (InvocationTargetException e) { e.printStackTrace(); } @@ -990,9 +988,7 @@ public class DisguiseUtilities { trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException - PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); - - destroyPacket.getIntegerArrays().write(0, new int[]{disguise.getEntity().getEntityId()}); + PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); for (Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); @@ -1057,6 +1053,10 @@ public class DisguiseUtilities { } public static PacketContainer getDestroyPacket(int... ids) { + if (NmsVersion.v1_17.isSupported() && ids.length != 1) { + throw new IllegalStateException("Should use getDestroyPackets for ints of len " + ids.length); + } + PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); destroyPacket.getIntegerArrays().write(0, ids); @@ -1064,6 +1064,22 @@ public class DisguiseUtilities { return destroyPacket; } + public static PacketContainer[] getDestroyPackets(int... ids) { + if (!NmsVersion.v1_17.isSupported()) { + return new PacketContainer[]{getDestroyPacket(ids)}; + } + + PacketContainer[] packets = new PacketContainer[ids.length]; + + for (int i = 0; i < packets.length; i++) { + packets[i] = new PacketContainer(Server.ENTITY_DESTROY); + + packets[i].getIntegers().write(0, ids[i]); + } + + return packets; + } + public static TargetedDisguise getDisguise(Player observer, Entity entity) { int entityId = entity.getEntityId(); @@ -1768,12 +1784,12 @@ public class DisguiseUtilities { ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId(); // Send a packet to destroy the fake entity - PacketContainer packet = getDestroyPacket(ids); - - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); - } catch (Exception ex) { - ex.printStackTrace(); + for (PacketContainer packet : getDestroyPackets(ids)) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + } catch (Exception ex) { + ex.printStackTrace(); + } } // player.spigot().setCollidesWithEntities(true); @@ -1806,10 +1822,10 @@ public class DisguiseUtilities { if (!runningPaper) { Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); - ((Set) trackedPlayersObj).remove(ReflectionManager.getNmsEntity(player)); + ((Set) trackedPlayersObj).remove(ReflectionManager.getEntityTrackerInstance(player)); } else { ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get(entityTrackerEntry)) - .remove(ReflectionManager.getNmsEntity(player)); + .remove(ReflectionManager.getEntityTrackerInstance(player)); } } } catch (Exception ex) { @@ -2345,10 +2361,10 @@ public class DisguiseUtilities { // Add himself to his own entity tracker Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); - ((Set) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player)); + ((Set) trackedPlayersObj).add(ReflectionManager.getEntityTrackerInstance(player)); } else { Field field = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap"); - Object nmsEntity = ReflectionManager.getNmsEntity(player); + Object nmsEntity = ReflectionManager.getEntityTrackerInstance(player); Map map = ((Map) field.get(entityTrackerEntry)); map.put(nmsEntity, true); } @@ -2365,7 +2381,8 @@ public class DisguiseUtilities { boolean isMoving = false; try { - Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving"); + Field field = ReflectionManager.getNmsClass("EntityTrackerEntry") + .getDeclaredField(NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving"); field.setAccessible(true); isMoving = field.getBoolean(entityTrackerEntry); } catch (Exception ex) { @@ -2978,7 +2995,9 @@ public class DisguiseUtilities { } if (destroyIds.length > 0) { - packets.add(getDestroyPacket(destroyIds)); + for (PacketContainer packet : getDestroyPackets(destroyIds)) { + packets.add(packet); + } } return packets; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java index 498d6516..e175e4c2 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java @@ -1,13 +1,18 @@ package me.libraryaddict.disguise.utilities.packets.packetlisteners; import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; /** @@ -20,36 +25,65 @@ public class PacketListenerEntityDestroy extends PacketAdapter { @Override public void onPacketSending(PacketEvent event) { + if (event.isCancelled()) { + return; + } + + if (!NmsVersion.v1_17.isSupported()) { + onPre17Packet(event); + return; + } + + int[] toAdd = getToRemove(event.getPlayer(), event.getPacket().getIntegers().read(0)); + + if (toAdd == null) { + return; + } + + try { + for (PacketContainer container : DisguiseUtilities.getDestroyPackets(toAdd)) { + ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), container); + } + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + private int[] getToRemove(Player player, int entityId) { + if (entityId == DisguiseAPI.getSelfDisguiseId()) { + return null; + } + + Disguise disguise = DisguiseUtilities.getDisguise(player, entityId); + + if (disguise == null) { + return null; + } + + int len = disguise.getMultiNameLength(); + + if (len == 0) { + return null; + } + + return disguise.getArmorstandIds(); + } + + public void onPre17Packet(PacketEvent event) { int[] entityIds = event.getPacket().getIntegerArrays().read(0); int[] newEntityIds = entityIds; for (int entityId : entityIds) { - if (entityId == DisguiseAPI.getSelfDisguiseId()) { - return; - } + int[] toAdd = getToRemove(event.getPlayer(), entityId); - Disguise disguise = DisguiseUtilities.getDisguise(event.getPlayer(), entityId); - - if (disguise == null) { + if (toAdd == null) { continue; } - int len = disguise.getMultiNameLength(); + newEntityIds = Arrays.copyOf(entityIds, entityIds.length + toAdd.length); - if (len == 0) { - continue; - } - - // If this packet has already been processed - if (entityIds.length == newEntityIds.length && - Arrays.stream(entityIds).anyMatch(id -> id == disguise.getArmorstandIds()[0])) { - return; - } - - newEntityIds = Arrays.copyOf(entityIds, entityIds.length + len); - - for (int a = 0; a < len; a++) { - newEntityIds[newEntityIds.length - (a + 1)] = disguise.getArmorstandIds()[a]; + for (int a = 0; a < toAdd.length; a++) { + newEntityIds[newEntityIds.length - (a + 1)] = toAdd[a]; } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java index ef960c9f..50377b8d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java @@ -8,7 +8,8 @@ public enum NmsVersion { v1_13, v1_14, v1_15, - v1_16; + v1_16, + v1_17; /** * If this nms version isn't newer than the running version diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 1bb7be5b..55b77e4c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -112,20 +112,35 @@ public class ReflectionManager { private static Method getObjectives; private static Method getPlayerScoreObjective; private static Method setScore; + private static HashMap classLocations = new HashMap<>(); + private static Field playerConnection; public static void init() { try { boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class); setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); - entityCountField = getNmsField("Entity", "entityCount"); + + if (NmsVersion.v1_17.isSupported()) { + for (Field f : getNmsClass("Entity").getDeclaredFields()) { + if (f.getType() != AtomicInteger.class) { + continue; + } + + f.setAccessible(true); + entityCountField = f; + break; + } + } else { + entityCountField = getNmsField("Entity", "entityCount"); + } mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE); mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE); boundingBoxMethod = getNmsMethod("Entity", "getBoundingBox"); bukkitEntityMethod = getNmsMethod("Entity", "getBukkitEntity"); - Class craftItemClass = getCraftClass("inventory.CraftItemStack"); + Class craftItemClass = getCraftClass("CraftItemStack"); itemAsCraftCopyMethod = getCraftMethod(craftItemClass, "asCraftCopy", ItemStack.class); itemAsNmsCopyMethod = getCraftMethod(craftItemClass, "asNMSCopy", ItemStack.class); itemAsBukkitMethod = getCraftMethod(craftItemClass, "asBukkitCopy", getNmsClass("ItemStack")); @@ -136,11 +151,19 @@ public class ReflectionManager { enumDirectionMethod = getNmsMethod("EnumDirection", "fromType2", int.class); enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants(); chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class); - packetPlayOutConstructor = - getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class, - getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")); + + if (NmsVersion.v1_17.isSupported()) { + packetPlayOutConstructor = + getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, getNmsClass("EnumGamemode"), + getNmsClass("IChatBaseComponent")); + } else { + packetPlayOutConstructor = + getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class, + getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")); + } + enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants(); - getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle"); + getNmsEntityMethod = getCraftMethod("CraftEntity", "getHandle"); enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants(); Class craftSound = getCraftClass("CraftSound"); @@ -159,23 +182,30 @@ public class ReflectionManager { getBlockData = getNmsMethod(getNmsClass("Block"), "getBlockData"); if (NmsVersion.v1_13.isSupported()) { - craftBlockDataGetState = getCraftMethod("block.data.CraftBlockData", "getState"); - magicGetBlock = getCraftMethod("util.CraftMagicNumbers", "getBlock", Material.class); - magicGetMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Block")); + craftBlockDataGetState = getCraftMethod("CraftBlockData", "getState"); + magicGetBlock = getCraftMethod("CraftMagicNumbers", "getBlock", Material.class); + magicGetMaterial = getCraftMethod("CraftMagicNumbers", "getMaterial", getNmsClass("Block")); entityTypesAMethod = getNmsMethod("EntityTypes", "a", String.class); if (NmsVersion.v1_14.isSupported()) { entityPoseClass = getNmsClass("EntityPose"); registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey")); villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class); - villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); - villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); + + if (NmsVersion.v1_17.isSupported()) { + villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null); + villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null); + playerConnection = getNmsField("EntityPlayer", "b"); + } else { + villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); + villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); + } } else { registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey")); } } - bukkitKeyToNms = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); + bukkitKeyToNms = getCraftMethod("CraftNamespacedKey", "toMinecraft", NamespacedKey.class); dataWatcherItemConstructor = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class); vec3DConstructor = getNmsConstructor("Vec3D", double.class, double.class, double.class); getOldItemAsBlock = getNmsMethod(getNmsClass("Block"), "asBlock", getNmsClass("Item")); @@ -183,14 +213,44 @@ public class ReflectionManager { getBlockDataAsId = getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData")); getNmsWorld = getCraftMethod("CraftWorld", "getHandle"); - deserializedItemMeta = getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class); + deserializedItemMeta = getCraftMethod(getCraftClass("CraftMetaItem$SerializableMeta"), "deserialize", Map.class); + + if (NmsVersion.v1_17.isSupported()) { + boolean nextInt = false; + + for (Field f : getNmsClass("Entity").getDeclaredFields()) { + if (f.getType().getSimpleName().equals("Tag")) { + nextInt = true; + } else if (f.getType() == int.class && nextInt) { + noDamageTicks = f; + break; + } + } + } else { + noDamageTicks = getNmsField("Entity", "noDamageTicks"); + } - noDamageTicks = getNmsField("Entity", "noDamageTicks"); isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource")); - genericDamage = getNmsField("DamageSource", "GENERIC").get(null); - boardField = getCraftClass("scoreboard.CraftScoreboard").getDeclaredField("board"); + + for (Field f : getNmsClass("DamageSource").getFields()) { + Object obj = f.get(null); + + if (obj == null) { + continue; + } + + if (!obj.toString().contains("(generic)")) { + continue; + } + + genericDamage = obj; + break; + } + + boardField = getCraftClass("CraftScoreboard").getDeclaredField("board"); boardField.setAccessible(true); - scoreboardCrtieriaHealth = getNmsField("IScoreboardCriteria", NmsVersion.v1_13.isSupported() ? "HEALTH" : "g").get(null); + scoreboardCrtieriaHealth = + getNmsField("IScoreboardCriteria", NmsVersion.v1_17.isSupported() ? NmsVersion.v1_13.isSupported() ? "f" : "HEALTH" : "g").get(null); setScore = getNmsMethod("ScoreboardScore", "setScore", int.class); if (!NmsVersion.v1_13.isSupported()) { @@ -241,15 +301,15 @@ public class ReflectionManager { ex.printStackTrace(); } - pingField = getNmsField("EntityPlayer", "ping"); + pingField = getNmsField("EntityPlayer", NmsVersion.v1_17.isSupported() ? "e" : "ping"); if (NmsVersion.v1_14.isSupported()) { - chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap"); - trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities"); - entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry"); + chunkMapField = getNmsField("ChunkProviderServer", NmsVersion.v1_17.isSupported() ? "a" : "playerChunkMap"); + trackedEntitiesField = getNmsField("PlayerChunkMap", NmsVersion.v1_17.isSupported() ? "G" : "trackedEntities"); + entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", NmsVersion.v1_17.isSupported() ? "b" : "trackerEntry"); if (NmsVersion.v1_16.isSupported()) { - chunkProviderField = getNmsField("WorldServer", "chunkProvider"); + chunkProviderField = getNmsField("WorldServer", NmsVersion.v1_17.isSupported() ? "C" : "chunkProvider"); } else { chunkProviderField = getNmsField("World", "chunkProvider"); } @@ -384,23 +444,52 @@ public class ReflectionManager { return -1; } + public static Object getEntityTrackerInstance(Player player) { + try { + if (NmsVersion.v1_17.isSupported()) { + return playerConnection.get(getNmsEntity(player)); + } + + return getNmsEntity(player); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + + return null; + } + public static Object createEntityInstance(DisguiseType disguiseType, String entityName) { try { - Class entityClass = getNmsClass("Entity" + entityName); + Class entityClass; + + if (NmsVersion.v1_17.isSupported()) { + entityClass = getNmsClassIgnoreErrors("Entity" + entityName); + + if (entityClass == null) { + entityClass = getNmsClass(entityName); + } + } else { + entityClass = getNmsClass("Entity" + entityName); + } + Object entityObject; Object world = getWorldServer(Bukkit.getWorlds().get(0)); if (entityName.equals("Player")) { Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); - - Object playerinteractmanager = - getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) - .newInstance(world); - WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); - entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(), - playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); + if (NmsVersion.v1_17.isSupported()) { + entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType()) + .newInstance(minecraftServer, world, gameProfile.getHandle()); + } else { + Object playerinteractmanager = + getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) + .newInstance(world); + + entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(), + playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); + } } else if (entityName.equals("EnderPearl")) { entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); @@ -564,7 +653,7 @@ public class ReflectionManager { public static Class getCraftClass(String className) { try { - return Class.forName("org.bukkit.craftbukkit." + getBukkitVersion() + "." + className); + return Class.forName(getLocation("org.bukkit.craftbukkit", className)); } catch (Exception e) { e.printStackTrace(); } @@ -679,6 +768,10 @@ public class ReflectionManager { try { Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName()); + if (NmsVersion.v1_17.isSupported()) { + return packetPlayOutConstructor.newInstance(gameProfile.getHandle(), 0, enumGamemode[1], playerListName); + } + return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName); } catch (Exception ex) { ex.printStackTrace(); @@ -748,9 +841,33 @@ public class ReflectionManager { return new UUID(firstLong, secondLong); } + private static String getLocation(String pack, String className) { + String toReturn = classLocations.get(className); + + if (toReturn != null) { + return toReturn; + } + + try { + ArrayList classes = ClassGetter.getEntriesForPackage(pack); + + String realLocation = classes.stream().filter(s -> s.endsWith("/" + className + ".class")).findAny().get().replace("/", ".").replace(".class", ""); + + classLocations.put(className, realLocation); + + return realLocation; + } catch (Throwable throwable) { + // System.err.println(pack + " - " + className); + // throwable.printStackTrace(); + classLocations.put(className, className); + } + + return className; + } + public static Class getNmsClass(String className) { try { - return Class.forName("net.minecraft.server." + getBukkitVersion() + "." + className); + return Class.forName(getLocation("net.minecraft", className)); } catch (Exception e) { e.printStackTrace(); } @@ -760,7 +877,7 @@ public class ReflectionManager { public static Class getNmsClassIgnoreErrors(String className) { try { - return Class.forName("net.minecraft.server." + getBukkitVersion() + "." + className); + return Class.forName(getLocation("net.minecraft", className)); } catch (Exception ignored) { } @@ -1212,7 +1329,7 @@ public class ReflectionManager { Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name); - Object registry = getNmsField("IRegistry", "ITEM").get(null); + Object registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null); Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass()); Object item = getMethod.invoke(registry, mcKey); @@ -1221,7 +1338,7 @@ public class ReflectionManager { return null; } - Method getMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Item")); + Method getMaterial = getCraftMethod("CraftMagicNumbers", "getMaterial", getNmsClass("Item")); return (Material) getMaterial.invoke(null, item); } catch (Exception ex) { @@ -1247,7 +1364,7 @@ public class ReflectionManager { Object registry; if (NmsVersion.v1_13.isSupported()) { - registry = getNmsField("IRegistry", "ITEM").get(null); + registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null); } else { registry = getNmsField("Item", "REGISTRY").get(null); } @@ -1415,7 +1532,7 @@ public class ReflectionManager { Class typesClass = getNmsClass("IRegistry"); - Object registry = typesClass.getField("ENTITY_TYPE").get(null); + Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); Constructor c = getNmsClass("EntityTypes").getConstructors()[0]; @@ -1452,9 +1569,9 @@ public class ReflectionManager { try { Class typesClass = getNmsClass("IRegistry"); - Object registry = typesClass.getField("ENTITY_TYPE").get(null); + Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); - return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes); + return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes); } catch (Exception ex) { ex.printStackTrace(); } @@ -1469,9 +1586,9 @@ public class ReflectionManager { Class typesClass = getNmsClass("IRegistry"); - Object registry = typesClass.getField("ENTITY_TYPE").get(null); + Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); - return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes); + return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes); } return entityType.getTypeId(); @@ -1486,10 +1603,10 @@ public class ReflectionManager { try { Class typesClass = getNmsClass("IRegistry"); - Object registry = typesClass.getField("ENTITY_TYPE").get(null); + Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString()); - return registry.getClass().getMethod("a", mcKey.getClass()).invoke(registry, mcKey); + return registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", mcKey.getClass()).invoke(registry, mcKey); } catch (Exception ex) { ex.printStackTrace(); } @@ -1552,7 +1669,7 @@ public class ReflectionManager { Object iBlockData = idMethod.invoke(null, id); Class iBlockClass = getNmsClass("IBlockData"); - return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass).invoke(null, iBlockData); + return (BlockData) getCraftMethod("CraftBlockData", "fromData", iBlockClass).invoke(null, iBlockData); } catch (Exception ex) { ex.printStackTrace(); } @@ -1609,6 +1726,12 @@ public class ReflectionManager { try { switch (disguiseType) { + case MARKER: + watcherClass = FlagWatcher.class; + break; + case GLOW_ITEM_FRAME: + watcherClass = ItemFrameWatcher.class; + break; case ARROW: watcherClass = TippedArrowWatcher.class; break; @@ -1648,10 +1771,6 @@ public class ReflectionManager { case ELDER_GUARDIAN: watcherClass = GuardianWatcher.class; break; - case WITHER_SKELETON: - case STRAY: - watcherClass = SkeletonWatcher.class; - break; case ILLUSIONER: case EVOKER: watcherClass = IllagerWizardWatcher.class; @@ -1764,6 +1883,21 @@ public class ReflectionManager { if (nmsEntityName == null) { switch (disguiseType) { + case AXOLOTL: + nmsEntityName = "Axolotl"; + break; + case GOAT: + nmsEntityName = "Goat"; + break; + case GLOW_ITEM_FRAME: + nmsEntityName = "GlowItemFrame"; + break; + case GLOW_SQUID: + nmsEntityName = "GlowSquid"; + break; + case MARKER: + nmsEntityName = "Marker"; + break; case DONKEY: nmsEntityName = "HorseDonkey"; break;