aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHacktheTime <l4bg0jb7@duck.com>2023-12-15 18:16:01 +0100
committerHacktheTime <l4bg0jb7@duck.com>2023-12-15 18:16:01 +0100
commitbf86da0fd755ca29b48de2fece6d57d50f9eb14f (patch)
tree3e2a919818594593e70e81530a668841ce7236ea
parent38dc93f626c9a858835eef59488ef2b9ee441bc9 (diff)
downloadBBsentials-bf86da0fd755ca29b48de2fece6d57d50f9eb14f.tar.gz
BBsentials-bf86da0fd755ca29b48de2fece6d57d50f9eb14f.tar.bz2
BBsentials-bf86da0fd755ca29b48de2fece6d57d50f9eb14f.zip
varios changes. added runnables for on server join and leave. moved the start onServerSwap() wait over too BBsentials.onServerJoin()
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java19
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/Config.java2
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/SplashStatusUpdateListener.java15
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/mclibraries/MCUtils.java4
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java2
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/Commands.java5
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/DebugThread.java3
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java106
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java5
-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/DebugThread.java4
-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
14 files changed, 233 insertions, 132 deletions
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<Runnable> onServerJoin = new ArrayList<>();
+ public static List<Runnable> 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<String> 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<ClientCommandRegistrationCallback> 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<String> test() {
return List.of("");
@@ -72,7 +71,7 @@ public class DebugThread implements de.hype.bbsentials.common.client.DebugThread
public List<String> getSplashLeechingPlayers() {
List<PlayerEntity> 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<PlayerEntity> getPlayersInRadius(ClientPlayerEntity referencePlayer, List<PlayerEntity> players, double radius) {
- List<PlayerEntity> 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<PlayerEntity> filterOut(List<PlayerEntity> players, Predicate<PlayerEntity> 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<PlayerEntity> getSplashLeechingPlayersPlayerEntity() {
+ List<PlayerEntity> 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<String> getSplashLeechingPlayers() {
+ return getSplashLeechingPlayersPlayerEntity().stream().map((player -> player.getDisplayName().getString())).toList();
}
- public List<PlayerEntity> filterOut(List<PlayerEntity> players, Predicate<PlayerEntity> predicate) {
- return players.stream().filter(predicate).toList();
+ public void registerSplashOverlay() {
+ HudRenderCallback.EVENT.register(this::renderSplashOverlay);
}
- public List<String> getSplashLeechingPlayers() {
- List<PlayerEntity> 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<PlayerEntity> splashLeechers = getSplashLeechingPlayersPlayerEntity();
+ List<PlayerEntity> allParticipiants = filterOut(getAllPlayers(), (player) -> isInRadius(MinecraftClient.getInstance().player, player, 5));
+ List<PlayerEntity> musicPants = new ArrayList<>();
+ List<Text> 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<String> 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<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);
}
+
}