misc: Some code cleanup
This commit is contained in:
parent
017e698460
commit
6ff28248c9
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
|
@ -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 {
|
||||
|
@ -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<C> {
|
||||
return this.safeReload();
|
||||
}
|
||||
|
||||
public void setValues(Consumer<C> consumer) {
|
||||
consumer.accept(this.config);
|
||||
this.safeReload();
|
||||
}
|
||||
|
||||
public C get() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
private final CompletableFuture<Boolean> safeReload() {
|
||||
private CompletableFuture<Boolean> safeReload() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
C newConfig = null;
|
||||
try {
|
||||
|
@ -3,5 +3,5 @@ package me.adrianed.authmevelocity.common.enums;
|
||||
public enum SendMode {
|
||||
TO_FIRST,
|
||||
TO_EMPTIEST_SERVER,
|
||||
RANDOM;
|
||||
RANDOM
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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<ProxyConfiguration> config;
|
||||
|
||||
protected final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
|
||||
final Set<UUID> 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<Player> predicate){
|
||||
public void removePlayerIf(@NotNull Predicate<Player> 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);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ 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;
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user