isCreative() 공개 메소드

public isCreative ( ) : boolean
리턴 boolean
예제 #1
10
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $target->getBreakTime($item);
         if ($player->isCreative() and $breakTime > 0.15) {
             $breakTime = 0.15;
         }
         if ($player->hasEffect(Effect::SWIFTNESS)) {
             $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
         }
         if ($player->hasEffect(Effect::MINING_FATIGUE)) {
             $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1);
         }
         $breakTime -= 0.05;
         //1 tick compensation
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) {
             return false;
         }
         $player->lastBreak = microtime(true);
         $drops = $ev->getDrops();
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             $drops[$k] = Item::get($i[0], $i[1], $i[2]);
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     $tag = $item->getNamedTagEntry("CanDestroy");
     if ($tag instanceof Enum) {
         $canBreak = false;
         foreach ($tag as $v) {
             if ($v instanceof String) {
                 $entry = Item::fromString($v->getValue());
                 if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) {
                     $canBreak = true;
                     break;
                 }
             }
         }
         if (!$canBreak) {
             return false;
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         if ($player !== null) {
             unset($players[$player->getLoaderId()]);
         }
         $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players);
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }
예제 #2
1
파일: Chest.php 프로젝트: xpyctum/Genisys
 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 CompoundTag("", [new EnumTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("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 StringTag) {
             if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }
예제 #3
1
파일: Furnace.php 프로젝트: iTXTech/Genisys
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         if ($t instanceof FurnaceTile) {
             $furnace = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::FURNACE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("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 StringTag) {
             if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
예제 #4
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         $dispenser = null;
         if ($t instanceof TileDispenser) {
             $dispenser = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::DISPENSER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $dispenser = Tile::createTile(Tile::DISPENSER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($dispenser->getInventory());
     }
     return true;
 }
예제 #5
0
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anviletEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $tile = $this->getLevel()->getTile($this);
         $enchantTable = null;
         if ($tile instanceof EnchantTable) {
             $enchantTable = $tile;
         }
     } else {
         $this->getLevel()->setBlock($this, $this, true, true);
         $nbt = new CompoundTag("", [new StringTag("id", Tile::ENCHANT_TABLE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
         if ($item->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
         }
         if ($item->hasCustomBlockData()) {
             foreach ($item->getCustomBlockData() as $key => $v) {
                 $nbt->{$key} = $v;
             }
         }
         $enchantTable = Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     }
     $player->addWindow($enchantTable->getInventory());
     return true;
 }
예제 #6
0
 /**
  * Clear players inventory
  * @param Player $target
  */
 public static function clearInventory(Player $target)
 {
     if ($target->isCreative() || $target->isSpectator()) {
         return;
     }
     $target->getInventory()->clearAll();
 }
예제 #7
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         if ($player->getServer()->limitedCreative and $player->isCreative()) {
             return true;
         }
         $player->craftingType = Player::CRAFTING_BIG;
     }
     return true;
 }
예제 #8
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow(new AnvilInventory($this));
     }
     return true;
 }
예제 #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;
 }
예제 #10
0
 public function execute(Player $source) : bool
 {
     $droppedItem = $this->getTargetItem();
     if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
         if (!$source->getFloatingInventory()->contains($droppedItem)) {
             return false;
         }
         $source->getFloatingInventory()->removeItem($droppedItem);
     }
     $source->dropItem($droppedItem);
     return true;
 }
예제 #11
0
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anviletEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow(new AnvilInventory($this));
     }
     return true;
 }
예제 #12
0
파일: TNT.php 프로젝트: iTXTech/Genisys
 public function prime(Player $player = null)
 {
     $this->meta = 1;
     if ($player != null and $player->isCreative()) {
         $dropItem = false;
     } else {
         $dropItem = true;
     }
     $mot = (new Random())->nextSignedFloat() * M_PI * 2;
     $tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]), $dropItem);
     $tnt->spawnToAll();
     $this->level->addSound(new TNTPrimeSound($this));
 }
예제 #13
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;
 }
예제 #14
0
파일: Anvil.php 프로젝트: iTXTech/Genisys
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anvilEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow(new AnvilInventory($this));
         $player->craftingType = Player::CRAFTING_ANVIL;
     }
     return true;
 }
