|
8 | 8 | import com.mojang.brigadier.context.CommandContext; |
9 | 9 | import com.mojang.brigadier.exceptions.CommandSyntaxException; |
10 | 10 | import dev.architectury.platform.Platform; |
| 11 | +import dev.ftb.mods.ftblibrary.FTBLibraryCommands; |
| 12 | +import dev.ftb.mods.ftblibrary.net.EditNBTPacket; |
| 13 | +import dev.ftb.mods.ftblibrary.util.NetworkHelper; |
11 | 14 | import dev.ftb.mods.ftbteams.FTBTeamsAPIImpl; |
12 | 15 | import dev.ftb.mods.ftbteams.api.FTBTeamsAPI; |
13 | 16 | import dev.ftb.mods.ftbteams.api.Team; |
|
17 | 20 | import dev.ftb.mods.ftbteams.api.event.TeamInfoEvent; |
18 | 21 | import dev.ftb.mods.ftbteams.api.property.TeamPropertyArgument; |
19 | 22 | import net.minecraft.ChatFormatting; |
| 23 | +import net.minecraft.Util; |
20 | 24 | import net.minecraft.commands.CommandSourceStack; |
21 | 25 | import net.minecraft.commands.Commands; |
22 | 26 | import net.minecraft.commands.arguments.GameProfileArgument; |
| 27 | +import net.minecraft.nbt.CompoundTag; |
23 | 28 | import net.minecraft.network.chat.Component; |
24 | 29 | import net.minecraft.server.level.ServerPlayer; |
25 | 30 |
|
@@ -196,6 +201,13 @@ public void register(CommandDispatcher<CommandSourceStack> dispatcher) { |
196 | 201 | .executes(FTBTeamsCommands::forceRemovePlayers)) |
197 | 202 | ) |
198 | 203 | ) |
| 204 | + .then(Commands.literal("nbtedit") |
| 205 | + .requires(requiresOPorSP()) |
| 206 | + .executes(this::editPlayerTeamNBT) |
| 207 | + .then(createTeamArg() |
| 208 | + .executes(FTBTeamsCommands::editTeamNBT) |
| 209 | + ) |
| 210 | + ) |
199 | 211 | ); |
200 | 212 |
|
201 | 213 | if (Platform.isDevelopmentEnvironment()) { |
@@ -359,4 +371,33 @@ private int addFakePlayer(Collection<GameProfile> profiles) { |
359 | 371 |
|
360 | 372 | return Command.SINGLE_SUCCESS; |
361 | 373 | } |
| 374 | + |
| 375 | + private int editPlayerTeamNBT(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { |
| 376 | + return doTeamEdit(ctx, ctx.getSource().getPlayerOrException(), getTeam(ctx)); |
| 377 | + } |
| 378 | + |
| 379 | + private static int editTeamNBT(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { |
| 380 | + return doTeamEdit(ctx, ctx.getSource().getPlayerOrException(), TeamArgument.get(ctx, "team")); |
| 381 | + } |
| 382 | + |
| 383 | + private static int doTeamEdit(CommandContext<CommandSourceStack> ctx, ServerPlayer editor, Team team) { |
| 384 | + if (team instanceof AbstractTeam abstractTeam) { |
| 385 | + CompoundTag info = Util.make(new CompoundTag(), t -> { |
| 386 | + t.putString("title", Component.Serializer.toJson(abstractTeam.getColoredName(), editor.registryAccess())); |
| 387 | + t.putString("type", "ftbteams:team"); |
| 388 | + t.putUUID("id", team.getTeamId()); |
| 389 | + t.putString("team_type", abstractTeam.getType().getSerializedName()); |
| 390 | + t.put("text", FTBLibraryCommands.InfoBuilder.create(ctx) |
| 391 | + .add("Team Type", Component.translatable(team.getTypeTranslationKey())) |
| 392 | + .add("Owner", Component.literal(team.getOwner().toString())) |
| 393 | + .add("Members", Component.literal(String.valueOf(team.getMembers().size()))) |
| 394 | + .build() |
| 395 | + ); |
| 396 | + }); |
| 397 | + CompoundTag tag = abstractTeam.serializeNBT(ctx.getSource().getServer().registryAccess()); |
| 398 | + NetworkHelper.sendTo(editor, new EditNBTPacket(info, tag)); |
| 399 | + return Command.SINGLE_SUCCESS; |
| 400 | + } |
| 401 | + return 0; |
| 402 | + } |
362 | 403 | } |
0 commit comments