diff --git a/README.md b/README.md index 2b58179..5a61ea8 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ This plugin adds the support for [Velocity](https://velocitypowered.com/) to [AuthMeReloaded](https://github.com/AuthMe/AuthMeReloaded) ## Requirements -- Paper, Airplane or Purpur 1.13+ +- Paper, Pufferfish or Purpur 1.13+ - Velocity 3.1.2+ - Java 17+ ## Setup 1. Download the latest release of the plugin [link](https://github.com/4drian3d/AuthMeVelocity/releases) 2. Put the plugin in the Velocity plugins folder and on all your Auth servers that have AuthMe installed. -4. Start the Velocity proxy and set up the config.conf with the auth servers. +3. Start the Velocity proxy and set up the config.conf with the auth servers. ## Plugin API Check the plugin API [here](https://github.com/4drian3d/AuthMeVelocity/wiki/Plugin-API) diff --git a/api/paper/src/main/java/me/adrianed/authmevelocity/api/paper/event/PreSendLoginEvent.java b/api/paper/src/main/java/me/adrianed/authmevelocity/api/paper/event/PreSendLoginEvent.java index ba8bfff..9651be9 100644 --- a/api/paper/src/main/java/me/adrianed/authmevelocity/api/paper/event/PreSendLoginEvent.java +++ b/api/paper/src/main/java/me/adrianed/authmevelocity/api/paper/event/PreSendLoginEvent.java @@ -42,7 +42,7 @@ public final class PreSendLoginEvent extends PlayerEvent implements Cancellable * Obtain the handlerlist of this event * @return the handlerlist */ - public static HandlerList getHandlerList() { + public static @NotNull HandlerList getHandlerList() { return HANDLERS; } } diff --git a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/AuthMeVelocityAPI.java b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/AuthMeVelocityAPI.java index 5c0bb10..f049a4c 100644 --- a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/AuthMeVelocityAPI.java +++ b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/AuthMeVelocityAPI.java @@ -30,14 +30,14 @@ public interface AuthMeVelocityAPI { /** * Adds a player to the list of logged in players * @param player the new logged player - * @return if the player was succesfully added + * @return if the player was successfully added */ boolean addPlayer(@NotNull Player player); /** * Removes a player from the list of logged-in players * @param player the unlogged player - * @return if the player was succesfully removed + * @return if the player was successfully removed */ boolean removePlayer(@NotNull Player player); @@ -69,9 +69,9 @@ public interface AuthMeVelocityAPI { boolean isAuthServer(@NotNull ServerConnection connection); /** - * Checks if a string is an name of an auth server + * Checks if a string is a name of an auth server * @param server the server name - * @return if the server is an auth serverr + * @return if the server is an auth server */ boolean isAuthServer(@NotNull String server); } diff --git a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ProxyUnregisterEvent.java b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ProxyUnregisterEvent.java index acbdab0..164ee8a 100644 --- a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ProxyUnregisterEvent.java +++ b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ProxyUnregisterEvent.java @@ -4,5 +4,5 @@ import com.velocitypowered.api.proxy.Player; import org.jetbrains.annotations.NotNull; -/**Event executed in case the player has unregister itself*/ +/**Event executed in case the player has unregistered itself*/ public record ProxyUnregisterEvent(@NotNull Player player) {} diff --git a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ServerResult.java b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ServerResult.java index c69f2d2..b9abf50 100644 --- a/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ServerResult.java +++ b/api/velocity/src/main/java/me/adrianed/authmevelocity/api/velocity/event/ServerResult.java @@ -30,7 +30,7 @@ public final class ServerResult implements Result { * @param server the resulted server * @return A ServerResult with allowed result and custom server result */ - public static final ServerResult allowed(RegisteredServer server) { + public static ServerResult allowed(RegisteredServer server) { return new ServerResult(server); } @@ -39,7 +39,7 @@ public final class ServerResult implements Result { * * @return A ServerResult with denied result and null server */ - public static final ServerResult denied() { + public static ServerResult denied() { return DENIED; } diff --git a/build.gradle.kts b/build.gradle.kts index 4a63c67..117990c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - plugins { java id("com.github.johnrengelman.shadow") version "7.1.2" diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 8d3c912..bd15c2a 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -10,9 +10,9 @@ repositories { dependencies { compileOnly("org.spongepowered:configurate-hocon:4.1.2") - compileOnly("org.slf4j:slf4j-api:2.0.4") + compileOnly("org.slf4j:slf4j-api:2.0.5") compileOnly("net.byteflux:libby-core:1.1.5") - compileOnly("net.kyori:adventure-api:4.11.0") + compileOnly("net.kyori:adventure-api:4.12.0") } tasks { diff --git a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ConfigurationContainer.java b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ConfigurationContainer.java index 5315f53..f9766cb 100644 --- a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ConfigurationContainer.java +++ b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ConfigurationContainer.java @@ -1,7 +1,6 @@ package me.adrianed.authmevelocity.common.configuration; import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; import org.slf4j.Logger; import org.spongepowered.configurate.CommentedConfigurationNode; @@ -30,16 +29,11 @@ public class ConfigurationContainer { return this.safeReload(); } - public void setValues(Consumer consumer) { - consumer.accept(this.config); - this.safeReload(); - } - public C get() { return this.config; } - private final CompletableFuture safeReload() { + private CompletableFuture safeReload() { return CompletableFuture.supplyAsync(() -> { C newConfig = null; try { diff --git a/common/src/main/java/me/adrianed/authmevelocity/common/enums/SendMode.java b/common/src/main/java/me/adrianed/authmevelocity/common/enums/SendMode.java index ee77c16..541510c 100644 --- a/common/src/main/java/me/adrianed/authmevelocity/common/enums/SendMode.java +++ b/common/src/main/java/me/adrianed/authmevelocity/common/enums/SendMode.java @@ -3,5 +3,5 @@ package me.adrianed.authmevelocity.common.enums; public enum SendMode { TO_FIRST, TO_EMPTIEST_SERVER, - RANDOM; + RANDOM } diff --git a/paper/src/main/java/me/adrianed/authmevelocity/paper/listeners/MessageListener.java b/paper/src/main/java/me/adrianed/authmevelocity/paper/listeners/MessageListener.java index faef963..e3cb38a 100644 --- a/paper/src/main/java/me/adrianed/authmevelocity/paper/listeners/MessageListener.java +++ b/paper/src/main/java/me/adrianed/authmevelocity/paper/listeners/MessageListener.java @@ -20,7 +20,7 @@ public class MessageListener implements PluginMessageListener { } @Override - public void onPluginMessageReceived(@NotNull String identifier, @NotNull Player player, @NotNull byte[] bytes) { + public void onPluginMessageReceived(@NotNull String identifier, @NotNull Player player, byte @NotNull [] bytes) { if (!identifier.equals("authmevelocity")) { plugin.logDebug("PluginMessage | Not AuthMeVelocity identifier"); return; @@ -28,10 +28,11 @@ public class MessageListener implements PluginMessageListener { plugin.logDebug("PluginMessage | AuthMeVelocity identifier"); + @SuppressWarnings("UnstableApiUsage") final ByteArrayDataInput input = ByteStreams.newDataInput(bytes); - final String subchannel = input.readUTF(); + final String subChannel = input.readUTF(); - if ("main".equals(subchannel)) { + if ("main".equals(subChannel)) { plugin.logDebug("PluginMessage | Main Subchannel"); final String msg = input.readUTF(); if ("LOGIN".equals(msg)) { diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java index 9d56d6a..a9b98ad 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java @@ -28,6 +28,7 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import net.byteflux.libby.VelocityLibraryManager; import net.kyori.adventure.text.minimessage.MiniMessage; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.bstats.charts.SimplePie; import org.bstats.velocity.Metrics; @@ -66,7 +67,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { private final Metrics.Factory metricsFactory; private ConfigurationContainer config; - protected final Set loggedPlayers = ConcurrentHashMap.newKeySet(); + final Set loggedPlayers = ConcurrentHashMap.newKeySet(); @Inject public AuthMeVelocityPlugin( @@ -123,7 +124,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { this.sendInfoMessage(); } - protected ProxyServer getProxy(){ + ProxyServer getProxy(){ return this.proxy; } @@ -144,47 +145,47 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { } @Override - public boolean isLogged(Player player){ + public boolean isLogged(@NotNull Player player){ return loggedPlayers.contains(player.getUniqueId()); } @Override - public boolean isNotLogged(Player player){ + public boolean isNotLogged(@NotNull Player player){ return !loggedPlayers.contains(player.getUniqueId()); } @Override - public boolean addPlayer(Player player){ + public boolean addPlayer(@NotNull Player player){ return loggedPlayers.add(player.getUniqueId()); } @Override - public boolean removePlayer(Player player){ + public boolean removePlayer(@NotNull Player player){ return loggedPlayers.remove(player.getUniqueId()); } @Override - public void removePlayerIf(Predicate predicate){ + public void removePlayerIf(@NotNull Predicate predicate){ loggedPlayers.removeIf(uuid -> predicate.test(getProxy().getPlayer(uuid).orElse(null))); } @Override - public boolean isInAuthServer(Player player){ + public boolean isInAuthServer(@NotNull Player player){ return player.getCurrentServer().map(this::isAuthServer).orElse(false); } @Override - public boolean isAuthServer(RegisteredServer server){ - return config.get().authServers().contains(server.getServerInfo().getName()); + public boolean isAuthServer(@NotNull RegisteredServer server){ + return isAuthServer(server.getServerInfo().getName()); } @Override - public boolean isAuthServer(ServerConnection connection){ - return config.get().authServers().contains(connection.getServerInfo().getName()); + public boolean isAuthServer(@NotNull ServerConnection connection){ + return isAuthServer(connection.getServerInfo().getName()); } @Override - public boolean isAuthServer(String server){ + public boolean isAuthServer(@NotNull String server){ return config.get().authServers().contains(server); } diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java index 6eef772..9567813 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java @@ -19,11 +19,11 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin; import me.adrianed.authmevelocity.velocity.utils.AuthmeUtils; -public class ConnectListener { +public final class ConnectListener { private final ProxyServer proxy; private final Logger logger; private final AuthMeVelocityPlugin plugin; - + public ConnectListener(AuthMeVelocityPlugin plugin, ProxyServer proxy, Logger logger) { this.plugin = plugin; this.logger = logger; @@ -32,14 +32,14 @@ public class ConnectListener { @Subscribe(order = PostOrder.LATE) public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){ - if(!plugin.config().get().ensureAuthServer().ensureFirstServerIsAuthServer()) { + if (!plugin.config().get().ensureAuthServer().ensureFirstServerIsAuthServer()) { continuation.resume(); plugin.logDebug("PlayerChooseInitialServerEvent | Not enabled"); return; } Optional optionalSV = event.getInitialServer(); - if(optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())){ + if (optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())){ continuation.resume(); plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server"); return; @@ -66,13 +66,14 @@ public class ConnectListener { } // this should be present, "event.getResult().isAllowed()" is the "isPresent" check - if(!plugin.isAuthServer(event.getResult().getServer().orElse(null))) { + if (!plugin.isAuthServer(event.getResult().getServer().orElseThrow())) { plugin.logDebug("ServerPreConnectEvent | Server is not an auth server"); event.setResult(ServerPreConnectEvent.ServerResult.denied()); } continuation.resume(); } + @SuppressWarnings("UnstableApiUsage") @Subscribe public void onServerPostConnect(ServerPostConnectEvent event) { final Player player = event.getPlayer(); diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java index 6d43f23..f7c3618 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java @@ -53,7 +53,7 @@ public class PluginMessageListener { final ByteArrayDataInput input = event.dataAsDataStream(); final String message = input.readUTF(); - final MessageType type = MessageType.INDEX.value( + final MessageType type = MessageType.INDEX.valueOrThrow( message.toUpperCase(Locale.ROOT)); final String name = input.readUTF(); final @Nullable Player player = proxy.getPlayer(name).orElse(null); diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java index 7242663..c04c1b4 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java @@ -46,7 +46,7 @@ public final class ProxyListener { } if (canBeIgnored(player)) { - plugin.logDebug("CommandexecuteEvent | Ignored signed player"); + plugin.logDebug("CommandExecuteEvent | Ignored signed player"); continuation.resume(); return; } @@ -101,7 +101,7 @@ public final class ProxyListener { } } - plugin.logDebug("TabCompleteEvent | Not allowed tabcompletion"); + plugin.logDebug("TabCompleteEvent | Not allowed tab-completion"); event.getSuggestions().clear(); }