Resolved 1️⃣ in #3961

This commit is contained in:
PEMapModder 2016-02-19 18:33:21 +08:00
parent 05530bedc6
commit 80250aa78e
2 changed files with 69 additions and 79 deletions

View File

@ -21,6 +21,7 @@
namespace pocketmine; namespace pocketmine;
use pocketmine\block\Air;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\entity\Arrow; use pocketmine\entity\Arrow;
@ -76,11 +77,9 @@ use pocketmine\inventory\PlayerInventory;
use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\ShapelessRecipe;
use pocketmine\inventory\SimpleTransactionGroup; use pocketmine\inventory\SimpleTransactionGroup;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\ChunkLoader; use pocketmine\level\ChunkLoader;
use pocketmine\level\format\FullChunk; use pocketmine\level\format\FullChunk;
use pocketmine\level\format\LevelProvider;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\Location; use pocketmine\level\Location;
use pocketmine\level\Position; use pocketmine\level\Position;
@ -93,13 +92,12 @@ use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\LongTag; use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\network\Network;
use pocketmine\network\protocol\AdventureSettingsPacket; use pocketmine\network\protocol\AdventureSettingsPacket;
use pocketmine\network\protocol\AnimatePacket; use pocketmine\network\protocol\AnimatePacket;
use pocketmine\network\protocol\BatchPacket; use pocketmine\network\protocol\BatchPacket;
@ -110,20 +108,19 @@ use pocketmine\network\protocol\DisconnectPacket;
use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\FullChunkDataPacket;
use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\PlayerActionPacket; use pocketmine\network\protocol\PlayerActionPacket;
use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\PlayStatusPacket;
use pocketmine\network\protocol\RespawnPacket; use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\SetPlayerGameTypePacket;
use pocketmine\network\protocol\TextPacket;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetHealthPacket;
use pocketmine\network\protocol\SetPlayerGameTypePacket;
use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\SetTimePacket;
use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\StartGamePacket;
use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TakeItemEntityPacket;
use pocketmine\network\protocol\TextPacket;
use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\network\SourceInterface; use pocketmine\network\SourceInterface;
use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissibleBase;
@ -133,10 +130,9 @@ use pocketmine\tile\Sign;
use pocketmine\tile\Spawnable; use pocketmine\tile\Spawnable;
use pocketmine\tile\Tile; use pocketmine\tile\Tile;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use raklib\Binary; use raklib\Binary;
/** /**
* Main class that handles networking, recovery, and packet sending to the server part * Main class that handles networking, recovery, and packet sending to the server part
*/ */
@ -221,7 +217,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
protected $viewDistance; protected $viewDistance;
protected $chunksPerTick; protected $chunksPerTick;
protected $spawnThreshold; protected $spawnThreshold;
/** @var null|Position */ /** @var null|Position */
private $spawnPosition = null; private $spawnPosition = null;
@ -505,7 +501,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->clientID = $clientID; $this->clientID = $clientID;
$this->loaderId = Level::generateChunkLoaderId($this); $this->loaderId = Level::generateChunkLoaderId($this);
$this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4); $this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4);
$this->spawnThreshold = (int) $this->server->getProperty("chunk-sending.spawn-threshold", 56); $this->spawnThreshold = (int) $this->server->getProperty("chunk-sending.spawn-threshold", 56);
$this->spawnPosition = null; $this->spawnPosition = null;
$this->gamemode = $this->server->getGamemode(); $this->gamemode = $this->server->getGamemode();
$this->setLevel($this->server->getDefaultLevel()); $this->setLevel($this->server->getDefaultLevel());
@ -559,9 +555,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return $this->displayName; return $this->displayName;
} }
/** /**
* @param string $name * @param string $name
*/ */
public function setDisplayName($name){ public function setDisplayName($name){
$this->displayName = $name; $this->displayName = $name;
if($this->spawned){ if($this->spawned){
@ -1906,13 +1902,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break; break;
} }
}else{ }else{
if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){
$this->inventory->setHeldItemIndex($packet->selectedSlot); $this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($packet->slot); $this->inventory->setHeldItemSlot($packet->slot);
}else{ }else{
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
} }
}elseif($item === null or $slot === -1 or !$item->deepEquals($packet->item)){ // packet error or not implemented }elseif($item === null or $slot === -1 or !$item->deepEquals($packet->item)){ // packet error or not implemented
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
@ -1922,13 +1918,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->setItem($packet->selectedSlot, $item); $this->inventory->setItem($packet->selectedSlot, $item);
$this->inventory->setHeldItemSlot($packet->selectedSlot); $this->inventory->setHeldItemSlot($packet->selectedSlot);
}else{ }else{
if($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()){ if($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()){
$this->inventory->setHeldItemIndex($packet->selectedSlot); $this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($slot); $this->inventory->setHeldItemSlot($slot);
}else{ }else{
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
} }
$this->inventory->sendHeldItem($this->hasSpawned); $this->inventory->sendHeldItem($this->hasSpawned);
@ -2062,6 +2058,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->sendHeldItem($this); $this->inventory->sendHeldItem($this);
break; break;
} }
$block = $target->getSide($packet->face);
if($block->getId() === Block::FIRE){
$this->level->setBlock($block, new Air());
}
$this->lastBreak = microtime(true); $this->lastBreak = microtime(true);
break; break;
case PlayerActionPacket::ACTION_ABORT_BREAK: case PlayerActionPacket::ACTION_ABORT_BREAK:
@ -2069,9 +2069,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break; break;
case PlayerActionPacket::ACTION_RELEASE_ITEM: case PlayerActionPacket::ACTION_RELEASE_ITEM:
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){
if($this->inventory->getItemInHand()->getId() === Item::BOW) { if($this->inventory->getItemInHand()->getId() === Item::BOW){
$bow = $this->inventory->getItemInHand(); $bow = $this->inventory->getItemInHand();
if ($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))) { if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
@ -2100,35 +2100,35 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$f = min((($p ** 2) + $p * 2) / 3, 1) * 2; $f = min((($p ** 2) + $p * 2) / 3, 1) * 2;
$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this, $f == 2 ? true : false), $f); $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this, $f == 2 ? true : false), $f);
if ($f < 0.1 or $diff < 5) { if($f < 0.1 or $diff < 5){
$ev->setCancelled(); $ev->setCancelled();
} }
$this->server->getPluginManager()->callEvent($ev); $this->server->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) { if($ev->isCancelled()){
$ev->getProjectile()->kill(); $ev->getProjectile()->kill();
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
} else { }else{
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if($this->isSurvival()){ if($this->isSurvival()){
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); $this->inventory->removeItem(Item::get(Item::ARROW, 0, 1));
$bow->setDamage($bow->getDamage() + 1); $bow->setDamage($bow->getDamage() + 1);
if ($bow->getDamage() >= 385) { if($bow->getDamage() >= 385){
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0));
} else { }else{
$this->inventory->setItemInHand($bow); $this->inventory->setItemInHand($bow);
} }
} }
if ($ev->getProjectile() instanceof Projectile) { if($ev->getProjectile() instanceof Projectile){
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($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{
$ev->getProjectile()->spawnToAll(); $ev->getProjectile()->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers()); $this->level->addSound(new LaunchSound($this), $this->getViewers());
} }
} else { }else{
$ev->getProjectile()->spawnToAll(); $ev->getProjectile()->spawnToAll();
} }
} }
@ -2146,7 +2146,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->dataPacket($pk); $this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk); Server::broadcastPacket($this->getViewers(), $pk);
if ($this->isSurvival()) { if($this->isSurvival()){
$slot = $this->inventory->getItemInHand(); $slot = $this->inventory->getItemInHand();
--$slot->count; --$slot->count;
$this->inventory->setItemInHand($slot); $this->inventory->setItemInHand($slot);
@ -2274,7 +2274,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->level->sendBlocks([$this], [$target], UpdateBlockPacket::FLAG_ALL_PRIORITY); $this->level->sendBlocks([$this], [$target], UpdateBlockPacket::FLAG_ALL_PRIORITY);
$this->inventory->sendHeldItem($this); $this->inventory->sendHeldItem($this);
if($tile instanceof Spawnable){ if($tile instanceof Spawnable){
$tile->spawnTo($this); $tile->spawnTo($this);
@ -2481,7 +2481,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if(is_array($amount)){ if(is_array($amount)){
$amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0; $amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0;
} }
$ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING); $ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING);
$this->heal($ev->getAmount(), $ev); $this->heal($ev->getAmount(), $ev);
--$slot->count; --$slot->count;
@ -2645,7 +2645,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$result = $packet->output[0]; $result = $packet->output[0];
if(!$canCraft or !$recipe->getResult()->deepEquals($result)){ if(!$canCraft or !$recipe->getResult()->deepEquals($result)){
$this->server->getLogger()->debug("Unmatched recipe ". $recipe->getId() ." from player ". $this->getName() .": expected " . $recipe->getResult() . ", got ". $result .", using: " . implode(", ", $ingredients)); $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
@ -2669,7 +2669,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
if(!$canCraft){ if(!$canCraft){
$this->server->getLogger()->debug("Unmatched recipe ". $recipe->getId() ." from player ". $this->getName() .": client does not have enough items, using: " . implode(", ", $ingredients)); $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
break; break;
} }
@ -2883,11 +2883,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage())); $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
if($isAdmin){ if($isAdmin){
if(!$this->isBanned()) { if(!$this->isBanned()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
}else{ }else{
$message = $reason; $message = $reason;
} }
}else{ }else{
if($reason === ""){ if($reason === ""){
$message = "disconnectionScreen.noReason"; $message = "disconnectionScreen.noReason";
@ -2910,11 +2910,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
*/ */
public function sendMessage($message){ public function sendMessage($message){
if($message instanceof TextContainer){ if($message instanceof TextContainer){
if ($message instanceof TranslationContainer) { if($message instanceof TranslationContainer){
$this->sendTranslation($message->getText(), $message->getParameters()); $this->sendTranslation($message->getText(), $message->getParameters());
return; return;
} }
$message = $message->getText(); $message = $message->getText();
} }
@ -2966,7 +2966,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
* *
* @param string $message Message to be broadcasted * @param string $message Message to be broadcasted
* @param string $reason Reason showed in console * @param string $reason Reason showed in console
* @param bool $notify * @param bool $notify
*/ */
public final function close($message = "", $reason = "generic reason", $notify = true){ public final function close($message = "", $reason = "generic reason", $notify = true){
@ -3250,13 +3250,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return; return;
} }
if($this->isCreative() if($this->isCreative()
and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC
and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE
and $source->getCause() !== EntityDamageEvent::CAUSE_VOID and $source->getCause() !== EntityDamageEvent::CAUSE_VOID
){ ){
$source->setCancelled(); $source->setCancelled();
}elseif($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL){ }elseif($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL){
$source->setCancelled(); $source->setCancelled();
} }
@ -3355,11 +3355,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
/** /**
* @param Vector3|Position|Location $pos * @param Vector3|Position|Location $pos
* @param float $yaw * @param float $yaw
* @param float $pitch * @param float $pitch
* *
* @return bool * @return bool
*/ */
public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ public function teleport(Vector3 $pos, $yaw = null, $pitch = null){
if(!$this->isOnline()){ if(!$this->isOnline()){
return false; return false;

View File

@ -22,21 +22,11 @@
namespace pocketmine\inventory; namespace pocketmine\inventory;
use pocketmine\block\Planks;
use pocketmine\block\Quartz;
use pocketmine\block\Sandstone;
use pocketmine\block\Slab;
use pocketmine\block\Fence;
use pocketmine\block\Stone;
use pocketmine\block\StoneBricks;
use pocketmine\block\StoneWall;
use pocketmine\block\Wood;
use pocketmine\block\Wood2;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\utils\UUID;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\MainLogger;
use pocketmine\utils\Config; use pocketmine\utils\Config;
use pocketmine\utils\MainLogger;
use pocketmine\utils\UUID;
class CraftingManager{ class CraftingManager{
@ -55,7 +45,7 @@ class CraftingManager{
// load recipes from src/pocketmine/recipes.json // load recipes from src/pocketmine/recipes.json
$recipes = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/recipes.json", Config::JSON, []); $recipes = new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/recipes.json", Config::JSON, []);
MainLogger::getLogger()->Info("Loading recipes..."); MainLogger::getLogger()->info("Loading recipes...");
foreach($recipes->getAll() as $recipe){ foreach($recipes->getAll() as $recipe){
switch($recipe["Type"]){ switch($recipe["Type"]){
case 0: case 0: