From 18bd778b7e7703cfaa8613a943ef5cd28f61d1b2 Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 9 Jun 2022 12:04:42 +0200 Subject: [PATCH] General minor code clean up and typo fixes --- .github/ISSUE_TEMPLATE/bug_report.yaml | 1 - README.md | 2 +- .../games647/fastlogin/bukkit/FastLoginBukkit.java | 2 +- .../fastlogin/bukkit/command/ToggleCommand.java | 2 +- .../games647/fastlogin/core/AsyncScheduler.java | 11 ----------- .../games647/fastlogin/core/StoredProfile.java | 3 +-- .../fastlogin/core/message/LoginActionMessage.java | 2 +- .../fastlogin/core/shared/FastLoginCore.java | 1 - .../fastlogin/core/shared/FloodgateManagement.java | 14 +++++++------- .../fastlogin/core/shared/JoinManagement.java | 2 +- .../fastlogin/core/shared/LoginSession.java | 3 +-- .../fastlogin/core/shared/PlatformPlugin.java | 4 ++-- .../fastlogin/core/storage/MySQLStorage.java | 4 ++-- core/src/main/resources/config.yml | 2 +- core/src/main/resources/messages.yml | 2 +- pom.xml | 2 +- velocity/pom.xml | 2 +- .../velocity/listener/PluginMessageListener.java | 5 +++-- .../fastlogin/velocity/task/ForceLoginTask.java | 2 +- 19 files changed, 26 insertions(+), 40 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 202c2dc3..ec8d48bc 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -36,7 +36,6 @@ body: attributes: label: Server log description: The error, stacktrace or link the complete log. You can use the links above for long versions. - render: shell placeholder: https://hastebin.com/ / https://gist.github.com/ - type: input attributes: diff --git a/README.md b/README.md index 8415d53d..82ddf833 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,6 @@ Install the plugin on both platforms, that is proxy (BungeeCord or Velocity) and * MySQL/MariaDB requires an external database server running. Check your server provider if there is one available or install one. 6. Set proxy and Spigot in offline mode by setting the value `onlinemode` in your `config.yml` to false -7. You should *always* firewall your Spigot server that it's only accessible through your proxy +7. You should *always* configure the firewall for your Spigot server so that it's only accessible through your proxy * This is also the case without this plugin * https://www.spigotmc.org/wiki/bungeecord-installation/#post-installation 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 a0aeedc5..ab4ceed1 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 @@ -124,7 +124,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin optPlayer = Bukkit.getServer().getOnlinePlayers().stream().findFirst(); - if (!optPlayer.isPresent()) { + if (optPlayer.isEmpty()) { plugin.getLog().info("No player online to send a plugin message to the proxy"); return; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AsyncScheduler.java b/core/src/main/java/com/github/games647/fastlogin/core/AsyncScheduler.java index 595b1714..d5ebe1a0 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AsyncScheduler.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AsyncScheduler.java @@ -52,12 +52,6 @@ public class AsyncScheduler { private final AtomicInteger currentlyRunning = new AtomicInteger(); - /* - private final ExecutorService databaseExecutor = new ThreadPoolExecutor(1, 10, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue<>(MAX_CAPACITY)); - */ - public AsyncScheduler(Logger logger, Executor processingPool) { this.logger = logger; this.processingPool = processingPool; @@ -76,9 +70,4 @@ public class AsyncScheduler { return null; }); } - - public void shutdown() { - // MoreExecutors.shutdownAndAwaitTermination(processingPool, 1, TimeUnit.MINUTES); - //MoreExecutors.shutdownAndAwaitTermination(databaseExecutor, 1, TimeUnit.MINUTES); - } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java index abbcca27..9757eb50 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java @@ -115,9 +115,8 @@ public class StoredProfile extends Profile { @Override public synchronized boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof StoredProfile)) return false; + if (!(o instanceof StoredProfile that)) return false; if (!super.equals(o)) return false; - StoredProfile that = (StoredProfile) o; return rowId == that.rowId && premium == that.premium && Objects.equals(lastIp, that.lastIp) && lastLogin.equals(that.lastLogin); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java b/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java index bbac44b9..cc533eed 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java @@ -80,7 +80,7 @@ public class LoginActionMessage implements ChannelMessage { //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target output.writeUTF(playerName); - //proxy identifier to check if it's a acceptable proxy + //proxy identifier to check if it's an acceptable proxy output.writeLong(proxyId.getMostSignificantBits()); output.writeLong(proxyId.getLeastSignificantBits()); } 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 a5723bf4..0a89d7f4 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 @@ -312,7 +312,6 @@ public class FastLoginCore

