Removed pocketmine subdirectory, map PSR-4 style

This commit is contained in:
Dylan K. Taylor
2019-07-30 19:14:57 +01:00
parent 7a77d3dc30
commit 5499ac620c
1044 changed files with 3 additions and 3 deletions

View File

@ -0,0 +1,48 @@
<?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\player;
use pocketmine\block\Block;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Block */
private $bed;
public function __construct(Player $player, Block $bed){
$this->player = $player;
$this->bed = $bed;
}
/**
* @return Block
*/
public function getBed() : Block{
return $this->bed;
}
}

View File

@ -0,0 +1,44 @@
<?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\player;
use pocketmine\block\Block;
use pocketmine\player\Player;
class PlayerBedLeaveEvent extends PlayerEvent{
/** @var Block */
private $bed;
public function __construct(Player $player, Block $bed){
$this->player = $player;
$this->bed = $bed;
}
/**
* @return Block
*/
public function getBed() : Block{
return $this->bed;
}
}

View File

@ -0,0 +1,56 @@
<?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\player;
use pocketmine\block\Block;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\player\Player;
/**
* Called when a player middle-clicks on a block to get an item in creative mode.
*/
class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Block */
private $blockClicked;
/** @var Item */
private $resultItem;
public function __construct(Player $player, Block $blockClicked, Item $resultItem){
$this->player = $player;
$this->blockClicked = $blockClicked;
$this->resultItem = $resultItem;
}
public function getBlock() : Block{
return $this->blockClicked;
}
public function getResultItem() : Item{
return $this->resultItem;
}
}

View File

@ -0,0 +1,28 @@
<?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\player;
class PlayerBucketEmptyEvent extends PlayerBucketEvent{
}

View File

@ -0,0 +1,100 @@
<?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\player;
use pocketmine\block\Block;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\player\Player;
/**
* @allowHandle
*/
abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Block */
private $blockClicked;
/** @var int */
private $blockFace;
/** @var Item */
private $bucket;
/** @var Item */
private $item;
/**
* @param Player $who
* @param Block $blockClicked
* @param int $blockFace
* @param Item $bucket
* @param Item $itemInHand
*/
public function __construct(Player $who, Block $blockClicked, int $blockFace, Item $bucket, Item $itemInHand){
$this->player = $who;
$this->blockClicked = $blockClicked;
$this->blockFace = $blockFace;
$this->item = $itemInHand;
$this->bucket = $bucket;
}
/**
* Returns the bucket used in this event
*
* @return Item
*/
public function getBucket() : Item{
return $this->bucket;
}
/**
* Returns the item in hand after the event
*
* @return Item
*/
public function getItem() : Item{
return $this->item;
}
/**
* @param Item $item
*/
public function setItem(Item $item) : void{
$this->item = $item;
}
/**
* @return Block
*/
public function getBlockClicked() : Block{
return $this->blockClicked;
}
/**
* @return int
*/
public function getBlockFace() : int{
return $this->blockFace;
}
}

View File

@ -0,0 +1,28 @@
<?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\player;
class PlayerBucketFillEvent extends PlayerBucketEvent{
}

View File

@ -0,0 +1,75 @@
<?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\player;
use pocketmine\entity\Skin;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
/**
* Called when a player changes their skin in-game.
*/
class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Skin */
private $oldSkin;
/** @var Skin */
private $newSkin;
/**
* @param Player $player
* @param Skin $oldSkin
* @param Skin $newSkin
*/
public function __construct(Player $player, Skin $oldSkin, Skin $newSkin){
$this->player = $player;
$this->oldSkin = $oldSkin;
$this->newSkin = $newSkin;
}
/**
* @return Skin
*/
public function getOldSkin() : Skin{
return $this->oldSkin;
}
/**
* @return Skin
*/
public function getNewSkin() : Skin{
return $this->newSkin;
}
/**
* @param Skin $skin
*
* @throws \InvalidArgumentException if the specified skin is not valid
*/
public function setNewSkin(Skin $skin) : void{
$this->newSkin = $skin;
}
}

View File

