Fixup remaining critical startup issues
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ClassMappings {
|
||||
private static HashMap<String, String> classLocations = new HashMap<>();
|
||||
|
||||
private static final String[] packages = getPackages();
|
||||
|
||||
public static String getClass(String packageHint, String className) {
|
||||
String location = classLocations.get(className);
|
||||
if (location != null)
|
||||
return location;
|
||||
location = className;
|
||||
String[] arrayOfString;
|
||||
int i;
|
||||
byte b;
|
||||
for (arrayOfString = packages, i = arrayOfString.length, b = 0; b < i; ) {
|
||||
String pack = arrayOfString[b];
|
||||
if (!pack.startsWith(packageHint)) {
|
||||
b++;
|
||||
continue;
|
||||
}
|
||||
String toTry = pack + "." + className;
|
||||
try {
|
||||
Class.forName(toTry);
|
||||
location = pack + "." + className;
|
||||
break;
|
||||
} catch (Throwable throwable) {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
classLocations.put(className, location);
|
||||
return location;
|
||||
}
|
||||
|
||||
private static String[] getPackages() {
|
||||
String[] s = {
|
||||
"net.minecraft.core", "net.minecraft.core.particles", "net.minecraft.nbt", "net.minecraft.network.chat", "net.minecraft.network.protocol.game", "net.minecraft.network.syncher", "net.minecraft.resources", "net.minecraft.server.level", "net.minecraft.server", "net.minecraft.server.network",
|
||||
"net.minecraft.sounds", "net.minecraft.world.damagesource", "net.minecraft.world.effect", "net.minecraft.world.entity.ambient", "net.minecraft.world.entity.animal.axolotl", "net.minecraft.world.entity.animal", "net.minecraft.world.entity.animal.goat", "net.minecraft.world.entity.animal.horse", "net.minecraft.world.entity.boss.enderdragon", "net.minecraft.world.entity.boss.wither",
|
||||
"net.minecraft.world.entity.decoration", "net.minecraft.world.entity", "net.minecraft.world.entity.item", "net.minecraft.world.entity.monster", "net.minecraft.world.entity.monster.hoglin", "net.minecraft.world.entity.monster.piglin", "net.minecraft.world.entity.npc", "net.minecraft.world.entity.player", "net.minecraft.world.entity.projectile", "net.minecraft.world.entity.vehicle",
|
||||
"net.minecraft.world.inventory", "net.minecraft.world.item", "net.minecraft.world.level.block", "net.minecraft.world.level.block.state", "net.minecraft.world.level", "net.minecraft.world.phys", "org.bukkit.craftbukkit.$version$.block.data", "org.bukkit.craftbukkit.$version$", "org.bukkit.craftbukkit.$version$.entity", "org.bukkit.craftbukkit.$version$.inventory",
|
||||
"org.bukkit.craftbukkit.$version$.util" };
|
||||
for (int i = 0; i < s.length; i++)
|
||||
s[i] = s[i].replace("$version$", ReflectionManager.getBukkitVersion());
|
||||
return s;
|
||||
}
|
||||
}
|
@@ -117,7 +117,15 @@ public class ReflectionManager {
|
||||
|
||||
public static void init() {
|
||||
try {
|
||||
v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18);
|
||||
// Load first because its necessary for 1.18+
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
entityPoseClass = getNmsClass("EntityPose");
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_18.isSupported()) {
|
||||
v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18);
|
||||
return;
|
||||
}
|
||||
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class);
|
||||
|
||||
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
|
||||
@@ -199,7 +207,6 @@ public class ReflectionManager {
|
||||
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);
|
||||
|
||||
@@ -348,6 +355,7 @@ public class ReflectionManager {
|
||||
if (NmsVersion.v1_18.isSupported()) {
|
||||
return v1_18ReflectionManager.getIncrementedStateId(player);
|
||||
}
|
||||
|
||||
try {
|
||||
Object container = playerInventoryContainer.get(getNmsEntity(player));
|
||||
|
||||
@@ -924,13 +932,7 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
public static WrappedGameProfile getGameProfile(UUID uuid, String playerName) {
|
||||
try {
|
||||
return new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(),
|
||||
playerName == null || playerName.length() < 17 ? playerName : playerName.substring(0, 16));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return ReflectionManagerAbstract.getGameProfile(uuid == null ? getRandomUUID() : uuid, playerName);
|
||||
}
|
||||
|
||||
public static WrappedGameProfile getClonedProfile(WrappedGameProfile gameProfile) {
|
||||
@@ -968,6 +970,10 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
private static String getLocation(String pack, String className) {
|
||||
if (NmsVersion.v1_18.isSupported()) {
|
||||
return ClassMappings.getClass(pack, className);
|
||||
}
|
||||
|
||||
String toReturn = classLocations.get(className);
|
||||
|
||||
if (toReturn != null) {
|
||||
@@ -1677,6 +1683,10 @@ 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));
|
||||
}
|
||||
|
||||
try {
|
||||
return dataWatcherItemConstructor.newInstance(watcherObject.getHandle(), convertInvalidMeta(value));
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
@@ -2253,7 +2263,7 @@ public class ReflectionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, nmsEntityName);
|
||||
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, NmsVersion.v1_18.isSupported() ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
|
||||
|
||||
if (nmsEntity == null) {
|
||||
DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
||||
|
Reference in New Issue
Block a user