예제 #15
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 ($player->isCreative()) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
예제 #16
0
 public function onRename(Player $player, Item $resultItem) : bool
 {
     if (!$resultItem->deepEquals($this->getItem(self::TARGET), true, false, true)) {
         //Item does not match target item. Everything must match except the tags.
         return false;
     }
     if ($player->getExpLevel() < $resultItem->getRepairCost()) {
         //Not enough exp
         return false;
     }
     $player->setExpLevel($player->getExpLevel() - $resultItem->getRepairCost());
     $this->clearAll();
     if (!$player->getServer()->allowInventoryCheats and !$player->isCreative()) {
         if (!$player->getFloatingInventory()->canAddItem($resultItem)) {
             return false;
         }
         $player->getFloatingInventory()->addItem($resultItem);
     }
     return true;
 }
예제 #17
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative()) {
             return true;
         }
         $t = $this->getLevel()->getTile($this);
         $brewingStand = false;
         if ($t instanceof TileBrewingStand) {
             $brewingStand = $t;
         } else {
             $nbt = new CompoundTag("", [new EnumTag("Items", []), new StringTag("id", Tile::BREWING_STAND), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $brewingStand = Tile::createTile(Tile::BREWING_STAND, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         $player->addWindow($brewingStand->getInventory());
     }
     return true;
 }
예제 #18
0
 public function participate(Player $player)
 {
     $soldier = new soldier($player);
     if ($player->isCreative()) {
         $player->setGamemode(0);
     }
     if (count($this->redteam->soldiers) < count($this->blueteam->soldiers)) {
         $soldier->setTeam($this->redteam);
         $color = TextFormat::RED;
     } else {
         $soldier->setTeam($this->blueteam);
         $color = TextFormat::BLUE;
     }
     $soldier->getTeam()->soldiers[$player->getName()] = $soldier;
     $rank = RankProvider::getInstance()->getRank($player);
     $prefix = $color . $soldier->getTeam()->getTeamName() . TextFormat::GOLD;
     $rank->addPrefixs([$prefix]);
     $rank->setPrefix($prefix);
     $player->teleport($soldier->getTeam()->getSpawnPoint());
     $this->eventlistener->giveRandomItem($player);
     $this->soldiers[$player->getName()] = $soldier;
 }
예제 #19
0
 /**
  * @param Player $source
  * @return bool
  *
  * Handles transaction execution. Returns whether transaction was successful or not.
  */
 public function execute(Player $source) : bool
 {
     if ($this->getInventory()->processSlotChange($this)) {
         //This means that the transaction should be handled the normal way
         if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
             $change = $this->getChange();
             if ($change === null) {
                 //No changes to make, ignore this transaction
                 return true;
             }
             /* Verify that we have the required items */
             if ($change["out"] instanceof Item) {
                 if (!$this->getInventory()->slotContains($this->getSlot(), $change["out"])) {
                     return false;
                 }
             }
             if ($change["in"] instanceof Item) {
                 if (!$source->getFloatingInventory()->contains($change["in"])) {
                     return false;
                 }
             }
             /* All checks passed, make changes to floating inventory
              * This will not be reached unless all requirements are met */
             if ($change["out"] instanceof Item) {
                 $source->getFloatingInventory()->addItem($change["out"]);
             }
             if ($change["in"] instanceof Item) {
                 $source->getFloatingInventory()->removeItem($change["in"]);
             }
         }
         $this->getInventory()->setItem($this->getSlot(), $this->getTargetItem(), false);
     }
     /* Process transaction achievements, like getting iron from a furnace */
     foreach ($this->achievements as $achievement) {
         $source->awardAchievement($achievement);
     }
     return true;
 }
예제 #20
0
파일: Level.php 프로젝트: kniffo80/Genisys
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return bool
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, bool $createParticles = false) : bool
 {
     $target = $this->getBlock($vector);
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isAdventure() or $player->isSpectator() or $player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         /*$breakTime = $target->getBreakTime($item);
         
         			if($player->isCreative() and $breakTime > 0.15){
         				$breakTime = 0.15;
         			}
         
         			if($player->hasEffect(Effect::SWIFTNESS)){
         				$breakTime *= 1 - (0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1));
         			}
         
         			if($player->hasEffect(Effect::MINING_FATIGUE)){
         				$breakTime *= 1 + (0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1));
         			}
         
         			$breakTime -= 0.05; //1 tick compensation
         
         			if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) > microtime(true)){
         				return false;
         			}*/
         $player->lastBreak = microtime(true);
         $drops = $ev->getDrops();
         if ($player->isSurvival() and $this->getServer()->expEnabled) {
             $exp = 0;
             if ($item->getEnchantmentLevel(Enchantment::TYPE_MINING_SILK_TOUCH) === 0) {
                 switch ($target->getId()) {
                     case Block::COAL_ORE:
                         $exp = mt_rand(0, 2);
                         break;
                     case Block::DIAMOND_ORE:
                     case Block::EMERALD_ORE:
                         $exp = mt_rand(3, 7);
                         break;
                     case Block::NETHER_QUARTZ_ORE:
                     case Block::LAPIS_ORE:
                         $exp = mt_rand(2, 5);
                         break;
                     case Block::REDSTONE_ORE:
                     case Block::GLOWING_REDSTONE_ORE:
                         $exp = mt_rand(1, 5);
                         break;
                 }
             }
             switch ($target->getId()) {
                 case Block::MONSTER_SPAWNER:
                     $exp = mt_rand(15, 43);
                     break;
             }
             if ($exp > 0) {
                 $this->spawnXPOrb($vector->add(0, 1, 0), $exp);
             }
         }
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             if (isset($i[0]) && isset($i[1]) && isset($i[2])) {
                 $drops[$k] = Item::get($i[0], $i[1], $i[2]);
             }
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     $tag = $item->getNamedTagEntry("CanDestroy");
     if ($tag instanceof ListTag) {
         $canBreak = false;
         foreach ($tag as $v) {
             if ($v instanceof StringTag) {
                 $entry = Item::fromString($v->getValue());
                 if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) {
                     $canBreak = true;
                     break;
                 }
             }
         }
         if (!$canBreak) {
             return false;
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         /*if($player !== null){
         			unset($players[$player->getLoaderId()]);
         		}*/
         $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players);
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }
예제 #21
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(false, [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 ($player->isCreative()) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }
예제 #22
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent() !== true) {
             return true;
         }
         $this->BroadcastRedstoneUpdate(Level::REDSTONE_UPDATE_PLACE, Block::REDSTONESOURCEPOWER);
         $this->getLevel()->scheduleUpdate($this, 2);
         $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;
 }