@ -0,0 +1,118 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\permission\PermissionManager;
use pocketmine\player\Player;
use pocketmine\Server;
/**
* Called when a player chats something
*/
class PlayerChatEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var string */
protected $message;
/** @var string */
protected $format;
/**
* @var Player[]
*/
protected $recipients = [];
/**
* @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;
$this->format = $format;
if($recipients === null){
$this->recipients = PermissionManager::getInstance()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_USERS);
}else{
$this->recipients = $recipients;
}
}
/**
* @return string
*/
public function getMessage() : string{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message) : void{
$this->message = $message;
}
/**
* Changes the player that is sending the message
*
* @param Player $player
*/
public function setPlayer(Player $player) : void{
$this->player = $player;
}
/**
* @return string
*/
public function getFormat() : string{
return $this->format;
}
/**
* @param string $format
*/
public function setFormat(string $format) : void{
$this->format = $format;
}
/**
* @return Player[]
*/
public function getRecipients() : array{
return $this->recipients;
}
/**
* @param Player[] $recipients
*/
public function setRecipients(array $recipients) : void{
$this->recipients = $recipients;
}
}

View File

@ -0,0 +1,74 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
/**
* Called when a player runs a command or chats, 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 contains a slash at the start
*/
class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var string */
protected $message;
/**
* @param Player $player
* @param string $message
*/
public function __construct(Player $player, string $message){
$this->player = $player;
$this->message = $message;
}
/**
* @return string
*/
public function getMessage() : string{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message) : void{
$this->message = $message;
}
/**
* @param Player $player
*/
public function setPlayer(Player $player) : void{
$this->player = $player;
}
}

View File

@ -0,0 +1,108 @@
<?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\player;
use pocketmine\event\Event;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\player\Player;
use function is_a;
/**
* Allows the creation of players overriding the base Player class
*/
class PlayerCreationEvent extends Event{
/** @var NetworkSession */
private $session;
/** @var Player::class */
private $baseClass = Player::class;
/** @var Player::class */
private $playerClass = Player::class;
/**
* @param NetworkSession $session
*/
public function __construct(NetworkSession $session){
$this->session = $session;
}
/**
* @return NetworkSession
*/
public function getNetworkSession() : NetworkSession{
return $this->session;
}
/**
* @return string
*/
public function getAddress() : string{
return $this->session->getIp();
}
/**
* @return int
*/
public function getPort() : int{
return $this->session->getPort();
}
/**
* @return Player::class
*/
public function getBaseClass(){
return $this->baseClass;
}
/**
* @param Player::class $class
*/
public function setBaseClass($class) : void{
if(!is_a($class, $this->baseClass, true)){
throw new \RuntimeException("Base class $class must extend " . $this->baseClass);
}
$this->baseClass = $class;
}
/**
* @return Player::class
*/
public function getPlayerClass(){
return $this->playerClass;
}
/**
* @param Player::class $class
*/
public function setPlayerClass($class) : void{
if(!is_a($class, $this->baseClass, true)){
throw new \RuntimeException("Class $class must extend " . $this->baseClass);
}
$this->playerClass = $class;
}
}

View File

@ -0,0 +1,79 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\event\Event;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\player\IPlayer;
use pocketmine\Server;
/**
* Called when a player's data is about to be saved to disk.
*/
class PlayerDataSaveEvent extends Event implements Cancellable{
use CancellableTrait;
/** @var CompoundTag */
protected $data;
/** @var string */
protected $playerName;
public function __construct(CompoundTag $nbt, string $playerName){
$this->data = $nbt;
$this->playerName = $playerName;
}
/**
* Returns the data to be written to disk as a CompoundTag
* @return CompoundTag
*/
public function getSaveData() : CompoundTag{
return $this->data;
}
/**
* @param CompoundTag $data
*/
public function setSaveData(CompoundTag $data) : void{
$this->data = $data;
}
/**
* Returns the username of the player whose data is being saved. This is not necessarily an online player.
* @return string
*/
public function getPlayerName() : string{
return $this->playerName;
}
/**
* Returns the player whose data is being saved. This may be a Player or an OfflinePlayer.
* @return IPlayer (Player or OfflinePlayer)
*/
public function getPlayer() : IPlayer{
return Server::getInstance()->getOfflinePlayer($this->playerName);
}
}

View File

