Merge pull request #68 from 4drian3d/compat/spigot
This commit is contained in:
commit
284164ba86
@ -10,7 +10,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.spongepowered:configurate-hocon:4.1.2")
|
||||
compileOnly("org.slf4j:slf4j-api:2.0.6")
|
||||
compileOnly("net.byteflux:libby-core:1.1.5")
|
||||
compileOnly("net.kyori:adventure-api:4.12.0")
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.adrianed.authmevelocity.common.configuration;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
@ -11,38 +11,29 @@ public class ConfigurationContainer<C> {
|
||||
private C config;
|
||||
private final HoconConfigurationLoader loader;
|
||||
private final Class<C> clazz;
|
||||
private final Logger logger;
|
||||
|
||||
public ConfigurationContainer(
|
||||
final C config,
|
||||
final Class<C> clazz,
|
||||
final HoconConfigurationLoader loader,
|
||||
final Logger logger
|
||||
final HoconConfigurationLoader loader
|
||||
) {
|
||||
this.config = config;
|
||||
this.loader = loader;
|
||||
this.clazz = clazz;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> reload() {
|
||||
return this.safeReload();
|
||||
}
|
||||
|
||||
public C get() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
private CompletableFuture<Boolean> safeReload() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
public CompletableFuture<Void> reload() {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
C newConfig = null;
|
||||
try {
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
newConfig = node.get(clazz);
|
||||
return true;
|
||||
} catch (ConfigurateException exception) {
|
||||
logger.error("Could not load config.conf file", exception);
|
||||
return false;
|
||||
throw new CompletionException("Could not load config.conf file", exception);
|
||||
} finally {
|
||||
if (newConfig != null) {
|
||||
config = newConfig;
|
||||
|
@ -1,17 +1,15 @@
|
||||
package me.adrianed.authmevelocity.common.configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
|
||||
public final class Loader {
|
||||
private Loader() {}
|
||||
public static <C> ConfigurationContainer<C> loadMainConfig(Path path, Class<C> clazz, Logger logger) {
|
||||
public static <C> ConfigurationContainer<C> loadMainConfig(Path path, Class<C> clazz) throws IOException {
|
||||
path = path.resolve("config.conf");
|
||||
final boolean firstCreation = Files.notExists(path);
|
||||
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
||||
@ -24,19 +22,14 @@ public final class Loader {
|
||||
.path(path)
|
||||
.build();
|
||||
|
||||
final C config;
|
||||
try {
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
config = node.get(clazz);
|
||||
if (firstCreation) {
|
||||
node.set(clazz, config);
|
||||
loader.save(node);
|
||||
}
|
||||
|
||||
} catch (ConfigurateException exception){
|
||||
logger.error("Could not load config.conf file", exception);
|
||||
return null;
|
||||
|
||||
final CommentedConfigurationNode node = loader.load();
|
||||
final C config = node.get(clazz);
|
||||
if (firstCreation) {
|
||||
node.set(clazz, config);
|
||||
loader.save(node);
|
||||
}
|
||||
return new ConfigurationContainer<>(config, clazz, loader, logger);
|
||||
|
||||
return new ConfigurationContainer<>(config, clazz, loader);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
group = me.adrianed.authmevelocity
|
||||
version = 3.0.2
|
||||
version = 3.0.3-SNAPSHOT
|
||||
description = AuthMeReloaded Support for Velocity
|
||||
url = https://github.com/4drian3d/AuthMeVelocity
|
||||
id = authmevelocity
|
||||
|
@ -12,7 +12,7 @@ repositories {
|
||||
dependencies {
|
||||
compileOnly(project(":authmevelocity-common"))
|
||||
compileOnly(project(":authmevelocity-api-paper"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.19.1-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
|
||||
compileOnly("fr.xephi:authme:5.6.0-SNAPSHOT")
|
||||
compileOnly("com.github.4drian3d:MiniPlaceholders:1.3.1")
|
||||
shadow("net.byteflux:libby-bukkit:1.1.5")
|
||||
|
@ -17,6 +17,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.byteflux.libby.BukkitLibraryManager;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
private static final String CHANNEL = "authmevelocity:main";
|
||||
|
||||
@ -24,11 +26,15 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final LibsManager libraries
|
||||
= new LibsManager(new BukkitLibraryManager(this));
|
||||
libraries.loadLibraries();
|
||||
new LibsManager(new BukkitLibraryManager(this)).loadLibraries();
|
||||
|
||||
this.config = Loader.loadMainConfig(getDataFolder().toPath(), PaperConfiguration.class, getSLF4JLogger());
|
||||
try {
|
||||
this.config = Loader.loadMainConfig(getDataFolder().toPath(), PaperConfiguration.class);
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.SEVERE, "Could not load config.conf file", e);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, new MessageListener(this));
|
||||
@ -38,7 +44,7 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
AuthmePlaceholders.getExpansion().register();
|
||||
}
|
||||
|
||||
this.getSLF4JLogger().info("AuthMeVelocity enabled");
|
||||
this.getLogger().info("AuthMeVelocity enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,10 +52,11 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
this.getServer().getMessenger().unregisterOutgoingPluginChannel(this, CHANNEL);
|
||||
this.getServer().getMessenger().unregisterIncomingPluginChannel(this, CHANNEL);
|
||||
|
||||
this.getSLF4JLogger().info("AuthmeVelocity disabled");
|
||||
this.getLogger().info("AuthMeVelocity disabled");
|
||||
}
|
||||
|
||||
public void sendMessageToProxy(final Player player, @NotNull MessageType type, @NotNull String playername) {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(type.toString());
|
||||
out.writeUTF(playername);
|
||||
@ -63,13 +70,9 @@ public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigurationContainer<PaperConfiguration> config() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public void logDebug(String debug) {
|
||||
if (config.get().debug()) {
|
||||
getSLF4JLogger().info("[DEBUG] {}", debug);
|
||||
getLogger().log(Level.INFO, "[DEBUG] {}", debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import fr.xephi.authme.events.RegisterEvent;
|
||||
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
||||
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -27,9 +28,13 @@ public final class AuthMeListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
plugin.logDebug("LoginEvent | Start");
|
||||
|
||||
if (new PreSendLoginEvent(player).callEvent()) {
|
||||
// I hate this, but... Spigot compatibility ¯\_(ツ)_/¯
|
||||
final var preSendLoginEvent = new PreSendLoginEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(preSendLoginEvent);
|
||||
|
||||
if (!preSendLoginEvent.isCancelled()) {
|
||||
plugin.sendMessageToProxy(player, MessageType.LOGIN, player.getName());
|
||||
plugin.getSLF4JLogger().info("LoginEvent | PreSendLoginEvent allowed");
|
||||
plugin.getLogger().info("LoginEvent | PreSendLoginEvent allowed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package me.adrianed.authmevelocity.paper.listeners;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import me.adrianed.authmevelocity.common.MessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -35,9 +37,9 @@ public class MessageListener implements PluginMessageListener {
|
||||
if ("main".equals(subChannel)) {
|
||||
plugin.logDebug("PluginMessage | Main Subchannel");
|
||||
final String msg = input.readUTF();
|
||||
if ("LOGIN".equals(msg)) {
|
||||
if (MessageType.LOGIN.toString().equals(msg)) {
|
||||
plugin.logDebug("PluginMessage | Login Message");
|
||||
new LoginByProxyEvent(player).callEvent();
|
||||
Bukkit.getPluginManager().callEvent(new LoginByProxyEvent(player));
|
||||
AuthMeApi.getInstance().forceLogin(player);
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,13 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||
logger, pluginDirectory, proxy.getPluginManager(), this));
|
||||
libraries.loadLibraries();
|
||||
|
||||
this.config = Loader.loadMainConfig(pluginDirectory, ProxyConfiguration.class, logger);
|
||||
try {
|
||||
this.config = Loader.loadMainConfig(pluginDirectory, ProxyConfiguration.class);
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not load config.conf file", e);
|
||||
return;
|
||||
}
|
||||
|
||||
logDebug("Loaded plugin libraries");
|
||||
|
||||
final int pluginId = 16128;
|
||||
@ -105,21 +111,21 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
|
||||
).forEach(listener ->
|
||||
proxy.getEventManager().register(this, listener));
|
||||
|
||||
boolean fastlogin = proxy.getPluginManager().isLoaded("fastlogin");
|
||||
final boolean fastlogin = proxy.getPluginManager().isLoaded("fastlogin");
|
||||
metrics.addCustomChart(new SimplePie("fastlogin_compatibility", () -> Boolean.toString(fastlogin)));
|
||||
if (fastlogin) {
|
||||
logDebug("Register FastLogin compatibility");
|
||||
proxy.getEventManager().register(this, new FastLoginListener(proxy, this));
|
||||
}
|
||||
|
||||
boolean miniplaceholders = proxy.getPluginManager().isLoaded("miniplaceholders");
|
||||
final boolean miniplaceholders = proxy.getPluginManager().isLoaded("miniplaceholders");
|
||||
metrics.addCustomChart(new SimplePie("miniplaceholders_compatibility", () -> Boolean.toString(miniplaceholders)));
|
||||
if (miniplaceholders) {
|
||||
logDebug("Register MiniPlaceholders compatibility");
|
||||
AuthMePlaceholders.getExpansion(this).register();
|
||||
}
|
||||
|
||||
AuthmeCommand.register(this, proxy.getCommandManager());
|
||||
AuthmeCommand.register(this, proxy.getCommandManager(), logger);
|
||||
|
||||
this.sendInfoMessage();
|
||||
}
|
||||
|
@ -10,25 +10,28 @@ import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
import me.adrianed.authmevelocity.velocity.AuthMeVelocityPlugin;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class AuthmeCommand {
|
||||
private AuthmeCommand() {}
|
||||
|
||||
public static void register(AuthMeVelocityPlugin plugin, CommandManager manager) {
|
||||
public static void register(AuthMeVelocityPlugin plugin, CommandManager manager, Logger logger) {
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder.<CommandSource>literal("authmevelocity")
|
||||
.requires(src -> src.hasPermission("authmevelocity.commands"))
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
||||
.executes(cmd -> {
|
||||
CommandSource source = cmd.getSource();
|
||||
plugin.config().reload().thenAcceptAsync(result -> {
|
||||
if(result) {
|
||||
plugin.config().reload().handleAsync((v, ex) -> {
|
||||
if (ex == null) {
|
||||
plugin.sendInfoMessage();
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<aqua>AuthmeVelocity <green>has been successfully reloaded"));
|
||||
"<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"));
|
||||
"<dark_red>There was an error while reloading the configuration. <red>Check the server console"));
|
||||
logger.error(ex.getMessage(), ex.getCause());
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user