diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-09-22 17:52:49 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-09-22 17:53:44 +0200 |
commit | c17f2a88303bfa9b8a57a0b61e15961756d1d780 (patch) | |
tree | 9d39d8cb890feaef9125debe11d6f1be5391c312 /src/main/java/de | |
parent | 0426478c522d7878c53e5c373d88022f357e1e74 (diff) | |
download | BBsentials-c17f2a88303bfa9b8a57a0b61e15961756d1d780.tar.gz BBsentials-c17f2a88303bfa9b8a57a0b61e15961756d1d780.tar.bz2 BBsentials-c17f2a88303bfa9b8a57a0b61e15961756d1d780.zip |
added auto splash updates. and updated mod json
Diffstat (limited to 'src/main/java/de')
7 files changed, 94 insertions, 25 deletions
diff --git a/src/main/java/de/hype/bbsentials/chat/Chat.java b/src/main/java/de/hype/bbsentials/chat/Chat.java index 84e1c9e..9e6a01e 100644 --- a/src/main/java/de/hype/bbsentials/chat/Chat.java +++ b/src/main/java/de/hype/bbsentials/chat/Chat.java @@ -2,6 +2,7 @@ package de.hype.bbsentials.chat; import de.hype.bbsentials.client.BBsentials; import de.hype.bbsentials.client.Config; +import de.hype.bbsentials.packets.packets.SplashUpdatePacket; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents; import net.minecraft.client.MinecraftClient; @@ -27,8 +28,7 @@ import java.util.concurrent.FutureTask; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static de.hype.bbsentials.client.BBsentials.config; -import static de.hype.bbsentials.client.BBsentials.getConfig; +import static de.hype.bbsentials.client.BBsentials.*; public class Chat { public Chat() { @@ -294,6 +294,11 @@ public class Chat { else if (message.contains("[OPEN MENU]") || message.contains("[YES]")) { setChatPromtId(messageOriginal.toString()); } + else if (message.startsWith("BUFF! You splashed yourself with")){ + if (splashStatusUpdateListener!=null){ + splashStatusUpdateListener.setStatus(SplashUpdatePacket.STATUS_SPLASHING); + } + } } return messageOriginal; diff --git a/src/main/java/de/hype/bbsentials/client/BBsentials.java b/src/main/java/de/hype/bbsentials/client/BBsentials.java index 5c14c2e..b74e633 100644 --- a/src/main/java/de/hype/bbsentials/client/BBsentials.java +++ b/src/main/java/de/hype/bbsentials/client/BBsentials.java @@ -35,6 +35,7 @@ public class BBsentials implements ClientModInitializer { public static boolean splashLobby; private static Thread bbthread; private boolean initialised = false; + public static SplashStatusUpdateListener splashStatusUpdateListener; public static Config getConfig() { return config; diff --git a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java index 2d0039c..555c42d 100644 --- a/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java +++ b/src/main/java/de/hype/bbsentials/client/BBsentialsConfigScreemFactory.java @@ -228,7 +228,7 @@ public class BBsentialsConfigScreemFactory { .build()); } //Mining Events if (config.hasBBRoles("dev")){ - ConfigCategory dev = builder.getOrCreateCategory(Text.of("Developing")); + ConfigCategory dev = builder.getOrCreateCategory(Text.of("§3Developing")); dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Dev Mode"), config.devMode) .setDefaultValue(false) .setTooltip(Text.of("Dev Mode")) @@ -240,6 +240,14 @@ public class BBsentialsConfigScreemFactory { .setSaveConsumer(newValue -> config.detailedDevMode = newValue) .build()); } + if (config.hasBBRoles("splasher")){ + ConfigCategory dev = builder.getOrCreateCategory(Text.of("§dSplashes")); + dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Dev Mode"), config.devMode) + .setDefaultValue(true) + .setTooltip(Text.of("Auto Update Statuses")) + .setSaveConsumer(newValue -> config.autoSplashStatusUpdates = newValue) + .build()); + } return builder.build(); } diff --git a/src/main/java/de/hype/bbsentials/client/Config.java b/src/main/java/de/hype/bbsentials/client/Config.java index 2c9e471..31e794c 100644 --- a/src/main/java/de/hype/bbsentials/client/Config.java +++ b/src/main/java/de/hype/bbsentials/client/Config.java @@ -39,6 +39,7 @@ public class Config implements Serializable { public boolean allowBBinviteMe = true; public boolean doDesktopNotifications = false; public boolean acceptReparty; + public boolean autoSplashStatusUpdates; public String nickname; public String NotifForPartyMessagesType; diff --git a/src/main/java/de/hype/bbsentials/client/ModMenueScreen.java b/src/main/java/de/hype/bbsentials/client/ModMenueScreen.java index 8376517..30bc74a 100644 --- a/src/main/java/de/hype/bbsentials/client/ModMenueScreen.java +++ b/src/main/java/de/hype/bbsentials/client/ModMenueScreen.java @@ -10,8 +10,9 @@ import net.minecraft.text.Text; public class ModMenueScreen implements ModMenuApi { @Override public ConfigScreenFactory<?> getModConfigScreenFactory() { - if (FabricLoader.getInstance().isModLoaded("cloth-config2")) - return BBsentialsConfigScreemFactory::create; - return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("BBsentials"), Text.of("BBsentials requires Cloth Config to be able to show the config.")); + if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) { + return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("BBsentials"), Text.of("BBsentials requires Cloth Config to be able to show the config.")); + } + return BBsentialsConfigScreemFactory::create; } } diff --git a/src/main/java/de/hype/bbsentials/client/SplashStatusUpdateListener.java b/src/main/java/de/hype/bbsentials/client/SplashStatusUpdateListener.java new file mode 100644 index 0000000..6b5180a --- /dev/null +++ b/src/main/java/de/hype/bbsentials/client/SplashStatusUpdateListener.java @@ -0,0 +1,67 @@ +package de.hype.bbsentials.client; + +import de.hype.bbsentials.communication.BBsentialConnection; +import de.hype.bbsentials.packets.packets.SplashNotifyPacket; +import de.hype.bbsentials.packets.packets.SplashUpdatePacket; + +import java.util.concurrent.TimeUnit; + +import static de.hype.bbsentials.client.BBsentials.executionService; +import static de.hype.bbsentials.client.BBsentials.splashLobby; + +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; + while (BBsentials.splashLobby) { + int maxPlayerCount = BBUtils.getMaximumPlayerCount() - 5; + while (splashLobby && !(status.equals(SplashUpdatePacket.STATUS_DONE) || status.equals(SplashUpdatePacket.STATUS_CANCELED))) { + if (!full&&(BBUtils.getPlayerCount() >= maxPlayerCount)) { + newStatus = SplashUpdatePacket.STATUS_FULL; + full=true; + } + if (!status.equals(newStatus)) { + status = newStatus; + connection.sendPacket(new SplashUpdatePacket(packet.splashId, status)); + } + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + 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)) { + executionService.schedule(() -> { + splashed=true; + setStatus(SplashUpdatePacket.STATUS_DONE); + splashLobby = false; + }, 1, TimeUnit.MINUTES); + } + } +} diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java index 68ce520..d458724 100644 --- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java +++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java @@ -1,8 +1,8 @@ package de.hype.bbsentials.communication; import de.hype.bbsentials.chat.Chat; -import de.hype.bbsentials.client.BBUtils; import de.hype.bbsentials.client.BBsentials; +import de.hype.bbsentials.client.SplashStatusUpdateListener; import de.hype.bbsentials.constants.enviromentShared.*; import de.hype.bbsentials.packets.AbstractPacket; import de.hype.bbsentials.packets.PacketManager; @@ -34,7 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import static de.hype.bbsentials.client.BBsentials.config; -import static de.hype.bbsentials.client.BBsentials.splashLobby; +import static de.hype.bbsentials.client.BBsentials.executionService; public class BBsentialConnection { private Socket socket; @@ -347,23 +347,9 @@ public class BBsentialConnection { int waitTime; if (packet.splasherUsername.equals(config.getUsername())) { - BBsentials.splashLobby = true; - String status = SplashUpdatePacket.STATUS_WAITING; - String newStatus = SplashUpdatePacket.STATUS_WAITING; - int maxPlayerCount = BBUtils.getMaximumPlayerCount() - 5; - while (splashLobby && !status.equals(SplashUpdatePacket.STATUS_DONE)) { - if (BBUtils.getPlayerCount() >= maxPlayerCount) { - newStatus = SplashUpdatePacket.STATUS_FULL; - } - if (!status.equals(newStatus)) { - status = newStatus; - sendPacket(new SplashUpdatePacket(packet.splashId, status)); - } - } - if (!status.equals(newStatus)) { - status = newStatus; - sendPacket(new SplashUpdatePacket(packet.splashId, status)); - } + SplashStatusUpdateListener splashStatusUpdateListener = new SplashStatusUpdateListener(this,packet); + BBsentials.splashStatusUpdateListener = splashStatusUpdateListener; + executionService.submit(splashStatusUpdateListener); } else { if (packet.lessWaste) { |