Fixed CPU leak

This commit is contained in:
Shoghi Cervantes 2014-10-31 21:05:37 +01:00
parent ae06681b60
commit 8601405a88
73 changed files with 304 additions and 564 deletions

View File

@ -584,7 +584,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return; return;
} }
$pk = FullChunkDataPacket::getFromPool(); $pk = new FullChunkDataPacket();
$pk->chunkX = $x; $pk->chunkX = $x;
$pk->chunkZ = $z; $pk->chunkZ = $z;
$pk->data = $payload; $pk->data = $payload;
@ -648,14 +648,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->blocked = false; $this->blocked = false;
$pk = SetTimePacket::getFromPool(); $pk = new SetTimePacket();
$pk->time = $this->level->getTime(); $pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false; $pk->started = $this->level->stopTime == false;
$this->dataPacket($pk); $this->dataPacket($pk);
$pos = $this->level->getSafeSpawn($this); $pos = $this->level->getSafeSpawn($this);
$this->server->getPluginManager()->callEvent($ev = PlayerRespawnEvent::createEvent($this, $pos)); $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
$this->teleport($ev->getRespawnPosition()); $this->teleport($ev->getRespawnPosition());
@ -663,7 +663,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this); $this->inventory->sendArmorContents($this);
$this->server->getPluginManager()->callEvent($ev = PlayerJoinEvent::createEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game")); $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game"));
if(strlen(trim($ev->getJoinMessage())) > 0){ if(strlen(trim($ev->getJoinMessage())) > 0){
$this->server->broadcastMessage($ev->getJoinMessage()); $this->server->broadcastMessage($ev->getJoinMessage());
} }
@ -748,7 +748,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
$this->server->getPluginManager()->callEvent($ev = $packet->getSendEvent($this)); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -774,7 +774,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
$this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -806,13 +806,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
} }
$this->server->getPluginManager()->callEvent($ev = PlayerBedEnterEvent::createEvent($this, $this->level->getBlock($pos))); $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
$this->sleeping = clone $pos; $this->sleeping = clone $pos;
$this->teleport(Position::createPosition($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
$this->sendMetadata($this->getViewers()); $this->sendMetadata($this->getViewers());
$this->sendMetadata($this); $this->sendMetadata($this);
@ -836,7 +836,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$level = $pos->getLevel(); $level = $pos->getLevel();
} }
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
$pk = SetSpawnPositionPacket::getFromPool(); $pk = new SetSpawnPositionPacket();
$pk->x = (int) $this->spawnPosition->x; $pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y; $pk->y = (int) $this->spawnPosition->y;
$pk->z = (int) $this->spawnPosition->z; $pk->z = (int) $this->spawnPosition->z;
@ -845,7 +845,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
public function stopSleep(){ public function stopSleep(){
if($this->sleeping instanceof Vector3){ if($this->sleeping instanceof Vector3){
$this->server->getPluginManager()->callEvent($ev = PlayerBedLeaveEvent::createEvent($this, $this->level->getBlock($this->sleeping))); $this->server->getPluginManager()->callEvent($ev = new PlayerBedLeaveEvent($this, $this->level->getBlock($this->sleeping)));
$this->sleeping = null; $this->sleeping = null;
@ -895,7 +895,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return false; return false;
} }
} }
$this->server->getPluginManager()->callEvent($ev = PlayerAchievementAwardedEvent::createEvent($this, $achievementId)); $this->server->getPluginManager()->callEvent($ev = new PlayerAchievementAwardedEvent($this, $achievementId));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->achievements[$achievementId] = true; $this->achievements[$achievementId] = true;
Achievement::broadcast($this, $achievementId); Achievement::broadcast($this, $achievementId);
@ -929,7 +929,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return false; return false;
} }
$this->server->getPluginManager()->callEvent($ev = PlayerGameModeChangeEvent::createEvent($this, (int) $gm)); $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -949,7 +949,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$spawnPosition = $this->getSpawn(); $spawnPosition = $this->getSpawn();
$pk = StartGamePacket::getFromPool(); $pk = new StartGamePacket();
$pk->seed = $this->level->getSeed(); $pk->seed = $this->level->getSeed();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y + $this->getEyeHeight(); $pk->y = $this->y + $this->getEyeHeight();
@ -1019,7 +1019,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$flags |= 0x20; //Show Nametags $flags |= 0x20; //Show Nametags
} }
$pk = AdventureSettingsPacket::getFromPool(); $pk = new AdventureSettingsPacket();
$pk->flags = $flags; $pk->flags = $flags;
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -1122,7 +1122,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->lastYaw = $to->yaw; $this->lastYaw = $to->yaw;
$this->lastPitch = $to->pitch; $this->lastPitch = $to->pitch;
$ev = PlayerMoveEvent::createEvent($this, $from, $to); $ev = new PlayerMoveEvent($this, $from, $to);
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
@ -1130,7 +1130,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination
$this->teleport($ev->getTo()); $this->teleport($ev->getTo());
}else{ }else{
$pk = MovePlayerPacket::getFromPool(); $pk = new MovePlayerPacket();
$pk->eid = $this->id; $pk->eid = $this->id;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
@ -1145,7 +1145,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if($revert){ if($revert){
$pk = MovePlayerPacket::getFromPool(); $pk = new MovePlayerPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->x = $from->x; $pk->x = $from->x;
$pk->y = $from->y + $this->getEyeHeight() + 0.01; $pk->y = $from->y + $this->getEyeHeight() + 0.01;
@ -1206,16 +1206,16 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
continue; continue;
} }
$this->server->getPluginManager()->callEvent($ev = InventoryPickupArrowEvent::createEvent($this->inventory, $entity)); $this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if($ev->isCancelled()){ if($ev->isCancelled()){
continue; continue;
} }
$pk = TakeItemEntityPacket::getFromPool(); $pk = new TakeItemEntityPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->target = $entity->getID(); $pk->target = $entity->getID();
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = TakeItemEntityPacket::getFromPool(); $pk = new TakeItemEntityPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->target = $entity->getID(); $pk->target = $entity->getID();
Server::broadcastPacket($entity->getViewers(), $pk); Server::broadcastPacket($entity->getViewers(), $pk);
@ -1231,7 +1231,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
continue; continue;
} }
$this->server->getPluginManager()->callEvent($ev = InventoryPickupItemEvent::createEvent($this->inventory, $entity)); $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if($ev->isCancelled()){ if($ev->isCancelled()){
continue; continue;
} }
@ -1245,11 +1245,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
break; break;
} }
$pk = TakeItemEntityPacket::getFromPool(); $pk = new TakeItemEntityPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->target = $entity->getID(); $pk->target = $entity->getID();
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = TakeItemEntityPacket::getFromPool(); $pk = new TakeItemEntityPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->target = $entity->getID(); $pk->target = $entity->getID();
Server::broadcastPacket($entity->getViewers(), $pk); Server::broadcastPacket($entity->getViewers(), $pk);
@ -1288,7 +1288,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return; return;
} }
$this->server->getPluginManager()->callEvent($ev = $packet->getReceiveEvent($this)); $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
return; return;
} }
@ -1312,11 +1312,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
$pk = LoginStatusPacket::getFromPool(); $pk = new LoginStatusPacket();
$pk->status = 1; $pk->status = 1;
$this->dataPacket($pk); $this->dataPacket($pk);
}else{ }else{
$pk = LoginStatusPacket::getFromPool(); $pk = new LoginStatusPacket();
$pk->status = 2; $pk->status = 2;
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -1330,7 +1330,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return; return;
} }
$this->server->getPluginManager()->callEvent($ev = PlayerPreLoginEvent::createEvent($this, "Plugin reason")); $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->close("", $ev->getKickMessage()); $this->close("", $ev->getKickMessage());
@ -1405,7 +1405,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt); parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt);
$this->loggedIn = true; $this->loggedIn = true;
$this->server->getPluginManager()->callEvent($ev = PlayerLoginEvent::createEvent($this, "Plugin reason")); $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->close(TextFormat::YELLOW . $this->username . " has left the game", $ev->getKickMessage()); $this->close(TextFormat::YELLOW . $this->username . " has left the game", $ev->getKickMessage());
@ -1418,7 +1418,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->inventory->setHeldItemSlot(0); $this->inventory->setHeldItemSlot(0);
} }
$pk = LoginStatusPacket::getFromPool(); $pk = new LoginStatusPacket();
$pk->status = 0; $pk->status = 0;
$this->dataPacket($pk); $this->dataPacket($pk);
@ -1430,7 +1430,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->dead = false; $this->dead = false;
$pk = StartGamePacket::getFromPool(); $pk = new StartGamePacket();
$pk->seed = $this->level->getSeed(); $pk->seed = $this->level->getSeed();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
@ -1443,18 +1443,18 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->eid = 0; //Always use EntityID as zero for the actual player $pk->eid = 0; //Always use EntityID as zero for the actual player
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = SetTimePacket::getFromPool(); $pk = new SetTimePacket();
$pk->time = $this->level->getTime(); $pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false; $pk->started = $this->level->stopTime == false;
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = SetSpawnPositionPacket::getFromPool(); $pk = new SetSpawnPositionPacket();
$pk->x = (int) $spawnPosition->x; $pk->x = (int) $spawnPosition->x;
$pk->y = (int) $spawnPosition->y; $pk->y = (int) $spawnPosition->y;
$pk->z = (int) $spawnPosition->z; $pk->z = (int) $spawnPosition->z;
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = SetHealthPacket::getFromPool(); $pk = new SetHealthPacket();
$pk->health = $this->getHealth(); $pk->health = $this->getHealth();
$this->dataPacket($pk); $this->dataPacket($pk);
if($this->getHealth() <= 0){ if($this->getHealth() <= 0){
@ -1484,7 +1484,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distance($this->forceMovement) > 0.2)){ if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distance($this->forceMovement) > 0.2)){
$pk = MovePlayerPacket::getFromPool(); $pk = new MovePlayerPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->x = $this->forceMovement->x; $pk->x = $this->forceMovement->x;
$pk->y = $this->forceMovement->y + $this->getEyeHeight() + 0.01; $pk->y = $this->forceMovement->y + $this->getEyeHeight() + 0.01;
@ -1571,7 +1571,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
break; break;
} }
$blockVector = Vector3::createVector($packet->x, $packet->y, $packet->z); $blockVector = new Vector3($packet->x, $packet->y, $packet->z);
$this->craftingType = 0; $this->craftingType = 0;
@ -1579,7 +1579,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$target = $this->level->getBlock($blockVector); $target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face); $block = $target->getSide($packet->face);
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $target->x; $pk->x = $target->x;
$pk->y = $target->y; $pk->y = $target->y;
$pk->z = $target->z; $pk->z = $target->z;
@ -1587,7 +1587,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->meta = $target->getDamage(); $pk->meta = $target->getDamage();
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $block->x; $pk->x = $block->x;
$pk->y = $block->y; $pk->y = $block->y;
$pk->z = $block->z; $pk->z = $block->z;
@ -1626,7 +1626,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$target = $this->level->getBlock($blockVector); $target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face); $block = $target->getSide($packet->face);
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $target->x; $pk->x = $target->x;
$pk->y = $target->y; $pk->y = $target->y;
$pk->z = $target->z; $pk->z = $target->z;
@ -1634,7 +1634,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->meta = $target->getDamage(); $pk->meta = $target->getDamage();
$this->dataPacket($pk); $this->dataPacket($pk);
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $block->x; $pk->x = $block->x;
$pk->y = $block->y; $pk->y = $block->y;
$pk->z = $block->z; $pk->z = $block->z;
@ -1669,7 +1669,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->inventory->removeItem(Item::get(Item::SNOWBALL, 0, 1)); $this->inventory->removeItem(Item::get(Item::SNOWBALL, 0, 1));
} }
if($snowball instanceof Projectile){ if($snowball instanceof Projectile){
$this->server->getPluginManager()->callEvent($projectileEv = ProjectileLaunchEvent::createEvent($snowball)); $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball));
if($projectileEv->isCancelled()){ if($projectileEv->isCancelled()){
$snowball->kill(); $snowball->kill();
}else{ }else{
@ -1722,7 +1722,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
]); ]);
$f = 1.5; $f = 1.5;
$ev = EntityShootBowEvent::createEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this), $f); $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this), $f);
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
@ -1739,7 +1739,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
} }
if($ev->getProjectile() instanceof Projectile){ if($ev->getProjectile() instanceof Projectile){
$this->server->getPluginManager()->callEvent($projectileEv = ProjectileLaunchEvent::createEvent($ev->getProjectile())); $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if($projectileEv->isCancelled()){ if($projectileEv->isCancelled()){
$ev->getProjectile()->kill(); $ev->getProjectile()->kill();
}else{ }else{
@ -1766,7 +1766,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$this->craftingType = 0; $this->craftingType = 0;
$vector = Vector3::createVector($packet->x, $packet->y, $packet->z); $vector = new Vector3($packet->x, $packet->y, $packet->z);
if($this->isCreative()){ if($this->isCreative()){
@ -1787,7 +1787,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$target = $this->level->getBlock($vector); $target = $this->level->getBlock($vector);
$tile = $this->level->getTile($vector); $tile = $this->level->getTile($vector);
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $target->x; $pk->x = $target->x;
$pk->y = $target->y; $pk->y = $target->y;
$pk->z = $target->z; $pk->z = $target->z;
@ -1901,7 +1901,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
} }
$ev = EntityDamageByEntityEvent::createEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage); $ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if($cancelled){ if($cancelled){
$ev->setCancelled(); $ev->setCancelled();
} }
@ -1931,12 +1931,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
break; break;
} }
$this->server->getPluginManager()->callEvent($ev = PlayerAnimationEvent::createEvent($this, $packet->action)); $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if($ev->isCancelled()){ if($ev->isCancelled()){
break; break;
} }
$pk = AnimatePacket::getFromPool(); $pk = new AnimatePacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->action = $ev->getAnimationType(); $pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk); Server::broadcastPacket($this->getViewers(), $pk);
@ -1948,7 +1948,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->craftingType = 0; $this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = PlayerRespawnEvent::createEvent($this, $this->getSpawn())); $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
$this->teleport($ev->getRespawnPosition()); $this->teleport($ev->getRespawnPosition());
$this->fireTicks = 0; $this->fireTicks = 0;
@ -2004,13 +2004,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
]; ];
$slot = $this->inventory->getItemInHand(); $slot = $this->inventory->getItemInHand();
if($this->getHealth() < 20 and isset($items[$slot->getID()])){ if($this->getHealth() < 20 and isset($items[$slot->getID()])){
$this->server->getPluginManager()->callEvent($ev = PlayerItemConsumeEvent::createEvent($this, $slot)); $this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $slot));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
$pk = EntityEventPacket::getFromPool(); $pk = new EntityEventPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->event = 9; $pk->event = 9;
$this->dataPacket($pk); $this->dataPacket($pk);
@ -2018,7 +2018,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
Server::broadcastPacket($this->getViewers(), $pk); Server::broadcastPacket($this->getViewers(), $pk);
$amount = $items[$slot->getID()]; $amount = $items[$slot->getID()];
$this->server->getPluginManager()->callEvent($ev = EntityRegainHealthEvent::createEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING)); $this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->heal($ev->getAmount(), $ev); $this->heal($ev->getAmount(), $ev);
} }
@ -2038,7 +2038,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$packet->eid = $this->id; $packet->eid = $this->id;
$item = $this->inventory->getItemInHand(); $item = $this->inventory->getItemInHand();
$ev = PlayerDropItemEvent::createEvent($this, $item); $ev = new PlayerDropItemEvent($this, $item);
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
@ -2063,7 +2063,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$packet->message = TextFormat::clean($packet->message); $packet->message = TextFormat::clean($packet->message);
if(trim($packet->message) != "" and strlen($packet->message) <= 255){ if(trim($packet->message) != "" and strlen($packet->message) <= 255){
$message = $packet->message; $message = $packet->message;
$this->server->getPluginManager()->callEvent($ev = PlayerCommandPreprocessEvent::createEvent($this, $message)); $this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, $message));
if($ev->isCancelled()){ if($ev->isCancelled()){
break; break;
} }
@ -2072,7 +2072,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
Timings::$playerCommandTimer->stopTiming(); Timings::$playerCommandTimer->stopTiming();
}else{ }else{
$this->server->getPluginManager()->callEvent($ev = PlayerChatEvent::createEvent($this, $ev->getMessage())); $this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->server->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients()); $this->server->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients());
} }
@ -2086,7 +2086,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->craftingType = 0; $this->craftingType = 0;
$this->currentTransaction = null; $this->currentTransaction = null;
if(isset($this->windowIndex[$packet->windowid])){ if(isset($this->windowIndex[$packet->windowid])){
$this->server->getPluginManager()->callEvent(InventoryCloseEvent::createEvent($this->windowIndex[$packet->windowid], $this)); $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this));
$this->removeWindow($this->windowIndex[$packet->windowid]); $this->removeWindow($this->windowIndex[$packet->windowid]);
}else{ }else{
unset($this->windowIndex[$packet->windowid]); unset($this->windowIndex[$packet->windowid]);
@ -2233,7 +2233,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$this->craftingType = 0; $this->craftingType = 0;
$t = $this->level->getTile(Vector3::createVector($packet->x, $packet->y, $packet->z)); $t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
if($t instanceof Sign){ if($t instanceof Sign){
$nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read($packet->namedtag); $nbt->read($packet->namedtag);
@ -2241,7 +2241,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($nbt["id"] !== Tile::SIGN){ if($nbt["id"] !== Tile::SIGN){
$t->spawnTo($this); $t->spawnTo($this);
}else{ }else{
$ev = SignChangeEvent::createEvent($t->getBlock(), $this, [ $ev = new SignChangeEvent($t->getBlock(), $this, [
$nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"] $nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"]
]); ]);
@ -2272,7 +2272,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @return bool * @return bool
*/ */
public function kick($reason = ""){ public function kick($reason = ""){
$this->server->getPluginManager()->callEvent($ev = PlayerKickEvent::createEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game"));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
$this->sendMessage($message); $this->sendMessage($message);
@ -2296,7 +2296,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$mes = explode("\n", $message); $mes = explode("\n", $message);
foreach($mes as $m){ foreach($mes as $m){
if($m !== ""){ if($m !== ""){
$pk = MessagePacket::getFromPool(); $pk = new MessagePacket();
$pk->source = ""; //Do not use this ;) $pk->source = ""; //Do not use this ;)
$pk->message = $m; $pk->message = $m;
$this->dataPacket($pk); $this->dataPacket($pk);
@ -2318,7 +2318,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($this->connected and !$this->closed){ if($this->connected and !$this->closed){
$this->connected = false; $this->connected = false;
if($this->username != ""){ if($this->username != ""){
$this->server->getPluginManager()->callEvent($ev = PlayerQuitEvent::createEvent($this, $message)); $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
if($this->server->getAutoSave() and $this->loggedIn === true){ if($this->server->getAutoSave() and $this->loggedIn === true){
$this->save(); $this->save();
} }
@ -2494,7 +2494,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
Entity::kill(); Entity::kill();
$this->server->getPluginManager()->callEvent($ev = PlayerDeathEvent::createEvent($this, $this->getDrops(), $message)); $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), $message));
if(!$ev->getKeepInventory()){ if(!$ev->getKeepInventory()){
foreach($ev->getDrops() as $item){ foreach($ev->getDrops() as $item){
@ -2517,7 +2517,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
public function setHealth($amount){ public function setHealth($amount){
parent::setHealth($amount); parent::setHealth($amount);
if($this->spawned === true){ if($this->spawned === true){
$pk = SetHealthPacket::getFromPool(); $pk = new SetHealthPacket();
$pk->health = $this->getHealth(); $pk->health = $this->getHealth();
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -2554,7 +2554,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if($this->getLastDamageCause() === $source){ if($this->getLastDamageCause() === $source){
$pk = EntityEventPacket::getFromPool(); $pk = new EntityEventPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->event = 2; $pk->event = 2;
$this->dataPacket($pk); $this->dataPacket($pk);
@ -2600,7 +2600,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->forceMovement = $pos; $this->forceMovement = $pos;
$this->newPosition = $pos; $this->newPosition = $pos;
$pk = MovePlayerPacket::getFromPool(); $pk = new MovePlayerPacket();
$pk->eid = 0; $pk->eid = 0;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y + $this->getEyeHeight(); $pk->y = $this->y + $this->getEyeHeight();

View File

@ -934,7 +934,6 @@ class Server{
*/ */
public function unloadLevel(Level $level, $forceUnload = false){ public function unloadLevel(Level $level, $forceUnload = false){
if($level->unload($forceUnload) === true){ if($level->unload($forceUnload) === true){
Position::clearPositions();
unset($this->levels[$level->getID()]); unset($this->levels[$level->getID()]);
return true; return true;
@ -990,7 +989,7 @@ class Server{
$level->initLevel(); $level->initLevel();
$this->getPluginManager()->callEvent(LevelLoadEvent::createEvent($level)); $this->getPluginManager()->callEvent(new LevelLoadEvent($level));
/*foreach($entities->getAll() as $entity){ /*foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){ if(!isset($entity["id"])){
@ -1125,9 +1124,9 @@ class Server{
$level->initLevel(); $level->initLevel();
$this->getPluginManager()->callEvent(LevelInitEvent::createEvent($level)); $this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(LevelLoadEvent::createEvent($level)); $this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice("Spawn terrain for level \"$name\" is being generated in the background"); $this->getLogger()->notice("Spawn terrain for level \"$name\" is being generated in the background");
@ -1765,7 +1764,7 @@ class Server{
public function checkConsole(){ public function checkConsole(){
Timings::$serverCommandTimer->startTiming(); Timings::$serverCommandTimer->startTiming();
if(($line = $this->console->getLine()) !== null){ if(($line = $this->console->getLine()) !== null){
$this->pluginManager->callEvent($ev = ServerCommandEvent::createEvent($this->consoleSender, $line)); $this->pluginManager->callEvent($ev = new ServerCommandEvent($this->consoleSender, $line));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->dispatchCommand($ev->getSender(), $ev->getCommand()); $this->dispatchCommand($ev->getSender(), $ev->getCommand());
} }
@ -2163,20 +2162,13 @@ class Server{
$this->generationManager->process(); $this->generationManager->process();
if(($this->tickCounter % 100) === 0){
Vector3::clearVectorList(); foreach($this->levels as $level){
Position::clearPositionList(); $level->clearCache();
if(($this->tickCounter % 4) === 0){
Event::clearAllPools();
if(($this->tickCounter % 80) === 0){
foreach($this->levels as $level){
$level->clearCache();
}
AxisAlignedBB::clearBoundingBoxPool();
} }
} }
Timings::$serverTickTimer->stopTiming(); Timings::$serverTickTimer->stopTiming();
TimingsHandler::tick(); TimingsHandler::tick();

View File

@ -36,7 +36,7 @@ class Bed extends Transparent{
} }
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,
@ -53,7 +53,7 @@ class Bed extends Transparent{
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE); $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
if($player instanceof Player and !$isNight){ if($player instanceof Player and !$isNight){
$pk = ChatPacket::getFromPool(); $pk = new ChatPacket();
$pk->message = "You can only sleep at night"; $pk->message = "You can only sleep at night";
$player->dataPacket($pk); $player->dataPacket($pk);
@ -77,7 +77,7 @@ class Bed extends Transparent{
$b = $blockWest; $b = $blockWest;
}else{ }else{
if($player instanceof Player){ if($player instanceof Player){
$pk = ChatPacket::getFromPool(); $pk = new ChatPacket();
$pk->message = "This bed is incomplete"; $pk->message = "This bed is incomplete";
$player->dataPacket($pk); $player->dataPacket($pk);
} }
@ -87,7 +87,7 @@ class Bed extends Transparent{
} }
if($player instanceof Player and $player->sleepOn($b) === false){ if($player instanceof Player and $player->sleepOn($b) === false){
$pk = ChatPacket::getFromPool(); $pk = new ChatPacket();
$pk->message = "This bed is occupied"; $pk->message = "This bed is occupied";
$player->dataPacket($pk); $player->dataPacket($pk);
} }

View File

@ -911,7 +911,7 @@ class Block extends Position implements Metadatable{
* @return AxisAlignedBB * @return AxisAlignedBB
*/ */
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -44,7 +44,7 @@ class Cactus extends Transparent{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + 0.0625, $this->x + 0.0625,
$this->y, $this->y,
$this->z + 0.0625, $this->z + 0.0625,
@ -55,7 +55,7 @@ class Cactus extends Transparent{
} }
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev->getFinalDamage(), $ev);
} }
@ -76,9 +76,9 @@ class Cactus extends Transparent{
if($this->getSide(0)->getID() !== self::CACTUS){ if($this->getSide(0)->getID() !== self::CACTUS){
if($this->meta == 0x0F){ if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === self::AIR){ if($b->getID() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($b, new Cactus())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }

View File

@ -41,7 +41,7 @@ class Cake extends Transparent{
$f = (1 + $this->getDamage() * 2) / 16; $f = (1 + $this->getDamage() * 2) / 16;
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + $f, $this->x + $f,
$this->y, $this->y,
$this->z + 0.0625, $this->z + 0.0625,
@ -81,7 +81,7 @@ class Cake extends Transparent{
public function onActivate(Item $item, Player $player = null){ public function onActivate(Item $item, Player $player = null){
if($player instanceof Player and $player->getHealth() < 20){ if($player instanceof Player and $player->getHealth() < 20){
++$this->meta; ++$this->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = EntityRegainHealthEvent::createEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING)); Server::getInstance()->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->heal($ev->getAmount(), $ev); $player->heal($ev->getAmount(), $ev);
} }

View File

@ -55,7 +55,7 @@ class Carpet extends Flowable{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -44,7 +44,7 @@ class Chest extends Transparent{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + 0.0625, $this->x + 0.0625,
$this->y, $this->y,
$this->z + 0.0625, $this->z + 0.0625,

View File

@ -57,7 +57,7 @@ abstract class Crops extends Flowable{
$block->meta = 7; $block->meta = 7;
} }
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true); $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
@ -82,7 +82,7 @@ abstract class Crops extends Flowable{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true); $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);

View File

@ -57,7 +57,7 @@ abstract class Door extends Transparent{
$f = 0.1875; $f = 0.1875;
$damage = $this->getFullDamage(); $damage = $this->getFullDamage();
$bb = AxisAlignedBB::getBoundingBoxFromPool( $bb = new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,
@ -271,7 +271,7 @@ abstract class Door extends Transparent{
if($player instanceof Player){ if($player instanceof Player){
unset($players[$player->getID()]); unset($players[$player->getID()]);
} }
$pk = LevelEventPacket::getFromPool(); $pk = new LevelEventPacket();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
@ -290,7 +290,7 @@ abstract class Door extends Transparent{
if($player instanceof Player){ if($player instanceof Player){
unset($players[$player->getID()]); unset($players[$player->getID()]);
} }
$pk = LevelEventPacket::getFromPool(); $pk = new LevelEventPacket();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;

View File

@ -31,7 +31,7 @@ class EndPortal extends Solid{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -32,7 +32,7 @@ class Farmland extends Solid{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -43,7 +43,7 @@ class Fence extends Transparent{
$f2 = $flag ? 0 : 0.375; $f2 = $flag ? 0 : 0.375;
$f3 = $flag1 ? 1 : 0.625; $f3 = $flag1 ? 1 : 0.625;
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + $f, $this->x + $f,
$this->y, $this->y,
$this->z + $f2, $this->z + $f2,

View File

@ -46,7 +46,7 @@ class FenceGate extends Transparent{
$i = ($this->getDamage() & 0x03); $i = ($this->getDamage() & 0x03);
if($i === 2 and $i === 0){ if($i === 2 and $i === 0){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z + 0.375, $this->z + 0.375,
@ -55,7 +55,7 @@ class FenceGate extends Transparent{
$this->z + 0.625 $this->z + 0.625
); );
}else{ }else{
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + 0.375, $this->x + 0.375,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -46,10 +46,10 @@ class Fire extends Flowable{
} }
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev->getFinalDamage(), $ev);
$ev = EntityCombustByBlockEvent::createEvent($this, $entity, 8); $ev = new EntityCombustByBlockEvent($this, $entity, 8);
Server::getInstance()->getPluginManager()->callEvent($ev); Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration()); $entity->setOnFire($ev->getDuration());

View File

@ -55,10 +55,10 @@ class Grass extends Solid{
$x = mt_rand($this->x - 1, $this->x + 1); $x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2); $y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1); $z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getID() === Block::DIRT){ if($block->getID() === Block::DIRT){
if($block->getSide(1) instanceof Transparent){ if($block->getSide(1) instanceof Transparent){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Grass())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState()); $this->getLevel()->setBlock($block, $ev->getNewState());
} }

View File

@ -48,7 +48,7 @@ class Ladder extends Transparent{
$f = 0.125; $f = 0.125;
if($this->meta === 2){ if($this->meta === 2){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z + 1 - $f, $this->z + 1 - $f,
@ -57,7 +57,7 @@ class Ladder extends Transparent{
$this->z + 1 $this->z + 1
); );
}elseif($this->meta === 3){ }elseif($this->meta === 3){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,
@ -66,7 +66,7 @@ class Ladder extends Transparent{
$this->z + $f $this->z + $f
); );
}elseif($this->meta === 4){ }elseif($this->meta === 4){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + 1 - $f, $this->x + 1 - $f,
$this->y, $this->y,
$this->z, $this->z,
@ -75,7 +75,7 @@ class Ladder extends Transparent{
$this->z + 1 $this->z + 1
); );
}elseif($this->meta === 5){ }elseif($this->meta === 5){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -38,10 +38,10 @@ class Lava extends Liquid{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$entity->fallDistance *= 0.5; $entity->fallDistance *= 0.5;
$ev = EntityDamageByBlockEvent::createEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev->getFinalDamage(), $ev);
$ev = EntityCombustByBlockEvent::createEvent($this, $entity, 15); $ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev); Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration()); $entity->setOnFire($ev->getDuration());

View File

@ -124,7 +124,7 @@ class Leaves extends Transparent{
$visited = []; $visited = [];
$check = 0; $check = 0;
Server::getInstance()->getPluginManager()->callEvent($ev = LeavesDecayEvent::createEvent($this)); Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false); $this->getLevel()->setBlock($this, $this, false, false);

View File

@ -116,7 +116,7 @@ class Leaves2 extends Leaves{
$visited = []; $visited = [];
$check = 0; $check = 0;
Server::getInstance()->getPluginManager()->callEvent($ev = LeavesDecayEvent::createEvent($this)); Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false); $this->getLevel()->setBlock($this, $this, false, false);

View File

@ -80,7 +80,7 @@ abstract class Liquid extends Transparent{
} }
public function getFlowVector(){ public function getFlowVector(){
$vector = Vector3::createVector(0, 0, 0); $vector = new Vector3(0, 0, 0);
$decay = $this->getEffectiveFlowDecay($this); $decay = $this->getEffectiveFlowDecay($this);
@ -99,7 +99,7 @@ abstract class Liquid extends Transparent{
}elseif($j === 3){ }elseif($j === 3){
++$z; ++$z;
} }
$sideBlock = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $sideBlock = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
$blockDecay = $this->getEffectiveFlowDecay($sideBlock); $blockDecay = $this->getEffectiveFlowDecay($sideBlock);
if($blockDecay < 0){ if($blockDecay < 0){
@ -314,7 +314,7 @@ abstract class Liquid extends Transparent{
}elseif($j === 3){ }elseif($j === 3){
++$z; ++$z;
} }
$blockSide = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){ if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){
continue; continue;
@ -356,7 +356,7 @@ abstract class Liquid extends Transparent{
}elseif($j === 3){ }elseif($j === 3){
++$z; ++$z;
} }
$block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if(!$block->isFlowable and !($block instanceof Liquid)){ if(!$block->isFlowable and !($block instanceof Liquid)){
continue; continue;

View File

@ -42,7 +42,7 @@ class MelonStem extends Crops{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true); $this->getLevel()->setBlock($this, $ev->getNewState(), true);
} }
@ -58,7 +58,7 @@ class MelonStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0); $d = $side->getSide(0);
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){ if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($side, new Melon())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -46,10 +46,10 @@ class Mycelium extends Solid{
$x = mt_rand($this->x - 1, $this->x + 1); $x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2); $y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1); $z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getID() === Block::DIRT){ if($block->getID() === Block::DIRT){
if($block->getSide(1) instanceof Transparent){ if($block->getSide(1) instanceof Transparent){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Mycelium())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState()); $this->getLevel()->setBlock($block, $ev->getNewState());
} }

View File

@ -42,7 +42,7 @@ class PumpkinStem extends Crops{
if($this->meta < 0x07){ if($this->meta < 0x07){
$block = clone $this; $block = clone $this;
++$block->meta; ++$block->meta;
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($this, $block)); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true); $this->getLevel()->setBlock($this, $ev->getNewState(), true);
} }
@ -58,7 +58,7 @@ class PumpkinStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(0); $d = $side->getSide(0);
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){ if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($side, new Pumpkin())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -50,7 +50,7 @@ class Slab extends Transparent{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){ if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y + 0.5, $this->y + 0.5,
$this->z, $this->z,
@ -59,7 +59,7 @@ class Slab extends Transparent{
$this->z + 1 $this->z + 1
); );
}else{ }else{
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -32,7 +32,7 @@ class SoulSand extends Solid{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -116,7 +116,7 @@ abstract class Stair extends Transparent{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){ if(($this->getDamage() & 0x04) > 0){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y + 0.5, $this->y + 0.5,
$this->z, $this->z,
@ -125,7 +125,7 @@ abstract class Stair extends Transparent{
$this->z + 1 $this->z + 1
); );
}else{ }else{
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -59,7 +59,7 @@ class StoneWall extends Transparent{
$f3 = 0.6875; $f3 = 0.6875;
} }
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + $f, $this->x + $f,
$this->y, $this->y,
$this->z + $f2, $this->z + $f2,

View File

@ -49,9 +49,9 @@ class Sugarcane extends Flowable{
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === self::AIR){ if($b->getID() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = BlockGrowEvent::createEvent($b, new Sugarcane())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }
@ -83,7 +83,7 @@ class Sugarcane extends Flowable{
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
if($this->meta === 0x0F){ if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(Vector3::createVector($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getID() === self::AIR){ if($b->getID() === self::AIR){
$this->getLevel()->setBlock($b, new Sugarcane(), true); $this->getLevel()->setBlock($b, new Sugarcane(), true);
break; break;

View File

@ -63,7 +63,7 @@ abstract class Thin extends Transparent{
$f3 = 1; $f3 = 1;
} }
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + $f, $this->x + $f,
$this->y, $this->y,
$this->z + $f2, $this->z + $f2,

View File

@ -44,7 +44,7 @@ class Trapdoor extends Transparent{
$f = 0.1875; $f = 0.1875;
if(($damage & 0x08) > 0){ if(($damage & 0x08) > 0){
$bb = AxisAlignedBB::getBoundingBoxFromPool( $bb = new AxisAlignedBB(
$this->x, $this->x,
$this->y + 1 - $f, $this->y + 1 - $f,
$this->z, $this->z,
@ -53,7 +53,7 @@ class Trapdoor extends Transparent{
$this->z + 1 $this->z + 1
); );
}else{ }else{
$bb = AxisAlignedBB::getBoundingBoxFromPool( $bb = new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -93,7 +93,7 @@ class Vine extends Transparent{
$f6 = 1; $f6 = 1;
} }
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x + $f1, $this->x + $f1,
$this->y + $f2, $this->y + $f2,
$this->z + $f3, $this->z + $f3,

View File

@ -48,7 +48,7 @@ class WoodSlab extends Transparent{
protected function recalculateBoundingBox(){ protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){ if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y + 0.5, $this->y + 0.5,
$this->z, $this->z,
@ -57,7 +57,7 @@ class WoodSlab extends Transparent{
$this->z + 1 $this->z + 1
); );
}else{ }else{
return AxisAlignedBB::getBoundingBoxFromPool( return new AxisAlignedBB(
$this->x, $this->x,
$this->y, $this->y,
$this->z, $this->z,

View File

@ -44,7 +44,7 @@ class KillCommand extends VanillaCommand{
} }
if($sender instanceof Player){ if($sender instanceof Player){
$sender->getServer()->getPluginManager()->callEvent($ev = EntityDamageEvent::createEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000)); $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000));
if($ev->isCancelled()){ if($ev->isCancelled()){
return true; return true;

View File

@ -46,8 +46,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
if(count($args) === 0){ if(count($args) === 0){
if($sender instanceof Player){ if($sender instanceof Player){
$level = $sender->getLevel(); $level = $sender->getLevel();
$pos = Vector3::cloneVector($sender); $pos = (new Vector3($sender->x, $sender->y, $sender->z))->round();
$pos = $pos->round();
}else{ }else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");

View File

@ -70,14 +70,14 @@ class SpawnpointCommand extends VanillaCommand{
$x = (int) $this->getRelativeDouble($pos->x, $sender, $args[1]); $x = (int) $this->getRelativeDouble($pos->x, $sender, $args[1]);
$y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, 128); $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, 128);
$z = $this->getRelativeDouble($pos->z, $sender, $args[3]); $z = $this->getRelativeDouble($pos->z, $sender, $args[3]);
$target->setSpawn(Position::createPosition($x, $y, $z, $level)); $target->setSpawn(new Position($x, $y, $z, $level));
Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $x . ", " . $y . ", " . $z); Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $x . ", " . $y . ", " . $z);
return true; return true;
} }
}elseif(count($args) <= 1){ }elseif(count($args) <= 1){
if($sender instanceof Player){ if($sender instanceof Player){
$pos = Position::createPosition((int) $sender->x, (int) $sender->y, (int) $sender->z, $sender->getLevel()); $pos = new Position((int) $sender->x, (int) $sender->y, (int) $sender->z, $sender->getLevel());
$target->setSpawn($pos); $target->setSpawn($pos);
Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $pos->x . ", " . $pos->y . ", " . $pos->z); Command::broadcastCommandMessage($sender, "Set " . $target->getDisplayName() . "'s spawnpoint to " . $pos->x . ", " . $pos->y . ", " . $pos->z);

View File

@ -88,8 +88,7 @@ class TeleportCommand extends VanillaCommand{
} }
if(count($args) < 3){ if(count($args) < 3){
$pos = Position::clonePosition($target); $origin->teleport($target);
$origin->teleport($pos);
Command::broadcastCommandMessage($sender, "Teleported " . $origin->getDisplayName() . " to " . $target->getDisplayName()); Command::broadcastCommandMessage($sender, "Teleported " . $origin->getDisplayName() . " to " . $target->getDisplayName());
return true; return true;
@ -98,7 +97,7 @@ class TeleportCommand extends VanillaCommand{
$x = $this->getRelativeDouble($target->x, $sender, $args[$pos++]); $x = $this->getRelativeDouble($target->x, $sender, $args[$pos++]);
$y = $this->getRelativeDouble($target->y, $sender, $args[$pos++], 0, 128); $y = $this->getRelativeDouble($target->y, $sender, $args[$pos++], 0, 128);
$z = $this->getRelativeDouble($target->z, $sender, $args[$pos]); $z = $this->getRelativeDouble($target->z, $sender, $args[$pos]);
$target->teleport(Vector3::createVector($x, $y, $z)); $target->teleport(new Vector3($x, $y, $z));
Command::broadcastCommandMessage($sender, "Teleported " . $target->getDisplayName() . " to " . round($x, 2) . ", " . round($y, 2) . ", " . round($z, 2)); Command::broadcastCommandMessage($sender, "Teleported " . $target->getDisplayName() . " to " . round($x, 2) . ", " . round($y, 2) . ", " . round($z, 2));
return true; return true;

View File

@ -71,7 +71,7 @@ class Arrow extends Projectile{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool(); $pk = new AddEntityPacket();
$pk->type = Arrow::NETWORK_ID; $pk->type = Arrow::NETWORK_ID;
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->x = $this->x; $pk->x = $this->x;
@ -80,7 +80,7 @@ class Arrow extends Projectile{
$pk->did = 0; //TODO: send motion here $pk->did = 0; //TODO: send motion here
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -177,7 +177,7 @@ abstract class Entity extends Location implements Metadatable{
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation( $this->setPositionAndRotation(
Vector3::createVector( new Vector3(
$this->namedtag["Pos"][0], $this->namedtag["Pos"][0],
$this->namedtag["Pos"][1], $this->namedtag["Pos"][1],
$this->namedtag["Pos"][2] $this->namedtag["Pos"][2]
@ -186,7 +186,7 @@ abstract class Entity extends Location implements Metadatable{
$this->namedtag->Rotation[1], $this->namedtag->Rotation[1],
true true
); );
$this->setMotion(Vector3::createVector($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2])); $this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
if(!isset($this->namedtag->FallDistance)){ if(!isset($this->namedtag->FallDistance)){
$this->namedtag->FallDistance = new Float("FallDistance", 0); $this->namedtag->FallDistance = new Float("FallDistance", 0);
@ -217,7 +217,7 @@ abstract class Entity extends Location implements Metadatable{
$this->level->addEntity($this); $this->level->addEntity($this);
$this->initEntity(); $this->initEntity();
$this->lastUpdate = $this->server->getTick(); $this->lastUpdate = $this->server->getTick();
$this->server->getPluginManager()->callEvent(EntitySpawnEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
$this->scheduleUpdate(); $this->scheduleUpdate();
@ -307,7 +307,7 @@ abstract class Entity extends Location implements Metadatable{
$player = [$player]; $player = [$player];
} }
$pk = SetEntityDataPacket::getFromPool(); $pk = new SetEntityDataPacket();
$pk->eid = $this->id; $pk->eid = $this->id;
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$pk->encode(); $pk->encode();
@ -315,7 +315,7 @@ abstract class Entity extends Location implements Metadatable{
foreach($player as $p){ foreach($player as $p){
if($p === $this){ if($p === $this){
/** @var Player $p */ /** @var Player $p */
$pk2 = SetEntityDataPacket::getFromPool(); $pk2 = new SetEntityDataPacket();
$pk2->eid = 0; $pk2->eid = 0;
$pk2->metadata = $this->getData(); $pk2->metadata = $this->getData();
$p->dataPacket($pk2); $p->dataPacket($pk2);
@ -330,7 +330,7 @@ abstract class Entity extends Location implements Metadatable{
*/ */
public function despawnFrom(Player $player){ public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){ if(isset($this->hasSpawned[$player->getID()])){
$pk = RemoveEntityPacket::getFromPool(); $pk = new RemoveEntityPacket();
$pk->eid = $this->id; $pk->eid = $this->id;
$player->dataPacket($pk); $player->dataPacket($pk);
unset($this->hasSpawned[$player->getID()]); unset($this->hasSpawned[$player->getID()]);
@ -424,7 +424,7 @@ abstract class Entity extends Location implements Metadatable{
$list = $this->level->getCollisionBlocks($this->boundingBox); $list = $this->level->getCollisionBlocks($this->boundingBox);
$v = Vector3::createVector($i, $j, $k); $v = new Vector3($i, $j, $k);
if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){ if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){
return false; return false;
@ -522,7 +522,7 @@ abstract class Entity extends Location implements Metadatable{
$this->checkBlockCollision(); $this->checkBlockCollision();
if($this->y < 0 and $this->dead !== true){ if($this->y < 0 and $this->dead !== true){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_VOID, 10); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);
$hasUpdate = true; $hasUpdate = true;
} }
@ -535,7 +535,7 @@ abstract class Entity extends Location implements Metadatable{
} }
}else{ }else{
if(($this->fireTicks % 20) === 0 or $tickDiff > 20){ if(($this->fireTicks % 20) === 0 or $tickDiff > 20){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);
} }
$this->fireTicks -= $tickDiff; $this->fireTicks -= $tickDiff;
@ -566,7 +566,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastPitch = $this->pitch; $this->lastPitch = $this->pitch;
if($this instanceof Human){ if($this instanceof Human){
$pk = MovePlayerPacket::getFromPool(); $pk = new MovePlayerPacket();
$pk->eid = $this->id; $pk->eid = $this->id;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
@ -576,7 +576,7 @@ abstract class Entity extends Location implements Metadatable{
$pk->bodyYaw = $this->yaw; $pk->bodyYaw = $this->yaw;
}else{ }else{
//TODO: add to move list //TODO: add to move list
$pk = MoveEntityPacket::getFromPool(); $pk = new MoveEntityPacket();
$pk->entities = [ $pk->entities = [
[$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch] [$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch]
]; ];
@ -590,7 +590,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastMotionY = $this->motionY; $this->lastMotionY = $this->motionY;
$this->lastMotionZ = $this->motionZ; $this->lastMotionZ = $this->motionZ;
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];
@ -617,7 +617,7 @@ abstract class Entity extends Location implements Metadatable{
$x = -$xz * sin(deg2rad($this->yaw)); $x = -$xz * sin(deg2rad($this->yaw));
$z = $xz * cos(deg2rad($this->yaw)); $z = $xz * cos(deg2rad($this->yaw));
return Vector3::createVector($x, $y, $z); return new Vector3($x, $y, $z);
} }
public function onUpdate($currentTick){ public function onUpdate($currentTick){
@ -709,7 +709,7 @@ abstract class Entity extends Location implements Metadatable{
public function fall($fallDistance){ public function fall($fallDistance){
$damage = floor($fallDistance - 3); $damage = floor($fallDistance - 3);
if($damage > 0){ if($damage > 0){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);
} }
} }
@ -732,7 +732,7 @@ abstract class Entity extends Location implements Metadatable{
protected function switchLevel(Level $targetLevel){ protected function switchLevel(Level $targetLevel){
if($this->isValid()){ if($this->isValid()){
$this->server->getPluginManager()->callEvent($ev = EntityLevelChangeEvent::createEvent($this, $this->level, $targetLevel)); $this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -750,13 +750,14 @@ abstract class Entity extends Location implements Metadatable{
} }
$this->level->freeChunk($X, $Z, $this); $this->level->freeChunk($X, $Z, $this);
} }
$this->level->freeAllChunks($this);
} }
} }
$this->setLevel($targetLevel, $this instanceof Player ? true : false); //Hard reference $this->setLevel($targetLevel, $this instanceof Player ? true : false); //Hard reference
$this->level->addEntity($this); $this->level->addEntity($this);
if($this instanceof Player){ if($this instanceof Player){
$this->usedChunks = []; $this->usedChunks = [];
$pk = SetTimePacket::getFromPool(); $pk = new SetTimePacket();
$pk->time = $this->level->getTime(); $pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false; $pk->started = $this->level->stopTime == false;
$this->dataPacket($pk); $this->dataPacket($pk);
@ -767,7 +768,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function getPosition(){ public function getPosition(){
return Position::createPosition($this->x, $this->y, $this->z, $this->level); return new Position($this->x, $this->y, $this->z, $this->level);
} }
public function getLocation(){ public function getLocation(){
@ -775,7 +776,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function isInsideOfWater(){ public function isInsideOfWater(){
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
if($block instanceof Water){ if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@ -786,7 +787,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function isInsideOfSolid(){ public function isInsideOfSolid(){
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$bb = $block->getBoundingBox(); $bb = $block->getBoundingBox();
@ -809,7 +810,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->keepMovement){ if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz); $this->boundingBox->offset($dx, $dy, $dz);
$this->setPosition(Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); $this->setPosition(new Vector3(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
$this->onGround = $this instanceof Player ? true : false; $this->onGround = $this instanceof Player ? true : false;
}else{ }else{
@ -833,7 +834,7 @@ abstract class Entity extends Location implements Metadatable{
$movY = $dy; $movY = $dy;
$movZ = $dz; $movZ = $dz;
$axisalignedbb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); $axisalignedbb = clone $this->boundingBox;
/*$sneakFlag = $this->onGround and $this instanceof Player; /*$sneakFlag = $this->onGround and $this instanceof Player;
@ -911,7 +912,7 @@ abstract class Entity extends Location implements Metadatable{
$dy = $this->stepHeight; $dy = $this->stepHeight;
$dz = $movZ; $dz = $movZ;
$axisalignedbb1 = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); $axisalignedbb1 = clone $this->boundingBox;
$this->boundingBox->setBB($axisalignedbb); $this->boundingBox->setBB($axisalignedbb);
@ -971,7 +972,7 @@ abstract class Entity extends Location implements Metadatable{
} }
$pos = Vector3::createVector( $pos = new Vector3(
($this->boundingBox->minX + $this->boundingBox->maxX) / 2, ($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
$this->boundingBox->minY - $this->ySize, $this->boundingBox->minY - $this->ySize,
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
@ -986,7 +987,7 @@ abstract class Entity extends Location implements Metadatable{
if($this instanceof Player){ if($this instanceof Player){
if(!$this->onGround or $movY != 0){ if(!$this->onGround or $movY != 0){
$bb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox); $bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 1; $bb->maxY = $bb->minY + 1;
if(count($this->level->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){ if(count($this->level->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){
$this->onGround = true; $this->onGround = true;
@ -1028,8 +1029,8 @@ abstract class Entity extends Location implements Metadatable{
$maxY = Math::floorFloat($this->boundingBox->maxY - 0.001); $maxY = Math::floorFloat($this->boundingBox->maxY - 0.001);
$maxZ = Math::floorFloat($this->boundingBox->maxZ - 0.001); $maxZ = Math::floorFloat($this->boundingBox->maxZ - 0.001);
$vector = Vector3::createVector(0, 0, 0); $vector = new Vector3(0, 0, 0);
$v = Vector3::createVector(0, 0, 0); $v = new Vector3(0, 0, 0);
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){ for($v->x = $minX; $v->x <= $maxX; ++$v->x){
@ -1113,12 +1114,12 @@ abstract class Entity extends Location implements Metadatable{
} }
public function getMotion(){ public function getMotion(){
return Vector3::createVector($this->motionX, $this->motionY, $this->motionZ); return new Vector3($this->motionX, $this->motionY, $this->motionZ);
} }
public function setMotion(Vector3 $motion){ public function setMotion(Vector3 $motion){
if(!$this->justCreated){ if(!$this->justCreated){
$this->server->getPluginManager()->callEvent($ev = EntityMotionEvent::createEvent($this, $motion)); $this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -1130,7 +1131,7 @@ abstract class Entity extends Location implements Metadatable{
if(!$this->justCreated){ if(!$this->justCreated){
if($this instanceof Player){ if($this instanceof Player){
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[0, $this->motionX, $this->motionY, $this->motionZ] [0, $this->motionX, $this->motionY, $this->motionZ]
]; ];
@ -1169,14 +1170,14 @@ abstract class Entity extends Location implements Metadatable{
} }
$from = Position::fromObject($this, $this->level); $from = Position::fromObject($this, $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
$this->server->getPluginManager()->callEvent($ev = EntityTeleportEvent::createEvent($this, $from, $to)); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
$this->ySize = 0; $this->ySize = 0;
$pos = $ev->getTo(); $pos = $ev->getTo();
$this->setMotion(Vector3::createVector(0, 0, 0)); $this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){
$this->fallDistance = 0; $this->fallDistance = 0;
$this->onGround = true; $this->onGround = true;
@ -1207,7 +1208,7 @@ abstract class Entity extends Location implements Metadatable{
public function close(){ public function close(){
if(!$this->closed){ if(!$this->closed){
$this->server->getPluginManager()->callEvent(EntityDespawnEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true; $this->closed = true;
unset($this->level->updateEntities[$this->id]); unset($this->level->updateEntities[$this->id]);
if($this->chunk instanceof FullChunk){ if($this->chunk instanceof FullChunk){

View File

@ -90,8 +90,7 @@ class FallingSand extends Entity{
if(!$this->dead){ if(!$this->dead){
if($this->ticksLived === 1){ if($this->ticksLived === 1){
$pos = Vector3::cloneVector($this); $block = $this->level->getBlock((new Vector3($this->x, $this->y, $this->z))->floor());
$block = $this->level->getBlock($pos->floor());
if($block->getID() != $this->blockId){ if($block->getID() != $this->blockId){
$this->kill(); $this->kill();
return true; return true;
@ -110,8 +109,7 @@ class FallingSand extends Entity{
$this->motionY *= 1 - $this->drag; $this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction; $this->motionZ *= $friction;
$pos = Vector3::cloneVector($this); $pos = (new Vector3($this->x, $this->y, $this->z))->floor();
$pos = $pos->floor();
if($this->onGround){ if($this->onGround){
$this->kill(); $this->kill();
@ -119,7 +117,7 @@ class FallingSand extends Entity{
if(!$block->isFullBlock){ if(!$block->isFullBlock){
$this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1));
}else{ }else{
$this->server->getPluginManager()->callEvent($ev = EntityBlockChangeEvent::createEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($pos, $ev->getTo(), true); $this->getLevel()->setBlock($pos, $ev->getTo(), true);
} }
@ -154,7 +152,7 @@ class FallingSand extends Entity{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool(); $pk = new AddEntityPacket();
$pk->type = FallingSand::NETWORK_ID; $pk->type = FallingSand::NETWORK_ID;
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->x = $this->x; $pk->x = $this->x;
@ -163,7 +161,7 @@ class FallingSand extends Entity{
$pk->did = -($this->getBlock() | $this->getDamage() << 0x10); $pk->did = -($this->getBlock() | $this->getDamage() << 0x10);
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -156,7 +156,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($player !== $this and !isset($this->hasSpawned[$player->getID()])){ if($player !== $this and !isset($this->hasSpawned[$player->getID()])){
$this->hasSpawned[$player->getID()] = $player; $this->hasSpawned[$player->getID()] = $player;
$pk = AddPlayerPacket::getFromPool(); $pk = new AddPlayerPacket();
$pk->clientID = 0; $pk->clientID = 0;
if($player->getRemoveFormat()){ if($player->getRemoveFormat()){
$pk->username = TextFormat::clean($this->nameTag); $pk->username = TextFormat::clean($this->nameTag);
@ -174,7 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];
@ -188,7 +188,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function despawnFrom(Player $player){ public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){ if(isset($this->hasSpawned[$player->getID()])){
$pk = RemovePlayerPacket::getFromPool(); $pk = new RemovePlayerPacket();
$pk->eid = $this->id; $pk->eid = $this->id;
$pk->clientID = 0; $pk->clientID = 0;
$player->dataPacket($pk); $player->dataPacket($pk);

View File

@ -71,7 +71,7 @@ class Item extends Entity{
$this->item = ItemItem::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]); $this->item = ItemItem::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]);
$this->server->getPluginManager()->callEvent(ItemSpawnEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
} }
public function onUpdate($currentTick){ public function onUpdate($currentTick){
@ -100,7 +100,7 @@ class Item extends Entity{
$friction = 1 - $this->drag; $friction = 1 - $this->drag;
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){ if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){
$friction = $this->getLevel()->getBlock(Vector3::createVector($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction; $friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
} }
$this->motionX *= $friction; $this->motionX *= $friction;
@ -114,7 +114,7 @@ class Item extends Entity{
} }
if($this->age > 6000){ if($this->age > 6000){
$this->server->getPluginManager()->callEvent($ev = ItemDespawnEvent::createEvent($this)); $this->server->getPluginManager()->callEvent($ev = new ItemDespawnEvent($this));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->age = 0; $this->age = 0;
}else{ }else{
@ -227,7 +227,7 @@ class Item extends Entity{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddItemEntityPacket::getFromPool(); $pk = new AddItemEntityPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
@ -238,7 +238,7 @@ class Item extends Entity{
$pk->item = $this->getItem(); $pk->item = $this->getItem();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -91,7 +91,7 @@ abstract class Living extends Entity implements Damageable{
} }
} }
$pk = EntityEventPacket::getFromPool(); $pk = new EntityEventPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->event = 2; //Ouch! $pk->event = 2; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk); Server::broadcastPacket($this->hasSpawned, $pk);
@ -114,7 +114,7 @@ abstract class Living extends Entity implements Damageable{
$f = sqrt($x ** 2 + $z ** 2); $f = sqrt($x ** 2 + $z ** 2);
$base = 0.4; $base = 0.4;
$motion = Vector3::createVector($this->motionX, $this->motionY, $this->motionZ); $motion = new Vector3($this->motionX, $this->motionY, $this->motionZ);
$motion->x /= 2; $motion->x /= 2;
$motion->y /= 2; $motion->y /= 2;
@ -139,7 +139,7 @@ abstract class Living extends Entity implements Damageable{
return; return;
} }
parent::kill(); parent::kill();
$this->server->getPluginManager()->callEvent($ev = EntityDeathEvent::createEvent($this, $this->getDrops())); $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
foreach($ev->getDrops() as $item){ foreach($ev->getDrops() as $item){
$this->getLevel()->dropItem($this, $item); $this->getLevel()->dropItem($this, $item);
} }
@ -147,10 +147,10 @@ abstract class Living extends Entity implements Damageable{
public function entityBaseTick($tickDiff = 1){ public function entityBaseTick($tickDiff = 1){
Timings::$timerEntityBaseTick->startTiming(); Timings::$timerEntityBaseTick->startTiming();
parent::entityBaseTick(); parent::entityBaseTick($tickDiff);
if($this->dead !== true and $this->isInsideOfSolid()){ if($this->dead !== true and $this->isInsideOfSolid()){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);
} }
@ -159,7 +159,7 @@ abstract class Living extends Entity implements Damageable{
if($this->airTicks <= -20){ if($this->airTicks <= -20){
$this->airTicks = 0; $this->airTicks = 0;
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);
} }
}else{ }else{

View File

@ -128,7 +128,7 @@ class PrimedTNT extends Entity implements Explosive{
} }
public function explode(){ public function explode(){
$this->server->getPluginManager()->callEvent($ev = ExplosionPrimeEvent::createEvent($this, 4)); $this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$explosion = new Explosion($this, $ev->getForce(), $this); $explosion = new Explosion($this, $ev->getForce(), $this);
@ -140,7 +140,7 @@ class PrimedTNT extends Entity implements Explosive{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool(); $pk = new AddEntityPacket();
$pk->type = PrimedTNT::NETWORK_ID; $pk->type = PrimedTNT::NETWORK_ID;
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->x = $this->x; $pk->x = $this->x;
@ -149,7 +149,7 @@ class PrimedTNT extends Entity implements Explosive{
$pk->did = 0; $pk->did = 0;
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -93,7 +93,7 @@ abstract class Projectile extends Entity{
$this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
$moveVector = Vector3::createVector($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this);
@ -129,18 +129,18 @@ abstract class Projectile extends Entity{
if($movingObjectPosition !== null){ if($movingObjectPosition !== null){
if($movingObjectPosition->entityHit !== null){ if($movingObjectPosition->entityHit !== null){
$this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
$motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2);
$damage = ceil($motion * $this->damage); $damage = ceil($motion * $this->damage);
$ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); $ev = new EntityDamageByEntityEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage);
$movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev);
if($this->fireTicks > 0){ if($this->fireTicks > 0){
$ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5); $ev = new EntityCombustByEntityEvent($this, $movingObjectPosition->entityHit, 5);
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$movingObjectPosition->entityHit->setOnFire($ev->getDuration()); $movingObjectPosition->entityHit->setOnFire($ev->getDuration());
@ -159,7 +159,7 @@ abstract class Projectile extends Entity{
$this->motionY = 0; $this->motionY = 0;
$this->motionZ = 0; $this->motionZ = 0;
$this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
} }
if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){ if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){

View File

@ -69,7 +69,7 @@ class Snowball extends Projectile{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool(); $pk = new AddEntityPacket();
$pk->type = Snowball::NETWORK_ID; $pk->type = Snowball::NETWORK_ID;
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->x = $this->x; $pk->x = $this->x;
@ -78,7 +78,7 @@ class Snowball extends Projectile{
$pk->did = 0; //TODO: send motion here $pk->did = 0; //TODO: send motion here
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -55,7 +55,7 @@ class Villager extends Creature implements NPC, Ageable{
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddMobPacket::getFromPool(); $pk = new AddMobPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->type = Villager::NETWORK_ID; $pk->type = Villager::NETWORK_ID;
$pk->x = $this->x; $pk->x = $this->x;
@ -66,7 +66,7 @@ class Villager extends Creature implements NPC, Ageable{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -46,7 +46,7 @@ class Zombie extends Monster{
public function spawnTo(Player $player){ public function spawnTo(Player $player){
$pk = AddMobPacket::getFromPool(); $pk = new AddMobPacket();
$pk->eid = $this->getID(); $pk->eid = $this->getID();
$pk->type = Zombie::NETWORK_ID; $pk->type = Zombie::NETWORK_ID;
$pk->x = $this->x; $pk->x = $this->x;
@ -57,7 +57,7 @@ class Zombie extends Monster{
$pk->metadata = $this->getData(); $pk->metadata = $this->getData();
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool(); $pk = new SetEntityMotionPacket();
$pk->entities = [ $pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ] [$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
]; ];

View File

@ -36,13 +36,6 @@ abstract class Event{
* Not doing so will deny the proper event initialization * Not doing so will deny the proper event initialization
*/ */
/** @var Event[] */
public static $eventPool = [];
public static $nextEvent = 0;
/** @var Event[] */
private static $knownEvents = [];
protected $eventName = null; protected $eventName = null;
private $isCancelled = false; private $isCancelled = false;
@ -94,40 +87,4 @@ abstract class Event{
return static::$handlerList; return static::$handlerList;
} }
public static function clearEventPool(){
static::$nextEvent = 0;
}
public static function clearAllPools(){
foreach(self::$knownEvents as $event){
$event::clearEventPool();
}
}
/**
* @param $params
*
* @return static
*/
public static function createEvent(...$params){
if(static::$nextEvent >= count(static::$eventPool)){
static::$eventPool[] = new static(...$params);
return static::$eventPool[static::$nextEvent++];
}
$ev = static::$eventPool[static::$nextEvent++];
$ev->__construct(...$params);
if($ev instanceof Cancellable){
$ev->setCancelled(false);
}
return $ev;
}
public static function onClassLoaded(){
self::$knownEvents[static::class] = static::class;
}
public static function getKnownEvents(){
return self::$knownEvents;
}
} }

View File

@ -131,7 +131,7 @@ abstract class BaseInventory implements Inventory{
$holder = $this->getHolder(); $holder = $this->getHolder();
if($holder instanceof Entity){ if($holder instanceof Entity){
Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $this->getItem($index), $item, $index)); Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $this->getItem($index), $item, $index));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendContents($this->getViewers()); $this->sendContents($this->getViewers());
@ -298,7 +298,7 @@ abstract class BaseInventory implements Inventory{
$old = $this->slots[$index]; $old = $this->slots[$index];
$holder = $this->getHolder(); $holder = $this->getHolder();
if($holder instanceof Entity){ if($holder instanceof Entity){
Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $old, $item, $index)); Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $old, $item, $index));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendContents($this->getViewers()); $this->sendContents($this->getViewers());
@ -350,7 +350,7 @@ abstract class BaseInventory implements Inventory{
} }
public function open(Player $who){ public function open(Player $who){
$who->getServer()->getPluginManager()->callEvent($ev = InventoryOpenEvent::createEvent($this, $who)); $who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -384,7 +384,7 @@ abstract class BaseInventory implements Inventory{
$target = [$target]; $target = [$target];
} }
$pk = ContainerSetContentPacket::getFromPool(); $pk = new ContainerSetContentPacket();
$pk->slots = []; $pk->slots = [];
for($i = 0; $i < $this->getSize(); ++$i){ for($i = 0; $i < $this->getSize(); ++$i){
$pk->slots[$i] = $this->getItem($i); $pk->slots[$i] = $this->getItem($i);
@ -409,7 +409,7 @@ abstract class BaseInventory implements Inventory{
$target = [$target]; $target = [$target];
} }
$pk = ContainerSetSlotPacket::getFromPool(); $pk = new ContainerSetSlotPacket();
$pk->slot = $index; $pk->slot = $index;
$pk->item = clone $this->getItem($index); $pk->item = clone $this->getItem($index);

View File

@ -43,7 +43,7 @@ class ChestInventory extends ContainerInventory{
parent::onOpen($who); parent::onOpen($who);
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool(); $pk = new TileEventPacket();
$pk->x = $this->getHolder()->getX(); $pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY(); $pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ(); $pk->z = $this->getHolder()->getZ();
@ -57,7 +57,7 @@ class ChestInventory extends ContainerInventory{
public function onClose(Player $who){ public function onClose(Player $who){
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool(); $pk = new TileEventPacket();
$pk->x = $this->getHolder()->getX(); $pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY(); $pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ(); $pk->z = $this->getHolder()->getZ();

View File

@ -29,7 +29,7 @@ use pocketmine\Player;
abstract class ContainerInventory extends BaseInventory{ abstract class ContainerInventory extends BaseInventory{
public function onOpen(Player $who){ public function onOpen(Player $who){
parent::onOpen($who); parent::onOpen($who);
$pk = ContainerOpenPacket::getFromPool(); $pk = new ContainerOpenPacket();
$pk->windowid = $who->getWindowId($this); $pk->windowid = $who->getWindowId($this);
$pk->type = $this->getType()->getNetworkType(); $pk->type = $this->getType()->getNetworkType();
$pk->slots = $this->getSize(); $pk->slots = $this->getSize();
@ -48,7 +48,7 @@ abstract class ContainerInventory extends BaseInventory{
} }
public function onClose(Player $who){ public function onClose(Player $who){
$pk = ContainerClosePacket::getFromPool(); $pk = new ContainerClosePacket();
$pk->windowid = $who->getWindowId($this); $pk->windowid = $who->getWindowId($this);
$who->dataPacket($pk); $who->dataPacket($pk);
parent::onClose($who); parent::onClose($who);

View File

@ -92,7 +92,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
return false; return false;
} }
Server::getInstance()->getPluginManager()->callEvent($ev = CraftItemEvent::createEvent($this, $this->getMatchingRecipe())); Server::getInstance()->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $this->getMatchingRecipe()));
if($ev->isCancelled()){ if($ev->isCancelled()){
foreach($this->inventories as $inventory){ foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers()); $inventory->sendContents($inventory->getViewers());

View File

@ -91,7 +91,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
parent::onOpen($who); parent::onOpen($who);
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool(); $pk = new TileEventPacket();
$pk->x = $this->right->getHolder()->getX(); $pk->x = $this->right->getHolder()->getX();
$pk->y = $this->right->getHolder()->getY(); $pk->y = $this->right->getHolder()->getY();
$pk->z = $this->right->getHolder()->getZ(); $pk->z = $this->right->getHolder()->getZ();
@ -105,7 +105,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
public function onClose(Player $who){ public function onClose(Player $who){
if(count($this->getViewers()) === 1){ if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool(); $pk = new TileEventPacket();
$pk->x = $this->right->getHolder()->getX(); $pk->x = $this->right->getHolder()->getX();
$pk->y = $this->right->getHolder()->getY(); $pk->y = $this->right->getHolder()->getY();
$pk->z = $this->right->getHolder()->getZ(); $pk->z = $this->right->getHolder()->getZ();

View File

@ -66,7 +66,7 @@ class PlayerInventory extends BaseInventory{
$this->itemInHandIndex = $index; $this->itemInHandIndex = $index;
$item = $this->getItemInHand(); $item = $this->getItemInHand();
$pk = PlayerEquipmentPacket::getFromPool(); $pk = new PlayerEquipmentPacket();
$pk->eid = $this->getHolder()->getID(); $pk->eid = $this->getHolder()->getID();
$pk->item = $item->getID(); $pk->item = $item->getID();
$pk->meta = $item->getDamage(); $pk->meta = $item->getDamage();
@ -103,7 +103,7 @@ class PlayerInventory extends BaseInventory{
if($slot >= -1 and $slot < $this->getSize()){ if($slot >= -1 and $slot < $this->getSize()){
$item = $this->getItem($slot); $item = $this->getItem($slot);
if($this->getHolder() instanceof Player){ if($this->getHolder() instanceof Player){
Server::getInstance()->getPluginManager()->callEvent($ev = PlayerItemHeldEvent::createEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex)); Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendHeldItem($this->getHolder()); $this->sendHeldItem($this->getHolder());
@ -126,7 +126,7 @@ class PlayerInventory extends BaseInventory{
$item = $this->getItemInHand(); $item = $this->getItemInHand();
$pk = PlayerEquipmentPacket::getFromPool(); $pk = new PlayerEquipmentPacket();
$pk->eid = $this->getHolder()->getID(); $pk->eid = $this->getHolder()->getID();
$pk->item = $item->getID(); $pk->item = $item->getID();
$pk->meta = $item->getDamage(); $pk->meta = $item->getDamage();
@ -203,7 +203,7 @@ class PlayerInventory extends BaseInventory{
} }
if($index >= $this->getSize()){ //Armor change if($index >= $this->getSize()){ //Armor change
Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $this->getItem($index), $item, $index)); Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
if($ev->isCancelled() and $this->getHolder() instanceof Player){ if($ev->isCancelled() and $this->getHolder() instanceof Player){
$this->sendArmorContents($this->getViewers()); $this->sendArmorContents($this->getViewers());
$this->sendContents($this->getViewers()); $this->sendContents($this->getViewers());
@ -229,7 +229,7 @@ class PlayerInventory extends BaseInventory{
$item = Item::get(Item::AIR, null, 0); $item = Item::get(Item::AIR, null, 0);
$old = $this->slots[$index]; $old = $this->slots[$index];
if($index >= $this->getSize() and $index < $this->size){ //Armor change if($index >= $this->getSize() and $index < $this->size){ //Armor change
Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $old, $item, $index)); Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->sendArmorContents($this->getViewers()); $this->sendArmorContents($this->getViewers());
$this->sendContents($this->getViewers()); $this->sendContents($this->getViewers());
@ -286,7 +286,7 @@ class PlayerInventory extends BaseInventory{
} }
} }
$pk = PlayerArmorEquipmentPacket::getFromPool(); $pk = new PlayerArmorEquipmentPacket();
$pk->eid = $this->getHolder()->getID(); $pk->eid = $this->getHolder()->getID();
$pk->slots = $slots; $pk->slots = $slots;
$pk->encode(); $pk->encode();
@ -298,7 +298,7 @@ class PlayerInventory extends BaseInventory{
//$pk2 = clone $pk; //$pk2 = clone $pk;
//$pk2->eid = 0; //$pk2->eid = 0;
$pk2 = ContainerSetContentPacket::getFromPool(); $pk2 = new ContainerSetContentPacket();
$pk2->windowid = 0x78; //Armor window id constant $pk2->windowid = 0x78; //Armor window id constant
$pk2->slots = $armor; $pk2->slots = $armor;
$player->dataPacket($pk2); $player->dataPacket($pk2);
@ -333,7 +333,7 @@ class PlayerInventory extends BaseInventory{
$target = [$target]; $target = [$target];
} }
$pk = ContainerSetContentPacket::getFromPool(); $pk = new ContainerSetContentPacket();
$pk->slots = []; $pk->slots = [];
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
$pk->slots[$i] = $this->getItem($i); $pk->slots[$i] = $this->getItem($i);
@ -365,7 +365,7 @@ class PlayerInventory extends BaseInventory{
$target = [$target]; $target = [$target];
} }
$pk = ContainerSetSlotPacket::getFromPool(); $pk = new ContainerSetSlotPacket();
$pk->slot = $index; $pk->slot = $index;
$pk->item = clone $this->getItem($index); $pk->item = clone $this->getItem($index);

View File

@ -138,7 +138,7 @@ class SimpleTransactionGroup implements TransactionGroup{
return false; return false;
} }
Server::getInstance()->getPluginManager()->callEvent($ev = InventoryTransactionEvent::createEvent($this)); Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this));
if($ev->isCancelled()){ if($ev->isCancelled()){
foreach($this->inventories as $inventory){ foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers()); $inventory->sendContents($inventory->getViewers());

View File

@ -42,7 +42,7 @@ class Bucket extends Item{
if($target instanceof Liquid and $target->getDamage() === 0){ if($target instanceof Liquid and $target->getDamage() === 0){
$result = clone $this; $result = clone $this;
$result->setDamage($target->getID()); $result->setDamage($target->getID());
$player->getServer()->getPluginManager()->callEvent($ev = PlayerBucketFillEvent::createEvent($player, $block, $face, $this, $result)); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->getLevel()->setBlock($target, new Air(), true, true); $player->getLevel()->setBlock($target, new Air(), true, true);
if($player->isSurvival()){ if($player->isSurvival()){
@ -56,7 +56,7 @@ class Bucket extends Item{
}elseif($targetBlock instanceof Liquid){ }elseif($targetBlock instanceof Liquid){
$result = clone $this; $result = clone $this;
$result->setDamage(0); $result->setDamage(0);
$player->getServer()->getPluginManager()->callEvent($ev = PlayerBucketFillEvent::createEvent($player, $block, $face, $this, $result)); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->getLevel()->setBlock($block, $targetBlock, true, true); $player->getLevel()->setBlock($block, $targetBlock, true, true);
if($player->isSurvival()){ if($player->isSurvival()){

View File

@ -83,9 +83,9 @@ class Explosion{
return false; return false;
} }
$pointer = Vector3::createVector(0, 0, 0); $pointer = new Vector3(0, 0, 0);
$vector = Vector3::createVector(0, 0, 0); $vector = new Vector3(0, 0, 0);
$vBlock = Vector3::createVector(0, 0, 0); $vBlock = new Vector3(0, 0, 0);
$mRays = $this->rays - 1; $mRays = $this->rays - 1;
for($i = 0; $i < $this->rays; ++$i){ for($i = 0; $i < $this->rays; ++$i){
@ -130,12 +130,11 @@ class Explosion{
public function explodeB(){ public function explodeB(){
$send = []; $send = [];
$source = Vector3::cloneVector($this->source); $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
$source = $source->floor();
$yield = (1 / $this->size) * 100; $yield = (1 / $this->size) * 100;
if($this->what instanceof Entity){ if($this->what instanceof Entity){
$this->level->getServer()->getPluginManager()->callEvent($ev = EntityExplodeEvent::createEvent($this->what, $this->source, $this->affectedBlocks, $yield)); $this->level->getServer()->getPluginManager()->callEvent($ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
}else{ }else{
@ -152,7 +151,7 @@ class Explosion{
$minZ = Math::floorFloat($this->source->z - $explosionSize - 1); $minZ = Math::floorFloat($this->source->z - $explosionSize - 1);
$maxZ = Math::floorFloat($this->source->z + $explosionSize + 1); $maxZ = Math::floorFloat($this->source->z + $explosionSize + 1);
$explosionBB = AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
$list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null); $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null);
foreach($list as $entity){ foreach($list as $entity){
@ -166,11 +165,11 @@ class Explosion{
$damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1); $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1);
if($this->what instanceof Entity){ if($this->what instanceof Entity){
$ev = EntityDamageByEntityEvent::createEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage); $ev = new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
}elseif($this->what instanceof Block){ }elseif($this->what instanceof Block){
$ev = EntityDamageByBlockEvent::createEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); $ev = new EntityDamageByBlockEvent($this->what, $entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
}else{ }else{
$ev = EntityDamageEvent::createEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
} }
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev->getFinalDamage(), $ev);
@ -212,7 +211,7 @@ class Explosion{
$this->level->setBlockIdAt($block->x, $block->y, $block->z, 0); $this->level->setBlockIdAt($block->x, $block->y, $block->z, 0);
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
} }
$pk = ExplodePacket::getFromPool(); $pk = new ExplodePacket();
$pk->x = $this->source->x; $pk->x = $this->source->x;
$pk->y = $this->source->y; $pk->y = $this->source->y;
$pk->z = $this->source->z; $pk->z = $this->source->z;

View File

@ -352,7 +352,7 @@ class Level implements ChunkManager, Metadatable{
*/ */
public function unload($force = false){ public function unload($force = false){
$ev = LevelUnloadEvent::createEvent($this); $ev = new LevelUnloadEvent($this);
if($this === $this->server->getDefaultLevel() and $force !== true){ if($this === $this->server->getDefaultLevel() and $force !== true){
$ev->setCancelled(true); $ev->setCancelled(true);
@ -439,7 +439,7 @@ class Level implements ChunkManager, Metadatable{
* Changes to this function won't be recorded on the version. * Changes to this function won't be recorded on the version.
*/ */
public function sendTime(){ public function sendTime(){
$pk = SetTimePacket::getFromPool(); $pk = new SetTimePacket();
$pk->time = (int) $this->time; $pk->time = (int) $this->time;
$pk->started = $this->stopTime == false; $pk->started = $this->stopTime == false;
@ -532,7 +532,7 @@ class Level implements ChunkManager, Metadatable{
foreach($mini as $blocks){ foreach($mini as $blocks){
/** @var Block $b */ /** @var Block $b */
foreach($blocks as $b){ foreach($blocks as $b){
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $b->x; $pk->x = $b->x;
$pk->y = $b->y; $pk->y = $b->y;
$pk->z = $b->z; $pk->z = $b->z;
@ -672,7 +672,7 @@ class Level implements ChunkManager, Metadatable{
return false; return false;
} }
$this->server->getPluginManager()->callEvent(LevelSaveEvent::createEvent($this)); $this->server->getPluginManager()->callEvent(new LevelSaveEvent($this));
$this->provider->setTime((int) $this->time); $this->provider->setTime((int) $this->time);
$this->saveChunks(); $this->saveChunks();
@ -704,7 +704,7 @@ class Level implements ChunkManager, Metadatable{
} }
for($side = 0; $side <= 5; ++$side){ for($side = 0; $side <= 5; ++$side){
$this->server->getPluginManager()->callEvent($ev = BlockUpdateEvent::createEvent($block->getSide($side))); $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block->getSide($side)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
} }
@ -801,7 +801,7 @@ class Level implements ChunkManager, Metadatable{
if($entities){ if($entities){
foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){ foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){
$collides[] = AxisAlignedBB::cloneBoundingBoxFromPool($ent->boundingBox); $collides[] = clone $ent->boundingBox;
} }
} }
@ -946,7 +946,7 @@ class Level implements ChunkManager, Metadatable{
} }
//if($direct === true){ //if($direct === true){
$pk = UpdateBlockPacket::getFromPool(); $pk = new UpdateBlockPacket();
$pk->x = $pos->x; $pk->x = $pos->x;
$pk->y = $pos->y; $pk->y = $pos->y;
$pk->z = $pos->z; $pk->z = $pos->z;
@ -973,10 +973,10 @@ class Level implements ChunkManager, Metadatable{
if($update === true){ if($update === true){
$this->updateAround($pos); $this->updateAround($pos);
$this->server->getPluginManager()->callEvent($ev = BlockUpdateEvent::createEvent($block)); $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
foreach($this->getNearbyEntities(AxisAlignedBB::getBoundingBoxFromPool($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){
$entity->scheduleUpdate(); $entity->scheduleUpdate();
} }
} }
@ -991,7 +991,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $delay * @param int $delay
*/ */
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){
$motion = $motion === null ? Vector3::createVector(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
if($item->getID() > 0 and $item->getCount() > 0){ if($item->getID() > 0 and $item->getCount() > 0){
$itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [ $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [
"Pos" => new Enum("Pos", [ "Pos" => new Enum("Pos", [
@ -1041,7 +1041,7 @@ class Level implements ChunkManager, Metadatable{
} }
if($player instanceof Player){ if($player instanceof Player){
$ev = BlockBreakEvent::createEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false); $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false);
$lastTime = $player->lastBreak - 0.1; //TODO: replace with true lag $lastTime = $player->lastBreak - 0.1; //TODO: replace with true lag
if(($player->getGamemode() & 0x01) > 0){ if(($player->getGamemode() & 0x01) > 0){
@ -1074,7 +1074,7 @@ class Level implements ChunkManager, Metadatable{
$level = $target->getLevel(); $level = $target->getLevel();
if($level instanceof Level){ if($level instanceof Level){
$above = $level->getBlock(Vector3::createVector($target->x, $target->y + 1, $target->z)); $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
if($above instanceof Block){ if($above instanceof Block){
if($above->getID() === Item::FIRE){ if($above->getID() === Item::FIRE){
$level->setBlock($above, new Air(), true); $level->setBlock($above, new Air(), true);
@ -1142,7 +1142,7 @@ class Level implements ChunkManager, Metadatable{
} }
if($player instanceof Player){ if($player instanceof Player){
$ev = PlayerInteractEvent::createEvent($player, $item, $target, $face); $ev = new PlayerInteractEvent($player, $item, $target, $face);
if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){ if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){
$t = new Vector2($target->x, $target->z); $t = new Vector2($target->x, $target->z);
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
@ -1207,7 +1207,7 @@ class Level implements ChunkManager, Metadatable{
if($player instanceof Player){ if($player instanceof Player){
$ev = BlockPlaceEvent::createEvent($player, $hand, $block, $target, $item); $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item);
if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){ if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){
$t = new Vector2($target->x, $target->z); $t = new Vector2($target->x, $target->z);
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
@ -1582,7 +1582,7 @@ class Level implements ChunkManager, Metadatable{
$this->setChunk($x, $z, $chunk); $this->setChunk($x, $z, $chunk);
$chunk = $this->getChunk($x, $z); $chunk = $this->getChunk($x, $z);
if($chunk instanceof FullChunk and (!($oldChunk instanceof FullChunk) or $oldChunk->isPopulated() === false) and $chunk->isPopulated()){ if($chunk instanceof FullChunk and (!($oldChunk instanceof FullChunk) or $oldChunk->isPopulated() === false) and $chunk->isPopulated()){
$this->server->getPluginManager()->callEvent(ChunkPopulateEvent::createEvent($chunk)); $this->server->getPluginManager()->callEvent(new ChunkPopulateEvent($chunk));
} }
} }
@ -1669,7 +1669,7 @@ class Level implements ChunkManager, Metadatable{
public function setSpawnLocation(Vector3 $pos){ public function setSpawnLocation(Vector3 $pos){
$previousSpawn = $this->getSpawnLocation(); $previousSpawn = $this->getSpawnLocation();
$this->provider->setSpawn($pos); $this->provider->setSpawn($pos);
$this->server->getPluginManager()->callEvent(SpawnChangeEvent::createEvent($this, $previousSpawn)); $this->server->getPluginManager()->callEvent(new SpawnChangeEvent($this, $previousSpawn));
} }
public function requestChunk($x, $z, Player $player, $order = LevelProvider::ORDER_ZXY){ public function requestChunk($x, $z, Player $player, $order = LevelProvider::ORDER_ZXY){
@ -1695,7 +1695,7 @@ class Level implements ChunkManager, Metadatable{
if(ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getID() . ":" . $index)) !== false){ if(ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getID() . ":" . $index)) !== false){
/** @var Player[] $players */ /** @var Player[] $players */
foreach($players as $player){ foreach($players as $player){
if(isset($player->usedChunks[$index])){ if($player->isConnected() and isset($player->usedChunks[$index])){
$player->sendChunk($x, $z, $cache); $player->sendChunk($x, $z, $cache);
} }
} }
@ -1838,7 +1838,7 @@ class Level implements ChunkManager, Metadatable{
} }
} }
$this->server->getPluginManager()->callEvent(ChunkLoadEvent::createEvent($chunk, !$chunk->isGenerated())); $this->server->getPluginManager()->callEvent(new ChunkLoadEvent($chunk, !$chunk->isGenerated()));
return true; return true;
} }
@ -1873,7 +1873,7 @@ class Level implements ChunkManager, Metadatable{
$chunk = $this->getChunk($x, $z); $chunk = $this->getChunk($x, $z);
if($chunk instanceof FullChunk){ if($chunk instanceof FullChunk){
$this->server->getPluginManager()->callEvent($ev = ChunkUnloadEvent::createEvent($chunk)); $this->server->getPluginManager()->callEvent($ev = new ChunkUnloadEvent($chunk));
if($ev->isCancelled()){ if($ev->isCancelled()){
return false; return false;
} }
@ -1932,7 +1932,7 @@ class Level implements ChunkManager, Metadatable{
$x = Math::floorFloat($spawn->x); $x = Math::floorFloat($spawn->x);
$y = Math::floorFloat($spawn->y); $y = Math::floorFloat($spawn->y);
$z = Math::floorFloat($spawn->z); $z = Math::floorFloat($spawn->z);
$v = Vector3::createVector($x, $y, $z); $v = new Vector3($x, $y, $z);
for(; $v->y > 0; --$v->y){ for(; $v->y > 0; --$v->y){
$b = $this->getBlock($v->getSide(0)); $b = $this->getBlock($v->getSide(0));
if($b === null){ if($b === null){
@ -1944,14 +1944,14 @@ class Level implements ChunkManager, Metadatable{
for(; $v->y < 128; ++$v->y){ for(; $v->y < 128; ++$v->y){
if($this->getBlock($v->getSide(1)) instanceof Air){ if($this->getBlock($v->getSide(1)) instanceof Air){
if($this->getBlock($v) instanceof Air){ if($this->getBlock($v) instanceof Air){
return Position::createPosition($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this); return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this);
} }
}else{ }else{
++$v->y; ++$v->y;
} }
} }
return Position::createPosition($spawn->x, $v->y, $spawn->z, $this); return new Position($spawn->x, $v->y, $spawn->z, $this);
} }
return false; return false;

View File

@ -64,7 +64,7 @@ class MovingObjectPosition{
$ob->blockX = $x; $ob->blockX = $x;
$ob->blockY = $y; $ob->blockY = $y;
$ob->blockZ = $z; $ob->blockZ = $z;
$ob->hitVector = Vector3::createVector($hitVector->x, $hitVector->y, $hitVector->z); $ob->hitVector = new Vector3($hitVector->x, $hitVector->y, $hitVector->z);
return $ob; return $ob;
} }
@ -77,7 +77,7 @@ class MovingObjectPosition{
$ob = new MovingObjectPosition; $ob = new MovingObjectPosition;
$ob->typeOfHit = 1; $ob->typeOfHit = 1;
$ob->entityHit = $entity; $ob->entityHit = $entity;
$ob->hitVector = Vector3::createVector($entity->x, $entity->y, $entity->z); $ob->hitVector = new Vector3($entity->x, $entity->y, $entity->z);
return $ob; return $ob;
} }
} }

View File

@ -25,51 +25,10 @@ use pocketmine\math\Vector3;
use pocketmine\utils\LevelException; use pocketmine\utils\LevelException;
class Position extends Vector3{ class Position extends Vector3{
/** @var Position[] */
private static $positionList = [];
private static $nextPosition = 0;
/** @var Level */ /** @var Level */
public $level = null; public $level = null;
public static function clearPositions(){
self::$nextPosition = 0;
self::$positionList = [];
}
public static function clearPositionList(){
if(self::$nextPosition > 65536){
self::clearVectors();
}else{
self::$nextPosition = 0;
}
}
/**
* @param $x
* @param $y
* @param $z
* @param Level $level
*
* @return Position
*/
public static function createPosition($x, $y, $z, Level $level){
if(self::$nextPosition >= count(self::$positionList)){
self::$positionList[] = new Position(0, 0, 0, null);
}
return self::$positionList[self::$nextPosition++]->setLevel($level)->setComponents($x, $y, $z);
}
public static function clonePosition(Position $pos){
if(self::$nextPosition >= count(self::$positionList)){
self::$positionList[] = new Position(0, 0, 0, null);
}
return self::$positionList[self::$nextPosition++]->setLevel($pos->level)->setComponents($pos->x, $pos->y, $pos->z);
}
/** /**
* @param int $x * @param int $x
* @param int $y * @param int $y
@ -84,7 +43,7 @@ class Position extends Vector3{
} }
public static function fromObject(Vector3 $pos, Level $level = null){ public static function fromObject(Vector3 $pos, Level $level = null){
return self::createPosition($pos->x, $pos->y, $pos->z, $level); return new Position($pos->x, $pos->y, $pos->z, $level);
} }
/** /**

View File

@ -24,11 +24,6 @@ use pocketmine\level\MovingObjectPosition;
class AxisAlignedBB{ class AxisAlignedBB{
/** @var AxisAlignedBB[] */
public static $boundingBoxes = [];
public static $nextBoundingBox = 0;
public $minX; public $minX;
public $minY; public $minY;
public $minZ; public $minZ;
@ -45,50 +40,6 @@ class AxisAlignedBB{
$this->maxZ = $maxZ; $this->maxZ = $maxZ;
} }
public static function clearBoundingBoxes(){
self::$nextBoundingBox = 0;
self::$boundingBoxes = [];
}
public static function clearBoundingBoxPool(){
if(self::$nextBoundingBox > 65536){
self::clearBoundingBoxes();
}else{
self::$nextBoundingBox = 0;
}
}
/**
* @param $minX
* @param $minY
* @param $minZ
* @param $maxX
* @param $maxY
* @param $maxZ
*
* @return AxisAlignedBB
*/
public static function getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ){
if(self::$nextBoundingBox >= count(self::$boundingBoxes)){
self::$boundingBoxes[] = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
}
return self::$boundingBoxes[self::$nextBoundingBox++]->setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
}
/**
* @param AxisAlignedBB $bb
*
* @return AxisAlignedBB
*/
public static function cloneBoundingBoxFromPool(AxisAlignedBB $bb){
if(self::$nextBoundingBox >= count(self::$boundingBoxes)){
self::$boundingBoxes[] = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
}
return self::$boundingBoxes[self::$nextBoundingBox++]->setBounds($bb->minX, $bb->minY, $bb->minZ, $bb->maxX, $bb->maxY, $bb->maxZ);
}
public function setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ public function setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){
$this->minX = $minX; $this->minX = $minX;
$this->minY = $minY; $this->minY = $minY;
@ -126,11 +77,11 @@ class AxisAlignedBB{
$maxZ += $z; $maxZ += $z;
} }
return AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); return new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
} }
public function grow($x, $y, $z){ public function grow($x, $y, $z){
return AxisAlignedBB::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); return new AxisAlignedBB($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
} }
public function expand($x, $y, $z){ public function expand($x, $y, $z){
@ -156,7 +107,7 @@ class AxisAlignedBB{
} }
public function shrink($x, $y, $z){ public function shrink($x, $y, $z){
return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); return new AxisAlignedBB($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z);
} }
public function contract($x, $y, $z){ public function contract($x, $y, $z){
@ -181,7 +132,7 @@ class AxisAlignedBB{
} }
public function getOffsetBoundingBox($x, $y, $z){ public function getOffsetBoundingBox($x, $y, $z){
return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); return new AxisAlignedBB($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
} }
public function calculateXOffset(AxisAlignedBB $bb, $x){ public function calculateXOffset(AxisAlignedBB $bb, $x){

View File

@ -23,10 +23,6 @@ namespace pocketmine\math;
class Vector3{ class Vector3{
/** @var Vector3[] */
public static $vectorList = [];
public static $nextVector = 0;
const SIDE_DOWN = 0; const SIDE_DOWN = 0;
const SIDE_UP = 1; const SIDE_UP = 1;
const SIDE_NORTH = 2; const SIDE_NORTH = 2;
@ -44,47 +40,6 @@ class Vector3{
$this->z = $z; $this->z = $z;
} }
public static function clearVectors(){
Vector3::$nextVector = 0;
Vector3::$vectorList = [];
}
public static function clearVectorList(){
if(Vector3::$nextVector > 65536){
Vector3::clearVectors();
}else{
Vector3::$nextVector = 0;
}
}
/**
* @param $x
* @param $y
* @param $z
*
* @return Vector3
*/
public static function createVector($x, $y, $z){
if(Vector3::$nextVector >= count(Vector3::$vectorList)){
Vector3::$vectorList[] = new Vector3(0, 0, 0);
}
return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($x, $y, $z);
}
/**
* @param Vector3 $vector
*
* @return Vector3
*/
public static function cloneVector(Vector3 $vector){
if(Vector3::$nextVector >= count(Vector3::$vectorList)){
Vector3::$vectorList[] = new Vector3(0, 0, 0);
}
return Vector3::$vectorList[Vector3::$nextVector++]->setComponents($vector->x, $vector->y, $vector->z);
}
public function getX(){ public function getX(){
return $this->x; return $this->x;
} }
@ -138,9 +93,9 @@ class Vector3{
*/ */
public function add($x, $y = 0, $z = 0){ public function add($x, $y = 0, $z = 0){
if($x instanceof Vector3){ if($x instanceof Vector3){
return Vector3::createVector($this->x + $x->x, $this->y + $x->y, $this->z + $x->z); return new Vector3($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
}else{ }else{
return Vector3::createVector($this->x + $x, $this->y + $y, $this->z + $z); return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
} }
} }
@ -160,46 +115,46 @@ class Vector3{
} }
public function multiply($number){ public function multiply($number){
return Vector3::createVector($this->x * $number, $this->y * $number, $this->z * $number); return new Vector3($this->x * $number, $this->y * $number, $this->z * $number);
} }
public function divide($number){ public function divide($number){
return Vector3::createVector($this->x / $number, $this->y / $number, $this->z / $number); return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
} }
public function ceil(){ public function ceil(){
return Vector3::createVector((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
} }
public function floor(){ public function floor(){
$x = (int) $this->x; $x = (int) $this->x;
$y = (int) $this->y; $y = (int) $this->y;
$z = (int) $this->z; $z = (int) $this->z;
return Vector3::createVector($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1); return new Vector3($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1);
} }
public function round(){ public function round(){
return Vector3::createVector(round($this->x), round($this->y), round($this->z)); return new Vector3(round($this->x), round($this->y), round($this->z));
} }
public function abs(){ public function abs(){
return Vector3::createVector(abs($this->x), abs($this->y), abs($this->z)); return new Vector3(abs($this->x), abs($this->y), abs($this->z));
} }
public function getSide($side, $step = 1){ public function getSide($side, $step = 1){
switch((int) $side){ switch((int) $side){
case Vector3::SIDE_DOWN: case Vector3::SIDE_DOWN:
return Vector3::createVector($this->x, $this->y - $step, $this->z); return new Vector3($this->x, $this->y - $step, $this->z);
case Vector3::SIDE_UP: case Vector3::SIDE_UP:
return Vector3::createVector($this->x, $this->y + $step, $this->z); return new Vector3($this->x, $this->y + $step, $this->z);
case Vector3::SIDE_NORTH: case Vector3::SIDE_NORTH:
return Vector3::createVector($this->x, $this->y, $this->z - $step); return new Vector3($this->x, $this->y, $this->z - $step);
case Vector3::SIDE_SOUTH: case Vector3::SIDE_SOUTH:
return Vector3::createVector($this->x, $this->y, $this->z + $step); return new Vector3($this->x, $this->y, $this->z + $step);
case Vector3::SIDE_WEST: case Vector3::SIDE_WEST:
return Vector3::createVector($this->x - $step, $this->y, $this->z); return new Vector3($this->x - $step, $this->y, $this->z);
case Vector3::SIDE_EAST: case Vector3::SIDE_EAST:
return Vector3::createVector($this->x + $step, $this->y, $this->z); return new Vector3($this->x + $step, $this->y, $this->z);
default: default:
return $this; return $this;
} }
@ -259,7 +214,7 @@ class Vector3{
return $this->divide($len); return $this->divide($len);
} }
return Vector3::createVector(0, 0, 0); return new Vector3(0, 0, 0);
} }
public function dot(Vector3 $v){ public function dot(Vector3 $v){
@ -267,7 +222,7 @@ class Vector3{
} }
public function cross(Vector3 $v){ public function cross(Vector3 $v){
return Vector3::createVector( return new Vector3(
$this->y * $v->z - $this->z * $v->y, $this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z, $this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x $this->x * $v->y - $this->y * $v->x
@ -297,7 +252,7 @@ class Vector3{
if($f < 0 or $f > 1){ if($f < 0 or $f > 1){
return null; return null;
}else{ }else{
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
} }
} }
@ -324,7 +279,7 @@ class Vector3{
if($f < 0 or $f > 1){ if($f < 0 or $f > 1){
return null; return null;
}else{ }else{
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
} }
} }
@ -351,7 +306,7 @@ class Vector3{
if($f < 0 or $f > 1){ if($f < 0 or $f > 1){
return null; return null;
}else{ }else{
return Vector3::createVector($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
} }
} }

View File

@ -121,8 +121,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
} }
public function doTick(){ public function doTick(){
$this->cleanPacketPool();
EncapsulatedPacket::cleanPacketPool();
$this->interface->sendTick(); $this->interface->sendTick();
} }
@ -236,7 +234,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
$pk = null; $pk = null;
if(!$packet->isEncoded){ if(!$packet->isEncoded){
$packet->encode(); $packet->encode();
unset($packet->__encapsulatedPacket);
}elseif(!$needACK){ }elseif(!$needACK){
if(!isset($packet->__encapsulatedPacket)){ if(!isset($packet->__encapsulatedPacket)){
$packet->__encapsulatedPacket = new CachedEncapsulatedPacket; $packet->__encapsulatedPacket = new CachedEncapsulatedPacket;
@ -248,13 +245,11 @@ class RakLibInterface implements ServerInstance, SourceInterface{
} }
if($pk === null){ if($pk === null){
$pk = EncapsulatedPacket::getPacketFromPool(); $pk = new EncapsulatedPacket();
$pk->buffer = $packet->buffer; $pk->buffer = $packet->buffer;
$pk->reliability = 2; $pk->reliability = 2;
if($needACK === true){ if($needACK === true){
$pk->identifierACK = $this->identifiersACK[$identifier]++; $pk->identifierACK = $this->identifiersACK[$identifier]++;
}else{
$pk->identifierACK = null;
} }
} }
@ -279,19 +274,12 @@ class RakLibInterface implements ServerInstance, SourceInterface{
if(isset($this->packetPool[$id])){ if(isset($this->packetPool[$id])){
/** @var DataPacket $class */ /** @var DataPacket $class */
$class = $this->packetPool[$id]; $class = $this->packetPool[$id];
return $class::getFromPool(); return new $class;
} }
return null; return null;
} }
public function cleanPacketPool(){
foreach($this->packetPool as $class){
/** @var DataPacket $class */
$class::cleanPool();
}
}
private function registerPackets(){ private function registerPackets(){
$this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class);
$this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class);
@ -344,7 +332,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
$pid = ord($buffer{0}); $pid = ord($buffer{0});
if(($data = $this->getPacketFromPool($pid)) === null){ if(($data = $this->getPacketFromPool($pid)) === null){
$data = UnknownPacket::getFromPool(); $data = new UnknownPacket();
$data->packetID = $pid; $data->packetID = $pid;
} }
$data->setBuffer(substr($buffer, 1)); $data->setBuffer(substr($buffer, 1));

View File

@ -27,69 +27,11 @@ namespace pocketmine\network\protocol;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
#endif #endif
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\Player;
abstract class DataPacket extends \stdClass{ abstract class DataPacket extends \stdClass{
/** @var DataPacket[] */
public static $pool = [];
public static $next = 0;
/** @var DataPacketSendEvent */
private $sendEvent = null;
/** @var DataPacketReceiveEvent */
private $receiveEvent = null;
public static function getFromPool(){
if(static::$next >= count(static::$pool)){
static::$pool[] = new static;
}
return static::$pool[static::$next++]->clean();
}
public static function cleanPool(){
if(static::$next > 16384){
static::$pool = [];
}
static::$next = 0;
}
/**
* @param Player $player
*
* @return DataPacketReceiveEvent
*/
public function getReceiveEvent(Player $player){
if($this->receiveEvent === null){
$this->receiveEvent = new DataPacketReceiveEvent($player, $this);
}else{
$this->receiveEvent->setCancelled(false);
$this->receiveEvent->__construct($player, $this);
}
return $this->receiveEvent;
}
/**
* @param Player $player
*
* @return DataPacketSendEvent
*/
public function getSendEvent(Player $player){
if($this->sendEvent === null){
$this->sendEvent = new DataPacketSendEvent($player, $this);
}else{
$this->sendEvent->setCancelled(false);
$this->sendEvent->__construct($player, $this);
}
return $this->sendEvent;
}
private $offset = 0; private $offset = 0;
public $buffer = ""; public $buffer = "";
public $isEncoded = false; public $isEncoded = false;

View File

@ -58,7 +58,7 @@ class QueryHandler{
} }
public function regenerateInfo(){ public function regenerateInfo(){
$this->server->getPluginManager()->callEvent($ev = QueryRegenerateEvent::createEvent($this->server, 5)); $this->server->getPluginManager()->callEvent($ev = new QueryRegenerateEvent($this->server, 5));
$this->longData = $ev->getLongQuery(); $this->longData = $ev->getLongQuery();
$this->shortData = $ev->getShortQuery(); $this->shortData = $ev->getShortQuery();
$this->timeout = microtime(true) + $ev->getTimeout(); $this->timeout = microtime(true) + $ev->getTimeout();

View File

@ -94,7 +94,7 @@ class RCON{
$response = new RemoteConsoleCommandSender(); $response = new RemoteConsoleCommandSender();
$command = $this->workers[$n]->cmd; $command = $this->workers[$n]->cmd;
$this->server->getPluginManager()->callEvent($ev = RemoteServerCommandEvent::createEvent($response, $command)); $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand()); $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());

View File

@ -122,7 +122,7 @@ class PharPluginLoader implements PluginLoader{
$plugin->setEnabled(true); $plugin->setEnabled(true);
$this->server->getPluginManager()->callEvent(PluginEnableEvent::createEvent($plugin)); $this->server->getPluginManager()->callEvent(new PluginEnableEvent($plugin));
} }
} }
@ -133,7 +133,7 @@ class PharPluginLoader implements PluginLoader{
if($plugin instanceof PluginBase and $plugin->isEnabled()){ if($plugin instanceof PluginBase and $plugin->isEnabled()){
$this->server->getLogger()->info("Disabling " . $plugin->getDescription()->getFullName()); $this->server->getLogger()->info("Disabling " . $plugin->getDescription()->getFullName());
$this->server->getPluginManager()->callEvent(PluginDisableEvent::createEvent($plugin)); $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin));
$plugin->setEnabled(false); $plugin->setEnabled(false);
} }

View File

@ -197,7 +197,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{
*/ */
public function getPair(){ public function getPair(){
if($this->isPaired()){ if($this->isPaired()){
$tile = $this->getLevel()->getTile(Vector3::createVector((int) $this->namedtag["pairx"], $this->y, (int) $this->namedtag["pairz"])); $tile = $this->getLevel()->getTile(new Vector3((int) $this->namedtag["pairx"], $this->y, (int) $this->namedtag["pairz"]));
if($tile instanceof Chest){ if($tile instanceof Chest){
return $tile; return $tile;
} }

View File

@ -169,7 +169,7 @@ class Furnace extends Tile implements InventoryHolder, Container{
} }
protected function checkFuel(Item $fuel){ protected function checkFuel(Item $fuel){
$this->server->getPluginManager()->callEvent($ev = FurnaceBurnEvent::createEvent($this, $fuel, $fuel->getFuelTime())); $this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime()));
if($ev->isCancelled()){ if($ev->isCancelled()){
return; return;
@ -219,7 +219,7 @@ class Furnace extends Tile implements InventoryHolder, Container{
if($this->namedtag["CookTime"] >= 200){ //10 seconds if($this->namedtag["CookTime"] >= 200){ //10 seconds
$product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1); $product = Item::get($smelt->getResult()->getID(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
$this->server->getPluginManager()->callEvent($ev = FurnaceSmeltEvent::createEvent($this, $raw, $product)); $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->inventory->setResult($ev->getResult()); $this->inventory->setResult($ev->getResult());
@ -252,13 +252,13 @@ class Furnace extends Tile implements InventoryHolder, Container{
foreach($this->getInventory()->getViewers() as $player){ foreach($this->getInventory()->getViewers() as $player){
$windowId = $player->getWindowId($this->getInventory()); $windowId = $player->getWindowId($this->getInventory());
if($windowId > 0){ if($windowId > 0){
$pk = ContainerSetDataPacket::getFromPool(); $pk = new ContainerSetDataPacket();
$pk->windowid = $windowId; $pk->windowid = $windowId;
$pk->property = 0; //Smelting $pk->property = 0; //Smelting
$pk->value = floor($this->namedtag["CookTime"]); $pk->value = floor($this->namedtag["CookTime"]);
$player->dataPacket($pk); $player->dataPacket($pk);
$pk = ContainerSetDataPacket::getFromPool(); $pk = new ContainerSetDataPacket();
$pk->windowid = $windowId; $pk->windowid = $windowId;
$pk->property = 1; //Fire icon $pk->property = 1; //Fire icon
$pk->value = $this->namedtag["BurnTicks"]; $pk->value = $this->namedtag["BurnTicks"];

View File

@ -36,7 +36,7 @@ abstract class Spawnable extends Tile{
$nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($this->getSpawnCompound()); $nbt->setData($this->getSpawnCompound());
$pk = EntityDataPacket::getFromPool(); $pk = new EntityDataPacket();
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;

View File

@ -58,7 +58,7 @@ class BlockIterator implements \Iterator{
$this->level = $level; $this->level = $level;
$this->maxDistance = (int) $maxDistance; $this->maxDistance = (int) $maxDistance;
$startClone = Vector3::createVector($start->x, $start->y, $start->z); $startClone = new Vector3($start->x, $start->y, $start->z);
$startClone->y += $yOffset; $startClone->y += $yOffset;
$this->currentDistance = 0; $this->currentDistance = 0;
@ -71,7 +71,7 @@ class BlockIterator implements \Iterator{
$secondPosition = 0; $secondPosition = 0;
$thirdPosition = 0; $thirdPosition = 0;
$pos = Vector3::createVector($startClone->x, $startClone->y, $startClone->z); $pos = new Vector3($startClone->x, $startClone->y, $startClone->z);
$startBlock = $this->level->getBlock($pos->floor()); $startBlock = $this->level->getBlock($pos->floor());
if($this->getXLength($direction) > $mainDirection){ if($this->getXLength($direction) > $mainDirection){

@ -1 +1 @@
Subproject commit cb3c3efd9cc8b04b686788a3a3450731f9ff97e4 Subproject commit a4d9a8a1f6b7eddfb21fa8512d431c22846b7fd2