mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Added typehints and PhpDoc for events API
excluded blocks and entities events API to avoid merge conflicts
This commit is contained in:
parent
6504fdabab
commit
6cd4d2c5a2
@ -28,7 +28,13 @@ namespace pocketmine\event;
|
||||
* Events that can be cancelled must use the interface Cancellable
|
||||
*/
|
||||
interface Cancellable{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCancelled();
|
||||
|
||||
public function setCancelled($value = true);
|
||||
/**
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setCancelled(bool $value = true);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ abstract class Event{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
final public function getEventName(){
|
||||
final public function getEventName() : string{
|
||||
return $this->eventName === null ? get_class($this) : $this->eventName;
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ abstract class Event{
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function isCancelled(){
|
||||
public function isCancelled() : bool{
|
||||
if(!($this instanceof Cancellable)){
|
||||
throw new \BadMethodCallException("Event is not Cancellable");
|
||||
}
|
||||
@ -67,19 +67,19 @@ abstract class Event{
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function setCancelled($value = true){
|
||||
public function setCancelled(bool $value = true){
|
||||
if(!($this instanceof Cancellable)){
|
||||
throw new \BadMethodCallException("Event is not Cancellable");
|
||||
}
|
||||
|
||||
/** @var Event $this */
|
||||
$this->isCancelled = (bool) $value;
|
||||
$this->isCancelled = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HandlerList
|
||||
*/
|
||||
public function getHandlers(){
|
||||
public function getHandlers() : HandlerList{
|
||||
if(static::$handlerList === null){
|
||||
static::$handlerList = new HandlerList();
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ class HandlerList{
|
||||
*
|
||||
* @return RegisteredListener[]
|
||||
*/
|
||||
public function getRegisteredListeners($plugin = null){
|
||||
public function getRegisteredListeners($plugin = null) : array{
|
||||
if($plugin !== null){
|
||||
$listeners = [];
|
||||
foreach($this->getRegisteredListeners(null) as $hash => $listener){
|
||||
@ -174,7 +174,7 @@ class HandlerList{
|
||||
/**
|
||||
* @return HandlerList[]
|
||||
*/
|
||||
public static function getHandlerLists(){
|
||||
public static function getHandlerLists() : array{
|
||||
return self::$allLists;
|
||||
}
|
||||
|
||||
|
@ -28,25 +28,31 @@ class TextContainer{
|
||||
/** @var string $text */
|
||||
protected $text;
|
||||
|
||||
public function __construct($text){
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function __construct(string $text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function setText($text){
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText(string $text){
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getText(){
|
||||
public function getText() : string{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(){
|
||||
public function __toString() : string{
|
||||
return $this->getText();
|
||||
}
|
||||
}
|
@ -172,11 +172,11 @@ abstract class Timings{
|
||||
|
||||
/**
|
||||
* @param TaskHandler $task
|
||||
* @param $period
|
||||
* @param int $period
|
||||
*
|
||||
* @return TimingsHandler
|
||||
*/
|
||||
public static function getPluginTaskTimings(TaskHandler $task, $period){
|
||||
public static function getPluginTaskTimings(TaskHandler $task, int $period){
|
||||
$ftask = $task->getTask();
|
||||
if($ftask instanceof PluginTask and $ftask->getOwner() !== null){
|
||||
$plugin = $ftask->getOwner()->getDescription()->getFullName();
|
||||
|
@ -49,7 +49,7 @@ class TimingsHandler{
|
||||
* @param string $name
|
||||
* @param TimingsHandler $parent
|
||||
*/
|
||||
public function __construct($name, TimingsHandler $parent = null){
|
||||
public function __construct(string $name, TimingsHandler $parent = null){
|
||||
$this->name = $name;
|
||||
if($parent !== null){
|
||||
$this->parent = $parent;
|
||||
@ -58,6 +58,9 @@ class TimingsHandler{
|
||||
self::$HANDLERS[spl_object_hash($this)] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $fp
|
||||
*/
|
||||
public static function printTimings($fp){
|
||||
fwrite($fp, "Minecraft" . PHP_EOL);
|
||||
|
||||
@ -100,7 +103,7 @@ class TimingsHandler{
|
||||
}
|
||||
}
|
||||
|
||||
public static function tick($measure = true){
|
||||
public static function tick(bool $measure = true){
|
||||
if(PluginManager::$useTimings){
|
||||
if($measure){
|
||||
foreach(self::$HANDLERS as $timings){
|
||||
|
@ -32,7 +32,7 @@ class TranslationContainer extends TextContainer{
|
||||
* @param string $text
|
||||
* @param string[] $params
|
||||
*/
|
||||
public function __construct($text, array $params = []){
|
||||
public function __construct(string $text, array $params = []){
|
||||
parent::__construct($text);
|
||||
|
||||
$this->setParameters($params);
|
||||
@ -41,7 +41,7 @@ class TranslationContainer extends TextContainer{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getParameters(){
|
||||
public function getParameters() : array{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
@ -50,20 +50,20 @@ class TranslationContainer extends TextContainer{
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getParameter($i){
|
||||
return isset($this->params[$i]) ? $this->params[$i] : null;
|
||||
public function getParameter(int $i){
|
||||
return $this->params[$i] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $i
|
||||
* @param string $str
|
||||
*/
|
||||
public function setParameter($i, $str){
|
||||
public function setParameter(int $i, string $str){
|
||||
if($i < 0 or $i > count($this->params)){ //Intended, allow to set the last
|
||||
throw new \InvalidArgumentException("Invalid index $i, have " . count($this->params));
|
||||
}
|
||||
|
||||
$this->params[(int) $i] = $str;
|
||||
$this->params[$i] = $str;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,8 @@ class CraftItemEvent extends Event implements Cancellable{
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param Item[] $input
|
||||
* @param Recipe $recipe
|
||||
* @param Item[] $input
|
||||
* @param Recipe $recipe
|
||||
*/
|
||||
public function __construct(Player $player, array $input, Recipe $recipe){
|
||||
$this->player = $player;
|
||||
@ -54,26 +54,23 @@ class CraftItemEvent extends Event implements Cancellable{
|
||||
/**
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getInput(){
|
||||
$items = [];
|
||||
foreach($this->input as $i => $item){
|
||||
$items[$i] = clone $item;
|
||||
}
|
||||
|
||||
return $items;
|
||||
public function getInput() : array{
|
||||
return array_map(function(Item $item) : Item{
|
||||
return clone $item;
|
||||
}, $this->input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Recipe
|
||||
*/
|
||||
public function getRecipe(){
|
||||
public function getRecipe() : Recipe{
|
||||
return $this->recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer(){
|
||||
public function getPlayer() : Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
||||
|
@ -31,57 +31,66 @@ use pocketmine\tile\Furnace;
|
||||
class FurnaceBurnEvent extends BlockEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Furnace */
|
||||
private $furnace;
|
||||
/** @var Item */
|
||||
private $fuel;
|
||||
/** @var int */
|
||||
private $burnTime;
|
||||
/** @var bool */
|
||||
private $burning = true;
|
||||
|
||||
public function __construct(Furnace $furnace, Item $fuel, $burnTime){
|
||||
/**
|
||||
* @param Furnace $furnace
|
||||
* @param Item $fuel
|
||||
* @param int $burnTime
|
||||
*/
|
||||
public function __construct(Furnace $furnace, Item $fuel, int $burnTime){
|
||||
parent::__construct($furnace->getBlock());
|
||||
$this->fuel = $fuel;
|
||||
$this->burnTime = (int) $burnTime;
|
||||
$this->burnTime = $burnTime;
|
||||
$this->furnace = $furnace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Furnace
|
||||
*/
|
||||
public function getFurnace(){
|
||||
public function getFurnace() : Furnace{
|
||||
return $this->furnace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getFuel(){
|
||||
public function getFuel() : Item{
|
||||
return $this->fuel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBurnTime(){
|
||||
public function getBurnTime() : int{
|
||||
return $this->burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $burnTime
|
||||
*/
|
||||
public function setBurnTime($burnTime){
|
||||
$this->burnTime = (int) $burnTime;
|
||||
public function setBurnTime(int $burnTime){
|
||||
$this->burnTime = $burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isBurning(){
|
||||
public function isBurning() : bool{
|
||||
return $this->burning;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $burning
|
||||
*/
|
||||
public function setBurning($burning){
|
||||
$this->burning = (bool) $burning;
|
||||
public function setBurning(bool $burning){
|
||||
$this->burning = $burning;
|
||||
}
|
||||
}
|
@ -31,10 +31,18 @@ use pocketmine\tile\Furnace;
|
||||
class FurnaceSmeltEvent extends BlockEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Furnace */
|
||||
private $furnace;
|
||||
/** @var Item */
|
||||
private $source;
|
||||
/** @var Item */
|
||||
private $result;
|
||||
|
||||
/**
|
||||
* @param Furnace $furnace
|
||||
* @param Item $source
|
||||
* @param Item $result
|
||||
*/
|
||||
public function __construct(Furnace $furnace, Item $source, Item $result){
|
||||
parent::__construct($furnace->getBlock());
|
||||
$this->source = clone $source;
|
||||
@ -46,21 +54,21 @@ class FurnaceSmeltEvent extends BlockEvent implements Cancellable{
|
||||
/**
|
||||
* @return Furnace
|
||||
*/
|
||||
public function getFurnace(){
|
||||
public function getFurnace() : Furnace{
|
||||
return $this->furnace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getSource(){
|
||||
public function getSource() : Item{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getResult(){
|
||||
public function getResult() : Item{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class InventoryCloseEvent extends InventoryEvent{
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer(){
|
||||
public function getPlayer() : Player{
|
||||
return $this->who;
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,14 @@ abstract class InventoryEvent extends Event{
|
||||
/**
|
||||
* @return Inventory
|
||||
*/
|
||||
public function getInventory(){
|
||||
public function getInventory() : Inventory{
|
||||
return $this->inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Human[]
|
||||
*/
|
||||
public function getViewers(){
|
||||
public function getViewers() : array{
|
||||
return $this->inventory->getViewers();
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ class InventoryOpenEvent extends InventoryEvent implements Cancellable{
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer(){
|
||||
public function getPlayer() : Player{
|
||||
return $this->who;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class InventoryPickupArrowEvent extends InventoryEvent implements Cancellable{
|
||||
/**
|
||||
* @return Arrow
|
||||
*/
|
||||
public function getArrow(){
|
||||
public function getArrow() : Arrow{
|
||||
return $this->arrow;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class InventoryTransactionEvent extends Event implements Cancellable{
|
||||
/**
|
||||
* @return TransactionGroup
|
||||
*/
|
||||
public function getTransaction(){
|
||||
public function getTransaction() : TransactionGroup{
|
||||
return $this->ts;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ abstract class ChunkEvent extends LevelEvent{
|
||||
/**
|
||||
* @return Chunk
|
||||
*/
|
||||
public function getChunk(){
|
||||
public function getChunk() : Chunk{
|
||||
return $this->chunk;
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ use pocketmine\level\format\Chunk;
|
||||
class ChunkLoadEvent extends ChunkEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var bool */
|
||||
private $newChunk;
|
||||
|
||||
public function __construct(Level $level, Chunk $chunk, bool $newChunk){
|
||||
@ -43,7 +44,7 @@ class ChunkLoadEvent extends ChunkEvent{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNewChunk(){
|
||||
public function isNewChunk() : bool{
|
||||
return $this->newChunk;
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ abstract class LevelEvent extends Event{
|
||||
/**
|
||||
* @return Level
|
||||
*/
|
||||
public function getLevel(){
|
||||
public function getLevel() : Level{
|
||||
return $this->level;
|
||||
}
|
||||
}
|
@ -48,7 +48,7 @@ class SpawnChangeEvent extends LevelEvent{
|
||||
/**
|
||||
* @return Position
|
||||
*/
|
||||
public function getPreviousSpawn(){
|
||||
public function getPreviousSpawn() : Position{
|
||||
return $this->previousSpawn;
|
||||
}
|
||||
}
|
@ -39,12 +39,15 @@ class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable{
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
*/
|
||||
public function __construct(Player $player, $achievementId){
|
||||
public function __construct(Player $player, string $achievementId){
|
||||
$this->player = $player;
|
||||
$this->achievement = $achievementId;
|
||||
}
|
||||
|
||||
public function getAchievement(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAchievement() : string{
|
||||
return $this->achievement;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ class PlayerAnimationEvent extends PlayerEvent implements Cancellable{
|
||||
|
||||
const ARM_SWING = 1;
|
||||
|
||||
/** @var int */
|
||||
private $animationType;
|
||||
|
||||
/**
|
||||
@ -48,7 +49,7 @@ class PlayerAnimationEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getAnimationType(){
|
||||
public function getAnimationType() : int{
|
||||
return $this->animationType;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ use pocketmine\Player;
|
||||
class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Block */
|
||||
private $bed;
|
||||
|
||||
public function __construct(Player $player, Block $bed){
|
||||
@ -37,7 +38,10 @@ class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
|
||||
$this->bed = $bed;
|
||||
}
|
||||
|
||||
public function getBed(){
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public function getBed() : Block{
|
||||
return $this->bed;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ use pocketmine\Player;
|
||||
class PlayerBedLeaveEvent extends PlayerEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Block */
|
||||
private $bed;
|
||||
|
||||
public function __construct(Player $player, Block $bed){
|
||||
@ -36,7 +37,10 @@ class PlayerBedLeaveEvent extends PlayerEvent{
|
||||
$this->bed = $bed;
|
||||
}
|
||||
|
||||
public function getBed(){
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public function getBed() : Block{
|
||||
return $this->bed;
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
|
||||
* @param Item $bucket
|
||||
* @param Item $itemInHand
|
||||
*/
|
||||
public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){
|
||||
public function __construct(Player $who, Block $blockClicked, int $blockFace, Item $bucket, Item $itemInHand){
|
||||
$this->player = $who;
|
||||
$this->blockClicked = $blockClicked;
|
||||
$this->blockFace = (int) $blockFace;
|
||||
$this->blockFace = $blockFace;
|
||||
$this->item = $itemInHand;
|
||||
$this->bucket = $bucket;
|
||||
}
|
||||
@ -59,7 +59,7 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getBucket(){
|
||||
public function getBucket() : Item{
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
@ -82,14 +82,14 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public function getBlockClicked(){
|
||||
public function getBlockClicked() : Block{
|
||||
return $this->blockClicked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBlockFace(){
|
||||
public function getBlockFace() : int{
|
||||
return $this->blockFace;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,4 @@ use pocketmine\Player;
|
||||
|
||||
class PlayerBucketFillEvent extends PlayerBucketEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){
|
||||
parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand);
|
||||
}
|
||||
}
|
@ -44,7 +44,13 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
|
||||
*/
|
||||
protected $recipients = [];
|
||||
|
||||
public function __construct(Player $player, $message, $format = "chat.type.text", array $recipients = null){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $message
|
||||
* @param string $format
|
||||
* @param Player[] $recipients
|
||||
*/
|
||||
public function __construct(Player $player, string $message, string $format = "chat.type.text", array $recipients = null){
|
||||
$this->player = $player;
|
||||
$this->message = $message;
|
||||
|
||||
@ -57,11 +63,17 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
|
||||
}
|
||||
}
|
||||
|
||||
public function getMessage(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage() : string{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMessage($message){
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function setMessage(string $message){
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
@ -74,18 +86,30 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getFormat(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFormat() : string{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
public function setFormat($format){
|
||||
/**
|
||||
* @param string $format
|
||||
*/
|
||||
public function setFormat(string $format){
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
public function getRecipients(){
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getRecipients() : array{
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player[] $recipients
|
||||
*/
|
||||
public function setRecipients(array $recipients){
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
|
@ -53,14 +53,14 @@ class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(){
|
||||
public function getMessage() : string{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function setMessage($message){
|
||||
public function setMessage(string $message){
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,13 @@ class PlayerCreationEvent extends Event{
|
||||
|
||||
/**
|
||||
* @param SourceInterface $interface
|
||||
* @param Player::class $baseClass
|
||||
* @param Player::class $playerClass
|
||||
* @param Player::class $baseClass
|
||||
* @param Player::class $playerClass
|
||||
* @param mixed $clientId
|
||||
* @param string $address
|
||||
* @param int $port
|
||||
*/
|
||||
public function __construct(SourceInterface $interface, $baseClass, $playerClass, $clientId, $address, $port){
|
||||
public function __construct(SourceInterface $interface, $baseClass, $playerClass, $clientId, string $address, int $port){
|
||||
$this->interface = $interface;
|
||||
$this->clientId = $clientId;
|
||||
$this->address = $address;
|
||||
@ -77,21 +77,21 @@ class PlayerCreationEvent extends Event{
|
||||
/**
|
||||
* @return SourceInterface
|
||||
*/
|
||||
public function getInterface(){
|
||||
public function getInterface() : SourceInterface{
|
||||
return $this->interface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(){
|
||||
public function getAddress() : string{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPort(){
|
||||
public function getPort() : int{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
|
@ -48,14 +48,14 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getEntity(){
|
||||
public function getEntity() : Player{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer(){
|
||||
public function getPlayer() : Player{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
@ -73,12 +73,12 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
$this->deathMessage = $deathMessage;
|
||||
}
|
||||
|
||||
public function getKeepInventory(){
|
||||
public function getKeepInventory() : bool{
|
||||
return $this->keepInventory;
|
||||
}
|
||||
|
||||
public function setKeepInventory($keepInventory){
|
||||
$this->keepInventory = (bool) $keepInventory;
|
||||
public function setKeepInventory(bool $keepInventory){
|
||||
$this->keepInventory = $keepInventory;
|
||||
}
|
||||
|
||||
}
|
@ -48,7 +48,7 @@ class PlayerDropItemEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return $this->drop;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ abstract class PlayerEvent extends Event{
|
||||
/** @var Player */
|
||||
protected $player;
|
||||
|
||||
public function getPlayer(){
|
||||
public function getPlayer() : Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
@ -25,9 +25,10 @@ namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\entity\EntityEvent;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerExhaustEvent extends PlayerEvent implements Cancellable{
|
||||
class PlayerExhaustEvent extends EntityEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
const CAUSE_ATTACK = 1;
|
||||
@ -47,14 +48,18 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var int */
|
||||
private $cause;
|
||||
|
||||
/** @var Human */
|
||||
protected $player;
|
||||
|
||||
public function __construct(Human $human, float $amount, int $cause){
|
||||
$this->entity = $human;
|
||||
$this->player = $human;
|
||||
$this->amount = $amount;
|
||||
$this->cause = $cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Human|Player
|
||||
* @return Human
|
||||
*/
|
||||
public function getPlayer(){
|
||||
return $this->player;
|
||||
|
@ -35,12 +35,12 @@ class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var int */
|
||||
protected $gamemode;
|
||||
|
||||
public function __construct(Player $player, $newGamemode){
|
||||
public function __construct(Player $player, int $newGamemode){
|
||||
$this->player = $player;
|
||||
$this->gamemode = (int) $newGamemode;
|
||||
$this->gamemode = $newGamemode;
|
||||
}
|
||||
|
||||
public function getNewGamemode(){
|
||||
public function getNewGamemode() : int{
|
||||
return $this->gamemode;
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,10 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
const RIGHT_CLICK_AIR = 3;
|
||||
const PHYSICAL = 4;
|
||||
|
||||
/**
|
||||
* @var Block
|
||||
*/
|
||||
/** @var Block */
|
||||
protected $blockTouched;
|
||||
|
||||
/** @var Vector3 */
|
||||
protected $touchVector;
|
||||
|
||||
/** @var int */
|
||||
@ -55,9 +54,10 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var Item */
|
||||
protected $item;
|
||||
|
||||
/** @var int */
|
||||
protected $action;
|
||||
|
||||
public function __construct(Player $player, Item $item, Vector3 $block, $face, $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
|
||||
public function __construct(Player $player, Item $item, Vector3 $block, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
|
||||
if($block instanceof Block){
|
||||
$this->blockTouched = $block;
|
||||
$this->touchVector = new Vector3(0, 0, 0);
|
||||
@ -67,42 +67,42 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
}
|
||||
$this->player = $player;
|
||||
$this->item = $item;
|
||||
$this->blockFace = (int) $face;
|
||||
$this->action = (int) $action;
|
||||
$this->blockFace = $face;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getAction(){
|
||||
public function getAction() : int{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public function getBlock(){
|
||||
public function getBlock() : Block{
|
||||
return $this->blockTouched;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Vector3
|
||||
*/
|
||||
public function getTouchVector(){
|
||||
public function getTouchVector() : Vector3{
|
||||
return $this->touchVector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getFace(){
|
||||
public function getFace() : int{
|
||||
return $this->blockFace;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return clone $this->item;
|
||||
}
|
||||
|
||||
|
@ -30,26 +30,36 @@ use pocketmine\Player;
|
||||
class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Item */
|
||||
private $item;
|
||||
private $slot;
|
||||
/** @var int */
|
||||
private $hotbarSlot;
|
||||
/** @var int */
|
||||
private $inventorySlot;
|
||||
|
||||
public function __construct(Player $player, Item $item, $inventorySlot, $slot){
|
||||
public function __construct(Player $player, Item $item, int $inventorySlot, int $hotbarSlot){
|
||||
$this->player = $player;
|
||||
$this->item = $item;
|
||||
$this->inventorySlot = (int) $inventorySlot;
|
||||
$this->slot = (int) $slot;
|
||||
$this->inventorySlot = $inventorySlot;
|
||||
$this->hotbarSlot = $hotbarSlot;
|
||||
}
|
||||
|
||||
public function getSlot(){
|
||||
return $this->slot;
|
||||
/**
|
||||
* Returns the hotbar slot the player is attempting to hold.
|
||||
* @return int
|
||||
*/
|
||||
public function getSlot() : int{
|
||||
return $this->hotbarSlot;
|
||||
}
|
||||
|
||||
public function getInventorySlot(){
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getInventorySlot() : int{
|
||||
return $this->inventorySlot;
|
||||
}
|
||||
|
||||
public function getItem(){
|
||||
public function getItem() : Item{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,12 @@ class PlayerJoinEvent extends PlayerEvent{
|
||||
/** @var string|TextContainer */
|
||||
protected $joinMessage;
|
||||
|
||||
/**
|
||||
* PlayerJoinEvent constructor.
|
||||
*
|
||||
* @param Player $player
|
||||
* @param TextContainer|string $joinMessage
|
||||
*/
|
||||
public function __construct(Player $player, $joinMessage){
|
||||
$this->player = $player;
|
||||
$this->joinMessage = $joinMessage;
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\TextContainer;
|
||||
use pocketmine\Player;
|
||||
|
||||
/**
|
||||
@ -32,26 +33,39 @@ use pocketmine\Player;
|
||||
class PlayerKickEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var string */
|
||||
/** @var TextContainer|string */
|
||||
protected $quitMessage;
|
||||
|
||||
/** @var string */
|
||||
protected $reason;
|
||||
|
||||
public function __construct(Player $player, $reason, $quitMessage){
|
||||
/**
|
||||
* PlayerKickEvent constructor.
|
||||
*
|
||||
* @param Player $player
|
||||
* @param string $reason
|
||||
* @param TextContainer|string $quitMessage
|
||||
*/
|
||||
public function __construct(Player $player, string $reason, $quitMessage){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
public function getReason(){
|
||||
public function getReason() : string{
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TextContainer|string $quitMessage
|
||||
*/
|
||||
public function setQuitMessage($quitMessage){
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TextContainer|string
|
||||
*/
|
||||
public function getQuitMessage(){
|
||||
return $this->quitMessage;
|
||||
}
|
||||
|
@ -35,16 +35,26 @@ class PlayerLoginEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var string */
|
||||
protected $kickMessage;
|
||||
|
||||
public function __construct(Player $player, $kickMessage){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $kickMessage
|
||||
*/
|
||||
public function __construct(Player $player, string $kickMessage){
|
||||
$this->player = $player;
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function setKickMessage($kickMessage){
|
||||
/**
|
||||
* @param string $kickMessage
|
||||
*/
|
||||
public function setKickMessage(string $kickMessage){
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function getKickMessage(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKickMessage() : string{
|
||||
return $this->kickMessage;
|
||||
}
|
||||
|
||||
|
@ -30,27 +30,46 @@ use pocketmine\Player;
|
||||
class PlayerMoveEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Location */
|
||||
private $from;
|
||||
/** @var Location */
|
||||
private $to;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param Location $from
|
||||
* @param Location $to
|
||||
*/
|
||||
public function __construct(Player $player, Location $from, Location $to){
|
||||
$this->player = $player;
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
}
|
||||
|
||||
public function getFrom(){
|
||||
/**
|
||||
* @return Location
|
||||
*/
|
||||
public function getFrom() : Location{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Location $from
|
||||
*/
|
||||
public function setFrom(Location $from){
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
public function getTo(){
|
||||
/**
|
||||
* @return Location
|
||||
*/
|
||||
public function getTo() : Location{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Location $to
|
||||
*/
|
||||
public function setTo(Location $to){
|
||||
$this->to = $to;
|
||||
}
|
||||
|
@ -35,16 +35,26 @@ class PlayerPreLoginEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var string */
|
||||
protected $kickMessage;
|
||||
|
||||
public function __construct(Player $player, $kickMessage){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $kickMessage
|
||||
*/
|
||||
public function __construct(Player $player, string $kickMessage){
|
||||
$this->player = $player;
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function setKickMessage($kickMessage){
|
||||
/**
|
||||
* @param string $kickMessage
|
||||
*/
|
||||
public function setKickMessage(string $kickMessage){
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function getKickMessage(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKickMessage() : string{
|
||||
return $this->kickMessage;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class PlayerRespawnEvent extends PlayerEvent{
|
||||
/**
|
||||
* @return Position
|
||||
*/
|
||||
public function getRespawnPosition(){
|
||||
public function getRespawnPosition() : Position{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,19 @@ class PlayerToggleFlightEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var bool */
|
||||
protected $isFlying;
|
||||
|
||||
public function __construct(Player $player, $isFlying){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param bool $isFlying
|
||||
*/
|
||||
public function __construct(Player $player, bool $isFlying){
|
||||
$this->player = $player;
|
||||
$this->isFlying = (bool) $isFlying;
|
||||
$this->isFlying = $isFlying;
|
||||
}
|
||||
|
||||
public function isFlying(){
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isFlying() : bool{
|
||||
return $this->isFlying;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,19 @@ class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var bool */
|
||||
protected $isSneaking;
|
||||
|
||||
public function __construct(Player $player, $isSneaking){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param bool $isSneaking
|
||||
*/
|
||||
public function __construct(Player $player, bool $isSneaking){
|
||||
$this->player = $player;
|
||||
$this->isSneaking = (bool) $isSneaking;
|
||||
$this->isSneaking = $isSneaking;
|
||||
}
|
||||
|
||||
public function isSneaking(){
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSneaking() : bool{
|
||||
return $this->isSneaking;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,19 @@ class PlayerToggleSprintEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var bool */
|
||||
protected $isSprinting;
|
||||
|
||||
public function __construct(Player $player, $isSprinting){
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param bool $isSprinting
|
||||
*/
|
||||
public function __construct(Player $player, bool $isSprinting){
|
||||
$this->player = $player;
|
||||
$this->isSprinting = (bool) $isSprinting;
|
||||
$this->isSprinting = $isSprinting;
|
||||
}
|
||||
|
||||
public function isSprinting(){
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSprinting() : bool{
|
||||
return $this->isSprinting;
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,19 @@ use pocketmine\Player;
|
||||
class PlayerTransferEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var string */
|
||||
protected $address;
|
||||
/** @var int */
|
||||
protected $port = 19132;
|
||||
/** @var string */
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $address
|
||||
* @param int $port
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct(Player $player, string $address, int $port, string $message){
|
||||
$this->player = $player;
|
||||
$this->address = $address;
|
||||
@ -40,26 +49,44 @@ class PlayerTransferEvent extends PlayerEvent implements Cancellable{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress() : string{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*/
|
||||
public function setAddress(string $address){
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPort() : int{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $port
|
||||
*/
|
||||
public function setPort(int $port){
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage() : string{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function setMessage(string $message){
|
||||
$this->message = $message;
|
||||
}
|
||||
|
@ -21,25 +21,35 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Events called when a player attempts to perform movement cheats such as clipping through blocks.
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player\cheat;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\math\Vector3;
|
||||
|
||||
/**
|
||||
* Called when a player attempts to perform movement cheats such as clipping through blocks.
|
||||
*/
|
||||
class PlayerIllegalMoveEvent extends PlayerCheatEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Vector3 */
|
||||
private $attemptedPosition;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param Vector3 $attemptedPosition
|
||||
*/
|
||||
public function __construct(Player $player, Vector3 $attemptedPosition){
|
||||
$this->attemptedPosition = $attemptedPosition;
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position the player attempted to move to.
|
||||
* @return Vector3
|
||||
*/
|
||||
public function getAttemptedPosition() : Vector3{
|
||||
return $this->attemptedPosition;
|
||||
}
|
||||
|
@ -24,15 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\plugin;
|
||||
|
||||
use pocketmine\plugin\Plugin;
|
||||
|
||||
class PluginDisableEvent extends PluginEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/**
|
||||
* @param Plugin $plugin
|
||||
*/
|
||||
public function __construct(Plugin $plugin){
|
||||
parent::__construct($plugin);
|
||||
}
|
||||
}
|
||||
|
@ -24,15 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\plugin;
|
||||
|
||||
use pocketmine\plugin\Plugin;
|
||||
|
||||
class PluginEnableEvent extends PluginEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/**
|
||||
* @param Plugin $plugin
|
||||
*/
|
||||
public function __construct(Plugin $plugin){
|
||||
parent::__construct($plugin);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ abstract class PluginEvent extends Event{
|
||||
/**
|
||||
* @return Plugin
|
||||
*/
|
||||
public function getPlugin(){
|
||||
public function getPlugin() : Plugin{
|
||||
return $this->plugin;
|
||||
}
|
||||
}
|
||||
|
@ -30,19 +30,31 @@ use pocketmine\Player;
|
||||
class DataPacketReceiveEvent extends ServerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var DataPacket */
|
||||
private $packet;
|
||||
/** @var Player */
|
||||
private $player;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param DataPacket $packet
|
||||
*/
|
||||
public function __construct(Player $player, DataPacket $packet){
|
||||
$this->packet = $packet;
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getPacket(){
|
||||
/**
|
||||
* @return DataPacket
|
||||
*/
|
||||
public function getPacket() : DataPacket{
|
||||
return $this->packet;
|
||||
}
|
||||
|
||||
public function getPlayer(){
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer() : Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
@ -30,19 +30,31 @@ use pocketmine\Player;
|
||||
class DataPacketSendEvent extends ServerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var DataPacket */
|
||||
private $packet;
|
||||
/** @var Player */
|
||||
private $player;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param DataPacket $packet
|
||||
*/
|
||||
public function __construct(Player $player, DataPacket $packet){
|
||||
$this->packet = $packet;
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getPacket(){
|
||||
/**
|
||||
* @return DataPacket
|
||||
*/
|
||||
public function getPacket() : DataPacket{
|
||||
return $this->packet;
|
||||
}
|
||||
|
||||
public function getPlayer(){
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer() : Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
@ -37,14 +37,16 @@ class LowMemoryEvent extends ServerEvent{
|
||||
private $memory;
|
||||
/** @var int */
|
||||
private $memoryLimit;
|
||||
/** @var int */
|
||||
private $triggerCount;
|
||||
/** @var bool */
|
||||
private $global;
|
||||
|
||||
public function __construct($memory, $memoryLimit, $isGlobal = false, $triggerCount = 0){
|
||||
public function __construct(int $memory, int $memoryLimit, bool $isGlobal = false, int $triggerCount = 0){
|
||||
$this->memory = $memory;
|
||||
$this->memoryLimit = $memoryLimit;
|
||||
$this->global = (bool) $isGlobal;
|
||||
$this->triggerCount = (int) $triggerCount;
|
||||
$this->global = $isGlobal;
|
||||
$this->triggerCount = $triggerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +54,7 @@ class LowMemoryEvent extends ServerEvent{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMemory(){
|
||||
public function getMemory() : int{
|
||||
return $this->memory;
|
||||
}
|
||||
|
||||
@ -61,7 +63,7 @@ class LowMemoryEvent extends ServerEvent{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMemoryLimit(){
|
||||
public function getMemoryLimit() : int{
|
||||
return $this->memoryLimit;
|
||||
}
|
||||
|
||||
@ -70,14 +72,14 @@ class LowMemoryEvent extends ServerEvent{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTriggerCount(){
|
||||
public function getTriggerCount() : int{
|
||||
return $this->triggerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isGlobal(){
|
||||
public function isGlobal() : bool{
|
||||
return $this->global;
|
||||
}
|
||||
|
||||
@ -86,7 +88,7 @@ class LowMemoryEvent extends ServerEvent{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMemoryFreed(){
|
||||
public function getMemoryFreed() : int{
|
||||
return $this->getMemory() - ($this->isGlobal() ? Utils::getMemoryUsage(true)[1] : Utils::getMemoryUsage(true)[0]);
|
||||
}
|
||||
|
||||
|
@ -33,28 +33,45 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
|
||||
const GAME_ID = "MINECRAFTPE";
|
||||
|
||||
/** @var int */
|
||||
private $timeout;
|
||||
/** @var string */
|
||||
private $serverName;
|
||||
/** @var bool */
|
||||
private $listPlugins;
|
||||
/** @var Plugin[] */
|
||||
private $plugins;
|
||||
/** @var Player[] */
|
||||
private $players;
|
||||
|
||||
/** @var string */
|
||||
private $gametype;
|
||||
/** @var string */
|
||||
private $version;
|
||||
/** @var string */
|
||||
private $server_engine;
|
||||
/** @var string */
|
||||
private $map;
|
||||
/** @var int */
|
||||
private $numPlayers;
|
||||
/** @var int */
|
||||
private $maxPlayers;
|
||||
/** @var string */
|
||||
private $whitelist;
|
||||
/** @var int */
|
||||
private $port;
|
||||
/** @var string */
|
||||
private $ip;
|
||||
|
||||
/** @var array */
|
||||
private $extraData = [];
|
||||
|
||||
|
||||
public function __construct(Server $server, $timeout = 5){
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function __construct(Server $server, int $timeout = 5){
|
||||
$this->timeout = $timeout;
|
||||
$this->serverName = $server->getMotd();
|
||||
$this->listPlugins = $server->getProperty("settings.query-plugins", true);
|
||||
@ -83,34 +100,49 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeout(){
|
||||
public function getTimeout() : int{
|
||||
return $this->timeout;
|
||||
}
|
||||
|
||||
public function setTimeout($timeout){
|
||||
/**
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function setTimeout(int $timeout){
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
public function getServerName(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServerName() : string{
|
||||
return $this->serverName;
|
||||
}
|
||||
|
||||
public function setServerName($serverName){
|
||||
/**
|
||||
* @param string $serverName
|
||||
*/
|
||||
public function setServerName(string $serverName){
|
||||
$this->serverName = $serverName;
|
||||
}
|
||||
|
||||
public function canListPlugins(){
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function canListPlugins() : bool{
|
||||
return $this->listPlugins;
|
||||
}
|
||||
|
||||
public function setListPlugins($value){
|
||||
$this->listPlugins = (bool) $value;
|
||||
/**
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setListPlugins(bool $value){
|
||||
$this->listPlugins = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Plugin[]
|
||||
*/
|
||||
public function getPlugins(){
|
||||
public function getPlugins() : array{
|
||||
return $this->plugins;
|
||||
}
|
||||
|
||||
@ -124,7 +156,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getPlayerList(){
|
||||
public function getPlayerList() : array{
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
@ -135,28 +167,46 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
$this->players = $players;
|
||||
}
|
||||
|
||||
public function getPlayerCount(){
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayerCount() : int{
|
||||
return $this->numPlayers;
|
||||
}
|
||||
|
||||
public function setPlayerCount($count){
|
||||
$this->numPlayers = (int) $count;
|
||||
/**
|
||||
* @param int $count
|
||||
*/
|
||||
public function setPlayerCount(int $count){
|
||||
$this->numPlayers = $count;
|
||||
}
|
||||
|
||||
public function getMaxPlayerCount(){
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxPlayerCount() : int{
|
||||
return $this->maxPlayers;
|
||||
}
|
||||
|
||||
public function setMaxPlayerCount($count){
|
||||
$this->maxPlayers = (int) $count;
|
||||
/**
|
||||
* @param int $count
|
||||
*/
|
||||
public function setMaxPlayerCount(int $count){
|
||||
$this->maxPlayers = $count;
|
||||
}
|
||||
|
||||
public function getWorld(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorld() : string{
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
public function setWorld($world){
|
||||
$this->map = (string) $world;
|
||||
/**
|
||||
* @param string $world
|
||||
*/
|
||||
public function setWorld(string $world){
|
||||
$this->map = $world;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,15 +214,21 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtraData(){
|
||||
public function getExtraData() : array{
|
||||
return $this->extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $extraData
|
||||
*/
|
||||
public function setExtraData(array $extraData){
|
||||
$this->extraData = $extraData;
|
||||
}
|
||||
|
||||
public function getLongQuery(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLongQuery() : string{
|
||||
$query = "";
|
||||
|
||||
$plist = $this->server_engine;
|
||||
@ -218,7 +274,10 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getShortQuery(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getShortQuery() : string{
|
||||
return $this->serverName . "\x00" . $this->gametype . "\x00" . $this->map . "\x00" . $this->numPlayers . "\x00" . $this->maxPlayers . "\x00" . Binary::writeLShort($this->port) . $this->ip . "\x00";
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class RemoteServerCommandEvent extends ServerCommandEvent{
|
||||
* @param CommandSender $sender
|
||||
* @param string $command
|
||||
*/
|
||||
public function __construct(CommandSender $sender, $command){
|
||||
public function __construct(CommandSender $sender, string $command){
|
||||
parent::__construct($sender, $command);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class ServerCommandEvent extends ServerEvent implements Cancellable{
|
||||
* @param CommandSender $sender
|
||||
* @param string $command
|
||||
*/
|
||||
public function __construct(CommandSender $sender, $command){
|
||||
public function __construct(CommandSender $sender, string $command){
|
||||
$this->sender = $sender;
|
||||
$this->command = $command;
|
||||
}
|
||||
@ -55,21 +55,21 @@ class ServerCommandEvent extends ServerEvent implements Cancellable{
|
||||
/**
|
||||
* @return CommandSender
|
||||
*/
|
||||
public function getSender(){
|
||||
public function getSender() : CommandSender{
|
||||
return $this->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCommand(){
|
||||
public function getCommand() : string{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
*/
|
||||
public function setCommand($command){
|
||||
public function setCommand(string $command){
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user