From 72f269cc871c252c72ce52d553ca7ff2e74dfda4 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 8 Apr 2024 16:45:41 +0100 Subject: [PATCH 1/2] add ability to share crystal waypoint locations --- .../dwarven/CrystalsLocationsManager.java | 27 +++++++++++++++++++ .../assets/skyblocker/lang/en_us.json | 1 + 2 files changed, 28 insertions(+) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index f43574ab7e..560cb1a398 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -9,6 +9,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.scheduler.MessageScheduler; import de.hysky.skyblocker.utils.scheduler.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -40,6 +41,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; +import static net.minecraft.command.CommandSource.suggestMatching; public class CrystalsLocationsManager { private static final Logger LOGGER = LogUtils.getLogger(); @@ -113,9 +115,16 @@ private static void registerWaypointLocationCommands(CommandDispatcher suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class))) ) ) + .then(literal("share") + .then(argument("place",StringArgumentType.greedyString()) + .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) + .executes(context -> shareWaypoint(getString(context, "place"))) + ) + ) ) ); } @@ -159,6 +168,24 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin return Command.SINGLE_SUCCESS; } + public static int shareWaypoint(String place) { + if (activeWaypoints.containsKey(place)) { + BlockPos location = activeWaypoints.get(place).pos; + MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString()+ " " + place + ": " + location.getX() + ", " + location.getY() + ", " + location.getZ()); + } + else { + //send fail message + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { + return 0; + } + MutableText failMessage = Constants.PREFIX.get(); + failMessage.append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail").withColor(Color.RED.getRGB())); + CLIENT.player.sendMessage(failMessage, false); + } + + return Command.SINGLE_SUCCESS; + } + private static void addCustomWaypoint(String waypointName, BlockPos pos) { CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 84409b9fe7..cb3c265bc7 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -344,6 +344,7 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled.@Tooltip": "Show a waypoint (waypoint selected in general/waypoints) at important areas in the crystal hollows e.g. Jungle Temple and Fairy Grotto. ", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat": "Find Waypoints In Chat", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat.@Tooltip": "When in crystal hollows read the chat to see if coordinates are sent and extract these to show as waypoint or on the map", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail": "Can only share waypoints you have found.", "text.autoconfig.skyblocker.option.locations.rift": "The Rift", "text.autoconfig.skyblocker.option.locations.rift.mirrorverseWaypoints": "Enable Mirrorverse Waypoints", From b945f1580a0c3b141f53153d04a52a788580289c Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:03:03 -0400 Subject: [PATCH 2/2] Refactor CrystalsLocationsManager --- .../dwarven/CrystalsLocationsManager.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index 560cb1a398..9c37de51d2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -4,7 +4,6 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.logging.LogUtils; - import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; @@ -25,7 +24,9 @@ import net.minecraft.text.ClickEvent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; +import org.slf4j.Logger; import java.awt.*; import java.util.Arrays; @@ -36,8 +37,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.slf4j.Logger; - import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; @@ -103,33 +102,34 @@ private static void extractLocationFromMessage(Text message, Boolean overlay) { LOGGER.error("[Skyblocker Crystals Locations Manager] Encountered an exception while extracing a location from a chat message!", e); } } - protected static Boolean checkInCrystals(BlockPos pos){ + + protected static Boolean checkInCrystals(BlockPos pos) { //checks if a location is inside crystal hollows bounds return pos.getX() >= 202 && pos.getX() <= 823 && pos.getZ() >= 202 && pos.getZ() <= 823 - && pos.getY() >= 31 && pos.getY() <= 188; + && pos.getY() >= 31 && pos.getY() <= 188; } private static void registerWaypointLocationCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(literal(SkyblockerMod.NAMESPACE) - .then(literal("crystalWaypoints") - .then(argument("pos", BlockPosArgumentType.blockPos()) - .then(argument("place", StringArgumentType.greedyString()) - .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) - .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class))) + .then(literal("crystalWaypoints") + .then(argument("pos", BlockPosArgumentType.blockPos()) + .then(argument("place", StringArgumentType.greedyString()) + .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) + .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class))) + ) ) - ) - .then(literal("share") - .then(argument("place",StringArgumentType.greedyString()) - .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) - .executes(context -> shareWaypoint(getString(context, "place"))) + .then(literal("share") + .then(argument("place", StringArgumentType.greedyString()) + .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) + .executes(context -> shareWaypoint(getString(context, "place"))) + ) ) ) - ) ); } - protected static Text getSetLocationMessage(String location,BlockPos blockPos) { + protected static Text getSetLocationMessage(String location, BlockPos blockPos) { MutableText text = Constants.PREFIX.get(); text.append(Text.literal("Added waypoint for ")); Color locationColor = WAYPOINT_LOCATIONS.get(location).color; @@ -170,17 +170,14 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin public static int shareWaypoint(String place) { if (activeWaypoints.containsKey(place)) { - BlockPos location = activeWaypoints.get(place).pos; - MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString()+ " " + place + ": " + location.getX() + ", " + location.getY() + ", " + location.getZ()); - } - else { + BlockPos pos = activeWaypoints.get(place).pos; + MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ()); + } else { //send fail message if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { return 0; } - MutableText failMessage = Constants.PREFIX.get(); - failMessage.append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail").withColor(Color.RED.getRGB())); - CLIENT.player.sendMessage(failMessage, false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail").formatted(Formatting.RED)), false); } return Command.SINGLE_SUCCESS;