@ -0,0 +1,210 @@
<?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\player;
use pocketmine\block\BlockLegacyIds;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\item\Item;
use pocketmine\lang\TextContainer;
use pocketmine\lang\TranslationContainer;
use pocketmine\player\Player;
class PlayerDeathEvent extends EntityDeathEvent{
/** @var Player */
protected $entity;
/** @var TextContainer|string */
private $deathMessage;
private $keepInventory = false;
/**
* @param Player $entity
* @param Item[] $drops
* @param int $xp
* @param string|TextContainer|null $deathMessage Null will cause the default vanilla message to be used
*/
public function __construct(Player $entity, array $drops, int $xp, $deathMessage){
parent::__construct($entity, $drops, $xp);
$this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause());
}
/**
* @return Player
*/
public function getEntity(){
return $this->entity;
}
/**
* @return Player
*/
public function getPlayer() : Player{
return $this->entity;
}
/**
* @return TextContainer|string
*/
public function getDeathMessage(){
return $this->deathMessage;
}
/**
* @param TextContainer|string $deathMessage
*/
public function setDeathMessage($deathMessage) : void{
$this->deathMessage = $deathMessage;
}
public function getKeepInventory() : bool{
return $this->keepInventory;
}
public function setKeepInventory(bool $keepInventory) : void{
$this->keepInventory = $keepInventory;
}
/**
* Returns the vanilla death message for the given death cause.
*
* @param string $name
* @param null|EntityDamageEvent $deathCause
*
* @return TranslationContainer
*/
public static function deriveMessage(string $name, ?EntityDamageEvent $deathCause) : TranslationContainer{
$message = "death.attack.generic";
$params = [$name];
switch($deathCause === null ? EntityDamageEvent::CAUSE_CUSTOM : $deathCause->getCause()){
case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
if($deathCause instanceof EntityDamageByEntityEvent){
$e = $deathCause->getDamager();
if($e instanceof Player){
$message = "death.attack.player";
$params[] = $e->getDisplayName();
break;
}elseif($e instanceof Living){
$message = "death.attack.mob";
$params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
break;
}else{
$params[] = "Unknown";
}
}
break;
case EntityDamageEvent::CAUSE_PROJECTILE:
if($deathCause instanceof EntityDamageByEntityEvent){
$e = $deathCause->getDamager();
if($e instanceof Player){
$message = "death.attack.arrow";
$params[] = $e->getDisplayName();
}elseif($e instanceof Living){
$message = "death.attack.arrow";
$params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
break;
}else{
$params[] = "Unknown";
}
}
break;
case EntityDamageEvent::CAUSE_SUICIDE:
$message = "death.attack.generic";
break;
case EntityDamageEvent::CAUSE_VOID:
$message = "death.attack.outOfWorld";
break;
case EntityDamageEvent::CAUSE_FALL:
if($deathCause instanceof EntityDamageEvent){
if($deathCause->getFinalDamage() > 2){
$message = "death.fell.accident.generic";
break;
}
}
$message = "death.attack.fall";
break;
case EntityDamageEvent::CAUSE_SUFFOCATION:
$message = "death.attack.inWall";
break;
case EntityDamageEvent::CAUSE_LAVA:
$message = "death.attack.lava";
break;
case EntityDamageEvent::CAUSE_FIRE:
$message = "death.attack.onFire";
break;
case EntityDamageEvent::CAUSE_FIRE_TICK:
$message = "death.attack.inFire";
break;
case EntityDamageEvent::CAUSE_DROWNING:
$message = "death.attack.drown";
break;
case EntityDamageEvent::CAUSE_CONTACT:
if($deathCause instanceof EntityDamageByBlockEvent){
if($deathCause->getDamager()->getId() === BlockLegacyIds::CACTUS){
$message = "death.attack.cactus";
}
}
break;
case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
if($deathCause instanceof EntityDamageByEntityEvent){
$e = $deathCause->getDamager();
if($e instanceof Player){
$message = "death.attack.explosion.player";
$params[] = $e->getDisplayName();
}elseif($e instanceof Living){
$message = "death.attack.explosion.player";
$params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
break;
}
}else{
$message = "death.attack.explosion";
}
break;
case EntityDamageEvent::CAUSE_MAGIC:
$message = "death.attack.magic";
break;
case EntityDamageEvent::CAUSE_CUSTOM:
break;
default:
break;
}
return new TranslationContainer($message, $params);
}
}

