From 2ccf715d06c2bdf9da5b3958e2210577eeb1a4ef Mon Sep 17 00:00:00 2001 From: Craig Date: Thu, 23 May 2024 20:38:42 +1000 Subject: [PATCH] Unlock all and lock all commands --- .../command/sub/UpgradesCommand.java | 62 +++++++++++++++---- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java index 11d03b413..34eebf8f9 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java @@ -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 register(CommandDispatcher 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 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 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 context) throws CommandSyntaxException { @@ -53,6 +90,7 @@ private static int setUpgradeLocked(CommandContext context) return Command.SINGLE_SUCCESS; } + private static int setUpgradeUnlocked(CommandContext context) throws CommandSyntaxException { Upgrade upgrade = UpgradeArgumentType.getUpgrade(context, "upgrade");