diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-09-21 21:55:59 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-09-21 21:55:59 +0200 |
commit | f30090beaa3f116ec3fcbe103fc72a393e5f9162 (patch) | |
tree | a4ad0a417a12641c237f4b4934c0002fbb296293 /src/main | |
parent | 2486da0f63a2c2cce7341a1402df7834414b6c42 (diff) | |
parent | a4b899e994577a9cbc1d2f19135268a3ff0bde63 (diff) | |
download | BBsentials-f30090beaa3f116ec3fcbe103fc72a393e5f9162.tar.gz BBsentials-f30090beaa3f116ec3fcbe103fc72a393e5f9162.tar.bz2 BBsentials-f30090beaa3f116ec3fcbe103fc72a393e5f9162.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/main')
4 files changed, 122 insertions, 63 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 8140e2e..4a8fb50 100644 --- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java +++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java @@ -2,9 +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.*; import de.hype.bbsentials.packets.AbstractPacket; import de.hype.bbsentials.packets.PacketManager; import de.hype.bbsentials.packets.PacketUtils; @@ -34,6 +32,9 @@ import java.util.Arrays; 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; private BufferedReader reader; @@ -46,8 +47,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 +126,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 +225,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 +234,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 +285,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 +304,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 +318,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 <E extends AbstractPacket> 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 +339,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,19 +368,20 @@ public class BBsentialConnection { } public void onBingoChatMessagePacket(BingoChatMessagePacket packet) { - if (BBsentials.config.showBingoChat) { + if (config.showBingoChat) { Chat.sendPrivateMessageToSelf("[" + packet.prefix + "] " + packet.username + ": " + packet.message); } } 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,..."); @@ -385,15 +390,46 @@ 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 (config.toDisplayConfig.blockChEvents&&packet.island.equals(Islands.CRYSTAL_HOLLOWS)) return; + 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,40 @@ 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); + } + else { + Chat.sendPrivateMessageToSelf("§r" + packet.message); } - if (packet.ping){ + 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 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 |