Added RemoteServerCommandEvent

This commit is contained in:
Shoghi Cervantes 2014-08-16 13:05:20 +02:00
parent 7e4a191593
commit eee0eb5458
3 changed files with 53 additions and 4 deletions

View File

@ -1661,10 +1661,9 @@ class Server{
Timings::$serverCommandTimer->startTiming();
if(($line = $this->console->getLine()) !== null){
$this->pluginManager->callEvent($ev = new ServerCommandEvent($this->consoleSender, $line));
if($ev->isCancelled()){
return;
if(!$ev->isCancelled()){
$this->dispatchCommand($ev->getSender(), $ev->getCommand());
}
$this->dispatchCommand($this->consoleSender, $ev->getCommand());
}
Timings::$serverCommandTimer->stopTiming();
}

View File

@ -0,0 +1,40 @@
<?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\event\server;
use pocketmine\command\CommandSender;
/**
* This event is called when a command is received over RCON.
*/
class RemoteServerCommandEvent extends ServerCommandEvent{
public static $handlerList = null;
/**
* @param CommandSender $sender
* @param string $command
*/
public function __construct(CommandSender $sender, $command){
parent::__construct($sender, $command);
}
}

View File

@ -26,6 +26,7 @@
namespace pocketmine\network\rcon;
use pocketmine\command\RemoteConsoleCommandSender;
use pocketmine\event\server\RemoteServerCommandEvent;
use pocketmine\scheduler\CallbackTask;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
@ -90,7 +91,16 @@ class RCON{
$thread->notify();
}, $this->workers[$n]);
}else{
$this->server->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
$response = new RemoteConsoleCommandSender();
$command = $this->workers[$n]->cmd;
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
if(!$ev->isCancelled()){
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
}
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
$this->workers[$n]->synchronized(function(RCONInstance $thread){
$thread->notify();