diff --git a/src/main/java/cc/fascinated/wildaddons/WildAddons.java b/src/main/java/cc/fascinated/wildaddons/Main.java similarity index 64% rename from src/main/java/cc/fascinated/wildaddons/WildAddons.java rename to src/main/java/cc/fascinated/wildaddons/Main.java index 3abc3eb..bf570c1 100644 --- a/src/main/java/cc/fascinated/wildaddons/WildAddons.java +++ b/src/main/java/cc/fascinated/wildaddons/Main.java @@ -2,22 +2,23 @@ package cc.fascinated.wildaddons; import lombok.Getter; import net.fabricmc.api.ModInitializer; +import net.minecraft.client.MinecraftClient; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -public class WildAddons implements ModInitializer { +public class Main implements ModInitializer { - public static final Logger LOGGER = LogManager.getLogger(WildAddons.class); + public static final Logger LOGGER = LogManager.getLogger(Main.class); @Getter private static final ExecutorService executorService = Executors.newCachedThreadPool(); + @Getter private static final MinecraftClient minecraftClient = MinecraftClient.getInstance(); /** * Runs the mod initializer. */ @Override public void onInitialize() { - } } diff --git a/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java b/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java index a4cca4e..2cc2173 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/AddonManager.java @@ -7,6 +7,9 @@ import java.util.Set; public class AddonManager { + /** + * The current registered addons + */ public static final Set ADDONS = new HashSet<>(); public AddonManager() { diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomer.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomer.java index 4950c71..05cae48 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomer.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/chat/AutoWelcomer.java @@ -1,13 +1,11 @@ package cc.fascinated.wildaddons.addon.impl.chat; -import cc.fascinated.wildaddons.WildAddons; +import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.Addon; import cc.fascinated.wildaddons.listener.PlayerListener; import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.utils.PlayerUtils; import net.minecraft.client.MinecraftClient; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.gui.PlayerListGui; import java.util.concurrent.ThreadLocalRandom; @@ -32,10 +30,10 @@ public class AutoWelcomer extends Addon { String name = parts[2]; // No need to welcome ourselves - if (MinecraftClient.getInstance().player.getName().getString().equals(name)) { + if (Main.getMinecraftClient().player.getName().getString().equals(name)) { return; } - WildAddons.getExecutorService().execute(() -> { + Main.getExecutorService().execute(() -> { try { // Sleep the thread for a randomized amount of time to make it look less suspicious Thread.sleep(ThreadLocalRandom.current().nextLong(600, 2000)); diff --git a/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java b/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java index 11a712d..d3ab6b5 100644 --- a/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java +++ b/src/main/java/cc/fascinated/wildaddons/listener/PlayerListener.java @@ -1,5 +1,6 @@ package cc.fascinated.wildaddons.listener; +import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.event.EventListener; import cc.fascinated.wildaddons.utils.PlayerUtils; import net.minecraft.client.MinecraftClient; @@ -17,7 +18,7 @@ public class PlayerListener implements EventListener { if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild return; } - ClientPlayerEntity player = MinecraftClient.getInstance().player; + ClientPlayerEntity player = Main.getMinecraftClient().player; if (player == null) { return; } diff --git a/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java b/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java index 4173235..679bc65 100644 --- a/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java +++ b/src/main/java/cc/fascinated/wildaddons/mixin/MinecraftClientMixin.java @@ -1,5 +1,6 @@ package cc.fascinated.wildaddons.mixin; +import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.event.EventListener; import cc.fascinated.wildaddons.event.EventManager; import cc.fascinated.wildaddons.utils.PlayerUtils; @@ -17,6 +18,9 @@ public class MinecraftClientMixin { if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild return; } + if (Main.getMinecraftClient().player == null) { + return; + } for (EventListener listener : EventManager.getListeners()) { listener.onTick(); } diff --git a/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java b/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java index 657e6fe..2e61215 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/PlayerUtils.java @@ -1,19 +1,18 @@ package cc.fascinated.wildaddons.utils; +import cc.fascinated.wildaddons.Main; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ServerInfo; public class PlayerUtils { - private static final MinecraftClient minecraftClient = MinecraftClient.getInstance(); - /** * Sends a chat message as the player. * * @param message the message to send */ public static void sendMessage(String message) { - minecraftClient.player.networkHandler.sendChatMessage(message); + Main.getMinecraftClient().player.networkHandler.sendChatMessage(message); } /** @@ -24,7 +23,7 @@ public class PlayerUtils { * @return true if same, otherwise false */ public static boolean onServer(String... ips) { - ServerInfo currentServerEntry = minecraftClient.getCurrentServerEntry(); + ServerInfo currentServerEntry = Main.getMinecraftClient().getCurrentServerEntry(); if (currentServerEntry == null) { return false; } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a75781a..8cf58ef 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -15,7 +15,7 @@ "cc.fascinated.wildaddons.client.WildAddonsClient" ], "main": [ - "cc.fascinated.wildaddons.WildAddons" + "cc.fascinated.wildaddons.Main" ] }, "mixins": [