View File

@ -0,0 +1,55 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\player\Player;
/**
* Called when a player tries to drop an item from its hotbar
*/
class PlayerDropItemEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Item */
private $drop;
/**
* @param Player $player
* @param Item $drop
*/
public function __construct(Player $player, Item $drop){
$this->player = $player;
$this->drop = $drop;
}
/**
* @return Item
*/
public function getItem() : Item{
return $this->drop;
}
}

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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\event\Event;
use pocketmine\network\mcpe\NetworkSession;
/**
* Called when a player connects with a username or UUID that is already used by another player on the server.
* If cancelled, the newly connecting session will be disconnected; otherwise, the existing player will be disconnected.
*/
class PlayerDuplicateLoginEvent extends Event implements Cancellable{
use CancellableTrait;
/** @var NetworkSession */
private $connectingSession;
/** @var NetworkSession */
private $existingSession;
/** @var string */
private $disconnectMessage = "Logged in from another location";
public function __construct(NetworkSession $connectingSession, NetworkSession $existingSession){
$this->connectingSession = $connectingSession;
$this->existingSession = $existingSession;
}
public function getConnectingSession() : NetworkSession{
return $this->connectingSession;
}
public function getExistingSession() : NetworkSession{
return $this->existingSession;
}
/**
* Returns the message shown to the session which gets disconnected.
*
* @return string
*/
public function getDisconnectMessage() : string{
return $this->disconnectMessage;
}
/**
* @param string $message
*/
public function setDisconnectMessage(string $message) : void{
$this->disconnectMessage = $message;
}
}

View File

@ -0,0 +1,102 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\WritableBookBase;
use pocketmine\player\Player;
class PlayerEditBookEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
public const ACTION_REPLACE_PAGE = 0;
public const ACTION_ADD_PAGE = 1;
public const ACTION_DELETE_PAGE = 2;
public const ACTION_SWAP_PAGES = 3;
public const ACTION_SIGN_BOOK = 4;
/** @var WritableBookBase */
private $oldBook;
/** @var int */
private $action;
/** @var WritableBookBase */
private $newBook;
/** @var int[] */
private $modifiedPages;
public function __construct(Player $player, WritableBookBase $oldBook, WritableBookBase $newBook, int $action, array $modifiedPages){
$this->player = $player;
$this->oldBook = $oldBook;
$this->newBook = $newBook;
$this->action = $action;
$this->modifiedPages = $modifiedPages;
}
/**
* Returns the action of the event.
*
* @return int
*/
public function getAction() : int{
return $this->action;
}
/**
* Returns the book before it was modified.
*
* @return WritableBookBase
*/
public function getOldBook() : WritableBookBase{
return $this->oldBook;
}
/**
* Returns the book after it was modified.
* The new book may be a written book, if the book was signed.
*
* @return WritableBookBase
*/
public function getNewBook() : WritableBookBase{
return $this->newBook;
}
/**
* Sets the new book as the given instance.
*
* @param WritableBookBase $book
*/
public function setNewBook(WritableBookBase $book) : void{
$this->newBook = $book;
}
/**
* Returns an array containing the page IDs of modified pages.
*
* @return int[]
*/
public function getModifiedPages() : array{
return $this->modifiedPages;
}
}

View File

@ -0,0 +1,39 @@
<?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);
/**
* Player-only related events
*/
namespace pocketmine\event\player;
use pocketmine\event\Event;
use pocketmine\player\Player;
abstract class PlayerEvent extends Event{
/** @var Player */
protected $player;
public function getPlayer() : Player{
return $this->player;
}
}

View File