예제 #23
-1
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player instanceof Player) {
         $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x1) === 1 ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         }
         if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if ($t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime >= microtime(true)) {
             return false;
         }
         $player->lastBreak = microtime(true);
     } elseif ($item instanceof Item and !$target->isBreakable($item)) {
         return false;
     }
     $level = $target->getLevel();
     if ($level instanceof Level) {
         $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
         if ($above instanceof Block) {
             if ($above->getId() === Item::FIRE) {
                 $level->setBlock($above, new Air(), true);
             }
         }
     }
     $drops = $target->getDrops($item);
     //Fixes tile entities being deleted before getting drops
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile instanceof Tile) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item instanceof Item) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if (!$player instanceof Player or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop[2] > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop));
             }
         }
     }
     return true;
 }
예제 #24
-1
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
         if ($player->hasEffect(Effect::SWIFTNESS)) {
             $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
         }
         if ($player->hasEffect(Effect::MINING_FATIGUE)) {
             $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1);
         }
         $breakTime -= 0.05;
         //1 tick compensation
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) {
             return false;
         }
         $player->lastBreak = PHP_INT_MAX;
         $drops = $ev->getDrops();
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             $drops[$k] = Item::get($i[0], $i[1], $i[2]);
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         if ($player !== null) {
             unset($players[$player->getLoaderId()]);
         }
         $pk = new LevelEventPacket();
         $pk->evid = 2001;
         $pk->x = $target->x + 0.5;
         $pk->y = $target->y + 0.5;
         $pk->z = $target->z + 0.5;
         $pk->data = $target->getId() + ($target->getDamage() << 12);
         Server::broadcastPacket($players, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }