Merge pull request #42 from 4drian3d/feat/command
This commit is contained in:
commit
30023ece19
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.1.1</version>
|
||||
<version>2.2.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>2.1.1</version>
|
||||
<version>2.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.glyart.authmevelocity.proxy;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.commands.AuthmeCommand;
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||
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.command.CommandSource;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
@ -13,14 +15,18 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
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.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -32,7 +38,9 @@ public class AuthMeVelocityPlugin {
|
||||
private final Logger logger;
|
||||
private final Path pluginDirectory;
|
||||
private AuthmeVelocityAPI api;
|
||||
private AuthMeConfig config;
|
||||
|
||||
private final List<Object> listeners = new ArrayList<>(3);
|
||||
protected final Set<UUID> loggedPlayers = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
@Inject
|
||||
@ -44,30 +52,20 @@ public class AuthMeVelocityPlugin {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
Toml toml = this.loadConfig(pluginDirectory);
|
||||
if (toml == null) {
|
||||
if (!this.reload()) {
|
||||
logger.warn("Failed to load config.toml. Shutting down.");
|
||||
return;
|
||||
}
|
||||
AuthMeConfig config = new AuthMeConfig(toml);
|
||||
this.api = new AuthmeVelocityAPI(this, config);
|
||||
proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL);
|
||||
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")) {
|
||||
proxy.getEventManager().register(this, new FastLoginListener(proxy, api));
|
||||
}
|
||||
proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL);
|
||||
|
||||
if (proxy.getPluginManager().isLoaded("miniplaceholders")) {
|
||||
AuthmePlaceholders.getExpansion(this).register();
|
||||
}
|
||||
|
||||
logger.info("-- AuthMeVelocity enabled --");
|
||||
logger.info("AuthServers: {}", config.getAuthServers());
|
||||
if (config.getToServerOptions().sendToServer()) {
|
||||
logger.info("LobbyServers: {}", config.getToServerOptions().getTeleportServers());
|
||||
}
|
||||
AuthmeCommand.register(this, proxy.getCommandManager());
|
||||
|
||||
this.sendInfoMessage();
|
||||
}
|
||||
|
||||
protected ProxyServer getProxy(){
|
||||
@ -93,9 +91,46 @@ public class AuthMeVelocityPlugin {
|
||||
|
||||
return new Toml().read(Files.newInputStream(configPath));
|
||||
} catch (IOException ex) {
|
||||
logger.info("An error ocurred on configuration initialization", ex);
|
||||
logger.error("An error ocurred on configuration initialization", ex);
|
||||
return null;
|
||||
} catch(IllegalStateException ex) {
|
||||
logger.error("Invalid configuration provided", ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean reload() {
|
||||
Toml toml = this.loadConfig(pluginDirectory);
|
||||
if (toml == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.config = new AuthMeConfig(toml);
|
||||
this.api = new AuthmeVelocityAPI(this, config);
|
||||
|
||||
listeners.forEach(listener -> proxy.getEventManager().unregisterListener(this, listener));
|
||||
listeners.clear();
|
||||
|
||||
listeners.add(new ProxyListener(config, api, logger, proxy));
|
||||
listeners.add(new PluginMessageListener(proxy, logger, config, api));
|
||||
|
||||
if (proxy.getPluginManager().isLoaded("fastlogin")) {
|
||||
listeners.add(new FastLoginListener(proxy, api));
|
||||
}
|
||||
|
||||
listeners.forEach(listener -> proxy.getEventManager().register(this, listener));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendInfoMessage() {
|
||||
CommandSource source = proxy.getConsoleCommandSource();
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
" <gray>--- <aqua>AuthMeVelocity</aqua> ---"));
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<gray>AuthServers: <green>" + config.getAuthServers()));
|
||||
if (config.getToServerOptions().sendToServer()) {
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<gray>LobbyServers: <green>" + config.getToServerOptions().getTeleportServers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.glyart.authmevelocity.proxy.commands;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public class AuthmeCommand {
|
||||
private AuthmeCommand() {}
|
||||
|
||||
public static void register(AuthMeVelocityPlugin plugin, CommandManager manager) {
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder.<CommandSource>literal("authmevelocity")
|
||||
.requires(src -> src.hasPermission("authmevelocity.commands"))
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
||||
.executes(cmd -> {
|
||||
CommandSource source = cmd.getSource();
|
||||
if (plugin.reload()) {
|
||||
plugin.sendInfoMessage();
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<aqua>AuthmeVelocity <green>has been successfully reloaded"));
|
||||
} else {
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<dark_red>There was an error while reloading the configuration. <red>Check the server console"));
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
).build();
|
||||
|
||||
BrigadierCommand brigadier = new BrigadierCommand(command);
|
||||
CommandMeta meta = manager.metaBuilder(brigadier)
|
||||
.plugin(plugin)
|
||||
.aliases("vauthme", "authmev")
|
||||
.build();
|
||||
|
||||
manager.register(meta, brigadier);
|
||||
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>2.1.1</version>
|
||||
<version>2.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user