API plugin to open a dialog for choosing another player.

Overview

ChoosePlayer

API plugin for choosing a player interactively.

API

Let player select another player

This API method opens a dialog to let player $chooser choose a player, then returns the name and UUID of the chosen player.

public static function ChoosePlayer::chooseCallback(
    Player $chooser,
    Closure $onSelect,
    Closure $onCancel,
    Closure $filter = null,
    string $text = "",
) : ChoosePlayerResult;

$filter are suggestion filters. The Filters helper class can be used for creating filters.

ChoosePlayerResult has two public fields: string $name and string $uuid. $name is the name of the player (which may or may not be in the correct case), and $uuid is the human-readable 36-character player UUID string. The consistency between name and UUID are provided on a best-effort basis by the suggester plugin, but may be inaccurate if the suggester plugin is out of sync.

An example plugin that provides an op command:

<?php

use pocketmine\command\{Command, CommandSender};
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;

use SOFe\ChoosePlayer\{ChoosePlayer, ChoosePlayerResult};

class Main extends PluginBase {
    public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool {
        if(!($sender instanceof Player)) {
            $sender->sendMessage("This command can only be used in-game");
            return true;
        }

        ChoosePlayer::chooseCallback($sender, function(ChoosePlayerResult $result) use($sender) : void {
            $chosenPlayerName = $result->name;
            $this->getServer()->addOp($chosenPlayerName);
            $sender->sendMessage("opped $chosenPlayerName");
        }, function() use($sender) : void {
            $sender->sendMessage("Operation cancelled");
        }, Filters::isnt($sender))

        return true;
    }
}

Provide suggestions

Use this API method to provide more ways of selecting players.

public static function \SOFe\ChoosePlayer\ChoosePlayer::suggest(\SOFe\ChoosePlayer\Suggester $suggester) : void;

See OnlinePlayerSuggester for example usage. A few points to note:

  • getId() should return a fully-qualified, consistent, unique identifier, because it is saved in the usage history for players.
  • getDisplayName() is used in the dialog where player selects the suggester. Feel free to decorate this name!
  • suggest is an async iterator.
    • TLDR: Implement the method like a normal await-generator async function (it does not have to be async if you don't need to). Simply write yield $suggestion => Await::VALUE for each suggestion.
    • Only a small batch of suggestions (20 by default) are displayed at a time. if possible, try loading no more than 20 suggestions at a time.
    • ChoosePlayer throws a TerminateSuggestionsException in the async iterator when the player stops selecting. You may want to wrap your code with try-finally blocks if there are resources you need to close.

Building

To compile this plugin to phar, you need to use Composer.

composer install
composer build

The output phar is generated in hack/ChoosePlayer.phar.

You can also find development builds in GitHub Actions (click into a run page and scroll to bottom) or on Poggit.

You might also like...
A good plugin to play a sound when the player hits the enemy's head

HeadshotSound A good plugin to play a sound when the player hits the enemy's head. How to use Hit the player with a snowball, egg and bow in the head

A simple plugin to teleport the player to world spawn when taking damage!

🧙‍♂️ • Damage TP Version Status Date 1.0.0 stable-dev 12/10/2022 📫 • General: Plugin Introduction: This is a simple plugin that teleports the player

An advanced plugin to manage events when the player enters the server!

⭐ • Better Join Version Status Date 1.0.0 stable-dev 12/10/2022 📫 • General: Plugin Introduction: This is an advanced player input management plugin

A simple plugin to display a block name that player break or place in popup!

🧱 • Block Popup Version Status Date 1.0.0 stable-alpha 12/10/2022 📫 • General: Plugin Introduction: This is a simple plugin to add the function to d

It's MX Player API gives All Content in JSON format

💞 MXPlayer API 🎵 🍻 MXPlayer API Can get Streaming URLs and Other Data in JSON Format From mxplayer.in links for Streaming 👑 How to Use : 🔐 Method

Scorm Player Api for play scorm modules

flux-scorm-player-api Scorm Player Api for play scorm modules Installation Native Download RUN (mkdir -p /%path%/libs/flux-scorm-player-api && cd /%pa

From the team that brought you laravel-random-command comes another gem!
From the team that brought you laravel-random-command comes another gem!

💍 Why require one if you can require them all? From the team that brought you laravel-random-command comes another gem! Requiring all our packages se

Displaying damage when hitting a player

DamageIndicator Displaying damage when hitting a player Information Command: No Permission: Coming soon Settings: Settings in config.yml How to use ?

Recoded, added features, removed useless stuff, more efficent code, PER PLAYER TEXT
Recoded, added features, removed useless stuff, more efficent code, PER PLAYER TEXT

WFT - 1.2.0 (BETA) Hello, and welcome to WFT. NOW IN API 4.0 This is the official recode of my old plugin WFT, witch had some issues. Overall I was no

Owner
Jonathan Chan Kwan Yin
a.k.a. SOFe, @chankyin. Infrastructure developer. I Go at daytime and Rust at night.
Jonathan Chan Kwan Yin
Plugin that allows a player to morph into mobs

BurgerMorphs This plugin adds a Morphs system to PMMP. Players can morph into most mobs available in the game. Players can also morph into baby versio

null 5 Aug 28, 2022
A PocketMine-MP plugin that replaces a block to another block when breaks, then back to the original block after a certain time

BlockReplacer A PocketMine-MP plugin that replaces a block to another block when breaks, then back to the original block after a certain time How to I

AIPTU 11 Sep 2, 2022
This is a plugin for pocketmine-mp, when locking a player's items helps players not to lose items or throw things around causing server lag.

[] LockedItem| v1.0.0 Player's item lock Features Player's item lock Players aren't afraid of losing items For Devolopers You can access to LockedItem

JeroGamingYT 3 Jan 4, 2022
A PocketMine-MP plugin to cancel the player's sprint

NoSprint A PocketMine-MP plugin to cancel the player's spint. Features Permissions bypass. Custom messages. Per world support. Lightweight and open so

null 3 May 17, 2022
A Pocketmine-MP (PMMP) leaderboard plugin that shows player statistics on a website.

WebLeaderBoard A Pocketmine-MP (PMMP) leaderboard plugin that shows all sorts of statistics on a website. Setup Guide To start using the plugin, downl

ItsMax123 6 Apr 5, 2022
This plugin gets player time while playing and leaderboard

TopNolep TopNolep is a plugin that retrieves the game time the player was on the server during, not only that, topnolep now provides a leaderboard tha

Edo 5 Oct 22, 2021
A plugin to test Server->getPlayerExact() vs Map performance

PeformanceTests A plugin to test Server->getPlayerExact() vs Map<username, Player> performance Timings with Server->getPlayerExact() https://timings.p

KingOfTurkey38 1 Feb 25, 2022
A PocketMine-MP plugin to regulate player hunger and prohibit eating certain foods easily

NoEats A PocketMine-MP plugin to regulate player hunger and prohibit eating certain foods easily. Features Managing hunger. Permission bypass. Support

null 2 Jan 16, 2022
This Plugin runs commands when a player does a certain emote

The EmoteCommands Plugin This Plugin runs commands when a player does a certain emote You will need a pocketmine server of at least version 4.0.0 Usag

DiamondStrider1 1 Jan 24, 2022
NoFly is a PocketMine-MP plugin that doesn't allow the player to fly

NoFly is a PocketMine-MP plugin that doesn't allow the player to fly

Azel F. 2 Mar 30, 2022