mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Added CommandEvent, deprecated (Remote)?ServerCommandEvent (#2376)
This commit is contained in:
parent
0dc4bd36e1
commit
ebffff0caa
@ -39,6 +39,7 @@ use pocketmine\event\HandlerList;
|
|||||||
use pocketmine\event\level\LevelInitEvent;
|
use pocketmine\event\level\LevelInitEvent;
|
||||||
use pocketmine\event\level\LevelLoadEvent;
|
use pocketmine\event\level\LevelLoadEvent;
|
||||||
use pocketmine\event\player\PlayerDataSaveEvent;
|
use pocketmine\event\player\PlayerDataSaveEvent;
|
||||||
|
use pocketmine\event\server\CommandEvent;
|
||||||
use pocketmine\event\server\QueryRegenerateEvent;
|
use pocketmine\event\server\QueryRegenerateEvent;
|
||||||
use pocketmine\event\server\ServerCommandEvent;
|
use pocketmine\event\server\ServerCommandEvent;
|
||||||
use pocketmine\inventory\CraftingManager;
|
use pocketmine\inventory\CraftingManager;
|
||||||
@ -1940,10 +1941,20 @@ class Server{
|
|||||||
*
|
*
|
||||||
* @param CommandSender $sender
|
* @param CommandSender $sender
|
||||||
* @param string $commandLine
|
* @param string $commandLine
|
||||||
|
* @param bool $internal
|
||||||
*
|
*
|
||||||
* @return bool
|
* @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)){
|
if($this->commandMap->dispatch($sender, $commandLine)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class FormattedCommandAlias extends Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($commands as $command){
|
foreach($commands as $command){
|
||||||
$result |= Server::getInstance()->dispatchCommand($sender, $command);
|
$result |= Server::getInstance()->dispatchCommand($sender, $command, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $result;
|
return (bool) $result;
|
||||||
|
73
src/pocketmine/event/server/CommandEvent.php
Normal file
73
src/pocketmine/event/server/CommandEvent.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,8 @@ use pocketmine\command\CommandSender;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is called when a command is received over RCON.
|
* This event is called when a command is received over RCON.
|
||||||
|
*
|
||||||
|
* @deprecated Use CommandEvent instead.
|
||||||
*/
|
*/
|
||||||
class RemoteServerCommandEvent extends ServerCommandEvent{
|
class RemoteServerCommandEvent extends ServerCommandEvent{
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ use pocketmine\event\Cancellable;
|
|||||||
* blocking commands on certain places, or applying modifiers.
|
* blocking commands on certain places, or applying modifiers.
|
||||||
*
|
*
|
||||||
* The message DOES NOT contain a slash at the start
|
* The message DOES NOT contain a slash at the start
|
||||||
|
*
|
||||||
|
* @deprecated Use CommandEvent instead.
|
||||||
*/
|
*/
|
||||||
class ServerCommandEvent extends ServerEvent implements Cancellable{
|
class ServerCommandEvent extends ServerEvent implements Cancellable{
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user