From cc07573c35f5df8d81379db4cb6eaa5d6fc496c8 Mon Sep 17 00:00:00 2001 From: hackthetime Date: Wed, 22 Nov 2023 10:44:16 +0100 Subject: renamed ExampleMod to ForgeMod. Added implemented missing Utils for Forge from PlayerList --- .../java/de/hype/bbsentials/forge/BBUtils.java | 31 ++++++++------ .../CommandImplementations/CommandOpenConfig.java | 4 +- .../java/de/hype/bbsentials/forge/DebugThread.java | 3 +- .../java/de/hype/bbsentials/forge/ExampleMod.java | 48 ---------------------- .../java/de/hype/bbsentials/forge/ForgeMod.java | 46 +++++++++++++++++++++ 5 files changed, 68 insertions(+), 64 deletions(-) delete mode 100644 forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java (limited to 'forge') 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 c7d2e22..e50ef3b 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/BBUtils.java @@ -1,16 +1,20 @@ 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.Islands; import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.server.gui.PlayerListComponent; +import java.util.Iterator; import java.util.List; public class BBUtils implements de.hype.bbsentials.common.mclibraries.BBUtils { public Islands getCurrentIsland() { try { - String string = Minecraft.getMinecraft().getNetHandler().getPlayerInfo("!C-b").getDisplayName().getUnformattedText(); + String string = getTabListPlayerName("!C-b"); if (!string.startsWith("Area: ")) { Chat.sendPrivateMessageToSelfError("Could not get Area data. Are you in Skyblock?"); } @@ -22,14 +26,15 @@ public class BBUtils implements de.hype.bbsentials.common.mclibraries.BBUtils { return null; } + public static String getTabListPlayerName(String id) { + return Minecraft.getMinecraft().getNetHandler().getPlayerInfo(id).getDisplayName().getUnformattedText(); + } public int getPlayerCount() { -// return Integer.parseInt(MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!B-a").getDisplayName().getString().trim().replaceAll("[^0-9]", "")); - return 0; + return Integer.parseInt(getTabListPlayerName("!B-a").trim().replaceAll("[^0-9]", "")); } public String getServer() { -// return MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!C-c").getDisplayName().getString().replace("Server:", "").trim(); - return "mini0b"; + return getTabListPlayerName("!C-c").replace("Server:", "").trim(); } public boolean isOnMegaServer() { @@ -53,14 +58,14 @@ public class BBUtils implements de.hype.bbsentials.common.mclibraries.BBUtils { public List getPlayers() { List list = Lists.newArrayList(); -// Iterator var2 = MinecraftClient.getInstance().getNetworkHandler().getPlayerList().iterator(); -// while (var2.hasNext()) { -// PlayerListEntry playerListEntry = (PlayerListEntry) var2.next(); -// String playerName = playerListEntry.getProfile().getName(); -// if (!playerName.startsWith("!")) { -// list.add(playerName); -// } -// } + Iterator var2 = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().iterator(); + while (var2.hasNext()) { + NetworkPlayerInfo playerListEntry = (NetworkPlayerInfo) var2.next(); + String playerName = playerListEntry.getDisplayName().getUnformattedText(); + if (!playerName.startsWith("!")) { + list.add(playerName); + } + } return list; } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandOpenConfig.java b/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandOpenConfig.java index acdc683..40fb418 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandOpenConfig.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/CommandImplementations/CommandOpenConfig.java @@ -1,6 +1,6 @@ package de.hype.bbsentials.forge.CommandImplementations; -import de.hype.bbsentials.forge.ExampleMod; +import de.hype.bbsentials.forge.ForgeMod; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; @@ -19,7 +19,7 @@ public class CommandOpenConfig extends CommandBase { @Override public void processCommand(ICommandSender sender, String[] args) { - ExampleMod.config.openConfigGui(); + ForgeMod.config.openConfigGui(); } @Override 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 6fb61fb..111eff5 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/DebugThread.java @@ -6,11 +6,12 @@ import java.util.List; public class DebugThread implements de.hype.bbsentials.common.client.DebugThread { @Override public void loop() { - + test(); } @Override public List test() { + ForgeMod.config.openConfigGui(); return Collections.singletonList(""); } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java b/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java deleted file mode 100644 index 1202036..0000000 --- a/forge/src/main/java/de/hype/bbsentials/forge/ExampleMod.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.hype.bbsentials.forge; - -import de.hype.bbsentials.common.client.BBsentials; -import de.hype.bbsentials.common.mclibraries.EnvironmentCore; -import de.hype.bbsentials.forge.client.MoulConfig; -import io.github.moulberry.moulconfig.gui.MoulConfigEditor; -import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -@Mod(modid = "bbsentials", useMetadata = true) -public class ExampleMod { - static boolean alreadyInialised = false; - static BBsentials sentials = new BBsentials(); - public static MoulConfig config = new MoulConfig(); - - @Mod.EventHandler - public void init(FMLInitializationEvent event) { - printLocation(); - EnvironmentCore core = new EnvironmentCore(new BBUtils(), new ForgeChat(), new MCUtils(), new Commands(), new Options(), new DebugThread()); - BBsentials.init(); - MinecraftForge.EVENT_BUS.register(this); - } - public void printLocation() { -// try { -// // Get the URL of the JAR file containing the class -// URL jarUrl = this.getClass().getProtectionDomain().getCodeSource().getLocation(); -// -// // Convert the URL to a URI -// File jarFile = new File(jarUrl.toURI()); -// -// // Get the absolute path of the JAR file -// String jarPath = jarFile.getAbsolutePath(); -// -//// throw new RuntimeException(jarPath); -// } catch (URISyntaxException e) { -// e.printStackTrace(); -// } - } - @SubscribeEvent - public void onEntityJoinWorld(EntityJoinWorldEvent event) { - BBsentials.onServerSwap(); - } -} - diff --git a/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java b/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java new file mode 100644 index 0000000..f39dcfc --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/ForgeMod.java @@ -0,0 +1,46 @@ +package de.hype.bbsentials.forge; + +import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.common.mclibraries.EnvironmentCore; +import de.hype.bbsentials.forge.client.MoulConfig; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +@Mod(modid = "bbsentials", useMetadata = true) +public class ForgeMod { + static boolean alreadyInialised = false; + static BBsentials sentials = new BBsentials(); + public static MoulConfig config = new MoulConfig(); + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + printLocation(); + EnvironmentCore core = new EnvironmentCore(new BBUtils(), new ForgeChat(), new MCUtils(), new Commands(), new Options(), new DebugThread()); + BBsentials.init(); + MinecraftForge.EVENT_BUS.register(this); + } + public void printLocation() { +// try { +// // Get the URL of the JAR file containing the class +// URL jarUrl = this.getClass().getProtectionDomain().getCodeSource().getLocation(); +// +// // Convert the URL to a URI +// File jarFile = new File(jarUrl.toURI()); +// +// // Get the absolute path of the JAR file +// String jarPath = jarFile.getAbsolutePath(); +// +//// throw new RuntimeException(jarPath); +// } catch (URISyntaxException e) { +// e.printStackTrace(); +// } + } + @SubscribeEvent + public void onEntityJoinWorld(EntityJoinWorldEvent event) { + BBsentials.onServerSwap(); + } +} + -- cgit