Exemplo n.º 1
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $result->setDamage($target->getId());
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $targetBlock, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent() === false and $face !== 0 and $face !== 1 and $block->isSolid() === false) {
         $faces = [2 => 0, 3 => 2, 4 => 1, 5 => 3];
         $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new Compound("", ["Motive" => new String("Motive", $data["Motive"]), "Pos" => new Enum("Pos", [new Double("", $data["x"]), new Double("", $data["y"]), new Double("", $data["z"])]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", $data["yaw"]), new Float("", 0)])]);
         $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
         $painting->spawnToAll();
         /*if($player->isSurvival()){
         				$item = $player->getInventory()->getItemInHand();
         				$count = $item->getCount();
         				if(--$count <= 0){
         					$player->getInventory()->setItemInHand(Item::get(Item::AIR));
         					return;
         				}
         
         				$item->setCount($count);
         				$player->getInventory()->setItemInHand($item);
         			}*/
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public function onClose(Player $who)
 {
     $pk = new ContainerClosePacket();
     $pk->windowid = $who->getWindowId($this);
     $who->dataPacket($pk);
     parent::onClose($who);
 }
Exemplo n.º 4
0
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($tile instanceof FlowerPotTile) {
         if ($tile->getFlowerPotItem() === Item::AIR) {
             switch ($item->getId()) {
                 case Item::TALL_GRASS:
                     if ($item->getDamage() === 1) {
                         break;
                     }
                 case Item::SAPLING:
                 case Item::DEAD_BUSH:
                 case Item::DANDELION:
                 case Item::RED_FLOWER:
                 case Item::BROWN_MUSHROOM:
                 case Item::RED_MUSHROOM:
                 case Item::CACTUS:
                     $tile->setFlowerPotData($item->getId(), $item->getDamage());
                     $this->setDamage($item->getDamage());
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
Exemplo n.º 5
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $faces = [0 => 3, 1 => 2, 2 => 1, 3 => 0];
     $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x1;
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
Exemplo n.º 6
0
 /**
  *
  * @param Player $player        	
  */
 public function giveEffects(Player $player)
 {
     $effects = $this->getEffects();
     foreach ($effects as $effect) {
         $player->addEffect($effect);
     }
 }
Exemplo n.º 7
0
 public function onActivate(Level $level, Player $player, $block, $target, $face, $fx, $fy, $fz)
 {
     foreach ($player->getLevel()->getEntities() as $entity) {
         if ($entity instanceof FishingHook) {
             if ($entity->shootingEntity === $player) {
                 $entity->reelLine();
             }
         }
     }
 }
Exemplo n.º 8
0
 public function onClose(Player $who)
 {
     $who->updateExperience();
     parent::onClose($who);
     $this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem(1));
     $this->getHolder()->getLevel()->dropItem($this->getHolder()->add(0.5, 0.5, 0.5), $this->getItem(0));
     $this->clear(0);
     $this->clear(1);
     $this->clear(2);
 }
Exemplo n.º 9
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow(new EnchantInventory($this));
     }
     return true;
 }
Exemplo n.º 10
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $block->getSide(0);
     if ($down->getId() === self::AIR) {
         return false;
     }
     $faces = [0 => 3, 1 => 0, 2 => 1, 3 => 2];
     $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x3;
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
Exemplo n.º 11
0
 public function __construct(Player $player, Block $block, Item $item, $instaBreak = false)
 {
     $this->block = $block;
     $this->item = $item;
     $this->player = $player;
     $this->instaBreak = (bool) $instaBreak;
     $drops = $player->isSurvival() ? $block->getDrops($item) : [];
     foreach ($drops as $i) {
         $this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
     }
 }
Exemplo n.º 12
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (($player->gamemode & 0x1) === 0 and $this->useOn($block) and $this->getDamage() >= $this->getMaxDurability()) {
         $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), true);
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 public function spawnTo(Player $player)
 {
     $pk = new AddPaintingPacket();
     $pk->eid = $this->getId();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->direction = $this->getDirection();
     $pk->title = $this->motive;
     $player->dataPacket($pk);
     parent::spawnTo($player);
 }
Exemplo n.º 14
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $block->getSide(0);
     if ($down->isTransparent() && !($down instanceof Slab && ($down->meta & 0x8) === 0x8) || $down instanceof WoodSlab && ($down->meta & 0x8) === 0x8 || $down instanceof Stair && ($down->meta & 0x4) === 0x4) {
         return false;
     }
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
Exemplo n.º 15
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative()) {
             return true;
         }
         if (($t = $this->getLevel()->getTile($this)) instanceof TileBrewingStand) {
             $player->addWindow(new BrewingInventory($t));
         }
     }
     return true;
 }
