From 034bf241e587d876d6fb859fbf262ad019e2e9ee Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 19 Jun 2023 21:17:49 +0200 Subject: [PATCH] 15.2 Changes: Commands: - The command '/t2code serverid' has been added to display the server ID assigned by the T2CodeLib. - The command '/t2code bcmd ' was added to execute a bungee command from a spigot plugin DebugLog: - The number of offline players is now displayed in T2CoderLog.txt - The offline players as well as the plugins in the T2CoderLog.txt are now listed in alphabetical order - Smaller code changes --- pom.xml | 2 +- .../BUNGEE/api/update/T2CBupdateAPI.java | 1 - .../t2codelib/BUNGEE/system/T2CBload.java | 2 +- .../t2codelib/BUNGEE/system/T2CodeBMain.java | 2 - .../system/pluginMessaging/T2CplmsgBcmd.java | 6 ++- .../system/T2CbungeeCommandSenderReciver.java | 19 ++++++--- .../SPIGOT/system/T2CodeLibMain.java | 1 + .../SPIGOT/system/cmd/CmdExecuter.java | 42 +++++++++++++++---- .../t2codelib/SPIGOT/system/cmd/Commands.java | 1 + .../SPIGOT/system/cmd/CreateReportLog.java | 19 ++++++++- 10 files changed, 71 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 4c2bf99..365190a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 15.1 + 15.2 diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java index c9450d0..f575d81 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java @@ -5,7 +5,6 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend; import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig; -import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import net.t2code.t2codelib.UpdateType; diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java index 11623dc..4aef1a1 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java @@ -34,7 +34,7 @@ public class T2CBload { throw new RuntimeException(e); } - T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, discord, spigotID,url); + T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, discord, spigotID, url); //API plugin.getProxy().registerChannel("t2c:bcmd"); diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java index 4202e1a..18386da 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java @@ -43,8 +43,6 @@ public class T2CodeBMain extends Plugin { mmIsLoad = false; } T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID(),Util.getGit()); - String[] fv = orgVersion.split("_"); - plugin.getDescription().setVersion(fv[0]); version = plugin.getDescription().getVersion(); } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/pluginMessaging/T2CplmsgBcmd.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/pluginMessaging/T2CplmsgBcmd.java index d2bad03..29a6867 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/pluginMessaging/T2CplmsgBcmd.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/pluginMessaging/T2CplmsgBcmd.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; +import net.t2code.t2codelib.Util; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -19,13 +20,14 @@ public class T2CplmsgBcmd implements Listener { try { String channel = stream.readUTF(); String input = stream.readUTF(); + String serverID = stream.readUTF(); if (channel.equals("T2Code-Console")) { - ProxyServer.getInstance().getConsole().sendMessage("Command Console: "+ input); + ProxyServer.getInstance().getConsole().sendMessage(Util.getPrefix()+" [§6"+serverID+"§r] §cT2C BCMD Command Console: §r"+ input); ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), input); } else { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(channel); if (player != null) { - ProxyServer.getInstance().getConsole().sendMessage("Command " + player +": "+ input); + ProxyServer.getInstance().getConsole().sendMessage(Util.getPrefix()+" [§6"+serverID+"§r] §cT2C BCMD Command §r" + player +": "+ input); ProxyServer.getInstance().getPluginManager().dispatchCommand(player, input); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CbungeeCommandSenderReciver.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CbungeeCommandSenderReciver.java index b585d5e..8726f6d 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CbungeeCommandSenderReciver.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CbungeeCommandSenderReciver.java @@ -1,5 +1,7 @@ package net.t2code.t2codelib.SPIGOT.system; +import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; +import net.t2code.t2codelib.Util; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -7,6 +9,7 @@ import org.bukkit.entity.Player; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Arrays; public class T2CbungeeCommandSenderReciver { @@ -24,18 +27,22 @@ public class T2CbungeeCommandSenderReciver { } } output.writeUTF(information); + output.writeUTF(String.valueOf(Util.getServerUUID())); } catch (IOException e) { e.printStackTrace(); } if (sender instanceof Player) { Player player = (Player) sender; player.sendPluginMessage(T2CodeLibMain.getPlugin(), "t2c:bcmd", stream.toByteArray()); - }else { - for(Player player : Bukkit.getOnlinePlayers()){ - player.sendPluginMessage(T2CodeLibMain.getPlugin(), "t2c:bcmd", stream.toByteArray()); - return; - } + T2Cdebug.debug(T2CodeLibMain.getPlugin(), "PluginMessage received T2CbungeeCommandSenderReciver: t2c:bcmd - " + Arrays.toString(stream.toByteArray()) + " Player: " + player.getName()); + } else { + + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendPluginMessage(T2CodeLibMain.getPlugin(), "t2c:bcmd", stream.toByteArray()); + T2Cdebug.debug(T2CodeLibMain.getPlugin(), "PluginMessage received T2CbungeeCommandSenderReciver: t2c:bcmd - " + Arrays.toString(stream.toByteArray()) + " Player: " + player.getName()); + return; + } + //todo } } - } 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 f20ed2c..7249ae2 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -111,6 +111,7 @@ public final class T2CodeLibMain extends JavaPlugin { Metrics.Bstats(plugin, Util.getBstatsID()); if (SelectLibConfig.getBungee()) { Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); + T2Csend.debug(plugin, "registerIncomingPluginChannel §et2c:bcmd"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bonlp"); if (!Bukkit.getMessenger().isIncomingChannelRegistered(plugin, "t2c:bonlp")) { diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java index 8723408..822ce3b 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java @@ -1,8 +1,11 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; +import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayers; +import net.t2code.t2codelib.SPIGOT.system.T2CbungeeCommandSenderReciver; +import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.Util; @@ -38,18 +41,31 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { Commands.info(sender); return false; case "updateinfo": - Commands.updateInfo(sender,args); + Commands.updateInfo(sender, args); return false; case "reloadconfig": SelectLibConfig.onSelect(); T2Csend.sender(sender, Util.getPrefix() + " §2Config successfully reloaded"); return false; case "debug": - Commands.debug(sender,args); + Commands.debug(sender, args); return false; case "test": T2Csend.sender(sender, T2CbungeePlayers.getBungeePlayers().toString()); return false; + case "serverid": + T2Csend.sender(sender, ("[prefix] T2C ServerID: copy'>" + + "[id]").replace("[prefix]", Util.getPrefix()).replace("[id]", String.valueOf(Util.getServerUUID()))); + return false; + case "bcmd": + String cmd = ""; + for (String s : args) { + cmd = cmd + s + " "; + } + cmd = cmd.replace("bcmd ", ""); + T2CbungeeCommandSenderReciver.sendToBungee(null, cmd, true); + T2Cdebug.debug(T2CodeLibMain.getPlugin(), "PluginMessage BCMD: " + cmd); + return false; default: T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); @@ -61,6 +77,8 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { private static HashMap arg1 = new HashMap() {{ put("debug", "t2code.admin"); put("info", "t2code.admin"); + put("serverid", "t2code.admin"); + put("bcmd", "t2code.admin"); put("reloadconfig", "t2code.admin"); put("updateinfo", "t2code.admin"); }}; @@ -81,17 +99,23 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { if (args.length == 2 && args[0].equalsIgnoreCase("debug")) { if (sender.hasPermission("t2code.admin")) { if (hasPermission(p, arg1.get("debug"))) { - if (passend("createReportLog",args[1])) list.add("createReportLog"); - if (passend("deleteReportLog",args[1])) list.add("deleteReportLog"); + if (passend("createReportLog", args[1])) list.add("createReportLog"); + if (passend("deleteReportLog", args[1])) list.add("deleteReportLog"); } } return list; } + if (args.length == 2 && args[0].equalsIgnoreCase("bcmd")) { + if (sender.hasPermission("t2code.admin")) { + list.add(""); + } + return list; + } if (args.length == 2 && args[0].equalsIgnoreCase("updateinfo")) { if (sender.hasPermission("t2code.admin")) { if (hasPermission(p, arg1.get("updateinfo"))) { - for (Map.Entry pl : T2CupdateAPI.pluginVersions.entrySet()){ - if (passend(pl.getValue().pluginName,args[1])) list.add(pl.getValue().pluginName); + for (Map.Entry pl : T2CupdateAPI.pluginVersions.entrySet()) { + if (passend(pl.getValue().pluginName, args[1])) list.add(pl.getValue().pluginName); } } } @@ -99,11 +123,11 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { } - if (args.length == 3 && args[0].equalsIgnoreCase("debug")&& args[1].equalsIgnoreCase("deleteReportLog")) { + if (args.length == 3 && args[0].equalsIgnoreCase("debug") && args[1].equalsIgnoreCase("deleteReportLog")) { if (sender.hasPermission("t2code.admin")) { if (hasPermission(p, arg1.get("debug"))) { - for (String st : ReportLogStorage.list){ - if (passend(st,args[2])) list.add(st); + for (String st : ReportLogStorage.list) { + if (passend(st, args[2])) list.add(st); } } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java index 81c2e25..3f6e730 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java @@ -3,6 +3,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; +import net.t2code.t2codelib.SPIGOT.system.T2CbungeeCommandSenderReciver; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import net.t2code.t2codelib.Util; import org.bukkit.Bukkit; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java index 58a65d9..df7ef1c 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java @@ -29,7 +29,10 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -101,18 +104,30 @@ public class CreateReportLog { pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV()); pWriter.println(); } + + pWriter.println("OfflinePlayers amount: " + Bukkit.getOfflinePlayers().length); pWriter.println("OfflinePlayers: "); - for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { + + ArrayList players = new ArrayList<>(); + Collections.addAll(players, Bukkit.getOfflinePlayers()); + players.sort(Comparator.comparing(OfflinePlayer::getName)); + for (OfflinePlayer player : players) { pWriter.println(" - " + player.getName() + " - " + player.getUniqueId()); } + pWriter.println(); pWriter.println("Plugins amount: " + Bukkit.getPluginManager().getPlugins().length); pWriter.println("Plugins: "); - for (Plugin pl : Bukkit.getPluginManager().getPlugins()) { + + ArrayList plugins = new ArrayList<>(); + Collections.addAll(plugins, Bukkit.getPluginManager().getPlugins()); + plugins.sort(Comparator.comparing(Plugin::getName)); + for (Plugin pl : plugins) { pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription().getAuthors() + " - SoftDepend: " + pl.getDescription().getSoftDepend() + " - Depend: " + pl.getDescription().getDepend() + " LoadBefore: " + pl.getDescription().getLoadBefore() + " - Website: " + pl.getDescription().getWebsite()); } + } catch (IOException ioe) { ioe.printStackTrace(); } finally {