feat(paper): Implement Paper Debug
feat(velocity): improved PluginMessageListener
This commit is contained in:
parent
6063375180
commit
315f6b043b
@ -41,4 +41,6 @@ tasks {
|
|||||||
|
|
||||||
options.release.set(17)
|
options.release.set(17)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
@ -10,6 +10,7 @@ dependencies {
|
|||||||
compileOnly("org.spongepowered:configurate-hocon:4.1.2")
|
compileOnly("org.spongepowered:configurate-hocon:4.1.2")
|
||||||
compileOnly("org.slf4j:slf4j-api:1.7.36")
|
compileOnly("org.slf4j:slf4j-api:1.7.36")
|
||||||
compileOnly("net.byteflux:libby-core:1.1.5")
|
compileOnly("net.byteflux:libby-core:1.1.5")
|
||||||
|
compileOnly("net.kyori:adventure-api:4.11.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package me.adrianed.authmevelocity.common;
|
package me.adrianed.authmevelocity.common;
|
||||||
|
|
||||||
|
import net.kyori.adventure.util.Index;
|
||||||
|
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
LOGIN, REGISTER, LOGOUT, FORCE_UNREGISTER, UNREGISTER;
|
LOGIN, REGISTER, LOGOUT, FORCE_UNREGISTER, UNREGISTER;
|
||||||
|
|
||||||
|
public static final Index<String, MessageType> INDEX = Index.create((value) -> value.toString(), MessageType.values());
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
|||||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
|
|
||||||
public class Loader {
|
public final class Loader {
|
||||||
|
private Loader() {}
|
||||||
public static <C> ConfigurationContainer<C> loadMainConfig(final Path path, Class<C> clazz, Logger logger){
|
public static <C> ConfigurationContainer<C> loadMainConfig(final Path path, Class<C> clazz, Logger logger){
|
||||||
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
||||||
.defaultOptions(opts -> opts
|
.defaultOptions(opts -> opts
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package me.adrianed.authmevelocity.common.configuration;
|
package me.adrianed.authmevelocity.common.configuration;
|
||||||
|
|
||||||
public interface PaperConfiguration {
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
boolean debug();
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
|
|
||||||
|
@ConfigSerializable
|
||||||
|
public class PaperConfiguration {
|
||||||
|
@Comment("Enable Debug Mode")
|
||||||
|
private boolean debug = false;
|
||||||
|
public boolean debug() {
|
||||||
|
return this.debug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,12 @@ import java.util.List;
|
|||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class ProxyConfiguration {
|
public class ProxyConfiguration {
|
||||||
|
@Comment("Enable debug mode")
|
||||||
|
private boolean debug = false;
|
||||||
|
public boolean debug() {
|
||||||
|
return this.debug;
|
||||||
|
}
|
||||||
|
|
||||||
@Comment("List of login/registration servers")
|
@Comment("List of login/registration servers")
|
||||||
private List<String> authServers = List.of("auth1", "auth2");
|
private List<String> authServers = List.of("auth1", "auth2");
|
||||||
public List<String> authServers() {
|
public List<String> authServers() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
group = me.adrianed.authmevelocity
|
group = me.adrianed.authmevelocity
|
||||||
version = 3.0.0-SNAPSHOT
|
version = 3.0.0-SNAPSHOT
|
||||||
description = A global chat regulator for you Velocity network
|
description = AuthMe Bridge with Velocity Proxy
|
||||||
url = https://forums.velocitypowered.com/t/chatregulator-a-global-chat-regulator-for-velocity/962
|
url = https://github.com/4drian3d/AuthMeVelocity
|
||||||
id = chatregulator
|
id = authmevelocity
|
||||||
|
|
||||||
caffeine-version = 3.1.1
|
caffeine-version = 3.1.1
|
||||||
configurate-version = 4.1.2
|
configurate-version = 4.1.2
|
||||||
|
@ -2,7 +2,11 @@ package me.adrianed.authmevelocity.paper;
|
|||||||
|
|
||||||
import me.adrianed.authmevelocity.paper.listeners.AuthMeListener;
|
import me.adrianed.authmevelocity.paper.listeners.AuthMeListener;
|
||||||
import me.adrianed.authmevelocity.paper.listeners.MessageListener;
|
import me.adrianed.authmevelocity.paper.listeners.MessageListener;
|
||||||
|
import me.adrianed.authmevelocity.common.configuration.ConfigurationContainer;
|
||||||
|
import me.adrianed.authmevelocity.common.configuration.Loader;
|
||||||
|
import me.adrianed.authmevelocity.common.configuration.PaperConfiguration;
|
||||||
import me.adrianed.authmevelocity.common.MessageType;
|
import me.adrianed.authmevelocity.common.MessageType;
|
||||||
|
import me.adrianed.authmevelocity.common.LibsManager;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
@ -11,13 +15,23 @@ 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;
|
||||||
|
|
||||||
public class AuthMeVelocityPlugin extends JavaPlugin {
|
import net.byteflux.libby.BukkitLibraryManager;
|
||||||
|
|
||||||
|
public final class AuthMeVelocityPlugin extends JavaPlugin {
|
||||||
private static final String CHANNEL = "authmevelocity:main";
|
private static final String CHANNEL = "authmevelocity:main";
|
||||||
|
|
||||||
|
private ConfigurationContainer<PaperConfiguration> config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
final LibsManager libraries
|
||||||
|
= new LibsManager(new BukkitLibraryManager(this));
|
||||||
|
libraries.loadLibraries();
|
||||||
|
|
||||||
|
this.config = Loader.loadMainConfig(getDataFolder().toPath(), PaperConfiguration.class, getSLF4JLogger());
|
||||||
|
|
||||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, new MessageListener());
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, new MessageListener(this));
|
||||||
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
||||||
|
|
||||||
if (this.getServer().getPluginManager().isPluginEnabled("MiniPlaceholders")) {
|
if (this.getServer().getPluginManager().isPluginEnabled("MiniPlaceholders")) {
|
||||||
@ -41,9 +55,21 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
|
|||||||
out.writeUTF(playername);
|
out.writeUTF(playername);
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
logDebug("MessageToProxy | Null Player, Player Name: "+playername);
|
||||||
Bukkit.getServer().sendPluginMessage(this, CHANNEL, out.toByteArray());
|
Bukkit.getServer().sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
} else {
|
} else {
|
||||||
|
logDebug("MessageToProxy | Player Present: "+player.getName()+", Player Name: "+playername);
|
||||||
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
player.sendPluginMessage(this, CHANNEL, out.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigurationContainer<PaperConfiguration> config() {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logDebug(String debug) {
|
||||||
|
if (config.get().debug()) {
|
||||||
|
getSLF4JLogger().info("[DEBUG] "+debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,29 +25,35 @@ public final class AuthMeListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onLogin(LoginEvent event) {
|
public void onLogin(LoginEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
plugin.logDebug("LoginEvent | Start");
|
||||||
|
|
||||||
if (new PreSendLoginEvent(player).callEvent()) {
|
if (new PreSendLoginEvent(player).callEvent()) {
|
||||||
plugin.sendMessageToProxy(player, MessageType.LOGIN, player.getName());
|
plugin.sendMessageToProxy(player, MessageType.LOGIN, player.getName());
|
||||||
|
plugin.getSLF4JLogger().info("LoginEvent | PreSendLoginEvent allowed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRegister(RegisterEvent event){
|
public void onRegister(RegisterEvent event) {
|
||||||
|
plugin.logDebug("RegisterEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER, event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogout(LogoutEvent event){
|
public void onLogout(LogoutEvent event) {
|
||||||
|
plugin.logDebug("LogoutEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT, event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onUnRegister(UnregisterByPlayerEvent event){
|
public void onUnRegister(UnregisterByPlayerEvent event) {
|
||||||
|
plugin.logDebug("UnregisterByPlayerEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.UNREGISTER, event.getPlayer().getName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.UNREGISTER, event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAdminUnRegister(UnregisterByAdminEvent event){
|
public void onAdminUnRegister(UnregisterByAdminEvent event) {
|
||||||
|
plugin.logDebug("UnregisterByAdminEvent | Executed");
|
||||||
plugin.sendMessageToProxy(event.getPlayer(), MessageType.FORCE_UNREGISTER, event.getPlayerName());
|
plugin.sendMessageToProxy(event.getPlayer(), MessageType.FORCE_UNREGISTER, event.getPlayerName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,21 +7,34 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import me.adrianed.authmevelocity.paper.AuthMeVelocityPlugin;
|
||||||
|
|
||||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||||
|
|
||||||
public class MessageListener implements PluginMessageListener {
|
public class MessageListener implements PluginMessageListener {
|
||||||
|
private final AuthMeVelocityPlugin plugin;
|
||||||
|
|
||||||
|
public MessageListener(AuthMeVelocityPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(@NotNull String identifier, @NotNull Player player, @NotNull byte[] bytes) {
|
public void onPluginMessageReceived(@NotNull String identifier, @NotNull Player player, @NotNull byte[] bytes) {
|
||||||
if (!identifier.equals("authmevelocity")) {
|
if (!identifier.equals("authmevelocity")) {
|
||||||
|
plugin.logDebug("PluginMessage | Not AuthMeVelocity identifier");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
plugin.logDebug("PluginMessage | AuthMeVelocity identifier");
|
||||||
String subchannel = input.readUTF();
|
|
||||||
|
final ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
||||||
|
final String subchannel = input.readUTF();
|
||||||
|
|
||||||
if ("main".equals(subchannel)) {
|
if ("main".equals(subchannel)) {
|
||||||
String msg = input.readUTF();
|
plugin.logDebug("PluginMessage | Main Subchannel");
|
||||||
|
final String msg = input.readUTF();
|
||||||
if ("LOGIN".equals(msg)) {
|
if ("LOGIN".equals(msg)) {
|
||||||
|
plugin.logDebug("PluginMessage | Login Message");
|
||||||
AuthMeApi.getInstance().forceLogin(player);
|
AuthMeApi.getInstance().forceLogin(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package me.adrianed.authmevelocity.velocity.listener;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.PreSendOnLoginEvent;
|
import me.adrianed.authmevelocity.api.velocity.event.PreSendOnLoginEvent;
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyForcedUnregisterEvent;
|
import me.adrianed.authmevelocity.api.velocity.event.ProxyForcedUnregisterEvent;
|
||||||
@ -9,6 +10,7 @@ import me.adrianed.authmevelocity.api.velocity.event.ProxyLoginEvent;
|
|||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyLogoutEvent;
|
import me.adrianed.authmevelocity.api.velocity.event.ProxyLogoutEvent;
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyRegisterEvent;
|
import me.adrianed.authmevelocity.api.velocity.event.ProxyRegisterEvent;
|
||||||
import me.adrianed.authmevelocity.api.velocity.event.ProxyUnregisterEvent;
|
import me.adrianed.authmevelocity.api.velocity.event.ProxyUnregisterEvent;
|
||||||
|
import me.adrianed.authmevelocity.common.MessageType;
|
||||||
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;
|
||||||
@ -53,33 +55,34 @@ public class PluginMessageListener {
|
|||||||
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
|
||||||
final ByteArrayDataInput input = event.dataAsDataStream();
|
final ByteArrayDataInput input = event.dataAsDataStream();
|
||||||
final String sChannel = input.readUTF();
|
final String message = input.readUTF();
|
||||||
final String playername = input.readUTF();
|
final MessageType type = MessageType.INDEX.value(
|
||||||
final @Nullable Player loggedPlayer = proxy.getPlayer(playername).orElse(null);
|
message.toUpperCase(Locale.ROOT));
|
||||||
switch (sChannel) {
|
final String name = input.readUTF();
|
||||||
case "LOGIN" :
|
final @Nullable Player player = proxy.getPlayer(name).orElse(null);
|
||||||
if (loggedPlayer != null && plugin.addPlayer(loggedPlayer)){
|
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
switch (type) {
|
||||||
this.createServerConnectionRequest(loggedPlayer, connection);
|
case LOGIN -> {
|
||||||
|
if (player != null && plugin.addPlayer(player)){
|
||||||
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(player));
|
||||||
|
this.createServerConnectionRequest(player, connection);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case "LOGOUT":
|
case LOGOUT -> {
|
||||||
if (loggedPlayer != null && plugin.removePlayer(loggedPlayer)){
|
if (player != null && plugin.removePlayer(player)){
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(player));
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case "REGISTER":
|
case REGISTER -> {
|
||||||
if (loggedPlayer != null)
|
if (player != null)
|
||||||
proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(player));
|
||||||
break;
|
}
|
||||||
case "UNREGISTER":
|
case UNREGISTER -> {
|
||||||
if(loggedPlayer != null)
|
if(player != null)
|
||||||
proxy.getEventManager().fireAndForget(new ProxyUnregisterEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyUnregisterEvent(player));
|
||||||
break;
|
}
|
||||||
case "FORCE_UNREGISTER":
|
case FORCE_UNREGISTER ->
|
||||||
proxy.getEventManager().fireAndForget(new ProxyForcedUnregisterEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyForcedUnregisterEvent(player));
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user