getEffectByName() public static method

public static getEffectByName ( $name )
Ejemplo n.º 1
0
 private function parseEffectLine($txt)
 {
     $txt = preg_split('/\\s*:\\s*/', $txt);
     if (count($txt) == 0 || count($txt) > 3) {
         return null;
     }
     if (!isset($txt[1]) || empty($txt[1])) {
         $txt[1] = 60;
     }
     if (!isset($txt[2]) || empty($txt[2])) {
         $txt[2] = 1;
     }
     if (is_numeric($txt[0])) {
         $effect = Effect::getEffect($txt[0]);
     } else {
         $effect = Effect::getEffectByName($txt[0]);
     }
     if ($effect === null) {
         return null;
     }
     $effect->setDuration($txt[1] * 20);
     $effect->setAmplifier($txt[2]);
     $effect->setVisible(true);
     return $effect;
 }
Ejemplo n.º 2
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) < 2) {
         return \true;
     }
     $player = $sender->getServer()->getPlayer($args[0]);
     if ($player === \null) {
         return \true;
     }
     if (\strtolower($args[1]) === "clear") {
         foreach ($player->getEffects() as $effect) {
             $player->removeEffect($effect->getId());
         }
         return \true;
     }
     $effect = Effect::getEffectByName($args[1]);
     if ($effect === \null) {
         $effect = Effect::getEffect((int) $args[1]);
     }
     if ($effect === \null) {
         return \true;
     }
     $duration = 300;
     $amplification = 0;
     if (\count($args) >= 3) {
         $duration = (int) $args[2];
         if (!$effect instanceof InstantEffect) {
             $duration *= 20;
         }
     } elseif ($effect instanceof InstantEffect) {
         $duration = 1;
     }
     if (\count($args) >= 4) {
         $amplification = (int) $args[3];
     }
     if (\count($args) >= 5) {
         $v = \strtolower($args[4]);
         if ($v === "on" or $v === "true" or $v === "t" or $v === "1") {
             $effect->setVisible(\false);
         }
     }
     if ($duration === 0) {
         if (!$player->hasEffect($effect->getId())) {
             if (\count($player->getEffects()) === 0) {
             } else {
             }
             return \true;
         }
         $player->removeEffect($effect->getId());
     } else {
         $effect->setDuration($duration)->setAmplifier($amplification);
         $player->addEffect($effect);
     }
     return \true;
 }
Ejemplo n.º 3
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) < 2) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     $player = $sender->getServer()->getPlayer($args[0]);
     if ($player === null) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
         return true;
     }
     if (strtolower($args[1]) === "clear") {
         foreach ($player->getEffects() as $effect) {
             $player->removeEffect($effect->getId());
         }
         $sender->sendMessage(new TranslationContainer("commands.effect.success.removed.all", [$player->getDisplayName()]));
         return true;
     }
     $effect = Effect::getEffectByName($args[1]);
     if ($effect === null) {
         $effect = Effect::getEffect((int) $args[1]);
     }
     if ($effect === null) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.effect.notFound", [(string) $args[1]]));
         return true;
     }
     $duration = 300;
     $amplification = 0;
     if (count($args) >= 3) {
         $duration = (int) $args[2];
         if (!$effect instanceof InstantEffect) {
             $duration *= 20;
         }
     } elseif ($effect instanceof InstantEffect) {
         $duration = 1;
     }
     if (count($args) >= 4) {
         $amplification = (int) $args[3];
     }
     if (count($args) >= 5) {
         $v = strtolower($args[4]);
         if ($v === "on" or $v === "true" or $v === "t" or $v === "1") {
             $effect->setVisible(false);
         }
     }
     if ($duration === 0) {
         if (!$player->hasEffect($effect->getId())) {
             if (count($player->getEffects()) === 0) {
                 $sender->sendMessage(new TranslationContainer("commands.effect.failure.notActive.all", [$player->getDisplayName()]));
             } else {
                 $sender->sendMessage(new TranslationContainer("commands.effect.failure.notActive", [$effect->getName(), $player->getDisplayName()]));
             }
             return true;
         }
         $player->removeEffect($effect->getId());
         $sender->sendMessage(new TranslationContainer("commands.effect.success.removed", [$effect->getName(), $player->getDisplayName()]));
     } else {
         $effect->setDuration($duration)->setAmplifier($amplification);
         $player->addEffect($effect);
         self::broadcastCommandMessage($sender, new TranslationContainer("%commands.effect.success", [$effect->getName(), $effect->getId(), $effect->getAmplifier(), $player->getDisplayName(), $effect->getDuration() / 20]));
     }
     return true;
 }
