mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 19:59:11 +00:00
Fixed wrong paths
This commit is contained in:
180
src/pocketmine/command/SimpleCommandMap.php
Normal file
180
src/pocketmine/command/SimpleCommandMap.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\command;
|
||||
|
||||
use pocketmine\command\defaults\BanCommand;
|
||||
use pocketmine\command\defaults\BanIpCommand;
|
||||
use pocketmine\command\defaults\BanListCommand;
|
||||
use pocketmine\command\defaults\DefaultGamemodeCommand;
|
||||
use pocketmine\command\defaults\DifficultyCommand;
|
||||
use pocketmine\command\defaults\HelpCommand;
|
||||
use pocketmine\command\defaults\ListCommand;
|
||||
use pocketmine\command\defaults\MeCommand;
|
||||
use pocketmine\command\defaults\PardonCommand;
|
||||
use pocketmine\command\defaults\PardonIpCommand;
|
||||
use pocketmine\command\defaults\PluginsCommand;
|
||||
use pocketmine\command\defaults\SayCommand;
|
||||
use pocketmine\command\defaults\SeedCommand;
|
||||
use pocketmine\command\defaults\StopCommand;
|
||||
use pocketmine\command\defaults\TellCommand;
|
||||
use pocketmine\command\defaults\VanillaCommand;
|
||||
use pocketmine\command\defaults\VersionCommand;
|
||||
use pocketmine\Server;
|
||||
|
||||
class SimpleCommandMap implements CommandMap{
|
||||
|
||||
/**
|
||||
* @var Command[]
|
||||
*/
|
||||
protected $knownCommands = array();
|
||||
|
||||
/** @var Server */
|
||||
private $server;
|
||||
|
||||
public function __construct(Server $server){
|
||||
$this->server = $server;
|
||||
$this->setDefaultCommands();
|
||||
}
|
||||
|
||||
private function setDefaultCommands(){
|
||||
$this->register("pocketmine", new VersionCommand("version"));
|
||||
$this->register("pocketmine", new PluginsCommand("plugins"));
|
||||
$this->register("pocketmine", new SeedCommand("seed"));
|
||||
$this->register("pocketmine", new HelpCommand("help"));
|
||||
$this->register("pocketmine", new StopCommand("stop"));
|
||||
$this->register("pocketmine", new TellCommand("tell"));
|
||||
$this->register("pocketmine", new DefaultGamemodeCommand("defaultgamemode"));
|
||||
$this->register("pocketmine", new BanCommand("ban"));
|
||||
$this->register("pocketmine", new BanIpCommand("ban-ip"));
|
||||
$this->register("pocketmine", new BanListCommand("banlist"));
|
||||
$this->register("pocketmine", new PardonCommand("pardon"));
|
||||
$this->register("pocketmine", new PardonIpCommand("pardon-ip"));
|
||||
$this->register("pocketmine", new SayCommand("say"));
|
||||
$this->register("pocketmine", new MeCommand("me"));
|
||||
$this->register("pocketmine", new ListCommand("list"));
|
||||
$this->register("pocketmine", new DifficultyCommand("difficulty"));
|
||||
}
|
||||
|
||||
|
||||
public function registerAll($fallbackPrefix, array $commands){
|
||||
foreach($commands as $command){
|
||||
$this->register($fallbackPrefix, $command);
|
||||
}
|
||||
}
|
||||
|
||||
public function register($fallbackPrefix, Command $command, $label = null){
|
||||
if($label === null){
|
||||
$label = $command->getName();
|
||||
}
|
||||
$label = strtolower(trim($label));
|
||||
$fallbackPrefix = strtolower(trim($fallbackPrefix));
|
||||
|
||||
$registered = $this->registerAlias($command, false, $fallbackPrefix, $label);
|
||||
|
||||
$aliases = $command->getAliases();
|
||||
foreach($aliases as $index => $alias){
|
||||
if(!$this->registerAlias($command, true, $fallbackPrefix, $alias)){
|
||||
unset($aliases[$index]);
|
||||
}
|
||||
}
|
||||
$command->setAliases($aliases);
|
||||
|
||||
if(!$registered){
|
||||
$command->setLabel($fallbackPrefix . ":" . $label);
|
||||
}
|
||||
|
||||
$command->register($this);
|
||||
|
||||
return $registered;
|
||||
}
|
||||
|
||||
private function registerAlias(Command $command, $isAlias, $fallbackPrefix, $label){
|
||||
$this->knownCommands[$fallbackPrefix . ":" . $label] = $command;
|
||||
if(($command instanceof VanillaCommand or $isAlias) and isset($this->knownCommands[$label])){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset($this->knownCommands[$label]) and $this->knownCommands[$label]->getLabel() === $label){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$isAlias){
|
||||
$command->setLabel($label);
|
||||
}
|
||||
|
||||
$this->knownCommands[$label] = $command;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function dispatch(CommandSender $sender, $commandLine){
|
||||
$args = explode(" ", $commandLine);
|
||||
|
||||
if(count($args) === 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$sentCommandLabel = strtolower(array_shift($args));
|
||||
$target = $this->getCommand($sentCommandLabel);
|
||||
|
||||
if($target === null){
|
||||
return false;
|
||||
}
|
||||
|
||||
$target->execute($sender, $sentCommandLabel, $args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearCommands(){
|
||||
foreach($this->knownCommands as $command){
|
||||
$command->unregister($this);
|
||||
}
|
||||
$this->knownCommands = array();
|
||||
$this->setDefaultCommands();
|
||||
}
|
||||
|
||||
public function getCommand($name){
|
||||
if(isset($this->knownCommands[$name])){
|
||||
return $this->knownCommands[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Command[]
|
||||
*/
|
||||
public function getCommands(){
|
||||
return $this->knownCommands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function registerServerAliases(){
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user