Merge pull request #15 from 4drian3d/configurate
Migration to Configurate and more
This commit is contained in:
commit
d32c1ae224
38
pom.xml
38
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>16</maven.compiler.source>
|
<maven.compiler.source>16</maven.compiler.source>
|
||||||
@ -38,42 +38,6 @@
|
|||||||
<target>16</target>
|
<target>16</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.3.1-SNAPSHOT</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>de.leonhard</pattern>
|
|
||||||
<shadedPattern>com.glyart.authmevelocity.libs.simplixstorage</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/maven/</exclude>
|
|
||||||
<exclude>META-INF/*.MF</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -39,10 +39,9 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.simplix-softworks</groupId>
|
<groupId>org.spongepowered</groupId>
|
||||||
<artifactId>SimplixStorage</artifactId>
|
<artifactId>configurate-hocon</artifactId>
|
||||||
<version>3.2.3</version>
|
<version>4.1.2</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.games647</groupId>
|
<groupId>com.github.games647</groupId>
|
||||||
@ -59,6 +58,42 @@
|
|||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.1-SNAPSHOT</version>
|
<version>3.2.1-SNAPSHOT</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.3.1-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<minimizeJar>true</minimizeJar>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.spongepowered</pattern>
|
||||||
|
<shadedPattern>com.glyart.authmevelocity.libs.configurate</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/maven/</exclude>
|
||||||
|
<exclude>META-INF/*.MF</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -6,28 +6,31 @@ import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import de.leonhard.storage.Yaml;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class AuthMeVelocityPlugin {
|
public class AuthMeVelocityPlugin {
|
||||||
private static ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private static Yaml config = new Yaml("config", "plugins/AuthmeVelocity");
|
private final Path pluginDirectory;
|
||||||
|
private static AuthMeVelocityPlugin plugin;
|
||||||
|
|
||||||
protected static final Set<UUID> loggedPlayers = Collections.synchronizedSet(new HashSet<UUID>());
|
protected static final Set<UUID> loggedPlayers = Collections.synchronizedSet(new HashSet<UUID>());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthMeVelocityPlugin(ProxyServer server, Logger logger) {
|
public AuthMeVelocityPlugin(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
|
||||||
proxy = server;
|
plugin = this;
|
||||||
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.pluginDirectory = dataDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -38,19 +41,20 @@ public class AuthMeVelocityPlugin {
|
|||||||
if(proxy.getPluginManager().getPlugin("fastlogin").isPresent()){
|
if(proxy.getPluginManager().getPlugin("fastlogin").isPresent()){
|
||||||
proxy.getEventManager().register(this, new FastLoginListener(proxy));
|
proxy.getEventManager().register(this, new FastLoginListener(proxy));
|
||||||
}
|
}
|
||||||
AuthMeConfig.defaultConfig();
|
AuthMeConfig.loadConfig(pluginDirectory, logger);
|
||||||
logger.info("-- AuthMeVelocity enabled --");
|
logger.info("-- AuthMeVelocity enabled --");
|
||||||
logger.info("AuthServers: " + config.getList("authservers"));
|
var config = AuthMeConfig.getConfig();
|
||||||
if(config.getBoolean("teleport.send-to-server-after-login")){
|
logger.info("AuthServers: {}", config.getAuthServers());
|
||||||
logger.info("LobbyServers: " + config.getList("teleport.servers"));
|
if(config.getToServerOptions().sendToServer()){
|
||||||
|
logger.info("LobbyServers: {}", config.getToServerOptions().getTeleportServers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Yaml getConfig(){
|
protected ProxyServer getProxy(){
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static ProxyServer getProxy(){
|
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AuthMeVelocityPlugin getInstance(){
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,15 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class AuthmeVelocityAPI {
|
public class AuthmeVelocityAPI {
|
||||||
/**
|
/**
|
||||||
* Check if the player is logged in or not
|
* Check if the player is logged in or not
|
||||||
* @param player the player
|
* @param player the player
|
||||||
* @return if the player is logged in or not
|
* @return if the player is logged in or not
|
||||||
*/
|
*/
|
||||||
public static boolean isLogged(Player player){
|
public static boolean isLogged(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
return AuthMeVelocityPlugin.loggedPlayers.contains(playerUUID);
|
return AuthMeVelocityPlugin.loggedPlayers.contains(playerUUID);
|
||||||
}
|
}
|
||||||
@ -19,33 +21,33 @@ public class 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
|
||||||
*/
|
*/
|
||||||
public static void addPlayer(Player player){
|
public static boolean addPlayer(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
if(!AuthmeVelocityAPI.isLogged(player)){
|
return AuthMeVelocityPlugin.loggedPlayers.add(playerUUID);
|
||||||
AuthMeVelocityPlugin.loggedPlayers.add(playerUUID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
public static void removePlayer(Player player){
|
public static boolean removePlayer(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
if(AuthmeVelocityAPI.isLogged(player)){
|
return AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
|
||||||
AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes players who meet the established condition
|
* Removes players who meet the established condition
|
||||||
* @param predicate the condition
|
* @param predicate the condition
|
||||||
*/
|
*/
|
||||||
public static void removePlayerIf(Predicate<Player> predicate){
|
public static void removePlayerIf(@NotNull Predicate<Player> predicate){
|
||||||
AuthMeVelocityPlugin.loggedPlayers.stream()
|
AuthMeVelocityPlugin.loggedPlayers.stream()
|
||||||
.map(uuid -> AuthMeVelocityPlugin.getProxy().getPlayer(uuid).orElse(null))
|
.map(uuid -> AuthMeVelocityPlugin.getInstance().getProxy().getPlayer(uuid).orElseThrow())
|
||||||
.filter(predicate)
|
.filter(predicate)
|
||||||
.forEach(player -> AuthMeVelocityPlugin.loggedPlayers.remove(player.getUniqueId()));
|
.forEach(player -> AuthMeVelocityPlugin.loggedPlayers.remove(player.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AuthmeVelocityAPI(){}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,90 @@
|
|||||||
package com.glyart.authmevelocity.proxy.config;
|
package com.glyart.authmevelocity.proxy.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
|
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||||
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
import de.leonhard.storage.Yaml;
|
public class AuthMeConfig {
|
||||||
|
private static final String HEADER = """
|
||||||
|
AuthmeVelocity Proxy
|
||||||
|
|
||||||
public interface AuthMeConfig {
|
Original Developer: xQuickGlare
|
||||||
public static void defaultConfig(){
|
Actual Developer: 4drian3d
|
||||||
Yaml config = AuthMeVelocityPlugin.getConfig();
|
""";
|
||||||
config.setDefault(
|
private static final HoconConfigurationLoader.Builder configBuilder = HoconConfigurationLoader.builder()
|
||||||
"authservers",
|
.defaultOptions(opts -> opts
|
||||||
List.of(
|
.shouldCopyDefaults(true)
|
||||||
|
.header(HEADER)
|
||||||
|
);
|
||||||
|
public static void loadConfig(@NotNull Path path, @NotNull Logger logger){
|
||||||
|
File configFile = new File(path.toFile(), "config.conf");
|
||||||
|
final HoconConfigurationLoader loader = configBuilder
|
||||||
|
.file(configFile)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final CommentedConfigurationNode node = loader.load();
|
||||||
|
config = node.get(Config.class);
|
||||||
|
node.set(Config.class, config);
|
||||||
|
loader.save(node);
|
||||||
|
} catch (ConfigurateException exception){
|
||||||
|
logger.error("Could not load configuration: {}", exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigSerializable
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Comment("List of login/registration servers")
|
||||||
|
private Set<String> authservers = Set.of(
|
||||||
"auth1",
|
"auth1",
|
||||||
"auth2"
|
"auth2"
|
||||||
));
|
);
|
||||||
config.setDefault(
|
|
||||||
"teleport.send-to-server-after-login",
|
private ServerOnLogin send = new ServerOnLogin();
|
||||||
false);
|
|
||||||
config.setDefault(
|
public Set<String> getAuthServers(){
|
||||||
"teleport.servers",
|
return this.authservers;
|
||||||
List.of(
|
}
|
||||||
|
|
||||||
|
public ServerOnLogin getToServerOptions(){
|
||||||
|
return this.send;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ConfigSerializable
|
||||||
|
public static class ServerOnLogin {
|
||||||
|
@Comment("Send logged in players to another server?")
|
||||||
|
private boolean sendToServerOnLogin = false;
|
||||||
|
|
||||||
|
@Comment("""
|
||||||
|
List of servers to send
|
||||||
|
One of these servers will be chosen at random
|
||||||
|
""")
|
||||||
|
private List<String> teleportServers = List.of(
|
||||||
"lobby1",
|
"lobby1",
|
||||||
"lobby2"
|
"lobby2"
|
||||||
));
|
);
|
||||||
|
|
||||||
|
public boolean sendToServer(){
|
||||||
|
return this.sendToServerOnLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getTeleportServers(){
|
||||||
|
return this.teleportServers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static Config config;
|
||||||
|
public static Config getConfig(){
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
private AuthMeConfig(){}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@ public class FastLoginListener {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){
|
public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){
|
||||||
Optional<Player> autoLoginPlayer = server.getPlayer(event.getProfile().getName());
|
Optional<Player> autoLoginPlayer = server.getPlayer(event.getProfile().getName());
|
||||||
if(autoLoginPlayer.isPresent()){
|
autoLoginPlayer.ifPresent(AuthmeVelocityAPI::addPlayer);
|
||||||
AuthmeVelocityAPI.addPlayer(autoLoginPlayer.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.glyart.authmevelocity.proxy.listener;
|
package com.glyart.authmevelocity.proxy.listener;
|
||||||
|
|
||||||
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
|
|
||||||
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
||||||
|
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||||
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.velocitypowered.api.event.EventTask;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
@ -25,41 +26,40 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class ProxyListener {
|
public class ProxyListener {
|
||||||
private final ProxyServer server;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
private final Random rm;
|
||||||
|
private AuthMeConfig.Config config;
|
||||||
|
|
||||||
public ProxyListener(ProxyServer server, Logger logger) {
|
public ProxyListener(ProxyServer proxy, Logger logger) {
|
||||||
this.server = server;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.rm = new Random();
|
||||||
|
this.config = AuthMeConfig.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPluginMessage(final PluginMessageEvent event) {
|
public void onPluginMessage(final PluginMessageEvent event) {
|
||||||
if (!(event.getSource() instanceof ServerConnection)) return;
|
if (!(event.getSource() instanceof ServerConnection) || !event.getIdentifier().getId().equals("authmevelocity:main"))
|
||||||
|
return;
|
||||||
if (!event.getIdentifier().getId().equals("authmevelocity:main")) return;
|
|
||||||
|
|
||||||
ByteArrayDataInput input = event.dataAsDataStream();
|
ByteArrayDataInput input = event.dataAsDataStream();
|
||||||
String sChannel = input.readUTF();
|
String sChannel = input.readUTF();
|
||||||
if (!sChannel.equals("LOGIN")) return;
|
if (!sChannel.equals("LOGIN")) return;
|
||||||
|
|
||||||
String user = input.readUTF();
|
String user = input.readUTF();
|
||||||
Optional<Player> optionalPlayer = server.getPlayer(UUID.fromString(user));
|
Optional<Player> optionalPlayer = proxy.getPlayer(UUID.fromString(user));
|
||||||
if (!optionalPlayer.isPresent()) return;
|
if (!optionalPlayer.isPresent()) return;
|
||||||
|
|
||||||
Player loggedPlayer = optionalPlayer.get();
|
Player loggedPlayer = optionalPlayer.get();
|
||||||
if (!AuthmeVelocityAPI.isLogged(loggedPlayer)){
|
if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){
|
||||||
AuthmeVelocityAPI.addPlayer(loggedPlayer);
|
RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElseThrow().getServer();
|
||||||
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer, loginServer));
|
||||||
RegisteredServer loginServer = loggedPlayer.getCurrentServer().get().getServer();
|
if(config.getToServerOptions().sendToServer()){
|
||||||
server.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer, loginServer));
|
List<String> serverList = config.getToServerOptions().getTeleportServers();
|
||||||
if(AuthMeVelocityPlugin.getConfig().getBoolean("teleport.send-to-server-after-login")){
|
|
||||||
Random rm = new Random();
|
|
||||||
List<String> serverList = AuthMeVelocityPlugin.getConfig().getStringList("teleport.servers");
|
|
||||||
String randomServer = serverList.get(rm.nextInt(serverList.size()));
|
String randomServer = serverList.get(rm.nextInt(serverList.size()));
|
||||||
Optional<RegisteredServer> optionalServer = server.getServer(randomServer);
|
Optional<RegisteredServer> optionalServer = proxy.getServer(randomServer);
|
||||||
if(optionalServer.isPresent()){
|
optionalServer.ifPresentOrElse(serverToSend -> {
|
||||||
RegisteredServer serverToSend = optionalServer.get();
|
|
||||||
try{
|
try{
|
||||||
if(!loggedPlayer.createConnectionRequest(serverToSend).connect().get().isSuccessful()){
|
if(!loggedPlayer.createConnectionRequest(serverToSend).connect().get().isSuccessful()){
|
||||||
logger.info("Unable to connect the player {} to the server {}",
|
logger.info("Unable to connect the player {} to the server {}",
|
||||||
@ -72,9 +72,7 @@ public class ProxyListener {
|
|||||||
serverToSend.getServerInfo().getName(),
|
serverToSend.getServerInfo().getName(),
|
||||||
exception);
|
exception);
|
||||||
}
|
}
|
||||||
} else{
|
}, () -> logger.info("The server {} does not exist", randomServer));
|
||||||
logger.info("The server {} does not exist", randomServer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,15 +84,12 @@ public class ProxyListener {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onCommandExecute(final CommandExecuteEvent event) {
|
public void onCommandExecute(final CommandExecuteEvent event) {
|
||||||
if (!(event.getCommandSource() instanceof Player player)) return;
|
if (!(event.getCommandSource() instanceof Player player) || AuthmeVelocityAPI.isLogged(player))
|
||||||
|
return;
|
||||||
if (AuthmeVelocityAPI.isLogged(player)) return;
|
|
||||||
|
|
||||||
Optional<ServerConnection> server = player.getCurrentServer();
|
Optional<ServerConnection> server = player.getCurrentServer();
|
||||||
boolean isAuthServer = server.isPresent() &&
|
|
||||||
AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName());
|
|
||||||
|
|
||||||
if (isAuthServer) {
|
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) {
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||||
} else {
|
} else {
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||||
@ -107,7 +102,7 @@ public class ProxyListener {
|
|||||||
if (AuthmeVelocityAPI.isLogged(player)) return;
|
if (AuthmeVelocityAPI.isLogged(player)) return;
|
||||||
|
|
||||||
Optional<ServerConnection> server = player.getCurrentServer();
|
Optional<ServerConnection> server = player.getCurrentServer();
|
||||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +114,7 @@ public class ProxyListener {
|
|||||||
if (AuthmeVelocityAPI.isLogged(event.getPlayer())) return;
|
if (AuthmeVelocityAPI.isLogged(event.getPlayer())) return;
|
||||||
|
|
||||||
Optional<RegisteredServer> server = event.getResult().getServer();
|
Optional<RegisteredServer> server = event.getResult().getServer();
|
||||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +122,11 @@ public class ProxyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onTabComplete(TabCompleteEvent event){
|
public EventTask onTabComplete(TabCompleteEvent event){
|
||||||
Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (!AuthmeVelocityAPI.isLogged(player)){
|
if (!AuthmeVelocityAPI.isLogged(player)){
|
||||||
event.getSuggestions().clear();
|
return EventTask.async(() -> event.getSuggestions().clear());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"version":"${project.version}",
|
"version":"${project.version}",
|
||||||
"url":"https://github.com/4drian3d/AuthMeVelocity",
|
"url":"https://github.com/4drian3d/AuthMeVelocity",
|
||||||
"description":"This plugin adds the support for AuthMeReloaded to Velocity.",
|
"description":"This plugin adds the support for AuthMeReloaded to Velocity.",
|
||||||
"authors":["xQuickGlare"],
|
"authors":["xQuickGlare", "4drian3d"],
|
||||||
"dependencies":[
|
"dependencies":[
|
||||||
{
|
{
|
||||||
"id":"fastlogin",
|
"id":"fastlogin",
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -5,17 +5,18 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class AuthMeVelocityPlugin extends JavaPlugin {
|
public class AuthMeVelocityPlugin extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
|
||||||
getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
||||||
|
|
||||||
getLogger().info("AuthMeVelocity enabled.");
|
this.getLogger().info("AuthMeVelocity enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLoginToProxy(Player player) {
|
public void sendLoginToProxy(@NotNull final Player player) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("LOGIN");
|
out.writeUTF("LOGIN");
|
||||||
out.writeUTF(player.getUniqueId().toString());
|
out.writeUTF(player.getUniqueId().toString());
|
||||||
|
@ -10,8 +10,8 @@ public class PreSendLoginEvent extends PlayerEvent implements Cancellable {
|
|||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
|
|
||||||
public PreSendLoginEvent(@NotNull Player player) {
|
public PreSendLoginEvent(@NotNull final Player player, boolean async) {
|
||||||
super(player);
|
super(player, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,10 +19,10 @@ public class AuthMeListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogin(LoginEvent event) {
|
public void onLogin(LoginEvent event) {
|
||||||
Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
PreSendLoginEvent sendloginevent = new PreSendLoginEvent(player);
|
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player, false);
|
||||||
Bukkit.getPluginManager().callEvent(sendloginevent);
|
Bukkit.getPluginManager().callEvent(preSendLoginEvent);
|
||||||
if(!sendloginevent.isCancelled()){
|
if(!preSendLoginEvent.isCancelled()){
|
||||||
plugin.sendLoginToProxy(player);
|
plugin.sendLoginToProxy(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user