Merge pull request #25 from 4drian3d/v2
2.0.0 | Improved Organization, API changes
This commit is contained in:
commit
6dee4bd6ef
@ -2,9 +2,9 @@
|
|||||||
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.16+
|
- Paper, Airplane or Purpur 1.13+
|
||||||
- Velocity 3.0.1+
|
- Velocity 3.1.1+
|
||||||
- Java 16
|
- Java 11+
|
||||||
|
|
||||||
## 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
pom.xml
2
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.5.0</version>
|
<version>2.0.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>1.5.0</version>
|
<version>2.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -34,11 +34,6 @@
|
|||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>configurate-hocon</artifactId>
|
|
||||||
<version>4.1.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.games647</groupId>
|
<groupId>com.github.games647</groupId>
|
||||||
<artifactId>fastlogin.velocity</artifactId>
|
<artifactId>fastlogin.velocity</artifactId>
|
||||||
@ -54,42 +49,6 @@
|
|||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.2.2</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>
|
||||||
|
@ -5,18 +5,22 @@ import com.glyart.authmevelocity.proxy.listener.FastLoginListener;
|
|||||||
import com.glyart.authmevelocity.proxy.listener.PluginMessageListener;
|
import com.glyart.authmevelocity.proxy.listener.PluginMessageListener;
|
||||||
import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.moandjiezana.toml.Toml;
|
||||||
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.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.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -24,30 +28,32 @@ public class AuthMeVelocityPlugin {
|
|||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Path pluginDirectory;
|
private final Path pluginDirectory;
|
||||||
private static AuthMeVelocityPlugin plugin;
|
private AuthmeVelocityAPI api;
|
||||||
|
|
||||||
protected static final Set<UUID> loggedPlayers = Collections.synchronizedSet(new HashSet<>());
|
protected final Set<UUID> loggedPlayers = Collections.<UUID>synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthMeVelocityPlugin(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
|
public AuthMeVelocityPlugin(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
|
||||||
plugin = this;
|
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.pluginDirectory = dataDirectory;
|
this.pluginDirectory = dataDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialize(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
AuthMeConfig.loadConfig(pluginDirectory, logger);
|
Toml toml = this.loadConfig(pluginDirectory, logger);
|
||||||
@NotNull var config = AuthMeConfig.getConfig();
|
if(toml == null){
|
||||||
|
logger.warn("Failed to load config.toml. Shutting down.");
|
||||||
proxy.getChannelRegistrar().register(
|
return;
|
||||||
MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
}
|
||||||
proxy.getEventManager().register(this, new ProxyListener(config));
|
AuthMeConfig config = Objects.requireNonNull(new AuthMeConfig(toml), "configuration cannot be null");
|
||||||
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config));
|
this.api = new AuthmeVelocityAPI(this, config);
|
||||||
|
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
||||||
|
proxy.getEventManager().register(this, new ProxyListener(config, api, logger, proxy));
|
||||||
|
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api));
|
||||||
|
|
||||||
if(proxy.getPluginManager().isLoaded("fastlogin")){
|
if(proxy.getPluginManager().isLoaded("fastlogin")){
|
||||||
proxy.getEventManager().register(this, new FastLoginListener(proxy));
|
proxy.getEventManager().register(this, new FastLoginListener(proxy, api));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("-- AuthMeVelocity enabled --");
|
logger.info("-- AuthMeVelocity enabled --");
|
||||||
@ -61,7 +67,28 @@ public class AuthMeVelocityPlugin {
|
|||||||
return this.proxy;
|
return this.proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthMeVelocityPlugin getInstance(){
|
public AuthmeVelocityAPI getAPI(){
|
||||||
return plugin;
|
return this.api;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Toml loadConfig(Path path, Logger logger){
|
||||||
|
if(!Files.exists(path)){
|
||||||
|
try {
|
||||||
|
Files.createDirectory(path);
|
||||||
|
} catch(IOException e){
|
||||||
|
logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Path configPath = path.resolve("config.toml");
|
||||||
|
if(!Files.exists(configPath)){
|
||||||
|
try(InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.toml")){
|
||||||
|
Files.copy(in, configPath);
|
||||||
|
} catch(IOException e){
|
||||||
|
logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Toml().read(configPath.toFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.glyart.authmevelocity.proxy;
|
package com.glyart.authmevelocity.proxy;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@ -11,17 +12,23 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APi provided to interact with logged players
|
* API provided to interact with logged players
|
||||||
*/
|
*/
|
||||||
public class AuthmeVelocityAPI {
|
public final class AuthmeVelocityAPI {
|
||||||
|
private final AuthMeVelocityPlugin plugin;
|
||||||
|
private final AuthMeConfig config;
|
||||||
|
AuthmeVelocityAPI(AuthMeVelocityPlugin plugin, AuthMeConfig config){
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 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(@NotNull Player player){
|
public boolean isLogged(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
return AuthMeVelocityPlugin.loggedPlayers.contains(playerUUID);
|
return plugin.loggedPlayers.contains(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,9 +36,9 @@ public class AuthmeVelocityAPI {
|
|||||||
* @param player the new logged player
|
* @param player the new logged player
|
||||||
* @return if the player was succesfully added
|
* @return if the player was succesfully added
|
||||||
*/
|
*/
|
||||||
public static boolean addPlayer(@NotNull Player player){
|
public boolean addPlayer(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
return AuthMeVelocityPlugin.loggedPlayers.add(playerUUID);
|
return plugin.loggedPlayers.add(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,20 +46,17 @@ public class AuthmeVelocityAPI {
|
|||||||
* @param player the unlogged player
|
* @param player the unlogged player
|
||||||
* @return if the player was succesfully removed
|
* @return if the player was succesfully removed
|
||||||
*/
|
*/
|
||||||
public static boolean removePlayer(@NotNull Player player){
|
public boolean removePlayer(@NotNull Player player){
|
||||||
final UUID playerUUID = player.getUniqueId();
|
final UUID playerUUID = player.getUniqueId();
|
||||||
return AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
|
return plugin.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(@NotNull Predicate<Player> predicate){
|
public void removePlayerIf(@NotNull Predicate<Player> predicate){
|
||||||
AuthMeVelocityPlugin.loggedPlayers.stream()
|
plugin.loggedPlayers.removeIf(uuid -> predicate.test(plugin.getProxy().getPlayer(uuid).orElseThrow()));
|
||||||
.map(uuid -> AuthMeVelocityPlugin.getInstance().getProxy().getPlayer(uuid).orElseThrow())
|
|
||||||
.filter(predicate)
|
|
||||||
.forEach(player -> AuthMeVelocityPlugin.loggedPlayers.remove(player.getUniqueId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,8 +64,8 @@ public class AuthmeVelocityAPI {
|
|||||||
* @param player the player
|
* @param player the player
|
||||||
* @return if the player is on a login server
|
* @return if the player is on a login server
|
||||||
*/
|
*/
|
||||||
public static boolean isInAuthServer(@NotNull Player player){
|
public boolean isInAuthServer(@NotNull Player player){
|
||||||
var connection = player.getCurrentServer();
|
Optional<ServerConnection> connection = player.getCurrentServer();
|
||||||
return connection.isPresent() && isAuthServer(connection.get());
|
return connection.isPresent() && isAuthServer(connection.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +74,8 @@ public class AuthmeVelocityAPI {
|
|||||||
* @param server the server
|
* @param server the server
|
||||||
* @return if the server is a login server
|
* @return if the server is a login server
|
||||||
*/
|
*/
|
||||||
public static boolean isAuthServer(@NotNull RegisteredServer server){
|
public boolean isAuthServer(@NotNull RegisteredServer server){
|
||||||
return AuthMeConfig.getConfig().getAuthServers().contains(server.getServerInfo().getName());
|
return config.getAuthServers().contains(server.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,9 +83,16 @@ public class AuthmeVelocityAPI {
|
|||||||
* @param connection the connection
|
* @param connection the connection
|
||||||
* @return if the connection is made from a login server
|
* @return if the connection is made from a login server
|
||||||
*/
|
*/
|
||||||
public static boolean isAuthServer(@NotNull ServerConnection connection){
|
public boolean isAuthServer(@NotNull ServerConnection connection){
|
||||||
return AuthMeConfig.getConfig().getAuthServers().contains(connection.getServerInfo().getName());
|
return config.getAuthServers().contains(connection.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthmeVelocityAPI(){}
|
/**
|
||||||
|
* Checks if a string is an name of an auth server
|
||||||
|
* @param server the server name
|
||||||
|
* @return if the server is an auth serverr
|
||||||
|
*/
|
||||||
|
public boolean isAuthServer(@NotNull String server){
|
||||||
|
return config.getAuthServers().contains(server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,111 +1,79 @@
|
|||||||
package com.glyart.authmevelocity.proxy.config;
|
package com.glyart.authmevelocity.proxy.config;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.moandjiezana.toml.Toml;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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;
|
|
||||||
|
|
||||||
public class AuthMeConfig {
|
public final class AuthMeConfig {
|
||||||
private static final String HEADER = "AuthmeVelocity Proxy\n\nOriginal Developer: xQuickGlare\nCurrent Developer: 4drian3d";
|
private final List<String> authServers;
|
||||||
private static final HoconConfigurationLoader.Builder configBuilder = HoconConfigurationLoader.builder()
|
private final ServerOnLogin serverOnLogin;
|
||||||
.defaultOptions(opts -> opts
|
private final Commands commands;
|
||||||
.shouldCopyDefaults(true)
|
private final EnsureAuthServer ensure;
|
||||||
.header(HEADER)
|
|
||||||
);
|
|
||||||
public static void loadConfig(@NotNull Path path, @NotNull Logger logger){
|
|
||||||
Path configPath = path.resolve("config.conf");
|
|
||||||
final HoconConfigurationLoader loader = configBuilder
|
|
||||||
.path(configPath)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
public AuthMeConfig(@NotNull Toml toml){
|
||||||
final CommentedConfigurationNode node = loader.load();
|
this.authServers = Objects.requireNonNull(toml.getList("authServers"), "the list of auth servers is not available, please check your configuration for any failure");
|
||||||
config = node.get(Config.class);
|
this.serverOnLogin = Objects.requireNonNull(toml.getTable("SendOnLogin"), "SendOnLogin options are not available, check your configuration").to(ServerOnLogin.class);
|
||||||
node.set(Config.class, config);
|
this.commands = Objects.requireNonNull(toml.getTable("Commands"), "Commands options are not available, check your configuration").to(Commands.class);
|
||||||
loader.save(node);
|
this.ensure = Objects.requireNonNull(toml.getTable("EnsureAuthServer"), "EnsureAuthServer options are not available, check your configuration").to(EnsureAuthServer.class);
|
||||||
} 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",
|
|
||||||
"auth2"
|
|
||||||
);
|
|
||||||
|
|
||||||
private Commands commands = new Commands();
|
|
||||||
|
|
||||||
private ServerOnLogin send = new ServerOnLogin();
|
|
||||||
|
|
||||||
public Set<String> getAuthServers(){
|
|
||||||
return this.authservers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Commands getCommandsConfig(){
|
|
||||||
return this.commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerOnLogin getToServerOptions(){
|
|
||||||
return this.send;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ConfigSerializable
|
|
||||||
public static class ServerOnLogin {
|
public static class ServerOnLogin {
|
||||||
@Comment("Send logged in players to another server?")
|
private boolean sendToServerOnLogin;
|
||||||
private boolean sendToServerOnLogin = false;
|
private List<String> teleportServers;
|
||||||
|
|
||||||
@Comment("List of servers to send\nOne of these servers will be chosen at random")
|
|
||||||
private List<String> teleportServers = List.of(
|
|
||||||
"lobby1",
|
|
||||||
"lobby2"
|
|
||||||
);
|
|
||||||
|
|
||||||
public boolean sendToServer(){
|
public boolean sendToServer(){
|
||||||
return this.sendToServerOnLogin;
|
return this.sendToServerOnLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTeleportServers(){
|
public @NotNull List<String> getTeleportServers(){
|
||||||
return this.teleportServers;
|
return this.teleportServers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigSerializable
|
|
||||||
public static class Commands{
|
public static class Commands{
|
||||||
@Comment("Sets the commands that users who have not yet logged in can execute")
|
private Set<String> allowedCommands;
|
||||||
private Set<String> allowedCommands = Set.of(
|
private String blockedCommandMessage;
|
||||||
"login",
|
|
||||||
"register",
|
|
||||||
"l",
|
|
||||||
"reg",
|
|
||||||
"email",
|
|
||||||
"captcha"
|
|
||||||
);
|
|
||||||
|
|
||||||
@Comment("Sets the message to send in case a non-logged-in player executes an unauthorized command\nTo deactivate the message, leave it empty")
|
public @NotNull Set<String> getAllowedCommands(){
|
||||||
private String blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet";
|
|
||||||
|
|
||||||
public Set<String> getAllowedCommands(){
|
|
||||||
return this.allowedCommands;
|
return this.allowedCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBlockedMessage() {
|
public @NotNull String getBlockedMessage() {
|
||||||
return this.blockedCommandMessage;
|
return this.blockedCommandMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static Config config;
|
|
||||||
public static Config getConfig(){
|
public static class EnsureAuthServer {
|
||||||
return config;
|
private boolean ensureFirstServerIsAuthServer;
|
||||||
|
private String disconnectMessage;
|
||||||
|
|
||||||
|
public boolean ensureAuthServer(){
|
||||||
|
return this.ensureFirstServerIsAuthServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getDisconnectMessage(){
|
||||||
|
return this.disconnectMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Commands getCommandsConfig(){
|
||||||
|
return this.commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ServerOnLogin getToServerOptions(){
|
||||||
|
return this.serverOnLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull EnsureAuthServer getEnsureOptions(){
|
||||||
|
return this.ensure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> getAuthServers(){
|
||||||
|
return this.authServers;
|
||||||
}
|
}
|
||||||
private AuthMeConfig(){}
|
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,12 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
public class ConfigUtils {
|
public final class ConfigUtils {
|
||||||
public static void sendBlockedMessage(Player player){
|
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder().character('&').hexColors().build();
|
||||||
var config = AuthMeConfig.getConfig();
|
public static void sendBlockedMessage(Player player, AuthMeConfig config){
|
||||||
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
|
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
|
||||||
if(!blockedMessage.isBlank()){
|
if(!blockedMessage.isBlank()){
|
||||||
player.sendMessage(
|
player.sendMessage(SERIALIZER.deserialize(blockedMessage));
|
||||||
LegacyComponentSerializer.legacyAmpersand().deserialize(
|
|
||||||
blockedMessage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private ConfigUtils(){}
|
private ConfigUtils(){}
|
||||||
|
@ -7,6 +7,8 @@ import com.velocitypowered.api.event.ResultedEvent.GenericResult;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event to be executed just before sending a player to another server after login/registration.
|
* Event to be executed just before sending a player to another server after login/registration.
|
||||||
* Here you have the ability to deny the event.
|
* Here you have the ability to deny the event.
|
||||||
@ -24,7 +26,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* @param actualServer the server on which the player is located
|
* @param actualServer the server on which the player is located
|
||||||
* @param serverToSend the server to which the player will be sent
|
* @param serverToSend the server to which the player will be sent
|
||||||
*/
|
*/
|
||||||
public PreSendOnLoginEvent(Player player, RegisteredServer actualServer, 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;
|
||||||
this.serverToSend = serverToSend;
|
this.serverToSend = serverToSend;
|
||||||
@ -34,7 +36,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* Obtain the logged player
|
* Obtain the logged player
|
||||||
* @return the player
|
* @return the player
|
||||||
*/
|
*/
|
||||||
public Player getPlayer(){
|
public @NotNull Player getPlayer(){
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* Obtain the server on which the player is located
|
* Obtain the server on which the player is located
|
||||||
* @return the actual server of the player
|
* @return the actual server of the player
|
||||||
*/
|
*/
|
||||||
public RegisteredServer getActualServer(){
|
public @NotNull RegisteredServer getActualServer(){
|
||||||
return this.actualserver;
|
return this.actualserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* Obtain the server to which the player will be sent
|
* Obtain the server to which the player will be sent
|
||||||
* @return the server to send the player
|
* @return the server to send the player
|
||||||
*/
|
*/
|
||||||
public RegisteredServer getSendServer(){
|
public @NotNull RegisteredServer getSendServer(){
|
||||||
return this.serverToSend;
|
return this.serverToSend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* Get the result of the event
|
* Get the result of the event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public GenericResult getResult() {
|
public @NotNull GenericResult getResult() {
|
||||||
return this.result;
|
return this.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* @param newresult the new result
|
* @param newresult the new result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setResult(GenericResult newresult) {
|
public void setResult(@NotNull GenericResult newresult) {
|
||||||
this.result = Objects.requireNonNull(newresult);
|
this.result = Objects.requireNonNull(newresult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.glyart.authmevelocity.proxy.event;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ProxyForcedUnregisterEvent {
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
public ProxyForcedUnregisterEvent(@Nullable Player player){
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Player getPlayer(){
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.glyart.authmevelocity.proxy.event;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ProxyUnregisterEvent {
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
public ProxyUnregisterEvent(@NotNull Player player){
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Player getPlayer(){
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
}
|
@ -7,11 +7,13 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
|||||||
|
|
||||||
public class FastLoginListener {
|
public class FastLoginListener {
|
||||||
private final ProxyServer server;
|
private final ProxyServer server;
|
||||||
public FastLoginListener(ProxyServer server){
|
private final AuthmeVelocityAPI api;
|
||||||
|
public FastLoginListener(ProxyServer server, AuthmeVelocityAPI api){
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
this.api = api;
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){
|
public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){
|
||||||
server.getPlayer(event.getProfile().getName()).ifPresent(AuthmeVelocityAPI::addPlayer);
|
server.getPlayer(event.getProfile().getName()).ifPresent(api::addPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,11 @@ import java.util.Random;
|
|||||||
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
||||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||||
import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent;
|
import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent;
|
||||||
|
import com.glyart.authmevelocity.proxy.event.ProxyForcedUnregisterEvent;
|
||||||
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
||||||
import com.glyart.authmevelocity.proxy.event.ProxyLogoutEvent;
|
import com.glyart.authmevelocity.proxy.event.ProxyLogoutEvent;
|
||||||
import com.glyart.authmevelocity.proxy.event.ProxyRegisterEvent;
|
import com.glyart.authmevelocity.proxy.event.ProxyRegisterEvent;
|
||||||
|
import com.glyart.authmevelocity.proxy.event.ProxyUnregisterEvent;
|
||||||
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;
|
||||||
@ -19,19 +21,22 @@ 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 org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class PluginMessageListener {
|
public class PluginMessageListener {
|
||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Random rm;
|
private final Random rm;
|
||||||
private AuthMeConfig.Config config;
|
private final AuthMeConfig config;
|
||||||
|
private final AuthmeVelocityAPI api;
|
||||||
|
|
||||||
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config) {
|
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.rm = new Random();
|
this.rm = new Random();
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -46,30 +51,36 @@ public class PluginMessageListener {
|
|||||||
|
|
||||||
ByteArrayDataInput input = event.dataAsDataStream();
|
ByteArrayDataInput input = event.dataAsDataStream();
|
||||||
final String sChannel = input.readUTF();
|
final String sChannel = input.readUTF();
|
||||||
final Player loggedPlayer = connection.getPlayer();
|
final String playername = input.readUTF();
|
||||||
|
final @Nullable Player loggedPlayer = proxy.getPlayer(playername).orElse(null);
|
||||||
switch(sChannel){
|
switch(sChannel){
|
||||||
case "LOGIN" :
|
case "LOGIN" :
|
||||||
if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){
|
if (loggedPlayer != null && api.addPlayer(loggedPlayer)){
|
||||||
createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection);
|
createServerConnectionRequest(loggedPlayer, proxy, logger, connection);
|
||||||
}
|
}
|
||||||
continuation.resume();
|
|
||||||
break;
|
break;
|
||||||
case "LOGOUT":
|
case "LOGOUT":
|
||||||
if(AuthmeVelocityAPI.removePlayer(loggedPlayer)){
|
if(loggedPlayer != null && api.removePlayer(loggedPlayer)){
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(loggedPlayer));
|
||||||
}
|
}
|
||||||
continuation.resume();
|
|
||||||
break;
|
break;
|
||||||
case "REGISTER":
|
case "REGISTER":
|
||||||
proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(loggedPlayer));
|
if(loggedPlayer != null)
|
||||||
continuation.resume();
|
proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(loggedPlayer));
|
||||||
break;
|
break;
|
||||||
|
case "UNREGISTER":
|
||||||
default: continuation.resume();
|
if(loggedPlayer != null)
|
||||||
|
proxy.getEventManager().fireAndForget(new ProxyUnregisterEvent(loggedPlayer));
|
||||||
|
break;
|
||||||
|
case "FORCE_UNREGISTER":
|
||||||
|
proxy.getEventManager().fireAndForget(new ProxyForcedUnregisterEvent(loggedPlayer));
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){
|
private void createServerConnectionRequest(Player loggedPlayer, ProxyServer proxy, Logger logger, ServerConnection connection){
|
||||||
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
|
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
||||||
if(config.getToServerOptions().sendToServer()){
|
if(config.getToServerOptions().sendToServer()){
|
||||||
|
@ -1,34 +1,48 @@
|
|||||||
package com.glyart.authmevelocity.proxy.listener;
|
package com.glyart.authmevelocity.proxy.listener;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
|
||||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||||
import com.glyart.authmevelocity.proxy.config.ConfigUtils;
|
import com.glyart.authmevelocity.proxy.config.ConfigUtils;
|
||||||
import com.glyart.authmevelocity.proxy.utils.AuthmeUtils;
|
import com.glyart.authmevelocity.proxy.utils.AuthmeUtils;
|
||||||
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.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;
|
||||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||||
|
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||||
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class ProxyListener {
|
public final class ProxyListener {
|
||||||
private AuthMeConfig.Config config;
|
private final AuthMeConfig config;
|
||||||
|
private final AuthmeVelocityAPI api;
|
||||||
|
private final ProxyServer proxy;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
public ProxyListener(@NotNull AuthMeConfig.Config config) {
|
public ProxyListener(@NotNull AuthMeConfig config, AuthmeVelocityAPI api, Logger logger, ProxyServer proxy) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.api = api;
|
||||||
|
this.logger = logger;
|
||||||
|
this.proxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDisconnect(final DisconnectEvent event) {
|
public EventTask onDisconnect(final DisconnectEvent event) {
|
||||||
AuthmeVelocityAPI.removePlayer(event.getPlayer());
|
return EventTask.async(() -> api.removePlayer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public void onCommandExecute(final CommandExecuteEvent event, Continuation continuation) {
|
public void onCommandExecute(final CommandExecuteEvent event, Continuation continuation) {
|
||||||
if (!(event.getCommandSource() instanceof Player)){
|
if (!(event.getCommandSource() instanceof Player)){
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
@ -37,50 +51,82 @@ public class ProxyListener {
|
|||||||
|
|
||||||
Player player = ((Player)event.getCommandSource());
|
Player player = ((Player)event.getCommandSource());
|
||||||
|
|
||||||
if(AuthmeVelocityAPI.isLogged(player)){
|
if(api.isLogged(player)){
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(AuthmeVelocityAPI.isInAuthServer(player)){
|
if(api.isInAuthServer(player)){
|
||||||
String command = AuthmeUtils.getFirstArgument(event.getCommand());
|
String command = AuthmeUtils.getFirstArgument(event.getCommand());
|
||||||
if(!config.getCommandsConfig().getAllowedCommands().contains(command)){
|
if(!config.getCommandsConfig().getAllowedCommands().contains(command)){
|
||||||
ConfigUtils.sendBlockedMessage(player);
|
ConfigUtils.sendBlockedMessage(player, config);
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ConfigUtils.sendBlockedMessage(player);
|
ConfigUtils.sendBlockedMessage(player, config);
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||||
}
|
}
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public void onPlayerChat(final PlayerChatEvent event) {
|
public void onPlayerChat(final PlayerChatEvent event) {
|
||||||
if (!AuthmeVelocityAPI.isLogged(event.getPlayer())) {
|
if (!api.isLogged(event.getPlayer())) {
|
||||||
event.setResult(PlayerChatEvent.ChatResult.denied());
|
event.setResult(PlayerChatEvent.ChatResult.denied());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onServerPreConnect(ServerPreConnectEvent event, Continuation continuation) {
|
public void onServerPreConnect(ServerPreConnectEvent event, Continuation continuation) {
|
||||||
if (AuthmeVelocityAPI.isLogged(event.getPlayer())){
|
if (api.isLogged(event.getPlayer())){
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getResult().getServer().ifPresent(server -> {
|
event.getResult().getServer().ifPresent(server -> {
|
||||||
if(!AuthmeVelocityAPI.isAuthServer(server)){
|
if(!api.isAuthServer(server)){
|
||||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public EventTask onTabComplete(TabCompleteEvent event){
|
public EventTask onTabComplete(TabCompleteEvent event){
|
||||||
if (!AuthmeVelocityAPI.isLogged(event.getPlayer())){
|
return EventTask.async(() -> {
|
||||||
return EventTask.async(() -> event.getSuggestions().clear());
|
if (!api.isLogged(event.getPlayer())){
|
||||||
|
event.getSuggestions().clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(order = PostOrder.LATE)
|
||||||
|
public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){
|
||||||
|
if(!config.getEnsureOptions().ensureAuthServer()){
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Optional<RegisteredServer> optionalSV = event.getInitialServer();
|
||||||
|
if(optionalSV.isPresent() && api.isAuthServer(optionalSV.get())){
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@Nullable RegisteredServer server = getAvailableServer();
|
||||||
|
if(server == null) {
|
||||||
|
continuation.resume();
|
||||||
|
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername());
|
||||||
|
event.getPlayer().disconnect(ConfigUtils.SERIALIZER.deserialize(config.getEnsureOptions().getDisconnectMessage()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setInitialServer(server);
|
||||||
|
continuation.resume();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable RegisteredServer getAvailableServer(){
|
||||||
|
for(String sv : config.getAuthServers()){
|
||||||
|
Optional<RegisteredServer> opt = proxy.getServer(sv);
|
||||||
|
if(opt.isPresent()) return opt.get();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
29
proxy/src/main/resources/config.toml
Normal file
29
proxy/src/main/resources/config.toml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# AuthmeVelocity Proxy
|
||||||
|
# Original Developer: xQuickGlare
|
||||||
|
# Actual Developer: 4drian3d
|
||||||
|
|
||||||
|
# List of login/registration servers
|
||||||
|
authServers = ["auth1", "auth2"]
|
||||||
|
|
||||||
|
[SendOnLogin]
|
||||||
|
# Send logged in players to another server?
|
||||||
|
sendToServerOnLogin = false
|
||||||
|
|
||||||
|
# List of servers to send
|
||||||
|
# One of these servers will be chosen at random
|
||||||
|
teleportServers = ["lobby1", "lobby2"]
|
||||||
|
|
||||||
|
[Commands]
|
||||||
|
# Sets the commands that users who have not yet logged in can execute
|
||||||
|
allowedCommands = ["login", "register", "l", "reg", "email", "captcha"]
|
||||||
|
|
||||||
|
# Sets the message to send in case a non-logged-in player executes an unauthorized command
|
||||||
|
# To deactivate the message, leave it empty
|
||||||
|
blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet"
|
||||||
|
|
||||||
|
[EnsureAuthServer]
|
||||||
|
# Ensure that the first server to which players connect is an auth server
|
||||||
|
ensureFirstServerIsAuthServer = false
|
||||||
|
|
||||||
|
# Message to be sent to the player in case no auth server is available
|
||||||
|
disconnectMessage = "&4You could not connect to a login server, please try again later"
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.glyart.authmevelocity</groupId>
|
<groupId>com.glyart.authmevelocity</groupId>
|
||||||
<version>1.5.0</version>
|
<version>2.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.18-R0.1-SNAPSHOT</version>
|
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -3,6 +3,8 @@ package com.glyart.authmevelocity.spigot;
|
|||||||
import com.glyart.authmevelocity.spigot.listeners.AuthMeListener;
|
import com.glyart.authmevelocity.spigot.listeners.AuthMeListener;
|
||||||
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 org.bukkit.Bukkit;
|
||||||
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;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -14,13 +16,18 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
|
|||||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||||
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
||||||
|
|
||||||
this.getLogger().info("AuthMeVelocity enabled.");
|
this.getSLF4JLogger().info("AuthMeVelocity enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToProxy(@NotNull final Player player, MessageType type) {
|
public void sendMessageToProxy(final Player player, @NotNull MessageType type, @NotNull String playername) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(type.toString());
|
out.writeUTF(type.toString());
|
||||||
|
out.writeUTF(playername);
|
||||||
|
|
||||||
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
if(player == null){
|
||||||
|
Bukkit.getServer().sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
|
} else {
|
||||||
|
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package com.glyart.authmevelocity.spigot;
|
package com.glyart.authmevelocity.spigot;
|
||||||
|
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
LOGIN, REGISTER, LOGOUT
|
LOGIN, REGISTER, LOGOUT, FORCE_UNREGISTER, UNREGISTER;
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,15 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class PreSendLoginEvent extends PlayerEvent implements Cancellable {
|
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 = false;
|
||||||
|
|
||||||
public PreSendLoginEvent(@NotNull final Player player) {
|
public PreSendLoginEvent(@NotNull Player player) {
|
||||||
super(player);
|
super(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return this.isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,8 @@ import com.glyart.authmevelocity.spigot.events.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.UnregisterByPlayerEvent;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -21,21 +23,31 @@ public class AuthMeListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onLogin(final LoginEvent event) {
|
public void onLogin(LoginEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player);
|
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player);
|
||||||
if(!preSendLoginEvent.callEvent()){
|
if(preSendLoginEvent.callEvent()){
|
||||||
plugin.sendMessageToProxy(player, MessageType.LOGIN);
|
plugin.sendMessageToProxy(player, MessageType.LOGIN, player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRegister(RegisterEvent event){
|
public void onRegister(RegisterEvent event){
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER);
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER, event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogout(LogoutEvent event){
|
public void onLogout(LogoutEvent event){
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT);
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT, event.getPlayer().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onUnRegister(UnregisterByPlayerEvent event){
|
||||||
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.UNREGISTER, event.getPlayer().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdminUnRegister(UnregisterByAdminEvent event){
|
||||||
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.FORCE_UNREGISTER, event.getPlayerName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
name: AuthMeVelocity
|
name: AuthMeVelocity
|
||||||
author: xQuickGlare
|
authors: [xQuickGlare, 4drian3d]
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
main: com.glyart.authmevelocity.spigot.AuthMeVelocityPlugin
|
main: com.glyart.authmevelocity.spigot.AuthMeVelocityPlugin
|
||||||
depend: [AuthMe]
|
depend: [AuthMe]
|
||||||
api-version: 1.16
|
# pls, dont use outdated versions, use 1.16.5+
|
||||||
|
api-version: 1.13
|
Loading…
x
Reference in New Issue
Block a user