From ac68a6fe8200127254e58d0a6005f072075a1842 Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Fri, 15 Dec 2023 18:24:37 +0100 Subject: changed the BBsentials.onServerSwap() to BBsentials.onServerJoin(). also added BBsentials.onServerLeave() both of those will now also go through a for loop of runnables and execute those ONCE after which being removed. added a Splash Leecher Display for Splashers. will be enabled automatically when a Splash is announced. Can also be enabled for 2 Minutes through /getLeechers added the Server host String as base in the github. --- .../CommandImplementations/CommandGetLeechers.java | 35 +++++ .../java/de/hype/bbsentials/forge/Commands.java | 2 +- .../java/de/hype/bbsentials/forge/ForgeMod.java | 2 +- .../java/de/hype/bbsentials/forge/MCUtils.java | 161 ++++++++++----------- 4 files changed, 115 insertions(+), 85 deletions(-) create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java (limited to 'forge') 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/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