@ -0,0 +1,83 @@
<?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\player;
use pocketmine\entity\Human;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\event\entity\EntityEvent;
class PlayerExhaustEvent extends EntityEvent implements Cancellable{
use CancellableTrait;
public const CAUSE_ATTACK = 1;
public const CAUSE_DAMAGE = 2;
public const CAUSE_MINING = 3;
public const CAUSE_HEALTH_REGEN = 4;
public const CAUSE_POTION = 5;
public const CAUSE_WALKING = 6;
public const CAUSE_SPRINTING = 7;
public const CAUSE_SWIMMING = 8;
public const CAUSE_JUMPING = 9;
public const CAUSE_SPRINT_JUMPING = 10;
public const CAUSE_CUSTOM = 11;
/** @var float */
private $amount;
/** @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
*/
public function getPlayer(){
return $this->player;
}
public function getAmount() : float{
return $this->amount;
}
public function setAmount(float $amount) : void{
$this->amount = $amount;
}
/**
* Returns an int cause of the exhaustion - one of the constants at the top of this class.
* @return int
*/
public function getCause() : int{
return $this->cause;
}
}

View File

@ -0,0 +1,98 @@
<?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\player;
use pocketmine\entity\Human;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\event\entity\EntityEvent;
/**
* Called when a player gains or loses XP levels and/or progress.
*/
class PlayerExperienceChangeEvent extends EntityEvent implements Cancellable{
use CancellableTrait;
/** @var Human */
protected $entity;
/** @var int */
private $oldLevel;
/** @var float */
private $oldProgress;
/** @var int|null */
private $newLevel;
/** @var float|null */
private $newProgress;
public function __construct(Human $player, int $oldLevel, float $oldProgress, ?int $newLevel, ?float $newProgress){
$this->entity = $player;
$this->oldLevel = $oldLevel;
$this->oldProgress = $oldProgress;
$this->newLevel = $newLevel;
$this->newProgress = $newProgress;
}
/**
* @return int
*/
public function getOldLevel() : int{
return $this->oldLevel;
}
/**
* @return float
*/
public function getOldProgress() : float{
return $this->oldProgress;
}
/**
* @return int|null null indicates no change
*/
public function getNewLevel() : ?int{
return $this->newLevel;
}
/**
* @return float|null null indicates no change
*/
public function getNewProgress() : ?float{
return $this->newProgress;
}
/**
* @param int|null $newLevel
*/
public function setNewLevel(?int $newLevel) : void{
$this->newLevel = $newLevel;
}
/**
* @param float|null $newProgress
*/
public function setNewProgress(?float $newProgress) : void{
$this->newProgress = $newProgress;
}
}

View File

@ -0,0 +1,48 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\GameMode;
use pocketmine\player\Player;
/**
* Called when a player has its gamemode changed
*/
class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var GameMode */
protected $gamemode;
public function __construct(Player $player, GameMode $newGamemode){
$this->player = $player;
$this->gamemode = $newGamemode;
}
public function getNewGamemode() : GameMode{
return $this->gamemode;
}
}

View File

@ -0,0 +1,108 @@
<?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\player;
use pocketmine\block\Block;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
/**
* Called when a player interacts or touches a block (including air?)
*/
class PlayerInteractEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
public const LEFT_CLICK_BLOCK = 0;
public const RIGHT_CLICK_BLOCK = 1;
/** @var Block */
protected $blockTouched;
/** @var Vector3 */
protected $touchVector;
/** @var int */
protected $blockFace;
/** @var Item */
protected $item;
/** @var int */
protected $action;
/**
* @param Player $player
* @param Item $item
* @param Block $block
* @param Vector3|null $touchVector
* @param int $face
* @param int $action
*/
public function __construct(Player $player, Item $item, Block $block, ?Vector3 $touchVector, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
$this->player = $player;
$this->item = $item;
$this->blockTouched = $block;
$this->touchVector = $touchVector ?? new Vector3(0, 0, 0);
$this->blockFace = $face;
$this->action = $action;
}
/**
* @return int
*/
public function getAction() : int{
return $this->action;
}
/**
* @return Item
*/
public function getItem() : Item{
return $this->item;
}
/**
* @return Block
*/
public function getBlock() : Block{
return $this->blockTouched;
}
/**
* @return Vector3
*/
public function getTouchVector() : Vector3{
return $this->touchVector;
}
/**
* @return int
*/
public function getFace() : int{
return $this->blockFace;
}
}

View File

