3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-26 03:20:07 +01:00

Change disabledSlots field to an array to deal with multiple field names in 1_16_R2

Dieser Commit ist enthalten in:
Steven 2020-11-17 14:34:55 +08:00
Ursprung 60a5be7b94
Commit c7834fdb9e
5 geänderte Dateien mit 24 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.St3venAU.plugins</groupId>
<artifactId>ArmorStandTools</artifactId>
<version>3.7.1</version>
<version>3.7.2</version>
<name>ArmorStandTools</name>
<repositories>

Datei anzeigen

@ -18,13 +18,12 @@ import java.util.Map;
abstract class NMS {
private final String
nmsVersion,
disabledSlotsFieldName;
private final String nmsVersion;
private final String[] disabledSlotsFieldNames;
NMS(String nmsVersion, String disabledSlotsFieldName) {
NMS(String nmsVersion, String... disabledSlotsFieldNames) {
this.nmsVersion = nmsVersion;
this.disabledSlotsFieldName = disabledSlotsFieldName;
this.disabledSlotsFieldNames = disabledSlotsFieldNames;
}
private Class<?> getNMSClass(String nmsClassString) throws ClassNotFoundException {
@ -63,17 +62,24 @@ abstract class NMS {
return slotsDisabled;
}
private Field getDisabledSlotsField(Object nmsEntity) {
if(nmsEntity == null) return null;
for(String field : disabledSlotsFieldNames) {
try {
Field f = nmsEntity.getClass().getDeclaredField(field);
f.setAccessible(true);
return f;
} catch (NoSuchFieldException e) {
}
}
return null;
}
private int getDisabledSlots(ArmorStand as) {
Object nmsEntity = getNmsEntity(as);
if(nmsEntity == null) return 0;
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(disabledSlotsFieldName);
} catch (NoSuchFieldException e) {
e.printStackTrace();
return 0;
}
f.setAccessible(true);
Field f = getDisabledSlotsField(nmsEntity);
if(f == null) return 0;
try {
return (Integer) f.get(nmsEntity);
} catch (IllegalAccessException e) {
@ -85,14 +91,7 @@ abstract class NMS {
void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) {
Object nmsEntity = getNmsEntity(as);
if (nmsEntity == null) return;
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(disabledSlotsFieldName);
} catch (NoSuchFieldException e) {
e.printStackTrace();
return;
}
f.setAccessible(true);
Field f = getDisabledSlotsField(nmsEntity);
try {
f.set(nmsEntity, slotsDisabled ? 0xFFFFFF : 0);
} catch (IllegalAccessException e) {

Datei anzeigen

@ -6,7 +6,7 @@ class NMS_v1_16_R2 extends NMS {
public NMS_v1_16_R2(String nmsVersion) {
super(
nmsVersion,
"disabledSlots"
"disabledSlots", "bv"
);
}

Datei anzeigen

@ -4,7 +4,7 @@
#
# Main Config
#
# File generated by: v3.7.1
# File generated by: v3.7.2
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
#

Datei anzeigen

@ -4,7 +4,7 @@
#
# Language Config
#
# File generated by: v3.7.1
# File generated by: v3.7.2
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
#