From 47c11dadcd55febd98325a67825bb705d3c02f6c Mon Sep 17 00:00:00 2001 From: hackthetime Date: Mon, 18 Sep 2023 09:59:31 +0200 Subject: added the code responsible to actually use the config of the mining and which one you want to get pinged for or not. --- .../communication/BBsentialConnection.java | 150 +++++++++++++-------- 1 file changed, 93 insertions(+), 57 deletions(-) diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java index 8140e2e..e70d0ad 100644 --- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java +++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java @@ -5,6 +5,7 @@ import de.hype.bbsentials.client.BBsentials; import de.hype.bbsentials.constants.enviromentShared.AuthenticationConstants; import de.hype.bbsentials.constants.enviromentShared.ChChestItem; import de.hype.bbsentials.constants.enviromentShared.Islands; +import de.hype.bbsentials.constants.enviromentShared.MiningEvents; import de.hype.bbsentials.packets.AbstractPacket; import de.hype.bbsentials.packets.PacketManager; import de.hype.bbsentials.packets.PacketUtils; @@ -34,6 +35,8 @@ import java.util.Arrays; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import static de.hype.bbsentials.client.BBsentials.config; + public class BBsentialConnection { private Socket socket; private BufferedReader reader; @@ -46,8 +49,41 @@ public class BBsentialConnection { public BBsentialConnection() { packetManager = new PacketManager(this); } - public interface MessageReceivedCallback { - void onMessageReceived(String message); + + public static int getPotTime() { + int remainingTimeInMinutes = 0; + StatusEffectInstance potTimeRequest = MinecraftClient.getInstance().player.getStatusEffect(StatusEffects.STRENGTH); + if (potTimeRequest != null) { + if (potTimeRequest.getAmplifier() >= 7) { + remainingTimeInMinutes = (int) (potTimeRequest.getDuration() / 20.0); + } + } + return remainingTimeInMinutes; + } + + public static boolean isCommandSafe(String command) { + if (command.startsWith("/p ") || command.startsWith("/party ") || command.startsWith("/boop ") || command.startsWith("/msg ") || command.startsWith("/hub ")) { + return true; + } + else { + BBsentials.bbserver.sendCommand("?emergency server-hacked? chchest command " + command); + String emergencyMessage = "We detected that there was a command used which is not configured to be safe! " + command + " please check if its safe. IMMEDIATELY report this to the Admins and Developer Hype_the_Time (@hackthetime). If it is not safe immediately remove BBsentials!!!!!!!! "; + System.out.println(emergencyMessage); + Chat.sendPrivateMessageToSelf("§4" + emergencyMessage + "\n\n"); + Chat.sendPrivateMessageToSelf("§4" + emergencyMessage + "\n\n"); + /*try { + Thread.sleep(5000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + throw new RuntimeException(emergencyMessage);*/ + } + return false; + } + + public static void playsound(SoundEvent event) { + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance + .master(event, 1.0F, 1.0F)); } public void connect(String serverIP, int serverPort) { @@ -92,7 +128,7 @@ public class BBsentialConnection { PublicKey serverPublicKey = serverCertificate.getPublicKey(); // Create a TrustManager that trusts only the server's public key - TrustManager[] trustManagers = new TrustManager[]{new X509TrustManager() { + TrustManager[] trustManagers = new TrustManager[] {new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; // We don't need to check the client's certificates } @@ -191,7 +227,7 @@ public class BBsentialConnection { if (BBsentials.getConfig().isDetailedDevModeEnabled()) { Chat.sendPrivateMessageToSelf("§bBBDev-s: " + message); } - if (socket.isConnected()&&writer!=null) { + if (socket.isConnected() && writer != null) { writer.println(message); } } @@ -200,13 +236,14 @@ public class BBsentialConnection { if (BBsentials.getConfig().isDetailedDevModeEnabled()) { Chat.sendPrivateMessageToSelf("§bBBDev-s: " + message); } - if (socket.isConnected()&&writer!=null) { + if (socket.isConnected() && writer != null) { writer.println(message); } else { Chat.sendPrivateMessageToSelf("§4BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect"); } } + //The following onMessageReceived may or may not be modified // or taken out of order in private/ non official versions of the mod! public void onMessageReceived(String message) { @@ -250,7 +287,7 @@ public class BBsentialConnection { System.exit(0); } else if (arguments[0].equals("hub")) { - BBsentials.config.sender.addHiddenSendTask("/hub", 1); + config.sender.addHiddenSendTask("/hub", 1); } } if (BBsentials.getConfig().isDetailedDevModeEnabled()) { @@ -269,9 +306,9 @@ public class BBsentialConnection { public void splashHighlightItem(String itemName, long displayTimeInMilliseconds) { this.itemName = itemName; - BBsentials.config.highlightitem = true; + config.highlightitem = true; BBsentials.executionService.schedule(() -> { - BBsentials.config.highlightitem = false; + config.highlightitem = false; try { socket.setSoTimeout(0); } catch (SocketException e) { @@ -283,51 +320,20 @@ public class BBsentialConnection { public String getItemName() { return itemName; } - - public static int getPotTime() { - int remainingTimeInMinutes = 0; - StatusEffectInstance potTimeRequest = MinecraftClient.getInstance().player.getStatusEffect(StatusEffects.STRENGTH); - if (potTimeRequest != null) { - if (potTimeRequest.getAmplifier() >= 7) { - remainingTimeInMinutes = (int) (potTimeRequest.getDuration() / 20.0); - } - } - return remainingTimeInMinutes; - } + //TODO search public void setMessageReceivedCallback(MessageReceivedCallback callback) { this.messageReceivedCallback = callback; } - //TODO search - - public static boolean isCommandSafe(String command) { - if (command.startsWith("/p ") || command.startsWith("/party ") || command.startsWith("/boop ") || command.startsWith("/msg ") || command.startsWith("/hub ")) { - return true; - } - else { - BBsentials.bbserver.sendCommand("?emergency server-hacked? chchest command " + command); - String emergencyMessage = "We detected that there was a command used which is not configured to be safe! " + command + " please check if its safe. IMMEDIATELY report this to the Admins and Developer Hype_the_Time (@hackthetime). If it is not safe immediately remove BBsentials!!!!!!!! "; - System.out.println(emergencyMessage); - Chat.sendPrivateMessageToSelf("§4" + emergencyMessage + "\n\n"); - Chat.sendPrivateMessageToSelf("§4" + emergencyMessage + "\n\n"); - /*try { - Thread.sleep(5000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - throw new RuntimeException(emergencyMessage);*/ - } - return false; - } public void sendPacket(E packet) { String packetName = packet.getClass().getSimpleName(); - String rawjson = PacketUtils.parsePacketToJson(packet); + String rawjson = PacketUtils.parsePacketToJson(packet); if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class))) { - Chat.sendPrivateMessageToSelf("BBDev-sP: "+packetName+": "+rawjson); + Chat.sendPrivateMessageToSelf("BBDev-sP: " + packetName + ": " + rawjson); } - if (socket.isConnected()&&writer!=null) { - writer.println(packetName + "." +rawjson); + if (socket.isConnected() && writer != null) { + writer.println(packetName + "." + rawjson); } else { Chat.sendPrivateMessageToSelf("BB: Couldn't send a Packet? did you get disconnected?"); @@ -335,7 +341,7 @@ public class BBsentialConnection { } public void onBroadcastMessagePacket(BroadcastMessagePacket packet) { - Chat.sendPrivateMessageToSelf("§6[A]§r ["+packet.prefix+"] "+packet.username+": "+packet.message); + Chat.sendPrivateMessageToSelf("§6[A]§r [" + packet.prefix + "] " + packet.username + ": " + packet.message); } public void onSplashNotifyPacket(SplashNotifyPacket packet) { @@ -364,7 +370,7 @@ public class BBsentialConnection { } public void onBingoChatMessagePacket(BingoChatMessagePacket packet) { - if (BBsentials.config.showBingoChat) { + if (config.showBingoChat) { Chat.sendPrivateMessageToSelf("[" + packet.prefix + "] " + packet.username + ": " + packet.message); } } @@ -385,15 +391,45 @@ public class BBsentialConnection { } public void onMiningEventPacket(MiningEventPacket packet) { - if (BBsentials.config.toDisplayConfig.getValue("disableAll")) { + if (config.toDisplayConfig.getValue("disableAll")) { //its will returns false cause disabled is checked already before. + if (packet.event.equals(MiningEvents.RAFFLE)) { + if (!config.toDisplayConfig.raffle) return; + } + else if (packet.event.equals(MiningEvents.GOBLIN_RAID)) { + if (!config.toDisplayConfig.goblinRaid) return; + } + else if (packet.event.equals(MiningEvents.MITHRIL_GOURMAND)) { + if (!config.toDisplayConfig.mithrilGourmand) return; + } + else if (packet.event.equals(MiningEvents.BETTER_TOGETHER)) { + if (config.toDisplayConfig.betterTogether.equals("none")) return; + if (config.toDisplayConfig.betterTogether.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (config.toDisplayConfig.betterTogether.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) + return; + } + else if (packet.event.equals(MiningEvents.DOUBLE_POWDER)) { + if (config.toDisplayConfig.doublePowder.equals("none")) return; + if (config.toDisplayConfig.doublePowder.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (config.toDisplayConfig.doublePowder.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) + return; + } + else if (packet.event.equals(MiningEvents.GONE_WITH_THE_WIND)) { + if (config.toDisplayConfig.goneWithTheWind.equals("none")) return; + if (config.toDisplayConfig.goneWithTheWind.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (config.toDisplayConfig.goneWithTheWind.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) + return; + } Chat.sendPrivateMessageToSelf(packet.username + "There is a " + packet.event.getDisplayName() + "in the " + packet.island.getDisplayName() + " now/soon."); } } public void onWelcomePacket(WelcomeClientPacket packet) { if (packet.success) { - BBsentials.config.bbsentialsRoles = packet.roles; + config.bbsentialsRoles = packet.roles; Chat.sendPrivateMessageToSelf("§aLogin Success"); if (!packet.motd.isEmpty()) { Chat.sendPrivateMessageToSelf(packet.motd); @@ -409,7 +445,7 @@ public class BBsentialConnection { } public void onDisplayMessagePacket(DisplayMessagePacket packet) { - Chat.sendPrivateMessageToSelf("§r"+packet.message); + Chat.sendPrivateMessageToSelf("§r" + packet.message); } public void onDisplayTellrawMessagePacket(DisplayTellrawMessagePacket packet) { @@ -426,24 +462,24 @@ public class BBsentialConnection { } public void onPartyPacket(PartyPacket packet) { - Chat.sendCommand("/p "+packet.type+String.join(" ",packet.users)); + Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users)); } public void onSystemMessagePacket(SystemMessagePacket packet) { if (packet.important) { - Chat.sendPrivateMessageToSelf("§c§n"+packet.message); - }else { - Chat.sendPrivateMessageToSelf("§r"+packet.message); + Chat.sendPrivateMessageToSelf("§c§n" + packet.message); } - if (packet.ping){ + else { + Chat.sendPrivateMessageToSelf("§r" + packet.message); + } + if (packet.ping) { playsound(SoundEvents.ENTITY_WARDEN_DIG); } } - public static void playsound(SoundEvent event){ - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance - .master(event, 1.0F, 1.0F)); + public interface MessageReceivedCallback { + void onMessageReceived(String message); } } \ No newline at end of file -- cgit From 99caacfeefea554afdb93265f4e9b199134dd9d2 Mon Sep 17 00:00:00 2001 From: HacktheTime <131038646+HacktheTime@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:00:14 +0200 Subject: Updated LICENSE updated license --- LICENSE | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 2b281e8..ed73f4e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,19 @@ -Copyright (c) 2023 -All rights reserved. +Copyright (c) 2023 hackthetime -Copying and changing code for own projects is allowed as long as you don't copy a lot and use it for different things (Inspiration, looking for solutions etc is normally fine). -Modifying this code to gain a personal advantage by abusing a feature unintentionally is STRICTLY forbidden. Sharing such modified code may even result in legal actions. \ No newline at end of file +**The Software is provided as is. Use is at own risk.** + + +The Code is under the CC BY-NC-ND license however with modifications listed below: + +Copying and changing code for own projects is allowed as long as you dont do so to abuse the Systems in place. +If you have credits somehwere and you used a signicant amount of Code (or get a request) of this project you have to link to it. If used next to no code dont bother. +There are some restricted areas which are not allowed to be modifed/removed etc. Those will be marked with start and end. +Modifying this code to gain a personal advantage by abusing a feature unintentionally is STRICTLY forbidden. Sharing such modifications is not allowed either. All modifications have to be pull requested after they have been fully implemented and work like exspected + +Summary: +No monetarysations +Sharing modified versions is disallowed. (If you want to do so feel free to make a pull reqeust and ask) +You need to give credit f you use it. (If u used next to no code, have no credits build in as well as havent gotten a request too include it dont bother adding it). + +Too contributors: +I may monetarise this mod in the future by allowing donations and will deffinetely allow donations for the Server costs. -- cgit From 4e4b9a67152064058280ceeca62c0b3d24825063 Mon Sep 17 00:00:00 2001 From: HacktheTime <131038646+HacktheTime@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:01:38 +0200 Subject: Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ed73f4e..f6fc0e7 100644 --- a/LICENSE +++ b/LICENSE @@ -3,7 +3,7 @@ Copyright (c) 2023 hackthetime **The Software is provided as is. Use is at own risk.** -The Code is under the CC BY-NC-ND license however with modifications listed below: +The Code is under the CC BY-NC-ND 4.0 license however with modifications listed below: Copying and changing code for own projects is allowed as long as you dont do so to abuse the Systems in place. If you have credits somehwere and you used a signicant amount of Code (or get a request) of this project you have to link to it. If used next to no code dont bother. -- cgit From ca5616226465ba65011f94d15d532442ecac6777 Mon Sep 17 00:00:00 2001 From: hackthetime Date: Mon, 18 Sep 2023 11:20:32 +0200 Subject: fixed mining eents ch block not affeting ch events added chchest items mod menu code to use that config threaded the message execution to put lessload on the main thread. used the execution service for it. --- .../java/de/hype/bbsentials/client/BBsentials.java | 2 +- .../client/BBsentialsConfigScreemFactory.java | 5 ++++ .../de/hype/bbsentials/client/ToDisplayConfig.java | 2 ++ .../communication/BBsentialConnection.java | 28 +++++++++++++++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hype/bbsentials/client/BBsentials.java b/src/main/java/de/hype/bbsentials/client/BBsentials.java index 6641c10..70384f6 100644 --- a/src/main/java/de/hype/bbsentials/client/BBsentials.java +++ b/src/main/java/de/hype/bbsentials/client/BBsentials.java @@ -219,7 +219,7 @@ public class BBsentials implements ClientModInitializer { bbthread = new Thread(() -> { bbserver = new BBsentialConnection(); coms = new CommandsOLD(); - bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message)); + bbserver.setMessageReceivedCallback(message -> executionService.execute(()->bbserver.onMessageReceived(message))); if (beta) { bbserver.connect(config.getBBServerURL(), 5011); } diff --git a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java index 4719557..2d0039c 100644 --- a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java +++ b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java @@ -172,6 +172,11 @@ public class BBsentialsConfigScreemFactory { .setTooltip(Text.of("Select to receive notifications when any Flawless Gemstone is found")) .setSaveConsumer(newValue -> config.toDisplayConfig.flawlessGemstone = newValue) .build()); + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("Jungle Heart"), config.toDisplayConfig.jungleHeart) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a JungleHeart is found")) + .setSaveConsumer(newValue -> config.toDisplayConfig.jungleHeart = newValue) + .build()); }//CHChestItems ConfigCategory miningEvents = builder.getOrCreateCategory(Text.of("Mining Events")); { diff --git a/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java b/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java index d3a1707..4a048ab 100644 --- a/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java +++ b/src/main/java/de/hype/bbsentials/client/ToDisplayConfig.java @@ -25,6 +25,8 @@ public class ToDisplayConfig { public boolean superliteMotor = false; public boolean syntheticHeart = false; public boolean flawlessGemstone = false; + public boolean jungleHeart = false; + //Mining Events. public boolean allEvents = true; public boolean blockChEvents = false; diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java index e70d0ad..4a8fb50 100644 --- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java +++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java @@ -2,10 +2,7 @@ package de.hype.bbsentials.communication; import de.hype.bbsentials.chat.Chat; import de.hype.bbsentials.client.BBsentials; -import de.hype.bbsentials.constants.enviromentShared.AuthenticationConstants; -import de.hype.bbsentials.constants.enviromentShared.ChChestItem; -import de.hype.bbsentials.constants.enviromentShared.Islands; -import de.hype.bbsentials.constants.enviromentShared.MiningEvents; +import de.hype.bbsentials.constants.enviromentShared.*; import de.hype.bbsentials.packets.AbstractPacket; import de.hype.bbsentials.packets.PacketManager; import de.hype.bbsentials.packets.PacketUtils; @@ -36,6 +33,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import static de.hype.bbsentials.client.BBsentials.config; +import static de.hype.bbsentials.client.BBsentials.executionService; public class BBsentialConnection { private Socket socket; @@ -377,12 +375,13 @@ public class BBsentialConnection { public void onChChestPacket(ChChestPacket packet) { if (isCommandSafe(packet.bbcommand)) { + if (showChChest(packet.items)){ String tellrawText = ("{\"text\":\"BB: @username found @item in a chest at (@coords). Click here to get a party invite @extramessage\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"@inviteCommand\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"On clicking you will get invited to a party. Command executed: @inviteCommand\"]}}"); tellrawText = tellrawText.replace("@username", packet.announcerUsername).replace("@item", Arrays.stream(packet.items).map(ChChestItem::getDisplayName).toList().toString()).replace("@coords", packet.locationCoords).replace("@inviteCommand", packet.bbcommand); if (!(packet.extraMessage == null || packet.extraMessage.isEmpty())) { tellrawText = tellrawText.replace("@extramessage", " : " + packet.extraMessage); } - Chat.sendPrivateMessageToSelfText(Chat.createClientSideTellraw(tellrawText)); + Chat.sendPrivateMessageToSelfText(Chat.createClientSideTellraw(tellrawText));} } else { Chat.sendPrivateMessageToSelf("§cFiltered out a suspicious packet! Please send a screenshot of this message with ping Hype_the_Time (hackthetime) in Bingo Apothecary, BB, SBZ, offical Hypixel,..."); @@ -393,6 +392,7 @@ public class BBsentialConnection { public void onMiningEventPacket(MiningEventPacket packet) { if (config.toDisplayConfig.getValue("disableAll")) { //its will returns false cause disabled is checked already before. + if (config.toDisplayConfig.blockChEvents&&packet.island.equals(Islands.CRYSTAL_HOLLOWS)) return; if (packet.event.equals(MiningEvents.RAFFLE)) { if (!config.toDisplayConfig.raffle) return; } @@ -477,9 +477,25 @@ public class BBsentialConnection { } } + public boolean showChChest(ChChestItem[] items) { + if (config.toDisplayConfig.allChChestItem) return true; + for (ChChestItem item : items) { + if (config.toDisplayConfig.customChChestItem&&item.isCustom()) return true; + if (config.toDisplayConfig.allRoboPart&&item.isRoboPart()) return true; + if (config.toDisplayConfig.prehistoricEgg&&item.equals(ChChestItems.PrehistoricEgg)) return true; + if (config.toDisplayConfig.pickonimbus2000&&item.equals(ChChestItems.Pickonimbus2000)) return true; + if (config.toDisplayConfig.controlSwitch&&item.equals(ChChestItems.ControlSwitch)) return true; + if (config.toDisplayConfig.electronTransmitter&&item.equals(ChChestItems.ElectronTransmitter)) return true; + if (config.toDisplayConfig.robotronReflector&&item.equals(ChChestItems.RobotronReflector)) return true; + if (config.toDisplayConfig.superliteMotor&&item.equals(ChChestItems.SuperliteMotor)) return true; + if (config.toDisplayConfig.syntheticHeart&&item.equals(ChChestItems.SyntheticHeart)) return true; + if (config.toDisplayConfig.flawlessGemstone&&item.equals(ChChestItems.FlawlessGemstone)) return true; + if (config.toDisplayConfig.jungleHeart&&item.equals(ChChestItems.JungleHeart)) return true; + } + return false; + } public interface MessageReceivedCallback { void onMessageReceived(String message); } - } \ No newline at end of file -- cgit