Skip to content

Commit

Permalink
Unlock all and lock all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeryn99 authored and 50ap5ud5 committed May 25, 2024
1 parent d7b4144 commit 2ccf715
Showing 1 changed file with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,65 @@
import whocraft.tardis_refined.command.arguments.UpgradeArgumentType;
import whocraft.tardis_refined.common.capability.TardisLevelOperator;
import whocraft.tardis_refined.common.capability.upgrades.Upgrade;
import whocraft.tardis_refined.common.capability.upgrades.Upgrades;
import whocraft.tardis_refined.common.util.CommandHelper;
import whocraft.tardis_refined.common.util.TardisHelper;
import whocraft.tardis_refined.constants.ModMessages;
import whocraft.tardis_refined.registry.RegistrySupplier;
import whocraft.tardis_refined.registry.RegistrySupplierHolder;

public class UpgradesCommand {

public static ArgumentBuilder<CommandSourceStack, ?> register(CommandDispatcher<CommandSourceStack> dispatcher) {
return Commands.literal("upgrades")
.then(Commands.literal("lock")
.then(Commands.argument("upgrade", UpgradeArgumentType.upgradeArgumentType())
.then(Commands.argument("tardis", DimensionArgument.dimension()).suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::setUpgradeLocked)
)
)
)
.then(Commands.argument("upgrade", UpgradeArgumentType.upgradeArgumentType())
.then(Commands.argument("tardis", DimensionArgument.dimension())
.suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::setUpgradeLocked))))
.then(Commands.literal("unlock")
.then(Commands.argument("upgrade", UpgradeArgumentType.upgradeArgumentType())
.then(Commands.argument("tardis", DimensionArgument.dimension()).suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::setUpgradeUnlocked)
)
)
);
.then(Commands.argument("upgrade", UpgradeArgumentType.upgradeArgumentType())
.then(Commands.argument("tardis", DimensionArgument.dimension())
.suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::setUpgradeUnlocked))))
.then(Commands.literal("unlock-all")
.then(Commands.argument("tardis", DimensionArgument.dimension())
.suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::unlockAll)))
.then(Commands.literal("lock-all")
.then(Commands.argument("tardis", DimensionArgument.dimension())
.suggests(CommandHelper.SUGGEST_TARDISES)
.executes(UpgradesCommand::lockAll)));
}



private static int unlockAll(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "tardis");
MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location());

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
for (Upgrade entry : Upgrades.UPGRADE_DEFERRED_REGISTRY.getRegistry()) {
tardisLevelOperator.getUpgradeHandler().unlockUpgrade(entry);
context.getSource().sendSystemMessage(Component.translatable(ModMessages.CMD_UPGRADE_UNLOCK, entry.getDisplayName(), tardisId));
}
});
return Command.SINGLE_SUCCESS;

}

private static int lockAll(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "tardis");
MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location());

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
for (Upgrade entry : Upgrades.UPGRADE_DEFERRED_REGISTRY.getRegistry()) {
tardisLevelOperator.getUpgradeHandler().lockUpgrade(entry);
context.getSource().sendSystemMessage(Component.translatable(ModMessages.CMD_UPGRADE_LOCK, entry.getDisplayName(), tardisId));
}
});
return Command.SINGLE_SUCCESS;

}

private static int setUpgradeLocked(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Expand All @@ -53,6 +90,7 @@ private static int setUpgradeLocked(CommandContext<CommandSourceStack> context)
return Command.SINGLE_SUCCESS;
}


private static int setUpgradeUnlocked(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {

Upgrade upgrade = UpgradeArgumentType.getUpgrade(context, "upgrade");
Expand Down

0 comments on commit 2ccf715

Please sign in to comment.