mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added PlayerBedEnterEvent and PlayerBedLeaveEvent
This commit is contained in:
parent
c52dc58d6f
commit
10b33546ef
@ -39,6 +39,8 @@ use pocketmine\event\inventory\InventoryCloseEvent;
|
||||
use pocketmine\event\inventory\InventoryPickupItemEvent;
|
||||
use pocketmine\event\player\PlayerAchievementAwardedEvent;
|
||||
use pocketmine\event\player\PlayerAnimationEvent;
|
||||
use pocketmine\event\player\PlayerBedEnterEvent;
|
||||
use pocketmine\event\player\PlayerBedLeaveEvent;
|
||||
use pocketmine\event\player\PlayerChatEvent;
|
||||
use pocketmine\event\player\PlayerCommandPreprocessEvent;
|
||||
use pocketmine\event\player\PlayerDeathEvent;
|
||||
@ -825,6 +827,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->getLevel()->getBlock($pos)));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sleeping = $pos;
|
||||
$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->getLevel()));
|
||||
|
||||
@ -858,10 +866,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
public function stopSleep(){
|
||||
$this->sleeping = false;
|
||||
if($this->sleeping instanceof Vector3){
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerBedLeaveEvent($this, $this->getLevel()->getBlock($pos)));
|
||||
|
||||
$this->sleeping = null;
|
||||
|
||||
$this->sendMetadata($this->getViewers());
|
||||
$this->sendMetadata($this);
|
||||
}
|
||||
|
||||
$this->sendMetadata($this->getViewers());
|
||||
$this->sendMetadata($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -869,7 +882,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
* Changes to this function won't be recorded on the version.
|
||||
*/
|
||||
public function checkSleep(){
|
||||
if($this->sleeping !== false){
|
||||
if($this->sleeping instanceof Vector3){
|
||||
//TODO: Move to Level
|
||||
|
||||
$time = $this->getLevel()->getTime() % Level::TIME_FULL;
|
||||
@ -2492,7 +2505,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
];
|
||||
|
||||
|
||||
if($this->sleeping !== false){
|
||||
if($this->sleeping instanceof Vector3){
|
||||
$d[16]["value"] = 2;
|
||||
$d[17]["value"] = [$this->sleeping->x, $this->sleeping->y, $this->sleeping->z];
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\event\entity\EntityMoveEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\entity\EntitySpawnEvent;
|
||||
use pocketmine\event\entity\EntityTeleportEvent;
|
||||
use pocketmine\event\player\PlayerMotionEvent;
|
||||
use pocketmine\event\Timings;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\FullChunk;
|
||||
@ -1100,9 +1101,11 @@ abstract class Entity extends Position implements Metadatable{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->motionX = $motion->x;
|
||||
$this->motionY = $motion->y;
|
||||
$this->motionZ = $motion->z;
|
||||
|
||||
if(!$this->justCreated){
|
||||
if($this instanceof Player){
|
||||
$pk = new SetEntityMotionPacket;
|
||||
|
42
src/pocketmine/event/player/PlayerBedEnterEvent.php
Normal file
42
src/pocketmine/event/player/PlayerBedEnterEvent.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
private $bed;
|
||||
|
||||
public function __construct(Player $player, Block $bed){
|
||||
$this->player = $player;
|
||||
$this->bed = $bed;
|
||||
}
|
||||
|
||||
public function getBed(){
|
||||
return $this->bed;
|
||||
}
|
||||
|
||||
}
|
41
src/pocketmine/event/player/PlayerBedLeaveEvent.php
Normal file
41
src/pocketmine/event/player/PlayerBedLeaveEvent.php
Normal 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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerBedLeaveEvent extends PlayerEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
private $bed;
|
||||
|
||||
public function __construct(Player $player, Block $bed){
|
||||
$this->player = $player;
|
||||
$this->bed = $bed;
|
||||
}
|
||||
|
||||
public function getBed(){
|
||||
return $this->bed;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user