InfoAPI
InfoAPI copied to clipboard
Error {unknownPath:player money}
final class Main extends PluginBase implements Listener {
public function onEnable() : void {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
InfoAPI::addMapping(
$this, "myplugin.money",
fn(Player $player) : int => 123,
);
}
public function onChat(PlayerJoinEvent $event) : void {
$event->setJoinMessage(InfoAPI::render(
$this, '{yellow}{player} {white}joined the server in world {aqua}"{player money}".',
["player" => $event->getPlayer()],
));
}
}
Please provide a minimal reproducible example.
wdym?
final class Main extends PluginBase implements Listener { public function onEnable() : void { $this->getServer()->getPluginManager()->registerEvents($this, $this); InfoAPI::addMapping( $this, "myplugin.money", fn(Player $player) : int => 123, ); } public function onChat(PlayerJoinEvent $event) : void { $event->setJoinMessage(InfoAPI::render( $this, '{yellow}{player} {white}joined the server in world {aqua}"{player money}".', ["player" => $event->getPlayer()], )); } }
{player money} isn't registered correctly
@nicholass003 what is the problem? i didn't find any issues by skimming.
@nicholass003 what is the problem? i didn't find any issues by skimming.
$event->setJoinMessage(InfoAPI::render(
$this, '{yellow}{player} {white}joined the server in world {aqua}"{player money}".',
["player" => $event->getPlayer()],
));
In this template it displays {player money} but when using InfoAPI::render there is no context key that registers "player money"
money is a field derived from player. do you know how InfoAPI is supposed to work?
money is a field derived from player. do you know how InfoAPI is supposed to work?
What am I doing wrong? I registered the money property for the Player object. In the render method I passed the Player object with the "player" key, and in the template I used {player money}
Thanks to @Endermanbugzjfc after we discussed we found the problem here, you need to pass $player as \pocketmine\command\CommandSender $sender to set "player" as $player
public function onPlayerJump(PlayerJumpEvent $event) : void{
$player = $event->getPlayer();
$template = "{nameTag} is jumping!\nIs {name} flying ? {flying}\nPlayer Counts {playerCount}\n\n{player nameTag} is jumping!\nIs {player name} flying ? {player flying}\nPlayer Counts {player playerCount}";
$player->sendMessage(InfoAPI::render($this, $template, [
"player" => $player
], $player));
}
Result
{unknownPath:nameTag} is jumping!
Is {unknownPath:name} flying ? {unknownPath:flying}
Player Counts 1
nichoIass003 is jumping!
Is nichoIass003 flying ? false
Player Counts {unknownPath:player playerCount}
money is a field derived from player. do you know how InfoAPI is supposed to work?
What am I doing wrong? I registered the money property for the Player object. In the render method I passed the Player object with the "player" key, and in the template I used {player money}
This is the correct one
protected function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
InfoAPI::addMapping(
$this, "money",
fn(Player $player) : int => 123,
);
}
public function onPlayerJump(PlayerJumpEvent $event) : void{
$moneyTest = "{player name} money is {player money}";
$player->getServer()->getLogger()->notice(InfoAPI::render($this, $moneyTest, [
"player" => $player
], $player));
}
Result
nichoIass003 money is 123
why would adding sender change the result of the output?
why would adding sender change the result of the output?
yeah you are right, it still works even without adding $player as sender, mb 😭
How to render with alias dots? e.g. "myplugin.money"
it's just a namespace like the command fallbackPrefix in PM commands
e.g.
{player myplugin.money}
is equivalent to
{player money}
if there is no ambiguity
with fallbackPrefix does not work
protected function onEnable(): void
{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
InfoAPI::addMapping(
$this, "myplugin.money",
fn(Player $player): int => 100
);
}
public function onPlayerJoin(PlayerJoinEvent $event): void
{
$event->setJoinMessage(InfoAPI::render(
$this, "{player} has {player money}",
["player" => $event->getPlayer()]
));
}
result
Steve has {unknownPath:player money}