Changed configuration format from hocon to toml
This commit is contained in:
parent
47c7e157c9
commit
e871d555d6
@ -34,11 +34,6 @@
|
||||
<version>3.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.games647</groupId>
|
||||
<artifactId>fastlogin.velocity</artifactId>
|
||||
@ -54,42 +49,6 @@
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</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>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.glyart.authmevelocity.proxy;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
|
||||
import com.glyart.authmevelocity.proxy.listener.FastLoginListener;
|
||||
import com.glyart.authmevelocity.proxy.listener.PluginMessageListener;
|
||||
import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
||||
import com.google.inject.Inject;
|
||||
import com.moandjiezana.toml.Toml;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
@ -14,6 +14,9 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -25,8 +28,7 @@ public class AuthMeVelocityPlugin {
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
private final Path pluginDirectory;
|
||||
private final AuthmeVelocityAPI api;
|
||||
Config config = null;
|
||||
private AuthmeVelocityAPI api;
|
||||
|
||||
protected final Set<UUID> loggedPlayers = Collections.<UUID>synchronizedSet(new HashSet<>());
|
||||
|
||||
@ -35,13 +37,17 @@ public class AuthMeVelocityPlugin {
|
||||
this.proxy = proxy;
|
||||
this.logger = logger;
|
||||
this.pluginDirectory = dataDirectory;
|
||||
this.api = new AuthmeVelocityAPI(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
this.config = Objects.requireNonNull(new AuthMeConfig().loadConfig(pluginDirectory, logger), "configuration cannot be null");
|
||||
|
||||
Toml toml = this.loadConfig(pluginDirectory, logger);
|
||||
if(toml == null){
|
||||
logger.warn("Failed to load config.toml. Shutting down.");
|
||||
return;
|
||||
}
|
||||
AuthMeConfig config = Objects.requireNonNull(new AuthMeConfig(toml), "configuration cannot be null");
|
||||
this.api = new AuthmeVelocityAPI(this, config);
|
||||
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
||||
proxy.getEventManager().register(this, new ProxyListener(config, api));
|
||||
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api));
|
||||
@ -64,4 +70,25 @@ public class AuthMeVelocityPlugin {
|
||||
public AuthmeVelocityAPI getAPI(){
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
@ -15,8 +16,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public final class AuthmeVelocityAPI {
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
AuthmeVelocityAPI(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
|
||||
@ -72,7 +75,7 @@ public final class AuthmeVelocityAPI {
|
||||
* @return if the server is a login server
|
||||
*/
|
||||
public boolean isAuthServer(@NotNull RegisteredServer server){
|
||||
return plugin.config.getAuthServers().contains(server.getServerInfo().getName());
|
||||
return config.getAuthServers().contains(server.getServerInfo().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,6 +84,6 @@ public final class AuthmeVelocityAPI {
|
||||
* @return if the connection is made from a login server
|
||||
*/
|
||||
public boolean isAuthServer(@NotNull ServerConnection connection){
|
||||
return plugin.config.getAuthServers().contains(connection.getServerInfo().getName());
|
||||
return config.getAuthServers().contains(connection.getServerInfo().getName());
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,24 @@
|
||||
package com.glyart.authmevelocity.proxy.config;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
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 com.moandjiezana.toml.Toml;
|
||||
|
||||
public class AuthMeConfig {
|
||||
public Config loadConfig(@NotNull Path path, @NotNull Logger logger){
|
||||
Path configPath = Objects.requireNonNull(path).resolve("config.conf");
|
||||
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
||||
.defaultOptions(opts -> opts
|
||||
.shouldCopyDefaults(true)
|
||||
.header("AuthmeVelocity Proxy\n\nOriginal Developer: xQuickGlare\nCurrent Developer: 4drian3d")
|
||||
)
|
||||
.path(configPath)
|
||||
.build();
|
||||
public final class AuthMeConfig {
|
||||
private final List<String> authServers;
|
||||
private final ServerOnLogin serverOnLogin;
|
||||
private final Commands commands;
|
||||
|
||||
try {
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
config = node.get(Config.class);
|
||||
node.set(Config.class, config);
|
||||
loader.save(node);
|
||||
return config;
|
||||
} catch (ConfigurateException exception){
|
||||
logger.error("Could not load configuration: {}", exception.getMessage());
|
||||
return null;
|
||||
}
|
||||
public AuthMeConfig(Toml toml){
|
||||
this.authServers = toml.getList("authServers");
|
||||
this.serverOnLogin = toml.getTable("SendOnLogin").to(ServerOnLogin.class);
|
||||
this.commands = toml.getTable("Commands").to(Commands.class);
|
||||
}
|
||||
|
||||
@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 {
|
||||
@Comment("Send logged in players to another server?")
|
||||
private boolean sendToServerOnLogin = false;
|
||||
|
||||
@Comment("List of servers to send\nOne of these servers will be chosen at random")
|
||||
private List<String> teleportServers = List.of(
|
||||
"lobby1",
|
||||
"lobby2"
|
||||
);
|
||||
private boolean sendToServerOnLogin;
|
||||
private List<String> teleportServers;
|
||||
|
||||
public boolean sendToServer(){
|
||||
return this.sendToServerOnLogin;
|
||||
@ -81,20 +29,9 @@ public class AuthMeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static class Commands{
|
||||
@Comment("Sets the commands that users who have not yet logged in can execute")
|
||||
private Set<String> allowedCommands = Set.of(
|
||||
"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")
|
||||
private String blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet";
|
||||
private Set<String> allowedCommands;
|
||||
private String blockedCommandMessage;
|
||||
|
||||
public Set<String> getAllowedCommands(){
|
||||
return this.allowedCommands;
|
||||
@ -104,8 +41,16 @@ public class AuthMeConfig {
|
||||
return this.blockedCommandMessage;
|
||||
}
|
||||
}
|
||||
private Config config = null;
|
||||
public Config getConfig(){
|
||||
return config;
|
||||
|
||||
public Commands getCommandsConfig(){
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
public ServerOnLogin getToServerOptions(){
|
||||
return this.serverOnLogin;
|
||||
}
|
||||
|
||||
public List<String> getAuthServers(){
|
||||
return this.authServers;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.glyart.authmevelocity.proxy.config;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class ConfigUtils {
|
||||
public static void sendBlockedMessage(Player player, Config config){
|
||||
public final class ConfigUtils {
|
||||
public static void sendBlockedMessage(Player player, AuthMeConfig config){
|
||||
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
|
||||
if(!blockedMessage.isBlank()){
|
||||
player.sendMessage(
|
||||
|
@ -25,10 +25,10 @@ public class PluginMessageListener {
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
private final Random rm;
|
||||
private final AuthMeConfig.Config config;
|
||||
private final AuthMeConfig config;
|
||||
private final AuthmeVelocityAPI api;
|
||||
|
||||
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
|
||||
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
|
||||
this.proxy = proxy;
|
||||
this.logger = logger;
|
||||
this.rm = new Random();
|
||||
@ -52,7 +52,7 @@ public class PluginMessageListener {
|
||||
switch(sChannel){
|
||||
case "LOGIN" :
|
||||
if (api.addPlayer(loggedPlayer)){
|
||||
createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection);
|
||||
createServerConnectionRequest(loggedPlayer, proxy, logger, connection);
|
||||
}
|
||||
continuation.resume();
|
||||
break;
|
||||
@ -71,7 +71,7 @@ public class PluginMessageListener {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
||||
if(config.getToServerOptions().sendToServer()){
|
||||
|
@ -16,11 +16,11 @@ import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ProxyListener {
|
||||
private AuthMeConfig.Config config;
|
||||
public final class ProxyListener {
|
||||
private final AuthMeConfig config;
|
||||
private final AuthmeVelocityAPI api;
|
||||
|
||||
public ProxyListener(@NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
|
||||
public ProxyListener(@NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
|
||||
this.config = config;
|
||||
this.api = api;
|
||||
}
|
||||
|
22
proxy/src/main/resources/config.toml
Normal file
22
proxy/src/main/resources/config.toml
Normal file
@ -0,0 +1,22 @@
|
||||
# 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"
|
Loading…
x
Reference in New Issue
Block a user