Merge branch 'release/3.2'

This commit is contained in:
Dylan K. Taylor 2018-08-19 13:01:54 +01:00
commit aa55cd9acf
5 changed files with 90 additions and 2 deletions

View File

@ -39,6 +39,7 @@ use pocketmine\event\HandlerList;
use pocketmine\event\level\LevelInitEvent;
use pocketmine\event\level\LevelLoadEvent;
use pocketmine\event\player\PlayerDataSaveEvent;
use pocketmine\event\server\CommandEvent;
use pocketmine\event\server\DataPacketBroadcastEvent;
use pocketmine\event\server\QueryRegenerateEvent;
use pocketmine\event\server\ServerCommandEvent;
@ -1991,10 +1992,20 @@ class Server{
*
* @param CommandSender $sender
* @param string $commandLine
* @param bool $internal
*
* @return bool
*/
public function dispatchCommand(CommandSender $sender, string $commandLine) : bool{
public function dispatchCommand(CommandSender $sender, string $commandLine, bool $internal = false) : bool{
if(!$internal){
$this->pluginManager->callEvent($ev = new CommandEvent($sender, $commandLine));
if($ev->isCancelled()){
return false;
}
$commandLine = $ev->getCommand();
}
if($this->commandMap->dispatch($sender, $commandLine)){
return true;
}

View File

@ -59,7 +59,7 @@ class FormattedCommandAlias extends Command{
}
foreach($commands as $command){
$result |= Server::getInstance()->dispatchCommand($sender, $command);
$result |= Server::getInstance()->dispatchCommand($sender, $command, true);
}
return (bool) $result;

View File

@ -0,0 +1,73 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\server;
use pocketmine\command\CommandSender;
use pocketmine\event\Cancellable;
/**
* Called when any CommandSender runs a command, early in the process
*
* You don't want to use this except for a few cases like logging commands,
* blocking commands on certain places, or applying modifiers.
*
* The message DOES NOT contain a slash at the start
*/
class CommandEvent extends ServerEvent implements Cancellable{
/** @var string */
protected $command;
/** @var CommandSender */
protected $sender;
/**
* @param CommandSender $sender
* @param string $command
*/
public function __construct(CommandSender $sender, string $command){
$this->sender = $sender;
$this->command = $command;
}
/**
* @return CommandSender
*/
public function getSender() : CommandSender{
return $this->sender;
}
/**
* @return string
*/
public function getCommand() : string{
return $this->command;
}
/**
* @param string $command
*/
public function setCommand(string $command) : void{
$this->command = $command;
}
}

View File

@ -27,6 +27,8 @@ use pocketmine\command\CommandSender;
/**
* This event is called when a command is received over RCON.
*
* @deprecated Use CommandEvent instead.
*/
class RemoteServerCommandEvent extends ServerCommandEvent{

View File

@ -33,6 +33,8 @@ use pocketmine\event\Cancellable;
* blocking commands on certain places, or applying modifiers.
*
* The message DOES NOT contain a slash at the start
*
* @deprecated Use CommandEvent instead.
*/
class ServerCommandEvent extends ServerEvent implements Cancellable{
/** @var string */