mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-25 01:21:24 +01:00
Fix for change in EntityTypes fields
This commit is contained in:
parent
1dc0edd7b0
commit
d9a0481a7e
@ -66,6 +66,10 @@ public class NMS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Field getField(Class<?> clazz, String field) {
|
public static Field getField(Class<?> clazz, String field) {
|
||||||
|
return getField(clazz, field, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Field getField(Class<?> clazz, String field, boolean log) {
|
||||||
if (clazz == null)
|
if (clazz == null)
|
||||||
return null;
|
return null;
|
||||||
Field f = null;
|
Field f = null;
|
||||||
@ -73,20 +77,28 @@ public class NMS {
|
|||||||
f = clazz.getDeclaredField(field);
|
f = clazz.getDeclaredField(field);
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (log) {
|
||||||
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field getFinalField(Class<?> clazz, String field) {
|
public static Field getFinalField(Class<?> clazz, String field) {
|
||||||
Field f = getField(clazz, field);
|
return getFinalField(clazz, field, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Field getFinalField(Class<?> clazz, String field, boolean log) {
|
||||||
|
Field f = getField(clazz, field, log);
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MODIFIERS_FIELD.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
MODIFIERS_FIELD.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (log) {
|
||||||
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
|
@ -1017,7 +1017,10 @@ public class NMSImpl implements NMSBridge {
|
|||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (ENTITY_REGISTRY == null)
|
if (ENTITY_REGISTRY == null)
|
||||||
return;
|
return;
|
||||||
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY");
|
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY", false);
|
||||||
|
if (field == null) {
|
||||||
|
field = NMS.getFinalField(IRegistry.class, "ENTITY_TYPE");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
field.set(null, ENTITY_REGISTRY.getWrapped());
|
field.set(null, ENTITY_REGISTRY.getWrapped());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1592,7 +1595,10 @@ public class NMSImpl implements NMSBridge {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY");
|
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY", false);
|
||||||
|
if (field == null) {
|
||||||
|
field = NMS.getFinalField(IRegistry.class, "ENTITY_TYPE");
|
||||||
|
}
|
||||||
ENTITY_REGISTRY = new CustomEntityRegistry((RegistryMaterials<EntityTypes<?>>) field.get(null));
|
ENTITY_REGISTRY = new CustomEntityRegistry((RegistryMaterials<EntityTypes<?>>) field.get(null));
|
||||||
field.set(null, ENTITY_REGISTRY);
|
field.set(null, ENTITY_REGISTRY);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user