Skip to content

Commit

Permalink
Add IgnoreCommandCase
Browse files Browse the repository at this point in the history
  • Loading branch information
PresentKim committed Jan 8, 2018
1 parent 683272c commit bc400df
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions IgnoreCommandCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* @name IgnoreCommandCase
* @main presentkim\singleton\IgnoreCommandCase
* @version 1.0.0
* @api 3.0.0-ALPHA10
* @description ignore command case
* @author PresentKim
*/


namespace presentkim\singleton {

use function implode;
use pocketmine\{
event\Listener, event\player\PlayerCommandPreprocessEvent, event\server\RemoteServerCommandEvent, event\server\ServerCommandEvent, plugin\PluginBase
};
use function strcasecmp;

class IgnoreCommandCase extends PluginBase implements Listener{

public function onEnable(){
$this->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);
}
}
}

0 comments on commit bc400df

Please sign in to comment.