From bc400df15cb3aeedd8920cedf2b8475bdbbca6c5 Mon Sep 17 00:00:00 2001 From: PresentKim Date: Tue, 9 Jan 2018 01:38:24 +0900 Subject: [PATCH] Add IgnoreCommandCase --- IgnoreCommandCase.php | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 IgnoreCommandCase.php diff --git a/IgnoreCommandCase.php b/IgnoreCommandCase.php new file mode 100644 index 0000000..abc13a2 --- /dev/null +++ b/IgnoreCommandCase.php @@ -0,0 +1,78 @@ +getServer()->getPluginManager()->registerEvents($this, $this); + } + + /** + * @priority LOWEST + * + * @param PlayerCommandPreprocessEvent $event + */ + public function onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent $event){ + if (strpos($message = $event->getMessage(), "/") === 0) { + $event->setMessage("/{$this->getCommand($this->getCommand(substr($message, 1)))}"); + } + } + + /** + * @priority LOWEST + * + * @param ServerCommandEvent $event + */ + public function onServerCommandEvent(ServerCommandEvent $event){ + $event->setCommand($this->getCommand($event->getCommand())); + } + + /** + * @priority LOWEST + * + * @param RemoteServerCommandEvent $event + */ + public function onRemoteServerCommandEvent(RemoteServerCommandEvent $event){ + $event->setCommand($this->getCommand($event->getCommand())); + } + + + /** + * @param string $command + * + * @return string + */ + public function getCommand(string $command){ + $explode = explode(" ", $command); + $commands = $this->getServer()->getCommandMap()->getCommands(); + if (isset($commands[$explode[0]])) { + return $command; + } else { + foreach ($this->getServer()->getCommandMap()->getCommands() as $key => $value) { + if (strcasecmp($explode[0], $key) === 0) { + $explode[0] = $key; + break; + } + } + } + return implode(" ", $explode); + } + } +} \ No newline at end of file