Exemplo n.º 16
0
 public static function broadcast(Player $player, $achievementId)
 {
     if (isset(Achievement::$list[$achievementId])) {
         $translation = new TranslationContainer("chat.type.achievement", [$player->getDisplayName(), TextFormat::RED . Achievement::$list[$achievementId]["name"]]);
         if (Server::getInstance()->getConfigString("announce-player-achievements", true) === true) {
             Server::getInstance()->broadcastMessage($translation);
         } else {
             $player->sendMessage($translation);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 17
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player and $player->getFood() < 20) {
         ++$this->meta;
         $player->setFood($player->getFood() + 2);
         if ($this->meta >= 0x6) {
             $this->getLevel()->setBlock($this, new Air(), true);
         } else {
             $this->getLevel()->setBlock($this, $this, true);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 18
0
 public function spawnTo(Player $player)
 {
     if ($this->closed) {
         return false;
     }
     $nbt = new NBT(NBT::LITTLE_ENDIAN);
     $nbt->setData($this->getSpawnCompound());
     $pk = new BlockEntityDataPacket();
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->namedtag = $nbt->write();
     $player->dataPacket($pk);
     return true;
 }
Exemplo n.º 19
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $this->getSide(0);
     if ($down->isTransparent() === false) {
         $faces = [0 => 3, 1 => 4, 2 => 2, 3 => 5];
         $d = $player instanceof Player ? $player->getDirection() : 0;
         $next = $this->getSide($faces[($d + 3) % 4]);
         $downNext = $this->getSide(0);
         if ($next->canBeReplaced() === true and $downNext->isTransparent() === false) {
             $meta = ($d + 3) % 4 & 0x3;
             $this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
             $this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x8), true, true);
             return true;
         }
     }
     return false;
 }
Exemplo n.º 20
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($target->isTransparent() === false) {
         $faces = [0 => 0, 1 => 1, 2 => 2, 3 => 3];
         $damage = $this->getDamage();
         $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x4;
         if ($damage >= 0 && $damage <= 3) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
         } elseif ($damage >= 4 && $damage <= 7) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] | 0x4;
         } elseif ($damage >= 8 && $damage <= 11) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] | 0x8;
         }
         $this->getLevel()->setBlock($block, $this, true);
         return true;
     }
     return false;
 }
Exemplo n.º 21
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($target->isTransparent() === false) {
         $faces = [3 => 3, 2 => 4, 4 => 2, 5 => 1];
         if ($face === 0) {
             $to = $player instanceof Player ? $player->getDirection() : 0;
             $this->meta = $to ^ 0x1 === 0x1 ? 0 : 7;
         } elseif ($face === 1) {
             $to = $player instanceof Player ? $player->getDirection() : 0;
             $this->meta = $to ^ 0x1 === 0x1 ? 6 : 5;
         } else {
             $this->meta = $faces[$face];
         }
         $this->getLevel()->setBlock($block, $this, true, true);
         return true;
     }
     return false;
 }
Exemplo n.º 22
0
 public function launch(Player $player)
 {
     $dir = $player->getDirectionVector();
     $frontPos = $player->add($dir->multiply(1.1));
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $frontPos->x), new Double("", $frontPos->y + $player->getEyeHeight()), new Double("", $frontPos->z)]), "Motion" => new Enum("Motion", [new Double("", $dir->x), new Double("", $dir->y), new Double("", $dir->z)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "Data" => new Byte("Data", $this->getDamage())]);
     $f = $this->f;
     $launched = Entity::createEntity($this->getEntityName(), $player->chunk, $nbt);
     $launched->setMotion($launched->getMotion()->multiply($f));
     if ($launched instanceof Projectile) {
         $player->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($launched));
         if ($projectileEv->isCancelled()) {
             $launched->kill();
         } else {
             $launched->spawnToAll();
             $player->level->addSound(new LaunchSound($player), $player->getViewers());
         }
     } else {
         $launched->spawnToAll();
     }
 }
Exemplo n.º 23
0
 public function send()
 {
     $pk = new UpdateAttributePacket();
     $pk->maxValue = $this->getMaxValue();
     $pk->minValue = $this->getMinValue();
     $pk->value = $this->currentValue;
     $pk->name = $this->getName();
     $pk->entityId = 0;
     $pk->encode();
     $this->player->dataPacket($pk);
 }
Exemplo n.º 24
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     if ($this->hasCustomName()) {
         $nbt->CustomName = new String("CustomName", $this->getCustomName());
     }
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_NO_AI, true);
         $entity->getLevel()->getServer()->broadcastPopup(TextFormat::RED . "Mob AI isn't implemented yet!");
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
Exemplo n.º 25
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $block->getSide($face);
     $boat = new BoatEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $boat->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Exemplo n.º 26
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         $furnace = false;
         if ($t instanceof Furnace) {
             $furnace = $t;
         } else {
             $nbt = new Compound("", [new Enum("Items", []), new String("id", Tile::FURNACE), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof String) {
             if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
Exemplo n.º 27
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent() !== true) {
             return true;
         }
         $t = $this->getLevel()->getTile($this);
         $chest = null;
         if ($t instanceof TileChest) {
             $chest = $t;
         } else {
             $nbt = new Compound("", [new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof String) {
             if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }
Exemplo n.º 28
0
 public function chunkRequestCallback($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
 {
     $this->timings->syncChunkSendTimer->startTiming();
     $index = Level::chunkHash($x, $z);
     if (!isset($this->chunkCache[$index]) and $this->cacheChunks and $this->server->getMemoryManager()->canUseChunkCache()) {
         $this->chunkCache[$index] = Player::getChunkCacheFromData($x, $z, $payload, $ordering);
         $this->sendChunkFromCache($x, $z);
         $this->timings->syncChunkSendTimer->stopTiming();
         return;
     }
     if (isset($this->chunkSendTasks[$index])) {
         foreach ($this->chunkSendQueue[$index] as $player) {
             /** @var Player $player */
             if ($player->isConnected() and isset($player->usedChunks[$index])) {
                 $player->sendChunk($x, $z, $payload, $ordering);
             }
         }
         unset($this->chunkSendQueue[$index]);
         unset($this->chunkSendTasks[$index]);
     }
     $this->timings->syncChunkSendTimer->stopTiming();
 }
Exemplo n.º 29
0
 /**
  *
  * @param Player $player
  */
 public function showPlayer(Player $player)
 {
     if ($player === $this) {
         return;
     }
     unset($this->hiddenPlayers[$player->getRawUniqueId()]);
     if ($player->isOnline()) {
         $player->spawnTo($this);
     }
 }
Exemplo n.º 30
0
 public function open(Player $who)
 {
     $who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->onOpen($who);
     return true;
 }