diff --git a/src/main/java/net/asodev/islandutils/mixins/ui/FishingUpgradeHighlightMixin.java b/src/main/java/net/asodev/islandutils/mixins/ui/FishingUpgradeHighlightMixin.java index 82dac229..92a08651 100644 --- a/src/main/java/net/asodev/islandutils/mixins/ui/FishingUpgradeHighlightMixin.java +++ b/src/main/java/net/asodev/islandutils/mixins/ui/FishingUpgradeHighlightMixin.java @@ -2,28 +2,19 @@ import net.asodev.islandutils.modules.FishingUpgradeIcon; import net.asodev.islandutils.options.IslandOptions; -import net.asodev.islandutils.state.Game; -import net.asodev.islandutils.state.MccIslandState; -import net.asodev.islandutils.util.Utils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.Slot; 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; -import java.util.List; - @Mixin(AbstractContainerScreen.class) public class FishingUpgradeHighlightMixin { @Inject(method = "renderSlot", at = @At(value = "TAIL")) private void renderSlot(GuiGraphics guiGraphics, Slot slot, CallbackInfo ci) { if (!slot.hasItem() || !IslandOptions.getMisc().isShowFishingUpgradeIcon()) return; - if (MccIslandState.getGame() != Game.FISHING) return; FishingUpgradeIcon.render(slot, guiGraphics); } } diff --git a/src/main/java/net/asodev/islandutils/state/Game.java b/src/main/java/net/asodev/islandutils/state/Game.java index 74ee8585..8c7cb668 100644 --- a/src/main/java/net/asodev/islandutils/state/Game.java +++ b/src/main/java/net/asodev/islandutils/state/Game.java @@ -1,15 +1,19 @@ package net.asodev.islandutils.state; import com.noxcrew.noxesium.network.clientbound.ClientboundMccServerPacket; -import net.asodev.islandutils.discord.FishingPresenceUpdator; +import net.asodev.islandutils.options.IslandOptions; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.NoSuchElementException; public enum Game { - HUB("Hub", "", null), - FISHING("Hub", "", null), + HUB("Hub", ""), + FISHING("Fishing", ""), TGTTOS("TGTTOS", "tgttos", getMusicLocation("tgttos")), HITW("Hole in the Wall", "hole_in_the_wall", getMusicLocation("hitw")), @@ -20,32 +24,38 @@ public enum Game { ROCKET_SPLEEF_RUSH("Rocket Spleef Rush", "rocket_spleef", getMusicLocation("rsr")), SKY_BATTLE("Sky Battle", "sky_battle", getMusicLocation("sky_battle"), true); - final private String name; - final private String islandId; - final private String subType; - final private ResourceLocation musicLocation; - private boolean hasTeamChat = false; - Game(String name, String islandId, ResourceLocation location) { - this.name = name; - this.islandId = islandId; - this.subType = null; - this.musicLocation = location; + public static final Logger logger = LoggerFactory.getLogger(Game.class); + + private final @NotNull String name; + private final @Nullable String islandId; + private final @Nullable String subType; + private final @Nullable ResourceLocation musicLocation; + private final boolean hasTeamChat; + + Game(@NotNull String name, @Nullable String islandId) { + this(name, islandId, null, null, false); } - Game(String name, String islandId, ResourceLocation location, boolean hasTeamChat) { - this(name, islandId, location); - this.hasTeamChat = hasTeamChat; + Game(@NotNull String name, @Nullable String islandId, @Nullable ResourceLocation musicLocation) { + this(name, islandId, null, musicLocation, false); + } + Game(@NotNull String name, @Nullable String islandId, @Nullable ResourceLocation musicLocation, boolean hasTeamChat) { + this(name, islandId, null, musicLocation, hasTeamChat); } - Game(String name, String islandId, String subType, ResourceLocation location) { + Game(@NotNull String name, @Nullable String islandId, @Nullable String subType, @Nullable ResourceLocation musicLocation) { + this(name, islandId, subType, musicLocation, false); + } + Game(@NotNull String name, @Nullable String islandId, @Nullable String subType, @Nullable ResourceLocation musicLocation, boolean hasTeamChat) { this.name = name; this.islandId = islandId; this.subType = subType; - this.musicLocation = location; + this.musicLocation = musicLocation; + this.hasTeamChat = hasTeamChat; } - public String getName() { + public @NotNull String getName() { return name; } - public ResourceLocation getMusicLocation() { + public @Nullable ResourceLocation getMusicLocation() { return musicLocation; } public boolean hasTeamChat() { @@ -57,15 +67,19 @@ public static ResourceLocation getMusicLocation(String name) { } public static Game fromPacket(ClientboundMccServerPacket packet) throws NoSuchElementException { + if (IslandOptions.getMisc().isDebugMode()) { + logger.info("Game::fromPacket: serverType = {}, associatedGame = {}, subType = {}", + packet.serverType(), packet.associatedGame(), packet.subType()); + } + if (packet.serverType().equals("lobby")) { - for (String temperature : FishingPresenceUpdator.temperatures) { - if (packet.subType().startsWith(temperature + "_")) return FISHING; - } return HUB; + } else if (packet.serverType().equals("fishing")) { + return FISHING; } for (Game game : values()) { - if (game.islandId.equals(packet.associatedGame())) { + if (game.islandId != null && game.islandId.equals(packet.associatedGame())) { if (game.subType != null && !game.subType.equals(packet.subType())) continue; return game; diff --git a/src/main/java/net/asodev/islandutils/state/MccIslandState.java b/src/main/java/net/asodev/islandutils/state/MccIslandState.java index 16c75140..7cb69d61 100644 --- a/src/main/java/net/asodev/islandutils/state/MccIslandState.java +++ b/src/main/java/net/asodev/islandutils/state/MccIslandState.java @@ -2,11 +2,8 @@ import net.asodev.islandutils.IslandUtilsEvents; import net.asodev.islandutils.util.ChatUtils; -import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextColor; public class MccIslandState { @@ -35,43 +32,6 @@ public static void setGame(Game game) { IslandUtilsEvents.GAME_UPDATE.invoker().onGameUpdate(game); } - public static void updateGame(Component displayName, String tablistTitle) { - String title = displayName.getString(); - - // Check for PKW Tablist Titles - if (tablistTitle.contains("PARKOUR WARRIOR SURVIVOR")) { - MccIslandState.setGame(Game.PARKOUR_WARRIOR_SURVIVOR); - return; - } else if (tablistTitle.contains("Parkour Warrior - ")) { - MccIslandState.setGame(Game.PARKOUR_WARRIOR_DOJO); - return; - } - - if (!isGameDisplayName(displayName)) { - MccIslandState.setGame(Game.HUB); - } else { // We're in a game!!! - // These checks are pretty self-explanatory - if (title.contains("HOLE IN THE WALL")) { - MccIslandState.setGame(Game.HITW); - } else if (title.contains("TGTTOS")) { - MccIslandState.setGame(Game.TGTTOS); - } else if (title.contains("SKY BATTLE")) { - MccIslandState.setGame(Game.SKY_BATTLE); - } else if (title.contains("BATTLE BOX")) { - MccIslandState.setGame(Game.BATTLE_BOX); - } else { - MccIslandState.setGame(Game.HUB); // Somehow we're in a game, but not soooo hub it is!! - } - } - } - static TextColor aqua = TextColor.fromLegacyFormat(ChatFormatting.AQUA); - private static boolean isGameDisplayName(Component component) { - for (Component sibling : component.getSiblings()) { // Get all the elements of this component - if (sibling.getStyle().getColor() == aqua) return true; // If it's aqua, YES - } - return false; // If not... no :( - } - public static void setMap(String map) { MccIslandState.map = map; }