diff options
Diffstat (limited to 'src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java')
-rw-r--r-- | src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java | 150 |
1 files 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 <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 +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 |