Ejemplo n.º 4
0
 public function blockBreak(BlockBreakEvent $event)
 {
     $block = $event->getBlock();
     if ($block->getId() === $this->data["lucky_block"] && $this->isAllowedWorld($block->getLevel())) {
         $player = $event->getPlayer();
         if (!$player->hasPermission("luckyblock.use")) {
             $player->sendMessage($this->tag . $this->message->get("not_allowed"));
             return;
         }
         $event->setCancelled();
         $player->getLevel()->setBlock($block, new Block(Block::AIR), false, true);
         $rand = new Random();
         switch ($rand->nextRange(1, 12)) {
             case 1:
                 if (!isset($this->data["functions"]["spawnTree"]) || $this->data["functions"]["spawnTree"]) {
                     $type = Sapling::OAK;
                     switch ($rand->nextRange(0, 3)) {
                         case 1:
                             $type = Sapling::BIRCH;
                             break;
                         case 2:
                             $type = Sapling::SPRUCE;
                             break;
                         case 3:
                             $type = Sapling::JUNGLE;
                             break;
                     }
                     if ($player->getLevel()->setBlock($block, new Sapling($type), true, true)) {
                         $player->getLevel()->getBlock($block)->onActivate(new Item(Item::DYE, 15), $player);
                         $player->sendMessage($this->tag . $this->message->get("tree"));
                     }
                     break;
                 }
             case 2:
                 if (!isset($this->data["functions"]["explosion"]) || $this->data["functions"]["explosion"]) {
                     $explosion = new Explosion($block, mt_rand($this->data["explosion_min"], $this->data["explosion_max"]));
                     if ($explosion->explodeA()) {
                         $explosion->explodeB();
                     }
                     $player->sendMessage($this->tag . $this->message->get("explosion"));
                     break;
                 }
             case 3:
                 if (!isset($this->data["functions"]["dropItem"]) || $this->data["functions"]["dropItem"]) {
                     if (mt_rand(0, 1)) {
                         if ($this->itemLoop($player, $block)) {
                             break;
                         }
                     }
                     if (count($this->data["items_dropped"]) === 0) {
                         $item = $this->randItem();
                     } else {
                         $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)];
                     }
                     $player->getLevel()->dropItem($block, $item);
                     $player->sendMessage($this->tag . $this->message->get("drop"));
                     break;
                 }
             case 4:
                 if (!isset($this->data["functions"]["bedrock"]) || $this->data["functions"]["bedrock"]) {
                     $player->getLevel()->setBlock($block, new Block(Block::BEDROCK));
                     $p = new Position($block->x, $block->y + 1, $block->z, $block->level);
                     if ($player->getLevel()->getBlock($p)->getId() != Block::AIR) {
                         break;
                     }
                     $block->getLevel()->setBlock($p, Block::get(Item::SIGN_POST));
                     $sign = new Sign($player->getLevel()->getChunk($block->x >> 4, $block->z >> 4), new CompoundTag(false, array(new IntTag("x", (int) $block->x), new IntTag("y", (int) $block->y + 1), new IntTag("z", (int) $block->z), new StringTag("Text1", $this->tag), new StringTag("Text2", $this->message->get("signText")))));
                     $sign->spawnToAll();
                     $player->sendMessage($this->tag . $this->message->get("sign"));
                     break;
                 }
             case 5:
                 if (!isset($this->data["functions"]["prison"]) || $this->data["functions"]["prison"]) {
                     $pos = $event->getPlayer();
                     $pos->x = round($pos->x) + 0.5;
                     $pos->y = round($pos->y);
                     $pos->z = round($pos->z) + 0.5;
                     $player->teleport($pos, $player->getYaw(), $player->getPitch());
                     $arr = [];
                     switch ($rand->nextRange(1, 5)) {
                         case 1:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::OBSIDIAN));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::OBSIDIAN));
                                         }
                                     }
                                 }
                             }
                             $player->getLevel()->updateAround($pos);
                             $player->sendMessage($this->tag . $this->message->get("prison"));
                             break;
                         case 2:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::STILL_LAVA));
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 2, $pos->z, $pos->getLevel()), new Block(Block::GLASS));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR));
                                         }
                                     }
                                 }
                             }
                             $player->getLevel()->updateAround($pos);
                             $player->sendMessage($this->tag . $this->message->get("prison"));
                             break;
                         case 3:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::SANDSTONE));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR));
                                         }
                                     }
                                 }
                             }
                             break;
                         case 4:
                             $arr = [["x" => -1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::GLASS], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN]];
                             break;
                         case 5:
                             $arr = [["x" => -1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::COBWEB]];
                             break;
                     }
                     $pos = $player->getPosition();
                     foreach ($arr as $i => $c) {
                         $player->getLevel()->setBlock($pos->add($c["x"], $c["y"], $c["z"]), Block::get($c["block"]), true, true);
                     }
                     break;
                 }
             case 6:
                 if (!isset($this->data["functions"]["chest"]) || $this->data["functions"]["chest"]) {
                     $player->getLevel()->setBlock($block, new Block(Block::CHEST), true, true);
                     $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z)]);
                     $nbt->Items->setTagType(NBT::TAG_Compound);
                     $tile = Tile::createTile("Chest", $block->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
                     if ($tile instanceof Chest) {
                         for ($i = 0; $i <= mt_rand(1, $this->data["max_chest_item"]); $i++) {
                             if (count($this->data["items_dropped"]) === 0) {
                                 $item = $this->randItem();
                             } else {
                                 $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)];
                             }
                             $tile->getInventory()->setItem($i, $item);
                         }
                         $player->sendMessage($this->tag . $this->message->get("chest"));
                     }
                     break;
                 }
             case 7:
                 if (!isset($this->data["functions"]["teleport"]) || $this->data["functions"]["teleport"]) {
                     $player->teleport($player->getLevel()->getSpawnLocation(), $player->getYaw(), $player->getPitch());
                     $player->sendMessage($this->tag . $this->message->get("spawn"));
                     break;
                 }
             case 8:
                 if (!isset($this->data["functions"]["potion"]) || $this->data["functions"]["potion"]) {
                     if (count($this->data["potions"])) {
                         $effect = Effect::getEffectByName($this->data["potions"][$rand->nextRange(0, count($this->data["potions"]) - 1)]);
                         $effect->setDuration($rand->nextRange(20, $this->data["max_duration"] * 20));
                         $player->addEffect($effect);
                         $player->sendMessage($this->tag . $this->message->get("effect"));
                     } else {
                         $player->sendMessage($this->tag . $this->message->get("unlucky"));
                     }
                     break;
                 }
             case 9:
                 //exec command
                 if (!isset($this->data["functions"]["execCmd"]) || $this->data["functions"]["execCmd"]) {
                     if (count($this->data["commands"])) {
                         $cmd = $this->data["commands"][$rand->nextRange(0, count($this->data["commands"]) - 1)];
                         $cmd = str_replace(["%PLAYER%", "%X%", "%Y%", "%Z%", "%WORLD%", "%IP%", "%XP%"], [$player->getName(), $player->getX(), $player->getY(), $player->getZ(), $player->getLevel()->getName(), $player->getAddress(), $player->getXpLevel()], $cmd);
                         $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd);
                         $player->sendMessage($this->tag . $this->message->get("command"));
                         break;
                     }
                 }
             case 10:
                 //mob
                 if (!isset($this->data["functions"]["mob"]) || $this->data["functions"]["mob"]) {
                     if (count($this->data["mob"])) {
                         $mob = $this->data["mob"][$rand->nextRange(0, count($this->data["mob"]) - 1)];
                         if ($this->isExistsEntity($mob)) {
                             $nbt = new CompoundTag("", [new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ())]), new ListTag("Rotation", [new FloatTag("", $player->getYaw()), new FloatTag("", $player->getPitch())]), new StringTag("CustomName", $this->tag)]);
                             $entity = Entity::createEntity($mob, $player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
                             if ($entity instanceof Entity) {
                                 $entity->spawnToAll();
                                 $this->getServer()->getScheduler()->scheduleDelayedTask(new TaskExplodeMob($this, $entity, mt_rand($this->data["explosion_min"], $this->data["explosion_max"])), 20 * mt_rand(1, $this->data["mob_explosion_delay"]));
                                 $player->sendMessage($this->tag . $this->message->get("mob"));
                                 break;
                             }
                         }
                     }
                 }
             case 11:
                 if (!isset($this->data["functions"]["lightning"]) || $this->data["functions"]["lightning"]) {
                     $player->getLevel()->spawnLightning($player);
                     $player->sendMessage($this->tag . $this->message->get("lightning"));
                     break;
                 }
             case 12:
                 $player->sendMessage($this->tag . $this->message->get("unlucky"));
                 break;
         }
         $player->getLevel()->save();
     }
 }
