From d7bd502812504373a3d4e181fa4635145d1c10be Mon Sep 17 00:00:00 2001 From: hackthetime Date: Thu, 14 Dec 2023 12:57:03 +0100 Subject: a lot of prob not full working things --- .../java/de/hype/bbsentials/forge/BBUtils.java | 3 +- .../java/de/hype/bbsentials/forge/MCUtils.java | 113 ++++++++++++++++++++- .../hype/bbsentials/forge/client/MoulConfig.java | 30 ++---- .../bbsentials/forge/client/MoulConfigManager.java | 22 ++++ 4 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java (limited to 'forge/src/main/java/de') diff --git a/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java b/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java index e50ef3b..97845c6 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java @@ -3,6 +3,7 @@ package de.hype.bbsentials.forge; import com.google.common.collect.Lists; import com.mojang.realmsclient.dto.PlayerInfo; import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.constants.enviromentShared.EnumUtils; import de.hype.bbsentials.common.constants.enviromentShared.Islands; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; @@ -19,7 +20,7 @@ public class BBUtils implements de.hype.bbsentials.common.mclibraries.BBUtils { Chat.sendPrivateMessageToSelfError("Could not get Area data. Are you in Skyblock?"); } else { - return Islands.getByDisplayName(string.replace("Area: ", "").trim()); + return EnumUtils.getEnumByName(Islands.class, string.replace("Area: ", "").trim()); } } catch (Exception e) { } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java index 251b20b..8bb02f0 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java @@ -3,14 +3,18 @@ package de.hype.bbsentials.forge; import com.mojang.authlib.exceptions.AuthenticationException; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.Display; import java.io.File; -import java.math.BigInteger; -import java.util.Random; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { public boolean isWindowFocused() { @@ -58,4 +62,109 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { return serverId; } + public List getAllPlayers() { + List players = new ArrayList<>(); + + // Iterate through all players on the server + for (EntityPlayer player : Minecraft.getMinecraft().thePlayer.getEntityWorld().playerEntities) { + if (!player.getDisplayNameString().startsWith("!")) { + players.add(player); + } + } + + return players; + } + + public List getPlayersInRadius(EntityPlayer referencePlayer, List players, double radius) { + List nearbyPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the reference player + for (EntityPlayer player : players) { + if (player != referencePlayer && player.getDistanceSq(referencePlayer.posX, referencePlayer.posY, referencePlayer.posZ) <= radius * radius) { + nearbyPlayers.add(player); + } + } + + return nearbyPlayers; + } + + + public List getBingoPlayers() { + List bingoPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the source player + for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { + NetworkPlayerInfo entry = it.next(); + try { + if (entry.getGameProfile().getName().startsWith("!")) { + String customName = entry.getDisplayName().getUnformattedText(); + if (customName.contains("Ⓑ")) { + bingoPlayers.add(customName.trim().split(" ")[1]); + } + } + } catch (Exception ignored) { + } + + } + return bingoPlayers; + } + + public List getIronmanPlayers() { + List ironmanPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the source player + for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { + NetworkPlayerInfo entry = it.next(); + try { + if (entry.getGameProfile().getName().startsWith("!")) { + String customName = entry.getDisplayName().getUnformattedText(); + if (customName.contains("♻")) { + ironmanPlayers.add(customName.trim().split(" ")[1]); + } + } + } catch (Exception ignored) { + } + + } + return ironmanPlayers; + } + + public List onlyFromList(List players, List usernames) { + ArrayList filtered = new ArrayList<>(); + for (EntityPlayer player : players) { + String playerUsername = player.getGameProfile().getName(); + for (int i = 0; i < usernames.size(); i++) { + if (playerUsername.equals(usernames.get(i))) { + usernames.remove(i); + filtered.add(player); + } + } + } + return filtered; + } + + public List filterOut(List players, List usernames) { + ArrayList filtered = new ArrayList<>(); + for (EntityPlayer player : players) { + String playerUsername = player.getGameProfile().getName(); + boolean toAdd = true; + for (int i = 0; i < usernames.size(); i++) { + if (playerUsername.equals(usernames.get(i))) { + toAdd = false; + usernames.remove(i); + break; + } + } + if (toAdd) { + filtered.add(player); + } + } + return filtered; + } + + public List getSplashLeechingPlayers() { + List players = getAllPlayers(); + players.remove(Minecraft.getMinecraft().thePlayer); + return getPlayersInRadius(Minecraft.getMinecraft().thePlayer, filterOut(getAllPlayers(), getBingoPlayers()), 5).stream().map((playerEntity -> playerEntity.getDisplayName().getFormattedText())).collect(Collectors.toList()); + } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java index 4d50a4e..e0598ff 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java @@ -4,43 +4,35 @@ import com.google.gson.annotations.Expose; import de.hype.bbsentials.forge.client.categories.FirstCategory; import io.github.moulberry.moulconfig.Config; import io.github.moulberry.moulconfig.annotations.Category; -import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; -import io.github.moulberry.moulconfig.annotations.ConfigOption; -import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper; -import io.github.moulberry.moulconfig.gui.MoulConfigEditor; -import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis; -import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver; -import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; import net.minecraft.client.Minecraft; -import net.minecraftforge.common.config.ConfigCategory; +import net.minecraft.util.ChatComponentText; import static de.hype.bbsentials.common.client.BBsentials.config; public class MoulConfig extends Config { - MoulConfigEditor editor; - MoulConfigProcessor processor; @Expose @Category(name = "First Category", desc = "This is the first category.") public FirstCategory firstCategory = new FirstCategory(); - public MoulConfig() { - processor = new MoulConfigProcessor<>(this); - editor = new MoulConfigEditor<>(processor); - BuiltinMoulConfigGuis.addProcessors(processor); - ConfigProcessorDriver.processConfig(MoulConfig.class, this, processor); - } - @Override public String getTitle() { return "BBsentials " + de.hype.bbsentials.common.client.Config.apiVersion; } + @Override public void saveNow() { config.save(); } - public void openConfigGui() { - Minecraft.getMinecraft().displayGuiScreen(new GuiScreenElementWrapper(editor)); + @Override + public void executeRunnable(int runnableId) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Just executed runnableId " + runnableId)); + } + + @Override + public boolean shouldAutoFocusSearchbar() { + return true; } + } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java new file mode 100644 index 0000000..07491cd --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java @@ -0,0 +1,22 @@ +package de.hype.bbsentials.forge.client; + +import io.github.moulberry.moulconfig.gui.MoulGuiOverlayEditor; +import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis; +import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver; +import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; +import net.minecraft.client.Minecraft; + +public class MoulConfigManager { + static MoulConfig moulConfig = new MoulConfig(); + MoulConfigProcessor testConfigMoulConfigProcessor; + + public MoulConfigManager() { + testConfigMoulConfigProcessor = new MoulConfigProcessor<>(moulConfig); + BuiltinMoulConfigGuis.addProcessors(testConfigMoulConfigProcessor); + ConfigProcessorDriver.processConfig(moulConfig.getClass(), moulConfig, testConfigMoulConfigProcessor); + } + + public void openConfigGui() { + Minecraft.getMinecraft().displayGuiScreen(new MoulGuiOverlayEditor(testConfigMoulConfigProcessor)); + } +} -- cgit From bf86da0fd755ca29b48de2fece6d57d50f9eb14f Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Fri, 15 Dec 2023 18:16:01 +0100 Subject: varios changes. added runnables for on server join and leave. moved the start onServerSwap() wait over too BBsentials.onServerJoin() --- .../hype/bbsentials/common/client/BBsentials.java | 19 ++- .../de/hype/bbsentials/common/client/Config.java | 2 +- .../common/client/SplashStatusUpdateListener.java | 15 +- .../bbsentials/common/mclibraries/MCUtils.java | 4 + .../fabric/BBsentialsConfigScreemFactory.java | 2 +- .../java/de/hype/bbsentials/fabric/Commands.java | 5 + .../de/hype/bbsentials/fabric/DebugThread.java | 3 +- .../java/de/hype/bbsentials/fabric/MCUtils.java | 106 ++++++++++---- .../de/hype/bbsentials/fabric/ModInitialiser.java | 5 +- .../CommandImplementations/CommandGetLeechers.java | 35 +++++ .../java/de/hype/bbsentials/forge/Commands.java | 2 +- .../java/de/hype/bbsentials/forge/DebugThread.java | 4 +- .../java/de/hype/bbsentials/forge/ForgeMod.java | 2 +- .../java/de/hype/bbsentials/forge/MCUtils.java | 161 ++++++++++----------- 14 files changed, 233 insertions(+), 132 deletions(-) create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java (limited to 'forge/src/main/java/de') 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 index 20ab520..dc92ce8 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java @@ -5,6 +5,8 @@ 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.ArrayList; +import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -14,7 +16,8 @@ public class BBsentials { private static boolean initialised = false; public static Commands coms; public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000); - public static boolean splashLobby; + public static List onServerJoin = new ArrayList<>(); + public static List onServerLeave = new ArrayList<>(); public static SplashStatusUpdateListener splashStatusUpdateListener; public static Thread bbthread; public static Chat chat = new Chat(); @@ -65,14 +68,22 @@ public class BBsentials { * Runs the mod initializer on the client environment. */ - public static void onServerSwap() { + public static void onServerJoin() { + for (int i = 0; i < onServerJoin.size(); i++) { + onServerJoin.remove(i).run(); + } if (!initialised) { initialised = true; if (Config.isBingoTime() || config.overrideBingoTime()) { connectToBBserver(); } } - splashLobby = false; + } + + public static void onServerLeave() { + for (int i = 0; i < onServerLeave.size(); i++) { + onServerLeave.remove(i).run(); + } } public static void init() { @@ -82,5 +93,7 @@ public class BBsentials { ); debugThread.start(); debugThread.setName("Debug Thread"); + splashStatusUpdateListener = new SplashStatusUpdateListener(null, null); + EnvironmentCore.mcUtils.registerSplashOverlay(); } } \ 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 index ceeafa9..5f7fb29 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/Config.java @@ -36,7 +36,7 @@ public class Config implements Serializable { public boolean connectToBeta = false; public boolean useMojangAuth = false; - public String bbServerURL = "localhost"; + public String bbServerURL = "static.88-198-149-240.clients.your-server.de"; public String apiKey = ""; public boolean showBingoChat = true; public boolean doAllChatCustomMenu = true; 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 index 8898e20..f214629 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java @@ -6,11 +6,14 @@ import de.hype.bbsentials.common.packets.packets.SplashNotifyPacket; import de.hype.bbsentials.common.packets.packets.SplashUpdatePacket; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; public class SplashStatusUpdateListener implements Runnable { public String newStatus = SplashUpdatePacket.STATUS_WAITING; public boolean splashed = false; public boolean full = false; + AtomicBoolean splashLobby = new AtomicBoolean(false); + public static boolean showSplashOverlayOverrideDisplay = false; BBsentialConnection connection; SplashNotifyPacket packet; private String status = SplashUpdatePacket.STATUS_WAITING; @@ -20,12 +23,16 @@ public class SplashStatusUpdateListener implements Runnable { this.packet = packet; } + public boolean showSplashOverlay() { + return splashLobby.get() || showSplashOverlayOverrideDisplay; + } + @Override public void run() { - BBsentials.splashLobby = true; + BBsentials.onServerLeave.add(() -> splashLobby.set(false)); int maxPlayerCount = EnvironmentCore.utils.getMaximumPlayerCount() - 5; - - while (BBsentials.splashLobby) { + splashLobby.set(true); + while (splashLobby.get()) { if (!full && (EnvironmentCore.utils.getPlayerCount() >= maxPlayerCount)) { newStatus = SplashUpdatePacket.STATUS_FULL; full = true; @@ -57,7 +64,7 @@ public class SplashStatusUpdateListener implements Runnable { splashed = true; BBsentials.executionService.schedule(() -> { setStatus(SplashUpdatePacket.STATUS_DONE); - BBsentials.splashLobby = false; + splashLobby.set(false); }, 1, TimeUnit.MINUTES); } } 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 index dbd407f..d4b2239 100644 --- a/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java +++ b/common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java @@ -11,11 +11,15 @@ public interface MCUtils { String getUsername(); String getMCUUID(); + void playsound(String eventName); int getPotTime(); String mojangAuth(String serverId); + // Leechers was originally inveneted by Calva but redone by me without access to the code, I made it since Calvas mod was private at that date List getSplashLeechingPlayers(); + + void registerSplashOverlay(); } 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 556208c..3154377 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java @@ -31,7 +31,7 @@ public class BBsentialsConfigScreemFactory { ConfigCategory server = builder.getOrCreateCategory(Text.of("Server")); if (BBsentials.config.getUsername().equalsIgnoreCase("Hype_the_Time")) { server.addEntry(entryBuilder.startTextField(Text.of("Server URL"), BBsentials.config.getBBServerURL().replaceAll(".", "*")) - .setDefaultValue("localhost") + .setDefaultValue("static.88-198-149-240.clients.your-server.de") .setTooltip(Text.of("Place the Server URL of the BBsentials Server here")) .setSaveConsumer((newValue) -> { if (newValue.replace("*", "").trim().isEmpty()) { 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 3d7f76a..e1774a2 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java @@ -5,6 +5,7 @@ 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.client.SplashStatusUpdateListener; import de.hype.bbsentials.common.constants.enviromentShared.ChChestItems; import de.hype.bbsentials.common.constants.enviromentShared.MiningEvents; import de.hype.bbsentials.common.mclibraries.EnvironmentCore; @@ -20,6 +21,7 @@ import net.minecraft.command.CommandSource; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; public class Commands implements MCCommand { Event event = ClientCommandRegistrationCallback.EVENT; @@ -281,7 +283,10 @@ public class Commands implements MCCommand { ClientCommandManager.literal("getLeecher") .executes((context) -> { BBsentials.executionService.execute(() -> { + SplashStatusUpdateListener.showSplashOverlayOverrideDisplay = true; Chat.sendPrivateMessageToSelfInfo("Leeching Players: " + String.join(", ", EnvironmentCore.mcUtils.getSplashLeechingPlayers())); + BBsentials.executionService.schedule(() -> SplashStatusUpdateListener.showSplashOverlayOverrideDisplay = false, + 2, TimeUnit.MINUTES); }); return 1; }) 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 92274a3..9c5a1e8 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java @@ -26,7 +26,6 @@ public class DebugThread implements de.hype.bbsentials.common.client.DebugThread public void doOnce() { doTest = true; } - @Override public List test() { return List.of(""); @@ -72,7 +71,7 @@ public class DebugThread implements de.hype.bbsentials.common.client.DebugThread public List getSplashLeechingPlayers() { List players = getAllPlayers(); - players.remove(MinecraftClient.getInstance().player); +// players.remove(MinecraftClient.getInstance().player); return getPlayersInRadius(MinecraftClient.getInstance().player, getNonBingoPlayers(players), 5).stream().map((playerEntity -> playerEntity.getDisplayName().getString())).toList(); } } 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 346bdca..2b2b229 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java @@ -2,22 +2,44 @@ package de.hype.bbsentials.fabric; import com.mojang.authlib.exceptions.AuthenticationException; import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.client.BBsentials; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvent; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; +import java.util.regex.Pattern; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { + public static boolean isBingo(PlayerEntity player) { + try { + return player.getDisplayName().getString().contains("Ⓑ"); + } catch (Exception e) { + return false; + } + } + + public static boolean isIronman(PlayerEntity player) { + try { + return player.getDisplayName().getString().contains("♻"); + } catch (Exception e) { + return false; + } + } + public boolean isWindowFocused() { return MinecraftClient.getInstance().isWindowFocused(); } @@ -34,10 +56,8 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { return MinecraftClient.getInstance().getSession().getUuidOrNull().toString(); } - public void playsound(String eventName) { - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance - .master(SoundEvent.of(new Identifier(eventName)), 1.0F, 1.0F)); + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvent.of(new Identifier(eventName)), 1.0F, 1.0F)); } public int getPotTime() { @@ -79,49 +99,71 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { // Iterate through all players and check their distance from the source player for (PlayerEntity player : MinecraftClient.getInstance().player.getEntityWorld().getPlayers()) { if (!player.getDisplayName().getString().startsWith("!")) { - players.add(player); + if (Pattern.compile("\"color\":\"(?!white)\\w+\"").matcher(Text.Serializer.toJson(player.getDisplayName())).find()) { + players.add(player); + } } } return players; } - public List getPlayersInRadius(ClientPlayerEntity referencePlayer, List players, double radius) { - List nearbyPlayers = new ArrayList<>(); - - // Iterate through all players and check their distance from the source player - for (PlayerEntity player : players) { - if (player != referencePlayer && player.squaredDistanceTo(referencePlayer) <= radius * radius) { - nearbyPlayers.add(player); - } - } + public boolean isInRadius(ClientPlayerEntity referencePlayer, PlayerEntity player, double radius) { + return player != referencePlayer && player.squaredDistanceTo(referencePlayer) <= radius * radius; + } - return nearbyPlayers; + public List filterOut(List players, Predicate predicate) { + return players.stream().filter(predicate).toList(); } - public static boolean isBingo(PlayerEntity player) { - try { - return player.getDisplayName().getString().contains("Ⓑ"); - } catch (Exception e) { - return false; - } + private List getSplashLeechingPlayersPlayerEntity() { + List players = getAllPlayers(); + players.remove(MinecraftClient.getInstance().player); + return filterOut(filterOut(getAllPlayers(), (player -> !isBingo(player))), (player) -> isInRadius(MinecraftClient.getInstance().player, player, 5)); } - public static boolean isIronman(PlayerEntity player) { - try { - return player.getDisplayName().getString().contains("♻"); - } catch (Exception e) { - return false; - } + public List getSplashLeechingPlayers() { + return getSplashLeechingPlayersPlayerEntity().stream().map((player -> player.getDisplayName().getString())).toList(); } - public List filterOut(List players, Predicate predicate) { - return players.stream().filter(predicate).toList(); + public void registerSplashOverlay() { + HudRenderCallback.EVENT.register(this::renderSplashOverlay); } - public List getSplashLeechingPlayers() { - List players = getAllPlayers(); - players.remove(MinecraftClient.getInstance().player); - return getPlayersInRadius(MinecraftClient.getInstance().player, filterOut(getAllPlayers(), MCUtils::isBingo), 5).stream().map((playerEntity -> playerEntity.getDisplayName().getString())).toList(); + private void renderSplashOverlay(DrawContext drawContext, float v) { + if (!BBsentials.splashStatusUpdateListener.showSplashOverlay()) return; + // Set the starting position for the overlay + int x = 10; + int y = 10; + + // Render each string in the list + List splashLeechers = getSplashLeechingPlayersPlayerEntity(); + List allParticipiants = filterOut(getAllPlayers(), (player) -> isInRadius(MinecraftClient.getInstance().player, player, 5)); + List musicPants = new ArrayList<>(); + List toDisplay = new ArrayList<>(); + toDisplay.add(Text.of("§6Total: " + allParticipiants.size() + " | Bingos: " + (allParticipiants.size() - splashLeechers.size()) + " | Leechers: " + splashLeechers.size())); + for (PlayerEntity participiant : allParticipiants) { + boolean hasPants = false; + for (ItemStack armorItem : participiant.getArmorItems()) { + try { + if (armorItem.getNbt().get("ExtraAttributes").asString().contains("MUSIC_PANTS")) { + musicPants.add(participiant); + hasPants = true; + } + } catch (Exception ignored) { + continue; + } + } + if (hasPants) { + String pantsAddition = Text.Serializer.toJson(Text.of("§4[♪]§ ")); + String normal = Text.Serializer.toJson(participiant.getDisplayName()); + toDisplay.add(Text.Serializer.fromJson("[" + pantsAddition + "," + normal + "]")); + } + } + toDisplay.addAll(splashLeechers.stream().map(PlayerEntity::getDisplayName).toList()); + for (Text text : toDisplay) { + drawContext.drawText(MinecraftClient.getInstance().textRenderer, text, x, y, 0xFFFFFF, true); + y += 10; // Adjust the vertical position for the next string + } } } \ No newline at end of file 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 2bb6aeb..ebdf7a6 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java @@ -231,7 +231,10 @@ public class ModInitialiser implements ClientModInitializer { codes = new NumPadCodes(); BBsentials.init(); ClientPlayConnectionEvents.JOIN.register((a, b, c) -> { - BBsentials.onServerSwap(); + BBsentials.onServerJoin(); + }); + ClientPlayConnectionEvents.JOIN.register((a, b, c) -> { + BBsentials.onServerLeave(); }); } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java b/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java new file mode 100644 index 0000000..4326ef4 --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java @@ -0,0 +1,35 @@ +package de.hype.bbsentials.forge.CommandImplementations; + +import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.common.client.SplashStatusUpdateListener; +import de.hype.bbsentials.common.mclibraries.EnvironmentCore; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +import java.util.concurrent.TimeUnit; + +public class CommandGetLeechers extends CommandBase { + + @Override + public String getCommandName() { + return "getLeechers"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/getLeechers"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + SplashStatusUpdateListener.showSplashOverlayOverrideDisplay = true; + Chat.sendPrivateMessageToSelfDebug("Leechers: " + String.join(", ", EnvironmentCore.mcUtils.getSplashLeechingPlayers())); + BBsentials.executionService.schedule(() -> SplashStatusUpdateListener.showSplashOverlayOverrideDisplay = false, 2, TimeUnit.MINUTES); + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return true; + } +} diff --git a/forge/src/main/java/de/hype/bbsentials/forge/Commands.java b/forge/src/main/java/de/hype/bbsentials/forge/Commands.java index a244209..80ed853 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/Commands.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/Commands.java @@ -6,7 +6,6 @@ import de.hype.bbsentials.common.mclibraries.MCCommand; import de.hype.bbsentials.common.packets.AbstractPacket; import de.hype.bbsentials.common.packets.packets.SplashNotifyPacket; import de.hype.bbsentials.forge.CommandImplementations.*; -import de.hype.bbsentials.forge.CommandImplementations.CommandBBI; import net.minecraftforge.client.ClientCommandHandler; public class Commands implements MCCommand { @@ -35,6 +34,7 @@ public class Commands implements MCCommand { } if (hasSplasher) { ClientCommandHandler.instance.registerCommand(new CommandSplashAnnounce()); + ClientCommandHandler.instance.registerCommand(new CommandGetLeechers()); } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java b/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java index 60d1469..ef926e3 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java @@ -1,7 +1,5 @@ package de.hype.bbsentials.forge; -import de.hype.bbsentials.forge.client.MoulConfigManager; - import java.util.Collections; import java.util.List; @@ -13,7 +11,7 @@ public class DebugThread implements de.hype.bbsentials.common.client.DebugThread @Override public List test() { - new MoulConfigManager().openConfigGui(); +// new MoulConfigManager().openConfigGui(); return Collections.singletonList(""); } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java b/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java index f39dcfc..d4ff5d4 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java @@ -40,7 +40,7 @@ public class ForgeMod { } @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { - BBsentials.onServerSwap(); + BBsentials.onServerJoin(); } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java index 8bb02f0..66e92b6 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java @@ -1,22 +1,45 @@ package de.hype.bbsentials.forge; import com.mojang.authlib.exceptions.AuthenticationException; +import de.hype.bbsentials.common.client.BBsentials; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.opengl.Display; import java.io.File; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import java.util.function.Predicate; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { + public static boolean isBingo(EntityPlayer player) { + try { + return player.getDisplayNameString().contains("Ⓑ"); + } catch (Exception e) { + return false; + } + } + + public static boolean isIronman(EntityPlayer player) { + try { + return player.getDisplayNameString().contains("♻"); + } catch (Exception e) { + return false; + } + } + public boolean isWindowFocused() { return Display.isActive(); } @@ -33,7 +56,6 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { return Minecraft.getMinecraft().getSession().getPlayerID().toString(); } - public void playsound(String eventName) { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation(eventName), 1.0F, 1.0F, 0.0F)); } @@ -49,7 +71,6 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { return remainingDuration; } - public String mojangAuth(String serverId) { try { Minecraft.getMinecraft().getSessionService().joinServer(Minecraft @@ -65,106 +86,80 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { public List getAllPlayers() { List players = new ArrayList<>(); - // Iterate through all players on the server - for (EntityPlayer player : Minecraft.getMinecraft().thePlayer.getEntityWorld().playerEntities) { + // Iterate through all players and check their distance from the source player + for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { if (!player.getDisplayNameString().startsWith("!")) { - players.add(player); + if (Pattern.compile("§(?!f)\\w+").matcher(IChatComponent.Serializer.componentToJson(player.getDisplayName())).find()) { + players.add(player); + } } } return players; } - public List getPlayersInRadius(EntityPlayer referencePlayer, List players, double radius) { - List nearbyPlayers = new ArrayList<>(); - - // Iterate through all players and check their distance from the reference player - for (EntityPlayer player : players) { - if (player != referencePlayer && player.getDistanceSq(referencePlayer.posX, referencePlayer.posY, referencePlayer.posZ) <= radius * radius) { - nearbyPlayers.add(player); - } - } - - return nearbyPlayers; + public boolean isInRadius(EntityPlayer referencePlayer, EntityPlayer player, double radius) { + return player != referencePlayer && player.getDistanceSq(referencePlayer.posX, referencePlayer.posY, referencePlayer.posZ) <= radius * radius; } + public List filterOut(List players, Predicate predicate) { + return players.stream().filter(predicate).collect(Collectors.toList()); + } - public List getBingoPlayers() { - List bingoPlayers = new ArrayList<>(); - - // Iterate through all players and check their distance from the source player - for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { - NetworkPlayerInfo entry = it.next(); - try { - if (entry.getGameProfile().getName().startsWith("!")) { - String customName = entry.getDisplayName().getUnformattedText(); - if (customName.contains("Ⓑ")) { - bingoPlayers.add(customName.trim().split(" ")[1]); - } - } - } catch (Exception ignored) { - } + private List getSplashLeechingPlayersPlayerEntity() { + List players = getAllPlayers(); + players.remove(Minecraft.getMinecraft().thePlayer); + return filterOut(filterOut(getAllPlayers(), (player -> !isBingo(player))), (player) -> isInRadius(Minecraft.getMinecraft().thePlayer, player, 5)); + } - } - return bingoPlayers; + public List getSplashLeechingPlayers() { + return getSplashLeechingPlayersPlayerEntity().stream().map((player -> player.getDisplayName().getFormattedText())).collect(Collectors.toList()); } - public List getIronmanPlayers() { - List ironmanPlayers = new ArrayList<>(); - // Iterate through all players and check their distance from the source player - for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { - NetworkPlayerInfo entry = it.next(); - try { - if (entry.getGameProfile().getName().startsWith("!")) { - String customName = entry.getDisplayName().getUnformattedText(); - if (customName.contains("♻")) { - ironmanPlayers.add(customName.trim().split(" ")[1]); + @SubscribeEvent + public void renderSplashOverlay(RenderGameOverlayEvent.Text event) { + if (!BBsentials.splashStatusUpdateListener.showSplashOverlay()) return; + + // Set the starting position for the overlay + int x = 10; + int y = 10; + + // Render each string in the list + List splashLeechers = getSplashLeechingPlayersPlayerEntity(); + List allParticipants = filterOut(getAllPlayers(), (player) -> isInRadius(Minecraft.getMinecraft().thePlayer, player, 5)); + List musicPants = new ArrayList<>(); + + List toDisplay = new ArrayList<>(); + toDisplay.add(new ChatComponentText("§6Total: " + allParticipants.size() + " | Bingos: " + (allParticipants.size() - splashLeechers.size()) + " | Leechers: " + splashLeechers.size())); + for (EntityPlayer participant : allParticipants) { + boolean hasPants = false; + for (ItemStack armorItem : participant.inventory.armorInventory) { + try { + if (armorItem.getTagCompound().getCompoundTag("ExtraAttributes").getString("display").contains("MUSIC_PANTS")) { + musicPants.add(participant); + hasPants = true; } + } catch (Exception ignored) { + continue; } - } catch (Exception ignored) { } - - } - return ironmanPlayers; - } - - public List onlyFromList(List players, List usernames) { - ArrayList filtered = new ArrayList<>(); - for (EntityPlayer player : players) { - String playerUsername = player.getGameProfile().getName(); - for (int i = 0; i < usernames.size(); i++) { - if (playerUsername.equals(usernames.get(i))) { - usernames.remove(i); - filtered.add(player); - } + if (hasPants) { + String pantsAddition = IChatComponent.Serializer.componentToJson(new ChatComponentText("§4[♪]§ ")); + String normal = IChatComponent.Serializer.componentToJson(participant.getDisplayName()); + toDisplay.add(IChatComponent.Serializer.jsonToComponent("[" + pantsAddition + "," + normal + "]")); } } - return filtered; - } - - public List filterOut(List players, List usernames) { - ArrayList filtered = new ArrayList<>(); - for (EntityPlayer player : players) { - String playerUsername = player.getGameProfile().getName(); - boolean toAdd = true; - for (int i = 0; i < usernames.size(); i++) { - if (playerUsername.equals(usernames.get(i))) { - toAdd = false; - usernames.remove(i); - break; - } - } - if (toAdd) { - filtered.add(player); - } + toDisplay.addAll(splashLeechers.stream().map(EntityPlayer::getDisplayName).collect(Collectors.toList())); + for (IChatComponent text : toDisplay) { + Minecraft.getMinecraft().fontRendererObj.drawString(text.getFormattedText(), x, y, 0xFFFFFF); + y += 10; // Adjust the vertical position for the next string } - return filtered; } - public List getSplashLeechingPlayers() { - List players = getAllPlayers(); - players.remove(Minecraft.getMinecraft().thePlayer); - return getPlayersInRadius(Minecraft.getMinecraft().thePlayer, filterOut(getAllPlayers(), getBingoPlayers()), 5).stream().map((playerEntity -> playerEntity.getDisplayName().getFormattedText())).collect(Collectors.toList()); + @Override + public void registerSplashOverlay() { + FMLCommonHandler.instance().bus().register(this); } + } -- cgit