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..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,11 +4,11 @@ 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; 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; @@ -24,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; @@ -35,11 +37,10 @@ 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; +import static net.minecraft.command.CommandSource.suggestMatching; public class CrystalsLocationsManager { private static final Logger LOGGER = LogUtils.getLogger(); @@ -101,26 +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()) - .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"))) + ) ) ) - ) ); } - 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; @@ -159,6 +168,21 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin return Command.SINGLE_SUCCESS; } + public static int shareWaypoint(String place) { + if (activeWaypoints.containsKey(place)) { + 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; + } + 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; + } + 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 c3b8c92e0a..aee38317f8 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",