1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-26 10:19:16 +00:00

Fixed issues with config subclasses

This commit is contained in:
Tim203
2020-11-21 15:28:52 +01:00
parent 660a35df96
commit 70fcac9fed
3 changed files with 22 additions and 9 deletions

View File

@@ -50,21 +50,33 @@ public class ConfigInitializer {
@Override
protected Map<String, Property> getPropertiesMap(Class<?> type, BeanAccess bAccess) {
Map<String, Property> properties = new LinkedHashMap<>();
getPropertiesFromClass(type, FloodgateConfig.class, properties);
return properties;
}
private void getPropertiesFromClass(Class<?> type, Class<?> stopAfter,
Map<String, Property> propertyMap) {
Class<?> current = type;
// make ProxyFloodgateConfig work
// iterate through all fields of this specific class
while (type.isAssignableFrom(current)) {
while (!Object.class.equals(current)) {
for (Field field : current.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
String correctName = getCorrectName(field.getName());
// children should override parents
properties.putIfAbsent(correctName, new FieldProperty(field));
propertyMap.putIfAbsent(correctName, new FieldProperty(field));
}
if (field.getClass().getSuperclass().equals(current)) {
getPropertiesFromClass(field.getClass(), field.getClass(), propertyMap);
}
}
current = current.getSuperclass();
if (current.equals(stopAfter)) {
return;
}
current = type.getSuperclass();
}
return properties;
}
private String getCorrectName(String name) {

View File

@@ -105,7 +105,8 @@ public final class ConfigLoader {
}
Path keyPath = dataFolder.resolve(configInstance.getKeyFileName());
if (!Files.exists(keyPath)) { // don't assume that the key always exists with the existence of a config
// don't assume that the key always exists with the existence of a config
if (!Files.exists(keyPath)) {
try {
Key key = keyProducer.produce();
cipher.init(key);

View File

@@ -67,8 +67,8 @@ public class SpigotSkinHandler extends SkinHandler {
PropertyMap properties = profile.getProperties();
Collection<Property> oldTexture = properties.get("textures");
properties.remove("textures", oldTexture);
//todo check if removing all texture properties breaks some stuff
properties.removeAll("textures");
Property property = new Property(
"textures",
response.get("value").getAsString(),