Files
TiedUp-/src/main/java/com/tiedup/remake/commands/subcommands/DebtSubCommand.java
NotEvil fa5cfb913c feat(C-01): i18n main commands — 148 translatable keys
Phase 3: Migrate Component.literal() in all remaining command files.
- NPCCommand (34), CellCommand (33), SocialCommand (16), CollarCommand (25),
  KeyCommand (18), BountyCommand (6), KidnapSetCommand (2), CaptivityDebugCommand (7),
  InventorySubCommand (3), TestAnimSubCommand (2), MasterTestSubCommand (7), DebtSubCommand (8)
- Strip all section sign color codes, use .withStyle(ChatFormatting)
- 148 new keys in en_us.json (command.tiedup.*)
- Debug/dynamic strings intentionally kept as literal
2026-04-15 13:54:26 +02:00

201 lines
7.4 KiB
Java

package com.tiedup.remake.commands.subcommands;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.tiedup.remake.commands.CommandHelper;
import com.tiedup.remake.prison.PrisonerManager;
import com.tiedup.remake.prison.RansomRecord;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
/**
* Debt management sub-commands for /tiedup.
* Handles: debt show, debt set, debt add, debt remove
*/
@SuppressWarnings("null")
public class DebtSubCommand {
public static void register(
LiteralArgumentBuilder<CommandSourceStack> root
) {
// /tiedup debt <player> [set|add|remove <amount>]
root.then(
Commands.literal("debt")
.requires(CommandHelper.REQUIRES_OP)
.then(
Commands.argument("player", EntityArgument.player())
// /tiedup debt <player> -> show debt
.executes(DebtSubCommand::debtShow)
// /tiedup debt <player> set <amount>
.then(
Commands.literal("set").then(
Commands.argument(
"amount",
IntegerArgumentType.integer(0)
).executes(DebtSubCommand::debtSet)
)
)
// /tiedup debt <player> add <amount>
.then(
Commands.literal("add").then(
Commands.argument(
"amount",
IntegerArgumentType.integer(0)
).executes(DebtSubCommand::debtAdd)
)
)
// /tiedup debt <player> remove <amount>
.then(
Commands.literal("remove").then(
Commands.argument(
"amount",
IntegerArgumentType.integer(0)
).executes(DebtSubCommand::debtRemove)
)
)
)
);
}
// Command Implementations
private static int debtShow(CommandContext<CommandSourceStack> context)
throws CommandSyntaxException {
ServerPlayer target = EntityArgument.getPlayer(context, "player");
ServerLevel level = context.getSource().getLevel();
PrisonerManager manager = PrisonerManager.get(level);
RansomRecord ransom = manager.getRansomRecord(target.getUUID());
if (ransom == null) {
context
.getSource()
.sendSuccess(
() ->
Component.translatable(
"command.tiedup.debt.no_record", target.getName().getString()
),
false
);
return 1;
}
int total = ransom.getTotalDebt();
int paid = ransom.getAmountPaid();
int remaining = ransom.getRemainingDebt();
context
.getSource()
.sendSuccess(
() ->
Component.translatable(
"command.tiedup.debt.show",
target.getName().getString(),
total, paid, remaining
).withStyle(ChatFormatting.YELLOW),
false
);
return 1;
}
private static int debtSet(CommandContext<CommandSourceStack> context)
throws CommandSyntaxException {
ServerPlayer target = EntityArgument.getPlayer(context, "player");
int amount = IntegerArgumentType.getInteger(context, "amount");
ServerLevel level = context.getSource().getLevel();
PrisonerManager manager = PrisonerManager.get(level);
RansomRecord ransom = manager.getRansomRecord(target.getUUID());
if (ransom == null) {
context
.getSource()
.sendFailure(
Component.translatable("command.tiedup.debt.no_record", target.getName().getString())
);
return 0;
}
ransom.setTotalDebt(amount);
context
.getSource()
.sendSuccess(
() ->
Component.translatable(
"command.tiedup.debt.set",
target.getName().getString(), amount
).withStyle(ChatFormatting.GREEN),
true
);
return 1;
}
private static int debtAdd(CommandContext<CommandSourceStack> context)
throws CommandSyntaxException {
ServerPlayer target = EntityArgument.getPlayer(context, "player");
int amount = IntegerArgumentType.getInteger(context, "amount");
ServerLevel level = context.getSource().getLevel();
PrisonerManager manager = PrisonerManager.get(level);
RansomRecord ransom = manager.getRansomRecord(target.getUUID());
if (ransom == null) {
context
.getSource()
.sendFailure(
Component.translatable("command.tiedup.debt.no_record", target.getName().getString())
);
return 0;
}
ransom.increaseDebt(amount);
context
.getSource()
.sendSuccess(
() ->
Component.translatable(
"command.tiedup.debt.added",
amount, target.getName().getString(), ransom.getRemainingDebt()
).withStyle(ChatFormatting.GREEN),
true
);
return 1;
}
private static int debtRemove(CommandContext<CommandSourceStack> context)
throws CommandSyntaxException {
ServerPlayer target = EntityArgument.getPlayer(context, "player");
int amount = IntegerArgumentType.getInteger(context, "amount");
ServerLevel level = context.getSource().getLevel();
PrisonerManager manager = PrisonerManager.get(level);
RansomRecord ransom = manager.getRansomRecord(target.getUUID());
if (ransom == null) {
context
.getSource()
.sendFailure(
Component.translatable("command.tiedup.debt.no_record", target.getName().getString())
);
return 0;
}
ransom.addPayment(amount, null);
boolean paid = ransom.isPaid();
context
.getSource()
.sendSuccess(
() ->
Component.translatable(
paid ? "command.tiedup.debt.removed_paid" : "command.tiedup.debt.removed",
amount, target.getName().getString(), ransom.getRemainingDebt()
).withStyle(ChatFormatting.GREEN),
true
);
return 1;
}
}