This commit is contained in:
Lee 2023-03-06 17:19:11 +00:00
parent f5e8c51ff7
commit 492657c0e4
7 changed files with 20 additions and 14 deletions

@ -2,22 +2,23 @@ package cc.fascinated.wildaddons;
import lombok.Getter; import lombok.Getter;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; 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 ExecutorService executorService = Executors.newCachedThreadPool();
@Getter private static final MinecraftClient minecraftClient = MinecraftClient.getInstance();
/** /**
* Runs the mod initializer. * Runs the mod initializer.
*/ */
@Override @Override
public void onInitialize() { public void onInitialize() {
} }
} }

@ -7,6 +7,9 @@ import java.util.Set;
public class AddonManager { public class AddonManager {
/**
* The current registered addons
*/
public static final Set<Addon> ADDONS = new HashSet<>(); public static final Set<Addon> ADDONS = new HashSet<>();
public AddonManager() { public AddonManager() {

@ -1,13 +1,11 @@
package cc.fascinated.wildaddons.addon.impl.chat; 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.addon.Addon;
import cc.fascinated.wildaddons.listener.PlayerListener; import cc.fascinated.wildaddons.listener.PlayerListener;
import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.statistic.Statistic;
import cc.fascinated.wildaddons.utils.PlayerUtils; import cc.fascinated.wildaddons.utils.PlayerUtils;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.gui.PlayerListGui;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -32,10 +30,10 @@ public class AutoWelcomer extends Addon {
String name = parts[2]; String name = parts[2];
// No need to welcome ourselves // No need to welcome ourselves
if (MinecraftClient.getInstance().player.getName().getString().equals(name)) { if (Main.getMinecraftClient().player.getName().getString().equals(name)) {
return; return;
} }
WildAddons.getExecutorService().execute(() -> { Main.getExecutorService().execute(() -> {
try { try {
// Sleep the thread for a randomized amount of time to make it look less suspicious // Sleep the thread for a randomized amount of time to make it look less suspicious
Thread.sleep(ThreadLocalRandom.current().nextLong(600, 2000)); Thread.sleep(ThreadLocalRandom.current().nextLong(600, 2000));

@ -1,5 +1,6 @@
package cc.fascinated.wildaddons.listener; package cc.fascinated.wildaddons.listener;
import cc.fascinated.wildaddons.Main;
import cc.fascinated.wildaddons.event.EventListener; import cc.fascinated.wildaddons.event.EventListener;
import cc.fascinated.wildaddons.utils.PlayerUtils; import cc.fascinated.wildaddons.utils.PlayerUtils;
import net.minecraft.client.MinecraftClient; 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 if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild
return; return;
} }
ClientPlayerEntity player = MinecraftClient.getInstance().player; ClientPlayerEntity player = Main.getMinecraftClient().player;
if (player == null) { if (player == null) {
return; return;
} }

@ -1,5 +1,6 @@
package cc.fascinated.wildaddons.mixin; package cc.fascinated.wildaddons.mixin;
import cc.fascinated.wildaddons.Main;
import cc.fascinated.wildaddons.event.EventListener; import cc.fascinated.wildaddons.event.EventListener;
import cc.fascinated.wildaddons.event.EventManager; import cc.fascinated.wildaddons.event.EventManager;
import cc.fascinated.wildaddons.utils.PlayerUtils; import cc.fascinated.wildaddons.utils.PlayerUtils;
@ -17,6 +18,9 @@ public class MinecraftClientMixin {
if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild if (!PlayerUtils.isOnWild()) { // Ignore if the player isn't on Wild
return; return;
} }
if (Main.getMinecraftClient().player == null) {
return;
}
for (EventListener listener : EventManager.getListeners()) { for (EventListener listener : EventManager.getListeners()) {
listener.onTick(); listener.onTick();
} }

@ -1,19 +1,18 @@
package cc.fascinated.wildaddons.utils; package cc.fascinated.wildaddons.utils;
import cc.fascinated.wildaddons.Main;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ServerInfo; import net.minecraft.client.network.ServerInfo;
public class PlayerUtils { public class PlayerUtils {
private static final MinecraftClient minecraftClient = MinecraftClient.getInstance();
/** /**
* Sends a chat message as the player. * Sends a chat message as the player.
* *
* @param message the message to send * @param message the message to send
*/ */
public static void sendMessage(String message) { 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 * @return true if same, otherwise false
*/ */
public static boolean onServer(String... ips) { public static boolean onServer(String... ips) {
ServerInfo currentServerEntry = minecraftClient.getCurrentServerEntry(); ServerInfo currentServerEntry = Main.getMinecraftClient().getCurrentServerEntry();
if (currentServerEntry == null) { if (currentServerEntry == null) {
return false; return false;
} }

@ -15,7 +15,7 @@
"cc.fascinated.wildaddons.client.WildAddonsClient" "cc.fascinated.wildaddons.client.WildAddonsClient"
], ],
"main": [ "main": [
"cc.fascinated.wildaddons.WildAddons" "cc.fascinated.wildaddons.Main"
] ]
}, },
"mixins": [ "mixins": [