From dcef62fa577efed2e41a91f1caabcd0edaabf11f Mon Sep 17 00:00:00 2001 From: games647 Date: Sat, 27 Jan 2018 21:49:32 +0100 Subject: [PATCH] Fix FileAlreadyExistsException for sym linked folders --- .../fastlogin/bukkit/EncryptionUtil.java | 25 +++++++++---------- .../fastlogin/bukkit/FastLoginBukkit.java | 11 ++++---- .../fastlogin/bungee/FastLoginBungee.java | 4 +-- .../bungee/listener/ConnectListener.java | 6 ++--- .../core/mojang/MojangApiConnector.java | 4 +-- .../fastlogin/core/shared/FastLoginCore.java | 12 +++++---- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java index 570fb06c..35d84854 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java @@ -1,8 +1,7 @@ package com.github.games647.fastlogin.bukkit; -import com.google.common.base.Charsets; - import java.math.BigInteger; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.Key; import java.security.KeyPair; @@ -28,6 +27,10 @@ public class EncryptionUtil { public static final int VERIFY_TOKEN_LENGTH = 4; public static final String KEY_PAIR_ALGORITHM = "RSA"; + private EncryptionUtil() { + //utility + } + /** * Generate a RSA key pair * @@ -61,9 +64,9 @@ public class EncryptionUtil { /** * Generate the server id based on client and server data. * - * @param sessionId session for the current login attempt + * @param sessionId session for the current login attempt * @param sharedSecret shared secret between the client and the server - * @param publicKey public key of the server + * @param publicKey public key of the server * @return the server id formatted as a hexadecimal string. */ public static String getServerIdHashString(String sessionId, Key sharedSecret, PublicKey publicKey) { @@ -80,9 +83,9 @@ public class EncryptionUtil { /** * Decrypts the content and extracts the key spec. * - * @param cipher decryption cipher + * @param cipher decryption cipher * @param privateKey private key of the server - * @param sharedKey the encrypted shared key + * @param sharedKey the encrypted shared key * @return shared secret key * @throws GeneralSecurityException */ @@ -95,8 +98,8 @@ public class EncryptionUtil { * Decrypted the given data using the cipher. * * @param cipher decryption cypher - * @param key server private key - * @param data the encrypted data + * @param key server private key + * @param data the encrypted data * @return clear text data * @throws GeneralSecurityException if it fails to initialize and decrypt the data */ @@ -109,14 +112,10 @@ public class EncryptionUtil { throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("SHA-1"); - digest.update(sessionId.getBytes(Charsets.ISO_8859_1)); + digest.update(sessionId.getBytes(StandardCharsets.ISO_8859_1)); digest.update(sharedSecret.getEncoded()); digest.update(publicKey.getEncoded()); return digest.digest(); } - - private EncryptionUtil() { - //utility - } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 73a95082..397dd929 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -4,15 +4,14 @@ import com.github.games647.fastlogin.bukkit.commands.CrackedCommand; import com.github.games647.fastlogin.bukkit.commands.PremiumCommand; import com.github.games647.fastlogin.bukkit.listener.BungeeListener; import com.github.games647.fastlogin.bukkit.listener.JoinListener; -import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener; import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener; +import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener; import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener; import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.mojang.MojangApiConnector; import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.PlatformPlugin; -import com.google.common.collect.Iterables; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import com.google.common.net.HostAndPort; @@ -20,6 +19,7 @@ import com.google.common.net.HostAndPort; import java.nio.file.Path; import java.security.KeyPair; import java.util.List; +import java.util.Optional; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ThreadFactory; @@ -124,13 +124,14 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin optPlayer = getServer().getOnlinePlayers().stream().findFirst(); + if (!optPlayer.isPresent()) { logger.info("No player online to send a plugin message to the proxy"); return; } - notifyBungeeCord(firstPlayer, target, activate, false); + notifyBungeeCord(optPlayer.get(), target, activate, false); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index f5eb1c5d..5db8af7b 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -7,12 +7,12 @@ import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.mojang.MojangApiConnector; import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.PlatformPlugin; -import com.google.common.collect.Maps; import com.google.common.net.HostAndPort; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.nio.file.Path; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ThreadFactory; @@ -30,7 +30,7 @@ import org.slf4j.Logger; */ public class FastLoginBungee extends Plugin implements PlatformPlugin { - private final ConcurrentMap session = Maps.newConcurrentMap(); + private final ConcurrentMap session = new ConcurrentHashMap<>(); private FastLoginCore core; private Logger logger; diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java index 632e7d32..f44979b7 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/ConnectListener.java @@ -5,9 +5,9 @@ import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck; import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask; import com.github.games647.fastlogin.core.PlayerProfile; import com.github.games647.fastlogin.core.shared.LoginSession; -import com.google.common.base.Charsets; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.UUID; import net.md_5.bungee.api.ProxyServer; @@ -46,7 +46,7 @@ public class ConnectListener implements Listener { } preLoginEvent.registerIntent(plugin); - + PendingConnection connection = preLoginEvent.getConnection(); Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, preLoginEvent, connection); ProxyServer.getInstance().getScheduler().runAsync(plugin, asyncPremiumCheck); @@ -74,7 +74,7 @@ public class ConnectListener implements Listener { //bungeecord will do this automatically so override it on disabled option if (!plugin.getCore().getConfig().get("premiumUuid", true)) { try { - UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(Charsets.UTF_8)); + UUID offlineUUID = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8)); //bungeecord doesn't support overriding the premium uuid //so we have to do it with reflection diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java index 14ab212b..b2cdcf01 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java @@ -3,7 +3,6 @@ package com.github.games647.fastlogin.core.mojang; import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.shared.LoginSession; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.net.HostAndPort; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -19,6 +18,7 @@ import java.net.URL; import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -60,7 +60,7 @@ public class MojangApiConnector { this.logger = logger; this.rateLimit = Math.max(rateLimit, 600); - List proxyBuilder = Lists.newArrayList(); + List proxyBuilder = new ArrayList<>(); for (HostAndPort proxy : proxies) { proxyBuilder.add(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getHostText(), proxy.getPort()))); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 23855c5b..d5c864fe 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -6,8 +6,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator; import com.github.games647.fastlogin.core.hooks.PasswordGenerator; import com.github.games647.fastlogin.core.mojang.MojangApiConnector; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.common.net.HostAndPort; import java.io.File; @@ -15,7 +13,9 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -39,7 +39,7 @@ public class FastLoginCore

> { protected final Map localeMessages = new ConcurrentHashMap<>(); private final ConcurrentMap pendingLogin = CommonUtil.buildCache(5, -1); - private final Set pendingConfirms = Sets.newHashSet(); + private final Set pendingConfirms = new HashSet<>(); private final T plugin; private Configuration config; @@ -76,7 +76,7 @@ public class FastLoginCore

> { List ipAddresses = config.getStringList("ip-addresses"); int requestLimit = config.getInt("mojang-request-limit"); - List proxyList = config.get("proxies", Lists.newArrayList()); + List proxyList = config.get("proxies", new ArrayList<>()); List proxies = proxyList.stream().map(HostAndPort::fromString).collect(Collectors.toList()); this.apiConnector = plugin.makeApiConnector(ipAddresses, requestLimit, proxies); @@ -170,7 +170,9 @@ public class FastLoginCore

> { Path dataFolder = plugin.getPluginFolder(); try { - Files.createDirectories(dataFolder); + if (Files.notExists(dataFolder)) { + Files.createDirectories(dataFolder); + } Path configFile = dataFolder.resolve(fileName); if (Files.notExists(configFile)) {