misc: improved some code quality
This commit is contained in:
parent
bc0ae1e7ad
commit
bf0e7e8aa2
@ -17,14 +17,13 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.api.velocity;
|
package me.adrianed.authmevelocity.api.velocity;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API provided to interact with logged players
|
* API provided to interact with logged players
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public final class PreSendOnLoginEvent implements ResultedEvent<ServerResult> {
|
public final class PreSendOnLoginEvent implements ResultedEvent<ServerResult> {
|
||||||
private ServerResult result;
|
private ServerResult result;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer actualserver;
|
private final RegisteredServer actualServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PreSendOnLoginEvent
|
* Create a new PreSendOnLoginEvent
|
||||||
@ -47,7 +47,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<ServerResult> {
|
|||||||
*/
|
*/
|
||||||
public PreSendOnLoginEvent(@NotNull Player player, @NotNull RegisteredServer actualServer, @NotNull RegisteredServer serverToSend){
|
public PreSendOnLoginEvent(@NotNull Player player, @NotNull RegisteredServer actualServer, @NotNull RegisteredServer serverToSend){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.actualserver = actualServer;
|
this.actualServer = actualServer;
|
||||||
result = ServerResult.allowed(serverToSend);
|
result = ServerResult.allowed(serverToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<ServerResult> {
|
|||||||
* @return the actual server of the player
|
* @return the actual server of the player
|
||||||
*/
|
*/
|
||||||
public @NotNull RegisteredServer actualServer(){
|
public @NotNull RegisteredServer actualServer(){
|
||||||
return this.actualserver;
|
return this.actualServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package me.adrianed.authmevelocity.api.velocity.event;
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**Event executed in case a player is forced unregister by a server operator*/
|
/**Event executed in case a player is forced unregister by a server operator*/
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package me.adrianed.authmevelocity.api.velocity.event;
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package me.adrianed.authmevelocity.api.velocity.event;
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**Event executed in case the player has logout from the network */
|
/**Event executed in case the player has logout from the network */
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package me.adrianed.authmevelocity.api.velocity.event;
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**Event executed in case the player has register itself*/
|
/**Event executed in case the player has register itself*/
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package me.adrianed.authmevelocity.api.velocity.event;
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**Event executed in case the player has unregistered itself*/
|
/**Event executed in case the player has unregistered itself*/
|
||||||
|
@ -20,7 +20,6 @@ allprojects {
|
|||||||
|
|
||||||
tasks.compileJava {
|
tasks.compileJava {
|
||||||
options.encoding = Charsets.UTF_8.name()
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
|
||||||
options.release.set(17)
|
options.release.set(17)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,11 +46,5 @@ tasks {
|
|||||||
build {
|
build {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
|
||||||
options.encoding = Charsets.UTF_8.name()
|
|
||||||
|
|
||||||
options.release.set(17)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +32,17 @@ public final class LibsManager {
|
|||||||
|
|
||||||
public void loadLibraries() {
|
public void loadLibraries() {
|
||||||
final Relocation configurateRelocation
|
final Relocation configurateRelocation
|
||||||
= new Relocation("org{}spongepowered", "me.adrianed.authmevelocity.libs.sponge");
|
= new Relocation(
|
||||||
|
"org{}spongepowered",
|
||||||
|
"me.adrianed.authmevelocity.libs.sponge");
|
||||||
final Relocation geantyrefRelocation =
|
final Relocation geantyrefRelocation =
|
||||||
new Relocation("io{}leangen{}geantyref", "me.adrianed.authmevelocity.libs.geantyref");
|
new Relocation(
|
||||||
|
"io{}leangen{}geantyref",
|
||||||
|
"me.adrianed.authmevelocity.libs.geantyref");
|
||||||
final Relocation typesafeRelocation
|
final Relocation typesafeRelocation
|
||||||
= new Relocation("com{}typesafe", "me.adrianed.authmevelocity.libs.config");
|
= new Relocation(
|
||||||
|
"com{}typesafe",
|
||||||
|
"me.adrianed.authmevelocity.libs.config");
|
||||||
final Library hocon = Library.builder()
|
final Library hocon = Library.builder()
|
||||||
.groupId("org{}spongepowered")
|
.groupId("org{}spongepowered")
|
||||||
.artifactId("configurate-hocon")
|
.artifactId("configurate-hocon")
|
||||||
|
@ -26,8 +26,8 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
|
|||||||
|
|
||||||
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
|
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
|
||||||
|
|
||||||
final class AuthmePlaceholders {
|
final class AuthMePlaceholders {
|
||||||
private AuthmePlaceholders() {}
|
private AuthMePlaceholders() {}
|
||||||
|
|
||||||
static Expansion getExpansion(){
|
static Expansion getExpansion(){
|
||||||
return Expansion.builder("authme")
|
return Expansion.builder("authme")
|
@ -53,12 +53,14 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
final var server = this.getServer();
|
||||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, new MessageListener(this));
|
|
||||||
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
|
||||||
|
|
||||||
if (this.getServer().getPluginManager().isPluginEnabled("MiniPlaceholders")) {
|
server.getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||||
AuthmePlaceholders.getExpansion().register();
|
server.getMessenger().registerIncomingPluginChannel(this, CHANNEL, new MessageListener(this));
|
||||||
|
server.getPluginManager().registerEvents(new AuthMeListener(this), this);
|
||||||
|
|
||||||
|
if (server.getPluginManager().isPluginEnabled("MiniPlaceholders")) {
|
||||||
|
AuthMePlaceholders.getExpansion().register();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLogger().info("AuthMeVelocity enabled");
|
this.getLogger().info("AuthMeVelocity enabled");
|
||||||
@ -72,21 +74,31 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
|||||||
this.getLogger().info("AuthMeVelocity disabled");
|
this.getLogger().info("AuthMeVelocity disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToProxy(final Player player, @NotNull MessageType type, @NotNull String playername) {
|
public void sendMessageToProxy(
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
final Player player,
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
final @NotNull MessageType type,
|
||||||
|
final @NotNull String playername
|
||||||
|
) {
|
||||||
|
@SuppressWarnings("UnstableApiUsage") final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(type.toString());
|
out.writeUTF(type.toString());
|
||||||
out.writeUTF(playername);
|
out.writeUTF(playername);
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
logDebug("MessageToProxy | Null Player, Player Name: "+playername);
|
logDebug("MessageToProxy | Null Player, Player Name: " + playername);
|
||||||
Bukkit.getServer().sendPluginMessage(this, CHANNEL, out.toByteArray());
|
Bukkit.getServer().sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
} else {
|
} else {
|
||||||
logDebug("MessageToProxy | Player Present: "+player.getName()+", Player Name: "+playername);
|
logDebug("MessageToProxy | Player Present: " + player.getName() + ", Player Name: " + playername);
|
||||||
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessageToProxy(
|
||||||
|
final Player player,
|
||||||
|
final @NotNull MessageType type
|
||||||
|
) {
|
||||||
|
sendMessageToProxy(player, type, player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
public void logDebug(String debug) {
|
public void logDebug(String debug) {
|
||||||
if (config.get().debug()) {
|
if (config.get().debug()) {
|
||||||
getLogger().info("[DEBUG] " + debug);
|
getLogger().info("[DEBUG] " + debug);
|
||||||
|
@ -17,16 +17,14 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.paper.listeners;
|
package me.adrianed.authmevelocity.paper.listeners;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.paper.AuthMeVelocityPlugin;
|
|
||||||
import me.adrianed.authmevelocity.common.MessageType;
|
|
||||||
import me.adrianed.authmevelocity.api.paper.event.PreSendLoginEvent;
|
|
||||||
|
|
||||||
import fr.xephi.authme.events.LoginEvent;
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
import fr.xephi.authme.events.LogoutEvent;
|
import fr.xephi.authme.events.LogoutEvent;
|
||||||
import fr.xephi.authme.events.RegisterEvent;
|
import fr.xephi.authme.events.RegisterEvent;
|
||||||
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
||||||
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
||||||
|
import me.adrianed.authmevelocity.api.paper.event.PreSendLoginEvent;
|
||||||
|
import me.adrianed.authmevelocity.common.MessageType;
|
||||||
|
import me.adrianed.authmevelocity.paper.AuthMeVelocityPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -41,7 +39,7 @@ public final class AuthMeListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onLogin(LoginEvent event) {
|
public void onLogin(final LoginEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
plugin.logDebug("LoginEvent | Start");
|
plugin.logDebug("LoginEvent | Start");
|
||||||
|
|
||||||
@ -56,25 +54,25 @@ public final class AuthMeListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRegister(RegisterEvent event) {
|
public void onRegister(final RegisterEvent event) {
|
||||||
plugin.logDebug("RegisterEvent | Executed");
|
plugin.logDebug("RegisterEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogout(LogoutEvent event) {
|
public void onLogout(final LogoutEvent event) {
|
||||||
plugin.logDebug("LogoutEvent | Executed");
|
plugin.logDebug("LogoutEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onUnRegister(UnregisterByPlayerEvent event) {
|
public void onUnRegister(final UnregisterByPlayerEvent event) {
|
||||||
plugin.logDebug("UnregisterByPlayerEvent | Executed");
|
plugin.logDebug("UnregisterByPlayerEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.UNREGISTER, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.UNREGISTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAdminUnRegister(UnregisterByAdminEvent event) {
|
public void onAdminUnRegister(final UnregisterByAdminEvent event) {
|
||||||
plugin.logDebug("UnregisterByAdminEvent | Executed");
|
plugin.logDebug("UnregisterByAdminEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.FORCE_UNREGISTER, event.getPlayerName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.FORCE_UNREGISTER, event.getPlayerName());
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,16 @@ package me.adrianed.authmevelocity.paper.listeners;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||||
|
import me.adrianed.authmevelocity.api.paper.event.LoginByProxyEvent;
|
||||||
import me.adrianed.authmevelocity.common.MessageType;
|
import me.adrianed.authmevelocity.common.MessageType;
|
||||||
|
import me.adrianed.authmevelocity.paper.AuthMeVelocityPlugin;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.api.paper.event.LoginByProxyEvent;
|
public final class MessageListener implements PluginMessageListener {
|
||||||
import me.adrianed.authmevelocity.paper.AuthMeVelocityPlugin;
|
|
||||||
|
|
||||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
|
||||||
|
|
||||||
public class MessageListener implements PluginMessageListener {
|
|
||||||
private final AuthMeVelocityPlugin plugin;
|
private final AuthMeVelocityPlugin plugin;
|
||||||
|
|
||||||
public MessageListener(AuthMeVelocityPlugin plugin) {
|
public MessageListener(AuthMeVelocityPlugin plugin) {
|
||||||
@ -39,7 +36,11 @@ public class MessageListener implements PluginMessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(@NotNull String identifier, @NotNull Player player, byte @NotNull [] bytes) {
|
public void onPluginMessageReceived(
|
||||||
|
final @NotNull String identifier,
|
||||||
|
final @NotNull Player player,
|
||||||
|
final 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;
|
||||||
|
@ -9,7 +9,7 @@ repositories {
|
|||||||
includeGroup("com.github.games647")
|
includeGroup("com.github.games647")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maven("https://repo.alessiodp.com/releases/"){
|
maven("https://repo.alessiodp.com/releases/") {
|
||||||
mavenContent {
|
mavenContent {
|
||||||
includeGroup("net.byteflux")
|
includeGroup("net.byteflux")
|
||||||
}
|
}
|
||||||
|
@ -18,21 +18,22 @@
|
|||||||
package me.adrianed.authmevelocity.velocity;
|
package me.adrianed.authmevelocity.velocity;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
import me.dreamerzero.miniplaceholders.api.Expansion;
|
||||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
|
|
||||||
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
|
import static me.dreamerzero.miniplaceholders.api.utils.Components.FALSE_COMPONENT;
|
||||||
|
import static me.dreamerzero.miniplaceholders.api.utils.Components.TRUE_COMPONENT;
|
||||||
|
|
||||||
final class AuthMePlaceholders {
|
final class AuthMePlaceholders {
|
||||||
private AuthMePlaceholders() {}
|
private AuthMePlaceholders() {
|
||||||
|
}
|
||||||
|
|
||||||
static Expansion getExpansion(AuthMeVelocityPlugin plugin){
|
static Expansion getExpansion(AuthMeVelocityPlugin plugin) {
|
||||||
return Expansion.builder("authme")
|
return Expansion.builder("authme")
|
||||||
.filter(Player.class)
|
.filter(Player.class)
|
||||||
// Logged Placeholders
|
// Logged Placeholders
|
||||||
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
|
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
|
||||||
Tag.selfClosingInserting(plugin.isLogged((Player)aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
|
Tag.selfClosingInserting(plugin.isLogged((Player) aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
|
||||||
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
|
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
|
||||||
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
||||||
return Tag.selfClosingInserting(
|
return Tag.selfClosingInserting(
|
||||||
@ -43,7 +44,7 @@ final class AuthMePlaceholders {
|
|||||||
})
|
})
|
||||||
// In Auth Server placeholders
|
// In Auth Server placeholders
|
||||||
.audiencePlaceholder("in_auth_server", (aud, queue, ctx) ->
|
.audiencePlaceholder("in_auth_server", (aud, queue, ctx) ->
|
||||||
Tag.selfClosingInserting(plugin.isInAuthServer((Player)aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
|
Tag.selfClosingInserting(plugin.isInAuthServer((Player) aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
|
||||||
.globalPlaceholder("player_in_auth_server", (queue, ctx) -> {
|
.globalPlaceholder("player_in_auth_server", (queue, ctx) -> {
|
||||||
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
||||||
return Tag.selfClosingInserting(
|
return Tag.selfClosingInserting(
|
||||||
|
@ -17,50 +17,48 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity;
|
package me.adrianed.authmevelocity.velocity;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.velocity.commands.AuthmeCommand;
|
import com.google.inject.Inject;
|
||||||
import me.adrianed.authmevelocity.velocity.listener.ConnectListener;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import me.adrianed.authmevelocity.velocity.listener.FastLoginListener;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import me.adrianed.authmevelocity.velocity.listener.PluginMessageListener;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import me.adrianed.authmevelocity.velocity.listener.ProxyListener;
|
import com.velocitypowered.api.plugin.Dependency;
|
||||||
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import me.adrianed.authmevelocity.api.velocity.AuthMeVelocityAPI;
|
import me.adrianed.authmevelocity.api.velocity.AuthMeVelocityAPI;
|
||||||
import me.adrianed.authmevelocity.common.Constants;
|
import me.adrianed.authmevelocity.common.Constants;
|
||||||
import me.adrianed.authmevelocity.common.LibsManager;
|
import me.adrianed.authmevelocity.common.LibsManager;
|
||||||
import me.adrianed.authmevelocity.common.configuration.ConfigurationContainer;
|
import me.adrianed.authmevelocity.common.configuration.ConfigurationContainer;
|
||||||
import me.adrianed.authmevelocity.common.configuration.Loader;
|
import me.adrianed.authmevelocity.common.configuration.Loader;
|
||||||
import me.adrianed.authmevelocity.common.configuration.ProxyConfiguration;
|
import me.adrianed.authmevelocity.common.configuration.ProxyConfiguration;
|
||||||
import com.google.inject.Inject;
|
import me.adrianed.authmevelocity.velocity.commands.AuthMeCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import me.adrianed.authmevelocity.velocity.listener.ConnectListener;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import me.adrianed.authmevelocity.velocity.listener.FastLoginListener;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import me.adrianed.authmevelocity.velocity.listener.PluginMessageListener;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import me.adrianed.authmevelocity.velocity.listener.ProxyListener;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
|
||||||
import com.velocitypowered.api.plugin.Dependency;
|
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
|
||||||
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.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bstats.velocity.Metrics;
|
import org.bstats.velocity.Metrics;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
id = "authmevelocity",
|
id = "authmevelocity",
|
||||||
name = "AuthMeVelocity",
|
name = "AuthMeVelocity",
|
||||||
url = "https://github.com/4drian3d/AuthMeVelocity",
|
url = "https://modrinth.com/plugin/authmevelocity",
|
||||||
description = Constants.DESCRIPTION,
|
description = Constants.DESCRIPTION,
|
||||||
version = Constants.VERSION,
|
version = Constants.VERSION,
|
||||||
authors = {"xQuickGlare", "4drian3d"},
|
authors = {"xQuickGlare", "4drian3d"},
|
||||||
@ -78,27 +76,19 @@ import java.util.UUID;
|
|||||||
public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||||
public static final ChannelIdentifier AUTHMEVELOCITY_CHANNEL
|
public static final ChannelIdentifier AUTHMEVELOCITY_CHANNEL
|
||||||
= MinecraftChannelIdentifier.create("authmevelocity", "main");
|
= MinecraftChannelIdentifier.create("authmevelocity", "main");
|
||||||
private final ProxyServer proxy;
|
@Inject
|
||||||
private final Logger logger;
|
private ProxyServer proxy;
|
||||||
private final Path pluginDirectory;
|
@Inject
|
||||||
private final Metrics.Factory metricsFactory;
|
private Logger logger;
|
||||||
|
@Inject
|
||||||
|
@DataDirectory
|
||||||
|
private Path pluginDirectory;
|
||||||
|
@Inject
|
||||||
|
private Metrics.Factory metricsFactory;
|
||||||
private ConfigurationContainer<ProxyConfiguration> config;
|
private ConfigurationContainer<ProxyConfiguration> config;
|
||||||
|
|
||||||
final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
|
final Set<UUID> loggedPlayers = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
@Inject
|
|
||||||
public AuthMeVelocityPlugin(
|
|
||||||
ProxyServer proxy,
|
|
||||||
Logger logger,
|
|
||||||
@DataDirectory Path dataDirectory,
|
|
||||||
Metrics.Factory factory
|
|
||||||
) {
|
|
||||||
this.proxy = proxy;
|
|
||||||
this.logger = logger;
|
|
||||||
this.pluginDirectory = dataDirectory;
|
|
||||||
this.metricsFactory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
final LibsManager libraries
|
final LibsManager libraries
|
||||||
@ -117,7 +107,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
logDebug("Loaded plugin libraries");
|
logDebug("Loaded plugin libraries");
|
||||||
|
|
||||||
final int pluginId = 16128;
|
final int pluginId = 16128;
|
||||||
Metrics metrics = metricsFactory.make(this, pluginId);
|
final Metrics metrics = metricsFactory.make(this, pluginId);
|
||||||
|
|
||||||
proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL);
|
proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL);
|
||||||
|
|
||||||
@ -142,7 +132,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
AuthMePlaceholders.getExpansion(this).register();
|
AuthMePlaceholders.getExpansion(this).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthmeCommand.register(this, proxy.getCommandManager(), logger);
|
AuthMeCommand.register(this, proxy.getCommandManager(), logger);
|
||||||
|
|
||||||
this.sendInfoMessage();
|
this.sendInfoMessage();
|
||||||
}
|
}
|
||||||
@ -152,7 +142,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendInfoMessage() {
|
public void sendInfoMessage() {
|
||||||
CommandSource source = proxy.getConsoleCommandSource();
|
final CommandSource source = proxy.getConsoleCommandSource();
|
||||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||||
" <gray>--- <aqua>AuthMeVelocity</aqua> ---"));
|
" <gray>--- <aqua>AuthMeVelocity</aqua> ---"));
|
||||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 AuthMeVelocity Contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.adrianed.authmevelocity.velocity.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
||||||
|
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class AuthMeCommand {
|
||||||
|
private AuthMeCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(
|
||||||
|
final AuthMeVelocityPlugin plugin,
|
||||||
|
final CommandManager manager,
|
||||||
|
final Logger logger
|
||||||
|
) {
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder.<CommandSource>literal("authmevelocity")
|
||||||
|
.requires(src -> src.hasPermission("authmevelocity.commands"))
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
||||||
|
.executes(cmd -> {
|
||||||
|
final CommandSource source = cmd.getSource();
|
||||||
|
plugin.config().reload().handleAsync((v, ex) -> {
|
||||||
|
if (ex == null) {
|
||||||
|
plugin.sendInfoMessage();
|
||||||
|
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||||
|
"<aqua>AuthmeVelocity <green>has been successfully reloaded"));
|
||||||
|
} else {
|
||||||
|
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||||
|
"<dark_red>There was an error while reloading the configuration. <red>Check the server console"));
|
||||||
|
logger.error(ex.getMessage(), ex.getCause());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
).build();
|
||||||
|
|
||||||
|
final BrigadierCommand brigadier = new BrigadierCommand(command);
|
||||||
|
final CommandMeta meta = manager.metaBuilder(brigadier)
|
||||||
|
.plugin(plugin)
|
||||||
|
.aliases("vauthme", "authmev")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
manager.register(meta, brigadier);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 AuthMeVelocity Contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity.commands;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
|
||||||
import com.velocitypowered.api.command.BrigadierCommand;
|
|
||||||
import com.velocitypowered.api.command.CommandManager;
|
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
public class AuthmeCommand {
|
|
||||||
private AuthmeCommand() {}
|
|
||||||
|
|
||||||
public static void register(AuthMeVelocityPlugin plugin, CommandManager manager, Logger logger) {
|
|
||||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder.<CommandSource>literal("authmevelocity")
|
|
||||||
.requires(src -> src.hasPermission("authmevelocity.commands"))
|
|
||||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
|
||||||
.executes(cmd -> {
|
|
||||||
CommandSource source = cmd.getSource();
|
|
||||||
plugin.config().reload().handleAsync((v, ex) -> {
|
|
||||||
if (ex == null) {
|
|
||||||
plugin.sendInfoMessage();
|
|
||||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
|
||||||
"<aqua>AuthmeVelocity <green>has been successfully reloaded"));
|
|
||||||
} else {
|
|
||||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
|
||||||
"<dark_red>There was an error while reloading the configuration. <red>Check the server console"));
|
|
||||||
logger.error(ex.getMessage(), ex.getCause());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
})
|
|
||||||
).build();
|
|
||||||
|
|
||||||
BrigadierCommand brigadier = new BrigadierCommand(command);
|
|
||||||
CommandMeta meta = manager.metaBuilder(brigadier)
|
|
||||||
.plugin(plugin)
|
|
||||||
.aliases("vauthme", "authmev")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
manager.register(meta, brigadier);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,10 +17,6 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity.listener;
|
package me.adrianed.authmevelocity.velocity.listener;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
@ -32,37 +28,46 @@ import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
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;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public final 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(
|
||||||
|
final AuthMeVelocityPlugin plugin,
|
||||||
|
final ProxyServer proxy,
|
||||||
|
final Logger logger
|
||||||
|
) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LATE)
|
@Subscribe(order = PostOrder.LATE)
|
||||||
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
public void onInitialServer(
|
||||||
|
final 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();
|
final 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;
|
||||||
}
|
}
|
||||||
var config = plugin.config().get();
|
final var config = plugin.config().get();
|
||||||
var server = AuthmeUtils.serverToSend(
|
final var server = AuthmeUtils.serverToSend(
|
||||||
config.ensureAuthServer().sendMode(), proxy, config.authServers(), config.advanced().randomAttempts());
|
config.ensureAuthServer().sendMode(), proxy, config.authServers(), config.advanced().randomAttempts());
|
||||||
|
|
||||||
// Velocity takes over in case the initial server is not present
|
// Velocity takes over in case the initial server is not present
|
||||||
@ -75,7 +80,10 @@ public final class ConnectListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onServerPreConnect(ServerPreConnectEvent event, Continuation continuation) {
|
public void onServerPreConnect(
|
||||||
|
final ServerPreConnectEvent event,
|
||||||
|
final Continuation continuation
|
||||||
|
) {
|
||||||
if (!event.getResult().isAllowed() || plugin.isLogged(event.getPlayer())) {
|
if (!event.getResult().isAllowed() || plugin.isLogged(event.getPlayer())) {
|
||||||
plugin.logDebug("ServerPreConnectEvent | Not allowed or player not logged");
|
plugin.logDebug("ServerPreConnectEvent | Not allowed or player not logged");
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
@ -92,7 +100,7 @@ public final class ConnectListener {
|
|||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onServerPostConnect(ServerPostConnectEvent event) {
|
public void onServerPostConnect(final ServerPostConnectEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (plugin.isLogged(player) && plugin.isInAuthServer(player)) {
|
if (plugin.isLogged(player) && plugin.isInAuthServer(player)) {
|
||||||
plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server");
|
plugin.logDebug("ServerPostConnectEvent | Already logged player and connected to an Auth server");
|
||||||
|
@ -20,7 +20,6 @@ package me.adrianed.authmevelocity.velocity.listener;
|
|||||||
import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEvent;
|
import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEvent;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||||
|
|
||||||
public class FastLoginListener {
|
public class FastLoginListener {
|
||||||
|
@ -17,15 +17,6 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity.listener;
|
package me.adrianed.authmevelocity.velocity.listener;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.PreSendOnLoginEvent;
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyForcedUnregisterEvent;
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyLoginEvent;
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyLogoutEvent;
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyRegisterEvent;
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyUnregisterEvent;
|
|
||||||
import me.adrianed.authmevelocity.common.MessageType;
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
@ -34,14 +25,16 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import me.adrianed.authmevelocity.api.velocity.event.*;
|
||||||
|
import me.adrianed.authmevelocity.common.MessageType;
|
||||||
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;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class PluginMessageListener {
|
public class PluginMessageListener {
|
||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
@ -80,7 +73,9 @@ public class PluginMessageListener {
|
|||||||
plugin.logDebug("PluginMessageEvent | Login type");
|
plugin.logDebug("PluginMessageEvent | Login type");
|
||||||
if (player != null && plugin.addPlayer(player)) {
|
if (player != null && plugin.addPlayer(player)) {
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(player));
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(player));
|
||||||
|
if (plugin.config().get().sendOnLogin().sendToServerOnLogin()) {
|
||||||
this.createServerConnectionRequest(player, connection);
|
this.createServerConnectionRequest(player, connection);
|
||||||
|
}
|
||||||
plugin.logDebug("PluginMessageEvent | Player not null");
|
plugin.logDebug("PluginMessageEvent | Player not null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,15 +110,11 @@ public class PluginMessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createServerConnectionRequest(Player player, ServerConnection connection){
|
private void createServerConnectionRequest(Player player, ServerConnection connection){
|
||||||
if (!plugin.config().get().sendOnLogin().sendToServerOnLogin()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final RegisteredServer loginServer = player.getCurrentServer().orElse(connection).getServer();
|
final RegisteredServer loginServer = player.getCurrentServer().orElse(connection).getServer();
|
||||||
|
|
||||||
var config = plugin.config().get();
|
final var config = plugin.config().get();
|
||||||
|
|
||||||
var toSend = AuthmeUtils.serverToSend(
|
final var toSend = AuthmeUtils.serverToSend(
|
||||||
config.sendOnLogin().sendMode(), proxy, config.sendOnLogin().teleportServers(), config.advanced().randomAttempts());
|
config.sendOnLogin().sendMode(), proxy, config.sendOnLogin().teleportServers(), config.advanced().randomAttempts());
|
||||||
|
|
||||||
if (toSend.isEmpty()) {
|
if (toSend.isEmpty()) {
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity.listener;
|
package me.adrianed.authmevelocity.velocity.listener;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.velocity.utils.AuthmeUtils;
|
|
||||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.EventTask;
|
import com.velocitypowered.api.event.EventTask;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
@ -29,7 +27,8 @@ import com.velocitypowered.api.event.player.PlayerChatEvent;
|
|||||||
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||||
|
import me.adrianed.authmevelocity.velocity.utils.AuthmeUtils;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
public final class ProxyListener {
|
public final class ProxyListener {
|
||||||
|
@ -17,18 +17,16 @@
|
|||||||
|
|
||||||
package me.adrianed.authmevelocity.velocity.utils;
|
package me.adrianed.authmevelocity.velocity.utils;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import me.adrianed.authmevelocity.common.enums.SendMode;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.common.enums.SendMode;
|
|
||||||
|
|
||||||
public class AuthmeUtils {
|
public class AuthmeUtils {
|
||||||
//Origin: https://github.com/4drian3d/ChatRegulator/blob/main/src/main/java/me/dreamerzero/chatregulator/utils/CommandUtils.java#L71
|
//Origin: https://github.com/4drian3d/ChatRegulator/blob/main/src/main/java/me/dreamerzero/chatregulator/utils/CommandUtils.java#L71
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user