Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented vanilla /xp command. #6429

Open
wants to merge 8 commits into
base: minor-next
Choose a base branch
from
Open

Conversation

ipad54
Copy link
Contributor

@ipad54 ipad54 commented Aug 17, 2024

Introduction

This PR implements /xp command from vanilla. Also, I think it would be convenient to have a built-in command that can give you experience levels to test enchanting tables / anvils instead of farming experience from bottles.

Changes

API changes

Added ExperienceCommand
Added 2 new permissions:

  • pocketmine.command.xp.other
  • pocketmine.command.xp.self

Follow-up

Before accepting this PR you need to add new translations into pmmp/Language repo

See pmmp/Language#185

Requires translations:

| pocketmine.command.xp.description | Adds or removes player experience |

| pocketmine.permission.command.xp.other | Allows the user to add or remove experience of other players |
| pocketmine.permission.command.xp.self | Allows the user to add or remove their experience |
| pocketmine.command.xp.usage | /xp <experience[L]> [player] |

| commands.xp.failure.widthdrawXp | Cannot give player negative experience points |
| commands.xp.success | Gave {%0} experience to {%1} |
| commands.xp.success.levels | Gave {%0} experience levels to {%1} |
| commands.xp.success.negative.levels | Taken {%0} levels from {%1} |

Tests

I tested this PR by doing the following:

  • Playtesting using a Minecraft client
    Screenshot_20240817_143222

src/command/defaults/ExperienceCommand.php Show resolved Hide resolved
src/command/defaults/ExperienceCommand.php Outdated Show resolved Hide resolved
src/command/defaults/ExperienceCommand.php Outdated Show resolved Hide resolved
src/command/defaults/ExperienceCommand.php Outdated Show resolved Hide resolved
src/command/defaults/ExperienceCommand.php Outdated Show resolved Hide resolved
src/command/defaults/ExperienceCommand.php Outdated Show resolved Hide resolved
@ShockedPlot7560 ShockedPlot7560 added Category: Gameplay Related to Minecraft gameplay experience Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Aug 19, 2024
}
$xpManager = $player->getXpManager();
if(str_ends_with($args[0], "L")){
$xpLevelAttr = $player->getAttributeMap()->get(Attribute::EXPERIENCE_LEVEL) ?? throw new AssumptionFailedError();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$xpLevelAttr = $player->getAttributeMap()->get(Attribute::EXPERIENCE_LEVEL) ?? throw new AssumptionFailedError();
/** @var Attribute $xpLevelAttr */
$xpLevelAttr = $player->getAttributeMap()->get(Attribute::EXPERIENCE_LEVEL);

Copy link
Contributor Author

@ipad54 ipad54 Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, @var in PM code shouldn’t be used for such assertions. Also, I’ve found similar assertion via AssumptionFailedError in the code for another attribute that should always exist by default too (https://github.com/pmmp/PocketMine-MP/blob/stable/src/network/mcpe/handler/InGamePacketHandler.php#L510)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Gameplay Related to Minecraft gameplay experience Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants