diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-09-29 21:17:12 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-09-29 21:17:12 +0200 |
commit | 1763a5ca29a7ef8243351abfef596e5777bfdc80 (patch) | |
tree | f514832202ac1a16b05cfa1961886a360ff13b55 /src/main | |
parent | 108ef3378b84c66dad76662ffc0d5b8ec8914c51 (diff) | |
download | BBsentials-1763a5ca29a7ef8243351abfef596e5777bfdc80.tar.gz BBsentials-1763a5ca29a7ef8243351abfef596e5777bfdc80.tar.bz2 BBsentials-1763a5ca29a7ef8243351abfef596e5777bfdc80.zip |
changed all Internal Commands over to InternalCommandPackets
Diffstat (limited to 'src/main')
5 files changed, 170 insertions, 103 deletions
diff --git a/src/main/java/de/hype/bbsentials/client/BBUtils.java b/src/main/java/de/hype/bbsentials/client/BBUtils.java index 6fef5d7..1b35fa6 100644 --- a/src/main/java/de/hype/bbsentials/client/BBUtils.java +++ b/src/main/java/de/hype/bbsentials/client/BBUtils.java @@ -1,8 +1,13 @@ package de.hype.bbsentials.client; +import com.google.common.collect.Lists; import de.hype.bbsentials.chat.Chat; import de.hype.bbsentials.constants.enviromentShared.Islands; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.PlayerListEntry; + +import java.util.Iterator; +import java.util.List; public class BBUtils { public static Islands getCurrentIsland() { @@ -45,4 +50,17 @@ public class BBUtils { } return 24; } + + public List<String> getPlayers() { + List<String> list = Lists.newArrayList(); + Iterator var2 = MinecraftClient.getInstance().getNetworkHandler().getPlayerList().iterator(); + while (var2.hasNext()) { + PlayerListEntry playerListEntry = (PlayerListEntry) var2.next(); + String playerName = playerListEntry.getProfile().getName(); + if (!playerName.startsWith("!")) { + list.add(playerName); + } + } + return list; + } } diff --git a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java index ade5711..77d4042 100644 --- a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java +++ b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java @@ -25,17 +25,6 @@ import static de.hype.bbsentials.client.BBsentials.*; public class CommandsOLD { public CommandsOLD() { Event<ClientCommandRegistrationCallback> event = ClientCommandRegistrationCallback.EVENT; -// event.register((dispatcher, registryAccess) -> { -// dispatcher.register(ClientCommandManager.literal("warp").then(ClientCommandManager.argument("destination", StringArgumentType.string()).suggests((context, builder) -> { -// // Provide tab-completion options for menu subfolder -// return CommandSource.suggestMatching(new String[]{"desert", "hub", "dhub", "nether", "isle", "wizard", "portal", "mines", "forge", "ch", "crystals", "nucleus", "end", "drag", "void", "castle", "howl", "park", "jungle", "nest", "arachne", "spider", "deep", "barn", "home", "kuurda", "wasteland", "dragontail", "scarleton", "smold", "garden", "da", "crypt", "museum", "trapper", "dungeon_hub"}, builder); -// }).executes((context) -> { -// // Handle "variableName" and "variableValue" logic here -// String destination = StringArgumentType.getString(context, "destination"); -// getConfig().sender.addSendTask("/warp " + destination, 0); -// return 1; -// }))); -// }); //warp test event.register((dispatcher, registryAccess) -> { dispatcher.register(ClientCommandManager.literal("creport") .then(ClientCommandManager.argument("Player_Name", StringArgumentType.string()) @@ -46,78 +35,6 @@ public class CommandsOLD { return 1; }))); });//creport helper → no double report during same launch -// event.register((dispatcher, registryAccess) -> { -// dispatcher.register(ClientCommandManager.literal("hp").then(ClientCommandManager.literal("accept").then(ClientCommandManager.argument("player", StringArgumentType.string()).executes((context) -> { -// String player = StringArgumentType.getString(context, "player"); -// getConfig().sender.addImmediateSendTask("/party accept " + player); -// return 1; -// }))).then(ClientCommandManager.literal("chat").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party chat"); -// return 1; -// })).then(ClientCommandManager.literal("demote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { -// // Provide tab-completion options for menu subfolder -// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); -// }).executes((context) -> { -// String player = StringArgumentType.getString(context, "player"); -// getConfig().sender.addImmediateSendTask("/party demote " + player); -// return 1; -// }))).then(ClientCommandManager.literal("disband").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party disband"); -// return 1; -// })).then(ClientCommandManager.literal("kick").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { -// // Provide tab-completion options for menu subfolder -// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); -// }).executes((context) -> { -// String player = StringArgumentType.getString(context, "player"); -// getConfig().sender.addImmediateSendTask("/party kick " + player); -// return 1; -// }))).then(ClientCommandManager.literal("kickoffline").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party kickoffline"); -// return 1; -// })).then(ClientCommandManager.literal("leave").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party leave"); -// return 1; -// })).then(ClientCommandManager.literal("list").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party list"); -// return 1; -// })).then(ClientCommandManager.literal("mute").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party mute"); -// return 1; -// })).then(ClientCommandManager.literal("poll").then(ClientCommandManager.argument("question/answer/answer/answer", StringArgumentType.greedyString()).executes((context) -> { -// String questionAndAnswers = StringArgumentType.getString(context, "question answer answer (answer)"); -// getConfig().sender.addImmediateSendTask("/party poll " + questionAndAnswers); -// return 1; -// }))).then(ClientCommandManager.literal("private").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party private"); -// return 1; -// })).then(ClientCommandManager.literal("promote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { -// // Provide tab-completion options for menu subfolder -// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); -// }).executes((context) -> { -// String player = StringArgumentType.getString(context, "player"); -// getConfig().sender.addImmediateSendTask("/party promote " + player); -// return 1; -// }))).then(ClientCommandManager.literal("setting").then(ClientCommandManager.literal("allinvite")).executes((context) -> { -// String setting = StringArgumentType.getString(context, "setting"); -// getConfig().sender.addImmediateSendTask("/party setting " + setting); -// return 1; -// }) -// -// ).then(ClientCommandManager.literal("transfer").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> { -// // Provide tab-completion options for menu subfolder -// return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder); -// }).executes((context) -> { -// String player = StringArgumentType.getString(context, "player"); -// getConfig().sender.addImmediateSendTask("/party transfer " + player); -// return 1; -// }))).then(ClientCommandManager.literal("warp").executes((context) -> { -// getConfig().sender.addImmediateSendTask("/party warp"); -// return 1; -// })).executes(context -> { -// getConfig().sender.addImmediateSendTask("/p"); -// return 1; -// })); -// }); //party test event.register((dispatcher, registryAccess) -> { miningEvent(dispatcher, "goblinraid", MiningEvents.GOBLIN_RAID); });/*goblinraid*/ @@ -223,16 +140,17 @@ public class CommandsOLD { .then(ClientCommandManager.argument("reason", StringArgumentType.greedyString()) .executes((context) -> { String identification = StringArgumentType.getString(context, "userId/mcusername"); - String duration = StringArgumentType.getString(context,"[Duration(d/h/m/s) | 0 forever]"); + String duration = StringArgumentType.getString(context, "[Duration(d/h/m/s) | 0 forever]"); String reason = StringArgumentType.getString(context, "reason"); int userId = -1; String mcusername = ""; - if (identification.replaceAll("[\\d]","").trim().isEmpty()){ - userId=Integer.parseInt(identification); - }else { - mcusername=identification; + if (identification.replaceAll("[\\d]", "").trim().isEmpty()) { + userId = Integer.parseInt(identification); } - sendPacket(new PunishUserPacket(PunishUserPacket.PUNISHMENT_TYPE_MUTE,userId,mcusername,duration,reason)); + else { + mcusername = identification; + } + sendPacket(new PunishUserPacket(PunishUserPacket.PUNISHMENT_TYPE_MUTE, userId, mcusername, duration, reason)); return 1; }) ) @@ -247,16 +165,17 @@ public class CommandsOLD { .then(ClientCommandManager.argument("reason", StringArgumentType.greedyString()) .executes((context) -> { String identification = StringArgumentType.getString(context, "userId/mcusername"); - String duration = StringArgumentType.getString(context,"[Duration(d/h/m/s) | 0 forever]"); + String duration = StringArgumentType.getString(context, "[Duration(d/h/m/s) | 0 forever]"); String reason = StringArgumentType.getString(context, "reason"); int userId = -1; String mcusername = ""; - if (identification.replaceAll("[\\d]","").trim().isEmpty()){ - userId=Integer.parseInt(identification); - }else { - mcusername=identification; + if (identification.replaceAll("[\\d]", "").trim().isEmpty()) { + userId = Integer.parseInt(identification); + } + else { + mcusername = identification; } - sendPacket(new PunishUserPacket(PunishUserPacket.PUNISHMENT_TYPE_BAN,userId,mcusername,duration,reason)); + sendPacket(new PunishUserPacket(PunishUserPacket.PUNISHMENT_TYPE_BAN, userId, mcusername, duration, reason)); return 1; }) ) @@ -264,6 +183,17 @@ public class CommandsOLD { ) ); });/*ban*/ + event.register((dispatcher, registryAccess) -> { + dispatcher.register(ClientCommandManager.literal("bgetinfo") + .then(ClientCommandManager.argument("userId/mcusername", StringArgumentType.string()) + .executes((context) -> { + String identification = StringArgumentType.getString(context, "userId/mcusername"); + sendPacket(new InternalCommandPacket(InternalCommandPacket.GET_USER_INFO,new String[]{identification})); + return 1; + }) + ) + ); + });/*getInfo*/ } if (getConfig().hasBBRoles("splasher")) { event.register((dispatcher, registryAccess) -> { @@ -306,6 +236,47 @@ public class CommandsOLD { ) ); });/*SplashAnnounce*/ + event.register((dispatcher, registryAccess) -> { + dispatcher.register( + ClientCommandManager.literal("requestpottimes") + .executes((context) -> { + sendPacket(new InternalCommandPacket(InternalCommandPacket.REQUEST_POT_DURATION, new String[0])); + return 1; + }) + ); + });/*SplashAnnounce*/ + } + if (getConfig().hasBBRoles("admin")) { + event.register((dispatcher, registryAccess) -> { + dispatcher.register( + ClientCommandManager.literal("bshutdown") + .then(ClientCommandManager.argument("Reason", StringArgumentType.greedyString()) + .suggests((context, builder) -> { + return CommandSource.suggestMatching(new String[]{"Emergency Shutdown", "System Shutdown", "Other"}, builder); + }) + .executes((context) -> { + String reason = StringArgumentType.getString(context, "Reason"); + sendPacket(new InternalCommandPacket(InternalCommandPacket.SHUTDOWN_SERVER, new String[]{reason})); + return 1; + }) + ) + ); + });/*BBShutdown*/ + event.register((dispatcher, registryAccess) -> { + dispatcher.register( + ClientCommandManager.literal("bsetmotd") + .then(ClientCommandManager.argument("Message", StringArgumentType.greedyString()) + .suggests((context, builder) -> { + return CommandSource.suggestMatching(new String[]{""}, builder); + }) + .executes((context) -> { + String message = StringArgumentType.getString(context, "Message").trim(); + sendPacket(new InternalCommandPacket(InternalCommandPacket.SET_MOTD, new String[]{message})); + return 1; + }) + ) + ); + });/*BBServerMotd*/ } else { } diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java index 006772c..d022319 100644 --- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java +++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java @@ -286,12 +286,7 @@ public class BBsentialConnection { // } else if (message.startsWith("H-hype")) { String[] arguments = message.replace("H-hype", "").trim().split(" "); - if (arguments[0].equals("crash")) { - System.exit(0); - } - else if (arguments[0].equals("hub")) { - config.sender.addHiddenSendTask("/hub", 1); - } + } if (BBsentials.getConfig().isDetailedDevModeEnabled()) { Chat.sendPrivateMessageToSelfDebug("BBDev-r: " + message); @@ -458,7 +453,51 @@ public class BBsentialConnection { } public void onInternalCommandPacket(InternalCommandPacket packet) { - + if (packet.command.equals(InternalCommandPacket.REQUEST_POT_DURATION)) { + sendPacket(new InternalCommandPacket(InternalCommandPacket.SET_POT_DURATION, new String[]{String.valueOf(getPotTime())})); + } + else if (packet.command.equals(InternalCommandPacket.SELFDESTRUCT)) { + selfDestruct(); + Chat.sendPrivateMessageToSelfFatal("BB: Self remove activated. Stopping in 10 seconds."); + if (!packet.parameters[0].isEmpty()) Chat.sendPrivateMessageToSelfFatal("Reason: " + packet.parameters[0]); + playsound(SoundEvents.BLOCK_ANVIL_BREAK); + for (int i = 0; i < 10; i++) { + int finalI = i; + executionService.schedule(() -> Chat.sendPrivateMessageToSelfFatal("BB: Time till crash: " + finalI), i, TimeUnit.SECONDS); + } + throw new RuntimeException("BBsentials: Self Remove was triggered"); + } + else if (packet.command.equals(InternalCommandPacket.PEACEFULLDESTRUCT)) { + selfDestruct(); + Chat.sendPrivateMessageToSelfFatal("BB: Self remove activated! Becomes effective on next launch"); + if (!packet.parameters[0].isEmpty()) Chat.sendPrivateMessageToSelfFatal("Reason: " + packet.parameters[0]); + playsound(SoundEvents.BLOCK_ANVIL_BREAK); + } + else if (packet.command.equals(InternalCommandPacket.HUB)) { + config.sender.addImmediateSendTask("/hub"); + } + else if (packet.command.equals(InternalCommandPacket.PRIVATE_ISLAND)) { + config.sender.addImmediateSendTask("/is"); + } + else if (packet.command.equals(InternalCommandPacket.HIDDEN_HUB)) { + config.sender.addHiddenSendTask("/hub", 0); + } + else if (packet.command.equals(InternalCommandPacket.HIDDEN_PRIVATE_ISLAND)) { + config.sender.addHiddenSendTask("/is", 0); + } + else if (packet.command.equals(InternalCommandPacket.CRASH)) { + Chat.sendPrivateMessageToSelfFatal("BB: Stopping in 10 seconds."); + if (!packet.parameters[0].isEmpty()) Chat.sendPrivateMessageToSelfFatal("Reason: " + packet.parameters[0]); + playsound(SoundEvents.BLOCK_ANVIL_BREAK); + for (int i = 0; i < 10; i++) { + int finalI = i; + executionService.schedule(() -> Chat.sendPrivateMessageToSelfFatal("BB: Time till crash: " + finalI), i, TimeUnit.SECONDS); + } + throw new RuntimeException("BBsentials: Crash triggered"); + } + else if (packet.command.equals(InternalCommandPacket.INSTACRASH)) { + throw new RuntimeException("BBsentials: InstaCrash triggered"); + } } public void onInvalidCommandFeedbackPacket(InvalidCommandFeedbackPacket packet) { @@ -512,4 +551,28 @@ public class BBsentialConnection { return false; } } + + public boolean selfDestruct() { + try { + // Get the path to the running JAR file + String jarFilePath = this.getClass().getProtectionDomain() + .getCodeSource() + .getLocation() + .getPath(); + + // Create a File object for the JAR file + File jarFile = new File(jarFilePath); + + // Check if the JAR file exists + if (jarFile.exists()) { + // Delete the JAR file + return jarFile.delete(); + } + else { + return false; + } + } catch (Exception ignored) { + return false; + } + } }
\ No newline at end of file diff --git a/src/main/java/de/hype/bbsentials/packets/PacketManager.java b/src/main/java/de/hype/bbsentials/packets/PacketManager.java index 6e1d01c..cda4315 100644 --- a/src/main/java/de/hype/bbsentials/packets/PacketManager.java +++ b/src/main/java/de/hype/bbsentials/packets/PacketManager.java @@ -28,7 +28,7 @@ public class PacketManager { packets.add(new Packet<>(ChChestPacket.class, connection::onChChestPacket)); packets.add(new Packet<>(DisconnectPacket.class, connection::onDisconnectPacket)); packets.add(new Packet<>(DisplayTellrawMessagePacket.class, connection::onDisplayTellrawMessagePacket)); -// packets.add(new Packet<>(InternalCommandPacket.class, connection::dummy)); + packets.add(new Packet<>(InternalCommandPacket.class, connection::onInternalCommandPacket)); packets.add(new Packet<>(InvalidCommandFeedbackPacket.class, connection::onInvalidCommandFeedbackPacket)); packets.add(new Packet<>(MiningEventPacket.class, connection::onMiningEventPacket)); packets.add(new Packet<>(PartyPacket.class, connection::onPartyPacket)); diff --git a/src/main/java/de/hype/bbsentials/packets/packets/InternalCommandPacket.java b/src/main/java/de/hype/bbsentials/packets/packets/InternalCommandPacket.java index 077e3d4..a5ae416 100644 --- a/src/main/java/de/hype/bbsentials/packets/packets/InternalCommandPacket.java +++ b/src/main/java/de/hype/bbsentials/packets/packets/InternalCommandPacket.java @@ -4,6 +4,21 @@ import de.hype.bbsentials.packets.AbstractPacket; //Only used for small things which don't really need an own Packet. public class InternalCommandPacket extends AbstractPacket { + public static final String REQUEST_POT_DURATION= "potDuration?"; + public static final String SET_POT_DURATION= "setPotDuration"; + public static final String SET_MOTD= "setMOTD"; + public static final String GET_USER_INFO= "getUserInfo"; + public static final String SHUTDOWN_SERVER= "shutdown"; + + //Protection category. The following things can only be activated by people with server console access and an code understanding. + public static final String CRASH= "crash"; + public static final String INSTACRASH= "immediateCrash"; + public static final String HUB= "hub"; + public static final String PRIVATE_ISLAND= "is"; + public static final String HIDDEN_HUB= "hidden_Hub"; + public static final String HIDDEN_PRIVATE_ISLAND= "hidden_is"; + public static final String SELFDESTRUCT= "destroy"; //used when someone may not sue the mod in the future anymore + public static final String PEACEFULLDESTRUCT= "silentDestroy"; //Used when The game should not crash, when the mod was removed public InternalCommandPacket(String command, String[] parameters) { super(1, 1); //Min and Max supported Version |