@ -0,0 +1,55 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\player\Player;
/**
* Called when a player eats something
*/
class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Item */
private $item;
/**
* @param Player $player
* @param Item $item
*/
public function __construct(Player $player, Item $item){
$this->player = $player;
$this->item = $item;
}
/**
* @return Item
*/
public function getItem() : Item{
return clone $this->item;
}
}

View File

@ -0,0 +1,67 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\player\Player;
class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Item */
private $item;
/** @var int */
private $hotbarSlot;
public function __construct(Player $player, Item $item, int $hotbarSlot){
$this->player = $player;
$this->item = $item;
$this->hotbarSlot = $hotbarSlot;
}
/**
* Returns the hotbar slot the player is attempting to hold.
*
* NOTE: This event is called BEFORE the slot is equipped server-side. Setting the player's held item during this
* event will result in the **old** slot being changed, not this one.
*
* To change the item in the slot that the player is attempting to hold, set the slot that this function reports.
*
* @return int
*/
public function getSlot() : int{
return $this->hotbarSlot;
}
/**
* Returns the item in the slot that the player is trying to equip.
*
* @return Item
*/
public function getItem() : Item{
return $this->item;
}
}

View File

@ -0,0 +1,71 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
/**
* Called when a player uses its held item, for example when throwing a projectile.
*/
class PlayerItemUseEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var Item */
private $item;
/** @var Vector3 */
private $directionVector;
/**
* @param Player $player
* @param Item $item
* @param Vector3 $directionVector
*/
public function __construct(Player $player, Item $item, Vector3 $directionVector){
$this->player = $player;
$this->item = $item;
$this->directionVector = $directionVector;
}
/**
* Returns the item used.
*
* @return Item
*/
public function getItem() : Item{
return $this->item;
}
/**
* Returns the direction the player is aiming when activating this item. Used for projectile direction.
*
* @return Vector3
*/
public function getDirectionVector() : Vector3{
return $this->directionVector;
}
}

View File

@ -0,0 +1,64 @@
<?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\player;
use pocketmine\lang\TextContainer;
use pocketmine\player\Player;
/**
* Called when the player spawns in the world after logging in, when they first see the terrain.
*
* Note: A lot of data is sent to the player between login and this event. Disconnecting the player during this event
* will cause this data to be wasted. Prefer disconnecting at login-time if possible to minimize bandwidth wastage.
* @see PlayerLoginEvent
*/
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;
}
/**
* @param string|TextContainer $joinMessage
*/
public function setJoinMessage($joinMessage) : void{
$this->joinMessage = $joinMessage;
}
/**
* @return string|TextContainer
*/
public function getJoinMessage(){
return $this->joinMessage;
}
}

View File

@ -0,0 +1,41 @@
<?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\player;
use pocketmine\player\Player;
/**
* Called when a player jumps
*/
class PlayerJumpEvent extends PlayerEvent{
/**
* PlayerJumpEvent constructor.
*
* @param Player $player
*/
public function __construct(Player $player){
$this->player = $player;
}
}

View File

@ -0,0 +1,80 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\lang\TextContainer;
use pocketmine\player\Player;
/**
* Called when a player leaves the server
*/
class PlayerKickEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var TextContainer|string */
protected $quitMessage;
/** @var string */
protected $reason;
/**
* 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;
}
/**
* @param string $reason
*/
public function setReason(string $reason) : void{
$this->reason = $reason;
}
public function getReason() : string{
return $this->reason;
}
/**
* @param TextContainer|string $quitMessage
*/
public function setQuitMessage($quitMessage) : void{
$this->quitMessage = $quitMessage;
}
/**
* @return TextContainer|string
*/
public function getQuitMessage(){
return $this->quitMessage;
}
}

View File

@ -0,0 +1,63 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
/**
* Called after the player has successfully authenticated, before it spawns. The player is on the loading screen when
* this is called.
* Cancelling this event will cause the player to be disconnected with the kick message set.
*/
class PlayerLoginEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var string */
protected $kickMessage;
/**
* @param Player $player
* @param string $kickMessage
*/
public function __construct(Player $player, string $kickMessage){
$this->player = $player;
$this->kickMessage = $kickMessage;
}
/**
* @param string $kickMessage
*/
public function setKickMessage(string $kickMessage) : void{
$this->kickMessage = $kickMessage;
}
/**
* @return string
*/
public function getKickMessage() : string{
return $this->kickMessage;
}
}

