diff --git a/common/src/main/java/coffee/waffle/emcutils/Util.java b/common/src/main/java/coffee/waffle/emcutils/Util.java index c4e07ee..b53cadf 100644 --- a/common/src/main/java/coffee/waffle/emcutils/Util.java +++ b/common/src/main/java/coffee/waffle/emcutils/Util.java @@ -1,6 +1,8 @@ package coffee.waffle.emcutils; import coffee.waffle.emcutils.container.EmpireServer; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,11 +18,30 @@ public class Util { public static final String MODID = "emcutils"; public static final Logger LOG = LoggerFactory.getLogger(MODID); - public static boolean isOnEMC = false; public static EmpireServer currentServer; public static String onJoinCommand; public static int playerGroupId = 0; + public static boolean isOnEMC() { + if (MinecraftClient.getInstance().isInSingleplayer()) { + return false; + } + + ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); + + if (networkHandler == null) { + return false; + } + + if (networkHandler.getConnection() == null) { + return false; + } + + String address = networkHandler.getConnection().getAddressAsString(true); + + return address.contains("emc.gs") || address.contains("empire.us") || address.contains("empireminecraft.com"); + } + public static void setCurrentServer(String name) { if (name.equalsIgnoreCase("utop")) name = "utopia"; for (EmpireServer server : EmpireServer.values()) { diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/ChatChannels.java b/common/src/main/java/coffee/waffle/emcutils/feature/ChatChannels.java index eca7f02..73d581a 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/ChatChannels.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/ChatChannels.java @@ -24,7 +24,7 @@ public class ChatChannels { private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; public static void handleChatScreenRender(Screen screen, DrawContext context) { - if (Util.isOnEMC && Config.chatButtonsEnabled()) { + if (Util.isOnEMC() && Config.chatButtonsEnabled()) { for (ChatChannel channel : ChatChannel.values()) { if (channel == ChatChannel.SUPPORTER && Util.playerGroupId < 2) break; if (channel == ChatChannel.MODERATOR && Util.playerGroupId < 5) break; @@ -36,7 +36,7 @@ public static void handleChatScreenRender(Screen screen, DrawContext context) { } public static void handleChatScreenMouseClicked(Screen screen, double mouseX, double mouseY) { - if (Util.isOnEMC && Config.chatButtonsEnabled()) { + if (Util.isOnEMC() && Config.chatButtonsEnabled()) { for (ChatChannel channel : ChatChannel.values()) { if (channel == ChatChannel.SUPPORTER && Util.playerGroupId < 2) break; if (channel == ChatChannel.MODERATOR && Util.playerGroupId < 5) break; diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/TabListOrganizer.java b/common/src/main/java/coffee/waffle/emcutils/feature/TabListOrganizer.java index d203180..e8b30f4 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/TabListOrganizer.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/TabListOrganizer.java @@ -16,7 +16,7 @@ public static List sortPlayers(List original) List enhanced = Lists.newArrayList(); List currentServer = Lists.newArrayList(); - if (!Util.isOnEMC) { + if (!Util.isOnEMC()) { return original; } diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java index 062dcbf..3b6b139 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java @@ -3,7 +3,6 @@ import coffee.waffle.emcutils.Util; import coffee.waffle.emcutils.event.TooltipCallback; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.minecraft.component.DataComponentTypes; @@ -16,7 +15,7 @@ public class UsableItems { public static void init() { TooltipCallback.ITEM.register((itemStack, list, tooltipContext, type) -> { - if (!Util.isOnEMC || !isUsableItemWithCooldown(itemStack)) return; + if (!Util.isOnEMC() || !isUsableItemWithCooldown(itemStack)) return; for (Text text : list) { if (text.getString().startsWith("Usable in: ") || diff --git a/common/src/main/java/coffee/waffle/emcutils/mixin/ClientPlayNetworkHandlerMixin.java b/common/src/main/java/coffee/waffle/emcutils/mixin/ClientPlayNetworkHandlerMixin.java index 158e413..9498309 100644 --- a/common/src/main/java/coffee/waffle/emcutils/mixin/ClientPlayNetworkHandlerMixin.java +++ b/common/src/main/java/coffee/waffle/emcutils/mixin/ClientPlayNetworkHandlerMixin.java @@ -41,7 +41,7 @@ abstract class ClientPlayNetworkHandlerMixin { @Inject(at = @At("TAIL"), method = "onGameJoin") void emcutils$onJoinEMC(GameJoinS2CPacket packet, CallbackInfo info) { - if (Util.isOnEMC && !emcutils$online) { + if (Util.isOnEMC() && !emcutils$online) { ChatListener.init(); CommandListener.init(); UsableItems.init(); @@ -52,7 +52,7 @@ abstract class ClientPlayNetworkHandlerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreens;open(Lnet/minecraft/screen/ScreenHandlerType;Lnet/minecraft/client/MinecraftClient;ILnet/minecraft/text/Text;)V"), method = "onOpenScreen", cancellable = true) void emcutils$changeToVaultScreen(OpenScreenS2CPacket packet, CallbackInfo ci) { - if (Util.isOnEMC && packet.getName().getString().startsWith("Page: ") && packet.getScreenHandlerType() == ScreenHandlerType.GENERIC_9X6) { + if (Util.isOnEMC() && packet.getName().getString().startsWith("Page: ") && packet.getScreenHandlerType() == ScreenHandlerType.GENERIC_9X6) { var pageTitle = packet.getName().copy(); if (pageTitle.getString().split(" ")[1].contains("69")) { pageTitle = pageTitle.append(Text.of(" ... nice")); diff --git a/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java b/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java deleted file mode 100644 index 82d56b5..0000000 --- a/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package coffee.waffle.emcutils.mixin; - -import coffee.waffle.emcutils.Util; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.multiplayer.ConnectScreen; -import net.minecraft.client.network.CookieStorage; -import net.minecraft.client.network.ServerAddress; -import net.minecraft.client.network.ServerInfo; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ConnectScreen.class) -abstract class ConnectScreenMixin { - @Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;Lnet/minecraft/client/network/CookieStorage;)V", at = @At("HEAD")) - void emcutils$onConnect(MinecraftClient client, ServerAddress address, ServerInfo info, CookieStorage cs, CallbackInfo ci) { - Util.isOnEMC = address.getAddress().matches("(.*\\.)?(emc\\.gs|empire\\.us|empireminecraft\\.com)"); - } -} diff --git a/common/src/main/java/coffee/waffle/emcutils/mixin/PlayerEntityMixin.java b/common/src/main/java/coffee/waffle/emcutils/mixin/PlayerEntityMixin.java index 0298fc7..24a33db 100644 --- a/common/src/main/java/coffee/waffle/emcutils/mixin/PlayerEntityMixin.java +++ b/common/src/main/java/coffee/waffle/emcutils/mixin/PlayerEntityMixin.java @@ -18,7 +18,7 @@ abstract class PlayerEntityMixin { private void emcutils$getDisplayName(CallbackInfoReturnable cir) { if (MinecraftClient.getInstance().isInSingleplayer()) return; // Don't run anything for singleplayer - if (Util.isOnEMC) { + if (Util.isOnEMC()) { PlayerEntity e = ((PlayerEntity) (Object) this); try { diff --git a/common/src/main/resources/emcutils-common.mixins.json b/common/src/main/resources/emcutils-common.mixins.json index e368849..cdb1d78 100644 --- a/common/src/main/resources/emcutils-common.mixins.json +++ b/common/src/main/resources/emcutils-common.mixins.json @@ -6,10 +6,9 @@ "client": [ "ChatScreenMixin", "ClientPlayNetworkHandlerMixin", - "ConnectScreenMixin", "IdentifierMixin", - "PlayerListHudMixin", - "PlayerEntityMixin" + "PlayerEntityMixin", + "PlayerListHudMixin" ], "injectors": { "defaultRequire": 1 diff --git a/gradle.properties b/gradle.properties index 27363ec..11f4086 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G org.gradle.parallel=true -mod_version=9.0.1 +mod_version=9.0.2 diff --git a/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java b/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java index 68d37d1..cc489f4 100644 --- a/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java +++ b/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java @@ -26,7 +26,7 @@ public void initialize(@NotNull final IClientAPI api) { LOG.info(MODID + " found JourneyMap - enabling integrations"); ClientEventRegistry.MAPPING_EVENT.subscribe(MODID, event -> { - if (event.getStage() == MappingEvent.Stage.MAPPING_STARTED && Util.isOnEMC) { + if (event.getStage() == MappingEvent.Stage.MAPPING_STARTED && Util.isOnEMC()) { // Disable cave maps on EMC assert client.world != null; if (!client.world.getRegistryKey().getValue().getPath().contains("nether")) { @@ -42,12 +42,12 @@ public void initialize(@NotNull final IClientAPI api) { // Turn off radars on EMC ClientEventRegistry.ENTITY_RADAR_UPDATE_EVENT.subscribe(MODID, event -> { - if (Util.isOnEMC) event.cancel(); + if (Util.isOnEMC()) event.cancel(); }); // Add residence TP button ClientEventRegistry.FULLSCREEN_POPUP_MENU_EVENT.subscribe(MODID, event -> { - if (Util.isOnEMC) event.getPopupMenu().addMenuItem("Teleport to Residence", new TeleportToResidenceAction()); + if (Util.isOnEMC()) event.getPopupMenu().addMenuItem("Teleport to Residence", new TeleportToResidenceAction()); }); } @@ -59,7 +59,7 @@ public String getModId() { private static class TeleportToResidenceAction implements ModPopupMenu.Action { @Override public void doAction(final @NotNull BlockPos pos) { - if (Util.isOnEMC) { + if (Util.isOnEMC()) { EmpireResidence res = Util.currentServer.getResidenceByLoc(new Vec3d(pos.getX(), pos.getY(), pos.getZ())); if (res != null) MinecraftClient.getInstance().player.networkHandler.sendCommand(res.visitCommand); } diff --git a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/GuiMapNameMixin.java b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/GuiMapNameMixin.java index fab734b..7b49ae2 100644 --- a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/GuiMapNameMixin.java +++ b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/GuiMapNameMixin.java @@ -19,6 +19,6 @@ abstract class GuiMapNameMixin { public void emcutils$xaero$setSubworldName(CallbackInfo ci) { var server = Util.currentServer.name.toLowerCase(); var world = MinecraftClient.getInstance().world.getRegistryKey().getValue().getPath(); - if (Util.isOnEMC) this.currentNameFieldContent = String.format("%s - %s", server, world); + if (Util.isOnEMC()) this.currentNameFieldContent = String.format("%s - %s", server, world); } } diff --git a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/MapTeleporterMixin.java b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/MapTeleporterMixin.java index ac9fd85..a4d9ad3 100644 --- a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/MapTeleporterMixin.java +++ b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/MapTeleporterMixin.java @@ -20,7 +20,7 @@ abstract class MapTeleporterMixin { @Inject(method = "teleport", at = @At(value = "INVOKE_ASSIGN", target = "Lxaero/map/world/MapWorld;getTeleportCommandFormat()Ljava/lang/String;", remap = false), cancellable = true, remap = false) private void emcutils$xaero$enableMapTeleportation(Screen screen, MapWorld mapWorld, int x, int y, int z, RegistryKey d, CallbackInfo ci) { - if (Util.isOnEMC) { + if (Util.isOnEMC()) { EmpireResidence res = Util.currentServer.getResidenceByLoc(new Vec3d(x, y, z)); if (res != null) { diff --git a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/ModSettingsMixin.java b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/ModSettingsMixin.java index 6d406e2..7b51882 100644 --- a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/ModSettingsMixin.java +++ b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/ModSettingsMixin.java @@ -13,11 +13,11 @@ abstract class ModSettingsMixin { @Inject(method = "caveMapsDisabled", at = @At("HEAD"), cancellable = true, remap = false) private void emcutils$xaero$disableCaveMaps(CallbackInfoReturnable cir) { - if (Util.isOnEMC) cir.setReturnValue(true); + if (Util.isOnEMC()) cir.setReturnValue(true); } @Inject(method = "getEntityRadar", at = @At("HEAD"), cancellable = true, remap = false) private void emcutils$xaero$disableRadar(CallbackInfoReturnable cir) { - if (Util.isOnEMC) cir.setReturnValue(false); + if (Util.isOnEMC()) cir.setReturnValue(false); } } diff --git a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/WaypointsManagerMixin.java b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/WaypointsManagerMixin.java index 3c9fe65..1ec2923 100644 --- a/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/WaypointsManagerMixin.java +++ b/xaero/src/main/java/coffee/waffle/emcutils/xaero/mixin/WaypointsManagerMixin.java @@ -20,7 +20,7 @@ abstract class WaypointsManagerMixin { @Inject(method = "teleportToWaypoint(Lxaero/common/minimap/waypoints/Waypoint;Lxaero/common/minimap/waypoints/WaypointWorld;Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At("HEAD"), cancellable = true) public void emcutils$xaero$teleportToResidence(Waypoint w, WaypointWorld world, Screen screen, boolean respectHiddenCoords, CallbackInfo ci) { if (world != null) { - if (Util.isOnEMC) { + if (Util.isOnEMC()) { EmpireResidence res = Util.currentServer.getResidenceByLoc(new Vec3d(w.getX(), 64, w.getZ())); if (res != null) {