aikar / aikar/commands

Resolved Player is always null

未關閉
#300 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
Java
星號
628
分支
150
PR 合併指標
30 天內沒有已合併 PR

描述

Thanks for the awesome framework.
I have a question about the context resolver and how it treats players?
I have the problem that my resolved player is always null and I am unable to find any documentation on how exactly context resolvers work.

I have the following command with two custom resolvers `SkilledPlayer` and `Skill`:

```java
@Subcommand("add")
@CommandCompletion("@players @skills")
@Description("{@@rcskills.add-cmd.desc}")
@CommandPermission("rcskills.admin.skill.add")
public void addSkill(SkilledPlayer skilledPlayer, Skill skill) {

skilledPlayer.addSkill(skill);
getCurrentCommandIssuer().sendMessage("{@@rcskills.add-cmd.info}");
}
```

```java
commandManager.getCommandContexts().registerContext(Skill.class, context -> {
Optional skill = getSkillManager().findSkillByNameOrId(context.popFirstArg());
if (skill.isEmpty()) {
throw new InvalidCommandArgument("{@@rcskills.resolver.skill.error}");
}
return skill.get();
});
commandManager.getCommandContexts().registerContext(net.silthus.skills.SkilledPlayer.class, context -> {
Player player = (Player) context.getResolvedArg(Player.class);
return skillManager.getPlayer(player);
});
```

The player I get from `context.getResolvedArg(Player.class) is always null and the `context.popFirstArg()` also sometimes returns null and I do not know why.

The executed command is `/rcs add Silthus test` where `Silthus` is the player name and `test` the skill identifier.

What do I need to change for my use case?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。