Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created July 28, 2019 03:08
Show Gist options
  • Save PJZ9n/752b68ad8b7bbfa06847b2d0898e5d44 to your computer and use it in GitHub Desktop.
Save PJZ9n/752b68ad8b7bbfa06847b2d0898e5d44 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
/**
* @name PluginC
* @version 1.0.0
* @main PJZ9n\PluginC\Main
* @api 3.0.0
*/
namespace PJZ9n\PluginC {
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;
use pocketmine\plugin\PluginBase;
class Main extends PluginBase
{
public function onEnable(): void
{
$command = new PluginCommand("plugincommand", $this);
$command->setDescription("テストコマンド");
$command->setUsage("/plugincommand [hoge|fuga] <name>");
$command->setExecutor(new TestExector());
$this->getServer()->getCommandMap()->register("PluginC", $command);
}
}
class TestExector implements CommandExecutor
{
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
{
//権限チェックいらない!
//ここに処理書く
if (!isset($args[0])) {
//Usageを送れる!
return false;
}
if (!isset($args[1])) {
//Usage(ry
return false;
}
switch ($args[0]) {
case "hoge":
$sender->sendMessage("OK!!! hoge");
return true;
case "fuga":
$sender->sendMessage("OK!!! fuga");
return true;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment