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)
|
This plugin adds the support for [Velocity](https://velocitypowered.com/) to [AuthMeReloaded](https://github.com/AuthMe/AuthMeReloaded)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Paper, Airplane or Purpur 1.13+
|
- Paper, Pufferfish or Purpur 1.13+
|
||||||
- Velocity 3.1.2+
|
- Velocity 3.1.2+
|
||||||
- Java 17+
|
- Java 17+
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
1. Download the latest release of the plugin [link](https://github.com/4drian3d/AuthMeVelocity/releases)
|
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.
|
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
|
## Plugin API
|
||||||
Check the plugin API [here](https://github.com/4drian3d/AuthMeVelocity/wiki/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
|
* Obtain the handlerlist of this event
|
||||||
* @return the handlerlist
|
* @return the handlerlist
|
||||||
*/
|
*/
|
||||||
public static HandlerList getHandlerList() {
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ public interface AuthMeVelocityAPI {
|
|||||||
/**
|
/**
|
||||||
* Adds a player to the list of logged in players
|
* Adds a player to the list of logged in players
|
||||||
* @param player the new logged player
|
* @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);
|
boolean addPlayer(@NotNull Player player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a player from the list of logged-in players
|
* Removes a player from the list of logged-in players
|
||||||
* @param player the unlogged player
|
* @param player the unlogged player
|
||||||
* @return if the player was succesfully removed
|
* @return if the player was successfully removed
|
||||||
*/
|
*/
|
||||||
boolean removePlayer(@NotNull Player player);
|
boolean removePlayer(@NotNull Player player);
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ public interface AuthMeVelocityAPI {
|
|||||||
boolean isAuthServer(@NotNull ServerConnection connection);
|
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
|
* @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);
|
boolean isAuthServer(@NotNull String server);
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,5 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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) {}
|
public record ProxyUnregisterEvent(@NotNull Player player) {}
|
||||||
|
@ -30,7 +30,7 @@ public final class ServerResult implements Result {
|
|||||||
* @param server the resulted server
|
* @param server the resulted server
|
||||||
* @return A ServerResult with allowed result and custom server result
|
* @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);
|
return new ServerResult(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public final class ServerResult implements Result {
|
|||||||
*
|
*
|
||||||
* @return A ServerResult with denied result and null server
|
* @return A ServerResult with denied result and null server
|
||||||
*/
|
*/
|
||||||
public static final ServerResult denied() {
|
public static ServerResult denied() {
|
||||||
return DENIED;
|
return DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||||
|
@ -10,9 +10,9 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.spongepowered:configurate-hocon:4.1.2")
|
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.byteflux:libby-core:1.1.5")
|
||||||
compileOnly("net.kyori:adventure-api:4.11.0")
|
compileOnly("net.kyori:adventure-api:4.12.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package me.adrianed.authmevelocity.common.configuration;
|
package me.adrianed.authmevelocity.common.configuration;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
@ -30,16 +29,11 @@ public class ConfigurationContainer<C> {
|
|||||||
return this.safeReload();
|
return this.safeReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValues(Consumer<C> consumer) {
|
|
||||||
consumer.accept(this.config);
|
|
||||||
this.safeReload();
|
|
||||||
}
|
|
||||||
|
|
||||||
public C get() {
|
public C get() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final CompletableFuture<Boolean> safeReload() {
|
private CompletableFuture<Boolean> safeReload() {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
C newConfig = null;
|
C newConfig = null;
|
||||||
try {
|
try {
|
||||||
|
@ -3,5 +3,5 @@ package me.adrianed.authmevelocity.common.enums;
|
|||||||
public enum SendMode {
|
public enum SendMode {
|
||||||
TO_FIRST,
|
TO_FIRST,
|
||||||
TO_EMPTIEST_SERVER,
|
TO_EMPTIEST_SERVER,
|
||||||
RANDOM;
|
RANDOM
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class MessageListener implements PluginMessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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")) {
|
if (!identifier.equals("authmevelocity")) {
|
||||||
plugin.logDebug("PluginMessage | Not AuthMeVelocity identifier");
|
plugin.logDebug("PluginMessage | Not AuthMeVelocity identifier");
|
||||||
return;
|
return;
|
||||||
@ -28,10 +28,11 @@ public class MessageListener implements PluginMessageListener {
|
|||||||
|
|
||||||
plugin.logDebug("PluginMessage | AuthMeVelocity identifier");
|
plugin.logDebug("PluginMessage | AuthMeVelocity identifier");
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
final ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
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");
|
plugin.logDebug("PluginMessage | Main Subchannel");
|
||||||
final String msg = input.readUTF();
|
final String msg = input.readUTF();
|
||||||
if ("LOGIN".equals(msg)) {
|
if ("LOGIN".equals(msg)) {
|
||||||
|
@ -28,6 +28,7 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
|||||||
import net.byteflux.libby.VelocityLibraryManager;
|
import net.byteflux.libby.VelocityLibraryManager;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bstats.velocity.Metrics;
|
import org.bstats.velocity.Metrics;
|
||||||
@ -66,7 +67,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
private final Metrics.Factory metricsFactory;
|
private final Metrics.Factory metricsFactory;
|
||||||
private ConfigurationContainer<ProxyConfiguration> config;
|
private ConfigurationContainer<ProxyConfiguration> config;
|
||||||
|
|
||||||
protected final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
|
final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthMeVelocityPlugin(
|
public AuthMeVelocityPlugin(
|
||||||
@ -123,7 +124,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
this.sendInfoMessage();
|
this.sendInfoMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ProxyServer getProxy(){
|
ProxyServer getProxy(){
|
||||||
return this.proxy;
|
return this.proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,47 +145,47 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogged(Player player){
|
public boolean isLogged(@NotNull Player player){
|
||||||
return loggedPlayers.contains(player.getUniqueId());
|
return loggedPlayers.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNotLogged(Player player){
|
public boolean isNotLogged(@NotNull Player player){
|
||||||
return !loggedPlayers.contains(player.getUniqueId());
|
return !loggedPlayers.contains(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addPlayer(Player player){
|
public boolean addPlayer(@NotNull Player player){
|
||||||
return loggedPlayers.add(player.getUniqueId());
|
return loggedPlayers.add(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removePlayer(Player player){
|
public boolean removePlayer(@NotNull Player player){
|
||||||
return loggedPlayers.remove(player.getUniqueId());
|
return loggedPlayers.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePlayerIf(Predicate<Player> predicate){
|
public void removePlayerIf(@NotNull Predicate<Player> predicate){
|
||||||
loggedPlayers.removeIf(uuid -> predicate.test(getProxy().getPlayer(uuid).orElse(null)));
|
loggedPlayers.removeIf(uuid -> predicate.test(getProxy().getPlayer(uuid).orElse(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInAuthServer(Player player){
|
public boolean isInAuthServer(@NotNull Player player){
|
||||||
return player.getCurrentServer().map(this::isAuthServer).orElse(false);
|
return player.getCurrentServer().map(this::isAuthServer).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthServer(RegisteredServer server){
|
public boolean isAuthServer(@NotNull RegisteredServer server){
|
||||||
return config.get().authServers().contains(server.getServerInfo().getName());
|
return isAuthServer(server.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthServer(ServerConnection connection){
|
public boolean isAuthServer(@NotNull ServerConnection connection){
|
||||||
return config.get().authServers().contains(connection.getServerInfo().getName());
|
return isAuthServer(connection.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthServer(String server){
|
public boolean isAuthServer(@NotNull String server){
|
||||||
return config.get().authServers().contains(server);
|
return config.get().authServers().contains(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|||||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||||
import me.adrianed.authmevelocity.velocity.utils.AuthmeUtils;
|
import me.adrianed.authmevelocity.velocity.utils.AuthmeUtils;
|
||||||
|
|
||||||
public class ConnectListener {
|
public final class ConnectListener {
|
||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final AuthMeVelocityPlugin plugin;
|
private final AuthMeVelocityPlugin plugin;
|
||||||
|
|
||||||
public ConnectListener(AuthMeVelocityPlugin plugin, ProxyServer proxy, Logger logger) {
|
public ConnectListener(AuthMeVelocityPlugin plugin, ProxyServer proxy, Logger logger) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -32,14 +32,14 @@ public class ConnectListener {
|
|||||||
|
|
||||||
@Subscribe(order = PostOrder.LATE)
|
@Subscribe(order = PostOrder.LATE)
|
||||||
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
||||||
if(!plugin.config().get().ensureAuthServer().ensureFirstServerIsAuthServer()) {
|
if (!plugin.config().get().ensureAuthServer().ensureFirstServerIsAuthServer()) {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
plugin.logDebug("PlayerChooseInitialServerEvent | Not enabled");
|
plugin.logDebug("PlayerChooseInitialServerEvent | Not enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<RegisteredServer> optionalSV = event.getInitialServer();
|
Optional<RegisteredServer> optionalSV = event.getInitialServer();
|
||||||
if(optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())){
|
if (optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())){
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server");
|
plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server");
|
||||||
return;
|
return;
|
||||||
@ -66,13 +66,14 @@ public class ConnectListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this should be present, "event.getResult().isAllowed()" is the "isPresent" check
|
// 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");
|
plugin.logDebug("ServerPreConnectEvent | Server is not an auth server");
|
||||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||||
}
|
}
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onServerPostConnect(ServerPostConnectEvent event) {
|
public void onServerPostConnect(ServerPostConnectEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
@ -53,7 +53,7 @@ public class PluginMessageListener {
|
|||||||
|
|
||||||
final ByteArrayDataInput input = event.dataAsDataStream();
|
final ByteArrayDataInput input = event.dataAsDataStream();
|
||||||
final String message = input.readUTF();
|
final String message = input.readUTF();
|
||||||
final MessageType type = MessageType.INDEX.value(
|
final MessageType type = MessageType.INDEX.valueOrThrow(
|
||||||
message.toUpperCase(Locale.ROOT));
|
message.toUpperCase(Locale.ROOT));
|
||||||
final String name = input.readUTF();
|
final String name = input.readUTF();
|
||||||
final @Nullable Player player = proxy.getPlayer(name).orElse(null);
|
final @Nullable Player player = proxy.getPlayer(name).orElse(null);
|
||||||
|
@ -46,7 +46,7 @@ public final class ProxyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (canBeIgnored(player)) {
|
if (canBeIgnored(player)) {
|
||||||
plugin.logDebug("CommandexecuteEvent | Ignored signed player");
|
plugin.logDebug("CommandExecuteEvent | Ignored signed player");
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
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();
|
event.getSuggestions().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user