InfoAPI icon indicating copy to clipboard operation
InfoAPI copied to clipboard

Error {unknownPath:player money}

Open t3chlust opened this issue 8 months ago • 14 comments

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()],
		));
	}
}

t3chlust avatar Mar 18 '25 04:03 t3chlust

Please provide a minimal reproducible example.

SOF3 avatar Mar 18 '25 06:03 SOF3

wdym?

t3chlust avatar Apr 04 '25 10:04 t3chlust

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 avatar Apr 09 '25 08:04 nicholass003

@nicholass003 what is the problem? i didn't find any issues by skimming.

SOF3 avatar Apr 09 '25 09:04 SOF3

@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"

nicholass003 avatar Apr 09 '25 10:04 nicholass003

money is a field derived from player. do you know how InfoAPI is supposed to work?

SOF3 avatar Apr 09 '25 11:04 SOF3

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}

t3chlust avatar Apr 11 '25 12:04 t3chlust

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}

nicholass003 avatar Apr 13 '25 15:04 nicholass003

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

nicholass003 avatar Apr 13 '25 16:04 nicholass003

why would adding sender change the result of the output?

SOF3 avatar Apr 13 '25 17:04 SOF3

why would adding sender change the result of the output?

yeah you are right, it still works even without adding $player as sender, mb 😭

nicholass003 avatar Apr 14 '25 12:04 nicholass003

How to render with alias dots? e.g. "myplugin.money"

t3chlust avatar Apr 14 '25 17:04 t3chlust

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

SOF3 avatar Apr 15 '25 05:04 SOF3

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}

t3chlust avatar Apr 15 '25 18:04 t3chlust