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; $id = $target->getId(); if ($id == self::STILL_WATER) { $id = self::WATER; } if ($id == self::STILL_LAVA) { $id = self::LAVA; } $result->setDamage($id); $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()); } return true; } else { $player->getInventory()->sendContents($player); } } } elseif ($targetBlock instanceof Liquid) { $result = clone $this; $result->setDamage(0); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { //Only disallow water placement in the Nether, allow other liquids to be placed //In vanilla, water buckets are emptied when used in the Nether, but no water placed. if (!($player->getLevel()->getDimension() === Level::DIMENSION_NETHER and $targetBlock->getID() === self::WATER)) { $player->getLevel()->setBlock($block, $targetBlock, true, true); } if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem()); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }
public function onBucketFill(PlayerBucketFillEvent $event) { if (!ServerAuth::getAPI()->isPlayerRegistered($event->getPlayer()->getName()) || !ServerAuth::getAPI()->isPlayerAuthenticated($event->getPlayer())) { $event->setCancelled(true); } }
public function onActivate(Item $item, Player $player = null) { $tile = $this->getLevel()->getTile($this); if (!$tile instanceof Cauldron) { return false; } switch ($item->getId()) { case Item::BUCKET: if ($item->getDamage() === 0) { //empty bucket if (!$this->isFull() or $tile->isCustomColor() or $tile->hasPotion()) { break; } $bucket = clone $item; $bucket->setDamage(8); //water bucket Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $this, 0, $item, $bucket)); if (!$ev->isCancelled()) { if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } $this->meta = 0; //empty $this->getLevel()->setBlock($this, $this, true); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } } elseif ($item->getDamage() === 8) { //water bucket if ($this->isFull() and !$tile->isCustomColor() and !$tile->hasPotion()) { break; } $bucket = clone $item; $bucket->setDamage(0); //empty bucket Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $this, 0, $item, $bucket)); if (!$ev->isCancelled()) { if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } if ($tile->hasPotion()) { //if has potion $this->meta = 0; //empty $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId(0xffff); //reset potion $tile->clearCustomColor(); $this->getLevel()->addSound(new ExplodeSound($this->add(0.5, 0, 0.5))); } else { $this->meta = 6; //fill $this->getLevel()->setBlock($this, $this, true); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } $this->update(); } } break; case Item::DYE: if ($tile->hasPotion()) { break; } $color = Color::getDyeColor($item->getDamage()); if ($tile->isCustomColor()) { $color = Color::averageColor($color, $tile->getCustomColor()); } if ($player->isSurvival()) { $item->setCount($item->getCount() - 1); /*if($item->getCount() <= 0){ $player->getInventory()->setItemInHand(Item::get(Item::AIR)); }*/ } $tile->setCustomColor($color); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); $this->update(); break; case Item::LEATHER_CAP: case Item::LEATHER_TUNIC: case Item::LEATHER_PANTS: case Item::LEATHER_BOOTS: if ($this->isEmpty()) { break; } if ($tile->isCustomColor()) { --$this->meta; $this->getLevel()->setBlock($this, $this, true); $newItem = clone $item; Utils::setCustomColorToArmor($newItem, $tile->getCustomColor()); $player->getInventory()->setItemInHand($newItem); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); if ($this->isEmpty()) { $tile->clearCustomColor(); } } else { --$this->meta; $this->getLevel()->setBlock($this, $this, true); $newItem = clone $item; Utils::clearCustomColorToArmor($newItem); $player->getInventory()->setItemInHand($newItem); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } break; case Item::POTION: case Item::SPLASH_POTION: if (!$this->isEmpty() and ($tile->getPotionId() !== $item->getDamage() and $item->getDamage() !== Potion::WATER_BOTTLE or $item->getId() === Item::POTION and $tile->getSplashPotion() or $item->getId() === Item::SPLASH_POTION and !$tile->getSplashPotion() or $item->getDamage() === Potion::WATER_BOTTLE and $tile->hasPotion())) { //long... $this->meta = 0x0; $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId(0xffff); //reset $tile->setSplashPotion(false); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $this->getLevel()->addSound(new ExplodeSound($this->add(0.5, 0, 0.5))); } elseif ($item->getDamage() === Potion::WATER_BOTTLE) { //water bottle $this->meta += 2; if ($this->meta > 0x6) { $this->meta = 0x6; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $tile->setPotionId(0xffff); $tile->setSplashPotion(false); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } elseif (!$this->isFull()) { $this->meta += 2; if ($this->meta > 0x6) { $this->meta = 0x6; } $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId($item->getDamage()); $tile->setSplashPotion($item->getId() === Item::SPLASH_POTION); $tile->clearCustomColor(); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $color = Potion::getColor($item->getDamage()); $this->getLevel()->addSound(new SpellSound($this->add(0.5, 1, 0.5), $color[0], $color[1], $color[2])); } break; case Item::GLASS_BOTTLE: if ($this->meta < 2) { break; } if ($tile->hasPotion()) { $this->meta -= 2; if ($this->meta < 0x0) { $this->meta = 0x0; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $result = Item::get(Item::POTION, $tile->getPotionId()); if ($item->getCount() === 1) { $player->getInventory()->setItemInHand($result); } else { $player->getInventory()->addItem($result); } } if ($this->isEmpty()) { $tile->setPotionId(0xffff); //reset $tile->setSplashPotion(false); } $color = Potion::getColor($result->getDamage()); $this->getLevel()->addSound(new SpellSound($this->add(0.5, 1, 0.5), $color[0], $color[1], $color[2])); } else { $this->meta -= 2; if ($this->meta < 0x0) { $this->meta = 0x0; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $result = Item::get(Item::POTION, Potion::WATER_BOTTLE); if ($item->getCount() > 1 and $player->getInventory()->canAddItem($result)) { $player->getInventory()->addItem($result); } else { $player->getInventory()->setItemInHand($result); } } $this->getLevel()->addSound(new GraySplashSound($this->add(0.5, 1, 0.5))); } break; } return true; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $bucketContents = Block::get($this->meta); if ($bucketContents instanceof Air) { // Bucket Empty so pick up block if ($target instanceof Liquid and $target->getDamage() === 0) { $result = clone $this; if ($target instanceof StillWater) { $toStore = Block::WATER; } elseif ($target instanceof StillLava) { $toStore = Block::LAVA; } else { return false; } $result->setDamage($toStore); $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 ($bucketContents instanceof Liquid) { // Bucket Full, so empty $result = clone $this; $result->setDamage(0); if ($bucketContents instanceof Water) { $toCreate = Block::STILL_WATER; } elseif ($bucketContents instanceof Lava) { $toCreate = Block::STILL_LAVA; } else { return false; } $bucketContents = Block::get($toCreate); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($block, $bucketContents, true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }
public function onBucket(PlayerBucketFillEvent $event) { $player = $event->getPlayer(); if ($player->isOp()) { return; } $area = $this->db[$event->getPlayer()->level->getFolderName()]->getArea($player->x, $player->z); if ($area != false) { if (isset($area["resident"][0])) { if ($this->db[$player->level->getFolderName()]->checkResident($area["ID"], $player->getName())) { return; } } $event->setCancelled(); } }
/** * @param PlayerBucketFillEvent $event * @priority HIGHEST * @ignoreCancelled true */ public function onPlayerBucketFill(PlayerBucketFillEvent $event) { if (!$this->plugin->getStorage()->getShield($event->getPlayer()->getLevel())->isAllowed(Shield::FILLING)) { $event->setCancelled(true); $event->getPlayer()->sendTip($this->plugin->getConfig()->get("fillNotAllowed")); } }
public function onBucketFill(PlayerBucketFillEvent $event) { if ($this->disableBucketUse) { $event->setCancelled(); } return; }
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; }