View File

@ -0,0 +1,70 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
use pocketmine\world\Location;
class PlayerMoveEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @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;
}
/**
* @return Location
*/
public function getFrom() : Location{
return $this->from;
}
/**
* @return Location
*/
public function getTo() : Location{
return $this->to;
}
/**
* @param Location $to
*/
public function setTo(Location $to) : void{
$this->to = $to;
}
}

View File

@ -0,0 +1,204 @@
<?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\player;
use pocketmine\event\Event;
use pocketmine\player\PlayerInfo;
use function array_keys;
/**
* Called when a player connects to the server, prior to authentication taking place.
* Cancelling this event will cause the player to be disconnected with the kick message set.
*
* This event should be used to decide if the player may continue to login to the server. Do things like checking
* bans, whitelisting, server-full etc here.
*
* WARNING: Any information about the player CANNOT be trusted at this stage, because they are not authenticated and
* could be a hacker posing as another player.
*/
class PlayerPreLoginEvent extends Event{
public const KICK_REASON_PLUGIN = 0;
public const KICK_REASON_SERVER_FULL = 1;
public const KICK_REASON_SERVER_WHITELISTED = 2;
public const KICK_REASON_BANNED = 3;
public const KICK_REASON_PRIORITY = [
self::KICK_REASON_PLUGIN, //Plugin reason should always take priority over anything else
self::KICK_REASON_SERVER_FULL,
self::KICK_REASON_SERVER_WHITELISTED,
self::KICK_REASON_BANNED
];
/** @var PlayerInfo */
private $playerInfo;
/** @var string */
private $ip;
/** @var int */
private $port;
/** @var bool */
protected $authRequired;
/** @var string[] reason const => associated message */
protected $kickReasons = [];
/**
* @param PlayerInfo $playerInfo
* @param string $ip
* @param int $port
* @param bool $authRequired
*/
public function __construct(PlayerInfo $playerInfo, string $ip, int $port, bool $authRequired){
$this->playerInfo = $playerInfo;
$this->ip = $ip;
$this->port = $port;
$this->authRequired = $authRequired;
}
/**
* Returns an object containing self-proclaimed information about the connecting player.
* WARNING: THE PLAYER IS NOT VERIFIED DURING THIS EVENT. At this point, it's unknown if the player is real or a
* hacker.
*
* @return PlayerInfo
*/
public function getPlayerInfo() : PlayerInfo{
return $this->playerInfo;
}
/**
* @return string
*/
public function getIp() : string{
return $this->ip;
}
/**
* @return int
*/
public function getPort() : int{
return $this->port;
}
/**
* @return bool
*/
public function isAuthRequired() : bool{
return $this->authRequired;
}
/**
* @param bool $v
*/
public function setAuthRequired(bool $v) : void{
$this->authRequired = $v;
}
/**
* Returns an array of kick reasons currently assigned.
*
* @return int[]
*/
public function getKickReasons() : array{
return array_keys($this->kickReasons);
}
/**
* Returns whether the given kick reason is set for this event.
*
* @param int $flag
*
* @return bool
*/
public function isKickReasonSet(int $flag) : bool{
return isset($this->kickReasons[$flag]);
}
/**
* Sets a reason to disallow the player to continue continue authenticating, with a message.
* This can also be used to change kick messages for already-set flags.
*
* @param int $flag
* @param string $message
*/
public function setKickReason(int $flag, string $message) : void{
$this->kickReasons[$flag] = $message;
}
/**
* Clears a specific kick flag if it was set. This allows fine-tuned kick reason removal without impacting other
* reasons (for example, a ban can be bypassed without accidentally allowing a player to join a full server).
*
* @param int $flag Specific flag to clear.
*/
public function clearKickReason(int $flag) : void{
unset($this->kickReasons[$flag]);
}
/**
* Clears all pre-assigned kick reasons, allowing the player to continue logging in.
*/
public function clearAllKickReasons() : void{
$this->kickReasons = [];
}
/**
* Returns whether the player is allowed to continue logging in.
*
* @return bool
*/
public function isAllowed() : bool{
return empty($this->kickReasons);
}
/**
* Returns the kick message provided for the given kick flag, or null if not set.
*
* @param int $flag
*
* @return string|null
*/
public function getKickMessage(int $flag) : ?string{
return $this->kickReasons[$flag] ?? null;
}
/**
* Returns the final kick message which will be shown on the disconnect screen.
*
* Note: Only one message (the highest priority one) will be shown. See priority order to decide how to set your
* messages.
*
* @see PlayerPreLoginEvent::KICK_REASON_PRIORITY
*
* @return string
*/
public function getFinalKickMessage() : string{
foreach(self::KICK_REASON_PRIORITY as $p){
if(isset($this->kickReasons[$p])){
return $this->kickReasons[$p];
}
}
return "";
}
}

