最終更新:
hitoshi0929 2015年09月26日(土) 16:44:39履歴
- テキストの編集ができるエディター(PHPの編集ができるもの)
- PocketMine-MP
- プラグイン「Devtools」
- プラグイン「PocketMoney」※連携したいプラグイン(ここではPocketMoney)
- PHP言語の知識
- PocketMine-MPのプラグインを作れる知識
※注意:このページはすこし初心者向けではありません。ご了承ください。
一部のプラグインには「API」と言う他のプラグインと連携できるようにする、関数が用意されています。
この関数を使用して、他のプラグインを操作したりすることができます。
またPocketMine-MPにもAPIがあり、プラグインはPocketMine-MPのAPIを使用して動いています。
この関数を使用して、他のプラグインを操作したりすることができます。
またPocketMine-MPにもAPIがあり、プラグインはPocketMine-MPのAPIを使用して動いています。
今回はPocketMoneyを使用してプレーヤーが参加(Join)したときにお金を渡すプラグインを作ります。
※一部コードの解説を飛ばしています。ご了承ください。
まず、サーバーにPocketMoneyが導入されているかをチェックします。
つぎにjoinEventは以下のようになります。
$this->PocketMoney->grantMoney()
は変数に入れたPocketMoneyのインスタンス使用して、
grantMoney()関数を呼び出してプレーヤーのお金を増やしています。
これで完成です。
PocketMoney以外にも、APIがあるプラグインはいくつもあります。
APIを使用し、他のプラグインとの連携を取ることで、より便利なプラグインを作ったりすることができます。
※一部コードの解説を飛ばしています。ご了承ください。
まず、サーバーにPocketMoneyが導入されているかをチェックします。
つぎにjoinEventは以下のようになります。
public function onJoin(PlayerJoinEvent $event) {
$player = $event->getPlayer();
$amount = 100;//付与する金額
//PocketMoneyのAPIを使ってお金を付与
$this->PocketMoney->grantMoney($player->getName(), $amount);
}
解説$this->PocketMoney->grantMoney()
は変数に入れたPocketMoneyのインスタンス使用して、
grantMoney()関数を呼び出してプレーヤーのお金を増やしています。
これで完成です。
PocketMoney以外にも、APIがあるプラグインはいくつもあります。
APIを使用し、他のプラグインとの連携を取ることで、より便利なプラグインを作ったりすることができます。
MainClass.php
<?php
namespace test;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerJoinEvent;
class MainClass extends PluginBase implements Listener {
public function onEnable() {
$this->getServer()->getPluginManager()->registerEvents($this, $this);//イベント登録
if($this->getServer()->getPluginManager()->getPlugin("PocketMoney") != null){
//PluginManagerからPocketMoneyのインスタンスを取得
$this->PocketMoney = $this->getServer()->getPluginManager()->getPlugin("PocketMoney");
$this->getLogger()->info("PocketMoneyを検出しました。");
}else{
$this->getLogger()->warning("PocketMoneyが見つかりませんでした");
$this->getServer()->getPluginManager()->disablePlugin($this);//このプラグインを無効化する
}
}
public function onJoin(PlayerJoinEvent $event) {
$player = $event->getPlayer();
$amount = 100;//付与する金額
//PocketMoneyのAPIを使ってお金を付与
$this->PocketMoney->grantMoney($player->getName(),$amount);
}
}

最新コメント