mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 09:39:56 +00:00
Added more new Events
This commit is contained in:
parent
fd0fcecb46
commit
ee265d44bd
@ -24,7 +24,6 @@
|
||||
*/
|
||||
namespace PocketMine\Entity;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Event\Entity\EntityLevelChangeEvent;
|
||||
use PocketMine\Event\Entity\EntityMotionEvent;
|
||||
use PocketMine\Event\Entity\EntityMoveEvent;
|
||||
@ -35,14 +34,14 @@ use PocketMine\Level\Position;
|
||||
use PocketMine\Math\AxisAlignedBB;
|
||||
use PocketMine\Math\Vector3 as Vector3;
|
||||
use PocketMine\NBT\Tag\Compound;
|
||||
use PocketMine\Network;
|
||||
use PocketMine\Network\Protocol\MoveEntityPacket_PosRot;
|
||||
use PocketMine\Network\Protocol\MovePlayerPacket;
|
||||
use PocketMine\Network\Protocol\RemoveEntityPacket;
|
||||
use PocketMine\Network\Protocol\SetEntityMotionPacket;
|
||||
use PocketMine\Network;
|
||||
use PocketMine\Player;
|
||||
use PocketMine\PMF\LevelFormat;
|
||||
use PocketMine\ServerAPI;
|
||||
use PocketMine;
|
||||
|
||||
abstract class Entity extends Position{
|
||||
public static $entityCount = 1;
|
||||
@ -130,7 +129,7 @@ abstract class Entity extends Position{
|
||||
$this->level->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
||||
$this->lastUpdate = microtime(true);
|
||||
$this->initEntity();
|
||||
ServerAPI::request()->api->dhandle("entity.add", $this);
|
||||
EventHandler::callEvent(new PocketMine\Event\Entity\EntitySpawnEvent($this));
|
||||
}
|
||||
|
||||
public function saveNBT(){
|
||||
@ -527,7 +526,7 @@ abstract class Entity extends Position{
|
||||
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
|
||||
unset(Entity::$list[$this->id]);
|
||||
$this->despawnFromAll();
|
||||
$this->server->api->dhandle("entity.remove", $this);
|
||||
EventHandler::callEvent(new PocketMine\Event\Entity\EntityDespawnEvent($this));
|
||||
}
|
||||
}
|
||||
|
||||
|
84
src/PocketMine/event/entity/EntityDespawnEvent.php
Normal file
84
src/PocketMine/event/entity/EntityDespawnEvent.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?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\Entity;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Entity\Entity;
|
||||
|
||||
/**
|
||||
* Called when a entity is despawned
|
||||
*/
|
||||
class EntityDespawnEvent extends EntityEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
*/
|
||||
public function __construct(Entity $entity){
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(){
|
||||
//TODO: implement Entity types
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCreature(){
|
||||
return $this->entity instanceof PocketMine\Entity\Creature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isHuman(){
|
||||
return $this->entity instanceof PocketMine\Entity\Human;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isProjectile(){
|
||||
return $this->entity instanceof PocketMine\Entity\Projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isVehicle(){
|
||||
return $this->entity instanceof PocketMine\Entity\Vehicle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isItem(){
|
||||
return $this->entity instanceof PocketMine\Entity\DroppedItem;
|
||||
}
|
||||
|
||||
}
|
100
src/PocketMine/event/entity/EntityExplodeEvent.php
Normal file
100
src/PocketMine/event/entity/EntityExplodeEvent.php
Normal 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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Entity;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Block\Block;
|
||||
use PocketMine\Entity\Entity;
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine\Level\Position;
|
||||
|
||||
/**
|
||||
* Called when a entity explodes
|
||||
*/
|
||||
class EntityExplodeEvent extends EntityEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var Position
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* @var Block[]
|
||||
*/
|
||||
protected $blocks;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $yield;
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
* @param Position $position
|
||||
* @param Block[] $blocks
|
||||
* @param float $yield
|
||||
*/
|
||||
public function __construct(Entity $entity, Position $position, array $blocks, $yield){
|
||||
$this->entity = $entity;
|
||||
$this->position = $position;
|
||||
$this->blocks = $blocks;
|
||||
$this->yield = $yield;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Position
|
||||
*/
|
||||
public function getPosition(){
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block[]
|
||||
*/
|
||||
public function getBlockList(){
|
||||
return $this->blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Block[] $blocks
|
||||
*/
|
||||
public function setBlockList(array $blocks){
|
||||
$this->blocks = $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getYield(){
|
||||
return $this->yield;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $yield
|
||||
*/
|
||||
public function setYield($yield){
|
||||
$this->yield = $yield;
|
||||
}
|
||||
|
||||
}
|
@ -22,15 +22,18 @@
|
||||
namespace PocketMine\Event\Entity;
|
||||
|
||||
use PocketMine\Entity\Entity;
|
||||
use PocketMine;
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine\Event;
|
||||
use PocketMine;
|
||||
use PocketMine\Math\Vector3 as Vector3;
|
||||
|
||||
class EntityMoveEvent extends EntityEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var \PocketMine\Math\Vector3
|
||||
*/
|
||||
private $pos;
|
||||
|
||||
public function __construct(Entity $entity, Vector3 $pos){
|
||||
|
91
src/PocketMine/event/entity/EntitySpawnEvent.php
Normal file
91
src/PocketMine/event/entity/EntitySpawnEvent.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?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\Entity;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Entity\Entity;
|
||||
|
||||
/**
|
||||
* Called when a entity is spawned
|
||||
*/
|
||||
class EntitySpawnEvent extends EntityEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
*/
|
||||
public function __construct(Entity $entity){
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PocketMine\Level\Position
|
||||
*/
|
||||
public function getPosition(){
|
||||
return $this->entity->getPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(){
|
||||
//TODO: implement Entity types
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCreature(){
|
||||
return $this->entity instanceof PocketMine\Entity\Creature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isHuman(){
|
||||
return $this->entity instanceof PocketMine\Entity\Human;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isProjectile(){
|
||||
return $this->entity instanceof PocketMine\Entity\Projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isVehicle(){
|
||||
return $this->entity instanceof PocketMine\Entity\Vehicle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isItem(){
|
||||
return $this->entity instanceof PocketMine\Entity\DroppedItem;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?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\Event\CancellableEvent;
|
||||
use PocketMine\Player;
|
||||
use PocketMine;
|
||||
|
||||
/**
|
||||
* Called when a player is awarded an achievement
|
||||
*/
|
||||
class PlayerAchievementAwardedEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $achievement;
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
*/
|
||||
public function __construct(Player $player, $achievementId){
|
||||
$this->player = $player;
|
||||
$this->achievement = $achievementId;
|
||||
}
|
||||
|
||||
public function getAchievement(){
|
||||
return $this->achievement;
|
||||
}
|
||||
}
|
@ -22,13 +22,13 @@
|
||||
namespace PocketMine\Level;
|
||||
|
||||
use PocketMine\Block\Block;
|
||||
use PocketMine;
|
||||
use PocketMine\Block\TNT;
|
||||
use PocketMine\Entity\Entity;
|
||||
use PocketMine\Item\Item;
|
||||
use PocketMine\Math\Vector3 as Vector3;
|
||||
use PocketMine\Network\Protocol\ExplodePacket;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
use PocketMine\ServerAPI;
|
||||
|
||||
class Explosion{
|
||||
public static $specialDrops = array(
|
||||
@ -42,23 +42,22 @@ class Explosion{
|
||||
public $level;
|
||||
public $source;
|
||||
public $size;
|
||||
/**
|
||||
* @var Block[]
|
||||
*/
|
||||
public $affectedBlocks = array();
|
||||
public $stepLen = 0.3;
|
||||
private $what;
|
||||
|
||||
public function __construct(Position $center, $size){
|
||||
public function __construct(Position $center, $size, $what = null){
|
||||
$this->level = $center->level;
|
||||
$this->source = $center;
|
||||
$this->size = max($size, 0);
|
||||
$this->what = $what;
|
||||
}
|
||||
|
||||
public function explode(){
|
||||
$server = ServerAPI::request();
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
|
||||
"level" => $this->level,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
)) === false
|
||||
){
|
||||
if($this->size < 0.1){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -98,15 +97,26 @@ class Explosion{
|
||||
$send = array();
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
$yield = (1 / $this->size) * 100;
|
||||
|
||||
if($this->what instanceof Entity){
|
||||
if(PocketMine\Event\EventHandler::callEvent($ev = new PocketMine\Event\Entity\EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield)) === PocketMine\Event\Event::DENY){
|
||||
return;
|
||||
}else{
|
||||
$yield = $ev->getYield();
|
||||
$this->affectedBlocks = $ev->getBlockList();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
/*foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
|
||||
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
||||
$entity->harm($damage, "explosion");
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
foreach($this->affectedBlocks as $block){
|
||||
|
||||
if($block instanceof TNT){
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
@ -118,7 +128,7 @@ class Explosion{
|
||||
//TODO
|
||||
//$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||
//$e->spawnToAll();
|
||||
}elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){
|
||||
}elseif(mt_rand(0, 100) < $yield){
|
||||
if(isset(self::$specialDrops[$block->getID()])){
|
||||
//TODO
|
||||
//$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get(self::$specialDrops[$block->getID()], 0));
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
namespace PocketMine\Level;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Block\Air;
|
||||
use PocketMine\Block\Block;
|
||||
use PocketMine\Item\Item;
|
||||
@ -51,7 +52,6 @@ use PocketMine\Utils\Cache;
|
||||
use PocketMine\Utils\Config;
|
||||
use PocketMine\Utils\Random;
|
||||
use PocketMine\Utils\Utils;
|
||||
use PocketMine;
|
||||
|
||||
/**
|
||||
* Class Level
|
||||
@ -421,14 +421,12 @@ class Level{
|
||||
}else{
|
||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||
}
|
||||
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
|
||||
$this->time = $time;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
Player::broadcastPacket($this->players, $pk);
|
||||
}
|
||||
$this->time = $time;
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
Player::broadcastPacket($this->players, $pk);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -25,12 +25,12 @@
|
||||
*/
|
||||
namespace PocketMine\Tile;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Level\Level;
|
||||
use PocketMine\Level\Position;
|
||||
use PocketMine\NBT\Tag\Compound;
|
||||
use PocketMine\PMF\LevelFormat;
|
||||
use PocketMine\ServerAPI;
|
||||
use PocketMine;
|
||||
|
||||
abstract class Tile extends Position{
|
||||
const SIGN = "Sign";
|
||||
@ -84,7 +84,6 @@ abstract class Tile extends Position{
|
||||
$this->chunkIndex = $index;
|
||||
$this->level->tiles[$this->id] = $this;
|
||||
$this->level->chunkTiles[$this->chunkIndex][$this->id] = $this;
|
||||
$this->server->api->dhandle("tile.add", $this);
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
@ -102,7 +101,6 @@ abstract class Tile extends Position{
|
||||
unset($this->level->tiles[$this->id]);
|
||||
unset($this->level->chunkTiles[$this->chunkIndex][$this->id]);
|
||||
unset(Tile::$list[$this->id]);
|
||||
$this->server->api->dhandle("tile.remove", $this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user