From 240f41ff03a3b3bee345b6dcc2773a0914326150 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 26 Jan 2020 11:22:21 -0600 Subject: [PATCH] Use Path instead of File for floodgate key file in config ...and fix related issues with the file not being found. --- .../platform/bukkit/GeyserBukkitConfiguration.java | 6 ++++-- .../platform/bungeecord/GeyserBungeeConfiguration.java | 6 ++++-- .../platform/sponge/GeyserSpongeConfiguration.java | 6 ++++-- .../platform/standalone/GeyserConfiguration.java | 9 ++++++--- .../java/org/geysermc/common/IGeyserConfiguration.java | 4 ++-- .../connector/network/session/GeyserSession.java | 3 +-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index f4c4b008c..e38a982db 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -29,6 +29,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -100,8 +102,8 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder.toString() + config.getString("floodgate-key-file", "public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 0aaf714b3..94580e583 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -30,6 +30,8 @@ import net.md_5.bungee.config.Configuration; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -101,8 +103,8 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder, config.getString("floodgate-key-file", "public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 86b3ef342..dbc83fbea 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -32,6 +32,8 @@ import ninja.leaping.configurate.ConfigurationNode; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -104,8 +106,8 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder, node.getNode("floodgate-key-file").getString("public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem")); } @Override diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java index 6f4837f8f..06cb711c1 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java @@ -27,10 +27,13 @@ package org.geysermc.platform.standalone; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.Getter; + import org.geysermc.common.IGeyserConfiguration; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) @@ -63,8 +66,8 @@ public class GeyserConfiguration implements IGeyserConfiguration { private MetricsInfo metrics; @Override - public File getFloodgateKeyFile() { - return new File(floodgateKeyFile); + public Path getFloodgateKeyFile() { + return Paths.get(floodgateKeyFile); } @Getter diff --git a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java index 0a1da2d35..db5d831b1 100644 --- a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java +++ b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java @@ -25,7 +25,7 @@ package org.geysermc.common; -import java.io.File; +import java.nio.file.Path; import java.util.Map; public interface IGeyserConfiguration { @@ -46,7 +46,7 @@ public interface IGeyserConfiguration { boolean isAllowThirdPartyCapes(); - File getFloodgateKeyFile(); + Path getFloodgateKeyFile(); IMetricsInfo getMetrics(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index f38e810d4..3ddc3bd43 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -66,7 +66,6 @@ import org.geysermc.floodgate.util.EncryptionUtil; import java.io.IOException; import java.net.InetSocketAddress; -import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; @@ -190,7 +189,7 @@ public class GeyserSession implements CommandSender { PublicKey key = null; try { key = EncryptionUtil.getKeyFromFile( - Paths.get(connector.getConfig().getFloodgateKeyFile().getPath()), + connector.getConfig().getFloodgateKeyFile(), PublicKey.class ); } catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) {