Ejemplo n.º 5
0
 public function onSignChange(SignChangeEvent $event)
 {
     if (!$event->getPlayer()->hasPermission("potiondispenser.create")) {
         return;
     }
     $text = $event->getLines();
     $prefix = strtoupper($text[0]);
     if ($prefix !== "[DISPENSER]" && $prefix !== "[POTION SHOP]") {
         return;
     }
     $effect = explode(':', $text[1] . $text[2]);
     if (count($effect) < 1) {
         return;
     }
     if ($effect[0] === "clear") {
         $this->registerDispenser(array("name" => "clear", "cost" => (int) $text[3]), $event->getBlock(), $event->getPlayer());
         $event->setLine(0, $this->getTranslation("DISPENSER"));
         $event->setLine(1, TextFormat::GOLD . $this->getTranslation("POTION_NAME_NO_LEV", $this->getTranslation("CLEAR")));
         $event->setLine(2, "");
         $event->setLine(3, $this->getTranslation("DISPENSER_COST", (int) $text[3] . EconomyAPI::getInstance()->getMonetaryUnit()));
         return;
     } elseif (count($effect) < 2) {
         return;
     }
     $effectInstance = Effect::getEffectByName($effect[0]);
     if ($effectInstance === null) {
         $effectInstance = Effect::getEffect($effect[0]);
         if ($effectInstance === null) {
             return;
         }
     }
     $effectId = $effectInstance->getId();
     $amplifier = (int) $effect[1];
     if ($effectInstance instanceof InstantEffect) {
         $duration = 1;
     } else {
         if (count($effect) < 3) {
             return;
         }
         $duration = (int) $effect[2] * 20;
     }
     $this->registerDispenser(array("name" => $effectId, "amplifier" => $amplifier, "duration" => $duration, "cost" => $text[3]), $event->getBlock(), $event->getPlayer());
     $event->setLine(0, $this->getTranslation("DISPENSER"));
     $color = $effectInstance->isBad() ? TextFormat::RED : TextFormat::AQUA;
     $event->setLine(1, $color . $this->getTranslation("POTION_NAME", $this->getServer()->getLanguage()->translate(new TextContainer($effectInstance->getName())), $amplifier + 1));
     if ($effectInstance instanceof InstantEffect) {
         $event->setLine(2, "");
     } else {
         $event->setLine(2, $this->getTranslation("DURATION", (int) $effect[2]));
     }
     $price = (int) $text[3] . EconomyAPI::getInstance()->getMonetaryUnit();
     $event->setLine(3, $this->getTranslation("DISPENSER_COST", $price));
 }
