From 4bc16379b879bb7e52ab891a52a14079d0244d5d Mon Sep 17 00:00:00 2001 From: Sleepy Evelyn <46009144+sleepy-evelyn@users.noreply.github.com> Date: Mon, 25 Nov 2024 08:31:30 +0000 Subject: [PATCH] Can now get an OPAC claim uuid from a user --- build.gradle.kts | 3 ++ .../commands/RailwaysTweaksCommands.java | 38 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d920fea..82209a2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -69,6 +69,9 @@ dependencies { } modCompileOnly("maven.modrinth:enchancement:1.20-26") + + // OPAC API + modApi("maven.modrinth:open-parties-and-claims:fabric-1.20.1-0.23.2") } tasks.processResources { diff --git a/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java b/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java index 5fb2757..501c7d2 100644 --- a/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java +++ b/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java @@ -1,6 +1,8 @@ package dev.ithundxr.railwaystweaks.commands; +import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; import com.simibubi.create.Create; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import dev.ithundxr.railwaystweaks.RailwaysTweaks; @@ -9,13 +11,14 @@ import me.pepperbell.simplenetworking.S2CPacket; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.UuidArgument; import net.minecraft.network.chat.Component; import slimeknights.tconstruct.common.network.TinkerNetwork; +import xaero.pac.common.server.api.OpenPACServerAPI; +import xaero.pac.common.server.parties.party.api.IServerPartyAPI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static net.minecraft.commands.Commands.literal; @@ -36,6 +39,18 @@ public static void init() { .requires(cs -> cs.hasPermission(2)) .executes(ctx -> avgMSPT(ctx.getSource()))); }); + + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal("railwaystweaks") + .then( + literal("opac-party") + .then(Commands.argument("player_uuid", UuidArgument.uuid()) + .executes(RailwaysTweaksCommands::getPlayerPartyName) + ) + ) + ); + }); + } private static ArgumentBuilder $dump_hephaestus_packets() { @@ -109,4 +124,19 @@ private static int avgMSPT(CommandSourceStack source) { source.sendSuccess(() -> Component.literal("Average MSPT (10s): " + String.format("%.1f", RailwaysTweaks.MSPT_TRACKER.getAverageMSPT())), true); return 0; } + + private static int getPlayerPartyName(CommandContext ctx) { + UUID uuid = UuidArgument.getUuid(ctx, "player_uuid"); + + OpenPACServerAPI api = OpenPACServerAPI.get(ctx.getSource().getServer()); + IServerPartyAPI partyAPI = api.getPartyManager().getPartyByMember(uuid); + + if (partyAPI != null) { + ctx.getSource().sendSuccess(() -> Component.literal(partyAPI.getDefaultName() + "\n" + partyAPI.getId()), true); + return 0; + } else { + ctx.getSource().sendFailure(Component.literal("Failed to get a party uuid from this player")); + return 1; + } + } }