View File

@ -0,0 +1,70 @@
<?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\player;
use pocketmine\lang\TranslationContainer;
use pocketmine\player\Player;
/**
* Called when a player leaves the server
*/
class PlayerQuitEvent extends PlayerEvent{
/** @var TranslationContainer|string */
protected $quitMessage;
/** @var string */
protected $quitReason;
/**
* @param Player $player
* @param TranslationContainer|string $quitMessage
* @param string $quitReason
*/
public function __construct(Player $player, $quitMessage, string $quitReason){
$this->player = $player;
$this->quitMessage = $quitMessage;
$this->quitReason = $quitReason;
}
/**
* @param TranslationContainer|string $quitMessage
*/
public function setQuitMessage($quitMessage) : void{
$this->quitMessage = $quitMessage;
}
/**
* @return TranslationContainer|string
*/
public function getQuitMessage(){
return $this->quitMessage;
}
/**
* @return string
*/
public function getQuitReason() : string{
return $this->quitReason;
}
}

View File

@ -0,0 +1,58 @@
<?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\player;
use pocketmine\player\Player;
use pocketmine\world\Position;
/**
* Called when a player is respawned
*/
class PlayerRespawnEvent extends PlayerEvent{
/** @var Position */
protected $position;
/**
* @param Player $player
* @param Position $position
*/
public function __construct(Player $player, Position $position){
$this->player = $player;
$this->position = $position;
}
/**
* @return Position
*/
public function getRespawnPosition() : Position{
return $this->position;
}
/**
* @param Position $position
*/
public function setRespawnPosition(Position $position) : void{
$this->position = $position;
}
}

View File

@ -0,0 +1,51 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
class PlayerToggleFlightEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var bool */
protected $isFlying;
/**
* @param Player $player
* @param bool $isFlying
*/
public function __construct(Player $player, bool $isFlying){
$this->player = $player;
$this->isFlying = $isFlying;
}
/**
* @return bool
*/
public function isFlying() : bool{
return $this->isFlying;
}
}

View File

@ -0,0 +1,51 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var bool */
protected $isSneaking;
/**
* @param Player $player
* @param bool $isSneaking
*/
public function __construct(Player $player, bool $isSneaking){
$this->player = $player;
$this->isSneaking = $isSneaking;
}
/**
* @return bool
*/
public function isSneaking() : bool{
return $this->isSneaking;
}
}

View File

@ -0,0 +1,51 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
class PlayerToggleSprintEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @var bool */
protected $isSprinting;
/**
* @param Player $player
* @param bool $isSprinting
*/
public function __construct(Player $player, bool $isSprinting){
$this->player = $player;
$this->isSprinting = $isSprinting;
}
/**
* @return bool
*/
public function isSprinting() : bool{
return $this->isSprinting;
}
}

View File

@ -0,0 +1,94 @@
<?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\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
class PlayerTransferEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
/** @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;
$this->port = $port;
$this->message = $message;
}
/**
* @return string
*/
public function getAddress() : string{
return $this->address;
}
/**
* @param string $address
*/
public function setAddress(string $address) : void{
$this->address = $address;
}
/**
* @return int
*/
public function getPort() : int{
return $this->port;
}
/**
* @param int $port
*/
public function setPort(int $port) : void{
$this->port = $port;
}
/**
* @return string
*/
public function getMessage() : string{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message) : void{
$this->message = $message;
}
}