From 7c3ffc80c355553301060239bfbf590f2bb35aec Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 1 Jul 2024 19:50:19 +0200 Subject: [PATCH] . --- pom.xml | 6 +- .../SPIGOT/api/messages/T2ChoverModule.java | 1 + .../SPIGOT/api/messages/T2Ctemplate.java | 6 +- .../SPIGOT/system/T2CodeLibMain.java | 10 +- .../VELOCITY/api/messages/T2CVsend.java | 7 ++ .../{T2CplmsgBcmd.java => T2CVplmsgCmd.java} | 14 +-- ...Response.java => T2CVapiAutoResponse.java} | 12 +- .../commandgui/T2CVapiCGUI.java | 10 +- ...OpSecurity.java => T2CVapiOpSecurity.java} | 12 +- .../api/proxyPlayers/T2CVPlayers.java | 111 ++++++++++++++++++ .../VELOCITY/system/T2CodeVMain.java | 31 +++-- .../VELOCITY/system/config/T2CVlibConfig.java | 2 + 12 files changed, 186 insertions(+), 36 deletions(-) rename src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/{T2CplmsgBcmd.java => T2CVplmsgCmd.java} (79%) rename src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/{T2CapiAutoResponse.java => T2CVapiAutoResponse.java} (85%) rename src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/{T2CapiOpSecurity.java => T2CVapiOpSecurity.java} (83%) create mode 100644 src/main/java/net/t2code/t2codelib/VELOCITY/api/proxyPlayers/T2CVPlayers.java diff --git a/pom.xml b/pom.xml index c0cefd8..5a056b7 100644 --- a/pom.xml +++ b/pom.xml @@ -27,8 +27,8 @@ maven-compiler-plugin 3.8.1 - 11 - 11 + 9 + 9 @@ -238,7 +238,7 @@ org.json json - 20230227 + 20231013 compile diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java index 7dbbd17..24718e1 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java @@ -26,6 +26,7 @@ public class T2ChoverModule { } public static void moduleConsole(String msg) { + Bukkit.getConsoleSender().sendMessage(msg); //todo if (T2CodeLibMain.getMmIsLoad()) { T2CminiMessage.sendConsoleMiniMessage(msg); return; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java index b3a89ca..3d77367 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java @@ -14,15 +14,15 @@ import java.util.List; import java.util.logging.Level; public class T2Ctemplate { - public static @NotNull Long onLoadHeader(String prefix, List autor, String version, String spigot, String discord) { + public static Long onLoadHeader(String prefix, List autor, String version, String spigot, String discord) { return onLoadHeader(prefix, autor, version, spigot, discord, null, null); } - public static @NotNull Long onLoadHeader(String prefix, List autor, String version, String spigot, String discord, Boolean isPremium) { + public static Long onLoadHeader(String prefix, List autor, String version, String spigot, String discord, Boolean isPremium) { return onLoadHeader(prefix, autor, version, spigot, discord, isPremium, null); } - public static Long onLoadHeader(@NotNull String prefix, @NotNull List autor, @NotNull String version, @NotNull String spigot, @NotNull String discord, Boolean isPremium, Boolean isVerify) { + public static Long onLoadHeader( String prefix, List autor, String version, String spigot, String discord, Boolean isPremium, Boolean isVerify) { Long long_ = System.currentTimeMillis(); /** diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index b9ef9c6..7cde812 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -2,10 +2,12 @@ package net.t2code.t2codelib.SPIGOT.system; import lombok.Getter; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayers; import net.t2code.t2codelib.SPIGOT.api.items.T2CitemVersion; +import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; @@ -43,23 +45,25 @@ public final class T2CodeLibMain extends JavaPlugin { @Getter private static Boolean mmIsLoad = true; private static Boolean load = false; + @Getter private static T2CplatformDetector.PlatformType plattform; - public static Logger logger; + // public static Logger logger; @Override public void onEnable() { // Plugin startup logic plugin = this; autor = plugin.getDescription().getAuthors(); - logger = getLogger(); + // logger = getLogger(); version = plugin.getDescription().getVersion(); - plattform = T2CplatformDetector.detectPlatform(); + try { adventure = BukkitAudiences.create(this); } catch (Exception e) { mmIsLoad = false; } + plattform = T2CplatformDetector.detectPlatform(); long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord(), null, null); checkIsBungee(); diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/messages/T2CVsend.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/messages/T2CVsend.java index 7ef4509..ec9c858 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/api/messages/T2CVsend.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/messages/T2CVsend.java @@ -4,6 +4,8 @@ import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; +import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig; +import net.t2code.t2codelib.VELOCITY.system.config.T2CVlibConfig; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -65,6 +67,11 @@ public class T2CVsend { logger.warn(msg); } + public static void debug(Logger logger, String msg) { + if (!(boolean)T2CVlibConfig.VALUES.debug.getValue()) return; + logger.warn(msg); + } + public static void info(Logger logger, String msg) { logger.info(msg); } diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CplmsgBcmd.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CVplmsgCmd.java similarity index 79% rename from src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CplmsgBcmd.java rename to src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CVplmsgCmd.java index 83ec498..928689e 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CplmsgBcmd.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/T2CVplmsgCmd.java @@ -6,7 +6,6 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PluginMessageEvent; -import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import net.t2code.t2codelib.Util; @@ -14,14 +13,15 @@ import net.t2code.t2codelib.VELOCITY.api.commands.T2CVcmd; import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain; import org.slf4j.Logger; -public class T2CplmsgBcmd { +public class T2CVplmsgCmd { - private static final ProxyServer server = T2CodeVMain.getServer(); - private static final Logger logger = T2CodeVMain.getLogger(); + private final ProxyServer server; + private final Logger logger; - @Subscribe - public void onProxyInitialization(ProxyInitializeEvent event) { + public T2CVplmsgCmd(ProxyServer server, Logger logger) { + this.server = server; + this.logger = logger; server.getChannelRegistrar().register(T2CodeVMain.bcmd); } @@ -46,7 +46,7 @@ public class T2CplmsgBcmd { } else { Player player = server.getPlayer(channel).orElse(null); if (player != null) { - logger.info("{} [{}] T2C BCMD Command {}: {}", Util.getVPrefix(), serverID, player, input); + logger.info("{} [{}] T2C BCMD Command {}: {}", Util.getVPrefix(), serverID, player, input); T2CVcmd.Player(player, input); } } diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CapiAutoResponse.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CVapiAutoResponse.java similarity index 85% rename from src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CapiAutoResponse.java rename to src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CVapiAutoResponse.java index d578d71..d7548ba 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CapiAutoResponse.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/autoResponse/T2CVapiAutoResponse.java @@ -15,9 +15,15 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; -public class T2CapiAutoResponse { - private static final ProxyServer server = T2CodeVMain.getServer(); - private static final Logger logger = T2CodeVMain.getLogger(); +public class T2CVapiAutoResponse { + private final ProxyServer server; + private final Logger logger; + + public T2CVapiAutoResponse(ProxyServer server, Logger logger) { + this.server = server; + this.logger = logger; + server.getChannelRegistrar().register(T2CodeVMain.aresp); + } @Subscribe public void onPluginmessage(PluginMessageEvent event) { diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/commandgui/T2CVapiCGUI.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/commandgui/T2CVapiCGUI.java index c4e64bd..b0cc059 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/commandgui/T2CVapiCGUI.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/commandgui/T2CVapiCGUI.java @@ -17,8 +17,14 @@ import java.io.IOException; public class T2CVapiCGUI { - private static final ProxyServer server = T2CodeVMain.getServer(); - private static final Logger logger = T2CodeVMain.getLogger(); + private static ProxyServer server; + private static Logger logger; + + public T2CVapiCGUI(ProxyServer server, Logger logger) { + T2CVapiCGUI.server = server; + T2CVapiCGUI.logger = logger; + server.getChannelRegistrar().register(T2CodeVMain.cguiopl); + } @Subscribe diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CapiOpSecurity.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CVapiOpSecurity.java similarity index 83% rename from src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CapiOpSecurity.java rename to src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CVapiOpSecurity.java index 3fe7999..0f494ea 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CapiOpSecurity.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/pluginMessaging/opSecurity/T2CVapiOpSecurity.java @@ -11,9 +11,15 @@ import org.slf4j.Logger; import java.io.*; -public class T2CapiOpSecurity { - private static final ProxyServer server = T2CodeVMain.getServer(); - private static final Logger logger = T2CodeVMain.getLogger(); +public class T2CVapiOpSecurity { + private static ProxyServer server ; + private static Logger logger ; + + public T2CVapiOpSecurity(ProxyServer server, Logger logger) { + T2CVapiOpSecurity.server = server; + T2CVapiOpSecurity.logger = logger; + server.getChannelRegistrar().register(T2CodeVMain.opsec); + } @Subscribe public void onPluginmessage(PluginMessageEvent event) { diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/api/proxyPlayers/T2CVPlayers.java b/src/main/java/net/t2code/t2codelib/VELOCITY/api/proxyPlayers/T2CVPlayers.java new file mode 100644 index 0000000..5faae36 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/api/proxyPlayers/T2CVPlayers.java @@ -0,0 +1,111 @@ +// This class was created by JaTiTV. + +package net.t2code.t2codelib.VELOCITY.api.proxyPlayers; + + + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayersEnum; +import net.t2code.t2codelib.VELOCITY.api.messages.T2CVsend; +import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain; +import org.slf4j.Logger; + +import java.io.*; + + +public class T2CVPlayers { + + public static ProxyServer server = T2CodeVMain.getServer(); + public static Logger logger = T2CodeVMain.getLogger(); + + @Subscribe + public void onJoin(PostLoginEvent e) { + sendToSpigotPlayer(e.getPlayer().getUsername(), T2CbungeePlayersEnum.JOIN, ""); + } + + @Subscribe + public void onDisconnect(DisconnectEvent e) { + sendToSpigotPlayer(e.getPlayer().getUsername(), T2CbungeePlayersEnum.QUIT, ""); + } + + public void sendToSpigotPlayer(String name, T2CbungeePlayersEnum value, String uuid) { + switch (value) { + case JOIN: + case QUIT: + sendToSpigotPlayerExecute(name, value, uuid); + break; + case GIVEALL: + StringBuilder input = new StringBuilder(); + for (Player player : server.getAllPlayers()) { + input.append(player.getUsername()).append(";"); + } + sendToSpigotPlayerExecute(input.toString(), T2CbungeePlayersEnum.GIVEALL, uuid); + break; + } + } + + private void sendToSpigotPlayerExecute(String name, T2CbungeePlayersEnum value, String uuid) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(stream); + try { + output.writeUTF(value.name()); + output.writeUTF(name); + output.writeUTF(uuid); + } catch (IOException e) { + logger.error (e.getMessage()); + } + T2CVsend.debug(logger, "PluginMessage received channel: t2c:bonlp"); + T2CVsend.debug(logger, "PluginMessage received subChannel: " + value.name()); + T2CVsend.debug(logger, "PluginMessage received input: " + name); + T2CVsend.debug(logger, "PluginMessage received input2/uuid: " + uuid); + byte[] data = stream.toByteArray(); + for (RegisteredServer server : server.getAllServers()) { + server.sendPluginMessage(T2CodeVMain.bonlp, data); + } + + } + + public static void sendToSpigotDeleteAll() { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream output = new DataOutputStream(stream); + try { + output.writeUTF(T2CbungeePlayersEnum.CLEAR.name()); + output.writeUTF(""); + output.writeUTF(""); + } catch (IOException e) { + logger.error(e.getMessage()); + } + byte[] data = stream.toByteArray(); + for (RegisteredServer server : server.getAllServers()) { + server.sendPluginMessage(T2CodeVMain.bonlp, data); + } + } + + @Subscribe + public void onPluginMessage(PluginMessageEvent event) { + if (event.getIdentifier() != T2CodeVMain.bonlp) { + return; + } + DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData())); + + try { + T2CbungeePlayersEnum subChannel = T2CbungeePlayersEnum.valueOf(stream.readUTF()); + String input = stream.readUTF(); + + T2CVsend.debug(logger, "PluginMessage received channel: " + T2CodeVMain.bonlp); + T2CVsend.debug(logger, "PluginMessage received subChannel: " + subChannel.name()); + T2CVsend.debug(logger, "PluginMessage received input/uuid: " + input); + + sendToSpigotPlayer("", subChannel, input); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/system/T2CodeVMain.java b/src/main/java/net/t2code/t2codelib/VELOCITY/system/T2CodeVMain.java index 8fe4cae..417e13b 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/system/T2CodeVMain.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/system/T2CodeVMain.java @@ -12,6 +12,11 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import lombok.Getter; import net.t2code.t2codelib.Util; +import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.T2CVplmsgCmd; +import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.autoResponse.T2CVapiAutoResponse; +import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.commandgui.T2CVapiCGUI; +import net.t2code.t2codelib.VELOCITY.api.pluginMessaging.opSecurity.T2CVapiOpSecurity; +import net.t2code.t2codelib.VELOCITY.api.proxyPlayers.T2CVPlayers; import net.t2code.t2codelib.VELOCITY.api.update.T2CVupdateAPI; import net.t2code.t2codelib.VELOCITY.system.bstats.Metrics; import net.t2code.t2codelib.VELOCITY.system.config.T2CVlibConfig; @@ -70,7 +75,7 @@ public class T2CodeVMain { logger.info("║ Discord: {}", Util.getDiscord()); try { - T2CVlibConfig.set(dataDirectory,logger); + T2CVlibConfig.set(dataDirectory, logger); } catch (IOException ex) { throw new RuntimeException(ex); } @@ -79,23 +84,25 @@ public class T2CodeVMain { // server.getEventManager().register(this, new T2CVpluginMessagingCmd(server, logger)); //API - server.getChannelRegistrar().register(T2CodeVMain.bcmd); + + server.getEventManager().register(this, new T2CVplmsgCmd(server, logger)); + server.getChannelRegistrar().register(T2CodeVMain.bonlp); T2CVPlayers.sendToSpigotDeleteAll(); - // if (T2CVlibConfig.getApiCommandGUIEnable()) { - server.getChannelRegistrar().register(T2CodeVMain.cguiopl); - T2CVapiCGUI.sendToSpigotDeleteAll(); - // } + if ((boolean) T2CVlibConfig.VALUES.apiCommandGUIEnable.getValue()) { + server.getEventManager().register(this, new T2CVapiCGUI(server, logger)); + T2CVapiCGUI.sendToSpigotDeleteAll(); + } - // if (T2CVlibConfig.getApiAutoResponse()) { - server.getChannelRegistrar().register(T2CodeVMain.aresp); - // } + if ((boolean) T2CVlibConfig.VALUES.apiAutoResponse.getValue()) { + server.getEventManager().register(this, new T2CVapiAutoResponse(server, logger)); + } - // if (T2CVlibConfig.getApiOpSecurity()) { - server.getChannelRegistrar().register(T2CodeVMain.opsec); - //} + if ((boolean) T2CVlibConfig.VALUES.apiOpSecurity.getValue()) { + server.getEventManager().register(this, new T2CVapiOpSecurity(server, logger)); + } Metrics.bStats(this, Util.getBstatsID(), metricsFactory); diff --git a/src/main/java/net/t2code/t2codelib/VELOCITY/system/config/T2CVlibConfig.java b/src/main/java/net/t2code/t2codelib/VELOCITY/system/config/T2CVlibConfig.java index 3de0ec6..c8ee0e8 100644 --- a/src/main/java/net/t2code/t2codelib/VELOCITY/system/config/T2CVlibConfig.java +++ b/src/main/java/net/t2code/t2codelib/VELOCITY/system/config/T2CVlibConfig.java @@ -20,6 +20,8 @@ public class T2CVlibConfig { updateTimer("updateCheck.timerInMin", 60, "In this option you can set the time interval in minutes in which updates should be checked."), seePreReleaseUpdates("updateCheck.seePreReleaseUpdates", true, "In this option you can set whether you want to receive and display beta and snapshot versions in the update check."), + debug("plugin.debug.debugModus", false, "The debug mode sends more detailed debug information to the console."), + apiCommandGUIEnable("api.commandGUI.enable", false, "With this option you activate the api interface for the T2C-CommandGUI plugin."), apiAutoResponse("api.autoResponse.enable", false, "With this option you activate the api interface for the T2C-AutoResponse plugin."), apiOpSecurity("api.opSecurity.enable", false, "With this option you activate the api interface for the T2C-OPSecurity plugin."),