1+ <?php
2+
3+ /**
4+ * @name IgnoreCommandCase
5+ * @main presentkim\singleton\IgnoreCommandCase
6+ * @version 1.0.0
7+ * @api 3.0.0-ALPHA10
8+ * @description ignore command case
9+ * @author PresentKim
10+ */
11+
12+
13+ namespace presentkim \singleton {
14+
15+ use function implode ;
16+ use pocketmine \{
17+ event \Listener , event \player \PlayerCommandPreprocessEvent , event \server \RemoteServerCommandEvent , event \server \ServerCommandEvent , plugin \PluginBase
18+ };
19+ use function strcasecmp ;
20+
21+ class IgnoreCommandCase extends PluginBase implements Listener{
22+
23+ public function onEnable (){
24+ $ this ->getServer ()->getPluginManager ()->registerEvents ($ this , $ this );
25+ }
26+
27+ /**
28+ * @priority LOWEST
29+ *
30+ * @param PlayerCommandPreprocessEvent $event
31+ */
32+ public function onPlayerCommandPreprocessEvent (PlayerCommandPreprocessEvent $ event ){
33+ if (strpos ($ message = $ event ->getMessage (), "/ " ) === 0 ) {
34+ $ event ->setMessage ("/ {$ this ->getCommand ($ this ->getCommand (substr ($ message , 1 )))}" );
35+ }
36+ }
37+
38+ /**
39+ * @priority LOWEST
40+ *
41+ * @param ServerCommandEvent $event
42+ */
43+ public function onServerCommandEvent (ServerCommandEvent $ event ){
44+ $ event ->setCommand ($ this ->getCommand ($ event ->getCommand ()));
45+ }
46+
47+ /**
48+ * @priority LOWEST
49+ *
50+ * @param RemoteServerCommandEvent $event
51+ */
52+ public function onRemoteServerCommandEvent (RemoteServerCommandEvent $ event ){
53+ $ event ->setCommand ($ this ->getCommand ($ event ->getCommand ()));
54+ }
55+
56+
57+ /**
58+ * @param string $command
59+ *
60+ * @return string
61+ */
62+ public function getCommand (string $ command ){
63+ $ explode = explode (" " , $ command );
64+ $ commands = $ this ->getServer ()->getCommandMap ()->getCommands ();
65+ if (isset ($ commands [$ explode [0 ]])) {
66+ return $ command ;
67+ } else {
68+ foreach ($ this ->getServer ()->getCommandMap ()->getCommands () as $ key => $ value ) {
69+ if (strcasecmp ($ explode [0 ], $ key ) === 0 ) {
70+ $ explode [0 ] = $ key ;
71+ break ;
72+ }
73+ }
74+ }
75+ return implode (" " , $ explode );
76+ }
77+ }
78+ }
0 commit comments