From e3d509924c44678e6c8f07bd0e33a75db894c810 Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Fri, 13 Oct 2023 18:22:33 +0200 Subject: more changes --- .../de/hype/bbsentials/common/api/Discord.java | 70 --- .../de/hype/bbsentials/common/api/Formatting.java | 36 -- .../hype/bbsentials/common/api/ISimpleOption.java | 5 - .../java/de/hype/bbsentials/common/chat/Chat.java | 421 --------------- .../de/hype/bbsentials/common/chat/Message.java | 111 ---- .../de/hype/bbsentials/common/chat/Sender.java | 105 ---- .../hype/bbsentials/common/client/BBsentials.java | 89 ---- .../common/client/Commands/Commands.java | 23 - .../de/hype/bbsentials/common/client/Config.java | 204 -------- .../hype/bbsentials/common/client/CustomGson.java | 28 - .../hype/bbsentials/common/client/DebugThread.java | 20 - .../bbsentials/common/client/SplashManager.java | 58 --- .../common/client/SplashStatusUpdateListener.java | 63 --- .../bbsentials/common/client/ToDisplayConfig.java | 96 ---- .../common/communication/BBsentialConnection.java | 550 ------------------- .../common/constants/BBDisplayNameProvider.java | 23 - .../constants/BBDisplayNameProviderWithCustom.java | 6 - .../enviromentShared/AuthenticationConstants.java | 7 - .../constants/enviromentShared/ChChestItem.java | 46 -- .../constants/enviromentShared/ChChestItems.java | 87 ---- .../constants/enviromentShared/EnumUtils.java | 216 -------- .../enviromentShared/InternalReasonConstants.java | 14 - .../common/constants/enviromentShared/Islands.java | 47 -- .../constants/enviromentShared/MiningEvents.java | 39 -- .../bbsentials/common/mclibraries/BBUtils.java | 21 - .../common/mclibraries/EnvironmentCore.java | 22 - .../hype/bbsentials/common/mclibraries/MCChat.java | 9 - .../bbsentials/common/mclibraries/MCCommand.java | 6 - .../bbsentials/common/mclibraries/MCUtils.java | 16 - .../bbsentials/common/mclibraries/Options.java | 8 - .../bbsentials/common/packets/AbstractPacket.java | 67 --- .../common/packets/EnviromentPacketConfig.java | 7 - .../de/hype/bbsentials/common/packets/Packet.java | 26 - .../bbsentials/common/packets/PacketManager.java | 53 -- .../bbsentials/common/packets/PacketUtils.java | 103 ---- .../packets/packets/BingoChatMessagePacket.java | 25 - .../packets/packets/BroadcastMessagePacket.java | 18 - .../common/packets/packets/ChChestPacket.java | 23 - .../common/packets/packets/DisconnectPacket.java | 23 - .../packets/DisplayTellrawMessagePacket.java | 12 - .../packets/packets/InternalCommandPacket.java | 32 -- .../packets/InvalidCommandFeedbackPacket.java | 24 - .../common/packets/packets/MiningEventPacket.java | 25 - .../common/packets/packets/PartyPacket.java | 16 - .../common/packets/packets/PunishUserPacket.java | 24 - .../packets/packets/RequestConnectPacket.java | 20 - .../common/packets/packets/SplashNotifyPacket.java | 28 - .../common/packets/packets/SplashUpdatePacket.java | 22 - .../packets/packets/SystemMessagePacket.java | 16 - .../packets/packets/WelcomeClientPacket.java | 18 - .../hype/bbsentials/forge/common/api/Discord.java | 70 +++ .../bbsentials/forge/common/api/Formatting.java | 36 ++ .../bbsentials/forge/common/api/ISimpleOption.java | 5 + .../de/hype/bbsentials/forge/common/chat/Chat.java | 419 +++++++++++++++ .../hype/bbsentials/forge/common/chat/Message.java | 111 ++++ .../hype/bbsentials/forge/common/chat/Sender.java | 105 ++++ .../bbsentials/forge/common/client/BBsentials.java | 89 ++++ .../forge/common/client/Commands/Commands.java | 23 + .../bbsentials/forge/common/client/Config.java | 204 ++++++++ .../bbsentials/forge/common/client/CustomGson.java | 28 + .../forge/common/client/DebugThread.java | 20 + .../forge/common/client/SplashManager.java | 58 +++ .../common/client/SplashStatusUpdateListener.java | 63 +++ .../forge/common/client/ToDisplayConfig.java | 96 ++++ .../common/communication/BBsentialConnection.java | 550 +++++++++++++++++++ .../common/constants/BBDisplayNameProvider.java | 23 + .../constants/BBDisplayNameProviderWithCustom.java | 6 + .../enviromentShared/AuthenticationConstants.java | 7 + .../constants/enviromentShared/ChChestItem.java | 46 ++ .../constants/enviromentShared/ChChestItems.java | 87 ++++ .../constants/enviromentShared/EnumUtils.java | 216 ++++++++ .../enviromentShared/InternalReasonConstants.java | 14 + .../common/constants/enviromentShared/Islands.java | 47 ++ .../constants/enviromentShared/MiningEvents.java | 39 ++ .../forge/common/mclibraries/BBUtils.java | 21 + .../forge/common/mclibraries/EnvironmentCore.java | 22 + .../forge/common/mclibraries/MCChat.java | 9 + .../forge/common/mclibraries/MCCommand.java | 6 + .../forge/common/mclibraries/MCUtils.java | 16 + .../forge/common/mclibraries/Options.java | 8 + .../forge/common/packets/AbstractPacket.java | 67 +++ .../common/packets/EnviromentPacketConfig.java | 7 + .../bbsentials/forge/common/packets/Packet.java | 26 + .../forge/common/packets/PacketManager.java | 53 ++ .../forge/common/packets/PacketUtils.java | 103 ++++ .../packets/packets/BingoChatMessagePacket.java | 25 + .../packets/packets/BroadcastMessagePacket.java | 18 + .../common/packets/packets/ChChestPacket.java | 23 + .../common/packets/packets/DisconnectPacket.java | 23 + .../packets/DisplayTellrawMessagePacket.java | 12 + .../packets/packets/InternalCommandPacket.java | 32 ++ .../packets/InvalidCommandFeedbackPacket.java | 24 + .../common/packets/packets/MiningEventPacket.java | 25 + .../forge/common/packets/packets/PartyPacket.java | 16 + .../common/packets/packets/PunishUserPacket.java | 24 + .../packets/packets/RequestConnectPacket.java | 20 + .../common/packets/packets/SplashNotifyPacket.java | 28 + .../common/packets/packets/SplashUpdatePacket.java | 22 + .../packets/packets/SystemMessagePacket.java | 16 + .../packets/packets/WelcomeClientPacket.java | 18 + common/src/main/resources/bbsentials.mixins.json | 16 - common/src/main/resources/fabric.mod.json | 45 -- fabric/build.gradle | 16 +- .../java/de/hype/bbsentials/fabric/BBUtils.java | 6 +- .../fabric/BBsentialsConfigScreemFactory.java | 4 +- .../java/de/hype/bbsentials/fabric/Commands.java | 16 +- .../de/hype/bbsentials/fabric/DebugThread.java | 2 +- .../java/de/hype/bbsentials/fabric/FabricChat.java | 6 +- .../java/de/hype/bbsentials/fabric/MCUtils.java | 2 +- .../de/hype/bbsentials/fabric/ModInitialiser.java | 12 +- .../java/de/hype/bbsentials/fabric/Options.java | 4 +- .../fabric/mixins/ItemRendererMixin.java | 2 +- .../fabric/mixins/SimpleOptionMixin.java | 2 +- .../assets/bbsentials/textures/item/splash_hub.png | Bin 5537 -> 0 bytes .../resources/assets/public_bbsentials_cert.crt | Bin 1431 -> 0 bytes fabric/src/main/resources/logo.png | Bin 2092 -> 0 bytes .../resources/sounds/mixkit-gaming-lock-2848.wav | Bin 201240 -> 0 bytes .../sounds/mixkit-interface-option-select-2573.wav | Bin 274068 -> 0 bytes .../main/resources/sounds/mixkit-long-pop-2358.wav | Bin 226002 -> 0 bytes .../resources/sounds/mixkit-sci-fi-click-900.wav | Bin 184244 -> 0 bytes .../sounds/mixkit-sci-fi-confirmation-914.wav | Bin 276320 -> 0 bytes forge/build.gradle | 127 +++++ forge/gradle.properties | 20 + .../java/de/hype/bbsentials/forge/ExampleMod.java | 36 ++ .../java/de/hype/bbsentials/forge/Temphook.java | 18 + .../java/de/hype/bbsentials/forge/chat/Chat.java | 580 +++++++++++++++++++++ .../java/de/hype/bbsentials/forge/chat/Sender.java | 100 ++++ .../hype/bbsentials/forge/client/BBsentials.java | 42 ++ .../hype/bbsentials/forge/client/CommandBBI.java | 87 ++++ .../forge/client/Commands/Command2xPowder.java | 29 ++ .../forge/client/Commands/CommandBAnnounce.java | 36 ++ .../forge/client/Commands/CommandBBServer.java | 41 ++ .../forge/client/Commands/CommandBBan.java | 36 ++ .../forge/client/Commands/CommandBC.java | 36 ++ .../forge/client/Commands/CommandBMute.java | 35 ++ .../client/Commands/CommandBetterTogether.java | 29 ++ .../forge/client/Commands/CommandBingoChat.java | 35 ++ .../forge/client/Commands/CommandChChest.java | 48 ++ .../forge/client/Commands/CommandGoblinRaid.java | 29 ++ .../client/Commands/CommandGoneWithTheWind.java | 29 ++ .../forge/client/Commands/CommandRaffle.java | 29 ++ .../client/Commands/CommandSplashAnnounce.java | 50 ++ .../forge/client/Commands/CommandsOLD.java | 38 ++ .../de/hype/bbsentials/forge/client/Config.java | 198 +++++++ .../forge/communication/BBsentialConnection.java | 341 ++++++++++++ .../bbsentials/forge/mixin/MixinGuiMainMenu.java | 16 + .../bbsentials/forge/mixin/MixinRenderItem.java | 30 ++ forge/src/main/resources/mcmod.info | 18 + forge/src/main/resources/mixins.bbsentials.json | 11 + settings.gradle | 26 +- 150 files changed, 5215 insertions(+), 3122 deletions(-) delete mode 100644 common/src/main/java/de/hype/bbsentials/common/api/Discord.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/api/Formatting.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/api/ISimpleOption.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/chat/Chat.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/chat/Message.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/chat/Sender.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/Commands/Commands.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/Config.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/CustomGson.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/SplashManager.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/client/ToDisplayConfig.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProvider.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProviderWithCustom.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItem.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItems.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/EnumUtils.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/Islands.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/MiningEvents.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/BBUtils.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/EnvironmentCore.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/MCCommand.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/mclibraries/Options.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/AbstractPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/EnviromentPacketConfig.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/Packet.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/PacketUtils.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/BingoChatMessagePacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/BroadcastMessagePacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/ChChestPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/DisconnectPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/DisplayTellrawMessagePacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/InternalCommandPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/InvalidCommandFeedbackPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/MiningEventPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/PartyPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/PunishUserPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestConnectPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashNotifyPacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashUpdatePacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/SystemMessagePacket.java delete mode 100644 common/src/main/java/de/hype/bbsentials/common/packets/packets/WelcomeClientPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/api/Discord.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/api/Formatting.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/api/ISimpleOption.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/chat/Chat.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/chat/Message.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/chat/Sender.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/BBsentials.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/Commands/Commands.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/Config.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/CustomGson.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/DebugThread.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/SplashManager.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/SplashStatusUpdateListener.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/client/ToDisplayConfig.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/communication/BBsentialConnection.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProvider.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProviderWithCustom.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/AuthenticationConstants.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItem.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItems.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/EnumUtils.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/InternalReasonConstants.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/Islands.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/MiningEvents.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/BBUtils.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/EnvironmentCore.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCChat.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCCommand.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCUtils.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/Options.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/AbstractPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/EnviromentPacketConfig.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/Packet.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketManager.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketUtils.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BingoChatMessagePacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BroadcastMessagePacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/ChChestPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisconnectPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisplayTellrawMessagePacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InternalCommandPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InvalidCommandFeedbackPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/MiningEventPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PartyPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PunishUserPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/RequestConnectPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashNotifyPacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashUpdatePacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SystemMessagePacket.java create mode 100644 common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/WelcomeClientPacket.java delete mode 100644 common/src/main/resources/bbsentials.mixins.json delete mode 100644 common/src/main/resources/fabric.mod.json delete mode 100644 fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png delete mode 100644 fabric/src/main/resources/assets/public_bbsentials_cert.crt delete mode 100644 fabric/src/main/resources/logo.png delete mode 100644 fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav delete mode 100644 fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav delete mode 100644 fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav delete mode 100644 fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav delete mode 100644 fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav create mode 100644 forge/build.gradle create mode 100644 forge/gradle.properties create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/Temphook.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/chat/Chat.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/chat/Sender.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/BBsentials.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/CommandBBI.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/Command2xPowder.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBAnnounce.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBServer.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBan.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBC.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBMute.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBetterTogether.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBingoChat.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandChChest.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoblinRaid.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoneWithTheWind.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandRaffle.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandSplashAnnounce.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandsOLD.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/Config.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/communication/BBsentialConnection.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinGuiMainMenu.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinRenderItem.java create mode 100644 forge/src/main/resources/mcmod.info create mode 100644 forge/src/main/resources/mixins.bbsentials.json diff --git a/common/src/main/java/de/hype/bbsentials/common/api/Discord.java b/common/src/main/java/de/hype/bbsentials/common/api/Discord.java deleted file mode 100644 index 6b2f468..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/api/Discord.java +++ /dev/null @@ -1,70 +0,0 @@ -package de.hype.bbsentials.common.api; - -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.client.BBsentials; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; - -public class Discord { - public static void sendWebhookMessage(String message) { - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - sendWebhookMessageNoThread(message); - } - }); - thread.start(); - } - - - public static void sendWebhookMessageNoThread(String message) { - CloseableHttpClient httpClient = HttpClients.createDefault(); - String WEBHOOK_URL = "https://discord.com/api/v8/webhooks/1127524566407860276/" + BBsentials.getConfig().getApiKey(); - - - try { - HttpPost httpPost = new HttpPost(WEBHOOK_URL); - - StringEntity jsonEntity = new StringEntity("{\"content\": \"" + message + "\"}", StandardCharsets.UTF_8); - jsonEntity.setContentType("application/json"); - httpPost.setEntity(jsonEntity); - - CloseableHttpResponse response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - - if (responseEntity != null) { - InputStream inputStream = responseEntity.getContent(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - - String line; - StringBuilder responseBuilder = new StringBuilder(); - while ((line = reader.readLine()) != null) { - responseBuilder.append(line); - } - - String responseString = responseBuilder.toString(); - Chat.sendPrivateMessageToSelfInfo(responseString); - } - - response.close(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/api/Formatting.java b/common/src/main/java/de/hype/bbsentials/common/api/Formatting.java deleted file mode 100644 index c8702d4..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/api/Formatting.java +++ /dev/null @@ -1,36 +0,0 @@ -package de.hype.bbsentials.common.api; - -public enum Formatting{ - BLACK("§0"), - DARK_BLUE("§1"), - DARK_GREEN("§2"), - DARK_AQUA("§3"), - DARK_RED("§4"), - DARK_PURPLE("§5"), - GOLD("§6"), - GRAY("§7"), - DARK_GRAY("§8"), - BLUE("§9"), - GREEN("§a"), - AQUA("§b"), - RED("§c"), - LIGHT_PURPLE("§d"), - YELLOW("§e"), - BOLD("§l"), - ITALIC("§o"), - UNDERLINE("§n"), - STRIKETHROUGH("§m"), - RESET("§r"), - WHITE("§f"); - - private final String code; - - Formatting(String code) { - this.code = code; - } - - @Override - public String toString() { - return code; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/api/ISimpleOption.java b/common/src/main/java/de/hype/bbsentials/common/api/ISimpleOption.java deleted file mode 100644 index 28808d9..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/api/ISimpleOption.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.hype.bbsentials.common.api; - -public interface ISimpleOption { - void set(Object value); -} diff --git a/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java b/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java deleted file mode 100644 index 7f450bb..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/chat/Chat.java +++ /dev/null @@ -1,421 +0,0 @@ -package de.hype.bbsentials.common.chat; - -import de.hype.bbsentials.common.api.Formatting; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.client.Config; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import de.hype.bbsentials.common.packets.packets.SplashUpdatePacket; - -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static de.hype.bbsentials.common.client.BBsentials.*; - -public class Chat { - - public static String[] getVariableInfo(String packageName, String className) { - List variableInfoList = new ArrayList<>(); - - // Combine the class name with the package name - String fullClassName = packageName + "." + className; - - // Load the class - Class clazz = null; - try { - clazz = Class.forName(fullClassName); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - // Extract fields of the class - Field[] fields = clazz.getDeclaredFields(); - - // Collect information for each field - for (Field field : fields) { - // Exclude transient fields - if (java.lang.reflect.Modifier.isTransient(field.getModifiers())) { - continue; - } - String variableName = field.getName(); - String variablePackageName = clazz.getPackage().getName(); - String variableClassName = clazz.getSimpleName(); - - variableInfoList.add(variableName); - } - - return variableInfoList.toArray(new String[variableInfoList.size()]); - } - - public static void setVariableValue(Object obj, String variableName, String value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { - if (value == null) { - // Handle null value case - sendPrivateMessageToSelfError("Invalid value: null"); - return; - } - - Class objClass = obj.getClass(); - Field field = objClass.getDeclaredField(variableName); - field.setAccessible(true); - - // Get the type of the field - Class fieldType = field.getType(); - - // Convert the value to the appropriate type - Object convertedValue = parseValue(value, fieldType); - - if (Modifier.isStatic(field.getModifiers())) { - // If the field is static - field.set(null, convertedValue); - } - else { - field.set(obj, convertedValue); - } - - // Check and output the value of the variable - sendPrivateMessageToSelfSuccess("The variable " + field.getName() + " is now: " + field.get(obj)); - } - - private static Object parseValue(String value, Class targetType) { - if (targetType == int.class || targetType == Integer.class) { - return Integer.parseInt(value); - } - else if (targetType == double.class || targetType == Double.class) { - return Double.parseDouble(value); - } - else if (targetType == float.class || targetType == Float.class) { - return Float.parseFloat(value); - } - else if (targetType == long.class || targetType == Long.class) { - return Long.parseLong(value); - } - else if (targetType == boolean.class || targetType == Boolean.class) { - return Boolean.parseBoolean(value); - } - else { - // For other types, return the original string value - return value; - } - } - - public static void getVariableValue(Object object, String variableName) throws NoSuchFieldException, IllegalAccessException { - Class objClass = object.getClass(); - Field field = objClass.getDeclaredField(variableName); - field.setAccessible(true); - sendPrivateMessageToSelfSuccess("The variable " + field.getName() + " is: " + field.get(object)); - } - - public Message onEvent(Message text) { - if (!isSpam(text.toString())) { - if (getConfig().isDetailedDevModeEnabled()) { - System.out.println("got a message: " + text.getJson()); - } - Message message = new Message(text.toString(),text.getString()); - executionService.execute(() -> processThreaded(message)); - return processNotThreaded(message); - } - return text; // Return the original message if it is spam - } - - //Handle in the messages which need to be modified here - public Message processNotThreaded(Message message) { -// if (message.isFromParty()) { -// message.replaceInJson("\"action\":\"run_command\",\"value\":\"/viewprofile", "\"action\":\"run_command\",\"value\":\"/bviewprofile " + messageUnformatted.split(">", 1)[1].trim()); -// } - if (message.isFromReportedUser()) { - sendPrivateMessageToSelfBase(Formatting.RED + "B: " + message.getUnformattedString()); - return null; - } - if (config.doPartyChatCustomMenu && message.isFromParty()) { - message.replaceInJson("/viewprofile \\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", "/socialoptions party " + message.getPlayerName() + " " + message.getUnformattedString()); - } - else if (config.doGuildChatCustomMenu && message.isFromGuild()) { - message.replaceInJson("/viewprofile \\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", "/socialoptions guild " + message.getPlayerName() + " " + message.getUnformattedString()); - } - else if (config.doAllChatCustomMenu) { - System.out.println("User: '" + message.getPlayerName() + "' | Message: " + message.getUnformattedString()); - message.replaceInJson("/socialoptions " + message.getPlayerName(), "/socialoptions sb " + message.getPlayerName() + " " + message.getUnformattedString()); - } - - return message; - } - - public void processThreaded(Message message) { - if (message.getString() != null) { - String messageUnformatted = message.getUnformattedString(); - String username = message.getPlayerName(); - if (message.isFromReportedUser()) { - - } - else if (!EnvironmentCore.mcUtils.isWindowFocused()) { - if (config.doDesktopNotifications) { - if ((messageUnformatted.endsWith("is visiting Your Garden !") || messageUnformatted.endsWith("is visiting Your Island !")) && !EnvironmentCore.mcUtils.isWindowFocused() && config.doDesktopNotifications) { - sendNotification("BBsentials Visit-Watcher", messageUnformatted); - } - else if (message.isMsg()) { - sendNotification("BBsentials Message Notifier", username + " sent you the following message: " + message.getMessageContent()); - } - if (message.getMessageContent().toLowerCase().contains(getConfig().getUsername().toLowerCase()) || (message.getMessageContent().toLowerCase().contains(getConfig().getNickname().toLowerCase() + " ") && getConfig().getNotifForParty().toLowerCase().equals("nick")) || getConfig().getNotifForParty().toLowerCase().equals("all")) { - sendNotification("BBsentials Party Chat Notification", username + " : " + message.getMessageContent()); - } - else { - if (message.getMessageContent().toLowerCase().contains(getConfig().getUsername().toLowerCase()) || message.getMessageContent().toLowerCase().contains(config.getNickname().toLowerCase() + " ")) { - sendNotification("BBsentials Notifier", "You got mentioned in chat! " + message.getMessageContent()); - } - } - } - } - else if (message.isServerMessage()) { - if (messageUnformatted.contains("disbanded the party")) { - lastPartyDisbandedUsername = username; - partyDisbandedMap.put(username, Instant.now()); - } - else if (message.contains("invited you to join their party")) { - if (lastPartyDisbandedUsername != null && partyDisbandedMap != null) { - Instant lastDisbandedInstant = partyDisbandedMap.get(lastPartyDisbandedUsername); - if (config.acceptReparty) { - if (lastDisbandedInstant != null && lastDisbandedInstant.isAfter(Instant.now().minusSeconds(20)) && (username.equals(lastPartyDisbandedUsername))) { - sendCommand("/p accept " + username); - } - } - } - if (!EnvironmentCore.mcUtils.isWindowFocused()) { - sendNotification("BBsentials Party Notifier", "You got invited too a party by: " + username); - } - } - else if (message.startsWith("Party Members (")) { - Config.partyMembers = new ArrayList<>(); - } - else if (message.startsWith("Party Moderators:")) { - String temp = messageUnformatted.replace("Party Moderators:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); - if (temp.contains(",")) { - for (int i = 0; i < temp.split(",").length; i++) { - Config.partyMembers.add(temp.split(",")[i - 1]); - } - } - else { - Config.partyMembers.add(temp); - } - } - else if (message.startsWith("Party Members:")) { - String temp = messageUnformatted.replace("Party Members:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); - if (temp.contains(",")) { - for (int i = 0; i < temp.split(",").length; i++) { - System.out.println("Added to plist: " + (temp.split(",")[i - 1])); - Config.partyMembers.add(temp.split(",")[i - 1]); - } - } - else { - Config.partyMembers.add(temp); - } - } - else if ((message.contains("Party Leader:") && !message.contains(getConfig().getUsername())) || message.equals("You are not currently in a party.") || (message.contains("warped the party into a Skyblock Dungeon") && !message.startsWith(getConfig().getUsername()) || (!message.startsWith("The party was transferred to " + getConfig().getUsername()) && message.startsWith("The party was transferred to"))) || messageUnformatted.endsWith(getConfig().getUsername() + " is now a Party Moderator") || (message.startsWith("The party was disbanded")) || (message.contains("You have joined ") && message.contains("'s party!")) || (message.contains("Party Leader, ") && message.contains(" , summoned you to their server.")) || (message.contains("warped to your dungeon"))) { - BBsentials.getConfig().setIsLeader(false); - if (getConfig().isDetailedDevModeEnabled()) { - sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader()); - } - } - else if (config.getPlayersInParty().length == 0 && messageUnformatted.endsWith("to the party! They have 60 seconds to accept")) { - config.setIsLeader(true); - } - else if (messageUnformatted.startsWith("You'll be partying with:")) { - List members = new ArrayList<>(); - for (String users : messageUnformatted.replace("You'll be partying with:", "").replaceAll("\\[[^\\]]*\\]","").trim().split(",")) { - if (users.contains("and ")){break;} - members.add(users); - } - Config.partyMembers=members; - } - else if (((messageUnformatted.startsWith("Party Leader: ") && messageUnformatted.endsWith(getConfig().getUsername() + " ●"))) || (message.contains(getConfig().getUsername() + " warped the party to a SkyBlock dungeon!")) || message.startsWith("The party was transferred to " + getConfig().getUsername()) || message.getUnformattedString().endsWith(" has promoted " + getConfig().getUsername() + " to Party Leader") || (message.contains("warped to your dungeon"))) { - BBsentials.getConfig().setIsLeader(true); - if (getConfig().isDetailedDevModeEnabled()) { - sendPrivateMessageToSelfDebug("Leader: " + getConfig().isLeader()); - } - } - else if (message.getUnformattedString().equals("Please type /report confirm to log your report for staff review.")) { - sendCommand("/report confirm"); - } - else if (messageUnformatted.startsWith("BUFF! You splashed yourself with")) { - if (splashStatusUpdateListener != null) { - splashStatusUpdateListener.setStatus(SplashUpdatePacket.STATUS_SPLASHING); - } - } - } - - else if (message.isFromGuild()) { - - } - else if (message.isFromParty()) { - - } - else if (message.isMsg()) { - if (messageUnformatted.endsWith("bb:party me")) { - if (BBsentials.getConfig().allowBBinviteMe()) { - sendCommand("/p " + username); - } - } - } - else { - if (message.contains("[OPEN MENU]") || message.contains("[YES]")) { - setChatPromtId(message.getJson()); - } - } - } - } - - //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""}// {"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile f772b2c7-bd2a-46e1-b1a2-41fa561157d6"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bShourtu§e's profile"}},"text":"§9Party §8> §b[MVP§c+§b] Shourtu§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"Hype_the_Time TEST"}],"text":""} - //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""} - private final Map partyDisbandedMap = new HashMap<>(); - private String lastPartyDisbandedUsername = null; - - - public boolean isSpam(String message) { - if (message==null) return true; - if (message.isEmpty()) return true; - if (message.contains("Mana")) return true; - if (message.contains("Status")) return true; - if (message.contains("Achievement Points")) return true; - return false; - } - - public String test() { - //put test code here - sendNotification("test", "This is an example which was run of the h:test test"); - return new String(); - } - - public static void sendPrivateMessageToSelfError(String message) { - sendPrivateMessageToSelfBase(Formatting.RED + message); - } - - public static void sendPrivateMessageToSelfFatal(String message) { - sendPrivateMessageToSelfBase(Formatting.DARK_RED + message); - } - - public static void sendPrivateMessageToSelfSuccess(String message) { - sendPrivateMessageToSelfBase(Formatting.GREEN + message); - } - - public static void sendPrivateMessageToSelfInfo(String message) { - sendPrivateMessageToSelfBase(Formatting.YELLOW + message); - } - - public static void sendPrivateMessageToSelfImportantInfo(String message) { - sendPrivateMessageToSelfBase(Formatting.GOLD + message); - } - - public static void sendPrivateMessageToSelfDebug(String message) { - sendPrivateMessageToSelfBase(Formatting.AQUA + message); - } - - private static void sendPrivateMessageToSelfBase(String message) { - EnvironmentCore.chat.sendClientSideMessage(Message.of(message)); - } - - public static void sendPrivateMessageToSelfText(Message message) { - EnvironmentCore.chat.sendClientSideMessage(message); - } - - public static void sendCommand(String s) { - getConfig().sender.addSendTask(s); - } - - public void sendNotification(String title, String text) { - executionService.execute(() -> { - try { - InputStream inputStream = getClass().getResourceAsStream("/sounds/mixkit-sci-fi-confirmation-914.wav"); - AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream); - Clip clip = AudioSystem.getClip(); - clip.open(audioInputStream); - clip.start(); - Thread.sleep(clip.getMicrosecondLength() / 1000); - clip.close(); - audioInputStream.close(); - } catch (Exception e) { - e.printStackTrace(); - } - }); - List argsList = new ArrayList<>(); - argsList.add("--title"); - argsList.add(title); - argsList.add("--passivepopup"); - argsList.add(text); - argsList.add("5"); - - try { - ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.command("kdialog"); - processBuilder.command().addAll(argsList); - - Process process = processBuilder.start(); - process.waitFor(); - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - } - public static void setChatPromtId(String logMessage) { - String cbUUIDPattern = "/cb ([a-fA-F0-9-]+)"; - Pattern cbPattern = Pattern.compile(cbUUIDPattern); - Matcher cbMatcher = cbPattern.matcher(logMessage); - - String yesClickAction = "/chatprompt ([a-fA-F0-9-]+) YES"; - Pattern yesPattern = Pattern.compile(yesClickAction); - Matcher yesMatcher = yesPattern.matcher(logMessage); - String lastPrompt = null; - if (cbMatcher.find()) { - lastPrompt = cbMatcher.group(1); - String finalLastPrompt1 = lastPrompt; - new Thread(new Runnable() { - @Override - public void run() { - String promptCommand = "/cb " + finalLastPrompt1; - BBsentials.getConfig().setLastChatPromptAnswer(promptCommand); - if (config.isDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\""); - } - try { - Thread.sleep(10 * 1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - BBsentials.getConfig().setLastChatPromptAnswer(null); - return; - } - }).start(); - } - if (yesMatcher.find()) { - lastPrompt = yesMatcher.group(1); - String finalLastPrompt = lastPrompt; - new Thread(new Runnable() { - @Override - public void run() { - String promptCommand = "/chatprompt " + finalLastPrompt + " YES"; - getConfig().setLastChatPromptAnswer(promptCommand); - if (config.isDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\""); - } - try { - Thread.sleep(10 * 1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - getConfig().setLastChatPromptAnswer(null); - return; - } - }).start(); - - } - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/chat/Message.java b/common/src/main/java/de/hype/bbsentials/common/chat/Message.java deleted file mode 100644 index 66a3599..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/chat/Message.java +++ /dev/null @@ -1,111 +0,0 @@ -package de.hype.bbsentials.common.chat; - -import de.hype.bbsentials.common.client.BBsentials; - -public class Message { - private String text; - private String unformattedString = null; - private String playerName = null; - private String string; - - public Message(String textJson,String string) { - this.text = textJson; - if (string==null) string = ""; - this.string=string; - } - public static Message of(String string){ - return new Message("{\"text\":\""+string+"\"}",string); - } - // - public String getJson() { - return text; - } - - public String getString() { - return string; - } - - public String getUnformattedString() { - if (unformattedString != null) return unformattedString; - unformattedString = string.replaceAll("§.", "").trim(); - return unformattedString; - } - - public String getMessageContent() { - if (isServerMessage()) return unformattedString; - return getUnformattedString().split(":", 2)[1]; - } - - Boolean guild = null; - - public boolean isFromGuild() { - if (guild != null) return guild; - guild = getUnformattedString().startsWith("Guild >"); - return guild; - } - - Boolean party = null; - - public boolean isFromParty() { - if (party != null) return party; - party = getUnformattedString().startsWith("Party >"); - return party; - } - - Boolean msg = null; - - public boolean isMsg() { - if (msg != null) return msg; - msg = getUnformattedString().startsWith("From") || getUnformattedString().startsWith("To"); - return msg; - } - - Boolean server = null; - - public boolean isServerMessage() { - if (server != null) return server; - int space = getUnformattedString().indexOf(" "); - int doublepoint = getUnformattedString().indexOf(":"); - return ((space + 2 < doublepoint)||doublepoint==-1||space==-1); - } - - public String getPlayerName() { - if (playerName != null) return playerName; - playerName = getUnformattedString(); - if (!playerName.contains(":")) { - playerName = ""; - return ""; - } - playerName = playerName.split(":", 2)[0]; - if (isMsg()) { - playerName = playerName.replaceFirst("From", "").replace("To", "").trim(); - } - if (playerName.contains(">")){ - playerName=playerName.split(">",2)[1]; - } -// playerName = playerName.replaceFirst("\\[[^\\]]*\\](?:\\s?[^\\x00-\\x7F]?\\s?\\[[^\\]]*\\])*", "").trim()// replaces every [] and unicode character before a asci character. - playerName = playerName.replaceAll("[^\\x00-\\x7F]","").replaceAll("\\[[^\\]]*\\]","").trim(); - if (playerName.matches("[^a-zA-Z0-9_-]+")) playerName = ""; - return playerName; - } - - public void replaceInJson(String replace, String replaceWith) { - text = text.replaceFirst(replace, replaceWith); - } - public boolean isFromReportedUser() { - return BBsentials.config.alreadyReported.contains(getPlayerName()) && !getPlayerName().isEmpty(); - } - - public boolean contains(String string) { - return getUnformattedString().contains(string); - } - - public boolean startsWith(String string) { - return getUnformattedString().startsWith(string); - } - - @Override - public String toString() { - return getUnformattedString(); - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/chat/Sender.java b/common/src/main/java/de/hype/bbsentials/common/chat/Sender.java deleted file mode 100644 index 9bdde1f..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/chat/Sender.java +++ /dev/null @@ -1,105 +0,0 @@ -package de.hype.bbsentials.common.chat; - -import de.hype.bbsentials.common.api.Formatting; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; - -import java.util.ArrayList; -import java.util.List; - -import static de.hype.bbsentials.common.chat.Chat.sendPrivateMessageToSelfInfo; -import static de.hype.bbsentials.common.chat.Chat.sendPrivateMessageToSelfText; - -public class Sender { - private final List sendQueue; - private final List sendQueueTiming; - private final List hidden; - - - public Sender() { - this.sendQueue = new ArrayList<>(); - this.sendQueueTiming = new ArrayList<>(); - this.hidden = new ArrayList<>(); - startSendingThread(); - } - - public void addSendTask(String task, double timing) { - synchronized (sendQueue) { - sendPrivateMessageToSelfText(Message.of(Formatting.GREEN + "Scheduled send-task (as " + sendQueueTiming.size() + " in line): " + task + " | Delay: " + timing)); - sendQueueTiming.add(timing); - sendQueue.add(task); - hidden.add(false); - sendQueue.notify(); // Notify the waiting thread that a new String has been added - } - } - - public void addHiddenSendTask(String task, double timing) { - synchronized (sendQueue) { - sendQueueTiming.add(timing); - sendQueue.add(task); - hidden.add(true); - - sendQueue.notify(); // Notify the waiting thread that a new String has been added - } - } - - public void addImmediateSendTask(String task) { - synchronized (sendQueue) { - sendQueueTiming.add(0, 0.0); - sendQueue.add(0, task); - hidden.add(false); - - sendQueue.notify(); // Notify the waiting thread that a new String has been added - } - } - - public void addSendTask(String task) { - addSendTask(task, 1); - } - - public void startSendingThread() { - Thread sendingThread = new Thread(new SendingRunnable()); - sendingThread.start(); - } - - private class SendingRunnable implements Runnable { - @Override - public void run() { - while (true) { - String task = getNextTask(); - if (task != null) { - send(task, sendQueueTiming.remove(0), hidden.remove(0)); - } - else { - synchronized (sendQueue) { - try { - sendQueue.wait(); // Wait for new Send - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } - } - } - - private String getNextTask() { - synchronized (sendQueue) { - if (!sendQueue.isEmpty()) { - return sendQueue.remove(0); - } - return null; - } - } - - private void send(String toSend, double timing, boolean hidden) { - try { - Thread.sleep((long) (timing * 1000)); // Simulate the send operation - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - EnvironmentCore.chat.sendChatMessage(toSend); - if (!hidden) { - sendPrivateMessageToSelfInfo("Sent Command to Server: " + toSend); - } - } - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java deleted file mode 100644 index b694add..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java +++ /dev/null @@ -1,89 +0,0 @@ -package de.hype.bbsentials.common.client; - -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.client.Commands.Commands; -import de.hype.bbsentials.common.communication.BBsentialConnection; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -public class BBsentials { - public static Config config; - public static BBsentialConnection connection; - public static Commands coms; - public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000); - public static boolean splashLobby; - private static Thread bbthread; - private static boolean initialised = false; - public static SplashStatusUpdateListener splashStatusUpdateListener; - - public static Config getConfig() { - return config; - } - - public static void connectToBBserver() { - connectToBBserver(config.connectToBeta); - } - - /** - * Checks if still connected to the Server. - * - * @return true if it connected; false if old connection is kept. - */ - public static boolean conditionalReconnectToBBserver() { - if (!connection.isConnected()) { - Chat.sendPrivateMessageToSelfInfo("Reconnecting"); - connectToBBserver(config.connectToBeta); - return true; - } - return false; - } - - public static void connectToBBserver(boolean beta) { - if (connection != null) { - connection.sendHiddenMessage("exit"); - } - if (bbthread != null) { - if (bbthread.isAlive()) { - bbthread.interrupt(); - } - } - bbthread = new Thread(() -> { - connection = new BBsentialConnection(); - coms = new Commands(); - connection.setMessageReceivedCallback(message -> executionService.execute(() -> connection.onMessageReceived(message))); - if (beta) { - connection.connect(config.getBBServerURL(), 5011); - } - else { - connection.connect(config.getBBServerURL(), 5000); - } - executionService.scheduleAtFixedRate(EnvironmentCore.debug, 0, 20, TimeUnit.SECONDS); - }); - bbthread.start(); - } - - /** - * Runs the mod initializer on the client environment. - */ - - public static void onServerSwap() { - splashLobby = false; - if (!initialised) { - config = Config.load(); - if (config.doGammaOverride) EnvironmentCore.mcoptions.setGamma(10); - Chat chat = new Chat(); - if (Config.isBingoTime() || config.overrideBingoTime()) { - connectToBBserver(); - } - initialised = true; - } - } - public void manualLoad() { - initialised = true; - config = Config.load(); - connectToBBserver(); - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Commands/Commands.java b/common/src/main/java/de/hype/bbsentials/common/client/Commands/Commands.java deleted file mode 100644 index deb4dda..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/Commands/Commands.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.hype.bbsentials.common.client.Commands; - -import de.hype.bbsentials.common.client.Config; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; - -import static de.hype.bbsentials.common.client.BBsentials.getConfig; -public class Commands { - public Commands() { - EnvironmentCore.commands.registerMain(); - Config config = getConfig(); - if (config.bbsentialsRoles != null) { - EnvironmentCore.commands.registerRoleRequired( - config.hasBBRoles("dev"), - config.hasBBRoles("admin"), - config.hasBBRoles("mod"), - config.hasBBRoles("splasher"), - config.hasBBRoles("beta"), - config.hasBBRoles("mining_events"), - config.hasBBRoles("mining_events") - ); - } - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/common/client/Config.java deleted file mode 100644 index a23fe62..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ /dev/null @@ -1,204 +0,0 @@ -package de.hype.bbsentials.common.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import de.hype.bbsentials.common.chat.Sender; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; - -import java.io.*; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -public class Config implements Serializable { - //DO NOT Change any of the following unless you know what you are doing! - public int apiVersion = 1; - public boolean allowServerPartyInvite = true; - public boolean devMode = false; - public boolean detailedDevMode = false; - //You can change again - - // set automatically - private transient boolean isLeader; - public transient String alreadyReported = ""; - public String[] bbsentialsRoles = {""}; - public static List partyMembers = new ArrayList<>(); - public transient ToDisplayConfig toDisplayConfig = ToDisplayConfig.loadFromFile(); - public transient final Sender sender = new Sender(); - public transient boolean highlightitem = false; - public transient String lastChatPromptAnswer = null; - private transient String username; - - // Set via load / default you may change these - public boolean overrideBingoTime = false; - public boolean connectToBeta = false; - - public String bbServerURL = "localhost"; - public String apiKey = ""; - public boolean showBingoChat = true; - public boolean doAllChatCustomMenu=true; - public boolean doPartyChatCustomMenu=true; - public boolean doGuildChatCustomMenu=true; - - public boolean allowBBinviteMe = true; - public boolean doDesktopNotifications = false; - public boolean showSplashStatusUpdates = true; - public boolean doGammaOverride = true; - public boolean acceptReparty; - public boolean autoSplashStatusUpdates; - public String nickname; - public String notifForMessagesType; - - // Set default attribute values - private void setDefaults() { - username = EnvironmentCore.mcUtils.getUsername(); - acceptReparty = true; - if (username.equals("Hype_the_Time")) { - nickname = "Hype"; - notifForMessagesType = "nick"; - doDesktopNotifications=true; - } //Gimmic for Developer due too things which dont make it into releases (bugs) - else { - nickname = ""; - notifForMessagesType = "none"; - } - } - - // Gson object for serialization - private final transient Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - // File object for storing the config - private final transient File CONFIG_FILE = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); - - // Constructor - public Config() { - setDefaults(); - } - - // Load the config from file - public static Config load() { - Config settings; - File CONFIG_FILE = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); - Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - if (CONFIG_FILE.exists()) { - try (FileReader reader = new FileReader(CONFIG_FILE)) { - settings = GSON.fromJson(reader, Config.class); - } catch (IOException e) { - e.printStackTrace(); - settings = new Config(); // Use default values if loading fails - settings.save(); - } catch (IllegalStateException e) { - System.out.println("Error loading config. Resetting it."); - settings = new Config(); - settings.save(); - } - } - else { - settings = new Config(); // Use default values if the file doesn't exist - settings.username = EnvironmentCore.mcUtils.getUsername(); - } - if (!settings.hasBBRoles("dev")) { - settings.detailedDevMode = false; - settings.devMode = false; - } - settings.save(); - return settings; - } - - // Save the config to file - public void save() { - try (FileWriter writer = new FileWriter(CONFIG_FILE)) { - GSON.toJson(this, writer); - } catch (IOException e) { - e.printStackTrace(); - } - toDisplayConfig.saveToFile(); - } - - // Getter methods for various config attributes - public String getUsername() { - return username; - } - - public boolean isLeader() { - return isLeader; - } - - public void setIsLeader(boolean value) { - isLeader = value; - } - - public String getNickname() { - return nickname; - } - - public String getNotifForParty() { - return notifForMessagesType; - } - - public boolean isDevModeEnabled() { - return devMode; - } - - public boolean isDetailedDevModeEnabled() { - return detailedDevMode; - } - - public String[] getPlayersInParty() { - return partyMembers.toArray(new String[0]); - } - - public void addReported(String playerName) { - alreadyReported = alreadyReported + " , " + playerName; - } - - public String getApiKey() { - return apiKey; - } - - public String getBBServerURL() { - return bbServerURL; - } - - - public static boolean isBingoTime() { - LocalDate currentDate = LocalDate.now(); - LocalDate lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth()); - LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1); - Boolean isBefore = currentDate.isAfter(lastDayOfMonth.minusDays(4)); - Boolean isInRange = currentDate.isBefore(firstDayOfMonth.plusDays(15)); - return isBefore || isInRange; - } - - public boolean overrideBingoTime() { - return overrideBingoTime; - } - - public String getLastChatPromptAnswer() { - return lastChatPromptAnswer; - } - - public boolean allowBBinviteMe() { - return allowBBinviteMe; - } - - public void setLastChatPromptAnswer(String lastChatPromptAnswer) { - this.lastChatPromptAnswer = lastChatPromptAnswer; - } - - public boolean hasBBRoles(String roleName) { - for (String role : bbsentialsRoles) { - if (role.equalsIgnoreCase(roleName)) { - return true; - } - } - return false; - } - - public int getApiVersion() { - return apiVersion; - } - - public String getMCUUID() { - return EnvironmentCore.mcUtils.getMCUUID().replace("-", ""); - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/CustomGson.java b/common/src/main/java/de/hype/bbsentials/common/client/CustomGson.java deleted file mode 100644 index 31f2626..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/CustomGson.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.hype.bbsentials.common.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public class CustomGson { - public static Gson create() { - return new GsonBuilder() -// .registerTypeHierarchyAdapter(BBDisplayNameProvider.class, new BBDisplayNameProviderSerializer()) - .create(); - - } - -// private static class BBDisplayNameProviderSerializer implements JsonSerializer, JsonDeserializer { -// @Override -// public JsonElement serialize(BBDisplayNameProvider src, Type typeOfSrc, JsonSerializationContext context) { -// return new JsonPrimitive(src.serialize()); // Serialize using the provided method -// } -// -// @Override -// public BBDisplayNameProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { -// String serializedValue = json.getAsString(); -// -// // Deserialize using the provided method (you need to implement this) -// return BBDisplayNameProvider.deserialize(serializedValue); -// } -// } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java b/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java deleted file mode 100644 index d51fcec..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/DebugThread.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.hype.bbsentials.common.client; - - -import java.util.List; - -public interface DebugThread extends Runnable { - - @Override - public default void run() { - loop(); - //place a breakpoint for only this thread here. - } - - public default void loop() { - } - - public default List test() { - return List.of(""); - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/SplashManager.java b/common/src/main/java/de/hype/bbsentials/common/client/SplashManager.java deleted file mode 100644 index 5d7d464..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/SplashManager.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.hype.bbsentials.common.client; - -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.constants.enviromentShared.Islands; -import de.hype.bbsentials.common.packets.packets.SplashNotifyPacket; -import de.hype.bbsentials.common.packets.packets.SplashUpdatePacket; - -import java.util.HashMap; -import java.util.Map; - -public class SplashManager { - public static Map splashPool = new HashMap<>(); - - public SplashManager() { - - } - - public static void addSplash(SplashNotifyPacket packet) { - splashPool.put(packet.splashId, new DisplaySplash(packet)); - } - - public static void updateSplash(SplashUpdatePacket packet) { - DisplaySplash splash = splashPool.get(packet.splashId); - if (splash != null) { - if (splash.alreadyDisplayed) { - if (BBsentials.config.showSplashStatusUpdates) { - Chat.sendPrivateMessageToSelfImportantInfo(splash.hubType.getDisplayName() + " #" + splash.hub + " is " + packet.status); - } - } - else { - splashPool.remove(splash.splashId); - } - } - } - - public static void display(int splashId) { - SplashNotifyPacket splash = splashPool.get(splashId); - if (splash == null) return; - String where; - if (splash.hubType.equals(Islands.DUNGEON_HUB)) { - where = "§5DUNGEON HUB§6"; - } - else { - where = "Hub"; - } - BBsentials.connection.splashHighlightItem("HUB #" + splash.hub, 20); - Chat.sendPrivateMessageToSelfImportantInfo(splash.splasherUsername + " is Splashing in " + where + " #" + splash.hub + " at " + splash.location + ":" + splash.extraMessage); - } - - private static class DisplaySplash extends SplashNotifyPacket { - public boolean alreadyDisplayed; - - public DisplaySplash(SplashNotifyPacket packet) { - super(packet.splashId, packet.hub, packet.splasherUsername, packet.location, packet.hubType, packet.extraMessage, packet.lessWaste); - alreadyDisplayed = false; - } - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java b/common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java deleted file mode 100644 index 5ea2384..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.hype.bbsentials.common.client; - -import de.hype.bbsentials.common.communication.BBsentialConnection; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import de.hype.bbsentials.common.packets.packets.SplashNotifyPacket; -import de.hype.bbsentials.common.packets.packets.SplashUpdatePacket; - -import java.util.concurrent.TimeUnit; - -public class SplashStatusUpdateListener implements Runnable { - BBsentialConnection connection; - SplashNotifyPacket packet; - private String status = SplashUpdatePacket.STATUS_WAITING; - public String newStatus = SplashUpdatePacket.STATUS_WAITING; - public boolean splashed = false; - public boolean full = false; - - public SplashStatusUpdateListener(BBsentialConnection connection, SplashNotifyPacket packet) { - this.connection = connection; - this.packet = packet; - } - - @Override - public void run() { - BBsentials.splashLobby = true; - int maxPlayerCount = EnvironmentCore.utils.getMaximumPlayerCount() - 5; - while (BBsentials.splashLobby) { - if (!full&&(EnvironmentCore.utils.getPlayerCount() >= maxPlayerCount)) { - newStatus = SplashUpdatePacket.STATUS_FULL; - full=true; - } - if (!status.equals(newStatus)) { - status = newStatus; - connection.sendPacket(new SplashUpdatePacket(packet.splashId, status)); - } - try { - Thread.sleep(250); - } catch (InterruptedException ignored) { - } - } - if (splashed) { - newStatus = SplashUpdatePacket.STATUS_DONE; - } - else { - newStatus = SplashUpdatePacket.STATUS_CANCELED; - } - if (!status.equals(newStatus)) { - status = newStatus; - connection.sendPacket(new SplashUpdatePacket(packet.splashId, status)); - } - } - - public void setStatus(String newStatus) { - this.newStatus = newStatus; - if (newStatus.equals(SplashUpdatePacket.STATUS_SPLASHING)) { - splashed=true; - BBsentials.executionService.schedule(() -> { - setStatus(SplashUpdatePacket.STATUS_DONE); - BBsentials.splashLobby = false; - }, 1, TimeUnit.MINUTES); - } - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/client/ToDisplayConfig.java b/common/src/main/java/de/hype/bbsentials/common/client/ToDisplayConfig.java deleted file mode 100644 index 8e8998c..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/client/ToDisplayConfig.java +++ /dev/null @@ -1,96 +0,0 @@ -package de.hype.bbsentials.common.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.lang.reflect.Field; - -public class ToDisplayConfig { - public boolean disableAll = false; - public boolean allChChestItem = true; - public boolean allRoboPart = false; - public boolean customChChestItem = false; - - public boolean prehistoricEgg = false; - public boolean pickonimbus2000 = false; - public boolean controlSwitch = false; - public boolean electronTransmitter = false; - public boolean ftx3070 = false; - public boolean robotronReflector = false; - 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; - - public String betterTogether = "none"; - public String doublePowder = "none"; - public String goneWithTheWind = "none"; - public boolean goblinRaid = false; - public boolean mithrilGourmand = false; - public boolean raffle = false; - - // Serialize the object to JSON and save to file - public void saveToFile() { - File configFile = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_display_Config.json"); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - try (FileWriter writer = new FileWriter(configFile)) { - gson.toJson(this, writer); - } catch (IOException e) { - e.printStackTrace(); - } - } - - // Deserialize the object from JSON file - public static ToDisplayConfig loadFromFile() { - File configFile = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_display_Config.json"); - Gson gson = new Gson(); - - try (FileReader reader = new FileReader(configFile)) { - return gson.fromJson(reader, ToDisplayConfig.class); - } catch (IOException e) { - e.printStackTrace(); - } - - // If file doesn't exist or there's an error, return a new instance - return new ToDisplayConfig(); - } - - public void setValueAndSave(String propertyName, Object newValue) { - String lowerCasePropertyName = propertyName.toLowerCase(); - - try { - Field field = getClass().getDeclaredField(lowerCasePropertyName); - field.setAccessible(true); - - field.set(this, newValue); - saveToFile(); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - } - - // Method to get a value based on property name - public boolean getValue(String propertyName) { - if (disableAll) return false; - String lowerCasePropertyName = propertyName.toLowerCase(); - try { - Field field = getClass().getDeclaredField(lowerCasePropertyName); - field.setAccessible(true); - return field.getBoolean(this); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - - return false; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java b/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java deleted file mode 100644 index 76ee4bd..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java +++ /dev/null @@ -1,550 +0,0 @@ -package de.hype.bbsentials.common.communication; - -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.chat.Message; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.client.SplashManager; -import de.hype.bbsentials.common.client.SplashStatusUpdateListener; -import de.hype.bbsentials.common.constants.enviromentShared.*; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import de.hype.bbsentials.common.packets.AbstractPacket; -import de.hype.bbsentials.common.packets.PacketManager; -import de.hype.bbsentials.common.packets.PacketUtils; -import de.hype.bbsentials.common.packets.packets.*; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.io.*; -import java.net.Socket; -import java.net.SocketException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.security.SecureRandom; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -public class BBsentialConnection { - private Socket socket; - private BufferedReader reader; - private PrintWriter writer; - private LinkedBlockingQueue messageQueue; - private MessageReceivedCallback messageReceivedCallback; - private String itemName = "Hub #0"; - private PacketManager packetManager; - - public BBsentialConnection() { - packetManager = new PacketManager(this); - } - - - - 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.connection.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.sendPrivateMessageToSelfFatal("§4" + emergencyMessage + "\n\n"); - /*try { - Thread.sleep(5000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - throw new RuntimeException(emergencyMessage);*/ - } - return false; - } - - - - public void connect(String serverIP, int serverPort) { - // Enable SSL handshake debugging - System.setProperty("javax.net.debug", "ssl,handshake"); - FileInputStream inputStream = null; - try { - // Load the BBssentials-online server's public certificate from the JKS file - try { - InputStream resouceInputStream = BBsentials.class.getResourceAsStream("/assets/public_bbsentials_cert.crt"); - - // Check if the resource exists - if (resouceInputStream == null) { - System.out.println("The resource '/assets/public_bbsentials_cert.crt' was not found."); - return; - } - - File tempFile = File.createTempFile("public_bbsentials_cert", ".crt"); - tempFile.deleteOnExit(); - - FileOutputStream outputStream = new FileOutputStream(tempFile); - - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = resouceInputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead); - } - - outputStream.close(); - resouceInputStream.close(); - - // Now you have the .crt file as a FileInputStream in the tempFile - inputStream = new FileInputStream(tempFile); - - // Use the fileInputStream as needed - - } catch (IOException e) { - e.printStackTrace(); - } - CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - X509Certificate serverCertificate = (X509Certificate) certFactory.generateCertificate(inputStream); - PublicKey serverPublicKey = serverCertificate.getPublicKey(); - - // Create a TrustManager that trusts only the server's public key - TrustManager[] trustManagers = new TrustManager[]{new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return null; // We don't need to check the client's certificates - } - - public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { - // Do nothing, client certificate validation not required - } - - public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { - // Check if the server certificate matches the expected one - if (certs.length == 1) { - PublicKey publicKey = certs[0].getPublicKey(); - if (!publicKey.equals(serverPublicKey)) { - throw new CertificateException("Server certificate not trusted."); - } - } - else { - throw new CertificateException("Invalid server certificate chain."); - } - } - }}; - - // Create an SSL context with the custom TrustManager - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, trustManagers, new SecureRandom()); - // Create an SSL socket factory - SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); - socket = sslSocketFactory.createSocket(serverIP, serverPort); - - socket.setKeepAlive(true); // Enable Keep-Alive - - reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); - writer = new PrintWriter(socket.getOutputStream(), true); - messageQueue = new LinkedBlockingQueue<>(); - - // Start message receiver thread - Thread messageReceiverThread = new Thread(() -> { - try { - while (true) { - String message = reader.readLine(); - if (message != null) { - if (messageReceivedCallback != null) { - messageReceivedCallback.onMessageReceived(message); - } - else { - Chat.sendPrivateMessageToSelfError("BB: It seemed like you disconnected. Reconnecting..."); - BBsentials.connectToBBserver(); - try { - Thread.sleep(1000 * 10); - } catch (Exception ignored) { - } - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } - }); - messageReceiverThread.start(); - messageReceiverThread.setName("bb receiver thread"); - // Start message sender thread - Thread messageSenderThread = new Thread(() -> { - try { - while (true) { - String message = messageQueue.take(); - writer.println(message); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (NullPointerException ignored) { - } - }); - messageSenderThread.start(); - messageSenderThread.setName("bb sender thread"); - - } catch (IOException | NoSuchAlgorithmException | - KeyManagementException e) { - e.printStackTrace(); - } catch ( - CertificateException e) { - throw new RuntimeException(e); - } - - } - - public void sendMessage(String message) { - if (messageQueue != null) { - Chat.sendPrivateMessageToSelfDebug("BBs: " + message); - messageQueue.offer(message); - } - else { - Chat.sendPrivateMessageToSelfError("BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect"); - } - } - - public void sendHiddenMessage(String message) { - if (BBsentials.getConfig().isDetailedDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); - } - try { - if (socket.isConnected() && writer != null) { - writer.println(message); - } - } catch (NullPointerException ignored) { - } - } - - public void sendCommand(String message) { - if (BBsentials.getConfig().isDetailedDevModeEnabled()) { - Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); - } - if (socket.isConnected() && writer != null) { - writer.println(message); - } - else { - Chat.sendPrivateMessageToSelfFatal("BB: 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) { - if (!PacketUtils.handleIfPacket(this, message)) { - if (message.startsWith("H-")) { - if (message.equals("H-BB-Login: ")) { - Chat.sendPrivateMessageToSelfSuccess("Logging into BBsentials-online"); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - sendPacket(new RequestConnectPacket(BBsentials.config.getMCUUID(), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE)); - } - } - else { - Chat.sendPrivateMessageToSelfSuccess("BB: " + message); - } - } - } - - public void dummy(Object o) { - //this does absoloutely nothing - } - - public void splashHighlightItem(String itemName, long displayTimeInMilliseconds) { - this.itemName = itemName; - BBsentials.config.highlightitem = true; - BBsentials.executionService.schedule(() -> { - BBsentials.config.highlightitem = false; - try { - socket.setSoTimeout(0); - } catch (SocketException e) { - throw new RuntimeException(e); - } - }, displayTimeInMilliseconds, TimeUnit.MILLISECONDS); - } - - public String getItemName() { - return itemName; - } - //TODO search - - public void setMessageReceivedCallback(MessageReceivedCallback callback) { - this.messageReceivedCallback = callback; - } - - public void sendPacket(E packet) { - String packetName = packet.getClass().getSimpleName(); - String rawjson = PacketUtils.parsePacketToJson(packet); - if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class))) { - Chat.sendPrivateMessageToSelfDebug("BBDev-sP: " + packetName + ": " + rawjson); - } - if (socket.isConnected() && writer != null) { - writer.println(packetName + "." + rawjson); - } - else { - Chat.sendPrivateMessageToSelfError("BB: Couldn't send a Packet? did you get disconnected?"); - } - } - - public void onBroadcastMessagePacket(BroadcastMessagePacket packet) { - Chat.sendPrivateMessageToSelfImportantInfo("[A] §r[" + packet.prefix + "§r]§6 " + packet.username + ": " + packet.message); - } - - public void onSplashNotifyPacket(SplashNotifyPacket packet) { - int waitTime; - if (packet.splasherUsername.equals(BBsentials.config.getUsername())&& BBsentials.config.autoSplashStatusUpdates) { - Chat.sendPrivateMessageToSelfInfo("The Splash Update Statuses will be updatet automatically for you. If you need to do something manually go into Discord Splash Dashboard"); - SplashStatusUpdateListener splashStatusUpdateListener = new SplashStatusUpdateListener(this, packet); - BBsentials.splashStatusUpdateListener = splashStatusUpdateListener; - BBsentials.executionService.execute(splashStatusUpdateListener); - } - else { - SplashManager.addSplash(packet); - if (packet.lessWaste) { - waitTime = Math.min(((EnvironmentCore.mcUtils.getPotTime() * 1000) / 80), 25 * 1000); - } - else { - waitTime = 0; - } - BBsentials.executionService.schedule(() -> { - SplashManager.display(packet.splashId); - }, waitTime, TimeUnit.MILLISECONDS); - } - } - - public void onBingoChatMessagePacket(BingoChatMessagePacket packet) { - if (BBsentials.config.showBingoChat) { - Chat.sendPrivateMessageToSelfInfo("[" + 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(new Message(tellrawText,"")); - } - } - else { - Chat.sendPrivateMessageToSelfImportantInfo("§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,..."); - Chat.sendPrivateMessageToSelfImportantInfo(PacketUtils.parsePacketToJson(packet)); - } - } - - public void onMiningEventPacket(MiningEventPacket packet) { - if (!BBsentials.config.toDisplayConfig.getValue("disableAll")) { - //its will returns false cause disabled is checked already before. - if (BBsentials.config.toDisplayConfig.blockChEvents && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) return; - if (!(BBsentials.config.toDisplayConfig.allEvents)) { - if (packet.event.equals(MiningEvents.RAFFLE)) { - if (!BBsentials.config.toDisplayConfig.raffle) return; - } - else if (packet.event.equals(MiningEvents.GOBLIN_RAID)) { - if (!BBsentials.config.toDisplayConfig.goblinRaid) return; - } - else if (packet.event.equals(MiningEvents.MITHRIL_GOURMAND)) { - if (!BBsentials.config.toDisplayConfig.mithrilGourmand) return; - } - else if (packet.event.equals(MiningEvents.BETTER_TOGETHER)) { - if (BBsentials.config.toDisplayConfig.betterTogether.equals("none")) return; - if (BBsentials.config.toDisplayConfig.betterTogether.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) - return; - if (BBsentials.config.toDisplayConfig.betterTogether.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) - return; - } - else if (packet.event.equals(MiningEvents.DOUBLE_POWDER)) { - if (BBsentials.config.toDisplayConfig.doublePowder.equals("none")) return; - if (BBsentials.config.toDisplayConfig.doublePowder.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) - return; - if (BBsentials.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 (BBsentials.config.toDisplayConfig.goneWithTheWind.equals("none")) return; - if (BBsentials.config.toDisplayConfig.goneWithTheWind.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) - return; - if (BBsentials.config.toDisplayConfig.goneWithTheWind.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) - return; - } - } - Chat.sendPrivateMessageToSelfImportantInfo(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; - Chat.sendPrivateMessageToSelfSuccess("Login Success"); - if (!packet.motd.isEmpty()) { - Chat.sendPrivateMessageToSelfImportantInfo(packet.motd); - } - } - else { - Chat.sendPrivateMessageToSelfError("Login Failed"); - } - } - - public void onDisconnectPacket(DisconnectPacket packet) { - Chat.sendPrivateMessageToSelfError(packet.displayMessage); - BBsentials.connection = null; - for (int i = 0; i < packet.waitBeforeReconnect.length; i++) { - int finalI = i; - BBsentials.executionService.schedule(() -> { - if (finalI == 1) { - BBsentials.connectToBBserver(); - } - else { - BBsentials.conditionalReconnectToBBserver(); - } - }, (long) (packet.waitBeforeReconnect[i] + (Math.random() * packet.randomExtraDelay)), TimeUnit.SECONDS); - } - } - - public void onDisplayTellrawMessagePacket(DisplayTellrawMessagePacket packet) { - /*Chat.sendPrivateMessageToSelfText(Chat.createClientSideTellraw(packet.rawJson));*/ - Chat.sendPrivateMessageToSelfImportantInfo("You received a tellraw Packet but it got ignored due too there being no safety checks in this version."); - } - - public void onInternalCommandPacket(InternalCommandPacket packet) { - if (packet.command.equals(InternalCommandPacket.REQUEST_POT_DURATION)) { - sendPacket(new InternalCommandPacket(InternalCommandPacket.SET_POT_DURATION, new String[]{String.valueOf(EnvironmentCore.mcUtils.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]); - EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); - for (int i = 0; i < 10; i++) { - int finalI = i; - BBsentials.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]); - EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); - } - else if (packet.command.equals(InternalCommandPacket.HUB)) { - BBsentials.config.sender.addImmediateSendTask("/hub"); - } - else if (packet.command.equals(InternalCommandPacket.PRIVATE_ISLAND)) { - BBsentials.config.sender.addImmediateSendTask("/is"); - } - else if (packet.command.equals(InternalCommandPacket.HIDDEN_HUB)) { - BBsentials.config.sender.addHiddenSendTask("/hub", 0); - } - else if (packet.command.equals(InternalCommandPacket.HIDDEN_PRIVATE_ISLAND)) { - BBsentials.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]); - Thread crashThread = new Thread(() -> { - EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); - for (int i = 10; i >= 0; i--) { - Chat.sendPrivateMessageToSelfFatal("BB: Time till crash: " + i); - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - } - } - System.exit(69); - }); - crashThread.start(); - } - else if (packet.command.equals(InternalCommandPacket.INSTACRASH)) { - System.out.println("BBsentials: InstaCrash triggered"); - System.exit(69); - } - } - - public void onInvalidCommandFeedbackPacket(InvalidCommandFeedbackPacket packet) { - Chat.sendPrivateMessageToSelfError(packet.displayMessage); - } - - public void onPartyPacket(PartyPacket packet) { - if (BBsentials.config.allowServerPartyInvite) { - Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users)); - } - else { - Chat.sendPrivateMessageToSelfImportantInfo("Blocked a Party Command from the Server: "+packet.type+" : "+String.join(" ", packet.users)); - } - } - - public void onSystemMessagePacket(SystemMessagePacket packet) { - if (packet.important) { - Chat.sendPrivateMessageToSelfImportantInfo("§n" + packet.message); - } - else { - Chat.sendPrivateMessageToSelfInfo(packet.message); - } - if (packet.ping) { - EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); - } - } - - public boolean showChChest(ChChestItem[] items) { - if (BBsentials.config.toDisplayConfig.allChChestItem) return true; - for (ChChestItem item : items) { - if (BBsentials.config.toDisplayConfig.customChChestItem && item.isCustom()) return true; - if (BBsentials.config.toDisplayConfig.allRoboPart && item.isRoboPart()) return true; - if (BBsentials.config.toDisplayConfig.prehistoricEgg && item.equals(ChChestItems.PrehistoricEgg)) return true; - if (BBsentials.config.toDisplayConfig.pickonimbus2000 && item.equals(ChChestItems.Pickonimbus2000)) return true; - if (BBsentials.config.toDisplayConfig.controlSwitch && item.equals(ChChestItems.ControlSwitch)) return true; - if (BBsentials.config.toDisplayConfig.electronTransmitter && item.equals(ChChestItems.ElectronTransmitter)) - return true; - if (BBsentials.config.toDisplayConfig.robotronReflector && item.equals(ChChestItems.RobotronReflector)) return true; - if (BBsentials.config.toDisplayConfig.superliteMotor && item.equals(ChChestItems.SuperliteMotor)) return true; - if (BBsentials.config.toDisplayConfig.syntheticHeart && item.equals(ChChestItems.SyntheticHeart)) return true; - if (BBsentials.config.toDisplayConfig.flawlessGemstone && item.equals(ChChestItems.FlawlessGemstone)) return true; - if (BBsentials.config.toDisplayConfig.jungleHeart && item.equals(ChChestItems.JungleHeart)) return true; - } - return false; - } - - public boolean isConnected() { - try { - socket.isConnected(); - return true; - } catch (Exception e) { - 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; - } - } - - public interface MessageReceivedCallback { - void onMessageReceived(String message); - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProvider.java b/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProvider.java deleted file mode 100644 index ca3aa36..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.hype.bbsentials.common.constants; - -public interface BBDisplayNameProvider { - String getDisplayName(); - - default String serialize() { - return name() + ":" + getDisplayName(); - } - - default String name() { - return ((Enum) this).name(); - } - -// public static BBDisplayNameProvider deserialize(String serializedValue) { -// String[] parts = serializedValue.split(":"); -// if (parts.length != 2) { -// throw new IllegalArgumentException("Invalid serialized value format"); -// } -// String enumName = parts[0]; -// String displayName = parts[1]; -// return ; -// } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProviderWithCustom.java b/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProviderWithCustom.java deleted file mode 100644 index 43cb5ac..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/BBDisplayNameProviderWithCustom.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.hype.bbsentials.common.constants; - -public interface BBDisplayNameProviderWithCustom> extends BBDisplayNameProvider { - T setDisplayName(String displayname); - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java deleted file mode 100644 index 52f1ea1..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/AuthenticationConstants.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -public class AuthenticationConstants { - //Authentication Types - public static final String MOJANG = "MOJANG"; - public static final String DATABASE = "DATABASE"; -} diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItem.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItem.java deleted file mode 100644 index b937367..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItem.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -public class ChChestItem { - private String displayName; - private boolean custom; - - public ChChestItem(String displayName) { - this.displayName = displayName; - this.custom = false; - } - - public ChChestItem(String displayName, boolean custom) { - this.displayName = displayName; - this.custom = custom; - } - - public String getDisplayName() { - return displayName; - } - - public ChChestItem setDisplayName(String displayName) { - this.displayName = displayName; - return this; - } - - public boolean isCustom() { - return custom; - } - - @Override - public String toString() { - return displayName; - } - - public boolean isGemstone() { - return displayName.startsWith("Flawless") && displayName.endsWith("Gemstone"); - } - - public boolean isRoboPart() { - String[] roboParts = {"Control Switch", "Electron Transmitter", "FTX 3070", "Robotron Reflector", "Superlite Motor", "Synthetic Heart"}; - for (String roboPart : roboParts) { - if (displayName.equals(roboPart)) return true; - } - return false; - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItems.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItems.java deleted file mode 100644 index 0a12742..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/ChChestItems.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class ChChestItems { - private static final List items = new ArrayList<>(); - - public static final ChChestItem PrehistoricEgg = new ChChestItem("Prehistoric Egg"); - public static final ChChestItem Pickonimbus2000 = new ChChestItem("Pickonimbus 2000"); - public static final ChChestItem ControlSwitch = new ChChestItem("Control Switch"); - public static final ChChestItem ElectronTransmitter = new ChChestItem("Electron Transmitter"); - public static final ChChestItem FTX3070 = new ChChestItem("FTX 3070"); - public static final ChChestItem RobotronReflector = new ChChestItem("Robotron Reflector"); - public static final ChChestItem SuperliteMotor = new ChChestItem("Superlite Motor"); - public static final ChChestItem SyntheticHeart = new ChChestItem("Synthetic Heart"); - public static final ChChestItem FlawlessGemstone = new ChChestItem("Flawless Gemstone"); - public static final ChChestItem JungleHeart = new ChChestItem("Jungle Heart"); - - // Automatically populate predefined items using reflection - static { - Field[] fields = ChChestItems.class.getDeclaredFields(); - for (Field field : fields) { - if (field.getType().equals(ChChestItem.class) && isPublicStaticFinal(field)) { - try { - items.add((ChChestItem) field.get(null)); - } catch (IllegalAccessException e) { - // Handle exception - } - } - } - } - - public static ChChestItem getItem(String displayName) { - ChChestItem existingItem = getPredefinedItem(displayName); - - if (existingItem != null) { - return existingItem; - } - - ChChestItem customItem = new ChChestItem(displayName, true); - return customItem; - } - - private static ChChestItem getPredefinedItem(String displayName) { - for (ChChestItem item : items) { - if (item.getDisplayName().equals(displayName)) { - return item; - } - } - return null; - } - - public static ChChestItem[] getItem(String[] displayNames) { - ChChestItem[] result = new ChChestItem[displayNames.length]; - for (int i = 0; i < displayNames.length; i++) { - result[i] = getItem(displayNames[i]); - } - return result; - } - - // Utility method to check if a field is public, static, and final - private static boolean isPublicStaticFinal(Field field) { - return java.lang.reflect.Modifier.isPublic(field.getModifiers()) && - java.lang.reflect.Modifier.isStatic(field.getModifiers()) && - java.lang.reflect.Modifier.isFinal(field.getModifiers()); - } - - public static ChChestItem createCustomItem(String displayName) { - ChChestItem customItem = new ChChestItem(displayName, true); - items.add(customItem); - return customItem; - } - - public static List getAllItems() { - return items; - } - - public static List getAllItemNames() { - return items.stream() - .map(ChChestItem::getDisplayName) - .collect(Collectors.toList()); - //very fancy way to convert a list to a list of values from the previous list - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/EnumUtils.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/EnumUtils.java deleted file mode 100644 index 5214f65..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/EnumUtils.java +++ /dev/null @@ -1,216 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -import de.hype.bbsentials.common.constants.BBDisplayNameProvider; -import de.hype.bbsentials.common.constants.BBDisplayNameProviderWithCustom; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class EnumUtils { - public static List getAllDisplayNames(Class enumClass) { - List displayNames = new ArrayList<>(); - - for (BBDisplayNameProvider item : enumClass.getEnumConstants()) { - displayNames.add(item.getDisplayName()); - } - - return displayNames; - } - - public static & BBDisplayNameProvider> List getEnumsAsList(Class enumClass) { - List enumList = new ArrayList<>(); - - for (T item : enumClass.getEnumConstants()) { - enumList.add(item); - } - - return enumList; - } - - public static List getDisplayNames(Collection itemList) { - List displayNames = new ArrayList<>(); - for (BBDisplayNameProvider item : itemList) { - displayNames.add(item.getDisplayName()); - } - return displayNames; - } - - public static List getEnumsAsList(List itemList) { - List enumList = new ArrayList<>(itemList); - return enumList; - } - - public static List getAllEnumNames(Class> enumClass) { - List enumNames = new ArrayList<>(); - Enum[] enumConstants = enumClass.getEnumConstants(); - - for (Enum enumConstant : enumConstants) { - enumNames.add(enumConstant.name()); - } - - return enumNames; - } - -// public interface BBDisplayNameProvider { -// String getDisplayName(); -// default public String serialize() { -// return name() + ":" + displayName; -// } -// -// default public ChChestItems deserialize(String serializedValue) { -// String[] parts = serializedValue.split(":"); -// if (parts.length != 2) { -// throw new IllegalArgumentException("Invalid serialized value format"); -// } -// String enumName = parts[0]; -// String displayName = parts[1]; -// -// return ChChestItems.valueOf(enumName).setDisplayName(displayName); -// } -// } - - - - // Methods for BBDisplayNameProviderWithCustom - - public static & BBDisplayNameProviderWithCustom> T getEnumByNameWithCustom(Class enumClass, String enumName) { - boolean found = false; - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.name().equals(enumName)) { - return (enumValue); - } - } - return createCustomEnum(enumClass, enumName); - } - - public static & BBDisplayNameProviderWithCustom> T getEnumByValueWithCustom(Class enumClass, String value) { - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.getDisplayName().equals(value)) { - return enumValue; - } - } - return (createCustomEnum(enumClass, value)); - - } - - public static & BBDisplayNameProviderWithCustom> T[] getEnumsByNameWithCustom(Class enumClass, String[] names) { - List matchingEnums = new ArrayList<>(); - - for (String name : names) { - boolean found = false; - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.name().equals(name)) { - matchingEnums.add(enumValue); - found = true; - break; - } - } - if (!found) { - matchingEnums.add(createCustomEnum(enumClass, name)); - } - } - - return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); - } - - public static & BBDisplayNameProviderWithCustom> T[] getEnumsByValueWithCustom(Class enumClass, String[] values) { - List matchingEnums = new ArrayList<>(); - - for (String value : values) { - boolean found = false; - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.toString().equals(value)) { - matchingEnums.add(enumValue); - found = true; - break; - } - } - if (!found) { - matchingEnums.add(createCustomEnum(enumClass, value)); - } - } - - return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); - } - - // Methods for BBDisplayNameProvider - - public static & BBDisplayNameProvider> T getEnumByName(Class enumClass, String enumName) { - try { - return Enum.valueOf(enumClass, enumName); - } catch (IllegalArgumentException e) { - return null; // Enum value not found - } - } - public static & BBDisplayNameProvider, U extends Enum> U getEnumByName(Class enumClass, Class enumType, String enumName) { - try { - return Enum.valueOf(enumType, enumName); - } catch (IllegalArgumentException e) { - return null; // Enum value not found - } - } - - - public static & BBDisplayNameProvider> T getEnumByValue(Class enumClass, String value) { - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.getDisplayName().equals(value)) { - return enumValue; - } - } - return null; - } - - public static & BBDisplayNameProvider> T[] getEnumsByName(Class enumClass, String[] names) { - List matchingEnums = new ArrayList<>(); - - for (String name : names) { - boolean found = false; - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.name().equals(name)) { - matchingEnums.add(enumValue); - found = true; - break; - } - } - } - - return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); - } - - public static & BBDisplayNameProvider> T[] getEnumsByValue(Class enumClass, String[] values) { - List matchingEnums = new ArrayList<>(); - - for (String value : values) { - boolean found = false; - for (T enumValue : enumClass.getEnumConstants()) { - if (enumValue.getDisplayName().equals(value)) { - matchingEnums.add(enumValue); - found = true; - break; - } - } - } - - return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); - } - - private static & BBDisplayNameProviderWithCustom> T createCustomEnum(Class enumClass, String value) { - T customEnum = null; - try { - customEnum = Enum.valueOf(enumClass, "Custom"); - } catch (Exception ignored) { - try { - customEnum = Enum.valueOf(enumClass, "CUSTOM"); - } catch (Exception ignored2) { - } - } - if (customEnum == null) { - } - customEnum.setDisplayName(value); - return customEnum; - - } -} - - diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java deleted file mode 100644 index 43835c6..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/InternalReasonConstants.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -public enum InternalReasonConstants { - INVALID_PARAMETER, - MISSING_PARAMETER, - INSUFFICIENT_PRIVILEGES, - MUTED, - BANNED, - API_UNSUPPORTED, - INVALID_LOGIN, - KICKED, - ANOTHER_LOGIN, - SERVER_RESTART -} diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/Islands.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/Islands.java deleted file mode 100644 index e2e914c..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/Islands.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -import de.hype.bbsentials.common.constants.BBDisplayNameProvider; - -public enum Islands implements BBDisplayNameProvider { - CRYSTAL_HOLLOWS("crystal_hollows", "Crystal Hollows"), - CRIMSON_ISLE("crimson_isle", "Crimson Isle"), - DEEP_CAVERNS("mining_2", "Deep Caverns"), - DUNGEON("dungeon", "Dungeon"), - DUNGEON_HUB("dungeon_hub", "Dungeon Hub"), - DWARVEN_MINES("mining_3", "Dwarven Mines"), - GOLD_MINE("mining_1", "Gold Mine"), - HUB("hub", "Hub"), - KUUDRA("kuudra", "Kuudra"), - PRIVATE_ISLAND("dynamic", "Private Islands"), - SPIDERS_DEN("combat_1", "Spider's Den"), - THE_END("combat_3", "The End"), - THE_FARMING_ISLANDS("farming_1", "The Farming Islands"), - JERRYS_WORKSHOP("winter", "Jerry's Workshop"), - THE_RIFT("rift", "The Rift"); - - - private final String internalName; - private final String displayName; - - Islands(String internalName, String displayName) { - this.internalName = internalName; - this.displayName = displayName; - } - - public String getInternalName() { - return internalName; - } - - public String getDisplayName() { - return displayName; - } - public static Islands getByDisplayName(String displayName) { - for (Islands island : values()) { - if (island.getDisplayName().equals(displayName)) { - return island; - } - } - return null; // Return null if the display name doesn't match any enum value - } - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/MiningEvents.java b/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/MiningEvents.java deleted file mode 100644 index 5f6e99e..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/constants/enviromentShared/MiningEvents.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.hype.bbsentials.common.constants.enviromentShared; - -import de.hype.bbsentials.common.constants.BBDisplayNameProvider; - -// Mining Events -public enum MiningEvents implements BBDisplayNameProvider { - BETTER_TOGETHER("Better Together"), - DOUBLE_POWDER("Double Powder"), - GONE_WITH_THE_WIND("Gone with the Wind"), - GOBLIN_RAID("Goblin Raid"), - MITHRIL_GOURMAND("Mithril Gourmand"), - RAFFLE("Raffle"); - - private final String displayName; - - MiningEvents(String displayName) { - this.displayName = displayName; - } - - @Override - public String getDisplayName() { - return displayName; - } - - //Some Events cant happen in Crystal Holows - public boolean isDWEventOnly() { - if (this.equals(MiningEvents.MITHRIL_GOURMAND) || this.equals(MiningEvents.RAFFLE) || this.equals(MiningEvents.GOBLIN_RAID)) { - return true; - } - return false; - } - - public static boolean isDWEventOnly(String event) { - if (event.equals(MiningEvents.MITHRIL_GOURMAND.getDisplayName()) || event.equals(MiningEvents.RAFFLE.getDisplayName()) || event.equals(MiningEvents.GOBLIN_RAID.getDisplayName())) { - return true; - } - return false; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/BBUtils.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/BBUtils.java deleted file mode 100644 index b2c9559..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/BBUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - -import de.hype.bbsentials.common.constants.enviromentShared.Islands; - -import java.util.List; - -public interface BBUtils { - Islands getCurrentIsland(); - - int getPlayerCount(); - - String getServer(); - - boolean isOnMegaServer(); - - boolean isOnMiniServer(); - - int getMaximumPlayerCount(); - - List getPlayers(); -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/EnvironmentCore.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/EnvironmentCore.java deleted file mode 100644 index f7e2eab..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/EnvironmentCore.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - - -import de.hype.bbsentials.common.client.DebugThread; - -public class EnvironmentCore { - public static MCCommand commands; - public static BBUtils utils; - public static MCChat chat; - public static MCUtils mcUtils; - public static Options mcoptions; - public static DebugThread debug; - - public EnvironmentCore(BBUtils utils, MCChat chat, MCUtils mcUtils, MCCommand commands, Options options, DebugThread debug) { - EnvironmentCore.utils = utils; - EnvironmentCore.chat = chat; - EnvironmentCore.mcUtils = mcUtils; - EnvironmentCore.commands = commands; - EnvironmentCore.mcoptions = options; - EnvironmentCore.debug=debug; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java deleted file mode 100644 index eeb89fe..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCChat.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - -import de.hype.bbsentials.common.chat.Message; - -public interface MCChat { - void init(); - void sendChatMessage(String message); - void sendClientSideMessage(Message message); -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCCommand.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCCommand.java deleted file mode 100644 index 133cff0..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCCommand.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - -public interface MCCommand { - public void registerMain(); - public void registerRoleRequired(boolean hasDev, boolean hasAdmin, boolean hasMod, boolean hasSplasher, boolean hasBeta, boolean hasMiningEvents, boolean hasChChest); -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java deleted file mode 100644 index 493785a..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - -import java.io.File; - -public interface MCUtils { - boolean isWindowFocused(); - - File getConfigPath(); - - String getUsername(); - - String getMCUUID(); - void playsound(String eventName); - - int getPotTime(); -} diff --git a/common/src/main/java/de/hype/bbsentials/common/mclibraries/Options.java b/common/src/main/java/de/hype/bbsentials/common/mclibraries/Options.java deleted file mode 100644 index b5cb014..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/Options.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.hype.bbsentials.common.mclibraries; - -public interface Options { - void setFov(int value); - - void setGamma(double value); -} - diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/AbstractPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/AbstractPacket.java deleted file mode 100644 index 7328517..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/AbstractPacket.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.hype.bbsentials.common.packets; - -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.client.Config; -import de.hype.bbsentials.common.communication.BBsentialConnection; -import de.hype.bbsentials.common.packets.packets.InvalidCommandFeedbackPacket; - -import java.lang.reflect.Field; - -public class AbstractPacket { - public final int apiVersionMin; - public final int apiVersionMax; - - protected AbstractPacket(int apiVersionMin, int apiVersionMax) { - this.apiVersionMax = apiVersionMax; - this.apiVersionMin = apiVersionMin; - - } - - public boolean isValid(BBsentialConnection connection, String[] allowedNullFields) { - if (isApiSupported(BBsentials.config)) { - Chat.sendPrivateMessageToSelfFatal("You are using an outdated version of the mod"); - } - return true; - } - - public boolean isApiSupported(Config config) { - //int version = Core.getConfig().getVersion(); - int version = config.getApiVersion(); - if (version >= apiVersionMin && version <= apiVersionMax) { - return true; - } - return false; - } - - public String hasNullFields(String[] allowedNullFields) { - Field[] fields = this.getClass().getDeclaredFields(); - if (!this.getClass().getSimpleName().equals(InvalidCommandFeedbackPacket.class.getSimpleName())) { - for (Field field : fields) { - field.setAccessible(true); - try { - if (field.get(this) == null) { - if (allowedNullFields == null) return field.getName(); - if (isAllowedNull(allowedNullFields, field.getName())) { - return field.getName(); - } - } - } catch (IllegalAccessException e) { - // Handle the exception if needed - e.printStackTrace(); - } - } - } - return null; - - } - - public boolean isAllowedNull(String[] allowedFields, String fieldName) { - for (String allowedField : allowedFields) { - if (allowedField.equals(fieldName)) { - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/EnviromentPacketConfig.java b/common/src/main/java/de/hype/bbsentials/common/packets/EnviromentPacketConfig.java deleted file mode 100644 index ee82d32..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/EnviromentPacketConfig.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.hype.bbsentials.common.packets; - -public class EnviromentPacketConfig { - public static final String enviroment = "Client"; - public static final String notEnviroment = "Server"; - public static final int apiVersion = 1; -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/Packet.java b/common/src/main/java/de/hype/bbsentials/common/packets/Packet.java deleted file mode 100644 index f184578..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/Packet.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.hype.bbsentials.common.packets; - -import java.util.function.Consumer; - -public class Packet { - - private final Class clazz; - private final Consumer consumer; - - public Packet(Class clazz, Consumer consumer) { - this.clazz = clazz; - this.consumer = consumer; - } - - public String getName() { - return clazz.getSimpleName(); - } - - public Class getClazz() { - return clazz; - } - - public Consumer getConsumer() { - return consumer; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java b/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java deleted file mode 100644 index 23368d8..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/PacketManager.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.hype.bbsentials.common.packets; - -import de.hype.bbsentials.common.communication.BBsentialConnection; -import de.hype.bbsentials.common.packets.packets.*; - -import java.util.ArrayList; -import java.util.List; - -public class PacketManager { - private static List> packets = new ArrayList<>(); - - public List> getPackets() { - return packets; - } - - // Define a map to store packet classes and their associated actions - BBsentialConnection connection; - - // Method to initialize packet actions - public PacketManager(BBsentialConnection connection) { - this.connection = connection; - initializePacketActions(connection); - } - - public static void initializePacketActions(BBsentialConnection connection) { - packets.add(new Packet<>(BingoChatMessagePacket.class, connection::onBingoChatMessagePacket)); - packets.add(new Packet<>(BroadcastMessagePacket.class, connection::onBroadcastMessagePacket)); - 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::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)); -// packets.add(new Packet<>(RequestConnectPacket.class, connection::dummy)); - packets.add(new Packet<>(SplashNotifyPacket.class, connection::onSplashNotifyPacket)); - packets.add(new Packet<>(SystemMessagePacket.class, connection::onSystemMessagePacket)); - packets.add(new Packet<>(WelcomeClientPacket.class, connection::onWelcomePacket)); - } - - // Method to handle a received packet - - - // method to get a list of all packets - public static List> getAllPacketClasses() { - initializePacketActions(null); - List> allPackets = new ArrayList<>(); - for (int i = 0; i < allPackets.size(); i++) { - allPackets.add(packets.get(i).getClazz()); - } - return allPackets; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/PacketUtils.java b/common/src/main/java/de/hype/bbsentials/common/packets/PacketUtils.java deleted file mode 100644 index bc5f9b0..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/PacketUtils.java +++ /dev/null @@ -1,103 +0,0 @@ -package de.hype.bbsentials.common.packets; - -import com.google.gson.Gson; -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.client.CustomGson; -import de.hype.bbsentials.common.communication.BBsentialConnection; - -import java.util.function.Consumer; - - -public class PacketUtils { - public static final Gson gson = CustomGson.create(); - - public static String parsePacketToJson(AbstractPacket packet) { - return gson.toJson(packet); - } - - public static void tryToProcessPacket(Packet packet, String rawJson) { - Class clazz = packet.getClazz(); - Consumer consumer = packet.getConsumer(); - T abstractPacket = gson.fromJson(rawJson, clazz); - consumer.accept(abstractPacket); - } - - private static void showError(Throwable t, String errorMessage) { - System.out.println(errorMessage + " because of: " + t.getClass().getSimpleName() + ": " + t.getMessage()); - new Error(errorMessage, t).printStackTrace(); - } - - public static class APIException extends Error { - - public APIException(String errorMessage, Throwable t) { - super(errorMessage, t); - } - - public APIException(String errorMessage) { - super(errorMessage); - } - } - - public static T getAsPacket(String message, Class clazz) { - if (!message.contains(".")) return null; - String packetName = message.split("\\.")[0]; - String rawJson = message.substring(packetName.length() + 1); - if (!packetName.equals(clazz.getSimpleName())) { - try { - T parsedPacket = gson.fromJson(rawJson, clazz); - return parsedPacket; - } catch (Throwable t) { - showError(t, "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment); - } - } - String errorMessage = "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment; - - showError(new APIException("Found unknown packet: " + packetName + "'"), errorMessage); - return null; - } - - public static boolean isPacket(String message, Class clazz) { - if (!message.contains(".")) return false; - String packetName = message.split("\\.")[0]; - if (packetName.equals(clazz.getSimpleName())) { - return true; - } - return false; - } - - public static boolean isPacket(String message) { - if (!message.contains(".")) return false; - String packetName = message.split("\\.")[0]; - for (Class packetClass : PacketManager.getAllPacketClasses()) { - if (!packetName.equals(packetClass.getSimpleName())) { - return true; - } - } - return false; - } - - public static boolean handleIfPacket(BBsentialConnection connection, String message) { - //Return = is Packet - if (!message.contains(".")) return false; - String packetName = message.split("\\.")[0]; - String rawJson = message.substring(packetName.length() + 1); - PacketManager manager = new PacketManager(connection); - for (Packet packet : manager.getPackets()) { - if (!packetName.equals(packet.getClazz().getSimpleName())) continue; - try { - if (BBsentials.getConfig().isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelfDebug(packetName+":"+rawJson); - tryToProcessPacket(packet, rawJson); - return true; - }catch (RuntimeException e){ - throw e; - }catch (Exception t) { - showError(t, "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment); - } - } - String errorMessage = "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment; - - showError(new APIException("Found unknown packet: " + packetName + "'"), errorMessage); - return false; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/BingoChatMessagePacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/BingoChatMessagePacket.java deleted file mode 100644 index c7432da..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/BingoChatMessagePacket.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class BingoChatMessagePacket extends AbstractPacket { - - public BingoChatMessagePacket(String prefix, String username, String message, int bingo_cards) { - super(1, 1); //Min and Max supported Version - this.message = message; - this.username = username; - this.prefix = prefix; - this.bingo_cards = bingo_cards; - } - - public final String message; - public final String username; - public final String prefix; - public final int bingo_cards; - - public boolean baseCheck() { - boolean cancelPacket = false; - return !cancelPacket; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/BroadcastMessagePacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/BroadcastMessagePacket.java deleted file mode 100644 index bbd6d90..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/BroadcastMessagePacket.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class BroadcastMessagePacket extends AbstractPacket { - - public final String message; - public final String username; - public final String prefix; - - public BroadcastMessagePacket(String prefix, String username, String message) { - super(1, 1); //Min and Max supported Version - this.message = message; - this.username = username; - this.prefix = prefix; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/ChChestPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/ChChestPacket.java deleted file mode 100644 index 7355397..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/ChChestPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.constants.enviromentShared.ChChestItem; -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class ChChestPacket extends AbstractPacket { - - public ChChestPacket(String announcerUsername, ChChestItem[] items, String locationCoords, String bbcommand, String extraMessage) { - super(1, 1); //Min and Max supported Version - this.announcerUsername = announcerUsername; - this.locationCoords = locationCoords; - this.bbcommand = bbcommand; - this.extraMessage = extraMessage; - this.items = items; - } - - public final String announcerUsername; - public final String locationCoords; - public final String bbcommand; - public final String extraMessage; - public final ChChestItem[] items; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisconnectPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisconnectPacket.java deleted file mode 100644 index ca60a49..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisconnectPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.constants.enviromentShared.InternalReasonConstants; -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class DisconnectPacket extends AbstractPacket { - - public DisconnectPacket(InternalReasonConstants internalReason, int[] waitBeforeReconnect, int randomExtraDelay, String displayReason, String displayMessage) { - super(1, 1); //Min and Max supportet Version - this.internalReason = internalReason; - this.waitBeforeReconnect = waitBeforeReconnect; - this.displayReason = displayReason; - this.displayMessage = displayMessage; - this.randomExtraDelay = randomExtraDelay; - } - - public final InternalReasonConstants internalReason; - public final int[] waitBeforeReconnect; - public final int randomExtraDelay; - public final String displayReason; - public final String displayMessage; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisplayTellrawMessagePacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisplayTellrawMessagePacket.java deleted file mode 100644 index e3e7f70..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/DisplayTellrawMessagePacket.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class DisplayTellrawMessagePacket extends AbstractPacket { - public final String rawJson; - - public DisplayTellrawMessagePacket(String rawJson) { - super(1, 1); //Min and Max supported Version - this.rawJson = rawJson; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/InternalCommandPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/InternalCommandPacket.java deleted file mode 100644 index fb7a774..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/InternalCommandPacket.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.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 - this.command = command; - this.parameters = parameters; - } - - public final String command; - public final String[] parameters; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/InvalidCommandFeedbackPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/InvalidCommandFeedbackPacket.java deleted file mode 100644 index 2f4510e..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/InvalidCommandFeedbackPacket.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class InvalidCommandFeedbackPacket extends AbstractPacket { - - public InvalidCommandFeedbackPacket(String internalReason, String command, String displayMessage, String argument, String permissionNeeded, String[] userPermissions) { - super(1, 1); //Min and Max supportet Version - this.internalReason = internalReason; - this.argument = argument; - this.permissionNeeded = permissionNeeded; - this.userPermissions = userPermissions; - this.command = command; - this.displayMessage = displayMessage; - } - - public final String internalReason; - public final String argument; - public final String permissionNeeded; - public final String[] userPermissions; - public final String command; - public final String displayMessage; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/MiningEventPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/MiningEventPacket.java deleted file mode 100644 index 9d9be62..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/MiningEventPacket.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.constants.enviromentShared.Islands; -import de.hype.bbsentials.common.constants.enviromentShared.MiningEvents; -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class MiningEventPacket extends AbstractPacket { - - - public final MiningEvents event; - public final String username; - public final Islands island; - - public MiningEventPacket(MiningEvents event, String username, Islands island) throws Exception { - super(1, 1); //Min and Max supported Version - this.event = event; - this.username = username; - if (island.equals(Islands.CRYSTAL_HOLLOWS)) { - if (event.equals(MiningEvents.MITHRIL_GOURMAND) || event.equals(MiningEvents.RAFFLE) || event.equals(MiningEvents.GOBLIN_RAID)) { - throw new Exception("The specified event can not happen on this Server"); - } - } - this.island = island; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/PartyPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/PartyPacket.java deleted file mode 100644 index 48a36f4..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/PartyPacket.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class PartyPacket extends AbstractPacket { - - public PartyPacket(String type, String[] users) { - super(1, 1); //Min and Max supportet Version - this.type = type; - this.users = users; - } - - public final String type; - public final String[] users; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/PunishUserPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/PunishUserPacket.java deleted file mode 100644 index dce052f..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/PunishUserPacket.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class PunishUserPacket extends AbstractPacket { - public static final String PUNISHMENT_TYPE_BAN = "BAN"; - public static final String PUNISHMENT_TYPE_MUTE = "MUTE"; - - public PunishUserPacket(String punishmentType,int userId, String username, String duration, String reason) { - super(1, 1); - this.type = punishmentType; - this.username = username; - this.userId = userId; - this.duration = duration; - this.reason = reason; - } - - public final String username; - public final String type; - public final int userId; - public final String duration; - public final String reason; - -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestConnectPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestConnectPacket.java deleted file mode 100644 index 9ce468a..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/RequestConnectPacket.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class RequestConnectPacket extends AbstractPacket { - - - public RequestConnectPacket(String mcuuid, String key, int clientApiVersion, String authType) { - super(1, 1); //Min and Max supported Version - this.mcuuid = mcuuid; - this.key = key; - this.authType = authType; - this.clientApiVersion = clientApiVersion; - } - - public final String mcuuid; - public final String key; - public final String authType; - public final int clientApiVersion; -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashNotifyPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashNotifyPacket.java deleted file mode 100644 index 427e4f2..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashNotifyPacket.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.constants.enviromentShared.Islands; -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class SplashNotifyPacket extends AbstractPacket { - - - public SplashNotifyPacket(int splashId, int hub, String splasherUsername, String location, Islands hubType, String extraMessage, boolean lessWaste) { - super(1, 1); //Min and Max supported Version - this.hub = hub; - this.splashId = splashId; - - this.lessWaste = lessWaste; - this.splasherUsername = splasherUsername; - this.location = location; - this.hubType = hubType; - this.extraMessage = extraMessage; - } - - public final int hub; - public final int splashId; - public final boolean lessWaste; - public final String splasherUsername; - public final String location; - public final Islands hubType; - public final String extraMessage; -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashUpdatePacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashUpdatePacket.java deleted file mode 100644 index 9645daf..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SplashUpdatePacket.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class SplashUpdatePacket extends AbstractPacket { - public static final String STATUS_WAITING = "Waiting"; - public static final String STATUS_FULL = "Full"; - public static final String STATUS_SPLASHING = "Splashing"; - public static final String STATUS_CANCELED = "Canceled"; - public static final String STATUS_DONE = "Done"; - - - public SplashUpdatePacket(int splashId, String status) { - super(1, 1); //Min and Max supported Version - this.splashId = splashId; - this.status = status; - } - - public final int splashId; - public final String status; -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SystemMessagePacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/SystemMessagePacket.java deleted file mode 100644 index 13b92d4..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/SystemMessagePacket.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class SystemMessagePacket extends AbstractPacket { - public final String message; - public final boolean important; - public final boolean ping; - - public SystemMessagePacket(String message, boolean important, boolean ping) { - super(1, 1); //Min and Max supported Version - this.message = message; - this.important = important; - this.ping = ping; - } -} diff --git a/common/src/main/java/de/hype/bbsentials/common/packets/packets/WelcomeClientPacket.java b/common/src/main/java/de/hype/bbsentials/common/packets/packets/WelcomeClientPacket.java deleted file mode 100644 index 00aa003..0000000 --- a/common/src/main/java/de/hype/bbsentials/common/packets/packets/WelcomeClientPacket.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.hype.bbsentials.common.packets.packets; - -import de.hype.bbsentials.common.packets.AbstractPacket; - -public class WelcomeClientPacket extends AbstractPacket { - - public WelcomeClientPacket(String[] roles, String motd, boolean success) { - super(1, 1); //Min and Max supportet Version - this.roles = roles; - this.motd = motd; - this.success = success; - } - - public final String[] roles; - public final String motd; - public final boolean success; - -} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/api/Discord.java b/common/src/main/java/de/hype/bbsentials/forge/common/api/Discord.java new file mode 100644 index 0000000..0093305 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/api/Discord.java @@ -0,0 +1,70 @@ +package de.hype.bbsentials.forge.common.api; + +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.client.BBsentials; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +public class Discord { + public static void sendWebhookMessage(String message) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + sendWebhookMessageNoThread(message); + } + }); + thread.start(); + } + + + public static void sendWebhookMessageNoThread(String message) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String WEBHOOK_URL = "https://discord.com/api/v8/webhooks/1127524566407860276/" + BBsentials.getConfig().getApiKey(); + + + try { + HttpPost httpPost = new HttpPost(WEBHOOK_URL); + + StringEntity jsonEntity = new StringEntity("{\"content\": \"" + message + "\"}", StandardCharsets.UTF_8); + jsonEntity.setContentType("application/json"); + httpPost.setEntity(jsonEntity); + + CloseableHttpResponse response = httpClient.execute(httpPost); + HttpEntity responseEntity = response.getEntity(); + + if (responseEntity != null) { + InputStream inputStream = responseEntity.getContent(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + + String line; + StringBuilder responseBuilder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + responseBuilder.append(line); + } + + String responseString = responseBuilder.toString(); + Chat.sendPrivateMessageToSelfInfo(responseString); + } + + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/api/Formatting.java b/common/src/main/java/de/hype/bbsentials/forge/common/api/Formatting.java new file mode 100644 index 0000000..9118533 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/api/Formatting.java @@ -0,0 +1,36 @@ +package de.hype.bbsentials.forge.common.api; + +public enum Formatting{ + BLACK("§0"), + DARK_BLUE("§1"), + DARK_GREEN("§2"), + DARK_AQUA("§3"), + DARK_RED("§4"), + DARK_PURPLE("§5"), + GOLD("§6"), + GRAY("§7"), + DARK_GRAY("§8"), + BLUE("§9"), + GREEN("§a"), + AQUA("§b"), + RED("§c"), + LIGHT_PURPLE("§d"), + YELLOW("§e"), + BOLD("§l"), + ITALIC("§o"), + UNDERLINE("§n"), + STRIKETHROUGH("§m"), + RESET("§r"), + WHITE("§f"); + + private final String code; + + Formatting(String code) { + this.code = code; + } + + @Override + public String toString() { + return code; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/api/ISimpleOption.java b/common/src/main/java/de/hype/bbsentials/forge/common/api/ISimpleOption.java new file mode 100644 index 0000000..fcaf70e --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/api/ISimpleOption.java @@ -0,0 +1,5 @@ +package de.hype.bbsentials.forge.common.api; + +public interface ISimpleOption { + void set(Object value); +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/chat/Chat.java b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Chat.java new file mode 100644 index 0000000..a9562ef --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Chat.java @@ -0,0 +1,419 @@ +package de.hype.bbsentials.forge.common.chat; + +import de.hype.bbsentials.forge.common.api.Formatting; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.Config; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.common.packets.packets.SplashUpdatePacket; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Chat { + + public static String[] getVariableInfo(String packageName, String className) { + List variableInfoList = new ArrayList<>(); + + // Combine the class name with the package name + String fullClassName = packageName + "." + className; + + // Load the class + Class clazz = null; + try { + clazz = Class.forName(fullClassName); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + // Extract fields of the class + Field[] fields = clazz.getDeclaredFields(); + + // Collect information for each field + for (Field field : fields) { + // Exclude transient fields + if (java.lang.reflect.Modifier.isTransient(field.getModifiers())) { + continue; + } + String variableName = field.getName(); + String variablePackageName = clazz.getPackage().getName(); + String variableClassName = clazz.getSimpleName(); + + variableInfoList.add(variableName); + } + + return variableInfoList.toArray(new String[variableInfoList.size()]); + } + + public static void setVariableValue(Object obj, String variableName, String value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { + if (value == null) { + // Handle null value case + sendPrivateMessageToSelfError("Invalid value: null"); + return; + } + + Class objClass = obj.getClass(); + Field field = objClass.getDeclaredField(variableName); + field.setAccessible(true); + + // Get the type of the field + Class fieldType = field.getType(); + + // Convert the value to the appropriate type + Object convertedValue = parseValue(value, fieldType); + + if (Modifier.isStatic(field.getModifiers())) { + // If the field is static + field.set(null, convertedValue); + } + else { + field.set(obj, convertedValue); + } + + // Check and output the value of the variable + sendPrivateMessageToSelfSuccess("The variable " + field.getName() + " is now: " + field.get(obj)); + } + + private static Object parseValue(String value, Class targetType) { + if (targetType == int.class || targetType == Integer.class) { + return Integer.parseInt(value); + } + else if (targetType == double.class || targetType == Double.class) { + return Double.parseDouble(value); + } + else if (targetType == float.class || targetType == Float.class) { + return Float.parseFloat(value); + } + else if (targetType == long.class || targetType == Long.class) { + return Long.parseLong(value); + } + else if (targetType == boolean.class || targetType == Boolean.class) { + return Boolean.parseBoolean(value); + } + else { + // For other types, return the original string value + return value; + } + } + + public static void getVariableValue(Object object, String variableName) throws NoSuchFieldException, IllegalAccessException { + Class objClass = object.getClass(); + Field field = objClass.getDeclaredField(variableName); + field.setAccessible(true); + sendPrivateMessageToSelfSuccess("The variable " + field.getName() + " is: " + field.get(object)); + } + + public Message onEvent(Message text) { + if (!isSpam(text.toString())) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + System.out.println("got a message: " + text.getJson()); + } + Message message = new Message(text.toString(),text.getString()); + BBsentials.executionService.execute(() -> processThreaded(message)); + return processNotThreaded(message); + } + return text; // Return the original message if it is spam + } + + //Handle in the messages which need to be modified here + public Message processNotThreaded(Message message) { +// if (message.isFromParty()) { +// message.replaceInJson("\"action\":\"run_command\",\"value\":\"/viewprofile", "\"action\":\"run_command\",\"value\":\"/bviewprofile " + messageUnformatted.split(">", 1)[1].trim()); +// } + if (message.isFromReportedUser()) { + sendPrivateMessageToSelfBase(Formatting.RED + "B: " + message.getUnformattedString()); + return null; + } + if (BBsentials.config.doPartyChatCustomMenu && message.isFromParty()) { + message.replaceInJson("/viewprofile \\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", "/socialoptions party " + message.getPlayerName() + " " + message.getUnformattedString()); + } + else if (BBsentials.config.doGuildChatCustomMenu && message.isFromGuild()) { + message.replaceInJson("/viewprofile \\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", "/socialoptions guild " + message.getPlayerName() + " " + message.getUnformattedString()); + } + else if (BBsentials.config.doAllChatCustomMenu) { + System.out.println("User: '" + message.getPlayerName() + "' | Message: " + message.getUnformattedString()); + message.replaceInJson("/socialoptions " + message.getPlayerName(), "/socialoptions sb " + message.getPlayerName() + " " + message.getUnformattedString()); + } + + return message; + } + + public void processThreaded(Message message) { + if (message.getString() != null) { + String messageUnformatted = message.getUnformattedString(); + String username = message.getPlayerName(); + if (message.isFromReportedUser()) { + + } + else if (!EnvironmentCore.mcUtils.isWindowFocused()) { + if (BBsentials.config.doDesktopNotifications) { + if ((messageUnformatted.endsWith("is visiting Your Garden !") || messageUnformatted.endsWith("is visiting Your Island !")) && !EnvironmentCore.mcUtils.isWindowFocused() && BBsentials.config.doDesktopNotifications) { + sendNotification("BBsentials Visit-Watcher", messageUnformatted); + } + else if (message.isMsg()) { + sendNotification("BBsentials Message Notifier", username + " sent you the following message: " + message.getMessageContent()); + } + if (message.getMessageContent().toLowerCase().contains(BBsentials.getConfig().getUsername().toLowerCase()) || (message.getMessageContent().toLowerCase().contains(BBsentials.getConfig().getNickname().toLowerCase() + " ") && BBsentials.getConfig().getNotifForParty().toLowerCase().equals("nick")) || BBsentials.getConfig().getNotifForParty().toLowerCase().equals("all")) { + sendNotification("BBsentials Party Chat Notification", username + " : " + message.getMessageContent()); + } + else { + if (message.getMessageContent().toLowerCase().contains(BBsentials.getConfig().getUsername().toLowerCase()) || message.getMessageContent().toLowerCase().contains(BBsentials.config.getNickname().toLowerCase() + " ")) { + sendNotification("BBsentials Notifier", "You got mentioned in chat! " + message.getMessageContent()); + } + } + } + } + else if (message.isServerMessage()) { + if (messageUnformatted.contains("disbanded the party")) { + lastPartyDisbandedUsername = username; + partyDisbandedMap.put(username, Instant.now()); + } + else if (message.contains("invited you to join their party")) { + if (lastPartyDisbandedUsername != null && partyDisbandedMap != null) { + Instant lastDisbandedInstant = partyDisbandedMap.get(lastPartyDisbandedUsername); + if (BBsentials.config.acceptReparty) { + if (lastDisbandedInstant != null && lastDisbandedInstant.isAfter(Instant.now().minusSeconds(20)) && (username.equals(lastPartyDisbandedUsername))) { + sendCommand("/p accept " + username); + } + } + } + if (!EnvironmentCore.mcUtils.isWindowFocused()) { + sendNotification("BBsentials Party Notifier", "You got invited too a party by: " + username); + } + } + else if (message.startsWith("Party Members (")) { + Config.partyMembers = new ArrayList<>(); + } + else if (message.startsWith("Party Moderators:")) { + String temp = messageUnformatted.replace("Party Moderators:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); + if (temp.contains(",")) { + for (int i = 0; i < temp.split(",").length; i++) { + Config.partyMembers.add(temp.split(",")[i - 1]); + } + } + else { + Config.partyMembers.add(temp); + } + } + else if (message.startsWith("Party Members:")) { + String temp = messageUnformatted.replace("Party Members:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); + if (temp.contains(",")) { + for (int i = 0; i < temp.split(",").length; i++) { + System.out.println("Added to plist: " + (temp.split(",")[i - 1])); + Config.partyMembers.add(temp.split(",")[i - 1]); + } + } + else { + Config.partyMembers.add(temp); + } + } + else if ((message.contains("Party Leader:") && !message.contains(BBsentials.getConfig().getUsername())) || message.equals("You are not currently in a party.") || (message.contains("warped the party into a Skyblock Dungeon") && !message.startsWith(BBsentials.getConfig().getUsername()) || (!message.startsWith("The party was transferred to " + BBsentials.getConfig().getUsername()) && message.startsWith("The party was transferred to"))) || messageUnformatted.endsWith(BBsentials.getConfig().getUsername() + " is now a Party Moderator") || (message.startsWith("The party was disbanded")) || (message.contains("You have joined ") && message.contains("'s party!")) || (message.contains("Party Leader, ") && message.contains(" , summoned you to their server.")) || (message.contains("warped to your dungeon"))) { + BBsentials.getConfig().setIsLeader(false); + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + sendPrivateMessageToSelfDebug("Leader: " + BBsentials.getConfig().isLeader()); + } + } + else if (BBsentials.config.getPlayersInParty().length == 0 && messageUnformatted.endsWith("to the party! They have 60 seconds to accept")) { + BBsentials.config.setIsLeader(true); + } + else if (messageUnformatted.startsWith("You'll be partying with:")) { + List members = new ArrayList<>(); + for (String users : messageUnformatted.replace("You'll be partying with:", "").replaceAll("\\[[^\\]]*\\]","").trim().split(",")) { + if (users.contains("and ")){break;} + members.add(users); + } + Config.partyMembers=members; + } + else if (((messageUnformatted.startsWith("Party Leader: ") && messageUnformatted.endsWith(BBsentials.getConfig().getUsername() + " ●"))) || (message.contains(BBsentials.getConfig().getUsername() + " warped the party to a SkyBlock dungeon!")) || message.startsWith("The party was transferred to " + BBsentials.getConfig().getUsername()) || message.getUnformattedString().endsWith(" has promoted " + BBsentials.getConfig().getUsername() + " to Party Leader") || (message.contains("warped to your dungeon"))) { + BBsentials.getConfig().setIsLeader(true); + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + sendPrivateMessageToSelfDebug("Leader: " + BBsentials.getConfig().isLeader()); + } + } + else if (message.getUnformattedString().equals("Please type /report confirm to log your report for staff review.")) { + sendCommand("/report confirm"); + } + else if (messageUnformatted.startsWith("BUFF! You splashed yourself with")) { + if (BBsentials.splashStatusUpdateListener != null) { + BBsentials.splashStatusUpdateListener.setStatus(SplashUpdatePacket.STATUS_SPLASHING); + } + } + } + + else if (message.isFromGuild()) { + + } + else if (message.isFromParty()) { + + } + else if (message.isMsg()) { + if (messageUnformatted.endsWith("bb:party me")) { + if (BBsentials.getConfig().allowBBinviteMe()) { + sendCommand("/p " + username); + } + } + } + else { + if (message.contains("[OPEN MENU]") || message.contains("[YES]")) { + setChatPromtId(message.getJson()); + } + } + } + } + + //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""}// {"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile f772b2c7-bd2a-46e1-b1a2-41fa561157d6"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bShourtu§e's profile"}},"text":"§9Party §8> §b[MVP§c+§b] Shourtu§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"Hype_the_Time TEST"}],"text":""} + //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""} + private final Map partyDisbandedMap = new HashMap<>(); + private String lastPartyDisbandedUsername = null; + + + public boolean isSpam(String message) { + if (message==null) return true; + if (message.isEmpty()) return true; + if (message.contains("Mana")) return true; + if (message.contains("Status")) return true; + if (message.contains("Achievement Points")) return true; + return false; + } + + public String test() { + //put test code here + sendNotification("test", "This is an example which was run of the h:test test"); + return new String(); + } + + public static void sendPrivateMessageToSelfError(String message) { + sendPrivateMessageToSelfBase(Formatting.RED + message); + } + + public static void sendPrivateMessageToSelfFatal(String message) { + sendPrivateMessageToSelfBase(Formatting.DARK_RED + message); + } + + public static void sendPrivateMessageToSelfSuccess(String message) { + sendPrivateMessageToSelfBase(Formatting.GREEN + message); + } + + public static void sendPrivateMessageToSelfInfo(String message) { + sendPrivateMessageToSelfBase(Formatting.YELLOW + message); + } + + public static void sendPrivateMessageToSelfImportantInfo(String message) { + sendPrivateMessageToSelfBase(Formatting.GOLD + message); + } + + public static void sendPrivateMessageToSelfDebug(String message) { + sendPrivateMessageToSelfBase(Formatting.AQUA + message); + } + + private static void sendPrivateMessageToSelfBase(String message) { + EnvironmentCore.chat.sendClientSideMessage(Message.of(message)); + } + + public static void sendPrivateMessageToSelfText(Message message) { + EnvironmentCore.chat.sendClientSideMessage(message); + } + + public static void sendCommand(String s) { + BBsentials.getConfig().sender.addSendTask(s); + } + + public void sendNotification(String title, String text) { + BBsentials.executionService.execute(() -> { + try { + InputStream inputStream = getClass().getResourceAsStream("/sounds/mixkit-sci-fi-confirmation-914.wav"); + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream); + Clip clip = AudioSystem.getClip(); + clip.open(audioInputStream); + clip.start(); + Thread.sleep(clip.getMicrosecondLength() / 1000); + clip.close(); + audioInputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + List argsList = new ArrayList<>(); + argsList.add("--title"); + argsList.add(title); + argsList.add("--passivepopup"); + argsList.add(text); + argsList.add("5"); + + try { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("kdialog"); + processBuilder.command().addAll(argsList); + + Process process = processBuilder.start(); + process.waitFor(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + public static void setChatPromtId(String logMessage) { + String cbUUIDPattern = "/cb ([a-fA-F0-9-]+)"; + Pattern cbPattern = Pattern.compile(cbUUIDPattern); + Matcher cbMatcher = cbPattern.matcher(logMessage); + + String yesClickAction = "/chatprompt ([a-fA-F0-9-]+) YES"; + Pattern yesPattern = Pattern.compile(yesClickAction); + Matcher yesMatcher = yesPattern.matcher(logMessage); + String lastPrompt = null; + if (cbMatcher.find()) { + lastPrompt = cbMatcher.group(1); + String finalLastPrompt1 = lastPrompt; + new Thread(new Runnable() { + @Override + public void run() { + String promptCommand = "/cb " + finalLastPrompt1; + BBsentials.getConfig().setLastChatPromptAnswer(promptCommand); + if (BBsentials.config.isDevModeEnabled()) { + Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\""); + } + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + BBsentials.getConfig().setLastChatPromptAnswer(null); + return; + } + }).start(); + } + if (yesMatcher.find()) { + lastPrompt = yesMatcher.group(1); + String finalLastPrompt = lastPrompt; + new Thread(new Runnable() { + @Override + public void run() { + String promptCommand = "/chatprompt " + finalLastPrompt + " YES"; + BBsentials.getConfig().setLastChatPromptAnswer(promptCommand); + if (BBsentials.config.isDevModeEnabled()) { + Chat.sendPrivateMessageToSelfDebug("set the last prompt action too + \"" + promptCommand + "\""); + } + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + BBsentials.getConfig().setLastChatPromptAnswer(null); + return; + } + }).start(); + + } + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/chat/Message.java b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Message.java new file mode 100644 index 0000000..5c5769b --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Message.java @@ -0,0 +1,111 @@ +package de.hype.bbsentials.forge.common.chat; + +import de.hype.bbsentials.forge.common.client.BBsentials; + +public class Message { + private String text; + private String unformattedString = null; + private String playerName = null; + private String string; + + public Message(String textJson,String string) { + this.text = textJson; + if (string==null) string = ""; + this.string=string; + } + public static Message of(String string){ + return new Message("{\"text\":\""+string+"\"}",string); + } + // + public String getJson() { + return text; + } + + public String getString() { + return string; + } + + public String getUnformattedString() { + if (unformattedString != null) return unformattedString; + unformattedString = string.replaceAll("§.", "").trim(); + return unformattedString; + } + + public String getMessageContent() { + if (isServerMessage()) return unformattedString; + return getUnformattedString().split(":", 2)[1]; + } + + Boolean guild = null; + + public boolean isFromGuild() { + if (guild != null) return guild; + guild = getUnformattedString().startsWith("Guild >"); + return guild; + } + + Boolean party = null; + + public boolean isFromParty() { + if (party != null) return party; + party = getUnformattedString().startsWith("Party >"); + return party; + } + + Boolean msg = null; + + public boolean isMsg() { + if (msg != null) return msg; + msg = getUnformattedString().startsWith("From") || getUnformattedString().startsWith("To"); + return msg; + } + + Boolean server = null; + + public boolean isServerMessage() { + if (server != null) return server; + int space = getUnformattedString().indexOf(" "); + int doublepoint = getUnformattedString().indexOf(":"); + return ((space + 2 < doublepoint)||doublepoint==-1||space==-1); + } + + public String getPlayerName() { + if (playerName != null) return playerName; + playerName = getUnformattedString(); + if (!playerName.contains(":")) { + playerName = ""; + return ""; + } + playerName = playerName.split(":", 2)[0]; + if (isMsg()) { + playerName = playerName.replaceFirst("From", "").replace("To", "").trim(); + } + if (playerName.contains(">")){ + playerName=playerName.split(">",2)[1]; + } +// playerName = playerName.replaceFirst("\\[[^\\]]*\\](?:\\s?[^\\x00-\\x7F]?\\s?\\[[^\\]]*\\])*", "").trim()// replaces every [] and unicode character before a asci character. + playerName = playerName.replaceAll("[^\\x00-\\x7F]","").replaceAll("\\[[^\\]]*\\]","").trim(); + if (playerName.matches("[^a-zA-Z0-9_-]+")) playerName = ""; + return playerName; + } + + public void replaceInJson(String replace, String replaceWith) { + text = text.replaceFirst(replace, replaceWith); + } + public boolean isFromReportedUser() { + return BBsentials.config.alreadyReported.contains(getPlayerName()) && !getPlayerName().isEmpty(); + } + + public boolean contains(String string) { + return getUnformattedString().contains(string); + } + + public boolean startsWith(String string) { + return getUnformattedString().startsWith(string); + } + + @Override + public String toString() { + return getUnformattedString(); + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/chat/Sender.java b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Sender.java new file mode 100644 index 0000000..742c18a --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/chat/Sender.java @@ -0,0 +1,105 @@ +package de.hype.bbsentials.forge.common.chat; + +import de.hype.bbsentials.forge.common.api.Formatting; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; + +import java.util.ArrayList; +import java.util.List; + +import static de.hype.bbsentials.forge.common.chat.Chat.sendPrivateMessageToSelfInfo; +import static de.hype.bbsentials.forge.common.chat.Chat.sendPrivateMessageToSelfText; + +public class Sender { + private final List sendQueue; + private final List sendQueueTiming; + private final List hidden; + + + public Sender() { + this.sendQueue = new ArrayList<>(); + this.sendQueueTiming = new ArrayList<>(); + this.hidden = new ArrayList<>(); + startSendingThread(); + } + + public void addSendTask(String task, double timing) { + synchronized (sendQueue) { + sendPrivateMessageToSelfText(Message.of(Formatting.GREEN + "Scheduled send-task (as " + sendQueueTiming.size() + " in line): " + task + " | Delay: " + timing)); + sendQueueTiming.add(timing); + sendQueue.add(task); + hidden.add(false); + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addHiddenSendTask(String task, double timing) { + synchronized (sendQueue) { + sendQueueTiming.add(timing); + sendQueue.add(task); + hidden.add(true); + + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addImmediateSendTask(String task) { + synchronized (sendQueue) { + sendQueueTiming.add(0, 0.0); + sendQueue.add(0, task); + hidden.add(false); + + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addSendTask(String task) { + addSendTask(task, 1); + } + + public void startSendingThread() { + Thread sendingThread = new Thread(new SendingRunnable()); + sendingThread.start(); + } + + private class SendingRunnable implements Runnable { + @Override + public void run() { + while (true) { + String task = getNextTask(); + if (task != null) { + send(task, sendQueueTiming.remove(0), hidden.remove(0)); + } + else { + synchronized (sendQueue) { + try { + sendQueue.wait(); // Wait for new Send + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } + } + + private String getNextTask() { + synchronized (sendQueue) { + if (!sendQueue.isEmpty()) { + return sendQueue.remove(0); + } + return null; + } + } + + private void send(String toSend, double timing, boolean hidden) { + try { + Thread.sleep((long) (timing * 1000)); // Simulate the send operation + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + EnvironmentCore.chat.sendChatMessage(toSend); + if (!hidden) { + sendPrivateMessageToSelfInfo("Sent Command to Server: " + toSend); + } + } + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/BBsentials.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/BBsentials.java new file mode 100644 index 0000000..24ef170 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/BBsentials.java @@ -0,0 +1,89 @@ +package de.hype.bbsentials.forge.common.client; + +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.client.Commands.Commands; +import de.hype.bbsentials.forge.common.communication.BBsentialConnection; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class BBsentials { + public static Config config; + public static BBsentialConnection connection; + public static Commands coms; + public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000); + public static boolean splashLobby; + private static Thread bbthread; + private static boolean initialised = false; + public static SplashStatusUpdateListener splashStatusUpdateListener; + + public static Config getConfig() { + return config; + } + + public static void connectToBBserver() { + connectToBBserver(config.connectToBeta); + } + + /** + * Checks if still connected to the Server. + * + * @return true if it connected; false if old connection is kept. + */ + public static boolean conditionalReconnectToBBserver() { + if (!connection.isConnected()) { + Chat.sendPrivateMessageToSelfInfo("Reconnecting"); + connectToBBserver(config.connectToBeta); + return true; + } + return false; + } + + public static void connectToBBserver(boolean beta) { + if (connection != null) { + connection.sendHiddenMessage("exit"); + } + if (bbthread != null) { + if (bbthread.isAlive()) { + bbthread.interrupt(); + } + } + bbthread = new Thread(() -> { + connection = new BBsentialConnection(); + coms = new Commands(); + connection.setMessageReceivedCallback(message -> executionService.execute(() -> connection.onMessageReceived(message))); + if (beta) { + connection.connect(config.getBBServerURL(), 5011); + } + else { + connection.connect(config.getBBServerURL(), 5000); + } + executionService.scheduleAtFixedRate(EnvironmentCore.debug, 0, 20, TimeUnit.SECONDS); + }); + bbthread.start(); + } + + /** + * Runs the mod initializer on the client environment. + */ + + public static void onServerSwap() { + splashLobby = false; + if (!initialised) { + config = Config.load(); + if (config.doGammaOverride) EnvironmentCore.mcoptions.setGamma(10); + Chat chat = new Chat(); + if (Config.isBingoTime() || config.overrideBingoTime()) { + connectToBBserver(); + } + initialised = true; + } + } + public void manualLoad() { + initialised = true; + config = Config.load(); + connectToBBserver(); + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/Commands/Commands.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/Commands/Commands.java new file mode 100644 index 0000000..804e816 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/Commands/Commands.java @@ -0,0 +1,23 @@ +package de.hype.bbsentials.forge.common.client.Commands; + +import de.hype.bbsentials.forge.common.client.Config; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; + +import static de.hype.bbsentials.forge.common.client.BBsentials.getConfig; +public class Commands { + public Commands() { + EnvironmentCore.commands.registerMain(); + Config config = getConfig(); + if (config.bbsentialsRoles != null) { + EnvironmentCore.commands.registerRoleRequired( + config.hasBBRoles("dev"), + config.hasBBRoles("admin"), + config.hasBBRoles("mod"), + config.hasBBRoles("splasher"), + config.hasBBRoles("beta"), + config.hasBBRoles("mining_events"), + config.hasBBRoles("mining_events") + ); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/Config.java new file mode 100644 index 0000000..abe7e23 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/Config.java @@ -0,0 +1,204 @@ +package de.hype.bbsentials.forge.common.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import de.hype.bbsentials.forge.common.chat.Sender; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; + +import java.io.*; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class Config implements Serializable { + //DO NOT Change any of the following unless you know what you are doing! + public int apiVersion = 1; + public boolean allowServerPartyInvite = true; + public boolean devMode = false; + public boolean detailedDevMode = false; + //You can change again + + // set automatically + private transient boolean isLeader; + public transient String alreadyReported = ""; + public String[] bbsentialsRoles = {""}; + public static List partyMembers = new ArrayList<>(); + public transient ToDisplayConfig toDisplayConfig = ToDisplayConfig.loadFromFile(); + public transient final Sender sender = new Sender(); + public transient boolean highlightitem = false; + public transient String lastChatPromptAnswer = null; + private transient String username; + + // Set via load / default you may change these + public boolean overrideBingoTime = false; + public boolean connectToBeta = false; + + public String bbServerURL = "localhost"; + public String apiKey = ""; + public boolean showBingoChat = true; + public boolean doAllChatCustomMenu=true; + public boolean doPartyChatCustomMenu=true; + public boolean doGuildChatCustomMenu=true; + + public boolean allowBBinviteMe = true; + public boolean doDesktopNotifications = false; + public boolean showSplashStatusUpdates = true; + public boolean doGammaOverride = true; + public boolean acceptReparty; + public boolean autoSplashStatusUpdates; + public String nickname; + public String notifForMessagesType; + + // Set default attribute values + private void setDefaults() { + username = EnvironmentCore.mcUtils.getUsername(); + acceptReparty = true; + if (username.equals("Hype_the_Time")) { + nickname = "Hype"; + notifForMessagesType = "nick"; + doDesktopNotifications=true; + } //Gimmic for Developer due too things which dont make it into releases (bugs) + else { + nickname = ""; + notifForMessagesType = "none"; + } + } + + // Gson object for serialization + private final transient Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + // File object for storing the config + private final transient File CONFIG_FILE = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); + + // Constructor + public Config() { + setDefaults(); + } + + // Load the config from file + public static Config load() { + Config settings; + File CONFIG_FILE = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); + Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + if (CONFIG_FILE.exists()) { + try (FileReader reader = new FileReader(CONFIG_FILE)) { + settings = GSON.fromJson(reader, Config.class); + } catch (IOException e) { + e.printStackTrace(); + settings = new Config(); // Use default values if loading fails + settings.save(); + } catch (IllegalStateException e) { + System.out.println("Error loading config. Resetting it."); + settings = new Config(); + settings.save(); + } + } + else { + settings = new Config(); // Use default values if the file doesn't exist + settings.username = EnvironmentCore.mcUtils.getUsername(); + } + if (!settings.hasBBRoles("dev")) { + settings.detailedDevMode = false; + settings.devMode = false; + } + settings.save(); + return settings; + } + + // Save the config to file + public void save() { + try (FileWriter writer = new FileWriter(CONFIG_FILE)) { + GSON.toJson(this, writer); + } catch (IOException e) { + e.printStackTrace(); + } + toDisplayConfig.saveToFile(); + } + + // Getter methods for various config attributes + public String getUsername() { + return username; + } + + public boolean isLeader() { + return isLeader; + } + + public void setIsLeader(boolean value) { + isLeader = value; + } + + public String getNickname() { + return nickname; + } + + public String getNotifForParty() { + return notifForMessagesType; + } + + public boolean isDevModeEnabled() { + return devMode; + } + + public boolean isDetailedDevModeEnabled() { + return detailedDevMode; + } + + public String[] getPlayersInParty() { + return partyMembers.toArray(new String[0]); + } + + public void addReported(String playerName) { + alreadyReported = alreadyReported + " , " + playerName; + } + + public String getApiKey() { + return apiKey; + } + + public String getBBServerURL() { + return bbServerURL; + } + + + public static boolean isBingoTime() { + LocalDate currentDate = LocalDate.now(); + LocalDate lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth()); + LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1); + Boolean isBefore = currentDate.isAfter(lastDayOfMonth.minusDays(4)); + Boolean isInRange = currentDate.isBefore(firstDayOfMonth.plusDays(15)); + return isBefore || isInRange; + } + + public boolean overrideBingoTime() { + return overrideBingoTime; + } + + public String getLastChatPromptAnswer() { + return lastChatPromptAnswer; + } + + public boolean allowBBinviteMe() { + return allowBBinviteMe; + } + + public void setLastChatPromptAnswer(String lastChatPromptAnswer) { + this.lastChatPromptAnswer = lastChatPromptAnswer; + } + + public boolean hasBBRoles(String roleName) { + for (String role : bbsentialsRoles) { + if (role.equalsIgnoreCase(roleName)) { + return true; + } + } + return false; + } + + public int getApiVersion() { + return apiVersion; + } + + public String getMCUUID() { + return EnvironmentCore.mcUtils.getMCUUID().replace("-", ""); + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/CustomGson.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/CustomGson.java new file mode 100644 index 0000000..71870c8 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/CustomGson.java @@ -0,0 +1,28 @@ +package de.hype.bbsentials.forge.common.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class CustomGson { + public static Gson create() { + return new GsonBuilder() +// .registerTypeHierarchyAdapter(BBDisplayNameProvider.class, new BBDisplayNameProviderSerializer()) + .create(); + + } + +// private static class BBDisplayNameProviderSerializer implements JsonSerializer, JsonDeserializer { +// @Override +// public JsonElement serialize(BBDisplayNameProvider src, Type typeOfSrc, JsonSerializationContext context) { +// return new JsonPrimitive(src.serialize()); // Serialize using the provided method +// } +// +// @Override +// public BBDisplayNameProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { +// String serializedValue = json.getAsString(); +// +// // Deserialize using the provided method (you need to implement this) +// return BBDisplayNameProvider.deserialize(serializedValue); +// } +// } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/DebugThread.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/DebugThread.java new file mode 100644 index 0000000..db2b692 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/DebugThread.java @@ -0,0 +1,20 @@ +package de.hype.bbsentials.forge.common.client; + + +import java.util.List; + +public interface DebugThread extends Runnable { + + @Override + public default void run() { + loop(); + //place a breakpoint for only this thread here. + } + + public default void loop() { + } + + public default List test() { + return List.of(""); + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashManager.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashManager.java new file mode 100644 index 0000000..7495559 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashManager.java @@ -0,0 +1,58 @@ +package de.hype.bbsentials.forge.common.client; + +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.constants.enviromentShared.Islands; +import de.hype.bbsentials.forge.common.packets.packets.SplashNotifyPacket; +import de.hype.bbsentials.forge.common.packets.packets.SplashUpdatePacket; + +import java.util.HashMap; +import java.util.Map; + +public class SplashManager { + public static Map splashPool = new HashMap<>(); + + public SplashManager() { + + } + + public static void addSplash(SplashNotifyPacket packet) { + splashPool.put(packet.splashId, new DisplaySplash(packet)); + } + + public static void updateSplash(SplashUpdatePacket packet) { + DisplaySplash splash = splashPool.get(packet.splashId); + if (splash != null) { + if (splash.alreadyDisplayed) { + if (BBsentials.config.showSplashStatusUpdates) { + Chat.sendPrivateMessageToSelfImportantInfo(splash.hubType.getDisplayName() + " #" + splash.hub + " is " + packet.status); + } + } + else { + splashPool.remove(splash.splashId); + } + } + } + + public static void display(int splashId) { + SplashNotifyPacket splash = splashPool.get(splashId); + if (splash == null) return; + String where; + if (splash.hubType.equals(Islands.DUNGEON_HUB)) { + where = "§5DUNGEON HUB§6"; + } + else { + where = "Hub"; + } + BBsentials.connection.splashHighlightItem("HUB #" + splash.hub, 20); + Chat.sendPrivateMessageToSelfImportantInfo(splash.splasherUsername + " is Splashing in " + where + " #" + splash.hub + " at " + splash.location + ":" + splash.extraMessage); + } + + private static class DisplaySplash extends SplashNotifyPacket { + public boolean alreadyDisplayed; + + public DisplaySplash(SplashNotifyPacket packet) { + super(packet.splashId, packet.hub, packet.splasherUsername, packet.location, packet.hubType, packet.extraMessage, packet.lessWaste); + alreadyDisplayed = false; + } + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashStatusUpdateListener.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashStatusUpdateListener.java new file mode 100644 index 0000000..8054818 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/SplashStatusUpdateListener.java @@ -0,0 +1,63 @@ +package de.hype.bbsentials.forge.common.client; + +import de.hype.bbsentials.forge.common.communication.BBsentialConnection; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.common.packets.packets.SplashNotifyPacket; +import de.hype.bbsentials.forge.common.packets.packets.SplashUpdatePacket; + +import java.util.concurrent.TimeUnit; + +public class SplashStatusUpdateListener implements Runnable { + BBsentialConnection connection; + SplashNotifyPacket packet; + private String status = SplashUpdatePacket.STATUS_WAITING; + public String newStatus = SplashUpdatePacket.STATUS_WAITING; + public boolean splashed = false; + public boolean full = false; + + public SplashStatusUpdateListener(BBsentialConnection connection, SplashNotifyPacket packet) { + this.connection = connection; + this.packet = packet; + } + + @Override + public void run() { + BBsentials.splashLobby = true; + int maxPlayerCount = EnvironmentCore.utils.getMaximumPlayerCount() - 5; + while (BBsentials.splashLobby) { + if (!full&&(EnvironmentCore.utils.getPlayerCount() >= maxPlayerCount)) { + newStatus = SplashUpdatePacket.STATUS_FULL; + full=true; + } + if (!status.equals(newStatus)) { + status = newStatus; + connection.sendPacket(new SplashUpdatePacket(packet.splashId, status)); + } + try { + Thread.sleep(250); + } catch (InterruptedException ignored) { + } + } + if (splashed) { + newStatus = SplashUpdatePacket.STATUS_DONE; + } + else { + newStatus = SplashUpdatePacket.STATUS_CANCELED; + } + if (!status.equals(newStatus)) { + status = newStatus; + connection.sendPacket(new SplashUpdatePacket(packet.splashId, status)); + } + } + + public void setStatus(String newStatus) { + this.newStatus = newStatus; + if (newStatus.equals(SplashUpdatePacket.STATUS_SPLASHING)) { + splashed=true; + BBsentials.executionService.schedule(() -> { + setStatus(SplashUpdatePacket.STATUS_DONE); + BBsentials.splashLobby = false; + }, 1, TimeUnit.MINUTES); + } + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/client/ToDisplayConfig.java b/common/src/main/java/de/hype/bbsentials/forge/common/client/ToDisplayConfig.java new file mode 100644 index 0000000..603fccb --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/client/ToDisplayConfig.java @@ -0,0 +1,96 @@ +package de.hype.bbsentials.forge.common.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; + +public class ToDisplayConfig { + public boolean disableAll = false; + public boolean allChChestItem = true; + public boolean allRoboPart = false; + public boolean customChChestItem = false; + + public boolean prehistoricEgg = false; + public boolean pickonimbus2000 = false; + public boolean controlSwitch = false; + public boolean electronTransmitter = false; + public boolean ftx3070 = false; + public boolean robotronReflector = false; + 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; + + public String betterTogether = "none"; + public String doublePowder = "none"; + public String goneWithTheWind = "none"; + public boolean goblinRaid = false; + public boolean mithrilGourmand = false; + public boolean raffle = false; + + // Serialize the object to JSON and save to file + public void saveToFile() { + File configFile = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_display_Config.json"); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + try (FileWriter writer = new FileWriter(configFile)) { + gson.toJson(this, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Deserialize the object from JSON file + public static ToDisplayConfig loadFromFile() { + File configFile = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_display_Config.json"); + Gson gson = new Gson(); + + try (FileReader reader = new FileReader(configFile)) { + return gson.fromJson(reader, ToDisplayConfig.class); + } catch (IOException e) { + e.printStackTrace(); + } + + // If file doesn't exist or there's an error, return a new instance + return new ToDisplayConfig(); + } + + public void setValueAndSave(String propertyName, Object newValue) { + String lowerCasePropertyName = propertyName.toLowerCase(); + + try { + Field field = getClass().getDeclaredField(lowerCasePropertyName); + field.setAccessible(true); + + field.set(this, newValue); + saveToFile(); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + // Method to get a value based on property name + public boolean getValue(String propertyName) { + if (disableAll) return false; + String lowerCasePropertyName = propertyName.toLowerCase(); + try { + Field field = getClass().getDeclaredField(lowerCasePropertyName); + field.setAccessible(true); + return field.getBoolean(this); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + + return false; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/communication/BBsentialConnection.java b/common/src/main/java/de/hype/bbsentials/forge/common/communication/BBsentialConnection.java new file mode 100644 index 0000000..1603a24 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/communication/BBsentialConnection.java @@ -0,0 +1,550 @@ +package de.hype.bbsentials.forge.common.communication; + +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.chat.Message; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.SplashManager; +import de.hype.bbsentials.forge.common.client.SplashStatusUpdateListener; +import de.hype.bbsentials.forge.common.constants.enviromentShared.*; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; +import de.hype.bbsentials.forge.common.packets.PacketManager; +import de.hype.bbsentials.forge.common.packets.PacketUtils; +import de.hype.bbsentials.forge.common.packets.packets.*; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.*; +import java.net.Socket; +import java.net.SocketException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public class BBsentialConnection { + private Socket socket; + private BufferedReader reader; + private PrintWriter writer; + private LinkedBlockingQueue messageQueue; + private MessageReceivedCallback messageReceivedCallback; + private String itemName = "Hub #0"; + private PacketManager packetManager; + + public BBsentialConnection() { + packetManager = new PacketManager(this); + } + + + + 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.connection.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.sendPrivateMessageToSelfFatal("§4" + emergencyMessage + "\n\n"); + /*try { + Thread.sleep(5000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + throw new RuntimeException(emergencyMessage);*/ + } + return false; + } + + + + public void connect(String serverIP, int serverPort) { + // Enable SSL handshake debugging + System.setProperty("javax.net.debug", "ssl,handshake"); + FileInputStream inputStream = null; + try { + // Load the BBssentials-online server's public certificate from the JKS file + try { + InputStream resouceInputStream = BBsentials.class.getResourceAsStream("/assets/public_bbsentials_cert.crt"); + + // Check if the resource exists + if (resouceInputStream == null) { + System.out.println("The resource '/assets/public_bbsentials_cert.crt' was not found."); + return; + } + + File tempFile = File.createTempFile("public_bbsentials_cert", ".crt"); + tempFile.deleteOnExit(); + + FileOutputStream outputStream = new FileOutputStream(tempFile); + + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = resouceInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + outputStream.close(); + resouceInputStream.close(); + + // Now you have the .crt file as a FileInputStream in the tempFile + inputStream = new FileInputStream(tempFile); + + // Use the fileInputStream as needed + + } catch (IOException e) { + e.printStackTrace(); + } + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + X509Certificate serverCertificate = (X509Certificate) certFactory.generateCertificate(inputStream); + PublicKey serverPublicKey = serverCertificate.getPublicKey(); + + // Create a TrustManager that trusts only the server's public key + TrustManager[] trustManagers = new TrustManager[]{new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; // We don't need to check the client's certificates + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { + // Do nothing, client certificate validation not required + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { + // Check if the server certificate matches the expected one + if (certs.length == 1) { + PublicKey publicKey = certs[0].getPublicKey(); + if (!publicKey.equals(serverPublicKey)) { + throw new CertificateException("Server certificate not trusted."); + } + } + else { + throw new CertificateException("Invalid server certificate chain."); + } + } + }}; + + // Create an SSL context with the custom TrustManager + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustManagers, new SecureRandom()); + // Create an SSL socket factory + SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + socket = sslSocketFactory.createSocket(serverIP, serverPort); + + socket.setKeepAlive(true); // Enable Keep-Alive + + reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + writer = new PrintWriter(socket.getOutputStream(), true); + messageQueue = new LinkedBlockingQueue<>(); + + // Start message receiver thread + Thread messageReceiverThread = new Thread(() -> { + try { + while (true) { + String message = reader.readLine(); + if (message != null) { + if (messageReceivedCallback != null) { + messageReceivedCallback.onMessageReceived(message); + } + else { + Chat.sendPrivateMessageToSelfError("BB: It seemed like you disconnected. Reconnecting..."); + BBsentials.connectToBBserver(); + try { + Thread.sleep(1000 * 10); + } catch (Exception ignored) { + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + }); + messageReceiverThread.start(); + messageReceiverThread.setName("bb receiver thread"); + // Start message sender thread + Thread messageSenderThread = new Thread(() -> { + try { + while (true) { + String message = messageQueue.take(); + writer.println(message); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (NullPointerException ignored) { + } + }); + messageSenderThread.start(); + messageSenderThread.setName("bb sender thread"); + + } catch (IOException | NoSuchAlgorithmException | + KeyManagementException e) { + e.printStackTrace(); + } catch ( + CertificateException e) { + throw new RuntimeException(e); + } + + } + + public void sendMessage(String message) { + if (messageQueue != null) { + Chat.sendPrivateMessageToSelfDebug("BBs: " + message); + messageQueue.offer(message); + } + else { + Chat.sendPrivateMessageToSelfError("BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect"); + } + } + + public void sendHiddenMessage(String message) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); + } + try { + if (socket.isConnected() && writer != null) { + writer.println(message); + } + } catch (NullPointerException ignored) { + } + } + + public void sendCommand(String message) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelfDebug("BBDev-s: " + message); + } + if (socket.isConnected() && writer != null) { + writer.println(message); + } + else { + Chat.sendPrivateMessageToSelfFatal("BB: 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) { + if (!PacketUtils.handleIfPacket(this, message)) { + if (message.startsWith("H-")) { + if (message.equals("H-BB-Login: ")) { + Chat.sendPrivateMessageToSelfSuccess("Logging into BBsentials-online"); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + sendPacket(new RequestConnectPacket(BBsentials.config.getMCUUID(), BBsentials.getConfig().getApiKey(), BBsentials.getConfig().getApiVersion(), AuthenticationConstants.DATABASE)); + } + } + else { + Chat.sendPrivateMessageToSelfSuccess("BB: " + message); + } + } + } + + public void dummy(Object o) { + //this does absoloutely nothing + } + + public void splashHighlightItem(String itemName, long displayTimeInMilliseconds) { + this.itemName = itemName; + BBsentials.config.highlightitem = true; + BBsentials.executionService.schedule(() -> { + BBsentials.config.highlightitem = false; + try { + socket.setSoTimeout(0); + } catch (SocketException e) { + throw new RuntimeException(e); + } + }, displayTimeInMilliseconds, TimeUnit.MILLISECONDS); + } + + public String getItemName() { + return itemName; + } + //TODO search + + public void setMessageReceivedCallback(MessageReceivedCallback callback) { + this.messageReceivedCallback = callback; + } + + public void sendPacket(E packet) { + String packetName = packet.getClass().getSimpleName(); + String rawjson = PacketUtils.parsePacketToJson(packet); + if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class))) { + Chat.sendPrivateMessageToSelfDebug("BBDev-sP: " + packetName + ": " + rawjson); + } + if (socket.isConnected() && writer != null) { + writer.println(packetName + "." + rawjson); + } + else { + Chat.sendPrivateMessageToSelfError("BB: Couldn't send a Packet? did you get disconnected?"); + } + } + + public void onBroadcastMessagePacket(BroadcastMessagePacket packet) { + Chat.sendPrivateMessageToSelfImportantInfo("[A] §r[" + packet.prefix + "§r]§6 " + packet.username + ": " + packet.message); + } + + public void onSplashNotifyPacket(SplashNotifyPacket packet) { + int waitTime; + if (packet.splasherUsername.equals(BBsentials.config.getUsername())&& BBsentials.config.autoSplashStatusUpdates) { + Chat.sendPrivateMessageToSelfInfo("The Splash Update Statuses will be updatet automatically for you. If you need to do something manually go into Discord Splash Dashboard"); + SplashStatusUpdateListener splashStatusUpdateListener = new SplashStatusUpdateListener(this, packet); + BBsentials.splashStatusUpdateListener = splashStatusUpdateListener; + BBsentials.executionService.execute(splashStatusUpdateListener); + } + else { + SplashManager.addSplash(packet); + if (packet.lessWaste) { + waitTime = Math.min(((EnvironmentCore.mcUtils.getPotTime() * 1000) / 80), 25 * 1000); + } + else { + waitTime = 0; + } + BBsentials.executionService.schedule(() -> { + SplashManager.display(packet.splashId); + }, waitTime, TimeUnit.MILLISECONDS); + } + } + + public void onBingoChatMessagePacket(BingoChatMessagePacket packet) { + if (BBsentials.config.showBingoChat) { + Chat.sendPrivateMessageToSelfInfo("[" + 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(new Message(tellrawText,"")); + } + } + else { + Chat.sendPrivateMessageToSelfImportantInfo("§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,..."); + Chat.sendPrivateMessageToSelfImportantInfo(PacketUtils.parsePacketToJson(packet)); + } + } + + public void onMiningEventPacket(MiningEventPacket packet) { + if (!BBsentials.config.toDisplayConfig.getValue("disableAll")) { + //its will returns false cause disabled is checked already before. + if (BBsentials.config.toDisplayConfig.blockChEvents && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) return; + if (!(BBsentials.config.toDisplayConfig.allEvents)) { + if (packet.event.equals(MiningEvents.RAFFLE)) { + if (!BBsentials.config.toDisplayConfig.raffle) return; + } + else if (packet.event.equals(MiningEvents.GOBLIN_RAID)) { + if (!BBsentials.config.toDisplayConfig.goblinRaid) return; + } + else if (packet.event.equals(MiningEvents.MITHRIL_GOURMAND)) { + if (!BBsentials.config.toDisplayConfig.mithrilGourmand) return; + } + else if (packet.event.equals(MiningEvents.BETTER_TOGETHER)) { + if (BBsentials.config.toDisplayConfig.betterTogether.equals("none")) return; + if (BBsentials.config.toDisplayConfig.betterTogether.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (BBsentials.config.toDisplayConfig.betterTogether.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) + return; + } + else if (packet.event.equals(MiningEvents.DOUBLE_POWDER)) { + if (BBsentials.config.toDisplayConfig.doublePowder.equals("none")) return; + if (BBsentials.config.toDisplayConfig.doublePowder.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (BBsentials.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 (BBsentials.config.toDisplayConfig.goneWithTheWind.equals("none")) return; + if (BBsentials.config.toDisplayConfig.goneWithTheWind.equals(Islands.DWARVEN_MINES.getDisplayName()) && packet.island.equals(Islands.CRYSTAL_HOLLOWS)) + return; + if (BBsentials.config.toDisplayConfig.goneWithTheWind.equals(Islands.CRYSTAL_HOLLOWS.getDisplayName()) && packet.island.equals(Islands.DWARVEN_MINES)) + return; + } + } + Chat.sendPrivateMessageToSelfImportantInfo(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; + Chat.sendPrivateMessageToSelfSuccess("Login Success"); + if (!packet.motd.isEmpty()) { + Chat.sendPrivateMessageToSelfImportantInfo(packet.motd); + } + } + else { + Chat.sendPrivateMessageToSelfError("Login Failed"); + } + } + + public void onDisconnectPacket(DisconnectPacket packet) { + Chat.sendPrivateMessageToSelfError(packet.displayMessage); + BBsentials.connection = null; + for (int i = 0; i < packet.waitBeforeReconnect.length; i++) { + int finalI = i; + BBsentials.executionService.schedule(() -> { + if (finalI == 1) { + BBsentials.connectToBBserver(); + } + else { + BBsentials.conditionalReconnectToBBserver(); + } + }, (long) (packet.waitBeforeReconnect[i] + (Math.random() * packet.randomExtraDelay)), TimeUnit.SECONDS); + } + } + + public void onDisplayTellrawMessagePacket(DisplayTellrawMessagePacket packet) { + /*Chat.sendPrivateMessageToSelfText(Chat.createClientSideTellraw(packet.rawJson));*/ + Chat.sendPrivateMessageToSelfImportantInfo("You received a tellraw Packet but it got ignored due too there being no safety checks in this version."); + } + + public void onInternalCommandPacket(InternalCommandPacket packet) { + if (packet.command.equals(InternalCommandPacket.REQUEST_POT_DURATION)) { + sendPacket(new InternalCommandPacket(InternalCommandPacket.SET_POT_DURATION, new String[]{String.valueOf(EnvironmentCore.mcUtils.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]); + EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); + for (int i = 0; i < 10; i++) { + int finalI = i; + BBsentials.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]); + EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); + } + else if (packet.command.equals(InternalCommandPacket.HUB)) { + BBsentials.config.sender.addImmediateSendTask("/hub"); + } + else if (packet.command.equals(InternalCommandPacket.PRIVATE_ISLAND)) { + BBsentials.config.sender.addImmediateSendTask("/is"); + } + else if (packet.command.equals(InternalCommandPacket.HIDDEN_HUB)) { + BBsentials.config.sender.addHiddenSendTask("/hub", 0); + } + else if (packet.command.equals(InternalCommandPacket.HIDDEN_PRIVATE_ISLAND)) { + BBsentials.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]); + Thread crashThread = new Thread(() -> { + EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); + for (int i = 10; i >= 0; i--) { + Chat.sendPrivateMessageToSelfFatal("BB: Time till crash: " + i); + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + } + } + System.exit(69); + }); + crashThread.start(); + } + else if (packet.command.equals(InternalCommandPacket.INSTACRASH)) { + System.out.println("BBsentials: InstaCrash triggered"); + System.exit(69); + } + } + + public void onInvalidCommandFeedbackPacket(InvalidCommandFeedbackPacket packet) { + Chat.sendPrivateMessageToSelfError(packet.displayMessage); + } + + public void onPartyPacket(PartyPacket packet) { + if (BBsentials.config.allowServerPartyInvite) { + Chat.sendCommand("/p " + packet.type + String.join(" ", packet.users)); + } + else { + Chat.sendPrivateMessageToSelfImportantInfo("Blocked a Party Command from the Server: "+packet.type+" : "+String.join(" ", packet.users)); + } + } + + public void onSystemMessagePacket(SystemMessagePacket packet) { + if (packet.important) { + Chat.sendPrivateMessageToSelfImportantInfo("§n" + packet.message); + } + else { + Chat.sendPrivateMessageToSelfInfo(packet.message); + } + if (packet.ping) { + EnvironmentCore.mcUtils.playsound("block.anvil.destroy"); + } + } + + public boolean showChChest(ChChestItem[] items) { + if (BBsentials.config.toDisplayConfig.allChChestItem) return true; + for (ChChestItem item : items) { + if (BBsentials.config.toDisplayConfig.customChChestItem && item.isCustom()) return true; + if (BBsentials.config.toDisplayConfig.allRoboPart && item.isRoboPart()) return true; + if (BBsentials.config.toDisplayConfig.prehistoricEgg && item.equals(ChChestItems.PrehistoricEgg)) return true; + if (BBsentials.config.toDisplayConfig.pickonimbus2000 && item.equals(ChChestItems.Pickonimbus2000)) return true; + if (BBsentials.config.toDisplayConfig.controlSwitch && item.equals(ChChestItems.ControlSwitch)) return true; + if (BBsentials.config.toDisplayConfig.electronTransmitter && item.equals(ChChestItems.ElectronTransmitter)) + return true; + if (BBsentials.config.toDisplayConfig.robotronReflector && item.equals(ChChestItems.RobotronReflector)) return true; + if (BBsentials.config.toDisplayConfig.superliteMotor && item.equals(ChChestItems.SuperliteMotor)) return true; + if (BBsentials.config.toDisplayConfig.syntheticHeart && item.equals(ChChestItems.SyntheticHeart)) return true; + if (BBsentials.config.toDisplayConfig.flawlessGemstone && item.equals(ChChestItems.FlawlessGemstone)) return true; + if (BBsentials.config.toDisplayConfig.jungleHeart && item.equals(ChChestItems.JungleHeart)) return true; + } + return false; + } + + public boolean isConnected() { + try { + socket.isConnected(); + return true; + } catch (Exception e) { + 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; + } + } + + public interface MessageReceivedCallback { + void onMessageReceived(String message); + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProvider.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProvider.java new file mode 100644 index 0000000..7728b99 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProvider.java @@ -0,0 +1,23 @@ +package de.hype.bbsentials.forge.common.constants; + +public interface BBDisplayNameProvider { + String getDisplayName(); + + default String serialize() { + return name() + ":" + getDisplayName(); + } + + default String name() { + return ((Enum) this).name(); + } + +// public static BBDisplayNameProvider deserialize(String serializedValue) { +// String[] parts = serializedValue.split(":"); +// if (parts.length != 2) { +// throw new IllegalArgumentException("Invalid serialized value format"); +// } +// String enumName = parts[0]; +// String displayName = parts[1]; +// return ; +// } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProviderWithCustom.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProviderWithCustom.java new file mode 100644 index 0000000..c1508c3 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/BBDisplayNameProviderWithCustom.java @@ -0,0 +1,6 @@ +package de.hype.bbsentials.forge.common.constants; + +public interface BBDisplayNameProviderWithCustom> extends BBDisplayNameProvider { + T setDisplayName(String displayname); + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/AuthenticationConstants.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/AuthenticationConstants.java new file mode 100644 index 0000000..cbb1bc0 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/AuthenticationConstants.java @@ -0,0 +1,7 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +public class AuthenticationConstants { + //Authentication Types + public static final String MOJANG = "MOJANG"; + public static final String DATABASE = "DATABASE"; +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItem.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItem.java new file mode 100644 index 0000000..8c1cf20 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItem.java @@ -0,0 +1,46 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +public class ChChestItem { + private String displayName; + private boolean custom; + + public ChChestItem(String displayName) { + this.displayName = displayName; + this.custom = false; + } + + public ChChestItem(String displayName, boolean custom) { + this.displayName = displayName; + this.custom = custom; + } + + public String getDisplayName() { + return displayName; + } + + public ChChestItem setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public boolean isCustom() { + return custom; + } + + @Override + public String toString() { + return displayName; + } + + public boolean isGemstone() { + return displayName.startsWith("Flawless") && displayName.endsWith("Gemstone"); + } + + public boolean isRoboPart() { + String[] roboParts = {"Control Switch", "Electron Transmitter", "FTX 3070", "Robotron Reflector", "Superlite Motor", "Synthetic Heart"}; + for (String roboPart : roboParts) { + if (displayName.equals(roboPart)) return true; + } + return false; + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItems.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItems.java new file mode 100644 index 0000000..0301356 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/ChChestItems.java @@ -0,0 +1,87 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class ChChestItems { + private static final List items = new ArrayList<>(); + + public static final ChChestItem PrehistoricEgg = new ChChestItem("Prehistoric Egg"); + public static final ChChestItem Pickonimbus2000 = new ChChestItem("Pickonimbus 2000"); + public static final ChChestItem ControlSwitch = new ChChestItem("Control Switch"); + public static final ChChestItem ElectronTransmitter = new ChChestItem("Electron Transmitter"); + public static final ChChestItem FTX3070 = new ChChestItem("FTX 3070"); + public static final ChChestItem RobotronReflector = new ChChestItem("Robotron Reflector"); + public static final ChChestItem SuperliteMotor = new ChChestItem("Superlite Motor"); + public static final ChChestItem SyntheticHeart = new ChChestItem("Synthetic Heart"); + public static final ChChestItem FlawlessGemstone = new ChChestItem("Flawless Gemstone"); + public static final ChChestItem JungleHeart = new ChChestItem("Jungle Heart"); + + // Automatically populate predefined items using reflection + static { + Field[] fields = ChChestItems.class.getDeclaredFields(); + for (Field field : fields) { + if (field.getType().equals(ChChestItem.class) && isPublicStaticFinal(field)) { + try { + items.add((ChChestItem) field.get(null)); + } catch (IllegalAccessException e) { + // Handle exception + } + } + } + } + + public static ChChestItem getItem(String displayName) { + ChChestItem existingItem = getPredefinedItem(displayName); + + if (existingItem != null) { + return existingItem; + } + + ChChestItem customItem = new ChChestItem(displayName, true); + return customItem; + } + + private static ChChestItem getPredefinedItem(String displayName) { + for (ChChestItem item : items) { + if (item.getDisplayName().equals(displayName)) { + return item; + } + } + return null; + } + + public static ChChestItem[] getItem(String[] displayNames) { + ChChestItem[] result = new ChChestItem[displayNames.length]; + for (int i = 0; i < displayNames.length; i++) { + result[i] = getItem(displayNames[i]); + } + return result; + } + + // Utility method to check if a field is public, static, and final + private static boolean isPublicStaticFinal(Field field) { + return java.lang.reflect.Modifier.isPublic(field.getModifiers()) && + java.lang.reflect.Modifier.isStatic(field.getModifiers()) && + java.lang.reflect.Modifier.isFinal(field.getModifiers()); + } + + public static ChChestItem createCustomItem(String displayName) { + ChChestItem customItem = new ChChestItem(displayName, true); + items.add(customItem); + return customItem; + } + + public static List getAllItems() { + return items; + } + + public static List getAllItemNames() { + return items.stream() + .map(ChChestItem::getDisplayName) + .collect(Collectors.toList()); + //very fancy way to convert a list to a list of values from the previous list + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/EnumUtils.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/EnumUtils.java new file mode 100644 index 0000000..3664d4f --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/EnumUtils.java @@ -0,0 +1,216 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +import de.hype.bbsentials.forge.common.constants.BBDisplayNameProvider; +import de.hype.bbsentials.forge.common.constants.BBDisplayNameProviderWithCustom; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class EnumUtils { + public static List getAllDisplayNames(Class enumClass) { + List displayNames = new ArrayList<>(); + + for (BBDisplayNameProvider item : enumClass.getEnumConstants()) { + displayNames.add(item.getDisplayName()); + } + + return displayNames; + } + + public static & BBDisplayNameProvider> List getEnumsAsList(Class enumClass) { + List enumList = new ArrayList<>(); + + for (T item : enumClass.getEnumConstants()) { + enumList.add(item); + } + + return enumList; + } + + public static List getDisplayNames(Collection itemList) { + List displayNames = new ArrayList<>(); + for (BBDisplayNameProvider item : itemList) { + displayNames.add(item.getDisplayName()); + } + return displayNames; + } + + public static List getEnumsAsList(List itemList) { + List enumList = new ArrayList<>(itemList); + return enumList; + } + + public static List getAllEnumNames(Class> enumClass) { + List enumNames = new ArrayList<>(); + Enum[] enumConstants = enumClass.getEnumConstants(); + + for (Enum enumConstant : enumConstants) { + enumNames.add(enumConstant.name()); + } + + return enumNames; + } + +// public interface BBDisplayNameProvider { +// String getDisplayName(); +// default public String serialize() { +// return name() + ":" + displayName; +// } +// +// default public ChChestItems deserialize(String serializedValue) { +// String[] parts = serializedValue.split(":"); +// if (parts.length != 2) { +// throw new IllegalArgumentException("Invalid serialized value format"); +// } +// String enumName = parts[0]; +// String displayName = parts[1]; +// +// return ChChestItems.valueOf(enumName).setDisplayName(displayName); +// } +// } + + + + // Methods for BBDisplayNameProviderWithCustom + + public static & BBDisplayNameProviderWithCustom> T getEnumByNameWithCustom(Class enumClass, String enumName) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(enumName)) { + return (enumValue); + } + } + return createCustomEnum(enumClass, enumName); + } + + public static & BBDisplayNameProviderWithCustom> T getEnumByValueWithCustom(Class enumClass, String value) { + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + return enumValue; + } + } + return (createCustomEnum(enumClass, value)); + + } + + public static & BBDisplayNameProviderWithCustom> T[] getEnumsByNameWithCustom(Class enumClass, String[] names) { + List matchingEnums = new ArrayList<>(); + + for (String name : names) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(name)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + if (!found) { + matchingEnums.add(createCustomEnum(enumClass, name)); + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + public static & BBDisplayNameProviderWithCustom> T[] getEnumsByValueWithCustom(Class enumClass, String[] values) { + List matchingEnums = new ArrayList<>(); + + for (String value : values) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.toString().equals(value)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + if (!found) { + matchingEnums.add(createCustomEnum(enumClass, value)); + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + // Methods for BBDisplayNameProvider + + public static & BBDisplayNameProvider> T getEnumByName(Class enumClass, String enumName) { + try { + return Enum.valueOf(enumClass, enumName); + } catch (IllegalArgumentException e) { + return null; // Enum value not found + } + } + public static & BBDisplayNameProvider, U extends Enum> U getEnumByName(Class enumClass, Class enumType, String enumName) { + try { + return Enum.valueOf(enumType, enumName); + } catch (IllegalArgumentException e) { + return null; // Enum value not found + } + } + + + public static & BBDisplayNameProvider> T getEnumByValue(Class enumClass, String value) { + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + return enumValue; + } + } + return null; + } + + public static & BBDisplayNameProvider> T[] getEnumsByName(Class enumClass, String[] names) { + List matchingEnums = new ArrayList<>(); + + for (String name : names) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.name().equals(name)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + public static & BBDisplayNameProvider> T[] getEnumsByValue(Class enumClass, String[] values) { + List matchingEnums = new ArrayList<>(); + + for (String value : values) { + boolean found = false; + for (T enumValue : enumClass.getEnumConstants()) { + if (enumValue.getDisplayName().equals(value)) { + matchingEnums.add(enumValue); + found = true; + break; + } + } + } + + return matchingEnums.toArray((T[]) java.lang.reflect.Array.newInstance(enumClass, 0)); + } + + private static & BBDisplayNameProviderWithCustom> T createCustomEnum(Class enumClass, String value) { + T customEnum = null; + try { + customEnum = Enum.valueOf(enumClass, "Custom"); + } catch (Exception ignored) { + try { + customEnum = Enum.valueOf(enumClass, "CUSTOM"); + } catch (Exception ignored2) { + } + } + if (customEnum == null) { + } + customEnum.setDisplayName(value); + return customEnum; + + } +} + + diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/InternalReasonConstants.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/InternalReasonConstants.java new file mode 100644 index 0000000..35b710e --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/InternalReasonConstants.java @@ -0,0 +1,14 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +public enum InternalReasonConstants { + INVALID_PARAMETER, + MISSING_PARAMETER, + INSUFFICIENT_PRIVILEGES, + MUTED, + BANNED, + API_UNSUPPORTED, + INVALID_LOGIN, + KICKED, + ANOTHER_LOGIN, + SERVER_RESTART +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/Islands.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/Islands.java new file mode 100644 index 0000000..6a1e5f1 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/Islands.java @@ -0,0 +1,47 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +import de.hype.bbsentials.forge.common.constants.BBDisplayNameProvider; + +public enum Islands implements BBDisplayNameProvider { + CRYSTAL_HOLLOWS("crystal_hollows", "Crystal Hollows"), + CRIMSON_ISLE("crimson_isle", "Crimson Isle"), + DEEP_CAVERNS("mining_2", "Deep Caverns"), + DUNGEON("dungeon", "Dungeon"), + DUNGEON_HUB("dungeon_hub", "Dungeon Hub"), + DWARVEN_MINES("mining_3", "Dwarven Mines"), + GOLD_MINE("mining_1", "Gold Mine"), + HUB("hub", "Hub"), + KUUDRA("kuudra", "Kuudra"), + PRIVATE_ISLAND("dynamic", "Private Islands"), + SPIDERS_DEN("combat_1", "Spider's Den"), + THE_END("combat_3", "The End"), + THE_FARMING_ISLANDS("farming_1", "The Farming Islands"), + JERRYS_WORKSHOP("winter", "Jerry's Workshop"), + THE_RIFT("rift", "The Rift"); + + + private final String internalName; + private final String displayName; + + Islands(String internalName, String displayName) { + this.internalName = internalName; + this.displayName = displayName; + } + + public String getInternalName() { + return internalName; + } + + public String getDisplayName() { + return displayName; + } + public static Islands getByDisplayName(String displayName) { + for (Islands island : values()) { + if (island.getDisplayName().equals(displayName)) { + return island; + } + } + return null; // Return null if the display name doesn't match any enum value + } + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/MiningEvents.java b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/MiningEvents.java new file mode 100644 index 0000000..c6baf87 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/constants/enviromentShared/MiningEvents.java @@ -0,0 +1,39 @@ +package de.hype.bbsentials.forge.common.constants.enviromentShared; + +import de.hype.bbsentials.forge.common.constants.BBDisplayNameProvider; + +// Mining Events +public enum MiningEvents implements BBDisplayNameProvider { + BETTER_TOGETHER("Better Together"), + DOUBLE_POWDER("Double Powder"), + GONE_WITH_THE_WIND("Gone with the Wind"), + GOBLIN_RAID("Goblin Raid"), + MITHRIL_GOURMAND("Mithril Gourmand"), + RAFFLE("Raffle"); + + private final String displayName; + + MiningEvents(String displayName) { + this.displayName = displayName; + } + + @Override + public String getDisplayName() { + return displayName; + } + + //Some Events cant happen in Crystal Holows + public boolean isDWEventOnly() { + if (this.equals(MiningEvents.MITHRIL_GOURMAND) || this.equals(MiningEvents.RAFFLE) || this.equals(MiningEvents.GOBLIN_RAID)) { + return true; + } + return false; + } + + public static boolean isDWEventOnly(String event) { + if (event.equals(MiningEvents.MITHRIL_GOURMAND.getDisplayName()) || event.equals(MiningEvents.RAFFLE.getDisplayName()) || event.equals(MiningEvents.GOBLIN_RAID.getDisplayName())) { + return true; + } + return false; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/BBUtils.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/BBUtils.java new file mode 100644 index 0000000..1c7f1b4 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/BBUtils.java @@ -0,0 +1,21 @@ +package de.hype.bbsentials.forge.common.mclibraries; + +import de.hype.bbsentials.forge.common.constants.enviromentShared.Islands; + +import java.util.List; + +public interface BBUtils { + Islands getCurrentIsland(); + + int getPlayerCount(); + + String getServer(); + + boolean isOnMegaServer(); + + boolean isOnMiniServer(); + + int getMaximumPlayerCount(); + + List getPlayers(); +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/EnvironmentCore.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/EnvironmentCore.java new file mode 100644 index 0000000..377c25b --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/EnvironmentCore.java @@ -0,0 +1,22 @@ +package de.hype.bbsentials.forge.common.mclibraries; + + +import de.hype.bbsentials.forge.common.client.DebugThread; + +public class EnvironmentCore { + public static MCCommand commands; + public static BBUtils utils; + public static MCChat chat; + public static MCUtils mcUtils; + public static Options mcoptions; + public static DebugThread debug; + + public EnvironmentCore(BBUtils utils, MCChat chat, MCUtils mcUtils, MCCommand commands, Options options, DebugThread debug) { + EnvironmentCore.utils = utils; + EnvironmentCore.chat = chat; + EnvironmentCore.mcUtils = mcUtils; + EnvironmentCore.commands = commands; + EnvironmentCore.mcoptions = options; + EnvironmentCore.debug=debug; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCChat.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCChat.java new file mode 100644 index 0000000..c4abda0 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCChat.java @@ -0,0 +1,9 @@ +package de.hype.bbsentials.forge.common.mclibraries; + +import de.hype.bbsentials.forge.common.chat.Message; + +public interface MCChat { + void init(); + void sendChatMessage(String message); + void sendClientSideMessage(Message message); +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCCommand.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCCommand.java new file mode 100644 index 0000000..a82fb86 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCCommand.java @@ -0,0 +1,6 @@ +package de.hype.bbsentials.forge.common.mclibraries; + +public interface MCCommand { + public void registerMain(); + public void registerRoleRequired(boolean hasDev, boolean hasAdmin, boolean hasMod, boolean hasSplasher, boolean hasBeta, boolean hasMiningEvents, boolean hasChChest); +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCUtils.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCUtils.java new file mode 100644 index 0000000..ab11bfc --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/MCUtils.java @@ -0,0 +1,16 @@ +package de.hype.bbsentials.forge.common.mclibraries; + +import java.io.File; + +public interface MCUtils { + boolean isWindowFocused(); + + File getConfigPath(); + + String getUsername(); + + String getMCUUID(); + void playsound(String eventName); + + int getPotTime(); +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/Options.java b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/Options.java new file mode 100644 index 0000000..6d6f125 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/mclibraries/Options.java @@ -0,0 +1,8 @@ +package de.hype.bbsentials.forge.common.mclibraries; + +public interface Options { + void setFov(int value); + + void setGamma(double value); +} + diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/AbstractPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/AbstractPacket.java new file mode 100644 index 0000000..7b2e74b --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/AbstractPacket.java @@ -0,0 +1,67 @@ +package de.hype.bbsentials.forge.common.packets; + +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.Config; +import de.hype.bbsentials.forge.common.communication.BBsentialConnection; +import de.hype.bbsentials.forge.common.packets.packets.InvalidCommandFeedbackPacket; + +import java.lang.reflect.Field; + +public class AbstractPacket { + public final int apiVersionMin; + public final int apiVersionMax; + + protected AbstractPacket(int apiVersionMin, int apiVersionMax) { + this.apiVersionMax = apiVersionMax; + this.apiVersionMin = apiVersionMin; + + } + + public boolean isValid(BBsentialConnection connection, String[] allowedNullFields) { + if (isApiSupported(BBsentials.config)) { + Chat.sendPrivateMessageToSelfFatal("You are using an outdated version of the mod"); + } + return true; + } + + public boolean isApiSupported(Config config) { + //int version = Core.getConfig().getVersion(); + int version = config.getApiVersion(); + if (version >= apiVersionMin && version <= apiVersionMax) { + return true; + } + return false; + } + + public String hasNullFields(String[] allowedNullFields) { + Field[] fields = this.getClass().getDeclaredFields(); + if (!this.getClass().getSimpleName().equals(InvalidCommandFeedbackPacket.class.getSimpleName())) { + for (Field field : fields) { + field.setAccessible(true); + try { + if (field.get(this) == null) { + if (allowedNullFields == null) return field.getName(); + if (isAllowedNull(allowedNullFields, field.getName())) { + return field.getName(); + } + } + } catch (IllegalAccessException e) { + // Handle the exception if needed + e.printStackTrace(); + } + } + } + return null; + + } + + public boolean isAllowedNull(String[] allowedFields, String fieldName) { + for (String allowedField : allowedFields) { + if (allowedField.equals(fieldName)) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/EnviromentPacketConfig.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/EnviromentPacketConfig.java new file mode 100644 index 0000000..8d95998 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/EnviromentPacketConfig.java @@ -0,0 +1,7 @@ +package de.hype.bbsentials.forge.common.packets; + +public class EnviromentPacketConfig { + public static final String enviroment = "Client"; + public static final String notEnviroment = "Server"; + public static final int apiVersion = 1; +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/Packet.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/Packet.java new file mode 100644 index 0000000..0724cd2 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/Packet.java @@ -0,0 +1,26 @@ +package de.hype.bbsentials.forge.common.packets; + +import java.util.function.Consumer; + +public class Packet { + + private final Class clazz; + private final Consumer consumer; + + public Packet(Class clazz, Consumer consumer) { + this.clazz = clazz; + this.consumer = consumer; + } + + public String getName() { + return clazz.getSimpleName(); + } + + public Class getClazz() { + return clazz; + } + + public Consumer getConsumer() { + return consumer; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketManager.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketManager.java new file mode 100644 index 0000000..2641f4a --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketManager.java @@ -0,0 +1,53 @@ +package de.hype.bbsentials.forge.common.packets; + +import de.hype.bbsentials.forge.common.communication.BBsentialConnection; +import de.hype.bbsentials.forge.common.packets.packets.*; + +import java.util.ArrayList; +import java.util.List; + +public class PacketManager { + private static List> packets = new ArrayList<>(); + + public List> getPackets() { + return packets; + } + + // Define a map to store packet classes and their associated actions + BBsentialConnection connection; + + // Method to initialize packet actions + public PacketManager(BBsentialConnection connection) { + this.connection = connection; + initializePacketActions(connection); + } + + public static void initializePacketActions(BBsentialConnection connection) { + packets.add(new Packet<>(BingoChatMessagePacket.class, connection::onBingoChatMessagePacket)); + packets.add(new Packet<>(BroadcastMessagePacket.class, connection::onBroadcastMessagePacket)); + 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::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)); +// packets.add(new Packet<>(RequestConnectPacket.class, connection::dummy)); + packets.add(new Packet<>(SplashNotifyPacket.class, connection::onSplashNotifyPacket)); + packets.add(new Packet<>(SystemMessagePacket.class, connection::onSystemMessagePacket)); + packets.add(new Packet<>(WelcomeClientPacket.class, connection::onWelcomePacket)); + } + + // Method to handle a received packet + + + // method to get a list of all packets + public static List> getAllPacketClasses() { + initializePacketActions(null); + List> allPackets = new ArrayList<>(); + for (int i = 0; i < allPackets.size(); i++) { + allPackets.add(packets.get(i).getClazz()); + } + return allPackets; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketUtils.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketUtils.java new file mode 100644 index 0000000..7b9ade4 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/PacketUtils.java @@ -0,0 +1,103 @@ +package de.hype.bbsentials.forge.common.packets; + +import com.google.gson.Gson; +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.CustomGson; +import de.hype.bbsentials.forge.common.communication.BBsentialConnection; + +import java.util.function.Consumer; + + +public class PacketUtils { + public static final Gson gson = CustomGson.create(); + + public static String parsePacketToJson(AbstractPacket packet) { + return gson.toJson(packet); + } + + public static void tryToProcessPacket(Packet packet, String rawJson) { + Class clazz = packet.getClazz(); + Consumer consumer = packet.getConsumer(); + T abstractPacket = gson.fromJson(rawJson, clazz); + consumer.accept(abstractPacket); + } + + private static void showError(Throwable t, String errorMessage) { + System.out.println(errorMessage + " because of: " + t.getClass().getSimpleName() + ": " + t.getMessage()); + new Error(errorMessage, t).printStackTrace(); + } + + public static class APIException extends Error { + + public APIException(String errorMessage, Throwable t) { + super(errorMessage, t); + } + + public APIException(String errorMessage) { + super(errorMessage); + } + } + + public static T getAsPacket(String message, Class clazz) { + if (!message.contains(".")) return null; + String packetName = message.split("\\.")[0]; + String rawJson = message.substring(packetName.length() + 1); + if (!packetName.equals(clazz.getSimpleName())) { + try { + T parsedPacket = gson.fromJson(rawJson, clazz); + return parsedPacket; + } catch (Throwable t) { + showError(t, "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment); + } + } + String errorMessage = "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment; + + showError(new APIException("Found unknown packet: " + packetName + "'"), errorMessage); + return null; + } + + public static boolean isPacket(String message, Class clazz) { + if (!message.contains(".")) return false; + String packetName = message.split("\\.")[0]; + if (packetName.equals(clazz.getSimpleName())) { + return true; + } + return false; + } + + public static boolean isPacket(String message) { + if (!message.contains(".")) return false; + String packetName = message.split("\\.")[0]; + for (Class packetClass : PacketManager.getAllPacketClasses()) { + if (!packetName.equals(packetClass.getSimpleName())) { + return true; + } + } + return false; + } + + public static boolean handleIfPacket(BBsentialConnection connection, String message) { + //Return = is Packet + if (!message.contains(".")) return false; + String packetName = message.split("\\.")[0]; + String rawJson = message.substring(packetName.length() + 1); + PacketManager manager = new PacketManager(connection); + for (Packet packet : manager.getPackets()) { + if (!packetName.equals(packet.getClazz().getSimpleName())) continue; + try { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelfDebug(packetName+":"+rawJson); + tryToProcessPacket(packet, rawJson); + return true; + }catch (RuntimeException e){ + throw e; + }catch (Exception t) { + showError(t, "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment); + } + } + String errorMessage = "Could not process packet '" + packetName + "' from " + EnviromentPacketConfig.notEnviroment; + + showError(new APIException("Found unknown packet: " + packetName + "'"), errorMessage); + return false; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BingoChatMessagePacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BingoChatMessagePacket.java new file mode 100644 index 0000000..cd2e945 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BingoChatMessagePacket.java @@ -0,0 +1,25 @@ +package de.hype.bbsentials.forge.common.packets.packets; + + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class BingoChatMessagePacket extends AbstractPacket { + + public BingoChatMessagePacket(String prefix, String username, String message, int bingo_cards) { + super(1, 1); //Min and Max supported Version + this.message = message; + this.username = username; + this.prefix = prefix; + this.bingo_cards = bingo_cards; + } + + public final String message; + public final String username; + public final String prefix; + public final int bingo_cards; + + public boolean baseCheck() { + boolean cancelPacket = false; + return !cancelPacket; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BroadcastMessagePacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BroadcastMessagePacket.java new file mode 100644 index 0000000..88cf5cf --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/BroadcastMessagePacket.java @@ -0,0 +1,18 @@ +package de.hype.bbsentials.forge.common.packets.packets; + + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class BroadcastMessagePacket extends AbstractPacket { + + public final String message; + public final String username; + public final String prefix; + + public BroadcastMessagePacket(String prefix, String username, String message) { + super(1, 1); //Min and Max supported Version + this.message = message; + this.username = username; + this.prefix = prefix; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/ChChestPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/ChChestPacket.java new file mode 100644 index 0000000..9cd41f8 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/ChChestPacket.java @@ -0,0 +1,23 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.constants.enviromentShared.ChChestItem; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class ChChestPacket extends AbstractPacket { + + public ChChestPacket(String announcerUsername, ChChestItem[] items, String locationCoords, String bbcommand, String extraMessage) { + super(1, 1); //Min and Max supported Version + this.announcerUsername = announcerUsername; + this.locationCoords = locationCoords; + this.bbcommand = bbcommand; + this.extraMessage = extraMessage; + this.items = items; + } + + public final String announcerUsername; + public final String locationCoords; + public final String bbcommand; + public final String extraMessage; + public final ChChestItem[] items; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisconnectPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisconnectPacket.java new file mode 100644 index 0000000..7b8782e --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisconnectPacket.java @@ -0,0 +1,23 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.constants.enviromentShared.InternalReasonConstants; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class DisconnectPacket extends AbstractPacket { + + public DisconnectPacket(InternalReasonConstants internalReason, int[] waitBeforeReconnect, int randomExtraDelay, String displayReason, String displayMessage) { + super(1, 1); //Min and Max supportet Version + this.internalReason = internalReason; + this.waitBeforeReconnect = waitBeforeReconnect; + this.displayReason = displayReason; + this.displayMessage = displayMessage; + this.randomExtraDelay = randomExtraDelay; + } + + public final InternalReasonConstants internalReason; + public final int[] waitBeforeReconnect; + public final int randomExtraDelay; + public final String displayReason; + public final String displayMessage; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisplayTellrawMessagePacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisplayTellrawMessagePacket.java new file mode 100644 index 0000000..ab3ddf4 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/DisplayTellrawMessagePacket.java @@ -0,0 +1,12 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class DisplayTellrawMessagePacket extends AbstractPacket { + public final String rawJson; + + public DisplayTellrawMessagePacket(String rawJson) { + super(1, 1); //Min and Max supported Version + this.rawJson = rawJson; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InternalCommandPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InternalCommandPacket.java new file mode 100644 index 0000000..b1f7c25 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InternalCommandPacket.java @@ -0,0 +1,32 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.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 + this.command = command; + this.parameters = parameters; + } + + public final String command; + public final String[] parameters; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InvalidCommandFeedbackPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InvalidCommandFeedbackPacket.java new file mode 100644 index 0000000..1394a11 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/InvalidCommandFeedbackPacket.java @@ -0,0 +1,24 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class InvalidCommandFeedbackPacket extends AbstractPacket { + + public InvalidCommandFeedbackPacket(String internalReason, String command, String displayMessage, String argument, String permissionNeeded, String[] userPermissions) { + super(1, 1); //Min and Max supportet Version + this.internalReason = internalReason; + this.argument = argument; + this.permissionNeeded = permissionNeeded; + this.userPermissions = userPermissions; + this.command = command; + this.displayMessage = displayMessage; + } + + public final String internalReason; + public final String argument; + public final String permissionNeeded; + public final String[] userPermissions; + public final String command; + public final String displayMessage; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/MiningEventPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/MiningEventPacket.java new file mode 100644 index 0000000..67a88da --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/MiningEventPacket.java @@ -0,0 +1,25 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.constants.enviromentShared.Islands; +import de.hype.bbsentials.forge.common.constants.enviromentShared.MiningEvents; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class MiningEventPacket extends AbstractPacket { + + + public final MiningEvents event; + public final String username; + public final Islands island; + + public MiningEventPacket(MiningEvents event, String username, Islands island) throws Exception { + super(1, 1); //Min and Max supported Version + this.event = event; + this.username = username; + if (island.equals(Islands.CRYSTAL_HOLLOWS)) { + if (event.equals(MiningEvents.MITHRIL_GOURMAND) || event.equals(MiningEvents.RAFFLE) || event.equals(MiningEvents.GOBLIN_RAID)) { + throw new Exception("The specified event can not happen on this Server"); + } + } + this.island = island; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PartyPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PartyPacket.java new file mode 100644 index 0000000..b536d6d --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PartyPacket.java @@ -0,0 +1,16 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class PartyPacket extends AbstractPacket { + + public PartyPacket(String type, String[] users) { + super(1, 1); //Min and Max supportet Version + this.type = type; + this.users = users; + } + + public final String type; + public final String[] users; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PunishUserPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PunishUserPacket.java new file mode 100644 index 0000000..d807ad8 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/PunishUserPacket.java @@ -0,0 +1,24 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class PunishUserPacket extends AbstractPacket { + public static final String PUNISHMENT_TYPE_BAN = "BAN"; + public static final String PUNISHMENT_TYPE_MUTE = "MUTE"; + + public PunishUserPacket(String punishmentType,int userId, String username, String duration, String reason) { + super(1, 1); + this.type = punishmentType; + this.username = username; + this.userId = userId; + this.duration = duration; + this.reason = reason; + } + + public final String username; + public final String type; + public final int userId; + public final String duration; + public final String reason; + +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/RequestConnectPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/RequestConnectPacket.java new file mode 100644 index 0000000..705e2f5 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/RequestConnectPacket.java @@ -0,0 +1,20 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class RequestConnectPacket extends AbstractPacket { + + + public RequestConnectPacket(String mcuuid, String key, int clientApiVersion, String authType) { + super(1, 1); //Min and Max supported Version + this.mcuuid = mcuuid; + this.key = key; + this.authType = authType; + this.clientApiVersion = clientApiVersion; + } + + public final String mcuuid; + public final String key; + public final String authType; + public final int clientApiVersion; +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashNotifyPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashNotifyPacket.java new file mode 100644 index 0000000..ad3e459 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashNotifyPacket.java @@ -0,0 +1,28 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.constants.enviromentShared.Islands; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class SplashNotifyPacket extends AbstractPacket { + + + public SplashNotifyPacket(int splashId, int hub, String splasherUsername, String location, Islands hubType, String extraMessage, boolean lessWaste) { + super(1, 1); //Min and Max supported Version + this.hub = hub; + this.splashId = splashId; + + this.lessWaste = lessWaste; + this.splasherUsername = splasherUsername; + this.location = location; + this.hubType = hubType; + this.extraMessage = extraMessage; + } + + public final int hub; + public final int splashId; + public final boolean lessWaste; + public final String splasherUsername; + public final String location; + public final Islands hubType; + public final String extraMessage; +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashUpdatePacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashUpdatePacket.java new file mode 100644 index 0000000..f0e306b --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SplashUpdatePacket.java @@ -0,0 +1,22 @@ +package de.hype.bbsentials.forge.common.packets.packets; + + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class SplashUpdatePacket extends AbstractPacket { + public static final String STATUS_WAITING = "Waiting"; + public static final String STATUS_FULL = "Full"; + public static final String STATUS_SPLASHING = "Splashing"; + public static final String STATUS_CANCELED = "Canceled"; + public static final String STATUS_DONE = "Done"; + + + public SplashUpdatePacket(int splashId, String status) { + super(1, 1); //Min and Max supported Version + this.splashId = splashId; + this.status = status; + } + + public final int splashId; + public final String status; +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SystemMessagePacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SystemMessagePacket.java new file mode 100644 index 0000000..3ec68c1 --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/SystemMessagePacket.java @@ -0,0 +1,16 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class SystemMessagePacket extends AbstractPacket { + public final String message; + public final boolean important; + public final boolean ping; + + public SystemMessagePacket(String message, boolean important, boolean ping) { + super(1, 1); //Min and Max supported Version + this.message = message; + this.important = important; + this.ping = ping; + } +} diff --git a/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/WelcomeClientPacket.java b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/WelcomeClientPacket.java new file mode 100644 index 0000000..01e743d --- /dev/null +++ b/common/src/main/java/de/hype/bbsentials/forge/common/packets/packets/WelcomeClientPacket.java @@ -0,0 +1,18 @@ +package de.hype.bbsentials.forge.common.packets.packets; + +import de.hype.bbsentials.forge.common.packets.AbstractPacket; + +public class WelcomeClientPacket extends AbstractPacket { + + public WelcomeClientPacket(String[] roles, String motd, boolean success) { + super(1, 1); //Min and Max supportet Version + this.roles = roles; + this.motd = motd; + this.success = success; + } + + public final String[] roles; + public final String motd; + public final boolean success; + +} \ No newline at end of file diff --git a/common/src/main/resources/bbsentials.mixins.json b/common/src/main/resources/bbsentials.mixins.json deleted file mode 100644 index 4467110..0000000 --- a/common/src/main/resources/bbsentials.mixins.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "de.hype.bbsentials.mixins", - "compatibilityLevel": "JAVA_8", - "mixins": [], - "client": [ - "de.hype.bbsentials.common.mixins.ClientCommandSourceMixin", - "de.hype.bbsentials.common.mixins.ItemRendererMixin", - "de.hype.bbsentials.common.mixins.ScreenMixin", - "de.hype.bbsentials.common.mixins.SimpleOptionMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/common/src/main/resources/fabric.mod.json b/common/src/main/resources/fabric.mod.json deleted file mode 100644 index d296d7c..0000000 --- a/common/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "schemaVersion": 1, - "id": "bbsentials", - "version": "${version}", - "name": "BBsentials", - "icon": "logo.png", - "description": "Mod to connect to the BBsentials Network for Splashes and more", - "authors": [ - "Hype_the_Time/hackthetime" - ], - "contributors": ["hannibal2"], - "contact": { - "homepage": "https://github.com/HacktheTime/BBsentials1.20", - "issues": "https://github.com/HacktheTime/BBsentials1.20/issues", - "email": "s0844x76@duck.com", - "sources": "https://github.com/HacktheTime/BBsentials1.20" - }, - "license": "Look on Github (Sources). a Modified \"CC BY-NC-ND 4.0\" License", - "environment": "client", - "entrypoints": { - "client": [ - "de.hype.bbsentials.common.client.BBsentials" - ], - "modmenu": [ - "de.hype.bbsentials.fabric.ModMenueScreen" - ] - }, - "depends": { - "fabricloader": ">=${loader_version}", - "fabric": "*", - "minecraft": "${minecraft_version}" - }, - "mixins": [ - "bbsentials.mixins.json" - ], - "custom": { - "modmenu": { - "links": { - "License": "https://github.com/HacktheTime/BBsentials1.20/blob/master/LICENSE", - "modmenu.discord":"discord.gg/qr5mPRq8uG" - }, - "update_checker": true - } - } -} \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index 4fa2a38..8200bfb 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -17,7 +17,7 @@ repositories { // for more information about repositories. } dependencies { - implementation project(path: ':common') + implementation project(":common") // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" @@ -76,7 +76,12 @@ jar { 'MixinConfigs': 'modid.mixin.json' } } +task copyCustomJar(type: Copy) { + from jar // Specify the customJar task as the source + into project.projectDir // Set the destination directory (e.g., project root) +} +copyCustomJar.dependsOn jar // configure the maven publication publishing { publications { @@ -92,4 +97,11 @@ publishing { // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. } -} \ No newline at end of file +} +sourceSets { + main { + resources { + project(':common').sourceSets.main.resources.srcDirs + } + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java index 5dca4ac..d0442cc 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java @@ -1,15 +1,15 @@ package de.hype.bbsentials.fabric; import com.google.common.collect.Lists; -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.constants.enviromentShared.Islands; +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.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 implements de.hype.bbsentials.common.mclibraries.BBUtils { +public class BBUtils implements de.hype.bbsentials.forge.common.mclibraries.BBUtils { public Islands getCurrentIsland() { try { String string = MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!C-b").getDisplayName().getString(); diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java index a723284..64775db 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java @@ -1,7 +1,7 @@ package de.hype.bbsentials.fabric; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.constants.enviromentShared.Islands; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.constants.enviromentShared.Islands; import me.shedaniel.clothconfig2.api.ConfigBuilder; import me.shedaniel.clothconfig2.api.ConfigCategory; import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java b/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java index e23d76b..d4f1369 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java @@ -3,14 +3,14 @@ package de.hype.bbsentials.fabric; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.constants.enviromentShared.ChChestItems; -import de.hype.bbsentials.common.constants.enviromentShared.MiningEvents; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import de.hype.bbsentials.common.mclibraries.MCCommand; -import de.hype.bbsentials.common.packets.AbstractPacket; -import de.hype.bbsentials.common.packets.packets.*; +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.constants.enviromentShared.ChChestItems; +import de.hype.bbsentials.forge.common.constants.enviromentShared.MiningEvents; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.common.mclibraries.MCCommand; +import de.hype.bbsentials.forge.common.packets.AbstractPacket; +import de.hype.bbsentials.forge.common.packets.packets.*; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java b/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java index 1752492..eaf4f61 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java @@ -2,7 +2,7 @@ package de.hype.bbsentials.fabric; import java.util.List; -public class DebugThread implements de.hype.bbsentials.common.client.DebugThread { +public class DebugThread implements de.hype.bbsentials.forge.common.client.DebugThread { @Override public void loop() { diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java index 0244181..8e538a6 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java @@ -1,8 +1,8 @@ package de.hype.bbsentials.fabric; -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.chat.Message; -import de.hype.bbsentials.common.mclibraries.MCChat; +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.chat.Message; +import de.hype.bbsentials.forge.common.mclibraries.MCChat; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents; import net.minecraft.client.MinecraftClient; diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java index 149b72a..5230f2e 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java @@ -10,7 +10,7 @@ import net.minecraft.util.Identifier; import java.io.File; -public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { +public class MCUtils implements de.hype.bbsentials.forge.common.mclibraries.MCUtils { public boolean isWindowFocused() { return MinecraftClient.getInstance().isWindowFocused(); } diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java index 2e7b4fe..7769582 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java @@ -1,11 +1,11 @@ package de.hype.bbsentials.fabric; import com.mojang.brigadier.arguments.StringArgumentType; -import de.hype.bbsentials.common.chat.Chat; -import de.hype.bbsentials.common.chat.Message; -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.client.Config; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.common.chat.Chat; +import de.hype.bbsentials.forge.common.chat.Message; +import de.hype.bbsentials.forge.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.Config; +import de.hype.bbsentials.forge.common.mclibraries.EnvironmentCore; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; -import static de.hype.bbsentials.common.client.BBsentials.*; +import static de.hype.bbsentials.forge.common.client.BBsentials.*; public class ModInitialiser implements ClientModInitializer { @Override diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java b/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java index 3d7cbe3..4d519bb 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java @@ -1,9 +1,9 @@ package de.hype.bbsentials.fabric; -import de.hype.bbsentials.common.api.ISimpleOption; +import de.hype.bbsentials.forge.common.api.ISimpleOption; import net.minecraft.client.MinecraftClient; -public class Options implements de.hype.bbsentials.common.mclibraries.Options { +public class Options implements de.hype.bbsentials.forge.common.mclibraries.Options { public void setFov(int value) { ((ISimpleOption) (Object) MinecraftClient.getInstance().options.getFov()).set(value); } diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java index 0c6a2bb..2207c5a 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java @@ -1,6 +1,6 @@ package de.hype.bbsentials.fabric.mixins; -import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.forge.common.client.BBsentials; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.ItemRenderer; diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java index 711ac09..64c90b2 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java @@ -1,6 +1,6 @@ package de.hype.bbsentials.fabric.mixins; -import de.hype.bbsentials.common.api.ISimpleOption; +import de.hype.bbsentials.forge.common.api.ISimpleOption; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.SimpleOption; import org.spongepowered.asm.mixin.Final; diff --git a/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png b/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png deleted file mode 100644 index 7929d1a..0000000 Binary files a/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png and /dev/null differ diff --git a/fabric/src/main/resources/assets/public_bbsentials_cert.crt b/fabric/src/main/resources/assets/public_bbsentials_cert.crt deleted file mode 100644 index 723fc34..0000000 Binary files a/fabric/src/main/resources/assets/public_bbsentials_cert.crt and /dev/null differ diff --git a/fabric/src/main/resources/logo.png b/fabric/src/main/resources/logo.png deleted file mode 100644 index 407312a..0000000 Binary files a/fabric/src/main/resources/logo.png and /dev/null differ diff --git a/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav b/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav deleted file mode 100644 index d079479..0000000 Binary files a/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav and /dev/null differ diff --git a/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav b/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav deleted file mode 100644 index f118ac5..0000000 Binary files a/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav and /dev/null differ diff --git a/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav b/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav deleted file mode 100644 index 4bed79a..0000000 Binary files a/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav and /dev/null differ diff --git a/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav b/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav deleted file mode 100644 index 582445e..0000000 Binary files a/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav and /dev/null differ diff --git a/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav b/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav deleted file mode 100644 index 37800c9..0000000 Binary files a/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav and /dev/null differ diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..2b7af90 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,127 @@ +plugins { + id("idea") + id("java") + id("gg.essential.loom") version "0.10.0.+" + id("dev.architectury.architectury-pack200") version "0.1.3" + id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.bnorm.power.kotlin-power-assert") version "0.13.0" +} + +// Toolchains: +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(8)) +} + +// Minecraft configuration: +loom { + log4jConfigs.from(file("log4j2.xml")) + launchConfigs { + "client" { + // If you don't want mixins, remove these lines + property("mixin.debug", "true") + property("asmhelper.verbose", "true") + arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") + arg("--mixin", "mixins.$modid.json") + } + } + forge { + pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) + // If you don't want mixins, remove this lines + mixinConfig("mixins.bbsentials.json") + } + // If you don't want mixins, remove these lines + mixin { + defaultRefmapName.set("mixins.bbsentials.refmap.json") + } +} + +sourceSets.main { + output.resourcesDir = file("$buildDir/classes/java/main") +} + +// Dependencies: + +repositories { + mavenCentral() + maven("https://repo.spongepowered.org/maven/") + // If you don't want to log in with your real minecraft account, remove this line + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") +} + +val shadowImpl: Configuration by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} + +dependencies { + minecraft("com.mojang:minecraft:1.8.9") + mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") + forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + + // If you don't want mixins, remove these lines + shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false + } + annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") + + // If you don't want to log in with your real minecraft account, remove this line + runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.2") + +} + +// Tasks: + +tasks.withType(JavaCompile::class) { + options.encoding = "UTF-8" +} + +tasks.withType(Jar::class) { + archiveBaseName.set(modid) + manifest.attributes.run { + this["FMLCorePluginContainsFMLMod"] = "true" + this["ForceLoadAsMod"] = "true" + + // If you don't want mixins, remove these lines + this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker" + this["MixinConfigs"] = "mixins.$modid.json" + } +} + +tasks.processResources { + inputs.property("version", project.version) + inputs.property("mcversion", mcVersion) + inputs.property("modid", modid) + inputs.property("mixinGroup", mixinGroup) + + filesMatching(listOf("mcmod.info", "mixins.$modid.json")) { + expand(inputs.properties) + rename { fileName -> + fileName.replaceAll("(.+_at.cfg)", "META-INF/" + fileName) + } + } +} + + +val remapJar by tasks.named("remapJar") { + archiveClassifier.set("") + from(tasks.shadowJar) + input.set(tasks.shadowJar.get().archiveFile) +} + +tasks.jar { + archiveClassifier.set("without-deps") + destinationDirectory.set(layout.buildDirectory.dir("badjars")) +} + +tasks.shadowJar { + destinationDirectory.set(layout.buildDirectory.dir("badjars")) + archiveClassifier.set("all-dev") + configurations = listOf(shadowImpl) + doLast { + configurations.forEach { + println("Copying jars into mod: ${it.files}") + } + } +} + +tasks.assemble.get().dependsOn(tasks.remapJar) + diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 0000000..3545637 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1,20 @@ +loom.platform=forge +org.gradle.jvmargs=-Xmx4g +mcVersion = 1.8.9 +modid = bbsentials +version = 1.0.0 +# Done to increase the memory available to gradle. +# Fabric Properties +# check these on https://modmuss50.me/fabric.html +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.1 +loader_version=0.14.22 +#Fabric api +fabric_version=0.89.2+1.20.2 +# Mod Properties +mod_version=1.0 +baseGroup = de.hype.bbsentials.forge +forgeMcVersion = 1.8.9 +maven_group=de.hype +archives_base_name=bbsentials +#Other \ No newline at end of file diff --git a/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java b/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java new file mode 100644 index 0000000..9a118a1 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java @@ -0,0 +1,36 @@ +package de.hype.bbsentials.forge; + +import de.hype.bbsentials.forge.client.BBsentials; +import de.hype.bbsentials.forge.client.CommandBBI; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod(modid = "bbsentials", useMetadata = true) +public class ExampleMod { + static boolean alreadyInialised = false; + static BBsentials sentials = new BBsentials(); + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(this); + } + + public void clientSetup() { + if (!alreadyInialised) { + ClientCommandHandler.instance.registerCommand(new CommandBBI()); + alreadyInialised = true; + sentials.init(); + } + } + + @SubscribeEvent + public void onEntityJoinWorld(EntityJoinWorldEvent event) { + clientSetup(); + MinecraftForge.EVENT_BUS.unregister(this); + } +} + diff --git a/forge/src/main/java/de/hype/bbsentials/forge/Temphook.java b/forge/src/main/java/de/hype/bbsentials/forge/Temphook.java new file mode 100644 index 0000000..9b0ce86 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/Temphook.java @@ -0,0 +1,18 @@ +package de.hype.bbsentials.forge; + +import de.hype.bbsentials.forge.client.BBsentials; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +public class Temphook { + public static void renderItemOverlayPost(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, CallbackInfo ci) { + if (BBsentials.config.highlightitem) { + if (stack != null) { + if (stack.getDisplayName().contains(BBsentials.bbserver.getItemName())) { + stack.setStackDisplayName("§6(Bingo Splash) " + stack.getDisplayName()); + } + } + } + } +} \ No newline at end of file diff --git a/forge/src/main/java/de/hype/bbsentials/forge/chat/Chat.java b/forge/src/main/java/de/hype/bbsentials/forge/chat/Chat.java new file mode 100644 index 0000000..ec81c52 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/chat/Chat.java @@ -0,0 +1,580 @@ +package de.hype.bbsentials.forge.chat; + +import de.hype.bbsentials.forge.client.BBsentials; +import de.hype.bbsentials.forge.client.Config; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.opengl.Display; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static de.hype.bbsentials.forge.client.BBsentials.config; +import static de.hype.bbsentials.forge.client.BBsentials.getConfig; + +public class Chat { + public Chat() { + init(); + } + + public static String[] getVariableInfo(String packageName, String className) { + List variableInfoList = new ArrayList<>(); + + // Combine the class name with the package name + String fullClassName = packageName + "." + className; + + // Load the class + Class clazz = null; + try { + clazz = Class.forName(fullClassName); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + // Extract fields of the class + Field[] fields = clazz.getDeclaredFields(); + + // Collect information for each field + for (Field field : fields) { + // Exclude transient fields + if (Modifier.isTransient(field.getModifiers())) { + continue; + } + + String variableName = field.getName(); + String variablePackageName = clazz.getPackage().getName(); + String variableClassName = clazz.getSimpleName(); + + String variableInfo = variableName; + variableInfoList.add(variableInfo); + } + + return variableInfoList.toArray(new String[variableInfoList.size()]); + } + + public static void setVariableValue(Object obj, String variableName, String value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { + if (value == null) { + // Handle null value case + sendPrivateMessageToSelf(EnumChatFormatting.RED + "Invalid value: null"); + return; + } + + Class objClass = obj.getClass(); + Field field = objClass.getDeclaredField(variableName); + field.setAccessible(true); + + // Get the type of the field + Class fieldType = field.getType(); + + // Convert the value to the appropriate type + Object convertedValue = parseValue(value, fieldType); + + if (Modifier.isStatic(field.getModifiers())) { + // If the field is static + field.set(null, convertedValue); + } + else { + field.set(obj, convertedValue); + } + + // Check and output the value of the variable + sendPrivateMessageToSelf(EnumChatFormatting.GREEN + "The variable " + field.getName() + " is now: " + field.get(obj)); + } + + private static Object parseValue(String value, Class targetType) { + if (targetType == int.class || targetType == Integer.class) { + return Integer.parseInt(value); + } + else if (targetType == double.class || targetType == Double.class) { + return Double.parseDouble(value); + } + else if (targetType == float.class || targetType == Float.class) { + return Float.parseFloat(value); + } + else if (targetType == long.class || targetType == Long.class) { + return Long.parseLong(value); + } + else if (targetType == boolean.class || targetType == Boolean.class) { + return Boolean.parseBoolean(value); + } + else { + // For other types, return the original string value + return value; + } + } + + public static void getVariableValue(Object object, String variableName) throws NoSuchFieldException, IllegalAccessException { + Class objClass = object.getClass(); + Field field = objClass.getDeclaredField(variableName); + field.setAccessible(true); + sendPrivateMessageToSelf(EnumChatFormatting.GREEN + "The variable " + field.getName() + " is: " + field.get(object)); + } + + private void init() { + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void onClientChatReceived(ClientChatReceivedEvent event) { + IChatComponent newMessage = onEvent(event.message); + if (!newMessage.equals(event.message)){ + event.setCanceled(true); + Chat.sendPrivateMessageToSelfText(newMessage); + } + } + + private net.minecraft.util.IChatComponent onEvent(net.minecraft.util.IChatComponent message) { + Callable callable = () -> { + if (!isSpam(message.toString())) { + if (getConfig().isDetailedDevModeEnabled()) { + System.out.println("got a message: " + net.minecraft.util.IChatComponent.Serializer.componentToJson(message)); + } + return handleInClient(message); + } + return message; // Return the original message if it is spam + }; + + FutureTask future = new FutureTask<>(callable); + Thread thread = new Thread(future); + thread.start(); + + try { + return future.get(); // Retrieve the result from the background thread + } catch (InterruptedException | ExecutionException e) { + // Handle exceptions, if needed + e.printStackTrace(); + } + + return message; // Return the original message if an exception occurred + } + + //Handle in client + public net.minecraft.util.IChatComponent handleInClient(net.minecraft.util.IChatComponent messageOriginal) { + String message = extractPlainText(messageOriginal.toString()).trim(); + if (getConfig().messageFromAlreadyReported(message) && getPlayerNameFromMessage(message) != " " && getPlayerNameFromMessage(message) != "") { + System.out.println("Message: " + message); + sendPrivateMessageToSelf(EnumChatFormatting.RED + "B: " + message); + return null; + } + if (getConfig().isDevModeEnabled()) { + System.out.println("Got message to analyse internally: " + message); + } + //party accepter + if (message != null) { + if (message.contains("party")) { + if (message.contains("disbanded the party")) { + lastPartyDisbandedMessage = message; + partyDisbandedMap.put(getPlayerNameFromMessage(message), Instant.now()); + if (getConfig().isDevModeEnabled()) { + sendPrivateMessageToSelf("Watching next 20 Sec for invite: " + getPlayerNameFromMessage(message)); + } + } + else if (message.contains("invited you to join their party")) { + if (lastPartyDisbandedMessage != null && partyDisbandedMap != null) { + Instant lastDisbandedInstant = partyDisbandedMap.get(getPlayerNameFromMessage(lastPartyDisbandedMessage)); + if (lastDisbandedInstant != null && lastDisbandedInstant.isAfter(Instant.now().minusSeconds(20)) && (getPlayerNameFromMessage(message).equals(getPlayerNameFromMessage(lastPartyDisbandedMessage)))) { + sendCommand("/p accept " + getPlayerNameFromMessage(lastPartyDisbandedMessage)); + } + } + if (!Display.isActive()) { + sendNotification("BBsentials Party Notifier", "You got invited too a party by: " + getPlayerNameFromMessage(message)); + } + + } + else if (message.equals("Party > " + BBsentials.getConfig().getUsername() + ": rp")) { + sendCommand("/pl"); + repartyActive = true; + } + else if (message.startsWith("Party Members (")) { + Config.partyMembers = new ArrayList(); + } + else if (message.startsWith("Party Moderators:") && repartyActive) { + message = message.replace("Party Moderators:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); + if (message.contains(",")) { + for (int i = 0; i < message.split(",").length; i++) { + Config.partyMembers.add(message.split(",")[i - 1]); + } + } + else { + Config.partyMembers.add(message); + } + } + else if (message.startsWith("Party Members:")) { + message = message.replace("Party Members:", "").replace(" ●", "").replaceAll("\\s*\\[[^\\]]+\\]", "").trim(); + if (message.contains(",")) { + for (int i = 0; i < message.split(",").length; i++) { + System.out.println("Added to plist: " + (message.split(",")[i - 1])); + Config.partyMembers.add(message.split(",")[i - 1]); + } + } + else { + Config.partyMembers.add(message); + } + if (repartyActive) { + repartyActive = false; + sendCommand("/p disband"); + for (int i = 0; i < Integer.max(4, getConfig().getPlayersInParty().length); i++) { + if (i < getConfig().getPlayersInParty().length) { + sendCommand("/p invite " + getConfig().getPlayersInParty()[i]); + } + } + } + } + else if (message.endsWith("bb:party me") && message.startsWith("From ")) { + if (BBsentials.getConfig().allowBBinviteMe()) { + sendCommand("/p " + getPlayerNameFromMessage(message.replace("From ", ""))); + } + } + + } //Everything containing party is processed differently (split so fewer checks) + else if (message.contains("unlocked Wither Essence") && message.startsWith(getConfig().getUsername())) { + if (BBsentials.getConfig().isLeader()) { + repartyActive = true; + sendCommand("/pl"); + } + else { + System.out.println("No Reparty because not leader"); + } + if (getConfig().isLeaveDungeonAutomatically()) { + config.sender.addSendTask("/warp dhub", 3); + } + } + else if (message.contains("unlocked Crimson Essence") && message.startsWith(getConfig().getUsername())) { + if (BBsentials.getConfig().isLeader()) { + repartyActive = true; + sendCommand("/pl"); + } + else { + System.out.println("No Reparty because not leader"); + } + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + if (getConfig().isLeaveKuudraAutomatically()) { + sendCommand("/warp kuudra"); + } + } + else if (message.contains("bb:test")) { + sendPrivateMessageToSelf(test()); + } + else if ((message.endsWith("is visiting Your Garden !") || message.endsWith("is visiting Your Island !")) && !Display.isActive()) { + sendNotification("BBsentials Visit-Watcher", message); + } + else if (message.equals("Please type /report confirm to log your report for staff review.")) { + sendCommand("/report confirm"); + } + else if (message.contains(":") && !Display.isActive()) { + if (message.startsWith("Party >")) { + String partyMessage = message.replaceFirst("Party >", "").trim(); + messageOriginal = replaceAllForText(messageOriginal, "\"action\":\"run_command\",\"value\":\"/viewprofile", "\"action\":\"run_command\",\"value\":\"/hci menu pcm " + partyMessage); + if (partyMessage.split(":", 2)[1].toLowerCase().contains(getConfig().getUsername().toLowerCase()) || (partyMessage.toLowerCase().contains(getConfig().getNickname().toLowerCase() + " ") && getConfig().getNotifForParty().toLowerCase().equals("nick")) || getConfig().getNotifForParty().toLowerCase().equals("all")) { + sendNotification("BBsentials Party Chat Notification", partyMessage); + } + } + else if (message.startsWith("From ")) { + String sender = getPlayerNameFromMessage(message.replaceFirst("From", "").trim()); + String content = message.split(":", 2)[1]; + sendNotification("BBsentials Message Notifier", sender + " sent you the following message: " + content); + } + else if (message.toLowerCase().contains("party")) { + if ((message.contains("Party Leader:") && !message.contains(getConfig().getUsername())) || message.equals("You are not currently in a party.") || (message.contains("warped the party into a Skyblock Dungeon") && !message.startsWith(getConfig().getUsername()) || (!message.startsWith("The party was transferred to " + getConfig().getUsername()) && message.startsWith("The party was transferred to"))) || message.equals(getConfig().getUsername() + " is now a Party Moderator") || (message.equals("The party was disbanded because all invites expired and the party was empty.")) || (message.contains("You have joined ") && message.contains("'s party!")) || (message.contains("Party Leader, ") && message.contains(" , summoned you to their server.")) || (message.contains("warped to your dungeon"))) { + BBsentials.getConfig().setIsLeader(false); + if (getConfig().isDetailedDevModeEnabled()) { + sendPrivateMessageToSelf("Leader: " + getConfig().isLeader()); + } + } + if ((message.equals("Party Leader: " + getConfig().getUsername() + " ●")) || (message.contains(getConfig().getUsername() + " warped the party to a SkyBlock dungeon!")) || message.startsWith("The party was transferred to " + getConfig().getUsername()) || message.equals("Raul_J has promoted " + getConfig().getUsername() + " to Party Leader") || (message.contains("warped to your dungeon"))) { + BBsentials.getConfig().setIsLeader(true); + if (getConfig().isDetailedDevModeEnabled()) { + sendPrivateMessageToSelf("Leader: " + getConfig().isLeader()); + } + } + else if (repartyActive && !BBsentials.getConfig().isLeader()) { + repartyActive = false; + sendPrivateMessageToSelf("Resetted Reparty is Active since you are not leader "); + } + } + else { + String[] temp = message.split(":", 2); + String content = temp[temp.length - 1]; + if (temp.length == 2 && (content.toLowerCase().contains(getConfig().getUsername().toLowerCase()) || content.toLowerCase().contains(config.getNickname().toLowerCase() + " "))) { + sendNotification("BBsentials Notifier", "You got mentioned in chat! " + content); + } + } + } + else if (message.equals("You laid an Egg!")) { + Thread eggThread = new Thread(() -> { + try { + Thread.sleep(21000); // Wait for 21 seconds (in milliseconds) + sendPrivateMessageToSelf("Chicken Head is ready"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + eggThread.start(); + } + else if (message.contains("[OPEN MENU]") || message.contains("YES")) { + setChatPromtId(messageOriginal.toString()); + } + + } + return messageOriginal; + } + + //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""}// {"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile f772b2c7-bd2a-46e1-b1a2-41fa561157d6"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bShourtu§e's profile"}},"text":"§9Party §8> §b[MVP§c+§b] Shourtu§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"Hype_the_Time TEST"}],"text":""} + //{"strikethrough":false,"extra":[{"strikethrough":false,"clickEvent":{"action":"run_command","value":"/viewprofile 4fa1228c-8dd6-47c4-8fe3-b04b580311b8"},"hoverEvent":{"action":"show_text","contents":{"strikethrough":false,"text":"§eClick here to view §bHype_the_Time§e's profile"}},"text":"§9Party §8> §b[MVP§2+§b] Hype_the_Time§f: "},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"text":"h:test"}],"text":""} + private final Map partyDisbandedMap = new HashMap<>(); + private String lastPartyDisbandedMessage = null; + + public static String getPlayerNameFromMessage(String message) { + message = message.replaceAll("\\[.*?\\]", "").trim(); + message = message.replaceAll("-----------------------------------------------------", "").replaceAll(":", ""); + String[] temp = message.split(" "); + String playerName = ""; + + for (int i = 0; i < temp.length; i++) { + if (!temp[i].equals(" ") && !temp[i].equals("")) { + playerName = temp[i]; + break; // Stop looping after finding the first non-empty value + } + } + + // Remove the rank from the player name, if it exists + Pattern rankPattern = Pattern.compile("\\s*\\[[^\\]]+\\]"); + playerName = rankPattern.matcher(playerName).replaceAll(" "); + + return playerName; + } + + public String extractPlainText(String input) { + String returns = ""; + String[] literals = input.split("literal\\{"); + if (!input.startsWith("literal")) { + literals[0] = ""; + } + for (int i = 0; i < literals.length; i++) { + if (dontExclude(literals, i) && !literals[i].equals("")) { + String literal = literals[i].split("}")[0]; + + if (!literal.isEmpty()) { + returns = returns + literal; + } + } + } + // Remove § formatting + returns = returns.replaceAll("§.", ""); + // Remove brackets that contain only uppercase letters or pluses + returns = returns.replaceAll("\\[[A-Z+]+\\]", ""); + returns = returns.replaceAll("\\[[0-9]+\\]", ""); + returns = returns.trim(); + returns = returns.replaceAll("\\s+", " "); + + return returns; + } + + private boolean dontExclude(String[] s, int i) { + if ((i - 1) < 0) { + return true; + } + else { + if (s[i - 1].endsWith("value='")) { + return false; + } + else { + return true; + } + } + } + + public boolean isSpam(String message) { + if (message.contains("Mana")) return true; + if (message.contains("Achievement Points")) return true; + return false; + } + + private boolean repartyActive = false; + + public String test() { + //put test code here + sendNotification("test", "This is an example which was run of the h:test test"); + return new String(); + } + + private static String removeMultipleSpaces(String input) { + return input.replaceAll("\\s+", " "); + } + + public static void sendPrivateMessageToSelf(String message) { + if (Minecraft.getMinecraft().thePlayer != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + message)); + } + } + + public static void sendPrivateMessageToSelfText(net.minecraft.util.IChatComponent message) { + if (Minecraft.getMinecraft().thePlayer != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(message); + } + } + + public static void sendCommand(String s) { + getConfig().sender.addSendTask(s); + } + + public void sendNotification(String title, String text) { + Thread soundThread = new Thread(() -> { + try { + InputStream inputStream = getClass().getResourceAsStream("/sounds/mixkit-sci-fi-confirmation-914.wav"); + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream); + Clip clip = AudioSystem.getClip(); + clip.open(audioInputStream); + clip.start(); + Thread.sleep(clip.getMicrosecondLength() / 1000); + clip.close(); + audioInputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + + soundThread.start(); + + List argsList = new ArrayList<>(); + argsList.add("--title"); + argsList.add(title); + argsList.add("--passivepopup"); + argsList.add(text); + argsList.add("5"); + + try { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("kdialog"); + processBuilder.command().addAll(argsList); + + Process process = processBuilder.start(); + process.waitFor(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + public static net.minecraft.util.IChatComponent createClientSideTellraw(String tellrawInput) { + net.minecraft.util.IChatComponent formattedMessage = null; + try { + formattedMessage = net.minecraft.util.IChatComponent.Serializer.jsonToComponent(tellrawInput); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Invalid Json: \n" + tellrawInput); + } + return formattedMessage; + } + + public static void followMenu(String menu, String message) { + // Check the "menu" argument and execute the appropriate logic + String command; + String username = getPlayerNameFromMessage(message); + if (message.contains(":")) { + message = message.split(":", 2)[1].trim(); + if (menu.equalsIgnoreCase("pcm")) { + command = "[\"\",{\"text\":\"@@username\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/pc @username\"}},{\"text\":\" [Copy_Message]\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"Copy-Text-Message\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Copy the message the Player send without their name into the clipboard.\"]}},{\"text\":\" [Kick_Player]\",\"color\":\"dark_red\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p kick @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Kick the player from the party\"]}},{\"text\":\" [Promote_Player]\",\"color\":\"dark_green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p promote @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Promote the player\"]}},{\"text\":\" [Demote_Player]\",\"color\":\"red\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p demote @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Demote the player\"]}},{\"text\":\" [Transfer_to_Player]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p transfer @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Transfer the Party to the player\"]}},{\"text\":\" [Mute/Unmute_Party]\",\"color\":\"dark_aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p mute @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Mutes the ENTIRE party but party moderators or Hypixel Staff can still type.\"]}}]"; + //{"jformat":8,"jobject":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"gray","insertion":"","click_event_type":"suggest_command","click_event_value":"/pc @username","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"@username"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"blue","insertion":"","click_event_type":"copy_to_clipboard","click_event_value":"Copy-Text-Message","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Copy the message the Player send without their name into the clipboard."}],"text":" [Copy_Message]"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"dark_red","insertion":"","click_event_type":"run_command","click_event_value":"/p kick @username","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Kick the player from the party"}],"text":" [Kick_Player]"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"dark_green","insertion":"","click_event_type":"run_command","click_event_value":"/p promote @username","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Promote the player"}],"text":" [Promote_Player]"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"red","insertion":"","click_event_type":"run_command","click_event_value":"/p demote @username","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Demote the player"}],"text":" [Demote_Player]"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"gold","insertion":"","click_event_type":"run_command","click_event_value":"/p transfer @username","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Transfer the Party to the player"}],"text":" [Transfer_to_Player]"},{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"dark_aqua","insertion":"","click_event_type":"run_command","click_event_value":"/p mute @username","hover_event_type":"show_text","hover_event_value":"","hover_event_object":{},"hover_event_children":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"font":null,"color":"none","insertion":"","click_event_type":"none","click_event_value":"","hover_event_type":"none","hover_event_value":"","hover_event_object":{},"hover_event_children":[],"text":"Mutes the ENTIRE party but party moderators or Hypixel Staff can still type."}],"text":" [Mute/Unmute_Party]"}],"command":"%s","jtemplate":"tellraw"} + } + else if (menu.equalsIgnoreCase("sbacm")) { + command = "[\"\",\"\\n\",{\"text\":\"@@username\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"@username\"}},{\"text\":\" [Party_Player]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p invite @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Invite the player to the party\"]}},{\"text\":\" [Ignore_Player]\",\"color\":\"yellow\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/ignore add @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Add the player to your ignore list.\"]}},{\"text\":\" [Chat_Report_Player]\",\"color\":\"dark_red\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/creport @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Chat report the user with /creport.\"]}},{\"text\":\" [Visit_Player]\",\"color\":\"dark_green\",\"insertion\":\" \",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/visit @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[]}},{\"text\":\" [/Invite_Player]\",\"color\":\"green\",\"insertion\":\" \",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/invite @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"/invite the player to visit your Island / Garden.\"]}},{\"text\":\" [Copy_Message] \",\"color\":\"blue\",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"Copy-Text-Message\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Copy the message the user send without their prefixes nor their username\"]}},{\"text\":\" [Copy_Username]\",\"color\":\"dark_aqua\",\"insertion\":\" \",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"@username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Copy the players username into the clipboard.\"]}},{\"text\":\" [/msg_Chat_Player]\",\"color\":\"light_purple\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/msg @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"/msg the Player. the chat will be set to message them. This means you do not need to type /msg upfront. To return to normal do /chat a\"]}},{\"text\":\" [Sky_shiiyu_player]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://sky.shiiyu.moe/stats/@username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Opens the players Skyblock Profile in Sky Crypt (sky.shiiyu.moe)\"]}},\"\\n\"]"; + } + else if (menu.equalsIgnoreCase("acm")) { + command = "[\"\",\"\\n\",{\"text\":\"@@username\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"@username\"}},{\"text\":\" [Party_Player]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/p invite @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Invite the player to the party\"]}},{\"text\":\" [Ignore_Player]\",\"color\":\"yellow\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/ignore add @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Add the player to your ignore list.\"]}},{\"text\":\" [Chat_Report_Player]\",\"color\":\"dark_red\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/creport @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Chat report the user with /creport.\"]}},{\"text\":\" [Copy_Message] \",\"color\":\"blue\",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"Copy-Text-Message\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Copy the message the user send without their prefixes nor their username\"]}},{\"text\":\" [Copy_Username]\",\"color\":\"dark_aqua\",\"insertion\":\" \",\"clickEvent\":{\"action\":\"copy_to_clipboard\",\"value\":\"@username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"Copy the players username into the clipboard.\"]}},{\"text\":\" [/msg_Chat_Player]\",\"color\":\"light_purple\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/msg @username\"},\"hoverEvent\":{\"action\":\"show_text\",\"contents\":[\"/msg the Player. the chat will be set to message them. This means you do not need to type /msg upfront. To return to normal do /chat a\"]}}"; + } + else { + // Handle unrecognized menu argument + sendPrivateMessageToSelf(EnumChatFormatting.RED + "Unrecognized menu argument! Do not use this command unless you know exactly what you are doing aka only use it as a developer!"); + return; + } + command = command.replaceAll("@username", username); + command = command.replaceAll("Copy-Text-Message", message); + sendPrivateMessageToSelfText(createClientSideTellraw(command)); + } + else { + sendPrivateMessageToSelf("Invalid message!: " + message); + } + } + + public static void setChatPromtId(String logMessage) { + String cbUUIDPattern = "/cb ([a-fA-F0-9-]+)"; + Pattern cbPattern = Pattern.compile(cbUUIDPattern); + Matcher cbMatcher = cbPattern.matcher(logMessage); + + String yesClickAction = "/chatprompt ([a-fA-F0-9-]+) YES"; + Pattern yesPattern = Pattern.compile(yesClickAction); + Matcher yesMatcher = yesPattern.matcher(logMessage); + String lastPrompt = null; + if (cbMatcher.find()) { + lastPrompt = cbMatcher.group(1); + String finalLastPrompt1 = lastPrompt; + new Thread(new Runnable() { + @Override + public void run() { + BBsentials.getConfig().setLastChatPromptAnswer("/cb " + finalLastPrompt1); + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + BBsentials.getConfig().setLastChatPromptAnswer(null); + return; + } + }).start(); + } + if (yesMatcher.find()) { + lastPrompt = yesMatcher.group(1); + String finalLastPrompt = lastPrompt; + new Thread(new Runnable() { + @Override + public void run() { + BBsentials.getConfig().setLastChatPromptAnswer("/chatprompt " + finalLastPrompt + " YES"); + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + BBsentials.getConfig().setLastChatPromptAnswer(null); + return; + } + }).start(); + + } + } + + public static net.minecraft.util.IChatComponent replaceAllForText(net.minecraft.util.IChatComponent input, String replace, String replaceWith) { + String text = net.minecraft.util.IChatComponent.Serializer.componentToJson(input); + if (text.contains(replace)) { + text = text.replaceAll("\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", ""); + } + text = text.replace(replace, replaceWith); + net.minecraft.util.IChatComponent output = net.minecraft.util.IChatComponent.Serializer.jsonToComponent(text); + return output; + } +} \ No newline at end of file diff --git a/forge/src/main/java/de/hype/bbsentials/forge/chat/Sender.java b/forge/src/main/java/de/hype/bbsentials/forge/chat/Sender.java new file mode 100644 index 0000000..15cd3d7 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/chat/Sender.java @@ -0,0 +1,100 @@ +package de.hype.bbsentials.forge.chat; + +import com.mojang.realmsclient.gui.ChatFormatting; +import net.minecraft.client.Minecraft; + +import java.util.ArrayList; +import java.util.List; + +public class Sender { + private final List sendQueue; + private final List sendQueueTiming; + private final List hidden; + + public Sender() { + this.sendQueue = new ArrayList<>(); + this.sendQueueTiming = new ArrayList<>(); + this.hidden = new ArrayList<>(); + startSendingThread(); + } + + public void addSendTask(String task, double timing) { + synchronized (sendQueue) { + Chat.sendPrivateMessageToSelf(ChatFormatting.GREEN + "Scheduled send-task (as " + sendQueueTiming.size() + " in line): " + task + " | Delay: " + timing); + sendQueueTiming.add(timing); + sendQueue.add(task); + hidden.add(false); + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addHiddenSendTask(String task, double timing) { + synchronized (sendQueue) { + sendQueueTiming.add(timing); + sendQueue.add(task); + hidden.add(true); + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addImmediateSendTask(String task) { + synchronized (sendQueue) { + sendQueueTiming.add(0, 0.0); + sendQueue.add(0, task); + hidden.add(false); + sendQueue.notify(); // Notify the waiting thread that a new String has been added + } + } + + public void addSendTask(String task) { + addSendTask(task, 1); + } + + public void startSendingThread() { + Thread sendingThread = new Thread(new SendingRunnable()); + sendingThread.start(); + } + + private class SendingRunnable implements Runnable { + @Override + public void run() { + while (true) { + String task = getNextTask(); + if (task != null) { + send(task, sendQueueTiming.remove(0), hidden.remove(0)); + } + else { + synchronized (sendQueue) { + try { + sendQueue.wait(); // Wait for new Send + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } + } + + private String getNextTask() { + synchronized (sendQueue) { + if (!sendQueue.isEmpty()) { + return sendQueue.remove(0); + } + return null; + } + } + + private void send(String toSend, double timing, boolean hidden) { + try { + Thread.sleep((long) (timing * 1000)); // Simulate the send operation + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + Minecraft.getMinecraft().thePlayer.sendChatMessage(toSend); + if (!hidden) { + Chat.sendPrivateMessageToSelf("Sent Command to Server: " + toSend); + } + + } + } +} \ No newline at end of file diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/BBsentials.java b/forge/src/main/java/de/hype/bbsentials/forge/client/BBsentials.java new file mode 100644 index 0000000..87dc13b --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/BBsentials.java @@ -0,0 +1,42 @@ +package de.hype.bbsentials.forge.client; + +import de.hype.bbsentials.forge.chat.Chat; +import de.hype.bbsentials.forge.client.Commands.CommandsOLD; +import de.hype.bbsentials.forge.communication.BBsentialConnection; + + +public class BBsentials { + private boolean initialised = false; + public static Config config; + public static BBsentialConnection bbserver; + public static CommandsOLD coms; + + public void init() { + if (!initialised) { + config = Config.load(); + Chat chat = new Chat(); + if (Config.isBingoTime() || config.overrideBingoTime()) { + connectToBBserver(); + } + initialised = true; + } + } + + public static Config getConfig() { + return config; + } + + public static void connectToBBserver() { + if (bbserver != null) { + bbserver.sendHiddenMessage("exit"); + } + bbserver = new BBsentialConnection(); + bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message)); + bbserver.connect(config.getBBServerURL(), 5000); + } + + public static void refreshCommands() { + coms = new CommandsOLD(); + } + +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/CommandBBI.java b/forge/src/main/java/de/hype/bbsentials/forge/client/CommandBBI.java new file mode 100644 index 0000000..352a7b6 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/CommandBBI.java @@ -0,0 +1,87 @@ +package de.hype.bbsentials.forge.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +import static de.hype.bbsentials.forge.client.BBsentials.connectToBBserver; +import static de.hype.bbsentials.forge.client.BBsentials.getConfig; + + +public class CommandBBI extends CommandBase { + + @Override + public String getCommandName() { + return "bbi"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/bbi "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length == 0) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bbi ")); + return; + } + + String subCommand = args[0]; + switch (subCommand) { + case "reconnect": + connectToBBserver(); + break; + + case "config": + if (args.length < 2) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bbi config ")); + return; + } + + String category = args[1]; + switch (category) { + case "save": + getConfig().save(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Saved config successfully")); + break; + + case "load": + BBsentials.config = Config.load(); + break; + + default: + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Unknown category: " + category)); + break; + } + break; + + case "set-key": + if (args.length < 4) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bbi set-key set-server ")); + return; + } + + String key = args[1]; + if (args[2].equalsIgnoreCase("set-server")) { + String value = args[3]; + // Handle setting the key and value logic here for server + } + else { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bbi set-key set-server ")); + } + break; + + default: + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Unknown command: " + subCommand)); + break; + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/Command2xPowder.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/Command2xPowder.java new file mode 100644 index 0000000..8044991 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/Command2xPowder.java @@ -0,0 +1,29 @@ +package de.hype.bbsentials.forge.client.Commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class Command2xPowder extends CommandBase { + + @Override + public String getCommandName() { + return "2xpowder"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/2xpowder"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + bbserver.sendMessage("?dwevent 2xpowder"); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBAnnounce.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBAnnounce.java new file mode 100644 index 0000000..3d2afb7 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBAnnounce.java @@ -0,0 +1,36 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBAnnounce extends CommandBase { + + @Override + public String getCommandName() { + return "bannounce"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName() + " "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length >= 1) { + String message = String.join(" ", args); + Chat.sendCommand("?announce " + message); + } + else { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: " + getCommandUsage(sender))); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBServer.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBServer.java new file mode 100644 index 0000000..3254d1c --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBServer.java @@ -0,0 +1,41 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.client.BBsentials; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBBServer extends CommandBase { + + @Override + public String getCommandName() { + return "bbserver"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/bbserver "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length < 1) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bbserver ")); + return; + } + + String message = args[0]; + if (message.equals("bb:reconnect")) { + BBsentials.connectToBBserver(); + } + else { + BBsentials.bbserver.sendMessage(message); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBan.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBan.java new file mode 100644 index 0000000..15d99b7 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBBan.java @@ -0,0 +1,36 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBBan extends CommandBase { + + @Override + public String getCommandName() { + return "bban"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName() + " "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length >= 1) { + String message = String.join(" ", args); + Chat.sendCommand("?bban " + message); + } + else { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: " + getCommandUsage(sender))); + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBC.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBC.java new file mode 100644 index 0000000..0b46507 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBC.java @@ -0,0 +1,36 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBC extends CommandBase { + + @Override + public String getCommandName() { + return "bc"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/bc "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length < 1) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bc ")); + return; + } + + String message = args[0]; + Chat.sendCommand("?bingochat " + message); + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBMute.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBMute.java new file mode 100644 index 0000000..3fd6390 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBMute.java @@ -0,0 +1,35 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBMute extends CommandBase { + + @Override + public String getCommandName() { + return "bmute"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName() + " "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length >= 1) { + String message = String.join(" ", args); + Chat.sendCommand("?mute " + message); + } + else { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: " + getCommandUsage(sender))); + } + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBetterTogether.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBetterTogether.java new file mode 100644 index 0000000..78f20f8 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBetterTogether.java @@ -0,0 +1,29 @@ +package de.hype.bbsentials.forge.client.Commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class CommandBetterTogether extends CommandBase { + + @Override + public String getCommandName() { + return "bettertogether"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/bettertogether"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + bbserver.sendMessage("?dwevent bettertogether"); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBingoChat.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBingoChat.java new file mode 100644 index 0000000..655cfdb --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandBingoChat.java @@ -0,0 +1,35 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +public class CommandBingoChat extends CommandBase { + + @Override + public String getCommandName() { + return "bingochat"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/bingochat "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length < 1) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /bingochat ")); + return; + } + + String message = args[0]; + Chat.sendCommand("?bingochat " + message); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandChChest.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandChChest.java new file mode 100644 index 0000000..daaa1f3 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandChChest.java @@ -0,0 +1,48 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class CommandChChest extends CommandBase { + + @Override + public String getCommandName() { + return "chchest"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/chchest "; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length < 5) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /chchest ")); + return; + } + + String item = args[0]; + try { + int x = parseInt(args[1]); + int y = parseInt(args[2]); + int z = parseInt(args[3]); + String contactWay = args[4]; + + String combinedString = "?chchest " + item + " " + x + " " + y + " " + z + " " + contactWay; + bbserver.sendMessage(combinedString); + } catch (Exception e) { + Chat.sendPrivateMessageToSelf("§cYour coords were invalid."); + } + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoblinRaid.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoblinRaid.java new file mode 100644 index 0000000..bb7d276 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoblinRaid.java @@ -0,0 +1,29 @@ +package de.hype.bbsentials.forge.client.Commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class CommandGoblinRaid extends CommandBase { + + @Override + public String getCommandName() { + return "goblinraid"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/goblinraid"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + bbserver.sendMessage("?dwevent goblinraid"); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoneWithTheWind.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoneWithTheWind.java new file mode 100644 index 0000000..602e422 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandGoneWithTheWind.java @@ -0,0 +1,29 @@ +package de.hype.bbsentials.forge.client.Commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class CommandGoneWithTheWind extends CommandBase { + + @Override + public String getCommandName() { + return "gonewiththewind"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/gonewiththewind"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + bbserver.sendMessage("?dwevent gonewiththewind"); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandRaffle.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandRaffle.java new file mode 100644 index 0000000..235c538 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandRaffle.java @@ -0,0 +1,29 @@ +package de.hype.bbsentials.forge.client.Commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import static de.hype.bbsentials.forge.client.BBsentials.bbserver; + + +public class CommandRaffle extends CommandBase { + + @Override + public String getCommandName() { + return "raffle"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/raffle"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + bbserver.sendMessage("?dwevent raffle"); + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandSplashAnnounce.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandSplashAnnounce.java new file mode 100644 index 0000000..041d0fc --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandSplashAnnounce.java @@ -0,0 +1,50 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.chat.Chat; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.NumberInvalidException; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +import java.util.Arrays; + +public class CommandSplashAnnounce extends CommandBase { + + @Override + public String getCommandName() { + return "splashAnnounce"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName() + " [extramessage]"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (args.length >= 2) { + int hub_Number = 0; + try { + hub_Number = parseInt(args[0], 1, 28); + } catch (NumberInvalidException e) { + Chat.sendPrivateMessageToSelf("§cInvalid hub number"); + } + String location = args[1]; + String message = ""; + + if (args.length > 2) { + message = String.join(" ", Arrays.copyOfRange(args, 2, args.length)); + } + + Chat.sendCommand("?splash " + hub_Number + " " + location + " " + message); + } + else { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: " + getCommandUsage(sender))); + } + } + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandsOLD.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandsOLD.java new file mode 100644 index 0000000..804815c --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Commands/CommandsOLD.java @@ -0,0 +1,38 @@ +package de.hype.bbsentials.forge.client.Commands; + +import de.hype.bbsentials.forge.client.BBsentials; +import net.minecraftforge.client.ClientCommandHandler; + +import static de.hype.bbsentials.forge.client.BBsentials.getConfig; + + +public class CommandsOLD { + public CommandsOLD() { + ClientCommandHandler.instance.registerCommand(new CommandGoblinRaid()); + ClientCommandHandler.instance.registerCommand(new Command2xPowder()); + ClientCommandHandler.instance.registerCommand(new CommandBetterTogether()); + ClientCommandHandler.instance.registerCommand(new CommandRaffle()); + ClientCommandHandler.instance.registerCommand(new CommandGoneWithTheWind()); + ClientCommandHandler.instance.registerCommand(new CommandChChest()); + ClientCommandHandler.instance.registerCommand(new CommandBBServer()); + ClientCommandHandler.instance.registerCommand(new CommandBC()); + ClientCommandHandler.instance.registerCommand(new CommandBingoChat()); + if (getConfig().bbsentialsRoles != null) { + if (getConfig().bbsentialsRoles.contains("mod")) { + ClientCommandHandler.instance.registerCommand(new CommandBAnnounce()); + ClientCommandHandler.instance.registerCommand(new CommandBMute()); + ClientCommandHandler.instance.registerCommand(new CommandBBan()); + } + if (getConfig().bbsentialsRoles.contains("splasher")) { + ClientCommandHandler.instance.registerCommand(new CommandSplashAnnounce()); + } + else { + } + } + } + + public void sendCommand(String message) { + BBsentials.bbserver.sendCommand(message); + } +} + diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/Config.java b/forge/src/main/java/de/hype/bbsentials/forge/client/Config.java new file mode 100644 index 0000000..f4fff7e --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/Config.java @@ -0,0 +1,198 @@ +//Keep in mind that a lot of the stuff in here may never be used and is here because its copied from the 1.20 version which is the main part of the code. + +package de.hype.bbsentials.forge.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import de.hype.bbsentials.forge.chat.Chat; +import de.hype.bbsentials.forge.chat.Sender; +import net.minecraft.client.Minecraft; + +import java.io.*; +import java.time.LocalDate; +import java.util.ArrayList; + +public class Config implements Serializable { + // Helper class for sending chat messages + public transient final Sender sender = new Sender(); + + public transient boolean highlightitem = false; + public transient String lastChatPromptAnswer = null; + + // Automatically set, no need for config + private transient String username; + private boolean overrideBingoTime = false; + + // Set in-game + private transient boolean isLeader; + private transient String alreadyReported = ""; + private String bbServerURL = "static.204.177.34.188.clients.your-server.de"; + public String bbsentialsRoles = ""; + public static ArrayList partyMembers = new ArrayList<>(); + + // Set via load / default + private String bbsentialsCommandPrefix = "."; + private String apiKey = ""; + private boolean leaveDungeonAutomatically; + private boolean allowBBinviteMe = true; + private boolean leaveKuudraAutomatically; + private boolean devMode = false; + private boolean detailedDevMode = false; + private boolean acceptReparty; + private String nickname; + private String getNotifForParty; + + // Set default attribute values + private void setDefaults() { + username = Minecraft.getMinecraft().thePlayer.getName(); + leaveKuudraAutomatically = true; + leaveDungeonAutomatically = true; + acceptReparty = true; + if (username.equals("Hype_the_Time")) { + nickname = "hype"; + getNotifForParty = "nick"; + } + else { + nickname = ""; + getNotifForParty = "none"; + } + } + // Gson object for serialization + private final transient Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + // File object for storing the config + private final transient File CONFIG_FILE = new File("./config/BBsential_settings.json"); + + // Constructor + public Config() { + setDefaults(); + } + + // Load the config from file + public static Config load() { + Config settings; + File CONFIG_FILE = new File("./config/BBsential_settings.json"); + Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + if (CONFIG_FILE.exists()) { + try (FileReader reader = new FileReader(CONFIG_FILE)) { + settings = GSON.fromJson(reader, Config.class); + } catch (IOException e) { + e.printStackTrace(); + settings = new Config(); // Use default values if loading fails + } + } + else { + settings = new Config(); // Use default values if the file doesn't exist + } + if (!settings.bbsentialsRoles.contains("dev")) { + settings.detailedDevMode = false; + settings.devMode = false; + } + settings.save(); + return settings; + } + + // Save the config to file + public void save() { + try (FileWriter writer = new FileWriter(CONFIG_FILE)) { + GSON.toJson(this, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Getter methods for various config attributes + public String getUsername() { + return username; + } + + public boolean isLeader() { + return isLeader; + } + + public void setIsLeader(boolean value) { + isLeader = value; + } + + public String getNickname() { + return nickname; + } + + public String getNotifForParty() { + return getNotifForParty; + } + + public boolean isLeaveDungeonAutomatically() { + return leaveDungeonAutomatically; + } + + public boolean isLeaveKuudraAutomatically() { + return leaveKuudraAutomatically; + } + + public boolean isDevModeEnabled() { + return devMode; + } + + public boolean isDetailedDevModeEnabled() { + return detailedDevMode; + } + + public String[] getPlayersInParty() { + return partyMembers.toArray(new String[0]); + } + + public boolean messageFromAlreadyReported(String message) { + return alreadyReported.contains(Chat.getPlayerNameFromMessage(message)); + } + + public void addReported(String playerName) { + alreadyReported = alreadyReported + " , " + playerName; + } + + public String getApiKey() { + return apiKey; + } + + public String getBBServerURL() { + return bbServerURL; + } + + public String getCommandPrefix(String type) { + if (type.equals("BBsentials")) { + System.out.println("Registered command with: " + bbsentialsCommandPrefix); + return bbsentialsCommandPrefix; + } + else { + return "/"; + } + } + + public static boolean isBingoTime() { + LocalDate currentDate = LocalDate.now(); + LocalDate lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth()); + LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1); + Boolean isBefore = currentDate.isAfter(lastDayOfMonth.minusDays(4)); + Boolean isInRange = currentDate.isBefore(firstDayOfMonth.plusDays(15)); + return isBefore || isInRange; + } + + public boolean overrideBingoTime() { + return overrideBingoTime; + } + + public boolean isHighlightitem() { + return highlightitem; + } + + public String getLastChatPromptAnswer() { + return lastChatPromptAnswer; + } + + public boolean allowBBinviteMe() { + return allowBBinviteMe; + } + + public void setLastChatPromptAnswer(String lastChatPromptAnswer) { + this.lastChatPromptAnswer = lastChatPromptAnswer; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/communication/BBsentialConnection.java b/forge/src/main/java/de/hype/bbsentials/forge/communication/BBsentialConnection.java new file mode 100644 index 0000000..94ab673 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/communication/BBsentialConnection.java @@ -0,0 +1,341 @@ +package de.hype.bbsentials.forge.communication; + +import de.hype.bbsentials.forge.chat.Chat; +import de.hype.bbsentials.forge.client.BBsentials; +import net.minecraft.client.Minecraft; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +import javax.net.ssl.*; +import java.io.*; +import java.net.Socket; +import java.net.SocketException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class BBsentialConnection { + private Socket socket; + private BufferedReader reader; + private PrintWriter writer; + private LinkedBlockingQueue messageQueue; + private MessageReceivedCallback messageReceivedCallback; + private ScheduledExecutorService executorService; + private String itemName = "Hub #0"; + + public interface MessageReceivedCallback { + void onMessageReceived(String message); + } + + public void connect(String serverIP, int serverPort) { + // Enable SSL handshake debugging + System.setProperty("javax.net.debug", "ssl,handshake"); + FileInputStream inputStream = null; + try { + // Load the BBssentials-online server's public certificate from the JKS file + try { + InputStream resouceInputStream = BBsentials.class.getResourceAsStream("/assets/public_bbsentials_cert.crt"); + + // Check if the resource exists + if (resouceInputStream == null) { + System.out.println("The resource '/assets/public_bbsentials_cert.crt' was not found."); + return; + } + + File tempFile = File.createTempFile("public_bbsentials_cert", ".crt"); + tempFile.deleteOnExit(); + + FileOutputStream outputStream = new FileOutputStream(tempFile); + + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = resouceInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + outputStream.close(); + resouceInputStream.close(); + + // Now you have the .crt file as a FileInputStream in the tempFile + inputStream = new FileInputStream(tempFile); + + // Use the fileInputStream as needed + + } catch (IOException e) { + e.printStackTrace(); + } + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + X509Certificate serverCertificate = (X509Certificate) certFactory.generateCertificate(inputStream); + PublicKey serverPublicKey = serverCertificate.getPublicKey(); + + // Create a TrustManager that trusts only the server's public key + TrustManager[] trustManagers = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; // We don't need to check the client's certificates + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { + // Do nothing, client certificate validation not required + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { + // Check if the server certificate matches the expected one + if (certs.length == 1) { + PublicKey publicKey = certs[0].getPublicKey(); + if (!publicKey.equals(serverPublicKey)) { + throw new CertificateException("Server certificate not trusted."); + } + } + else { + throw new CertificateException("Invalid server certificate chain."); + } + } + } + }; + + // Create an SSL context with the custom TrustManager + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustManagers, new SecureRandom()); + + // Create an SSL socket factory + SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + socket = (SSLSocket) sslSocketFactory.createSocket(serverIP, serverPort); + + socket.setKeepAlive(true); // Enable Keep-Alive + + reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + writer = new PrintWriter(socket.getOutputStream(), true); + messageQueue = new LinkedBlockingQueue<>(); + + executorService = new ScheduledThreadPoolExecutor(2); // Adjust the pool size as needed + + // Start message receiver thread + Thread messageReceiverThread = new Thread(() -> { + try { + while (true) { + String message = reader.readLine(); + if (message != null) { + if (messageReceivedCallback != null) { + messageReceivedCallback.onMessageReceived(message); + } + else { + Chat.sendPrivateMessageToSelf("BB: It seemed like you disconnected. Reconnecting..."); + BBsentials.connectToBBserver(); + try { + Thread.sleep(1000 * 10); + } catch (Exception ignored) { + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + }); + messageReceiverThread.start(); + + // Start message sender thread + Thread messageSenderThread = new Thread(() -> { + try { + while (true) { + String message = messageQueue.take(); + writer.println(message); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + messageSenderThread.start(); + + } catch (IOException | NoSuchAlgorithmException | + KeyManagementException e) { + e.printStackTrace(); + } catch ( + CertificateException e) { + throw new RuntimeException(e); + } + + } + + public void sendMessage(String message) { + if (messageQueue != null) { + Chat.sendPrivateMessageToSelf("§aBBs: " + message); + messageQueue.offer(message); + } + else { + Chat.sendPrivateMessageToSelf("§4BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect"); + } + } + + public void sendHiddenMessage(String message) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelf("BBDev-s: " + message); + } + if (messageQueue != null) { + writer.println(message); + } + } + + public void sendCommand(String message) { + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelf("BBDev-s: " + message); + } + if (messageQueue != 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) { + if (message.startsWith("H-")) { + if (message.equals("H-BB-Login: ")) { + Chat.sendPrivateMessageToSelf("§aLogging into BBsentials-online"); + sendHiddenMessage(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + writer.println(BBsentials.getConfig().getApiKey()); + sendHiddenMessage("?getperms"); + } + else if (message.contains("H-potdurations?")) { + sendHiddenMessage("?potduration " + getPotTime()); + } + else if (message.startsWith("H-splash")) { + String[] arguments = message.split(" ", 7); + int min = (1 * 60 * 60) - Integer.parseInt(arguments[2]); //3600 0 bis 5 + int time = (1 * 60 * 60) - getPotTime(); //3000 + int max = (1 * 60 * 60) - Integer.parseInt(arguments[3]); //3300 + if ((time <= min) && (time >= max)) { + if (arguments.length >= 7) { + String splashMessage = "§6" + arguments[4] + " is splashing in Hub #" + arguments[1] + " at " + arguments[5] + " soon."; + splashMessage = splashMessage + " : " + arguments[6]; + Chat.sendPrivateMessageToSelf(splashMessage); + splashHighlightItem("Hub #" + arguments[1], 30000); + } + } + } + else if (message.startsWith("H-roles")) { + BBsentials.getConfig().bbsentialsRoles = message.replace("H-Roles ", ""); + BBsentials.refreshCommands(); + } + else if (message.startsWith("H-chchest")) { + String[] arguments = message.replace("H-chchest", "").trim().split(" ", 6); // Split with limit of 5 + String username = arguments[0]; + String item = arguments[1]; + int x = Integer.parseInt(arguments[2]); + int y = Integer.parseInt(arguments[3]); + int z = Integer.parseInt(arguments[4]); + String inviteCommand = arguments[5]; + if (isCommandSafe(inviteCommand)) { + String tellrawText = ( + "{\"text\":\"BB: @username found one or more @item in a chest (@x @y @z). Click here to join\",\"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", username).replace("@item", item).replace("@x", x + "").replace("@y", y + "").replace("@z", z + "").replace("@inviteCommand", inviteCommand); + Chat.sendPrivateMessageToSelfText(Chat.createClientSideTellraw(tellrawText)); + } + } + else if (message.startsWith("H-event")) { + String[] arguments = message.replace("H-event", "").trim().split(" "); + Chat.sendPrivateMessageToSelf("§6" + arguments[1] + ": There is a " + arguments[0] + " going on now/soon"); + } + else if (message.startsWith("H-reconnect")) { + Chat.sendPrivateMessageToSelf("§4BBserver-online is going to restart soon. You will be automatically reconnected.\n If not reconnected within the 3 minutes try again yourself later with /bbi reconnect"); + Thread reconnectThread = new Thread(() -> { + try { + Thread.sleep((long) ((30 * 1000) + (Math.random() * 30 * 1000))); + } catch (InterruptedException e) { + e.printStackTrace(); + } + BBsentials.connectToBBserver(); + if (!socket.isConnected()) { + try { + Thread.sleep((long) ((30 * 1000) + (Math.random() * 30 * 1000))); + } catch (InterruptedException e) { + e.printStackTrace(); + } + BBsentials.connectToBBserver(); + } + }); + reconnectThread.start(); + } + else if (message.startsWith("H-hype")) { + String[] arguments = message.replace("H-hype", "").trim().split(" "); + if (arguments[0].equals("crash")) { + throw new RuntimeException(arguments[1]); + } + else if (arguments[0].equals("hub")) { +//TODO BBsentials.config.sender.addHiddenSendTask("/hub", 1); + } + } + if (BBsentials.getConfig().isDetailedDevModeEnabled()) { + Chat.sendPrivateMessageToSelf("BBDev-r: " + message); + } + } + else { + Chat.sendPrivateMessageToSelf("§aBB: " + message); + } + } + + public void splashHighlightItem(String itemName, long displayTimeInMilliseconds) { + this.itemName = itemName; + BBsentials.config.highlightitem = true; + executorService.schedule(() -> { + BBsentials.config.highlightitem = false; + try { + socket.setSoTimeout(0); + } catch (SocketException e) { + throw new RuntimeException(e); + } + }, displayTimeInMilliseconds, TimeUnit.MILLISECONDS); + } + + public String getItemName() { + return itemName; + } + + public static int getPotTime() { + int remainingTimeInMinutes = 0; + PotionEffect potTimeRequest = Minecraft.getMinecraft().thePlayer.getActivePotionEffect(Potion.damageBoost); + if (potTimeRequest != null) { + if (potTimeRequest.getAmplifier() >= 7) { + remainingTimeInMinutes = (int) (potTimeRequest.getDuration() / 20.0); + } + } + return remainingTimeInMinutes; + } + + 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; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinGuiMainMenu.java b/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinGuiMainMenu.java new file mode 100644 index 0000000..2b0c0b0 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinGuiMainMenu.java @@ -0,0 +1,16 @@ +package de.hype.bbsentials.forge.mixin; + +import net.minecraft.client.gui.GuiMainMenu; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GuiMainMenu.class) +public class MixinGuiMainMenu { + + @Inject(method = "initGui", at = @At("HEAD")) + public void onInitGui(CallbackInfo ci) { + + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinRenderItem.java b/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinRenderItem.java new file mode 100644 index 0000000..3675f3f --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/mixin/MixinRenderItem.java @@ -0,0 +1,30 @@ +package de.hype.bbsentials.forge.mixin; + +import de.hype.bbsentials.forge.Temphook; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderItem.class) +public abstract class MixinRenderItem { + + @Shadow + @Final + private TextureManager textureManager; + + @Inject(method = "renderItemOverlayIntoGUI", at = @At("RETURN")) + private void renderItemOverlayPost(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, CallbackInfo ci) { + Temphook.renderItemOverlayPost(fr, stack, xPosition, yPosition, text, ci); + } + + @Inject(method = "renderItemIntoGUI", at = @At("RETURN")) + public void renderItemReturn(ItemStack stack, int x, int y, CallbackInfo ci) { + } +} diff --git a/forge/src/main/resources/mcmod.info b/forge/src/main/resources/mcmod.info new file mode 100644 index 0000000..642d13a --- /dev/null +++ b/forge/src/main/resources/mcmod.info @@ -0,0 +1,18 @@ +[ + { + "modid": "${modid}", + "name": "BBsentials", + "description": "A mod that is used as an example.", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "https://github.com/romangraef/Forge1.8.9Template/", + "updateUrl": "", + "authorList": [ + "Hype_the_Time" + ], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +] \ No newline at end of file diff --git a/forge/src/main/resources/mixins.bbsentials.json b/forge/src/main/resources/mixins.bbsentials.json new file mode 100644 index 0000000..afc12e4 --- /dev/null +++ b/forge/src/main/resources/mixins.bbsentials.json @@ -0,0 +1,11 @@ +{ + "package": "de.hype.bbsentials.forge.mixin", + "refmap": "mixins.${modid}.refmap.json", + "minVersion": "0.7", + "compatibilityLevel": "JAVA_8", + "mixins": [ + ], + "client": [ + "MixinRenderItem" + ] +} diff --git a/settings.gradle b/settings.gradle index 302d62b..321db47 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,30 @@ pluginManagement { repositories { + mavenCentral() + gradlePluginPortal() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots' + } maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + url 'https://maven.architectury.dev/' } + maven { url 'https://maven.fabricmc.net'} + maven { url 'https://maven.minecraftforge.net/'} + maven { url 'https://repo.spongepowered.org/maven/'} + maven { url 'https://repo.sk1er.club/repository/maven-releases/'} gradlePluginPortal() } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "gg.essential.loom") { + useModule("gg.essential:architectury-loom:" + requested.version) + } + } + } + +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.6.0") } -include(":common", ":fabric") +include(":common", ":fabric",":forge") -- cgit