Ejemplo n.º 6
0
 public function Buy($Player, $Menu, $Slot)
 {
     if (!isset($this->plugin->Buys_Values[$Menu][1][$Slot])) {
         return true;
     }
     $BuyData = $this->plugin->Buys_Values[$Menu][1][$Slot];
     if ($this->PopupInfo2->PlayersData[strtolower($Player->getName())][1] >= $BuyData[0]) {
         switch ($BuyData[4]) {
             case 0:
                 $Item = Item::fromString($BuyData[1] . ":" . $BuyData[2]);
                 $Item->setCount($BuyData[3]);
                 if ($Player->getInventory()->canAddItem($Item)) {
                     $Player->getInventory()->addItem(clone $Item);
                     $this->PopupInfo2->PlayersData[strtolower($Player->getName())][1] -= $BuyData[0];
                 } else {
                     $Player->sendPopup($this->plugin->getMessage("bedwars.buy.inv_full"));
                 }
                 break;
             case 1:
                 if (($Effect = Effect::getEffectByName($BuyData[5])) == null && ($Effect = Effect::getEffect($BuyData[5])) == null) {
                     return;
                 }
                 $Effect->setDuration($BuyData[6] * 20);
                 $Effect->setAmplifier($BuyData[7]);
                 $Player->addEffect($Effect);
                 $this->PopupInfo2->PlayersData[strtolower($Player->getName())][1] -= $BuyData[0];
                 break;
         }
     } else {
         $Player->sendPopup($this->plugin->getMessage("bedwars.buy.no_money"));
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * /effect <player> <effect> [seconds] [amplifier] [hideParticles]
  *
  * @param Player $player
  * @param        $effectType
  * @param int    $duration
  * @param int    $amplification
  * @param bool   $hiderParticles
  * @return true
  */
 public static function addEffect(Player $player, $effectType, $duration = 300, $amplification = 0, $hiderParticles = false)
 {
     $effect = Effect::getEffectByName($effectType);
     if ($effect === null) {
         $effect = Effect::getEffect((int) $effectType);
     }
     // $duration = 300;
     $amplification = 0;
     if ($hiderParticles) {
         $effect->setVisible(\false);
     }
     $effect->setDuration($duration)->setAmplifier($amplification);
     $player->addEffect($effect);
     return $effect;
 }
Ejemplo n.º 8
0
 public function onBlockBreak(PlayerInteractEvent $event)
 {
     if ($event->getPlayer() instanceof Player && $this->isPlaying($event->getPlayer())) {
         // effect if in config
         if ($this->getConfig()->exists("blocks." . $event->getBlock()->getName()) && $this->getConfig()->exists("blocks." . $event->getBlock()->getName() . ".effect")) {
             $effect = Effect::getEffectByName($this->getConfig()->getNested("blocks." . $event->getBlock()->getName() . ".effect"));
             if ($effect instanceof Effect) {
                 $effect->setDuration(200);
                 $effect->setVisible(false);
                 $event->getPlayer()->addEffect($effect);
             }
         }
         $event->getPlayer()->getLevel()->setBlock(new Vector3($event->getBlock()->getX(), $event->getBlock()->getY(), $event->getBlock()->getZ()), Block::get(0));
     }
 }
Ejemplo n.º 9
0
 public function execute(CommandSender $sender, $label, array $args)
 {
     $label = "/" . $label . " ";
     if (!$sender->hasPermission("luckyblock.command")) {
         $sender->sendMessage($this->tag . TextFormat::RED . "You do not have permission to use this command!");
         return;
     }
     if (!isset($args) || !isset($args[0])) {
         $args[0] = "help";
     }
     $cmds = "";
     foreach ($args as $var) {
         $cmds = $cmds . "<" . $var . "> ";
     }
     $args[0] = strtolower($args[0]);
     $sender->sendMessage($this->tag . "Usage: " . TextFormat::DARK_AQUA . $label . $cmds);
     switch ($args[0]) {
         case "?":
         case "h":
         case "help":
             $var = ["on <none|function>", "off <none|function>", "list", "potion <add|rmv|list|duration> <effect>", "block <item>", "explosion <min|max|info>", "drop <add|rmv|list|max>", "world <allow|deny|list>", "command", "mob"];
             $message = "";
             foreach ($var as $c) {
                 $message .= $this->tag . TextFormat::WHITE . $label . $c . "\n";
             }
             $message .= $this->tag . TextFormat::GRAY . "Developed by" . TextFormat::BOLD . " @xionbig";
             $sender->sendMessage($message);
             return;
         case "effect":
         case "potion":
             if (!isset($args[1]) || empty($args[1])) {
                 $args[1] = "help";
             }
             switch ($args[1]) {
                 case "?":
                 case "h":
                 case "help":
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . $label . TextFormat::WHITE . " potion " . TextFormat::YELLOW . " <add|rmv|list>");
                     return;
                 case "add":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     if (Effect::getEffectByName($args[2]) instanceof Effect) {
                         if (!in_array($args[2], $this->data["potions"])) {
                             $arr = $this->setup->get("potions");
                             $arr[count($arr)] = $args[2];
                             $this->setup->set("potions", $arr);
                             $sender->sendMessage($this->tag . TextFormat::GREEN . "The potion '" . $args[2] . "' has been added successfully.");
                         } else {
                             $sender->sendMessage($this->tag . TextFormat::YELLOW . "The potion '" . $args[2] . "' is already present in the configuration.");
                         }
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The name of the potion is not valid");
                     }
                     break;
                 case "rmw":
                 case "rmv":
                 case "remove":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     if (in_array($args[2], $this->data["potions"])) {
                         $it = [];
                         foreach ($this->data["potions"] as $i) {
                             if ($i !== $args[2]) {
                                 $it = $args[2];
                             }
                         }
                         $this->setup->set("potions", $it);
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "The potion '" . $args[2] . "' has been successfully removed.");
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "The potion '" . $args[2] . "' was not found in the configuration.");
                     }
                     break;
                 case "list":
                     $list = $this->tag . "List of potions enabled: ";
                     foreach ($this->data["potions"] as $potion) {
                         $list .= $potion . ", ";
                     }
                     $sender->sendMessage($list);
                     return;
                 case "duration":
                     if (!isset($args[2]) || empty($args[2]) || !is_numeric($args[2]) || $args[2] < 1) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $this->setup->set("max_duration", $args[2]);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "The maximum duration of potion is set to " . $args[2]);
                     break;
             }
             $this->luckyBlock->reloadSetup($this->data);
             return;
         case "item":
         case "drop":
             if (!isset($args[1]) || empty($args[1])) {
                 $args[1] = "help";
             }
             switch ($args[1]) {
                 case "?":
                 case "h":
                 case "help":
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . $label . TextFormat::WHITE . " drop " . TextFormat::YELLOW . " <add|rmv|list>");
                     return;
                 case "add":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $item = $this->luckyBlock->getItem($args[2]);
                     if ($item->getId() != Item::AIR) {
                         if (!$this->luckyBlock->isExists($this->data["items_dropped"], $item)) {
                             $arr = $this->setup->get("items_dropped");
                             $arr[count($arr)] = $item->getId() . ":" . $item->getDamage();
                             $this->setup->set("items_dropped", $arr);
                             $sender->sendMessage($this->tag . TextFormat::GREEN . "The item '" . $item->getName() . "' has been added successfully.");
                         } else {
                             $sender->sendMessage($this->tag . TextFormat::YELLOW . "The item '" . $item->getName() . "' is already present in the configuration.");
                         }
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The item is not valid.");
                     }
                     break;
                 case "rmw":
                 case "rmv":
                 case "remove":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $item = $this->luckyBlock->getItem($args[2]);
                     if ($item->getId() != Item::AIR) {
                         if ($this->luckyBlock->isExists($this->data["items_dropped"], $item)) {
                             $it = [];
                             foreach ($this->data["items_dropped"] as $i) {
                                 if ($i->getId() !== $item->getId() && $i->getDamage() !== $item->getId()) {
                                     $it[] = $i->getId() . ":" . $i->getDamage();
                                 }
                             }
                             $this->setup->set("items_dropped", $it);
                             $sender->sendMessage($this->tag . TextFormat::GREEN . "The item '" . $item->getName() . "' has been successfully removed.");
                         } else {
                             $sender->sendMessage($this->tag . TextFormat::GREEN . "The item '" . $item->getName() . "' was not found in the configuration.");
                         }
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The item is not valid.");
                     }
                     break;
                 case "list":
                     $list = $this->tag . "List of items: ";
                     foreach ($this->data["items_dropped"] as $item) {
                         $list .= $item->getName() . "(id=" . $item->getId() . " damage=" . $item->getDamage() . "); ";
                     }
                     $sender->sendMessage($list);
                     break;
                 case "max":
                     if (!isset($args[2]) || !is_numeric($args[2]) || $args[2] <= 0) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $this->setup->set("max_chest_item", $args[2]);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "The maximum of the items generated inside the chest set to " . $args[2]);
                     break;
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "explosion":
             if (!isset($args[1]) || empty($args[1])) {
                 $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                 return;
             }
             switch ($args[1]) {
                 case "min":
                     if (!isset($args[2]) || !is_numeric($args[2]) || $args[2] < 0) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $this->setup->set("explosion_min", $args[2]);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "Explosion set minimum at " . $args[2]);
                     break;
                 case "max":
                     if (!isset($args[2]) || !is_numeric($args[2]) || $args[2] < 0) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $this->setup->set("explosion_max", $args[2]);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "Explosion set maximum at " . $args[2]);
                     break;
                 case "info":
                     $sender->sendMessage($this->tag . TextFormat::AQUA . "Explosion set minimum " . $this->data["explosion_min"] . " and maximum " . $this->data["explosion_max"]);
                     return;
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "block":
             //luckyblock
             if (!isset($args[1]) || empty($args[1])) {
                 $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                 return;
             }
             $item = $this->luckyBlock->getItem($args[1]);
             if ($item->getId() != Item::AIR) {
                 $this->setup->set("lucky_block", $item->getId() . ":" . $item->getDamage());
                 $sender->sendMessage($this->tag . TextFormat::GREEN . "Now the LuckyBlock is " . $item->getName());
             } else {
                 $sender->sendMessage($this->tag . TextFormat::RED . "The item is not valid.");
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "world":
             if (!isset($args[1]) || empty($args[1])) {
                 $args[1] = "help";
             }
             switch ($args[1]) {
                 case "?":
                 case "h":
                 case "help":
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . $label . TextFormat::WHITE . " world " . TextFormat::YELLOW . " <add|rmv|list>");
                     return;
                 case "allow":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     unset($args[0]);
                     unset($args[1]);
                     $level = "";
                     foreach ($args as $a) {
                         $level .= $a . " ";
                     }
                     $level = trim($level);
                     $get = $this->data["level"];
                     $get[] = $level;
                     $this->setup->set("level", $get);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "You have allowed to use LuckyBlock in world '" . $level . "'");
                     break;
                 case "allowall":
                     $this->setup->set("level", []);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "You have allowed to use LuckyBlock in all worlds!");
                     break;
                 case "deny":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $args = array_slice($args, 2);
                     $level = "";
                     foreach ($args as $a) {
                         $level .= $a . " ";
                     }
                     $level = trim($level);
                     $get = $this->data["level"];
                     $found = false;
                     foreach ($get as $c => $w) {
                         if (strtolower($w) == strtolower($level)) {
                             unset($get[$c]);
                             $found = true;
                         }
                     }
                     if ($found) {
                         $this->setup->set("level", $get);
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "The world '" . $level . "' has been removed from the configuration.");
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The world '" . $level . "' does not exist in the configuration.");
                     }
                     break;
                 case "list":
                     if (count($this->data["level"]) == 0) {
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "Players can use LuckyBlock in all worlds!");
                         break;
                     }
                     $list = $this->tag . "List of worlds allowed: ";
                     foreach ($this->data["level"] as $level) {
                         $list .= $level . "; ";
                     }
                     $sender->sendMessage($list);
                     break;
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "cmd":
         case "command":
         case "commands":
             if (!isset($args[1]) || empty($args[1])) {
                 $args[1] = "help";
             }
             switch ($args[1]) {
                 case "?":
                 case "h":
                 case "help":
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . $label . TextFormat::WHITE . " command " . TextFormat::YELLOW . " <add|rmv|list>");
                     return;
                 case "add":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $command = "";
                     $arg = array_slice($args, 2);
                     foreach ($arg as $a) {
                         $command .= " " . $a;
                     }
                     $arr = $this->setup->get("commands");
                     $command = trim(str_replace("/", "", $command));
                     $arr[count($arr)] = $command;
                     $this->setup->set("commands", $arr);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "The command '/" . $command . "' has been added successfully!");
                     break;
                 case "rmw":
                 case "rmv":
                 case "remove":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $command = "";
                     $arg = array_slice($args, 2);
                     foreach ($arg as $a) {
                         $command .= " " . $a;
                     }
                     $command = trim(str_replace("/", "", $command));
                     $get = $this->data["commands"];
                     $found = false;
                     foreach ($get as $c => $w) {
                         if (trim(str_replace("/", "", $w)) == $command) {
                             unset($get[$c]);
                             $found = true;
                         }
                     }
                     if ($found) {
                         $this->setup->set("commands", $get);
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "The command '/" . $command . "' has been removed from the configuration.");
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The command '/" . $command . "' does not exist in the configuration.");
                     }
                     break;
                 case "list":
                     if (count($this->data["commands"]) == 0) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "There aren't stored commands!");
                         break;
                     }
                     $sender->sendMessage($this->tag . "List of commands: ");
                     foreach ($this->data["commands"] as $c) {
                         $sender->sendMessage("- /" . $c);
                     }
                     break;
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "mob":
             if (!isset($args[1]) || empty($args[1])) {
                 $args[1] = "help";
             }
             switch ($args[1]) {
                 case "?":
                 case "h":
                 case "help":
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . $label . TextFormat::WHITE . " mob " . TextFormat::YELLOW . " <add|rmv|delay|list>");
                     return;
                 case "add":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $mob = "";
                     $arg = array_slice($args, 2);
                     foreach ($arg as $a) {
                         $mob .= " " . $a;
                     }
                     $arr = $this->setup->get("mob");
                     $mob = str_replace(" ", "", ucwords($mob));
                     if ($this->luckyBlock->isExistsEntity($mob)) {
                         $found = false;
                         foreach ($arr as $c => $w) {
                             if (str_replace(" ", "", $w) == $mob) {
                                 $found = true;
                             }
                         }
                         if ($found) {
                             $sender->sendMessage($this->tag . TextFormat::YELLOW . "The entity '" . $mob . "' has already been added.");
                             return;
                         } else {
                             $arr[count($arr)] = $mob;
                             $this->setup->set("mob", $arr);
                             $sender->sendMessage($this->tag . TextFormat::GREEN . "The mob '" . $mob . "' has been added successfully!");
                         }
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The entity '" . $mob . "' isn't valid.");
                         return;
                     }
                     break;
                 case "rmw":
                 case "rmv":
                 case "remove":
                     if (!isset($args[2]) || empty($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $mob = "";
                     $arg = array_slice($args, 2);
                     foreach ($arg as $a) {
                         $mob .= " " . $a;
                     }
                     $arr = $this->data["mob"];
                     $mob = str_replace(" ", "", ucwords($mob));
                     $found = false;
                     foreach ($arr as $c => $w) {
                         if (str_replace(" ", "", $w) == $mob) {
                             unset($arr[$c]);
                             $found = true;
                         }
                     }
                     if ($found) {
                         $sender->sendMessage($this->tag . TextFormat::GREEN . "The entity '" . $mob . "' has been removed successfully.");
                         $this->setup->set("mob", $arr);
                     } else {
                         $sender->sendMessage($this->tag . TextFormat::RED . "The mob '" . $mob . "' doesn't exist in the configuration!");
                         return;
                     }
                     break;
                 case "delay":
                     if (!isset($args[2]) || empty($args[2]) || !is_numeric($args[2])) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "Invalid parameters.");
                         return;
                     }
                     $this->setup->set("mob_explosion_delay", $args[2]);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "The explosion delay of the mob is set to " . $args[2]);
                     break;
                 case "list":
                     if (count($this->data["mob"]) == 0) {
                         $sender->sendMessage($this->tag . TextFormat::RED . "There aren't stored mobs!");
                         break;
                     }
                     $list = $this->tag . "List of mobs: ";
                     foreach ($this->data["mob"] as $c) {
                         $list .= $c . "; ";
                     }
                     $sender->sendMessage($list);
                     break;
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "on":
         case "true":
             if (!isset($args[1]) || empty($args[1])) {
                 $this->setup->set("status", "on");
                 $sender->sendMessage($this->tag . TextFormat::GREEN . "Plugin activated!");
             } else {
                 $arr = $this->data["functions"];
                 $found = false;
                 foreach ($arr as $c => $w) {
                     if (strtolower($c) == strtolower($args[1])) {
                         $arr[$c] = true;
                         $found = true;
                     }
                 }
                 if ($found) {
                     $this->setup->set("functions", $arr);
                     $sender->sendMessage($this->tag . TextFormat::GREEN . "The function '" . $args[1] . "' has been enabled!");
                 } else {
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . "The function " . $args[1] . " was not found!");
                 }
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "off":
         case "false":
             if (!isset($args[1]) || empty($args[1])) {
                 $this->setup->set("status", "off");
                 $sender->sendMessage($this->tag . TextFormat::RED . "Plugin disabled!");
             } else {
                 $arr = $this->data["functions"];
                 $found = false;
                 foreach ($arr as $c => $w) {
                     if (strtolower($c) == strtolower($args[1])) {
                         $arr[$c] = false;
                         $found = true;
                     }
                 }
                 if ($found) {
                     $this->setup->set("functions", $arr);
                     $sender->sendMessage($this->tag . TextFormat::RED . "The function '" . $args[1] . "' has been disabled!");
                 } else {
                     $sender->sendMessage($this->tag . TextFormat::YELLOW . "The function " . $args[1] . " was not found!");
                 }
             }
             $this->luckyBlock->reloadSetup($this->data, $this->setup);
             return;
         case "list":
             $sender->sendMessage($this->tag . "List of functions:");
             foreach ($this->data["functions"] as $f => $v) {
                 $text = $v == true ? TextFormat::GREEN . "enabled" : TextFormat::RED . "disabled";
                 $sender->sendMessage("- " . TextFormat::AQUA . $f . TextFormat::WHITE . " => " . $text);
             }
             return;
     }
     $sender->sendMessage($this->tag . TextFormat::RED . "The command does not exist!");
 }