> { public void close() { plugin.getLog().info("Safely shutting down scheduler. This could take up to one minute."); - plugin.getScheduler().shutdown(); if (storage != null) { storage.close(); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FloodgateManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FloodgateManagement.java index 6b63aa20..a7d6d8c6 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FloodgateManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FloodgateManagement.java @@ -50,7 +50,7 @@ public abstract class FloodgateManagement

premiumUUID = Optional.empty(); + Optional premiumUUID; try { premiumUUID = core.getResolver().findProfile(username); } catch (IOException | RateLimitException e) { @@ -138,7 +138,7 @@ public abstract class FloodgateManagement

* The config option 'non-conflicting' is ignored by this function, as name * conflicts are checked by a different part of the code. - * + * * @param configValue the value of either 'autoLoginFloodgate' or * 'autoRegisterFloodgate' from config.yml * @return true if the Player can be registered automatically @@ -150,14 +150,14 @@ public abstract class FloodgateManagement

{ premiumUUID = core.getResolver().findProfile(username); } - if (!premiumUUID.isPresent() + if (premiumUUID.isEmpty() || (!checkNameChange(source, username, premiumUUID.get()) && !checkPremiumName(source, username, profile))) { //nothing detected the player as premium -> start a cracked session diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java index 7eecaa18..33b5ff5c 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java @@ -27,7 +27,6 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.StoredProfile; import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; import java.util.UUID; @@ -35,7 +34,7 @@ public abstract class LoginSession { private final StoredProfile profile; - private String requestUsername; + private final String requestUsername; private String username; private UUID uuid; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java index ec368171..4c436ed6 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/PlatformPlugin.java @@ -59,8 +59,8 @@ public interface PlatformPlugin { default ThreadFactory getThreadFactory() { return new ThreadFactoryBuilder() .setNameFormat(getName() + " Pool Thread #%1$d") - // Hikari create daemons by default and we could daemon threads for our own scheduler too - // because we safely shutdown + // Hikari create daemons by default. We could daemon threads for our own scheduler too + // because we safely shut down .setDaemon(true) .build(); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java index b408007d..d3a3cd40 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java @@ -52,7 +52,7 @@ public class MySQLStorage extends SQLStorage { config.addDataSourceProperty("useSSL", useSSL); config.addDataSourceProperty("requireSSL", useSSL); - // adding paranoid hides hostname, username, version and so + // adding paranoid, hides hostname, username, version and so // could be useful for hiding server details config.addDataSourceProperty("paranoid", true); @@ -86,7 +86,7 @@ public class MySQLStorage extends SQLStorage { config.addDataSourceProperty("elideSetAutoCommits", true); // default true - internal timers for idle calculation -> removes System.getCurrentTimeMillis call per query - // Some platforms are slow on this and it could affect the throughput about 3% according to MySQL + // Some platforms are slow on this, it could affect the throughput about 3% according to MySQL // performance gems presentation // In our case it can be useful to see the time in error messages // config.addDataSourceProperty("maintainTimeStats", false); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 5bec5b88..1b0905d6 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -278,7 +278,7 @@ driver: 'org.sqlite.JDBC' database: '{pluginDir}/FastLogin.db' # MySQL/MariaDB -# If you want to enable it uncomment only the lines below this not this line. +# If you want to enable it, uncomment only the lines below; this not this line. # If on velocity use 'fastlogin.mariadb.jdbc.Driver' as driver #driver: 'com.mysql.jdbc.Driver' #host: '127.0.0.1' diff --git a/core/src/main/resources/messages.yml b/core/src/main/resources/messages.yml index f000fb39..8b315baa 100644 --- a/core/src/main/resources/messages.yml +++ b/core/src/main/resources/messages.yml @@ -90,7 +90,7 @@ invalid-request: '&4Invalid request' not-started: '&cServer is not fully started yet. Please retry' # Warning message if a user invoked /premium command -premium-warning: '&c&lWARNING: &6This command should &lonly&6 be invoked if you are the owner of this paid Minecraft account +premium-warning: '&c&lWARNING: &6This command should&l only&6 be invoked if you are the owner of this paid Minecraft account Type &a/premium&6 again to confirm' # ========= Bungee/Waterfall only ================================ diff --git a/pom.xml b/pom.xml index 899c2693..3fc975cb 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ Unknown - 1.8 + 1.17 ${java.version} ${java.version} diff --git a/velocity/pom.xml b/velocity/pom.xml index b4b0bcfb..4bd22364 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -36,7 +36,7 @@ ../pom.xml - + fastlogin.velocity jar diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java index 4f009d33..cdef0c2b 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java @@ -40,10 +40,11 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Arrays; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + public class PluginMessageListener { private final FastLoginVelocity plugin; @@ -66,7 +67,7 @@ public class PluginMessageListener { } //the client shouldn't be able to read the messages in order to know something about server internal states - //moreover the client shouldn't be able fake a running premium check by sending the result message + //moreover the client shouldn't be able to fake a running premium check by sending the result message pluginMessageEvent.setResult(PluginMessageEvent.ForwardResult.handled()); if (!(pluginMessageEvent.getSource() instanceof ServerConnection)) { diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java index aa56a23c..df5c4338 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -49,7 +49,7 @@ public class ForceLoginTask private final RegisteredServer server; //treat player as if they had a premium account, even when they don't - //used for Floodgate auto login/register + //used to do auto login for Floodgate aut private final boolean forcedOnlineMode; public ForceLoginTask(FastLoginCore core,