From ec9d5089e633a23e49bb5e740ca2b1b92f79837c Mon Sep 17 00:00:00 2001 From: Craig Date: Sun, 17 Dec 2023 00:20:27 +0000 Subject: [PATCH] Upgrade XP/Points command, Dhi better be happy --- .../command/TardisRefinedCommand.java | 7 +- .../command/sub/LevelCommand.java | 102 ++++++++++++++++++ .../capability/upgrades/UpgradeHandler.java | 5 +- .../patterns/ShellPatterns.java | 2 +- 4 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java diff --git a/common/src/main/java/whocraft/tardis_refined/command/TardisRefinedCommand.java b/common/src/main/java/whocraft/tardis_refined/command/TardisRefinedCommand.java index 622548f5e..bb6ea4153 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/TardisRefinedCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/TardisRefinedCommand.java @@ -4,8 +4,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import whocraft.tardis_refined.TardisRefined; -import whocraft.tardis_refined.command.sub.export.ExportDesktopCommand; import whocraft.tardis_refined.command.sub.InteriorCommand; +import whocraft.tardis_refined.command.sub.LevelCommand; +import whocraft.tardis_refined.command.sub.export.ExportDesktopCommand; import whocraft.tardis_refined.common.util.Platform; public class TardisRefinedCommand { @@ -14,9 +15,7 @@ public static void register(CommandDispatcher dispatcher) { dispatcher.register(Commands.literal(TardisRefined.MODID).requires(commandSource -> commandSource.hasPermission(Platform.getServer().getOperatorUserPermissionLevel())) .then(InteriorCommand.register(dispatcher)) .then(Commands.literal("data").then(Commands.literal("export").then(ExportDesktopCommand.register(dispatcher)))) - - ); - + .then(Commands.literal("level").then(LevelCommand.register(dispatcher)))); } } diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java new file mode 100644 index 000000000..62a1b481d --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java @@ -0,0 +1,102 @@ +package whocraft.tardis_refined.command.sub; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import whocraft.tardis_refined.common.capability.TardisLevelOperator; +import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler; +import whocraft.tardis_refined.common.util.CommandHelper; + +public class LevelCommand { + + public static ArgumentBuilder register(CommandDispatcher dispatcher) { + return Commands.argument("dimension", DimensionArgument.dimension()).suggests(CommandHelper.SUGGEST_TARDISES) + .then(Commands.literal("get-points").executes(LevelCommand::getDimensionPoints)) + .then(Commands.literal("set-points").then(Commands.argument("points", IntegerArgumentType.integer()).executes(LevelCommand::setDimensionPoints))) + .then(Commands.literal("add-points").then(Commands.argument("points", IntegerArgumentType.integer()).executes(LevelCommand::addDimensionPoints))) + .then(Commands.literal("get-xp").executes(LevelCommand::getDimensionXp)) + .then(Commands.literal("set-xp").then(Commands.argument("xp", IntegerArgumentType.integer()).executes(LevelCommand::setDimensionXp))) + .then(Commands.literal("add-xp").then(Commands.argument("xp", IntegerArgumentType.integer()).executes(LevelCommand::addDimensionXp))); + + } + + private static int getDimensionPoints(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + int points = tardisLevelOperator.getUpgradeHandler().getUpgradePoints(); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " levels: " + points)); + }); + + return Command.SINGLE_SUCCESS; + } + + private static int setDimensionPoints(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + int points = IntegerArgumentType.getInteger(context, "points"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + tardisLevelOperator.getUpgradeHandler().setUpgradePoints(points); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + points)); + }); + + return Command.SINGLE_SUCCESS; + } + + private static int addDimensionPoints(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + int points = IntegerArgumentType.getInteger(context, "points"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); + upgradeHandler.setUpgradePoints(upgradeHandler.getUpgradePoints() + points); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + upgradeHandler.getUpgradePoints())); + }); + + return Command.SINGLE_SUCCESS; + } + + private static int addDimensionXp(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + int points = IntegerArgumentType.getInteger(context, "points"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); + upgradeHandler.setUpgradeXP(upgradeHandler.getUpgradeXP() + points); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + upgradeHandler.getUpgradeXP())); + }); + + return Command.SINGLE_SUCCESS; + } + + private static int getDimensionXp(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + int xp = tardisLevelOperator.getUpgradeHandler().getUpgradeXP(); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " xp: " + xp)); + }); + + return Command.SINGLE_SUCCESS; + } + + private static int setDimensionXp(CommandContext context) throws CommandSyntaxException { + ServerLevel dimension = DimensionArgument.getDimension(context, "dimension"); + int points = IntegerArgumentType.getInteger(context, "xp"); + + TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { + tardisLevelOperator.getUpgradeHandler().setUpgradePoints(points); + context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " xp set to " + points)); + }); + + return Command.SINGLE_SUCCESS; + } +} diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/UpgradeHandler.java b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/UpgradeHandler.java index 417e289cd..3f23dde43 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/UpgradeHandler.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/UpgradeHandler.java @@ -101,7 +101,7 @@ public void addUpgradeXP(int upgradeXP) { this.upgradeXP = XP_PER_UPGRADE_POINT - Mth.abs(this.upgradeXP); } - this.upgradePoints = Mth.clamp(this.upgradePoints, 0, 99); + this.upgradePoints = Mth.clamp(this.upgradePoints, 0, Integer.MAX_VALUE); } @@ -110,8 +110,7 @@ public int getNeededXPForNextPoint() { } public void setUpgradePoints(int upgradePoints) { - this.upgradePoints = Mth.clamp(upgradePoints, 0, 99); - + this.upgradePoints = Mth.clamp(upgradePoints, 0, Integer.MAX_VALUE); } public int getUpgradePoints() { diff --git a/common/src/main/java/whocraft/tardis_refined/patterns/ShellPatterns.java b/common/src/main/java/whocraft/tardis_refined/patterns/ShellPatterns.java index 104cde2f7..3f32838d7 100644 --- a/common/src/main/java/whocraft/tardis_refined/patterns/ShellPatterns.java +++ b/common/src/main/java/whocraft/tardis_refined/patterns/ShellPatterns.java @@ -183,7 +183,7 @@ public static Map> registerDefaultPatterns( addDefaultPattern(ShellTheme.BIG_BEN.getId(), "gothic", false); Map> patternsByCollection = new HashMap<>(); - DEFAULT_PATTERNS.entrySet().forEach(entry -> patternsByCollection.put(entry.getKey(), entry.getValue())); + patternsByCollection.putAll(DEFAULT_PATTERNS); return patternsByCollection; }