-
-
Save PEMapModder/7fa4b58d11d50bc0d692 to your computer and use it in GitHub Desktop.
MyMemo - Auto-generated gist plugin stub by pmt.mcpe.me InstaPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: MyMemo | |
author: PEMapModder | |
version: 1.0.0 | |
api: | |
- 1.12.0 | |
main: PEMapModder\MyMemo\Main | |
commands: | |
memo: | |
description: Change your memo particle | |
usage: /memo <memo message> | |
permissions: [] | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PEMapModder\MyMemo; | |
use pocketmine\Player; | |
use pocketmine\command\CommandSender; | |
use pocketmine\command\Command; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerJoinEvent; | |
use pocketmine\plugin\PluginBase; | |
class Main extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
foreach($this->getServer()->getOnlinePlayers() as $player){ | |
$this->openSession($player); | |
} | |
} | |
public function onDisable(){ | |
foreach($this->getServer()->getOnlinePlayers() as $player){ | |
$this->closeSession($player); | |
} | |
} | |
public function e_join(PlayerJoinEvent $event){ | |
$this->openSession($event->getPlayer()); | |
} | |
public function e_quit(PlayerQuitEvent $event){ | |
$this->closeSession($event->getPlayer()); | |
} | |
public function onCommand(CommandSender $issuer, Command $cmd, $label, array $params){ | |
if(!($issuer instanceof Player)){ | |
$issuer->sendMessage("Please run this command in game.") | |
return true; | |
} | |
if(!isset($this->sessions[$issuer->getId()])){ | |
// for some reason, player sent a command before joining or after quitting. | |
// this is totally unexpected, and this should only happen if the plugin has some internal problems. | |
// instead of assuming, we should assert(false), which will trigger an error saying that some serious internal problems occurred. | |
// calling assert() should crash the server, or at least cancel the operation. | |
assert(false, "Player sent command before join or after quit"); | |
} | |
$session = $this->sessions[$issuer->getId()]; | |
$newText = implode(" ", $params); | |
$session->setParticleText($newText); | |
return true; | |
} | |
public function openSession(Player $player){ | |
$this->sessions[$player->getId()] = new MemoSession($player); | |
} | |
public function closeSession(Player $player){ | |
if(isset($this->sessions[$player->getId()])){ | |
$this->sessions[$player->getId()]->finalize(); | |
unset($this->sessions[$player->getId()]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace PEMapModder\MyMemo; | |
use pocketmine\Player; | |
use pocketmine\level\particle\FloatingTextParticle; | |
use pocketmine\math\Vector3; | |
class MemoSession{ | |
private $player; | |
public function __construct(Player $player){ | |
$this->player = $player; | |
$this->particle = new FloatingTextParticle($player, "<Memo here>"); | |
$player->getLevel()->addParticle($this->particle); | |
} | |
public function setParticleText($text){ | |
$this->particle->setText($text); | |
$this->player->getLevel()->addParticle($this->particle); | |
} | |
public function finalize(){ | |
$this->particle->setInvisible(); | |
$this->player->getLevel()->addParticle($this->particle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment