diff --git a/CHANGELOG.md b/CHANGELOG.md index 919c13b6a7..f6802bce2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog ## [1.4.0](#1-4-0) ## Additions -- Added the `/teststore` command allowing command block/mcfunction users to query a party, PC or both for Pokémon matching specific properties and returning the match count, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.teststore` if a permission mod is present. +- Added the `/teststore ` command allowing command block/mcfunction users to query a party, PC or both for Pokémon matching specific properties and returning the match count, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.teststore` if a permission mod is present. +- Added the `/querylearnset ` command allowing command block/mcfunction users to query a party slot and check if the Pokémon can learn a specific move returning a 1 if yes otherwise 0, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.querylearnset` if a permission mod is present. ## [1.3.1 (March 31st, 2023)](#1-3-1) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonCommands.kt b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonCommands.kt index 5825b4eff6..e832c4cb7c 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonCommands.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonCommands.kt @@ -39,5 +39,6 @@ object CobblemonCommands { SpawnPokemonFromPool.register(dispatcher) PokeboxCommand.register(dispatcher) TestStoreCommand.register(dispatcher) + QueryLearnsetCommand.register(dispatcher) } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/permission/CobblemonPermissions.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/permission/CobblemonPermissions.kt index b5afdb3b46..57d7196101 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/permission/CobblemonPermissions.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/permission/CobblemonPermissions.kt @@ -59,6 +59,8 @@ object CobblemonPermissions { val TEST_STORE = this.create("${COMMAND_PREFIX}teststore", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS) + val QUERY_LEARNSET = this.create("${COMMAND_PREFIX}querylearnset", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS) + fun all(): Iterable = this.permissions private fun create(node: String, level: PermissionLevel): Permission { diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/pokemon/moves/LearnsetQuery.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/pokemon/moves/LearnsetQuery.kt index b2f3be039d..a3d7ba393a 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/pokemon/moves/LearnsetQuery.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/pokemon/moves/LearnsetQuery.kt @@ -29,6 +29,7 @@ fun interface LearnsetQuery { || learnset.tutorMoves.contains(move) || learnset.tmMoves.contains(move) || learnset.formChangeMoves.contains(move) + || learnset.evolutionMoves.contains(move) } fun level(level: Int) = LearnsetQuery { move, learnset -> learnset.getLevelUpMovesUpTo(level).contains(move) } @@ -43,6 +44,8 @@ fun interface LearnsetQuery { val FORM_CHANGE = LearnsetQuery { move, learnset -> learnset.formChangeMoves.contains(move) } + val EVOLUTION = LearnsetQuery { move, learnset -> learnset.evolutionMoves.contains(move) } + } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/command/QueryLearnsetCommand.kt b/common/src/main/kotlin/com/cobblemon/mod/common/command/QueryLearnsetCommand.kt new file mode 100644 index 0000000000..1bbe065da3 --- /dev/null +++ b/common/src/main/kotlin/com/cobblemon/mod/common/command/QueryLearnsetCommand.kt @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package com.cobblemon.mod.common.command + +import com.cobblemon.mod.common.api.permission.CobblemonPermissions +import com.cobblemon.mod.common.api.pokemon.moves.LearnsetQuery +import com.cobblemon.mod.common.command.argument.MoveArgumentType +import com.cobblemon.mod.common.command.argument.PartySlotArgumentType +import com.cobblemon.mod.common.util.permission +import com.cobblemon.mod.common.util.player +import com.mojang.brigadier.Command +import com.mojang.brigadier.CommandDispatcher +import com.mojang.brigadier.context.CommandContext +import net.minecraft.command.argument.EntityArgumentType +import net.minecraft.server.command.CommandManager.argument +import net.minecraft.server.command.CommandManager.literal +import net.minecraft.server.command.ServerCommandSource + +object QueryLearnsetCommand { + + private const val NAME = "querylearnset" + private const val PLAYER = "player" + private const val SLOT = "slot" + private const val MOVE = "move" + private const val NO_SUCCESS = 0 + + fun register(dispatcher : CommandDispatcher) { + dispatcher.register( + literal(NAME) + .permission(CobblemonPermissions.QUERY_LEARNSET) + .then(argument(PLAYER, EntityArgumentType.player()) + .then(argument(SLOT, PartySlotArgumentType.partySlot()) + .then(argument(MOVE, MoveArgumentType.move()) + .executes(this::execute)))) + ) + } + + private fun execute(context: CommandContext): Int { + val player = context.player(PLAYER) + val pokemon = PartySlotArgumentType.getPokemonOf(context, SLOT, player) + val move = MoveArgumentType.getMove(context, MOVE) + return if (LearnsetQuery.ANY.canLearn(move, pokemon.form.moves)) Command.SINGLE_SUCCESS else NO_SUCCESS + } + +} \ No newline at end of file