aboutsummaryrefslogtreecommitdiff
path: root/forge
diff options
context:
space:
mode:
authorHacktheTime <l4bg0jb7@duck.com>2023-12-15 18:24:37 +0100
committerHacktheTime <l4bg0jb7@duck.com>2023-12-15 18:24:37 +0100
commitac68a6fe8200127254e58d0a6005f072075a1842 (patch)
tree871baae5b1f07e441146b71c956996b39f579e5d /forge
parent127dcc12a982b7b31a098f8f1e011725ead62d9b (diff)
downloadBBsentials-ac68a6fe8200127254e58d0a6005f072075a1842.tar.gz
BBsentials-ac68a6fe8200127254e58d0a6005f072075a1842.tar.bz2
BBsentials-ac68a6fe8200127254e58d0a6005f072075a1842.zip
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.
Diffstat (limited to 'forge')
-rw-r--r--forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandGetLeechers.java35
-rw-r--r--forge/src/main/java/de/hype/bbsentials/forge/Commands.java2
-rw-r--r--forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java2
-rw-r--r--forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java161
4 files changed, 115 insertions, 85 deletions
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<EntityPlayer> getAllPlayers() {
List<EntityPlayer> 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<EntityPlayer> getPlayersInRadius(EntityPlayer referencePlayer, List<EntityPlayer> players, double radius) {
- List<EntityPlayer> 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<EntityPlayer> filterOut(List<EntityPlayer> players, Predicate<EntityPlayer> predicate) {
+ return players.stream().filter(predicate).collect(Collectors.toList());
+ }
- public List<String> getBingoPlayers() {
- List<String> bingoPlayers = new ArrayList<>();
-
- // Iterate through all players and check their distance from the source player
- for (Iterator<NetworkPlayerInfo> 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<EntityPlayer> getSplashLeechingPlayersPlayerEntity() {
+ List<EntityPlayer> 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<String> getSplashLeechingPlayers() {
+ return getSplashLeechingPlayersPlayerEntity().stream().map((player -> player.getDisplayName().getFormattedText())).collect(Collectors.toList());
}
- public List<String> getIronmanPlayers() {
- List<String> ironmanPlayers = new ArrayList<>();
- // Iterate through all players and check their distance from the source player
- for (Iterator<NetworkPlayerInfo> 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<EntityPlayer> splashLeechers = getSplashLeechingPlayersPlayerEntity();
+ List<EntityPlayer> allParticipants = filterOut(getAllPlayers(), (player) -> isInRadius(Minecraft.getMinecraft().thePlayer, player, 5));
+ List<EntityPlayer> musicPants = new ArrayList<>();
+
+ List<IChatComponent> 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<EntityPlayer> onlyFromList(List<EntityPlayer> players, List<String> usernames) {
- ArrayList<EntityPlayer> 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<EntityPlayer> filterOut(List<EntityPlayer> players, List<String> usernames) {
- ArrayList<EntityPlayer> 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<String> getSplashLeechingPlayers() {
- List<EntityPlayer> 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);
}
+
}