diff --git a/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigInitializer.java b/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigInitializer.java index a5f51ce6..92aeb5b3 100644 --- a/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigInitializer.java +++ b/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigInitializer.java @@ -52,7 +52,8 @@ public class ConfigInitializer { Map properties = new LinkedHashMap<>(); Class current = type; // make ProxyFloodgateConfig work - while (FloodgateConfig.class.isAssignableFrom(current)) { + // iterate through all fields of this specific class + while (type.isAssignableFrom(current)) { for (Field field : current.getDeclaredFields()) { int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { diff --git a/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigLoader.java b/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigLoader.java index 730dbb8e..e3ecde02 100644 --- a/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigLoader.java +++ b/common/src/main/java/org/geysermc/floodgate/config/loader/ConfigLoader.java @@ -69,8 +69,8 @@ public final class ConfigLoader { } boolean newConfig = !Files.exists(configPath); - try { - if (newConfig) { + if (newConfig) { + try { InputStream newConfigFile = ConfigLoader.class.getClassLoader().getResourceAsStream(defaultConfigName); if (newConfigFile == null) { @@ -78,31 +78,9 @@ public final class ConfigLoader { } Files.copy(newConfigFile, configPath); - - Key key = keyProducer.produce(); - cipher.init(key); - - String test = "abcdefghijklmnopqrstuvwxyz0123456789"; - byte[] encrypted = cipher.encryptFromString(test); - String decrypted = cipher.decryptToString(encrypted); - - if (!test.equals(decrypted)) { - logger.error("Whoops, we tested the generated Floodgate keys but " + - "the decrypted test message doesn't match the original.\n" + - "Original message: " + test + "." + - "Decrypted message: " + decrypted + ".\n" + - "The encrypted message itself: " + new String(encrypted) - ); - throw new RuntimeException( - "Tested the generated public and private key but, " + - "the decrypted message doesn't match the original!" - ); - } - - Files.write(dataFolder.resolve("key.pem"), key.getEncoded()); + } catch (Exception exception) { + logger.error("Error while creating config", exception); } - } catch (Exception exception) { - logger.error("Error while creating config", exception); } T configInstance; @@ -126,8 +104,37 @@ public final class ConfigLoader { throw new RuntimeException("Failed to load the config! Try to delete the config file"); } + Path keyPath = dataFolder.resolve(configInstance.getKeyFileName()); + if (!Files.exists(keyPath)) { // don't assume that the key always exists with the existence of a config + try { + Key key = keyProducer.produce(); + cipher.init(key); + + String test = "abcdefghijklmnopqrstuvwxyz0123456789"; + byte[] encrypted = cipher.encryptFromString(test); + String decrypted = cipher.decryptToString(encrypted); + + if (!test.equals(decrypted)) { + logger.error("Whoops, we tested the generated Floodgate keys but " + + "the decrypted test message doesn't match the original.\n" + + "Original message: " + test + "." + + "Decrypted message: " + decrypted + ".\n" + + "The encrypted message itself: " + new String(encrypted) + ); + throw new RuntimeException( + "Tested the generated public and private key but, " + + "the decrypted message doesn't match the original!" + ); + } + + Files.write(keyPath, key.getEncoded()); + } catch (Exception exception) { + logger.error("Error while creating key", exception); + } + } + try { - Key key = keyProducer.produceFrom(dataFolder.resolve(configInstance.getKeyFileName())); + Key key = keyProducer.produceFrom(keyPath); cipher.init(key); configInstance.setKey(key); } catch (IOException exception) { diff --git a/database/sqlite/src/main/java/org/geysermc/floodgate/database/SqliteDatabase.java b/database/sqlite/src/main/java/org/geysermc/floodgate/database/SqliteDatabase.java index 563eddd7..41dab4f0 100644 --- a/database/sqlite/src/main/java/org/geysermc/floodgate/database/SqliteDatabase.java +++ b/database/sqlite/src/main/java/org/geysermc/floodgate/database/SqliteDatabase.java @@ -90,7 +90,7 @@ public class SqliteDatabase extends CommonPlayerLink { String javaUsername = result.getString("javaUsername"); UUID javaUniqueId = UUID.fromString(result.getString("javaUniqueId")); - return new LinkedPlayer(javaUsername, javaUniqueId, bedrockId); + return LinkedPlayer.of(javaUsername, javaUniqueId, bedrockId); } catch (SQLException | NullPointerException exception) { getLogger().error("Error while getting LinkedPlayer", exception); throw new CompletionException("Error while getting LinkedPlayer", exception); diff --git a/spigot/src/main/java/org/geysermc/floodgate/pluginmessage/SpigotSkinHandler.java b/spigot/src/main/java/org/geysermc/floodgate/pluginmessage/SpigotSkinHandler.java index 8dd00b0e..f04120dd 100644 --- a/spigot/src/main/java/org/geysermc/floodgate/pluginmessage/SpigotSkinHandler.java +++ b/spigot/src/main/java/org/geysermc/floodgate/pluginmessage/SpigotSkinHandler.java @@ -30,6 +30,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; import java.lang.reflect.Method; +import java.util.Collection; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.geysermc.floodgate.api.logger.FloodgateLogger; @@ -66,7 +67,8 @@ public class SpigotSkinHandler extends SkinHandler { PropertyMap properties = profile.getProperties(); - properties.remove("textures", properties.get("textures").iterator().next()); + Collection oldTexture = properties.get("textures"); + properties.remove("textures", oldTexture); Property property = new Property( "textures", response.get("value").getAsString(),