Change 1.17 to use the nms stuff too

This commit is contained in:
libraryaddict 2021-12-11 19:25:17 +13:00
parent 40ec806b28
commit 42cd210fc7
7 changed files with 682 additions and 228 deletions

View File

@ -185,6 +185,14 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>v1_17_R1</artifactId>
<version>${project.version}</version>
<classifier>remapped-spigot</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@ -111,8 +111,7 @@ public class ReflectionManager {
private static Field playerConnection;
private static Method incrementedInventoryStateId;
private static Field playerInventoryContainer;
private static ReflectionManagerAbstract v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18);
private static ReflectionManagerAbstract nmsReflection;
public static void init() {
try {
@ -121,37 +120,17 @@ public class ReflectionManager {
entityPoseClass = getNmsClass("EntityPose");
}
if (NmsVersion.v1_18.isSupported()) {
v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18);
nmsReflection = getReflectionManager(getVersion());
if (nmsReflection != null) {
return;
}
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class);
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
if (NmsVersion.v1_17.isSupported()) {
for (Field f : getNmsClass("Entity").getDeclaredFields()) {
if (f.getType() != AtomicInteger.class) {
continue;
}
f.setAccessible(true);
entityCountField = f;
break;
}
for (Field f : getNmsClass("EntityHuman").getDeclaredFields()) {
if (!f.getType().getSimpleName().equals("ContainerPlayer")) {
continue;
}
f.setAccessible(true);
playerInventoryContainer = f;
break;
}
} else {
entityCountField = getNmsField("Entity", "entityCount");
}
entityCountField = getNmsField("Entity", "entityCount");
mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE);
@ -170,15 +149,9 @@ public class ReflectionManager {
enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class);
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"));
}
packetPlayOutConstructor =
getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class,
getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent"));
enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants();
getNmsEntityMethod = getCraftMethod("CraftEntity", "getHandle");
@ -209,16 +182,9 @@ public class ReflectionManager {
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey"));
villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class);
if (NmsVersion.v1_17.isSupported()) {
villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null);
playerConnection = getNmsField("EntityPlayer", "b");
connectionEntityMethod = getNmsMethod("PlayerConnection", "d");
incrementedInventoryStateId = getNmsMethod("Container", "incrementStateId");
} else {
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
}
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
} else {
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
}
@ -234,20 +200,7 @@ public class ReflectionManager {
getNmsWorld = getCraftMethod("CraftWorld", "getHandle");
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"));
@ -311,15 +264,15 @@ public class ReflectionManager {
ex.printStackTrace();
}
pingField = getNmsField("EntityPlayer", NmsVersion.v1_17.isSupported() ? "e" : "ping");
pingField = getNmsField("EntityPlayer", "ping");
if (NmsVersion.v1_14.isSupported()) {
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");
chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap");
trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities");
entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry");
if (NmsVersion.v1_16.isSupported()) {
chunkProviderField = getNmsField("WorldServer", NmsVersion.v1_17.isSupported() ? "C" : "chunkProvider");
chunkProviderField = getNmsField("WorldServer", "chunkProvider");
} else {
chunkProviderField = getNmsField("World", "chunkProvider");
}
@ -331,8 +284,8 @@ public class ReflectionManager {
}
public static boolean hasInvul(Entity entity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.hasInvul(entity);
if (nmsReflection != null) {
return nmsReflection.hasInvul(entity);
}
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
@ -351,8 +304,8 @@ public class ReflectionManager {
}
public static int getIncrementedStateId(Player player) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getIncrementedStateId(player);
if (nmsReflection != null) {
return nmsReflection.getIncrementedStateId(player);
}
try {
@ -465,8 +418,8 @@ public class ReflectionManager {
}
public static int getNewEntityId(boolean increment) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getNewEntityId(increment);
if (nmsReflection != null) {
return nmsReflection.getNewEntityId(increment);
}
try {
@ -493,15 +446,11 @@ public class ReflectionManager {
}
public static Object getPlayerConnectionOrPlayer(Player player) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getPlayerConnectionOrPlayer(player);
if (nmsReflection != null) {
return nmsReflection.getPlayerConnectionOrPlayer(player);
}
try {
if (NmsVersion.v1_17.isSupported()) {
return playerConnection.get(getNmsEntity(player));
}
return getNmsEntity(player);
} catch (Throwable throwable) {
throwable.printStackTrace();
@ -511,22 +460,12 @@ public class ReflectionManager {
}
public static Object createEntityInstance(DisguiseType disguiseType, String entityName) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createEntityInstance(entityName);
if (nmsReflection != null) {
return nmsReflection.createEntityInstance(entityName);
}
try {
Class<?> entityClass;
if (NmsVersion.v1_17.isSupported()) {
entityClass = getNmsClassIgnoreErrors("Entity" + entityName);
if (entityClass == null) {
entityClass = getNmsClass(entityName);
}
} else {
entityClass = getNmsClass("Entity" + entityName);
}
Class<?> entityClass = getNmsClass("Entity" + entityName);
Object entityObject;
Object world = getWorldServer(Bukkit.getWorlds().get(0));
@ -535,17 +474,13 @@ public class ReflectionManager {
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
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);
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);
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"));
@ -583,8 +518,8 @@ public class ReflectionManager {
}
public static Object getMobEffectList(int id) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getMobEffectList(id);
if (nmsReflection != null) {
return nmsReflection.getMobEffectList(id);
}
try {
@ -601,8 +536,8 @@ public class ReflectionManager {
}
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createMobEffect(id, duration, amplification, ambient, particles);
if (nmsReflection != null) {
return nmsReflection.createMobEffect(id, duration, amplification, ambient, particles);
}
try {
@ -615,10 +550,10 @@ public class ReflectionManager {
}
public static FakeBoundingBox getBoundingBox(Entity entity) {
if (NmsVersion.v1_18.isSupported()) {
double x = v1_18ReflectionManager.getXBoundingBox(entity);
double y = v1_18ReflectionManager.getYBoundingBox(entity);
double z = v1_18ReflectionManager.getZBoundingBox(entity);
if (nmsReflection != null) {
double x = nmsReflection.getXBoundingBox(entity);
double y = nmsReflection.getYBoundingBox(entity);
double z = nmsReflection.getZBoundingBox(entity);
return new FakeBoundingBox(x, y, z);
}
@ -668,16 +603,11 @@ public class ReflectionManager {
}
public static Object getPlayerFromPlayerConnection(Object nmsEntity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getPlayerFromPlayerConnection(nmsEntity);
if (nmsReflection != null) {
return nmsReflection.getPlayerFromPlayerConnection(nmsEntity);
}
try {
if (NmsVersion.v1_17.isSupported()) {
// Convert from player connection to EntityPlayer
nmsEntity = connectionEntityMethod.invoke(nmsEntity);
}
return nmsEntity;
} catch (Exception ex) {
ex.printStackTrace();
@ -687,8 +617,8 @@ public class ReflectionManager {
}
public static Entity getBukkitEntity(Object nmsEntity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getBukkitEntity(nmsEntity);
if (nmsReflection != null) {
return nmsReflection.getBukkitEntity(nmsEntity);
}
try {
@ -701,8 +631,8 @@ public class ReflectionManager {
}
public static ItemStack getBukkitItem(Object nmsItem) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getBukkitItem(nmsItem);
if (nmsReflection != null) {
return nmsReflection.getBukkitItem(nmsItem);
}
try {
@ -715,8 +645,8 @@ public class ReflectionManager {
}
public static ItemStack getCraftItem(ItemStack bukkitItem) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getCraftItem(bukkitItem);
if (nmsReflection != null) {
return nmsReflection.getCraftItem(bukkitItem);
}
try {
@ -767,6 +697,7 @@ public class ReflectionManager {
try {
Class<?> aClass = Class.forName("me.libraryaddict.disguise.utilities.reflection." + nmsVersion.name() + ".ReflectionManager");
Object o = aClass.getConstructor().newInstance();
return (ReflectionManagerAbstract) o;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
@ -792,8 +723,8 @@ public class ReflectionManager {
}
public static Object getCraftSound(Sound sound) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getCraftSound(sound);
if (nmsReflection != null) {
return nmsReflection.getCraftSound(sound);
}
try {
@ -806,8 +737,8 @@ public class ReflectionManager {
}
public static Object getEntityTrackerEntry(Entity target) throws Exception {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEntityTrackerEntry(target);
if (nmsReflection != null) {
return nmsReflection.getEntityTrackerEntry(target);
}
Object world = getWorldServer(target.getWorld());
@ -833,8 +764,8 @@ public class ReflectionManager {
}
public static Object getMinecraftServer() {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getMinecraftServer();
if (nmsReflection != null) {
return nmsReflection.getMinecraftServer();
}
try {
@ -846,8 +777,8 @@ public class ReflectionManager {
}
public static String getEnumArt(Art art) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEnumArt(art);
if (nmsReflection != null) {
return nmsReflection.getEnumArt(art);
}
try {
@ -865,8 +796,8 @@ public class ReflectionManager {
}
public static Object getBlockPosition(int x, int y, int z) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getBlockPosition(x, y, z);
if (nmsReflection != null) {
return nmsReflection.getBlockPosition(x, y, z);
}
try {
@ -879,8 +810,8 @@ public class ReflectionManager {
}
public static Enum getEnumDirection(int direction) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEnumDirection(direction);
if (nmsReflection != null) {
return nmsReflection.getEnumDirection(direction);
}
try {
@ -893,8 +824,8 @@ public class ReflectionManager {
}
public static Enum getEnumPlayerInfoAction(int action) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEnumPlayerInfoAction(action);
if (nmsReflection != null) {
return nmsReflection.getEnumPlayerInfoAction(action);
}
try {
@ -907,17 +838,13 @@ public class ReflectionManager {
}
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getPlayerInfoData(gameProfile);
if (nmsReflection != null) {
return nmsReflection.getPlayerInfoData(gameProfile);
}
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();
@ -1008,8 +935,8 @@ public class ReflectionManager {
}
public static Object getNmsEntity(Entity entity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getNmsEntity(entity);
if (nmsReflection != null) {
return nmsReflection.getNmsEntity(entity);
}
try {
@ -1039,8 +966,8 @@ public class ReflectionManager {
}
public static Object getNmsItem(ItemStack itemstack) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getNmsItem(itemstack);
if (nmsReflection != null) {
return nmsReflection.getNmsItem(itemstack);
}
try {
@ -1087,8 +1014,8 @@ public class ReflectionManager {
}
public static double getPing(Player player) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getPing(player);
if (nmsReflection != null) {
return nmsReflection.getPing(player);
}
try {
@ -1101,8 +1028,8 @@ public class ReflectionManager {
}
public static float[] getSize(Entity entity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getSize(entity);
if (nmsReflection != null) {
return nmsReflection.getSize(entity);
}
try {
@ -1129,8 +1056,8 @@ public class ReflectionManager {
}
public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getSkullBlob(gameProfile);
if (nmsReflection != null) {
return nmsReflection.getSkullBlob(gameProfile);
}
try {
@ -1153,8 +1080,8 @@ public class ReflectionManager {
}
public static Float getSoundModifier(Object entity) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getSoundModifier(entity);
if (nmsReflection != null) {
return nmsReflection.getSoundModifier(entity);
}
try {
@ -1172,8 +1099,8 @@ public class ReflectionManager {
Object minecraftServer = getMinecraftServer();
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
if (NmsVersion.v1_18.isSupported()) {
v1_18ReflectionManager.injectCallback(playername, callback);
if (nmsReflection != null) {
nmsReflection.injectCallback(playername, callback);
} else {
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) {
@ -1202,8 +1129,8 @@ public class ReflectionManager {
}
public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) {
if (NmsVersion.v1_18.isSupported()) {
v1_18ReflectionManager.setBoundingBox(entity, newBox.getX(), newBox.getY(), newBox.getZ());
if (nmsReflection != null) {
nmsReflection.setBoundingBox(entity, newBox.getX(), newBox.getY(), newBox.getZ());
return;
}
@ -1220,8 +1147,8 @@ public class ReflectionManager {
}
public static Enum getSoundCategory(String category) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getSoundCategory(category);
if (nmsReflection != null) {
return nmsReflection.getSoundCategory(category);
}
return soundCategories.get(category);
@ -1252,8 +1179,8 @@ public class ReflectionManager {
* @return null if the equipment slot is null
*/
public static Enum createEnumItemSlot(EquipmentSlot slot) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createEnumItemSlot(slot);
if (nmsReflection != null) {
return nmsReflection.createEnumItemSlot(slot);
}
switch (slot) {
@ -1333,8 +1260,8 @@ public class ReflectionManager {
}
public static Object getSoundString(Sound sound) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getSoundString(sound);
if (nmsReflection != null) {
return nmsReflection.getSoundString(sound);
}
try {
@ -1381,8 +1308,8 @@ public class ReflectionManager {
public static Object convertInvalidMeta(Object value) {
if (value instanceof Optional) {
Optional opt = (Optional) value;
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.convertOptional(opt);
if (nmsReflection != null) {
return nmsReflection.convertOptional(opt);
}
if (!opt.isPresent()) {
@ -1425,8 +1352,8 @@ public class ReflectionManager {
}
} else if (value instanceof Vector3F) {
Vector3F angle = (Vector3F) value;
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.convertVec3(angle);
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
@ -1436,8 +1363,8 @@ public class ReflectionManager {
}
} else if (value instanceof EulerAngle) {
EulerAngle angle = (EulerAngle) value;
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.convertVec3(angle);
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
@ -1446,8 +1373,8 @@ public class ReflectionManager {
ex.printStackTrace();
}
} else if (value instanceof Direction) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.convertDirection((Direction) value);
if (nmsReflection != null) {
return nmsReflection.convertDirection((Direction) value);
}
try {
@ -1457,8 +1384,8 @@ public class ReflectionManager {
}
} else if (value instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) value;
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getBlockPosition(pos.getX(), pos.getY(), pos.getZ());
if (nmsReflection != null) {
return nmsReflection.getBlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
try {
@ -1486,8 +1413,8 @@ public class ReflectionManager {
}
public static Material getMaterial(String name) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getMaterial(name);
if (nmsReflection != null) {
return nmsReflection.getMaterial(name);
}
try {
@ -1501,7 +1428,7 @@ public class ReflectionManager {
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name);
Object registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null);
Object registry = getNmsField("IRegistry", "ITEM").get(null);
Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass());
Object item = getMethod.invoke(registry, mcKey);
@ -1526,8 +1453,8 @@ public class ReflectionManager {
}
public static String getItemName(Material material) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getItemName(material);
if (nmsReflection != null) {
return nmsReflection.getItemName(material);
}
try {
@ -1540,7 +1467,7 @@ public class ReflectionManager {
Object registry;
if (NmsVersion.v1_13.isSupported()) {
registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null);
registry = getNmsField("IRegistry", "ITEM").get(null);
} else {
registry = getNmsField("Item", "REGISTRY").get(null);
}
@ -1562,8 +1489,8 @@ public class ReflectionManager {
}
public static Object getNmsVillagerData(VillagerData data) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getNmsVillagerData(data.getType(), data.getProfession());
if (nmsReflection != null) {
return nmsReflection.getNmsVillagerData(data.getType(), data.getProfession());
}
Object type = getVillagerType(data.getType());
@ -1579,8 +1506,8 @@ public class ReflectionManager {
}
public static Object getVillagerType(Villager.Type type) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getVillagerType(type);
if (nmsReflection != null) {
return nmsReflection.getVillagerType(type);
}
try {
@ -1619,8 +1546,8 @@ public class ReflectionManager {
}
public static Object getVillagerProfession(Villager.Profession profession) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getVillagerProfession(profession);
if (nmsReflection != null) {
return nmsReflection.getVillagerProfession(profession);
}
try {
@ -1658,8 +1585,8 @@ public class ReflectionManager {
public static Object createDataWatcherItem(MetaIndex id, Object value) {
WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value);
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createDataWatcherItem(watcherObject, convertInvalidMeta(value));
if (nmsReflection != null) {
return nmsReflection.createDataWatcherItem(watcherObject, convertInvalidMeta(value));
}
try {
@ -1673,8 +1600,8 @@ public class ReflectionManager {
@Deprecated
public static Object createSoundEffect(String minecraftKey) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createSoundEffect(minecraftKey);
if (nmsReflection != null) {
return nmsReflection.createSoundEffect(minecraftKey);
}
try {
@ -1687,8 +1614,8 @@ public class ReflectionManager {
}
public static Object createMinecraftKey(String name) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.createMinecraftKey(name);
if (nmsReflection != null) {
return nmsReflection.createMinecraftKey(name);
}
try {
@ -1701,8 +1628,8 @@ public class ReflectionManager {
}
public static Object getVec3D(Vector vector) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getVec3D(vector);
if (nmsReflection != null) {
return nmsReflection.getVec3D(vector);
}
try {
@ -1715,8 +1642,8 @@ public class ReflectionManager {
}
public static Object getEntityType(EntityType entityType) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEntityType(entityType);
if (nmsReflection != null) {
return nmsReflection.getEntityType(entityType);
}
try {
@ -1735,8 +1662,8 @@ public class ReflectionManager {
}
public static Object registerEntityType(NamespacedKey key) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.registerEntityType(key);
if (nmsReflection != null) {
return nmsReflection.registerEntityType(key);
}
try {
@ -1744,7 +1671,7 @@ public class ReflectionManager {
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null);
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
Constructor c = getNmsClass("EntityTypes").getConstructors()[0];
@ -1778,16 +1705,16 @@ public class ReflectionManager {
}
public static int getEntityTypeId(Object entityTypes) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEntityTypeId(entityTypes);
if (nmsReflection != null) {
return nmsReflection.getEntityTypeId(entityTypes);
}
try {
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null);
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
} catch (Exception ex) {
ex.printStackTrace();
}
@ -1796,8 +1723,8 @@ public class ReflectionManager {
}
public static int getEntityTypeId(EntityType entityType) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEntityTypeId(entityType);
if (nmsReflection != null) {
return nmsReflection.getEntityTypeId(entityType);
}
try {
@ -1806,9 +1733,9 @@ public class ReflectionManager {
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null);
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
}
return entityType.getTypeId();
@ -1820,17 +1747,17 @@ public class ReflectionManager {
}
public static Object getEntityType(NamespacedKey name) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getEntityType(name);
if (nmsReflection != null) {
return nmsReflection.getEntityType(name);
}
try {
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null);
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString());
return registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", mcKey.getClass()).invoke(registry, mcKey);
return registry.getClass().getMethod("a", mcKey.getClass()).invoke(registry, mcKey);
} catch (Exception ex) {
ex.printStackTrace();
}
@ -1839,9 +1766,8 @@ public class ReflectionManager {
}
public static Object getNmsEntityPose(EntityPose entityPose) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getNmsEntityPose(
entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
if (nmsReflection != null) {
return nmsReflection.getNmsEntityPose(entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
}
return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
@ -1863,8 +1789,8 @@ public class ReflectionManager {
}
public static int getCombinedIdByBlockData(BlockData data) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getCombinedIdByBlockData(data);
if (nmsReflection != null) {
return nmsReflection.getCombinedIdByBlockData(data);
}
try {
@ -1879,8 +1805,8 @@ public class ReflectionManager {
}
public static int getCombinedIdByItemStack(ItemStack itemStack) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getCombinedIdByItemStack(itemStack);
if (nmsReflection != null) {
return nmsReflection.getCombinedIdByItemStack(itemStack);
}
try {
@ -1901,8 +1827,8 @@ public class ReflectionManager {
}
public static BlockData getBlockDataByCombinedId(int id) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getBlockDataByCombinedId(id);
if (nmsReflection != null) {
return nmsReflection.getBlockDataByCombinedId(id);
}
try {
@ -1919,8 +1845,8 @@ public class ReflectionManager {
}
public static ItemStack getItemStackByCombinedId(int id) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getItemStackByCombinedId(id);
if (nmsReflection != null) {
return nmsReflection.getItemStackByCombinedId(id);
}
try {
@ -1947,8 +1873,8 @@ public class ReflectionManager {
}
public static Object getWorldServer(World w) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getWorldServer(w);
if (nmsReflection != null) {
return nmsReflection.getWorldServer(w);
}
try {
@ -1961,8 +1887,8 @@ public class ReflectionManager {
}
public static ItemMeta getDeserializedItemMeta(Map<String, Object> meta) {
if (NmsVersion.v1_18.isSupported()) {
return v1_18ReflectionManager.getDeserializedItemMeta(meta);
if (nmsReflection != null) {
return nmsReflection.getDeserializedItemMeta(meta);
}
try {
@ -2240,7 +2166,7 @@ public class ReflectionManager {
}
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType,
NmsVersion.v1_18.isSupported() ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
if (nmsEntity == null) {
DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")");

View File

@ -9,6 +9,7 @@
<version>10.0.26-SNAPSHOT</version>
<modules>
<module>shared</module>
<module>v1_17_R1</module>
<module>v1_18_R1</module>
<module>plugin</module>
</modules>

View File

@ -7,8 +7,8 @@
<groupId>LibsDisguises</groupId>
<version>10.0.26-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<artifactId>shared</artifactId>
<dependencies>

81
v1_17_R1/pom.xml Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>LibsDisguises</artifactId>
<groupId>LibsDisguises</groupId>
<version>10.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>v1_17_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>shared</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-spigot</remappedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,437 @@
package me.libraryaddict.disguise.utilities.reflection.v1_17;
import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.Vector3f;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.*;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.npc.VillagerData;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.bukkit.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectFunction;
import org.bukkit.craftbukkit.v1_17_R1.CraftArt;
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.craftbukkit.v1_17_R1.CraftSound;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class ReflectionManager implements ReflectionManagerAbstract {
public boolean hasInvul(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof net.minecraft.world.entity.LivingEntity) {
return nmsEntity.invulnerableTime > 0;
} else {
return nmsEntity.isInvulnerableTo(DamageSource.GENERIC);
}
}
public int getIncrementedStateId(Player player) {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
return serverPlayer.containerMenu.incrementStateId(); // TODO Check correct container
}
public int getNewEntityId() {
return getNewEntityId(true);
}
public int getNewEntityId(boolean increment) {
try {
Field entityCounter = net.minecraft.world.entity.Entity.class.getDeclaredField("b");
entityCounter.setAccessible(true);
AtomicInteger atomicInteger = (AtomicInteger) entityCounter.get(null);
if (increment) {
return atomicInteger.incrementAndGet();
} else {
return atomicInteger.get();
}
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
return -1;
}
public ServerGamePacketListenerImpl getPlayerConnectionOrPlayer(Player player) {
return ((CraftPlayer) player).getHandle().connection;
}
public net.minecraft.world.entity.Entity createEntityInstance(String entityName) {
Optional<net.minecraft.world.entity.EntityType<?>> optional = net.minecraft.world.entity.EntityType.byString(entityName.toLowerCase(Locale.ROOT));
if (optional.isPresent()) {
net.minecraft.world.entity.EntityType<?> entityType = optional.get();
ServerLevel world = getWorldServer(Bukkit.getWorlds().get(0));
net.minecraft.world.entity.Entity entity;
if (entityType == net.minecraft.world.entity.EntityType.PLAYER) {
WrappedGameProfile gameProfile = ReflectionManagerAbstract.getGameProfile(new UUID(0, 0), "Steve");
entity = new ServerPlayer(getMinecraftServer(), world, (GameProfile) gameProfile.getHandle());
}/* else if (entityType == net.minecraft.world.entity.EntityType.ENDER_PEARL) {
entity = new ThrownEnderpearl(world, (net.minecraft.world.entity.LivingEntity) createEntityInstance("cow"));
} else if (entityType == net.minecraft.world.entity.EntityType.FISHING_BOBBER) {
entity = new FishingHook((net.minecraft.world.entity.player.Player) createEntityInstance("player"), world, 0, 0);
}*/ else {
entity = entityType.create(world);
}
// Workaround for paper being 2 smart 4 me
entity.setPos(1.0, 1.0, 1.0);
entity.setPos(0.0, 0.0, 0.0);
return entity;
}
return null;
}
public MobEffect getMobEffectList(int id) {
return MobEffect.byId(id);
}
public MobEffectInstance createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
public MobEffectInstance createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
return new MobEffectInstance(getMobEffectList(id), duration, amplification, ambient, particles);
}
public AABB getBoundingBox(Entity entity) {
return ((CraftEntity) entity).getHandle().getBoundingBox();
}
public double getXBoundingBox(Entity entity) {
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
}
public double getYBoundingBox(Entity entity) {
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
}
public double getZBoundingBox(Entity entity) {
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
}
public ServerPlayer getPlayerFromPlayerConnection(Object nmsEntity) {
return ((ServerPlayerConnection) nmsEntity).getPlayer();
}
public Entity getBukkitEntity(Object nmsEntity) {
return ((net.minecraft.world.entity.Entity) nmsEntity).getBukkitEntity();
}
public ItemStack getBukkitItem(Object nmsItem) {
return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsItem);
}
public ItemStack getCraftItem(ItemStack bukkitItem) {
return CraftItemStack.asCraftCopy(bukkitItem);
}
public SoundEvent getCraftSound(Sound sound) {
return CraftSound.getSoundEffect(sound);
}
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
ServerChunkCache chunkSource = world.getChunkProvider();
ChunkMap chunkMap = chunkSource.chunkMap;
Map<Integer, ChunkMap.TrackedEntity> entityMap = chunkMap.G;
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
if (trackedEntity == null) {
return null;
}
Field field = ChunkMap.TrackedEntity.class.getDeclaredField("b");
field.setAccessible(true);
return (ServerEntity) field.get(trackedEntity);
}
public DedicatedServer getMinecraftServer() {
return ((CraftServer) Bukkit.getServer()).getServer();
}
public String getEnumArt(Art art) {
return Registry.MOTIVE.getKey(CraftArt.BukkitToNotch(art)).getPath();
}
public BlockPos getBlockPosition(int x, int y, int z) {
return new BlockPos(x, y, z);
}
public net.minecraft.core.Direction getEnumDirection(int direction) {
return net.minecraft.core.Direction.from2DDataValue(direction);
}
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
return ClientboundPlayerInfoPacket.Action.values()[action];
}
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
new TextComponent(gameProfile.getName()));
}
public Object getNmsEntity(Entity entity) {
return ((CraftEntity) entity).getHandle();
}
public double getPing(Player player) {
return player.getPing();
}
public float[] getSize(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
EntityDimensions dimensions = nmsEntity.getDimensions(net.minecraft.world.entity.Pose.STANDING);
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
}
public Float getSoundModifier(Object entity) {
if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) {
return 0.0f;
} else {
return ((net.minecraft.world.entity.LivingEntity) entity).getVoicePitch();
}
}
public void injectCallback(String playername, ProfileLookupCallback callback) {
Agent agent = Agent.MINECRAFT;
getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, agent, callback);
}
public void setBoundingBox(Entity entity, double x, double y, double z) {
Location loc = entity.getLocation();
((CraftEntity) entity).getHandle().setBoundingBox(
new AABB(loc.getX() - x / 2, loc.getY() - y / 2, loc.getZ() - z / 2, loc.getX() + x / 2, loc.getY() + y / 2, loc.getZ() + z / 2));
}
public Enum getSoundCategory(String category) {
return Arrays.stream(SoundSource.values()).filter(soundSource -> category.equalsIgnoreCase(soundSource.getName())).findAny().get();
}
/**
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
*
* @param slot
* @return null if the equipment slot is null
*/
public Enum createEnumItemSlot(EquipmentSlot slot) {
switch (slot) {
case HAND:
return net.minecraft.world.entity.EquipmentSlot.MAINHAND;
case OFF_HAND:
return net.minecraft.world.entity.EquipmentSlot.OFFHAND;
case FEET:
return net.minecraft.world.entity.EquipmentSlot.FEET;
case LEGS:
return net.minecraft.world.entity.EquipmentSlot.LEGS;
case CHEST:
return net.minecraft.world.entity.EquipmentSlot.CHEST;
case HEAD:
return net.minecraft.world.entity.EquipmentSlot.HEAD;
default:
return null;
}
}
public Object getSoundString(Sound sound) {
return CraftSound.getSoundEffect(sound).getLocation().toString(); // TODO
}
public Optional<?> convertOptional(Object val) {
if (val instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) val;
return Optional.of(getBlockPosition(pos.getX(), pos.getY(), pos.getZ()));
} else if (val instanceof WrappedBlockData) {
Object obj = ((WrappedBlockData) val).getHandle();
return Optional.of(obj);
} else if (val instanceof ItemStack) {
Object obj = getNmsItem((ItemStack) val);
return Optional.of(obj);
} else if (val instanceof WrappedChatComponent) {
Object obj = ((WrappedChatComponent) val).getHandle();
return Optional.of(obj);
}
return Optional.empty();
}
public Vector3f convertVec3(Object object) {
if (object instanceof Vector3F) {
Vector3F vector3F = (Vector3F) object;
return new Vector3f(vector3F.getX(), vector3F.getY(), vector3F.getZ());
} else if (object instanceof EulerAngle) {
EulerAngle eulerAngle = (EulerAngle) object;
return new Vector3f((float) eulerAngle.getX(), (float) eulerAngle.getY(), (float) eulerAngle.getZ());
}
return null;
}
public net.minecraft.core.Direction convertDirection(Direction direction) {
return net.minecraft.core.Direction.from3DDataValue(direction.ordinal());
}
public Material getMaterial(String name) {
return CraftMagicNumbers.INSTANCE.getMaterial(name, CraftMagicNumbers.INSTANCE.getDataVersion());
}
public String getItemName(Material material) {
return Registry.ITEM.getKey(CraftMagicNumbers.getItem(material)).getPath();
}
public net.minecraft.world.item.ItemStack getNmsItem(ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack);
}
public VillagerData getNmsVillagerData(Villager.Type villagerType, Villager.Profession villagerProfession) {
VillagerType nmsVillagerType = Registry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(villagerType.getKey()));
VillagerProfession nmsVillagerProfession = Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(villagerProfession.getKey()));
return new net.minecraft.world.entity.npc.VillagerData(nmsVillagerType, nmsVillagerProfession, 1);
}
public VillagerType getVillagerType(Villager.Type type) {
return Registry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()));
}
public VillagerProfession getVillagerProfession(Villager.Profession profession) {
return Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(profession.getKey()));
}
public <T> SynchedEntityData.DataItem<T> createDataWatcherItem(WrappedDataWatcher.WrappedDataWatcherObject wrappedDataWatcherObject, T metaItem) {
return new SynchedEntityData.DataItem<>((EntityDataAccessor<T>) wrappedDataWatcherObject.getHandle(), metaItem);
}
@Deprecated
public SoundEvent createSoundEffect(String minecraftKey) {
return new SoundEvent(new ResourceLocation(minecraftKey));
}
@Override
public ResourceLocation createMinecraftKey(String name) {
return new ResourceLocation(name);
}
public Vec3 getVec3D(Vector vector) {
return new Vec3(vector.getX(), vector.getY(), vector.getZ());
}
public net.minecraft.world.entity.EntityType getEntityType(EntityType entityType) {
return net.minecraft.world.entity.EntityType.byString(
entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName()).orElse(null);
}
public Object registerEntityType(NamespacedKey key) {
net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity> newEntity =
new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0);
Registry.register(Registry.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(key), newEntity);
newEntity.getDescriptionId();
return newEntity; // TODO ??? Some reflection in legacy that I'm unsure about
}
public int getEntityTypeId(Object entityTypes) {
net.minecraft.world.entity.EntityType entityType = (net.minecraft.world.entity.EntityType) entityTypes;
return Registry.ENTITY_TYPE.getId(entityType);
}
public int getEntityTypeId(EntityType entityType) {
return getEntityTypeId(getEntityType(entityType));
}
public Object getEntityType(NamespacedKey name) {
return Registry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(name));
}
public Object getNmsEntityPose(String enumPose) {
return net.minecraft.world.entity.Pose.valueOf(enumPose);
}
public int getCombinedIdByBlockData(BlockData data) {
BlockState state = ((CraftBlockData) data).getState();
return Block.getId(state);
}
public int getCombinedIdByItemStack(ItemStack itemStack) {
Block block = CraftMagicNumbers.getBlock(itemStack.getType());
return Block.getId(block.defaultBlockState());
}
public BlockData getBlockDataByCombinedId(int id) {
return CraftBlockData.fromData(Block.stateById(id));
}
public ItemStack getItemStackByCombinedId(int id) {
return new ItemStack(CraftMagicNumbers.getMaterial(Block.stateById(id).getBlock()));
}
public ServerLevel getWorldServer(World w) {
return ((CraftWorld) w).getHandle();
}
public ItemMeta getDeserializedItemMeta(Map<String, Object> meta) {
try {
Class<?> aClass = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem$SerializableMeta");
Method deserialize = aClass.getDeclaredMethod("deserialize", Map.class);
Object itemMeta = deserialize.invoke(null, meta);
return (ItemMeta) itemMeta;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -6,9 +6,10 @@
<artifactId>LibsDisguises</artifactId>
<groupId>LibsDisguises</groupId>
<version>10.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<artifactId>v1_18_R1</artifactId>
<dependencies>