aboutsummaryrefslogtreecommitdiff
path: root/forge
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 /forge
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()
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/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
5 files changed, 116 insertions, 88 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/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);
}
+
}