diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..aaa4a01 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,38 @@ +name: PiggyCustomEnchants +main: PiggyCustomEnchants\Main +version: 1.1.3 +api: [1.1.3, 2.0.0, 2.0.1, 3.0.0, 3.0.1, 3.0.0-ALPHA1, 3.0.0-ALPHA2, 3.0.0-ALPHA3, 3.0.0-ALPHA4, 3.0.0-ALPHA5, 3.0.0-ALPHA6, 3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11, 3.0.0-ALPHA12, 3.0.0-ALPHA13, 3.0.0-ALPHA14, 3.0.0-ALPHA15] +load: POSTWORLD +author: DaPigGuy +translator: GamerSoiCon +permissions: + piggycustomenchants: + default: false + description: "Sử dụng mọi thứ trong PiggyCustomEnchants" + children: + piggycustomenchants.command: + default: op + description: "Sử dụng tất cả lệnh trong PiggyCustomEnchants " + children: + piggycustomenchants.command.ce: + default: op + description: "Sử dụng /customenchant" + children: + piggycustomenchants.command.ce.about: + default: true + description: "Sử dụng /customenchant about" + piggycustomenchants.command.ce.enchant: + default: op + description: "Sử dụng /customenchant enchant" + piggycustomenchants.command.ce.help: + default: true + description: "Sử dụng /customenchant help" + piggycustomenchants.command.ce.info: + default: true + description: "Sử dụng /customenchant info" + piggycustomenchants.command.ce.list: + default: true + description: "Sử dụng /customenchant list" + piggycustomenchants.overridecheck: + default: false + description: "Có thể dùng CustomEnchants Book lên Item và Enchant lên vật phẩm với bất cứ CE nào" diff --git a/resources/PCE_Icon.png b/resources/PCE_Icon.png new file mode 100644 index 0000000..d73fd11 Binary files /dev/null and b/resources/PCE_Icon.png differ diff --git a/resources/config.yml b/resources/config.yml new file mode 100644 index 0000000..a742435 --- /dev/null +++ b/resources/config.yml @@ -0,0 +1,40 @@ +# config.yml được việt hóa bởi Sói +#,-.----. +#\ / \ ,----.. ,---,. +#| : \ ,--, / / \ ,' .' | +#| | .\ :,--.'| | : :,---.' | +#. : |: || |, ,----._,. ,----._,. . | ;. /| | .' +#| | \ :`--'_ / / ' / / / ' / .--,. ; /--` : : |-, +#| : . /,' ,'| | : || : | /_ ./|; | ; : | ;/| +#; | |`-' ' | | | | .\ .| | .\ ., ' , ' :| : | | : .' +#| | ; | | : . ; '; |. ; '; /___/ \: |. | '___ | | |-, +#: ' | ' : |__' . . |' . . |. \ ' |' ; : .'|' : ;/| +#: : : | | '.'|`---`-'| | `---`-'| | \ ; :' | '/ :| | \ +#| | : ; : ;.'__/\_: | .'__/\_: | \ \ ;| : / | : .' +#`---'.| | , / | : : | : : : \ \\ \ .' | | ,' +# `---` ---`-' \ \ / \ \ / \ ' ; `---` `----' +# `--`-' `--`-' `--` + +# Tùy chỉnh màu cho Enchants tùy vào độ hiếm +# Danh sách màu có thể dùng : +# black, dark_blue, dark_green, dark_aqua, dark_red, dark_purple, gold, gray, dark_gray, blue, green, aqua, red, light_purple, yellow, and white. +color: + common: yellow + uncommon: blue + rare: gold + mythic: light_purple +# true/false để bật/tắt tính năng (UIs) FormAPI bởi Jojoe77777. Yêu cầu cài plugin FormAPI tại đây : http://123link.pw/1v62p +forms: + enabled: false +# Vô hiệu hóa để ngăn chặn lửa lan từ Blaze Enchants. (Khuyên các bạn nên để false) +blaze: + flames: false +# Drop vật phẩm khi giết vật/người từ Chicken Enchant. Mẫu: ("id:meta:số lượng"). Nếu lượng drop nhiều, plugin sẽ tự chọn ngẫn nhiên <3 VD : ["266:0:1", "264:0:64"] +chicken: + rare-drop: ["266:0:1"] +# Nếu bạn để trống phần này, vật phẩm có Enchant Jetpack sẽ có thể bay bất kì nơi nào trong server, ngược lại khi điền tên world, Jetpack sẽ không thể bay ở world đó, VD : ["PvPArena", "AnotherWorld"] +jetpack: + disabled: [] +# Vô hiệu hóa để ngăn chặn lửa lan từ Lightning Enchants. (Khuyên các bạn nên để false) +lightning: + flames: false diff --git a/src/PiggyCustomEnchants/Blocks/PiggyObsidian.php b/src/PiggyCustomEnchants/Blocks/PiggyObsidian.php new file mode 100644 index 0000000..27aa4af --- /dev/null +++ b/src/PiggyCustomEnchants/Blocks/PiggyObsidian.php @@ -0,0 +1,64 @@ +isMagmaWalker() ? "Magmawalker Obsidian" : "Obsidian"; + } + + public function isMagmaWalker() + { + return $this->getDamage() == 15; + } + + public function onRandomTick() : void + { + if ($this->isMagmaWalker()) { + $count = 0; + $random = mt_rand(0, 100); + for ($x = -1; $x <= 1; $x++) { + for ($z = -1; $z <= 1; $z++) { + $pos = $this->add($x, 0, $z); + if ($this !== $pos) { + $block = $this->getLevel()->getBlock($pos); + if ($block->getId() == $this->getId() && $block->isMagmaWalker()) { + $count++; + } + } + } + } + if ($random <= 33.33 || $count < 4) { + $this->age++; + } + if ($this->age >= 4) { + $this->getLevel()->useBreakOn($this); + } + $this->getLevel()->scheduleDelayedBlockUpdate($this, mt_rand(1, 2) * 20); + } + } + + public function onBreak(Item $item, Player $player = null): bool + { + return $this->getLevel()->setBlock($this, Block::get($this->isMagmaWalker() ? Block::LAVA : Block::AIR), true, true); + } + + public function getDrops(Item $item): array + { + return $this->isMagmaWalker() ? [] : parent::getDrops($item); + } +} diff --git a/src/PiggyCustomEnchants/Commands/CustomEnchantCommand.php b/src/PiggyCustomEnchants/Commands/CustomEnchantCommand.php new file mode 100644 index 0000000..7ff0e07 --- /dev/null +++ b/src/PiggyCustomEnchants/Commands/CustomEnchantCommand.php @@ -0,0 +1,469 @@ +setDescription("Enchant với Custom Enchants"); + $this->setUsage("/customenchant "); + $this->setAliases(["ce", "customenchants", "customenchantments", "customenchant", "phuphep", "soicon", "gamersoicon"]); + $this->setPermission("piggycustomenchants.command.ce"); + } + + public function execute(CommandSender $sender, string $commandLabel, array $args): bool + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + $forms = $sender instanceof Player && $plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled(); + if (count($args) < 1) { + if ($forms) { + $this->formMenu($sender); + return true; + } + $sender->sendMessage(TextFormat::RED . "Sử dụng: /customenchant "); + return false; + } + switch ($args[0]) { + case "about": + if (!$sender->hasPermission("piggycustomenchants.command.ce.about")) { + $this->error($sender, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + if ($forms) { + $this->aboutForm($sender); + return true; + } + $sender->sendMessage(TextFormat::GREEN . "PiggyCustomEnchants v" . $this->getPlugin()->getDescription()->getVersion() . " là một plugin Custom Enchants được làm bởi DaPigGuy (IGN: MCPEPIG) & Aericio & Translate by GamerSoiCon.\n" . TextFormat::GREEN . "Bạn có thể tìm thấy plugin tại https://github.com/DaPigGuy/PiggyCustomEnchants."); + break; + case "enchant": + if (!$sender->hasPermission("piggycustomenchants.command.ce.enchant")) { + $this->error($sender, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + if (count($args) < 2) { + if ($forms) { + $this->enchantForm($sender); + return true; + } + $sender->sendMessage(TextFormat::RED . "Sử dụng: /customenchant enchant [cấp độ] [người chơi]"); + return false; + } + if ($forms) { + $this->checkEnchantForm($sender, [$args[1], isset($args[2]) ? $args[2] : 1, isset($args[3]) ? $args[3] : $sender->getName()]); + return true; + } + $this->enchant($sender, $args[1], isset($args[2]) ? $args[2] : 1, isset($args[3]) ? $args[3] : $sender->getName()); + break; + case "help": + if (!$sender->hasPermission("piggycustomenchants.command.ce.help")) { + $this->error($sender, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + if ($forms) { + $this->helpForm($sender); + return true; + } + $sender->sendMessage(TextFormat::GREEN . "---PiggyCE Trợ Giúp---\n" . TextFormat::RESET . "/ce about: Hiển thị thông tin về plugin\n/ce enchant: Phù phép vật phẩm\n/ce help: Hiển thị trợ giúp\n/ce info: Xem mô tả của một Enchant bất kì\n/ce list: Hiển thị danh sách enchant"); + break; + case "info": + if (!$sender->hasPermission("piggycustomenchants.command.ce.info")) { + $this->error($sender, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + if (count($args) < 2) { + if ($forms) { + $this->infoForm($sender); + return true; + } + $sender->sendMessage(TextFormat::RED . "Sử dụng: /customenchant info "); + return false; + } + if ($forms) { + $this->sendInfo($sender, $args[1]); + return true; + } + if ((is_numeric($args[1]) && ($enchant = CustomEnchants::getEnchantment($args[1])) !== null) || ($enchant = CustomEnchants::getEnchantmentByName($args[1])) !== null) { + $sender->sendMessage(TextFormat::GREEN . $enchant->getName() . "\n" . TextFormat::RESET . "▶ ID: " . $enchant->getId() . "\n▶ MÔ TẢ: " . $plugin->getEnchantDescription($enchant) . "\n▶ LOẠI: " . $plugin->getEnchantType($enchant) . "\n▶ ĐỘ HIẾM: " . $plugin->getEnchantRarity($enchant) . "\n▶ LEVEL TỐI ĐA: " . $plugin->getEnchantMaxLevel($enchant)); + } else { + $sender->sendMessage(TextFormat::RED . "Enchant không hợp lệ."); + } + break; + case "list": + if (!$sender->hasPermission("piggycustomenchants.command.ce.list")) { + $this->error($sender, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + if ($forms) { + $this->listForm($sender); + return true; + } + $sender->sendMessage($this->list()); + break; + default: + if ($forms) { + $this->formMenu($sender); + return true; + } + $sender->sendMessage(TextFormat::RED . "Sử dụng: /customenchant "); + break; + } + return true; + } + return false; + } + + public function formMenu(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + switch ($data[0]) { + case 0: + if (!$player->hasPermission("piggycustomenchants.command.ce.about")) { + $this->errorForm($player, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + $this->aboutForm($player); + break; + case 1: + if (!$player->hasPermission("piggycustomenchants.command.ce.enchant")) { + $this->errorForm($player, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + $this->enchantForm($player); + break; + case 2: + if (!$player->hasPermission("piggycustomenchants.command.ce.help")) { + $this->errorForm($player, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + $this->helpForm($player); + break; + case 3: + if (!$player->hasPermission("piggycustomenchants.command.ce.info")) { + $this->errorForm($player, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + $this->infoForm($player); + break; + case 4: + if (!$player->hasPermission("piggycustomenchants.command.ce.list")) { + $this->errorForm($player, TextFormat::RED . "Bạn không có quyền để làm điều này !"); + return false; + } + $this->listForm($player); + break; + } + return true; + } + return false; + }); + $form->setTitle(TextFormat::GREEN . "── Custom Enchants Menu ──"); + $form->addButton("▶ Thông Tin Plugin"); + $form->addButton("▶ Phù Phép Item"); + $form->addButton("▶ Trợ Giúp"); + $form->addButton("▶ Thông Tin Enchants"); + $form->addButton("▶ Danh Sách Enchants"); + $form->sendToPlayer($player); + } + } + } + + public function error(CommandSender $sender, $error) + { + if ($sender instanceof Player) { + if ($this->errorForm($sender, $error)) { + return true; + } + } + $sender->sendMessage($error); + return true; + } + + public function errorForm(Player $player, $error) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->formMenu($player); + return true; + } + return false; + }); + $form->setTitle(TextFormat::RED . "── Lỗi ──"); + $form->setContent($error); + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + return true; + } + return false; + } + return false; + } + + public function aboutForm(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->formMenu($player); + return true; + } + return false; + }); + $form->setTitle(TextFormat::GREEN . "── Thông Tin Plugin ──"); + $form->setContent(TextFormat::GREEN . "▶ PiggyCustomEnchants v" . $this->getPlugin()->getDescription()->getVersion() . " là một plugin Custom Enchants được tạo bởi DaPigGuy (IGN: MCPEPIG) & Aericio & Translate by GamerSoiCon. Bạn có thể tìm thấy plugin tại https://github.com/DaPigGuy/PiggyCustomEnchants."); + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + } + } + } + + public function enchantForm(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createCustomForm(function (Player $player, $data) { + if (isset($data[0]) && isset($data[1]) && isset($data[2])) { + $this->checkEnchantForm($player, $data); + return true; + } + return false; + }); + $form->setTitle(TextFormat::GREEN . "── Enchant ──"); + $form->addInput(TextFormat::GREEN . "▶ Loại Enchant"); + $form->addInput(TextFormat::GREEN . "▶ Cấp Độ", "", 1); + $form->addInput(TextFormat::GREEN . "▶ Người Chơi", "", $player->getName()); + $form->sendToPlayer($player); + return true; + } + return false; + } + return false; + } + + public function checkEnchantForm(Player $player, $data) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $enchant = null; + if (is_numeric($data[0])) { + $enchant = CustomEnchants::getEnchantment((int)$data[0]); + } else { + $enchant = CustomEnchants::getEnchantmentByName($data[0]); + } + if ($enchant == null) { + $this->errorForm($player, TextFormat::RED . "Enchant không hợp lệ !"); + return false; + } + $target = $this->getPlugin()->getServer()->getPlayer($data[2]); + if (!$target instanceof Player) { + $this->errorForm($player, TextFormat::RED . "Không tìm thấy người chơi !"); + return false; + } + if (!$player->hasPermission("piggycustomenchants.overridecheck")) { + $result = $plugin->canBeEnchanted($target->getInventory()->getItemInHand(), $enchant, $data[1]); + if ($result !== true) { + switch ($result) { + case Main::NOT_COMPATIBLE: + $this->errorForm($player, TextFormat::RED . "Item này không thể kết hợp với enchant !"); + break; + case Main::NOT_COMPATIBLE_WITH_OTHER_ENCHANT: + $this->errorForm($player, TextFormat::RED . "Enchant này không thể kết hợp với enchant khác !"); + break; + case Main::MAX_LEVEL: + $this->errorForm($player, TextFormat::RED . "Cấp độ tối đa là " . $plugin->getEnchantMaxLevel($enchant) . "."); + break; + case Main::MORE_THAN_ONE: + $this->errorForm($player, TextFormat::RED . "Bạn chỉ có thể enchant item với một khoảng thời gian nhất định !"); + break; + } + return false; + } + } + $this->enchant($player, $data[0], $data[1], $data[2]); + return true; + } + return false; + } + return false; + } + + public function helpForm(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->formMenu($player); + return true; + } + return false; + }); + $form->setTitle(TextFormat::GREEN . "── Trợ Giúp ──"); + $form->setContent(TextFormat::GREEN . "▶ Nói cho tôi biết bạn đang nói đùa đi... Tại sao bạn thậm chí cần một trình đơn trợ giúp khi bạn có giao diện người dùng? Chờ đã ... tại sao điều này lại ở đây?"); + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + } + } + } + + public function infoForm(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createCustomForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->sendInfo($player, $data[0]); + } + }); + $form->setTitle(TextFormat::GREEN . "── Thông Tin Enchants ──"); + $form->addInput(TextFormat::GREEN . "▶ Enchantment"); + $form->sendToPlayer($player); + return true; + } + return false; + } + return false; + } + + public function sendInfo(Player $player, $enchant) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->formMenu($player); + return true; + } + return false; + }); + if ((is_numeric($enchant) && ($enchant = CustomEnchants::getEnchantment($enchant)) !== null) || ($enchant = CustomEnchants::getEnchantmentByName($enchant)) !== null) { + $form->setTitle(TextFormat::GREEN . "── Thông Tin Enchants ──"); + $form->setContent(TextFormat::GREEN . $enchant->getName() . "\n" . TextFormat::RESET . "▶ ID: " . $enchant->getId() . "\n▶ MÔ TẢ: " . $plugin->getEnchantDescription($enchant) . "\n▶ LOẠI: " . $plugin->getEnchantType($enchant) . "\n▶ ĐỘ HIẾM: " . $plugin->getEnchantRarity($enchant) . "\n▶ CẤP ĐỘ TỐI ĐA: " . $plugin->getEnchantMaxLevel($enchant)); + } else { + $form->setTitle(TextFormat::RED . "Lỗi"); + $form->setContent(TextFormat::RED . "Enchant không hợp lệ !"); + } + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + return true; + } + return false; + } + return false; + } + + public function listForm(Player $player) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $sorted = $this->getPlugin()->sortEnchants(); + foreach ($sorted as $type => $enchants) { + if (array_search($type, array_keys($sorted)) == $data[0]) { + $this->sendList($player, $type); + return true; + } + } + $this->formMenu($player); + } + return false; + }); + $form->setTitle(TextFormat::GREEN . "── Danh Sách Enchants ──"); + $sorted = $plugin->sortEnchants(); + foreach ($sorted as $type => $enchants) { + $form->addButton($type); + } + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + return true; + } + return false; + } + return false; + } + + public function sendList(Player $player, $type) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if ($plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if (isset($data[0])) { + $this->formMenu($player); + return true; + } + return false; + }); + $form->setContent(TextFormat::GREEN . TextFormat::BOLD . $type . "\n" . TextFormat::RESET . implode(", ", $this->getPlugin()->sortEnchants()[$type])); + $form->addButton(TextFormat::BOLD . "Trở về"); + $form->sendToPlayer($player); + } + } + } + + public function enchant(CommandSender $sender, $enchantment, $level, $target) + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + if (!is_numeric($level)) { + $level = 1; + $sender->sendMessage(TextFormat::RED . "Cấp độ phải là số !"); + } + $target == null ? $target = $sender : $target = $this->getPlugin()->getServer()->getPlayer($target); + if (!$target instanceof Player) { + if ($target instanceof ConsoleCommandSender) { + $sender->sendMessage(TextFormat::RED . "Hãy điền tên người chơi !"); + return false; + } + $sender->sendMessage(TextFormat::RED . "Người chơi không hợp lệ !"); + return false; + } + $target->getInventory()->setItemInHand($plugin->addEnchantment($target->getInventory()->getItemInHand(), $enchantment, $level, $sender->hasPermission("piggycustomenchants.overridecheck") ? false : true, $sender)); + return true; + } + return false; + } + + + public function list() + { + $plugin = $this->getPlugin(); + if ($plugin instanceof Main) { + $sorted = $plugin->sortEnchants(); + $list = ""; + foreach ($sorted as $type => $enchants) { + $list .= "\n" . TextFormat::GREEN . TextFormat::BOLD . $type . "\n" . TextFormat::RESET; + $list .= implode(", ", $enchants); + } + return $list; + } + return ""; + } +} diff --git a/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php new file mode 100644 index 0000000..25df276 --- /dev/null +++ b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchants.php @@ -0,0 +1,35 @@ + $enchantment) { + $vanillaenchants[$id] = $enchantment; + } + parent::$enchantments = $vanillaenchants; + } + + public static function getEnchantmentByName(string $name) + { + $const = CustomEnchantsIds::class . "::" . strtoupper($name); + if (defined($const)) { + return self::getEnchantment(constant($const)); + } + return null; + } + + public static function unregisterEnchantment($id) + { + if (isset(parent::$enchantments[$id])) { + unset(parent::$enchantments[$id]); + return true; + } + return false; + } +} diff --git a/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php new file mode 100644 index 0000000..4edc8ca --- /dev/null +++ b/src/PiggyCustomEnchants/CustomEnchants/CustomEnchantsIds.php @@ -0,0 +1,106 @@ + [1, false, false, Item::AIR, ""], + 2 => [2, false, false, Item::RAW_PORKCHOP, "Mysterious Raw Pork"], + 3 => [2, false, false, Item::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 4 => [3, true, false, Item::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 5 => [5, false, true, Item::ROTTEN_FLESH, "Mysterious Rotten Pork"], + 6 => [6, true, true, Item::ROTTEN_FLESH, "Mysterious Rotten Pork"] + ]; + + public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null, bool $placeholder = false, int $porklevel = 1) + { + if ($porklevel < 1) { + $porklevel = 1; + } + if ($porklevel > 6) { + $porklevel = 6; + } + $values = self::PORKLEVELS[$porklevel]; + $this->damage = $values[0]; + if ($values[1]) { + $this->setNameTag("Dinnerbone"); + } + $this->zombie = $values[2]; + $this->porklevel = $porklevel; + parent::__construct($level, $nbt, $shootingEntity, $placeholder); + } + + public function entityBaseTick(int $tickDiff = 1): bool + { + if ($this->closed) { + return false; + } + $hasUpdate = parent::entityBaseTick($tickDiff); + if (!$this->isCollided) { + if ($this->getPorkLevel() > 1) { + foreach ($this->getDrops() as $drop) { + $droppeditem = $this->getLevel()->dropItem($this, $drop); + $droppeditem->age = 5700; //300 ticks (15 seconds) til despawns} + } + } + } else { + $this->flagForDespawn(); + $hasUpdate = true; + } + return $hasUpdate; + } + + protected function sendSpawnPacket(Player $player): void + { + $pk = new AddEntityPacket(); + $pk->type = $this->isZombie() ? Entity::ZOMBIE_PIGMAN : static::TYPE_ID; + $pk->entityRuntimeId = $this->getId(); + $pk->position = $this->asVector3(); + $pk->motion = $this->getMotion(); + $pk->metadata = $this->propertyManager->getAll(); + $player->dataPacket($pk); + } + + public function getDrops(): array + { + $values = self::PORKLEVELS[$this->getPorkLevel()]; + return [ + Item::get($values[3], 0, 1)->setCustomName($values[4]) + ]; + } + + public function getPorkLevel() + { + return $this->porklevel; + } + + public function isZombie() + { + return $this->zombie; + } +} diff --git a/src/PiggyCustomEnchants/Entities/PiggyFireball.php b/src/PiggyCustomEnchants/Entities/PiggyFireball.php new file mode 100644 index 0000000..4c79d2f --- /dev/null +++ b/src/PiggyCustomEnchants/Entities/PiggyFireball.php @@ -0,0 +1,49 @@ +server->getPluginManager()->callEvent($ev); + if (!$ev->isCancelled()) { + $entity->setOnFire($ev->getDuration()); + } + parent::onCollideWithEntity($entity); + } + + public function entityBaseTick(int $tickDiff = 1): bool + { + if ($this->closed) { + return false; + } + if (!$this->isFlaggedForDespawn()) { + if ($this->blockHit !== null) { + if (($this->isCollidedHorizontally || $this->isCollidedVertically) && $this->getLevel()->getBlock($this)->canBeFlowedInto() && Main::$blazeFlames) { + $this->getLevel()->setBlock($this, Block::get(Block::FIRE)); + } + $this->flagForDespawn(); + } + } + $hasUpdate = parent::entityBaseTick($tickDiff); + return $hasUpdate; + } +} diff --git a/src/PiggyCustomEnchants/Entities/PiggyLightning.php b/src/PiggyCustomEnchants/Entities/PiggyLightning.php new file mode 100644 index 0000000..be75088 --- /dev/null +++ b/src/PiggyCustomEnchants/Entities/PiggyLightning.php @@ -0,0 +1,61 @@ +closed) { + return false; + } + $hasUpdate = parent::entityBaseTick($tickDiff); + foreach ($this->getLevel()->getNearbyEntities($this->getBoundingBox()->grow(4, 3, 4), $this) as $entity) { + if ($entity instanceof Living && $entity->isAlive() && $this->getOwningEntityId() !== $entity->getId()) { + $ev = new EntityCombustByEntityEvent($this, $entity, mt_rand(3, 8)); + $this->server->getPluginManager()->callEvent($ev); + if (!$ev->isCancelled()) { + $entity->setOnFire($ev->getDuration()); + } + $ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageEvent::CAUSE_CUSTOM, 5); + $this->server->getPluginManager()->callEvent($ev); + if (!$ev->isCancelled()) { + $entity->attack($ev); + } + } + } + if ($this->getLevel()->getBlock($this)->canBeFlowedInto() && Main::$lightningFlames) { + $this->getLevel()->setBlock($this, Block::get(Block::FIRE)); + } + if ($this->age > 20) { + $this->flagForDespawn(); + } + return $hasUpdate; + } + public function spawnTo(Player $player): void + { + $pk = new AddEntityPacket(); + $pk->entityRuntimeId = $this->getId(); + $pk->type = static::TYPE_ID; + $pk->position = $this->asVector3(); + $pk->motion = $this->getMotion(); + $pk->metadata = $this->propertyManager->getAll(); + $player->dataPacket($pk); + } +} diff --git a/src/PiggyCustomEnchants/Entities/PiggyProjectile.php b/src/PiggyCustomEnchants/Entities/PiggyProjectile.php new file mode 100644 index 0000000..fbb06fb --- /dev/null +++ b/src/PiggyCustomEnchants/Entities/PiggyProjectile.php @@ -0,0 +1,60 @@ +placeholder = $placeholder; + $this->ownerOriginalLocation = $shootingEntity->getPosition(); + parent::__construct($level, $nbt, $shootingEntity); + } + + public function entityBaseTick(int $tickDiff = 1): bool + { + if ($this->closed) { + return false; + } + $hasUpdate = parent::entityBaseTick($tickDiff); + if (!$this->isCollided) { + if ($this->getOwningEntity() instanceof Player && $this->placeholder) { + $this->getOwningEntity()->sendPosition($this->add($this->getDirectionVector()->multiply(2)), $this->yaw * 2 <= 360 ? $this->yaw * 2 : $this->yaw / 2, $this->pitch); + } + } else { + if ($this->placeholder) { + $this->getOwningEntity()->teleport($this->ownerOriginalLocation); + } + $this->flagForDespawn(); + $hasUpdate = true; + } + return $hasUpdate; + } + + public function spawnTo(Player $player): void + { + parent::spawnTo($player); + $pk = new AddEntityPacket(); + $pk->entityRuntimeId = $this->getId(); + $pk->type = static::TYPE_ID; + $pk->position = $this->asVector3(); + $pk->motion = $this->getMotion(); + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->metadata = $this->propertyManager->getAll(); + $player->dataPacket($pk); + } +} diff --git a/src/PiggyCustomEnchants/Entities/PiggyWitherSkull.php b/src/PiggyCustomEnchants/Entities/PiggyWitherSkull.php new file mode 100644 index 0000000..4793d11 --- /dev/null +++ b/src/PiggyCustomEnchants/Entities/PiggyWitherSkull.php @@ -0,0 +1,31 @@ +addEffect($effect); + } + parent::onCollideWithEntity($entity); + } +} diff --git a/src/PiggyCustomEnchants/Entities/VolleyArrow.php b/src/PiggyCustomEnchants/Entities/VolleyArrow.php new file mode 100644 index 0000000..6319e5d --- /dev/null +++ b/src/PiggyCustomEnchants/Entities/VolleyArrow.php @@ -0,0 +1,54 @@ +volley = $volley; + $this->placeholder = $placeholder; + $this->ownerOriginalLocation = $shootingEntity->getLocation(); + parent::__construct($level, $nbt, $shootingEntity, $critical); + } + + public function entityBaseTick(int $tickDiff = 1): bool + { + if ($this->closed) { + return false; + } + $hasUpdate = parent::entityBaseTick($tickDiff); + if (!$this->isFlaggedForDespawn()) { + if (!$this->isCollided) { + if ($this->getOwningEntity() instanceof Player && $this->placeholder) { + $this->getOwningEntity()->sendPosition($this->add($this->getDirectionVector()->multiply(-2)), $this->yaw, $this->pitch); + } + } else { + if ($this->isVolley()) { + $this->flagForDespawn(); + $hasUpdate = true; + } + if ($this->placeholder) { + $this->placeholder = false; + $this->getOwningEntity()->teleport($this->ownerOriginalLocation); + } + } + } + return $hasUpdate; + } + + public function isVolley() + { + return $this->volley; + } +} diff --git a/src/PiggyCustomEnchants/EventListener.php b/src/PiggyCustomEnchants/EventListener.php new file mode 100644 index 0000000..32fdd53 --- /dev/null +++ b/src/PiggyCustomEnchants/EventListener.php @@ -0,0 +1,1277 @@ + 1, + Block::IRON_ORE => 2, + Block::GOLD_ORE => 3, + Block::DIAMOND_ORE => 4, + Block::EMERALD_ORE => 5 + ]; + + const SMELTED_ITEM = [ + Item::COBBLESTONE => [Item::STONE, 0], + Item::IRON_ORE => [Item::IRON_INGOT, 0], + Item::GOLD_ORE => [Item::GOLD_INGOT, 0], + Item::SAND => [Item::GLASS, 0], + Item::CLAY => [Item::BRICK, 0], + Item::NETHERRACK => [Item::NETHER_BRICK, 0], + Item::STONE_BRICK => [Item::STONE_BRICK, 2], + Item::CACTUS => [Item::DYE, 2], + Item::WOOD => [Item::COAL, 1], + Item::WOOD2 => [Item::COAL, 1], + ]; + + private $plugin; + + public function __construct(Main $plugin) + { + $this->plugin = $plugin; + } + + public function onBreak(BlockBreakEvent $event) + { + $player = $event->getPlayer(); + $this->checkToolEnchants($player, $event); + } + + public function onArmorChange(EntityArmorChangeEvent $event) + { + $entity = $event->getEntity(); + $this->checkArmorEnchants($entity, $event); + } + + public function onDamage(EntityDamageEvent $event) + { + $entity = $event->getEntity(); + $cause = $event->getCause(); + if ($cause == EntityDamageEvent::CAUSE_FALL && $entity instanceof Player && (isset($this->plugin->nofall[$entity->getLowerCaseName()]) || isset($this->plugin->flying[$entity->getLowerCaseName()]))) { + unset($this->plugin->nofall[$entity->getLowerCaseName()]); + $event->setCancelled(); + } + if ($event instanceof EntityDamageByChildEntityEvent) { + $damager = $event->getDamager(); + $child = $event->getChild(); + if ($damager instanceof Player && $child instanceof Projectile) { + $this->checkGlobalEnchants($damager, $entity, $event); + $this->checkBowEnchants($damager, $entity, $event); + } + } + if ($event instanceof EntityDamageByEntityEvent) { + $damager = $event->getDamager(); + if ($damager instanceof Player) { + if ($damager->getInventory()->getItemInHand()->getId() !== Item::BOW) { //TODO: Move to canUse() function + $this->checkGlobalEnchants($damager, $entity, $event); + } + } + } + $this->checkArmorEnchants($entity, $event); + } + + public function onEffect(EntityEffectAddEvent $event) + { + $entity = $event->getEntity(); + if ($entity instanceof Player) { + $this->checkArmorEnchants($entity, $event); + } + } + + public function onShoot(EntityShootBowEvent $event) + { + $shooter = $event->getEntity(); + $entity = $event->getProjectile(); + if ($shooter instanceof Player) { + $this->checkBowEnchants($shooter, $entity, $event); + } + } + + public function onTransaction(InventoryTransactionEvent $event) + { + $transaction = $event->getTransaction(); + + foreach ($transaction->getActions() as $action) { + if ($action instanceof SlotChangeAction) { + $item_clicked = $action->getSourceItem(); + if ($item_clicked->getId() === Item::ENCHANTED_BOOK) { + $enchantedbook_action = $action; + } elseif (!$item_clicked->isNull()) { + $equipment_action = $action; + } + } + } + + if (isset($enchantedbook_action, $equipment_action)) { + $book = $enchantedbook_action->getSourceItem(); + $equipment = $equipment_action->getSourceItem(); + + $player = $transaction->getSource(); + $success = false; + + foreach ($book->getEnchantments() as $enchant) { + $is_customenchant = $enchant->getType() instanceof CustomEnchants; + if (!$is_customenchant || $this->plugin->canBeEnchanted($equipment, $enchant, $enchant->getLevel())) { + $success = true; + if ($is_customenchant) { + $equipment = $this->plugin->addEnchantment($equipment, $enchant->getId(), $enchant->getLevel()); + } else { + $equipment->addEnchantment($enchant); + } + } else { + $player->sendTip(TextFormat::RED . "Item này không thể kết hợp với enchant !"); + } + } + + if ($success) { + $event->setCancelled(); + $book->pop(); + $equipment_action->getInventory()->setItem($equipment_action->getSlot(), $equipment); + $enchantedbook_action->getInventory()->setItem($enchantedbook_action->getSlot(), $book); + $player->sendTip(TextFormat::GREEN . "Enchanting succeeded."); + } + } + } + + public function onDeath(PlayerDeathEvent $event) + { + $player = $event->getEntity(); + $this->checkGlobalEnchants($player, null, $event); + } + + public function onIllegalMove(PlayerIllegalMoveEvent $event) + { + $player = $event->getPlayer(); + if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER) !== null) { + $event->setCancelled(); + } + } + + public function onInteract(PlayerInteractEvent $event) + { + $player = $event->getPlayer(); + $this->checkToolEnchants($player, $event); + } + + public function onKick(PlayerKickEvent $event) + { + $player = $event->getPlayer(); + $reason = $event->getReason(); + if ($reason == "Bay ở chế độ 0 không được cho phép ở server này !") { + if (isset($this->plugin->flying[$player->getLowerCaseName()]) || $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER) !== null) { + $event->setCancelled(); + } + } + } + + public function onMove(PlayerMoveEvent $event) + { + $player = $event->getPlayer(); + $from = $event->getFrom(); + if (isset($this->plugin->nofall[$player->getLowerCaseName()])) { + if ($this->plugin->checkBlocks($player, 0, 1) !== true && $this->plugin->nofall[$player->getLowerCaseName()] < time()) { + unset($this->plugin->nofall[$player->getLowerCaseName()]); + } else { + $this->plugin->nofall[$player->getLowerCaseName()]++; + } + } + if ($from->getFloorX() == $player->getFloorX() && $from->getFloorY() == $player->getFloorY() && $from->getFloorZ() == $player->getFloorZ()) { + $this->plugin->moved[$player->getLowerCaseName()] = 10; + return false; + } + $this->plugin->moved[$player->getLowerCaseName()] = 0; + $this->checkGlobalEnchants($player, null, $event); + $this->checkArmorEnchants($player, $event); + return true; + } + + public function onQuit(PlayerQuitEvent $event) + { + $player = $event->getPlayer(); + $name = $player->getLowerCaseName(); + if (isset($this->plugin->blockface[$name])) { + unset($this->plugin->blockface[$name]); + } + if (isset($this->plugin->glowing[$name])) { + unset($this->plugin->glowing[$name]); + } + if (isset($this->plugin->grew[$name])) { + unset($this->plugin->grew[$name]); + } + if (isset($this->plugin->flying[$name])) { + unset($this->plugin->flying[$name]); + } + if (isset($this->plugin->hallucination[$name])) { + unset($this->plugin->hallucination[$name]); + } + if (isset($this->plugin->implants[$name])) { + unset($this->plugin->implants[$name]); + } + if (isset($this->plugin->mined[$name])) { + unset($this->plugin->mined[$name]); + } + if (isset($this->plugin->nofall[$name])) { + unset($this->plugin->nofall[$name]); + } + for ($i = 0; $i <= 3; $i++) { + if (isset($this->plugin->overload[$name . "||" . $i])) { + unset($this->plugin->overload[$name . "||" . $i]); + } + } + if (isset($this->plugin->prowl[$name])) { + unset($this->plugin->prowl[$name]); + } + if (isset($this->plugin->using[$name])) { + unset($this->plugin->using[$name]); + } + if (isset($this->plugin->shrunk[$name])) { + unset($this->plugin->shrunk[$name]); + } + } + + public function onSneak(PlayerToggleSneakEvent $event) + { + $player = $event->getPlayer(); + if ($event->isSneaking()) { + $this->checkArmorEnchants($player, $event); + } + } + + public function onHit(ProjectileHitBlockEvent $event) + { + $entity = $event->getEntity(); + $shooter = $entity->getOwningEntity(); + if ($shooter instanceof Player) { + $this->checkBowEnchants($shooter, $entity, $event); + } + } + + public function onDataPacketReceive(DataPacketReceiveEvent $event) + { + $player = $event->getPlayer(); + $packet = $event->getPacket(); + if ($packet instanceof PlayerActionPacket) { + $action = $packet->action; + switch ($action) { + case PlayerActionPacket::ACTION_JUMP: + $this->checkArmorEnchants($player, $event); + break; + case PlayerActionPacket::ACTION_CONTINUE_BREAK: + $this->plugin->blockface[$player->getLowerCaseName()] = $packet->face; + break; + } + } + } + + public function checkGlobalEnchants(Player $damager, Entity $entity = null, Event $event) + { + if ($event instanceof EntityDamageEvent) { + if ($entity instanceof Living) { + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLIND); + if ($enchantment !== null && $entity->hasEffect(Effect::BLINDNESS) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::BLINDNESS), 100 + 20 * $enchantment->getLevel(), 0, false); + $entity->addEffect($effect); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::POISON); + if ($enchantment !== null && $entity->hasEffect(Effect::POISON) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::POISON), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $entity->addEffect($effect); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::CRIPPLINGSTRIKE); + if ($enchantment !== null) { + if (!$entity->hasEffect(Effect::NAUSEA)) { + $effect = new EffectInstance(Effect::getEffect(Effect::NAUSEA), 100 * $enchantment->getLevel(), 0, false); + $entity->addEffect($effect); + } + if (!$entity->hasEffect(Effect::SLOWNESS)) { + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 100 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $entity->addEffect($effect); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::WITHER); + if ($enchantment !== null && $entity->hasEffect(Effect::WITHER) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::WITHER), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $entity->addEffect($effect); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LIFESTEAL); + if ($enchantment !== null) { + if ($damager->getHealth() + 2 + $enchantment->getLevel() <= $damager->getMaxHealth()) { + $damager->setHealth($damager->getHealth() + 2 + $enchantment->getLevel()); + } else { + $damager->setHealth($damager->getMaxHealth()); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DEATHBRINGER); + if ($enchantment !== null) { + $damage = 2 + ($enchantment->getLevel() / 10); + $event->setDamage($event->getDamage() + $damage); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GOOEY); + if ($enchantment !== null) { + $task = new GoeyTask($this->plugin, $entity, $enchantment->getLevel()); + $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($task, 1); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::VAMPIRE); + if ($enchantment !== null) { + if (!isset($this->plugin->vampirecd[$damager->getLowerCaseName()]) || time() > $this->plugin->vampirecd[$damager->getLowerCaseName()]) { + $this->plugin->vampirecd[$damager->getLowerCaseName()] = time() + 5; + if ($damager->getHealth() + ($event->getDamage() / 2) <= $damager->getMaxHealth()) { + $damager->setHealth($damager->getHealth() + ($event->getDamage() / 2)); + } else { + $damager->setHealth($damager->getMaxHealth()); + } + if ($damager->getFood() + ($event->getDamage() / 2) <= $damager->getMaxFood()) { + $damager->setFood($damager->getFood() + ($event->getDamage() / 2)); + } else { + $damager->setFood($damager->getMaxFood()); + } + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::CHARGE); + if ($enchantment !== null) { + if ($damager->isSprinting()) { + $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::AERIAL); + if ($enchantment !== null) { + if (!$damager->isOnGround()) { + $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DISARMING); + if ($enchantment !== null) { + if ($entity instanceof Player) { + $chance = 10 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance) { + $item = $entity->getInventory()->getItemInHand(); + $entity->getInventory()->removeItem($item); + $entity->dropItem($item); + } + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HALLUCINATION); + if ($enchantment !== null) { + $chance = 5 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance && $entity instanceof Player && isset($this->plugin->hallucination[$entity->getLowerCaseName()]) !== true) { + $this->plugin->hallucination[$entity->getLowerCaseName()] = true; + $task = new HallucinationTask($this->plugin, $entity, $entity->getPosition()); + $handler = $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($task, 1); + $task->setHandler($handler); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLESSED); + if ($enchantment !== null) { + $chance = 15 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance) { + foreach ($damager->getEffects() as $effect) { + if ($effect->getType()->isBad()) { + $damager->removeEffect($effect->getId()); + } + } + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DISARMOR); + if ($enchantment !== null) { + if ($entity instanceof Player) { + $chance = 10 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance) { + if (count($armor = $entity->getArmorInventory()->getContents(false)) > 0) { + $item = $armor[array_rand($armor)]; + $entity->getArmorInventory()->removeItem($item); + $entity->dropItem($item); + } + } + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BACKSTAB); + if ($enchantment !== null) { + if ($damager->getDirectionVector()->dot($entity->getDirectionVector()) > 0) { + $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LIGHTNING); + if ($enchantment !== null) { + $chance = 10 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance) { + $lightning = Entity::createEntity("PiggyLightning", $entity->getLevel(), Entity::createBaseNBT($entity)); + $lightning->setOwningEntity($damager); + $lightning->spawnToAll(); + } + } + } + if ($event instanceof PlayerDeathEvent) { + $drops = $event->getDrops(); + $soulbounded = []; + $soulboundedarmor = []; + foreach ($damager->getInventory()->getContents() as $k => $item) { + $enchantment = $item->getEnchantment(CustomEnchantsIds::SOULBOUND); + if ($enchantment !== null) { + $index = array_search($item, $drops); + if ($index !== false) { + unset($drops[$index]); + } + if ($k >= $damager->getInventory()->getSize()) { + $soulboundedarmor[abs($damager->getInventory()->getSize() - $k)] = $enchantment->getLevel() > 1 ? $this->plugin->addEnchantment($item, $enchantment->getId(), $enchantment->getLevel() - 1) : $this->plugin->removeEnchantment($item, $enchantment); + } else { + $soulbounded[$k] = $enchantment->getLevel() > 1 ? $this->plugin->addEnchantment($item, $enchantment->getId(), $enchantment->getLevel() - 1) : $this->plugin->removeEnchantment($item, $enchantment); + } + } + } + $event->setDrops([]); + $event->setKeepInventory(true); + foreach ($drops as $drop) { + $damager->getLevel()->dropItem($damager, $drop); + } + $damager->getArmorInventory()->setContents($soulboundedarmor); + $damager->getInventory()->setContents($soulbounded); + } + if ($event instanceof PlayerMoveEvent) { + foreach ($damager->getInventory()->getContents() as $slot => $item) { + $enchantment = $item->getEnchantment(CustomEnchantsIds::AUTOREPAIR); + if ($enchantment !== null) { + $newDir = $item->getDamage() - (1 + (1 * $enchantment->getLevel())); + if ($newDir < 0) { + $item->setDamage(0); + } else { + $item->setDamage($newDir); + } + $damager->getInventory()->setItem($slot, $item); + } + } + } + } + + /** + * @param Player $player + * @param Event $event + */ + public function checkToolEnchants(Player $player, Event $event) + { + if ($event instanceof BlockBreakEvent) { + $block = $event->getBlock(); + $drops = $event->getDrops(); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::EXPLOSIVE); + if ($enchantment !== null) { + if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { + $this->plugin->using[$player->getLowerCaseName()] = time() + 1; + $explosion = new PiggyExplosion($block, $enchantment->getLevel() * 5, $player, $this->plugin); + $explosion->explodeA(); + $explosion->explodeB(); + } + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::LUMBERJACK); + if ($enchantment !== null) { + if ($player->isSneaking()) { + if ($block->getId() == Block::WOOD || $block->getId() == Block::WOOD2) { + if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { + $this->plugin->mined[$player->getLowerCaseName()] = 0; + $this->breakTree($block, $player); + } + } + } + $event->setInstaBreak(true); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::DRILLER); + if ($enchantment !== null) { + if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { + if (isset($this->plugin->blockface[$player->getLowerCaseName()])) { + $side = $this->plugin->blockface[$player->getLowerCaseName()]; + $sides = [$side <= 1 ? $side + 2 : $side - 2, $side > 1 && $side < 4 ? $side + 2 : ($side >= 4 ? $side - 4 : $side + 4)]; + $item = $player->getInventory()->getItemInHand(); + $blocks = []; + for ($i = 0; $i <= $enchantment->getLevel(); $i++) { + $b = $block->getSide($side ^ 0x01, $i); + $b1 = $b->getSide($sides[0]); + $b2 = $b->getSide($sides[0] ^ 0x01); + $blocks[] = $b->getSide($sides[1]); + $blocks[] = $b->getSide($sides[1] ^ 0x01); + $blocks[] = $b1; + $blocks[] = $b2; + $blocks[] = $b1->getSide($sides[1] ^ 0x01); + $blocks[] = $b2->getSide($sides[1] ^ 0x01); + $blocks[] = $b1->getSide($sides[1]); + $blocks[] = $b2->getSide($sides[1]); + if ($b !== $block) { + $blocks[] = $b; + } + } + $this->plugin->using[$player->getLowerCaseName()] = time() + 1; + foreach ($blocks as $b) { + $block->getLevel()->useBreakOn($b, $item, $player); + } + unset($this->plugin->blockface[$player->getLowerCaseName()]); + } + } + $event->setInstaBreak(true); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::JACKPOT); + if ($enchantment !== null) { + $chance = 10 * $enchantment->getLevel(); + $random = mt_rand(0, 100); + if ($random <= $chance) { + if (isset(self::ORE_TIER[$block->getId()])) { + $tier = self::ORE_TIER[$block->getId()]; + if (($tierkey = array_search($tier + 1, self::ORE_TIER)) !== false) { + foreach ($drops as $key => $drop) { + foreach ($block->getDrops($player->getInventory()->getItemInHand()) as $originaldrop) { + if ($drop->equals($originaldrop)) { + unset($drops[$key]); + foreach (Block::get($tierkey, $originaldrop->getDamage())->getDrops(Item::get(Item::DIAMOND_PICKAXE)) as $newdrop) { //Diamond Pickaxe to make sure the item drops + $drops[] = $newdrop; + } + $event->setDrops($drops); + break; + } + } + } + } + } + } + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::SMELTING); + if ($enchantment !== null) { + $finaldrop = array(); + $otherdrops = array(); + foreach ($drops as $drop) { + if (isset(self::SMELTED_ITEM[$drop->getId()])) { + $finaldrop[] = Item::get(self::SMELTED_ITEM[$drop->getId()][0], self::SMELTED_ITEM[$drop->getId()][1], $drop->getCount()); + continue; + } + if ($drop->getId() == Item::SPONGE && $drop->getDamage() == 1) { + $finaldrop[] = Item::get(Item::SPONGE, 0, $drop->getCount()); + continue; + } + $finaldrop[] = $drop; + + } + $event->setDrops($drops = array_merge($finaldrop, $otherdrops)); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::ENERGIZING); + if ($enchantment !== null && $player->hasEffect(Effect::HASTE) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::HASTE), 20, 1 + $enchantment->getLevel() - 2, false); + $player->addEffect($effect); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::QUICKENING); + if ($enchantment !== null && $player->hasEffect(Effect::SPEED) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::SPEED), 40, 3 + $enchantment->getLevel() - 2, false); + $player->addEffect($effect); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::TELEPATHY); + if ($enchantment !== null) { + foreach ($drops as $drop) { + $player->getInventory()->addItem($drop); + } + $event->setDrops([]); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::FARMER); + if ($enchantment !== null) { + $seed = null; + switch ($block->getId()) { + case Block::WHEAT_BLOCK: + $seed = Item::SEEDS; + break; + case Block::POTATO_BLOCK: + $seed = Item::POTATO; + break; + case Block::CARROT_BLOCK: + $seed = Item::CARROT; + break; + case Block::BEETROOT_BLOCK: + $seed = Item::BEETROOT_SEEDS; + break; + } + if ($seed !== null) { + $seed = Item::get($seed, 0, 1); + $pos = $block->subtract(0, 1); + $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new PlaceTask($this->plugin, $pos, $block->getLevel(), $seed, $player), 1); + } + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HARVEST); + if ($enchantment !== null) { + $radius = $enchantment->getLevel(); + if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { + if ($block instanceof Crops) { + for ($x = -$radius; $x <= $radius; $x++) { + for ($z = -$radius; $z <= $radius; $z++) { + $pos = $block->add($x, 0, $z); + if ($block->getLevel()->getBlock($pos) instanceof Crops) { + $this->plugin->using[$player->getLowerCaseName()] = time() + 1; + $item = $player->getInventory()->getItemInHand(); + $block->getLevel()->useBreakOn($pos, $item, $player); + } + } + } + } + } + } + } + if ($event instanceof PlayerInteractEvent) { + $block = $event->getBlock(); + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::FERTILIZER); + if ($enchantment !== null) { + if (!isset($this->plugin->using[$player->getLowerCaseName()]) || $this->plugin->using[$player->getLowerCaseName()] < time()) { + if ($this->plugin->checkBlocks($block, [Block::DIRT, Block::GRASS])) { + $radius = $enchantment->getLevel(); + for ($x = -$radius; $x <= $radius; $x++) { + for ($z = -$radius; $z <= $radius; $z++) { + $pos = $block->add($x, 0, $z); + if ($this->plugin->checkBlocks(Position::fromObject($pos, $block->getLevel()), [Block::DIRT, Block::GRASS])) { + $this->plugin->using[$player->getLowerCaseName()] = time() + 1; + $item = $player->getInventory()->getItemInHand(); + $block->getLevel()->useItemOn($pos, $item, 0, $pos, $player); + } + } + } + } + } + } + } + } + + /** + * @param Player $damager + * @param Entity $entity + * @param EntityEvent $event + */ + public function checkBowEnchants(Player $damager, Entity $entity, EntityEvent $event) + { + if ($event instanceof EntityDamageByChildEntityEvent) { + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::MOLOTOV); + if ($enchantment !== null) { + $boundaries = 0.1 * $enchantment->getLevel(); + for ($x = $boundaries; $x >= -$boundaries; $x -= 0.1) { + for ($z = $boundaries; $z >= -$boundaries; $z -= 0.1) { + $entity->getLevel()->setBlock($entity->add(0, 1), Block::get(Block::FIRE)); + $fire = Entity::createEntity("FallingSand", $entity->getLevel(), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $entity->x + 0.5), new DoubleTag("", $entity->y + 1), new DoubleTag("", $entity->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $x), new DoubleTag("", 0.1), new DoubleTag("", $z)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "TileID" => new IntTag("TileID", 51), "Data" => new ByteTag("Data", 0)])); + $fire->spawnToAll(); + } + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PARALYZE); + if ($enchantment !== null and $entity instanceof Living) { + if (!$entity->hasEffect(Effect::SLOWNESS)) { + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 60 + ($enchantment->getLevel() - 1) * 20, 5 + $enchantment->getLevel() - 1, false); + $entity->addEffect($effect); + } + if (!$entity->hasEffect(Effect::BLINDNESS)) { + $effect = new EffectInstance(Effect::getEffect(Effect::BLINDNESS), 60 + ($enchantment->getLevel() - 1) * 20, 1, false); + $entity->addEffect($effect); + } + if (!$entity->hasEffect(Effect::WEAKNESS)) { + $effect = new EffectInstance(Effect::getEffect(Effect::WEAKNESS), 60 + ($enchantment->getLevel() - 1) * 20, 5 + $enchantment->getLevel() - 1, false); + $entity->addEffect($effect); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PIERCING); + if ($enchantment !== null) { + $event->setDamage(0, EntityDamageEvent::MODIFIER_ARMOR); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::SHUFFLE); + if ($enchantment !== null) { + $pos1 = clone $damager->getPosition(); + $pos2 = clone $entity->getPosition(); + $damager->teleport($pos2); + $entity->teleport($pos1); + $name = $entity->getNameTag(); + if ($entity instanceof Player) { + $name = $entity->getDisplayName(); + $entity->sendMessage(TextFormat::DARK_PURPLE . "Bạn đã dịch chuyển vị trí với " . $damager->getDisplayName()); + } + $damager->sendMessage(TextFormat::DARK_PURPLE . "Bạn đã dịch chuyển vị trí với " . $name); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BOUNTYHUNTER); + if ($enchantment !== null) { + if (!isset($this->plugin->bountyhuntercd[$damager->getLowerCaseName()]) || time() > $this->plugin->bountyhuntercd[$damager->getLowerCaseName()]) { + $bountydrop = $this->getBounty(); + $damager->getInventory()->addItem(Item::get($bountydrop, 0, mt_rand(0, 8 + $enchantment->getLevel()) + 1)); + $this->plugin->bountyhuntercd[$damager->getLowerCaseName()] = time() + 30; + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HEALING); + if ($enchantment !== null) { + if ($entity->getHealth() + $event->getDamage() + $enchantment->getLevel() <= $entity->getMaxHealth()) { + $entity->setHealth($entity->getHealth() + $event->getDamage() + $enchantment->getLevel()); + } else { + $entity->setHealth($entity->getMaxHealth()); + } + $event->setDamage(0); + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HEADHUNTER); + if ($enchantment !== null) { + $projectile = $event->getChild(); + if ($projectile->y > $entity->getPosition()->y + $entity->getEyeHeight()) { + $event->setDamage($event->getDamage() * (1 + 0.10 * $enchantment->getLevel())); + } + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GRAPPLING); + if ($enchantment !== null) { + $task = new GrapplingTask($this->plugin, $damager->getPosition(), $entity); + $this->plugin->getServer()->getScheduler()->scheduleDelayedTask($task, 1); //Delayed due to knockback interfering + } + } + if ($event instanceof EntityShootBowEvent) { + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PLACEHOLDER); + if ($enchantment !== null) { + $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); + $newentity = Entity::createEntity("VolleyArrow", $damager->getLevel(), $nbt, $damager, $entity->isCritical(), true, false); + $newentity->setMotion($newentity->getMotion()->multiply($event->getForce())); + $newentity->spawnToAll(); + $entity->close(); + $entity = $newentity; + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::BLAZE); + if ($enchantment !== null && $entity instanceof PiggyFireball !== true) { + $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); + $fireball = Entity::createEntity("PiggyFireball", $damager->getLevel(), $nbt, $damager, isset($entity->placeholder) ? $entity->placeholder : false); + $fireball->setMotion($fireball->getMotion()->multiply($event->getForce())); + $fireball->spawnToAll(); + $entity->close(); + $entity = $fireball; + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::PORKIFIED); + if ($enchantment !== null && $entity instanceof PigProjectile !== true) { + $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); + $pig = Entity::createEntity("PigProjectile", $damager->getLevel(), $nbt, $damager, isset($entity->placeholder) ? $entity->placeholder : false, $enchantment->getLevel()); + $pig->setMotion($pig->getMotion()->multiply($event->getForce())); + $pig->spawnToAll(); + $entity->close(); + $entity = $pig; + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::WITHERSKULL); + if ($enchantment !== null && $entity instanceof PiggyWitherSkull !== true) { + $nbt = Entity::createBaseNBT($entity, $damager->getDirectionVector(), $entity->yaw, $entity->pitch); + $skull = Entity::createEntity("PiggyWitherSkull", $damager->getLevel(), $nbt, $damager, isset($entity->placeholder) ? $entity->placeholder : false, $enchantment->getLevel() > 1 ? true : false); + $skull->setMotion($skull->getMotion()->multiply($event->getForce())); + $skull->spawnToAll(); + $entity->close(); + $entity = $skull; + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::VOLLEY); + if ($enchantment !== null) { + $amount = 1 + 2 * $enchantment->getLevel(); + $anglesbetweenarrows = (45 / ($amount - 1)) * M_PI / 180; + $pitch = ($damager->getLocation()->getPitch() + 90) * M_PI / 180; + $yaw = ($damager->getLocation()->getYaw() + 90 - 45 / 2) * M_PI / 180; + $sZ = cos($pitch); + for ($i = 0; $i < $amount; $i++) { + $nX = sin($pitch) * cos($yaw + $anglesbetweenarrows * $i); + $nY = sin($pitch) * sin($yaw + $anglesbetweenarrows * $i); + $newDir = new Vector3($nX, $sZ, $nY); + $projectile = null; + if ($entity instanceof Arrow) { + $nbt = Entity::createBaseNBT($damager->add(0, $damager->getEyeHeight()), $damager->getDirectionVector(), $damager->yaw, $damager->pitch); + $projectile = Entity::createEntity("VolleyArrow", $damager->getLevel(), $nbt, $damager, $entity->isCritical(), false, true); + } + if ($entity instanceof PiggyFireball) { + $nbt = Entity::createBaseNBT($damager->add(0, $damager->getEyeHeight()), $damager->getDirectionVector(), $damager->yaw, $damager->pitch); + $projectile = Entity::createEntity("PiggyFireball", $damager->getLevel(), $nbt, $damager); + } + if ($entity instanceof PigProjectile) { + $nbt = Entity::createBaseNBT($damager->add(0, $damager->getEyeHeight()), $damager->getDirectionVector(), $damager->yaw, $damager->pitch); + $projectile = Entity::createEntity("PigProjectile", $damager->getLevel(), $nbt, $damager, false, $entity->getPorkLevel()); + } + if ($entity instanceof PiggyWitherSkull) { + $nbt = Entity::createBaseNBT($damager->add(0, $damager->getEyeHeight()), $damager->getDirectionVector(), $damager->yaw, $damager->pitch); + $projectile = Entity::createEntity("PiggyWitherSkull", $damager->getLevel(), $nbt, $damager); + } + $projectile->setMotion($newDir->normalize()->multiply($entity->getMotion()->multiply($event->getForce())->length())); + if ($projectile->isOnFire()) { + $projectile->setOnFire($entity->fireTicks * 20); + } + $projectile->spawnToAll(); + } + $entity->close(); + } + } + if ($event instanceof ProjectileHitBlockEvent && $entity instanceof Projectile) { + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::GRAPPLING); + if ($enchantment !== null) { + $location = $entity->getPosition(); + $damagerloc = $damager->getPosition(); + if ($damager->distance($entity) < 6) { + if ($location->y > $damager->y) { + $damager->setMotion(new Vector3(0, 0.25, 0)); + } else { + $v = $location->subtract($damagerloc); + $damager->setMotion($v); + } + } else { + $g = -0.08; + $d = $location->distance($damagerloc); + $t = $d; + $v_x = (1.0 + 0.07 * $t) * ($location->x - $damagerloc->x) / $t; + $v_y = (1.0 + 0.03 * $t) * ($location->y - $damagerloc->y) / $t - 0.5 * $g * $t; + $v_z = (1.0 + 0.07 * $t) * ($location->z - $damagerloc->z) / $t; + $v = $damager->getMotion(); + $v->setComponents($v_x, $v_y, $v_z); + $damager->setMotion($v); + } + $this->plugin->nofall[$damager->getLowerCaseName()] = time() + 1; + } + $enchantment = $damager->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::MISSILE); + if ($enchantment !== null) { + for ($i = 0; $i <= $enchantment->getLevel(); $i++) { + $tnt = Entity::createEntity("PrimedTNT", $entity->getLevel(), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $entity->x), new DoubleTag("", $entity->y), new DoubleTag("", $entity->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 40)])); + $tnt->spawnToAll(); + $entity->close(); + } + } + } + } + + public function checkArmorEnchants(Entity $entity, Event $event) + { + if ($entity instanceof Player) { + $random = new Random(); + if ($event instanceof EntityDamageEvent) { + $damage = $event->getDamage(); + $cause = $event->getCause(); + $antikb = 4; + if ($cause == EntityDamageEvent::CAUSE_FALL) { + $enchantment = $entity->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::STOMP); + if ($enchantment !== null) { + $entities = $entity->getLevel()->getNearbyEntities($entity->getBoundingBox()); + foreach ($entities as $e) { + if ($entity === $e) { + continue; + } + $ev = new EntityDamageByEntityEvent($entity, $e, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage / 2); + $this->plugin->getServer()->getPluginManager()->callEvent($ev); + $e->attack($ev); + } + if (count($entities) > 1) { + $event->setDamage($event->getDamage() / 4); + } + } + } + foreach ($entity->getArmorInventory()->getContents() as $slot => $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::REVIVE); + if ($enchantment !== null) { + if ($event->getDamage() >= $entity->getHealth()) { + if ($enchantment->getLevel() > 1) { + $entity->getArmorInventory()->setItem($slot, $this->plugin->addEnchantment($armor, $enchantment->getId(), $enchantment->getLevel() - 1)); + } else { + $entity->getArmorInventory()->setItem($slot, $this->plugin->removeEnchantment($armor, $enchantment)); + } + $entity->removeAllEffects(); + $entity->setHealth($entity->getMaxHealth()); + $entity->setFood($entity->getMaxFood()); + $entity->setXpLevel(0); + $entity->setXpProgress(0); + $effect = new EffectInstance(Effect::getEffect(Effect::NAUSEA), 600, 0, false); + $entity->addEffect($effect); + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 600, 0, false); + $entity->addEffect($effect); + for ($i = $entity->y; $i <= 256; $i += 0.25) { + $entity->getLevel()->addParticle(new FlameParticle(new Vector3($entity->x, $i, $entity->z))); + } + $entity->sendTip(TextFormat::GREEN . "Bạn đã được hồi sinh !"); + $event->setDamage(0); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SELFDESTRUCT); + if ($enchantment !== null) { + if ($event->getDamage() >= $entity->getHealth()) { + for ($i = $enchantment->getLevel(); $i >= 0; $i--) { + $tnt = Entity::createEntity("PrimedTNT", $entity->getLevel(), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $entity->x), new DoubleTag("", $entity->y), new DoubleTag("", $entity->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $random->nextFloat() * 1.5 - 1), new DoubleTag("", $random->nextFloat() * 1.5), new DoubleTag("", $random->nextFloat() * 1.5 - 1)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 40)])); + $tnt->spawnToAll(); + } + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ENDERSHIFT); + if ($enchantment !== null) { + if ($entity->getHealth() - $event->getDamage() <= 4) { + if (!isset($this->plugin->endershiftcd[$entity->getLowerCaseName()]) || time() > $this->plugin->endershiftcd[$entity->getLowerCaseName()]) { + $this->plugin->endershiftcd[$entity->getLowerCaseName()] = time() + 300; + if (!$entity->hasEffect(Effect::SPEED)) { + $effect = new EffectInstance(Effect::getEffect(Effect::SPEED), 200 * $enchantment->getLevel(), $enchantment->getLevel() + 3, false); + $entity->addEffect($effect); + } + if (!$entity->hasEffect(Effect::ABSORPTION)) { + $effect = new EffectInstance(Effect::getEffect(Effect::ABSORPTION), 200 * $enchantment->getLevel(), $enchantment->getLevel() + 3, false); + $entity->addEffect($effect); + } + $entity->sendMessage("Bạn có cảm thấy một cơn sốt năng lượng đến từ bộ giáp của bạn ?"); + } + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::BERSERKER); + if ($enchantment !== null) { + if ($entity->getHealth() - $event->getDamage() <= 4) { + if ((!isset($this->plugin->berserkercd[$entity->getLowerCaseName()]) || time() > $this->plugin->berserkercd[$entity->getLowerCaseName()]) && $entity->hasEffect(Effect::STRENGTH) !== true) { + $this->plugin->berserkercd[$entity->getLowerCaseName()] = time() + 300; + $effect = new EffectInstance(Effect::getEffect(Effect::STRENGTH), 200 * $enchantment->getLevel(), 3 + $enchantment->getLevel(), false); + $entity->addEffect($effect); + $entity->sendMessage("Mất máu đã làm cho bạn mạnh mẽ hơn !"); + } + } + } + } + if ($event instanceof EntityDamageByEntityEvent) { + $damager = $event->getDamager(); + foreach ($entity->getArmorInventory()->getContents() as $slot => $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::MOLTEN); + if ($enchantment !== null) { + $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new MoltenTask($this->plugin, $damager, $enchantment->getLevel()), 1); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ENLIGHTED); + if ($enchantment !== null && $entity->hasEffect(Effect::REGENERATION) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::REGENERATION), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $entity->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::HARDENED); + if ($enchantment !== null && $damager->hasEffect(Effect::WEAKNESS) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::WEAKNESS), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::POISONED); + if ($enchantment !== null && $damager->hasEffect(Effect::POISON) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::POISON), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::FROZEN); + if ($enchantment !== null && $damager->hasEffect(Effect::SLOWNESS) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::REVULSION); + if ($enchantment !== null && $damager->hasEffect(Effect::NAUSEA) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::NAUSEA), 20 * $enchantment->getLevel(), 0, false); + $damager->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::CURSED); + if ($enchantment !== null && $damager->hasEffect(Effect::WITHER) !== true) { + $effect = new EffectInstance(Effect::getEffect(Effect::WITHER), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::DRUNK); + if ($enchantment !== null) { + if (!$damager->hasEffect(Effect::SLOWNESS)) { + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + if (!$damager->hasEffect(Effect::MINING_FATIGUE)) { + $effect = new EffectInstance(Effect::getEffect(Effect::MINING_FATIGUE), 60 * $enchantment->getLevel(), $enchantment->getLevel(), false); + $damager->addEffect($effect); + } + if (!$damager->hasEffect(Effect::NAUSEA)) { + $effect = new EffectInstance(Effect::getEffect(Effect::NAUSEA), 60 * $enchantment->getLevel(), 0, false); + $damager->addEffect($effect); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::CLOAKING); + if ($enchantment !== null) { + if ((!isset($this->plugin->cloakingcd[$entity->getLowerCaseName()]) || time() > $this->plugin->cloakingcd[$entity->getLowerCaseName()]) && $entity->hasEffect(Effect::INVISIBILITY)) { + $this->plugin->cloakingcd[$entity->getLowerCaseName()] = time() + 10; + $effect = new EffectInstance(Effect::getEffect(Effect::INVISIBILITY), 60 * $enchantment->getLevel(), 0, false); + $entity->addEffect($effect); + $entity->sendMessage(TextFormat::DARK_GRAY . "...Bạn đã trở nên vô hình..."); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ANTIKNOCKBACK); + if ($enchantment !== null) { + $event->setKnockBack($event->getKnockBack() - ($event->getKnockBack() / $antikb)); + $antikb--; + } + if ($damager instanceof Player) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::ARMORED); + if ($enchantment !== null) { + if ($damager->getInventory()->getItemInHand()->isSword()) { + $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::TANK); + if ($enchantment !== null) { + if ($damager->getInventory()->getItemInHand()->isAxe()) { + $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::HEAVY); + if ($enchantment !== null) { + if ($damager->getInventory()->getItemInHand()->getId() == Item::BOW) { + $event->setDamage($damage - ($damage * 0.2 * $enchantment->getLevel())); + } + } + } + } + } + } + if ($event instanceof EntityEffectAddEvent) { + $effect = $event->getEffect(); + $enchantment = $entity->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::FOCUSED); + if ($enchantment !== null) { + if (!isset($this->plugin->using[$entity->getLowerCaseName()]) || $this->plugin->using[$entity->getLowerCaseName()] < time()) { + if ($effect->getId() == Effect::NAUSEA) { + if ($effect->getEffectLevel() - ($enchantment->getLevel() * 2) <= 0) { + $event->setCancelled(); + } else { + $event->setCancelled(); + $this->plugin->using[$entity->getLowerCaseName()] = time() + 1; + $entity->addEffect($effect->setAmplifier($effect->getEffectLevel() - (1 + ($enchantment->getLevel() * 2)))); + } + } + } + } + $enchantment = $entity->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::ANTITOXIN); + if ($enchantment !== null) { + if ($effect->getId() == Effect::POISON) { + $event->setCancelled(); + } + } + } + if ($event instanceof PlayerMoveEvent) { + $enchantment = $entity->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::MAGMAWALKER); + if ($enchantment !== null) { + $block = $entity->getLevel()->getBlock($entity); + if (!$this->plugin->checkBlocks($block, [Block::STILL_LAVA, Block::LAVA, Block::FLOWING_LAVA])) { + $radius = $enchantment->getLevel() + 2; + for ($x = -$radius; $x <= $radius; $x++) { + for ($z = -$radius; $z <= $radius; $z++) { + $b = $entity->getLevel()->getBlock($entity->add($x, -1, $z)); + if ($this->plugin->checkBlocks($b, [Block::STILL_LAVA, Block::LAVA, Block::FLOWING_LAVA])) { + if ($this->plugin->checkBlocks($b, [Block::STILL_LAVA, Block::LAVA, Block::FLOWING_LAVA], -1) !== true) { + if (!($b->getId() == Block::FLOWING_LAVA && $b->getDamage() > 0)) { + $block = Block::get(Block::OBSIDIAN, 15); + $entity->getLevel()->setBlock($b, $block); + } + } + } + } + } + } + } + $enchantment = $entity->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::MEDITATION); + if ($enchantment !== null) { + if ($event->getFrom()->floor() !== $event->getTo()->floor()) { + $this->plugin->meditationTick[$entity->getLowerCaseName()] = 0; + } + } + $enchantment = $entity->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::IMPLANTS); + if ($enchantment !== null) { + if ($event->getFrom()->floor() !== $event->getTo()->floor()) { + if (!isset($this->plugin->implantscd[$entity->getLowerCaseName()]) || $this->plugin->implantscd[$entity->getLowerCaseName()] < time()) { + if ($entity->getFood() < 20) { + $entity->setFood($entity->getFood() + $enchantment->getLevel() > 20 ? 20 : $entity->getFood() + $enchantment->getLevel()); + } + if ($entity->getAirSupplyTicks() < $entity->getMaxAirSupplyTicks() && isset($this->plugin->implants[$entity->getLowerCaseName()]) !== true) { + $this->plugin->implants[$entity->getLowerCaseName()] = true; + $task = new ImplantsTask($this->plugin, $entity); + $handler = $this->plugin->getServer()->getScheduler()->scheduleDelayedRepeatingTask($task, 20, 60); + $task->setHandler($handler); + } + $this->plugin->implantscd[$entity->getLowerCaseName()] = time() + 1; + } + } + } + } + if ($event instanceof PlayerToggleSneakEvent) { + $shrinkpoints = 0; + $growpoints = 0; + $shrinklevel = 0; + $growlevel = 0; + foreach ($entity->getArmorInventory()->getContents() as $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SHRINK); + if ($enchantment !== null) { + $shrinklevel += $enchantment->getLevel(); + $shrinkpoints++; + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::GROW); + if ($enchantment !== null) { + $growlevel += $enchantment->getLevel(); + $growpoints++; + } + } + if ($shrinkpoints >= 4) { + if (isset($this->plugin->shrunk[$entity->getLowerCaseName()]) && $this->plugin->shrunk[$entity->getLowerCaseName()] > time()) { + $this->plugin->shrinkremaining[$entity->getLowerCaseName()] = $this->plugin->shrunk[$entity->getLowerCaseName()] - time(); + unset($this->plugin->shrinkcd[$entity->getLowerCaseName()]); + unset($this->plugin->shrunk[$entity->getLowerCaseName()]); + $entity->setScale(1); + $entity->sendTip(TextFormat::RED . "Bạn đã trở về kích thước ban đầu..."); + } else { + if (!isset($this->plugin->shrinkcd[$entity->getLowerCaseName()]) || $this->plugin->shrinkcd[$entity->getLowerCaseName()] <= time()) { + $scale = $entity->getScale() - 0.70 - (($shrinklevel / 4) * 0.05); + $entity->setScale($scale); + $this->plugin->shrunk[$entity->getLowerCaseName()] = isset($this->plugin->shrinkremaining[$entity->getLowerCaseName()]) ? time() + $this->plugin->shrinkremaining[$entity->getLowerCaseName()] : time() + 60; + $this->plugin->shrinkcd[$entity->getLowerCaseName()] = isset($this->plugin->shrinkremaining[$entity->getLowerCaseName()]) ? time() + (75 - (60 - $this->plugin->shrinkremaining[$entity->getLowerCaseName()])) : time() + 75; + $entity->sendTip(TextFormat::GREEN . "Bạn đã thu nhỏ !!!"); + if (isset($this->plugin->shrinkremaining[$entity->getLowerCaseName()])) { + unset($this->plugin->shrinkremaining[$entity->getLowerCaseName()]); + } + } + } + } + if ($growpoints >= 4) { + if (isset($this->plugin->grew[$entity->getLowerCaseName()]) && $this->plugin->grew[$entity->getLowerCaseName()] > time()) { + $this->plugin->growremaining[$entity->getLowerCaseName()] = $this->plugin->grew[$entity->getLowerCaseName()] - time(); + unset($this->plugin->growcd[$entity->getLowerCaseName()]); + unset($this->plugin->grew[$entity->getLowerCaseName()]); + $entity->setScale(1); + $entity->sendTip(TextFormat::RED . "Bạn đã thu nhỏ lại kích thước bình thường."); + } else { + if (!isset($this->plugin->growcd[$entity->getLowerCaseName()]) || $this->plugin->growcd[$entity->getLowerCaseName()] <= time()) { + $scale = $entity->getScale() + 0.30 + (($growlevel / 4) * 0.05); + $entity->setScale($scale); + $this->plugin->grew[$entity->getLowerCaseName()] = isset($this->plugin->growremaining[$entity->getLowerCaseName()]) ? time() + $this->plugin->growremaining[$entity->getLowerCaseName()] : time() + 60; + $this->plugin->growcd[$entity->getLowerCaseName()] = isset($this->plugin->growremaining[$entity->getLowerCaseName()]) ? time() + (75 - (60 - $this->plugin->growremaining[$entity->getLowerCaseName()])) : time() + 75; + $entity->sendTip(TextFormat::GREEN . "Bạn đã thu nhỏ !!!"); + if (isset($this->plugin->growremaining[$entity->getLowerCaseName()])) { + unset($this->plugin->growremaining[$entity->getLowerCaseName()]); + } + } + } + } + $enchantment = $entity->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::JETPACK); + if ($enchantment !== null) { + if (isset($this->plugin->flying[$entity->getLowerCaseName()]) && $this->plugin->flying[$entity->getLowerCaseName()] > time()) { + if ($entity->isOnGround()) { + $this->plugin->flyremaining[$entity->getLowerCaseName()] = $this->plugin->flying[$entity->getLowerCaseName()] - time(); + unset($this->plugin->jetpackcd[$entity->getLowerCaseName()]); + unset($this->plugin->flying[$entity->getLowerCaseName()]); + $entity->sendTip(TextFormat::RED . "Jetpack đã được tắt !"); + } else { + $entity->sendTip(TextFormat::RED . "Không thể bay ở khu vực không có block !"); + } + } else { + if (!in_array($event->getPlayer()->getLevel()->getName(), $this->plugin->jetpackDisabled)) { + if (!isset($this->plugin->jetpackcd[$entity->getLowerCaseName()]) || $this->plugin->jetpackcd[$entity->getLowerCaseName()] <= time()) { + $this->plugin->flying[$entity->getLowerCaseName()] = isset($this->plugin->flyremaining[$entity->getLowerCaseName()]) ? time() + $this->plugin->flyremaining[$entity->getLowerCaseName()] : time() + 300; + $this->plugin->jetpackcd[$entity->getLowerCaseName()] = isset($this->plugin->flyremaining[$entity->getLowerCaseName()]) ? time() + (360 - (300 - $this->plugin->flyremaining[$entity->getLowerCaseName()])) : time() + 360; + $entity->sendTip(TextFormat::GREEN . "Jetpack đã hoạt động !!!"); + if (isset($this->plugin->flyremaining[$entity->getLowerCaseName()])) { + unset($this->plugin->flyremaining[$entity->getLowerCaseName()]); + } + } + } else { + $entity->sendTip(TextFormat::RED . "Jetpack hiện đang bị vô hiệu hóa ở thế giới này !"); + } + } + } + } + if ($event instanceof DataPacketReceiveEvent) { + $packet = $event->getPacket(); + if ($packet instanceof PlayerActionPacket) { + $action = $packet->action; + switch ($action) { + case 8: + $enchantment = $entity->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::SPRINGS); + if ($enchantment !== null) { + $entity->setMotion(new Vector3(0, $entity->getJumpVelocity() + 0.4)); + $this->plugin->nofall[$entity->getLowerCaseName()] = time() + 1; + } + break; + } + } + } + } + } + + public function breakTree(Block $block, Player $player, Block $oldblock = null) + { + $item = $player->getInventory()->getItemInHand(); + for ($i = 0; $i <= 5; $i++) { + if ($this->plugin->mined[$player->getLowerCaseName()] > 800) { + break; + } + $this->plugin->using[$player->getLowerCaseName()] = time() + 1; + $side = $block->getSide($i); + if ($oldblock !== null) { + if ($side->equals($oldblock)) { + continue; + } + } + if ($side->getId() !== Block::WOOD && $side->getId() !== Block::WOOD2) { + continue; + } + $player->getLevel()->useBreakOn($side, $item, $player); + $this->plugin->mined[$player->getLowerCaseName()]++; + $this->breakTree($side, $player, $block); + } + } + + public function getBounty() + { + $random = mt_rand(0, 75); + $currentchance = 2.5; + if ($random < $currentchance) { + return Item::EMERALD; + } + $currentchance += 5; + if ($random < $currentchance) { + return Item::DIAMOND; + } + $currentchance += 15; + if ($random < $currentchance) { + return Item::GOLD_INGOT; + } + $currentchance += 27.5; + if ($random < $currentchance) { + return Item::IRON_INGOT; + } + return Item::COAL; + } +} diff --git a/src/PiggyCustomEnchants/Main.php b/src/PiggyCustomEnchants/Main.php new file mode 100644 index 0000000..01d8c25 --- /dev/null +++ b/src/PiggyCustomEnchants/Main.php @@ -0,0 +1,781 @@ + 1000, + 'CM' => 900, + 'D' => 500, + 'CD' => 400, + 'C' => 100, + 'XC' => 90, + 'L' => 50, + 'XL' => 40, + 'X' => 10, + 'IX' => 9, + 'V' => 5, + 'IV' => 4, + 'I' => 1 + ]; + + const COLOR_CONVERSION_TABLE = [ + "BLACK" => TextFormat::BLACK, + "DARK_BLUE" => TextFormat::DARK_BLUE, + "DARK_GREEN" => TextFormat::DARK_GREEN, + "DARK_AQUA" => TextFormat::DARK_AQUA, + "DARK_RED" => TextFormat::DARK_RED, + "DARK_PURPLE" => TextFormat::DARK_PURPLE, + "GOLD" => TextFormat::GOLD, + "GRAY" => TextFormat::GRAY, + "DARK_GRAY" => TextFormat::DARK_GRAY, + "BLUE" => TextFormat::BLUE, + "GREEN" => TextFormat::GREEN, + "AQUA" => TextFormat::AQUA, + "RED" => TextFormat::RED, + "LIGHT_PURPLE" => TextFormat::LIGHT_PURPLE, + "YELLOW" => TextFormat::YELLOW, + "WHITE" => TextFormat::WHITE + ]; + + const PIGGY_ENTITIES = [ + PiggyFireball::class, + PiggyLightning::class, + PigProjectile::class, + VolleyArrow::class, + PiggyWitherSkull::class + ]; + + public $berserkercd; + public $bountyhuntercd; + public $cloakingcd; + public $endershiftcd; + public $growcd; + public $implantscd; + public $jetpackcd; + public $shrinkcd; + public $vampirecd; + + public $growremaining; + public $jetpackDisabled; + public $shrinkremaining; + public $flyremaining; + + public $chickenTick; + public $forcefieldParticleTick; + public $gasParticleTick; + public $jetpackChargeTick; + public $meditationTick; + + public $blockface; + + public $glowing; + public $grew; + public $flying; + public $hallucination; + public $implants; + public $mined; + public $moved; + public $nofall; + public $overload; + public $prowl; + public $using; + public $shrunk; + + public $formsEnabled = false; + + public static $lightningFlames = false; + public static $blazeFlames = false; + + public $enchants = [ + CustomEnchantsIds::ANTIKNOCKBACK => ["Anti Knockback", "Armor", "Damage", "Rare", 1, "Giảm 25% knockback cho bộ giáp khi Enchant."], + CustomEnchantsIds::ANTITOXIN => ["Antitoxin", "Helmets", "Effect", "Mythic", 1, "Miễn nhiễm với chất độc !"], + CustomEnchantsIds::AERIAL => ["Aerial", "Weapons", "Damage", "Common", 5, "Tăng sát thương khi đánh trên trời."], + CustomEnchantsIds::ARMORED => ["Armored", "Armor", "Damage", "Rare", 5, "Giảm sát thương của kiếm xuống 20l% khi bị đánh !"], + CustomEnchantsIds::AUTOAIM => ["Auto Aim", "Bow", "Held", "Mythic", 1, "Xác định mục tiêu đang ở gần."], + CustomEnchantsIds::AUTOREPAIR => ["Autorepair", "Damageable", "Move", "Uncommon", 5, "Tự động sửa chữa vật phẩm khi di chuyển."], + CustomEnchantsIds::BACKSTAB => ["Backstab", "Weapons", "Damage", "Uncommon", 5, "Khi đánh người chơi từ phía sau (Móc lốt), bạn sẽ nhận được nhiều sát thương hơn !"], + CustomEnchantsIds::BERSERKER => ["Berserker", "Armor", "Damaged", "Rare", 5, "Tăng sức đánh khi máu còn ít."], + CustomEnchantsIds::BLESSED => ["Blessed", "Weapons", "Damage", "Uncommon", 3, "15l% (l = cấp CE) khả năng loại bỏ hiệu ứng xấu."], + CustomEnchantsIds::BLAZE => ["Blaze", "Bow", "Shoot", "Rare", 1, "Bắn ra quả cầu lửa !!!"], + CustomEnchantsIds::BLIND => ["Blind", "Weapons", "Damage", "Common", 5, "Làm cho đối thủ bị mù !"], + CustomEnchantsIds::BOUNTYHUNTER => ["Bounty Hunter", "Bow", "Damage", "Uncommon", 5, "Nhận được vật phẩm khi bắn người chơi."], + CustomEnchantsIds::CACTUS => ["Cactus", "Armor", "Equip", "Rare", 1, "Poke people around you", "Poke people around you"], + CustomEnchantsIds::CHARGE => ["Charge", "Weapons", "Damage", "Uncommon", 5, "Tăng sát thương khi chạy nước rút."], + CustomEnchantsIds::CHICKEN => ["Chicken", "Chestplate", "Equip", "Uncommon", 5, "Đẻ ra trứng mỗi 5 phút !, 5l% (l = cấp CE) cơ hội rơi ra đồ hiếm."], + CustomEnchantsIds::CLOAKING => ["Cloaking", "Armor", "Damaged", "Uncommon", 5, "Trở thành người tàng hình khi bị đánh..."], + CustomEnchantsIds::CRIPPLINGSTRIKE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gây hiệu ứng buồn nôn và đi chậm cho kẻ thù !"], + CustomEnchantsIds::CRIPPLE => ["Cripple", "Weapons", "Damage", "Common", 5, "Gây hiệu ứng buồn nôn và đi chậm cho kẻ thù !"], + CustomEnchantsIds::CURSED => ["Cursed", "Armor", "Damaged", "Uncommon", 5, "Làm cho đối thủ bị hiệu ứng Khô khi đánh."], + CustomEnchantsIds::DEATHBRINGER => ["Deathbringer", "Weapons", "Damage", "Rare", 5, "Tăng sát thương"], + CustomEnchantsIds::DISARMING => ["Disarming", "Weapons", "Damage", "Uncommon", 5, "10l% cơ hội làm mất đồ vật trên tay đối thủ !"], + CustomEnchantsIds::DISARMOR => ["Disarmor", "Weapons", "Damage", "Uncommon", 5, "10l% cơ hội làm mất áo giáp của đối thủ !"], + CustomEnchantsIds::DRILLER => ["Driller", "Tools", "Break", "Uncommon", 5, "Phá hủy 3x3 blocks cho mỗi cấp CE !"], + CustomEnchantsIds::DRUNK => ["Drunk", "Armor", "Damaged", "Rare", 5, "Gây hiệu ứng chậm, đào chậm và buồn nôn đến đối thủ khi đánh !"], + CustomEnchantsIds::ENDERSHIFT => ["Endershift", "Armor", "Damaged", "Rare", 5, "Tăng tốc độ và máu khi người chơi sắp chết."], + CustomEnchantsIds::ENERGIZING => ["Energizing", "Tools", "Break", "Uncommon", 5, "Tăng tốc độ đào khi đập block."], + CustomEnchantsIds::ENLIGHTED => ["Enlighted", "Armor", "Damaged", "Uncommon", 5, "Cung cấp hiệu ứng hồi máu khi đánh."], + CustomEnchantsIds::ENRAGED => ["Enraged", "Chestplate", "Equip", "Rare", 5, "Tăng sức mạnh cho mỗi cấp CE"], + CustomEnchantsIds::EXPLOSIVE => ["Explosive", "Tools", "Break", "Rare", 5, "Gây ra vụ nổ lớn khi đập một block."], + CustomEnchantsIds::FARMER => ["Farmer", "Hoe", "Break", "Uncommon", 1, "Tự động trồng lại cây khi thu hoạch."], + CustomEnchantsIds::FERTILIZER => ["Fertilizer", "Hoe", "Interact", "Uncommon", 3, "Tạo ra một khu nông nghiệp trong một bán kính xung quanh khối."], + CustomEnchantsIds::FOCUSED => ["Focused", "Helmets", "Effect", "Uncommon", 5, "Giảm ảnh hưởng của effect Buồn Nôn."], + CustomEnchantsIds::FORCEFIELD => ["Forcefield", "Armor", "Equip", "Mythic", 5, "Làm lệch các mũi tên và các thực thể sống trong 0.75x (x = # áo giáp)"], + CustomEnchantsIds::FROZEN => ["Frozen", "Armor", "Damaged", "Rare", 5, "Tăng tốc độ khi đánh !"], + CustomEnchantsIds::GEARS => ["Gears", "Boots", "Equip", "Uncommon", 5, "Cung cấp effect Speed!"], + CustomEnchantsIds::GLOWING => ["Glowing", "Helmets", "Equip", "Common", 1, "Cung cấp khả năng nhìn trong bóng tối."], + CustomEnchantsIds::GOOEY => ["Gooey", "Weapons", "Damage", "Uncommon", 5, "Ném kẻ thù vào không khí."], + CustomEnchantsIds::GRAPPLING => ["Grappling", "Bow", "Projectile_Hit", "Rare", 1, "Kéo bạn đến vị trí của mũi tên khi bắn. Nếu kẻ thù bị bắn, hắn sẽ bị kéo đến bạn !"], + CustomEnchantsIds::GROW => ["Grow", "Armor", "Sneak", "Uncommon", 5, "Tăng kích thước cơ thể khi ngồi (Phải mặc đủ bộ giáp Enchant Grow)"], + CustomEnchantsIds::HALLUCINATION => ["Hallucination", "Weapons", "Damage", "Mythic", 5, "5l% (l = cấp CE) cơ hội nhốt kẻ thù trong nhà tù giả !"], + CustomEnchantsIds::HARDENED => ["Hardened", "Armor", "Damaged", "Uncommon", 5, "Gây hiệu ứng yếu đến kẻ thù khi đánh !"], + CustomEnchantsIds::HASTE => ["Haste", "Tools", "Held", "Uncommon", 5, "Cung cấp effect Đào Nhanh khi cầm."], + CustomEnchantsIds::HARVEST => ["Harvest", "Hoe", "Break", "Uncommon", 3, "Thu hoạch cây trồng trong vòng một bán kính."], + CustomEnchantsIds::HEADHUNTER => ["Headhunter", "Bow", "Damage", "Uncommon", 5, "Tăng sát thương khi bắn vào đầu."], + CustomEnchantsIds::HEALING => ["Healing", "Bow", "Damage", "Rare", 5, "Hồi máu khi bắn trúng mục tiêu."], + CustomEnchantsIds::HEAVY => ["Heavy", "Armor", "Damage", "Rare", 5, "Giảm sát thương từ rìu 20l%"], + CustomEnchantsIds::IMPLANTS => ["Implants", "Helmets", "Move", "Rare", 5, "Bổ sung thanh đói và không khí."], + CustomEnchantsIds::JETPACK => ["Jetpack", "Boots", "Sneak", "Rare", 3, "Cho phép bay (Bay ở bất kì nơi nào bạn nhìn đến) khi bạn ngồi."], + CustomEnchantsIds::JACKPOT => ["Jackpot", "Tools", "Break", "Mythic", 10, "10l% cơ hội tăng khả năng có khoáng sản."], + CustomEnchantsIds::LIFESTEAL => ["Lifesteal", "Weapons", "Damage", "Common", 5, "Hồi máu khi đánh đối thủ."], + CustomEnchantsIds::LIGHTNING => ["Lightning", "Weapons", "Damage", "Rare", 5, "10l% cơ hội để giật điện đối thủ !"], + CustomEnchantsIds::LUMBERJACK => ["Lumberjack", "Axe", "Break", "Rare", 1, "Khai thác tất cả các bản ghi khi nhật kí bị hỏng !"], + CustomEnchantsIds::MAGMAWALKER => ["Magma Walker", "Boots", "Move", "Uncommon", 2, "Biến dung nham thành Hắc Diện Thạch xung quanh bạn."], + CustomEnchantsIds::MEDITATION => ["Meditation", "Helmets", "Equip", "Uncommon", 5, "Tăng cường sức khỏe và đói mỗi 20 giây (một nửa thanh đói / tim mỗi cấp CE)"], + CustomEnchantsIds::MISSILE => ["Missile", "Bow", "Projectile_Hit", "Rare", 5, "Tạo ra TNT khi đánh !!!"], + CustomEnchantsIds::MOLOTOV => ["Molotov", "Bow", "Projectile_Hit", "Uncommon", 5, "Bắt lửa xung quanh mục tiêu."], + CustomEnchantsIds::MOLTEN => ["Molten", "Armor", "Damaged", "Rare", 5, "Đặt đối thủ lên lửa khi đánh."], + CustomEnchantsIds::OBSIDIANSHIELD => ["Obsidian Shield", "Armor", "Equip", "Common", 5, "Cung cấp khả năng chống cháy !"], + CustomEnchantsIds::OVERLOAD => ["Overload", "Armor", "Equip", "Mythic", 3, "Cung cấp thêm 1 trái tim cho mỗi cấp độ cho mỗi áo giáp"], + CustomEnchantsIds::OXYGENATE => ["Oxygenate", "Tools", "Break", "Uncommon", 1, "Có thể thở dưới nước khi cầm."], + CustomEnchantsIds::PARACHUTE => ["Parachute", "Chestplate", "Equip", "Uncommon", 1, "Làm chậm khi rơi xuống (trên 3 blocks)"], + CustomEnchantsIds::PARALYZE => ["Paralyze", "Bow", "Damage", "Rare", 5, "Gây hiệu ứng chậm, mù, và yếu..."], + CustomEnchantsIds::PIERCING => ["Piercing", "Bow", "Damage", "Rare", 5, "Bắn xuyên áo giáp của đối thủ."], + CustomEnchantsIds::POISON => ["Poison", "Weapons", "Damage", "Uncommon", 5, "Gây độc cho người chơi"], + CustomEnchantsIds::POISONOUSCLOUD => ["Poisonous Cloud", "Armor", "Equip", "Rare", 3, ""], + CustomEnchantsIds::POISONED => ["Poisoned", "Armor", "Damaged", "Uncommon", 5, "Gây độc cho đối thủ khi đánh."], + CustomEnchantsIds::PORKIFIED => ["Porkified", "Bow", "Shoot", "Mythic", 3, "Bắn lợn !!"], + CustomEnchantsIds::PROWL => ["Prowl", "Chestplate", "Equip", "Rare", 1, "Tàng hình khi ngồi."], + CustomEnchantsIds::QUICKENING => ["Quickening", "Tools", "Break", "Uncommon", 5, "Tăng tốc độ chạy khi đập block."], + CustomEnchantsIds::RADAR => ["Radar", "Compass", "Inventory", "Rare", 5, "Xác định người chơi ở gần trong 50l (l = cấp CE) blocks."], + CustomEnchantsIds::REVIVE => ["Revive", "Armor", "Death", "Rare", 5, "Có thể hồi sinh khi bạn chết (có thể làm yếu/xóa bỏ CE)"], + CustomEnchantsIds::REVULSION => ["Revulsion", "Armor", "Damaged", "Uncommon", 5, "Gây buồn nôn cho đối thủ khi đánh."], + CustomEnchantsIds::SELFDESTRUCT => ["Self Destruct", "Armor", "Damaged", "Rare", 5, "Tạo ra TNT khi bạn chết !!!"], + CustomEnchantsIds::SHIELDED => ["Shielded", "Armor", "Equip", "Rare", 3, "Tăng tốc độ hồi máu khi mặc !"], + CustomEnchantsIds::SHRINK => ["Shrink", "Armor", "Sneak", "Uncommon", 2, "Thu nhỏ cơ thể khi ngồi ! (Phải mặc đủ bộ giáp Enchant Shrink)"], + CustomEnchantsIds::SHUFFLE => ["Shuffle", "Bow", "Damage", "Rare", 1, "Dịch chuyển đến mục tiêu."], + CustomEnchantsIds::SMELTING => ["Smelting", "Tools", "Break", "Uncommon", 1, "Tự động làm hỏng block khi đập."], + CustomEnchantsIds::SOULBOUND => ["Soulbound", "Global", "Death", "Mythic", 5, "Giữ đồ vật khi bạn chết ! (có thể sẽ xóa bỏ Enchant)"], + CustomEnchantsIds::SPIDER => ["Spider", "Chestplate", "Equip", "Rare", 1, "Leo tường..."], + CustomEnchantsIds::SPRINGS => ["Springs", "Boots", "Equip", "Uncommon", 5, "Cho hiệu ứng nhảy cao."], + CustomEnchantsIds::STOMP => ["Stomp", "Boots", "Fall_Damage", "Uncommon", 5, "Chuyển sát thương sang cho đối thủ khi bạn rơi."], + CustomEnchantsIds::TANK => ["Tank", "Armor", "Damage", "Uncommon", 5, "Tạo ra TNT khi bạn chết !!!"], + CustomEnchantsIds::TELEPATHY => ["Telepathy", "Tools", "Break", "Rare", 1, "Tự động lụm item xung quanh bạn."], + CustomEnchantsIds::VACUUM => ["Vacuum", "Chestplate", "Equip", "Rare", 3, "Nhét các item trong bán kính 3l."], + CustomEnchantsIds::VAMPIRE => ["Vampire", "Weapons", "Damage", "Uncommon", 1, "Hút máu đối thủ..."], + CustomEnchantsIds::VOLLEY => ["Volley", "Bow", "Shoot", "Uncommon", 5, "Bắn nhiều mũi tên trong hình Cái Nón."], + CustomEnchantsIds::WITHER => ["Wither", "Weapons", "Damage", "Uncommon", 5, "Gây cho đối thủ effect Khô Héo."], + CustomEnchantsIds::WITHERSKULL => ["Wither Skull", "Bow", "Shoot", "Mythic", 1, "Bắn ra cái đầu của Wither !"], + CustomEnchantsIds::PLACEHOLDER => ["Placeholder", "Bow", "Shoot", "Rare", 1, ""] + ]; + + public $incompatibilities = [ + CustomEnchantsIds::GROW => [CustomEnchantsIds::SHRINK], + CustomEnchantsIds::PORKIFIED => [CustomEnchantsIds::BLAZE, CustomEnchantsIds::WITHERSKULL], + CustomEnchantsIds::VOLLEY => [CustomEnchantsIds::GRAPPLING] + ]; + + public function onEnable() + { + if (!$this->isSpoon()) { + $this->initCustomEnchants(); + $this->saveDefaultConfig(); + if ($this->getConfig()->getNested("forms.enabled")) { + if ($this->getServer()->getPluginManager()->getPlugin("FormAPI") !== null) { + $this->formsEnabled = true; + } else { + $this->getLogger()->error("Form hiện đã bật nhưng hệ thống không tìm thấy plugin FormAPI ! Vui lòng cài tại: http://123link.pw/1v62p"); + } + } + if ($this->getConfig()->getNested("blaze.flames")) { + self::$blazeFlames = true; + } + if ($this->getConfig()->getNested("lightning.flames")) { + self::$lightningFlames = true; + } + $this->jetpackDisabled = $this->getConfig()->getNested("jetpack.disabled") ?? []; + if (count($this->jetpackDisabled) > 0) { + $this->getLogger()->info(TextFormat::RED . "Jetpack hiện đang bị vô hiệu hóa ở thế giới: " . implode(", ", $this->jetpackDisabled) . "."); + } + BlockFactory::registerBlock(new PiggyObsidian(), true); + foreach (self::PIGGY_ENTITIES as $piggyEntity) { + Entity::registerEntity($piggyEntity, true); + } + + if (!ItemFactory::isRegistered(Item::ENCHANTED_BOOK)) { + ItemFactory::registerItem(new Item(Item::ENCHANTED_BOOK, 0, "Sách CustomEnchants")); + } + $this->getServer()->getCommandMap()->register("customenchant", new CustomEnchantCommand("customenchant", $this)); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new AutoAimTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new CactusTask($this), 10); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new ChickenTask($this), 20); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new ForcefieldTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new EffectTask($this), 5); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new JetpackTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new MeditationTask($this), 20); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new ParachuteTask($this), 2); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new ProwlTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new RadarTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new SizeTask($this), 20); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new SpiderTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new PoisonousGasTask($this), 1); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new VacuumTask($this), 1); + $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); + + $this->getLogger()->info(TextFormat::GREEN . "ĐÃ HOẠT ĐỘNG !"); + } + } + + public function isSpoon() + { + if ($this->getServer()->getName() !== "PocketMine-MP") { + $this->getLogger()->error("Heo không hề thích spoons !. Do đó plugin sẽ không hoạt động cho đến khi bạn sử dụng PocketMine-MP !"); + return true; + } + if ($this->getDescription()->getAuthors() !== ["DaPigGuy"] || $this->getDescription()->getName() !== "PiggyCustomEnchants") { + $this->getLogger()->error("Bạn hiện không sử dụng bản gốc của plugin này !. Hãy sử dụng (PiggyCustomEnchants) bởi DaPigGuy/MCPEPIG."); + return true; + } + return false; + } + + public function initCustomEnchants() + { + CustomEnchants::init(); + foreach ($this->enchants as $id => $data) { + $ce = $this->translateDataToCE($id, $data); + CustomEnchants::registerEnchantment($ce); + } + } + + public function registerEnchantment($id, $name, $type, $trigger, $rarity, $maxlevel, $description = "") + { + $data = [$name, $type, $trigger, $rarity, $maxlevel, $description]; + $this->enchants[$id] = $data; + $ce = $this->translateDataToCE($id, $data); + CustomEnchants::registerEnchantment($ce); + } + + public function unregisterEnchantment($id) + { + if (isset($this->enchants[$id]) && CustomEnchants::getEnchantment($id) !== null) { + unset($this->enchants[$id]); + CustomEnchants::unregisterEnchantment($id); + return true; + } + return false; + } + + public function addIncompatibility(int $id, array $incompatibilities) + { + if (!isset($this->incompatibilities[$id])) { + $this->incompatibilities[$id] = $incompatibilities; + return true; + } + return false; + } + + public function translateDataToCE($id, $data) + { + $slot = CustomEnchants::SLOT_NONE; + switch ($data[1]) { + case "Global": + $slot = CustomEnchants::SLOT_ALL; + break; + case "Weapons": + $slot = CustomEnchants::SLOT_SWORD; + break; + case "Bow": + $slot = CustomEnchants::SLOT_BOW; + break; + case "Tools": + $slot = CustomEnchants::SLOT_TOOL; + break; + case "Pickaxe": + $slot = CustomEnchants::SLOT_PICKAXE; + break; + case "Axe": + $slot = CustomEnchants::SLOT_AXE; + break; + case "Shovel": + $slot = CustomEnchants::SLOT_SHOVEL; + break; + case "Hoe": + $slot = CustomEnchants::SLOT_HOE; + break; + case "Armor": + $slot = CustomEnchants::SLOT_ARMOR; + break; + case "Helmets": + $slot = CustomEnchants::SLOT_HEAD; + break; + case "Chestplate": + $slot = CustomEnchants::SLOT_TORSO; + break; + case "Leggings": + $slot = CustomEnchants::SLOT_LEGS; + break; + case "Boots": + $slot = CustomEnchants::SLOT_FEET; + break; + case "Compass": + $slot = 0b10000000000000; + break; + } + $rarity = CustomEnchants::RARITY_COMMON; + switch ($data[3]) { + case "Common": + $rarity = CustomEnchants::RARITY_COMMON; + break; + case "Uncommon": + $rarity = CustomEnchants::RARITY_UNCOMMON; + break; + case "Rare": + $rarity = CustomEnchants::RARITY_RARE; + break; + case "Mythic": + $rarity = CustomEnchants::RARITY_MYTHIC; + break; + } + $ce = new CustomEnchants($id, $data[0], $rarity, $slot, CustomEnchants::SLOT_NONE, $data[4]); + return $ce; + } + + public function addEnchantment(Item $item, $enchants, $levels, $check = true, CommandSender $sender = null) + { + if (!is_array($enchants)) { + $enchants = [$enchants]; + } + if (!is_array($levels)) { + $levels = [$levels]; + } + if (count($enchants) > count($levels)) { + for ($i = 0; $i <= count($enchants) - count($levels); $i++) { + $levels[] = 1; + } + } + $combined = array_combine($enchants, $levels); + foreach ($enchants as $enchant) { + $level = $combined[$enchant]; + if (!$enchant instanceof CustomEnchants) { + if (is_numeric($enchant)) { + $enchant = CustomEnchants::getEnchantment((int)$enchant); + } else { + $enchant = CustomEnchants::getEnchantmentByName($enchant); + } + } + if ($enchant == null) { + if ($sender !== null) { + $sender->sendMessage(TextFormat::RED . "Enchant không hợp lệ !"); + } + continue; + } + $result = $this->canBeEnchanted($item, $enchant, $level); + if ($result === true || $check !== true) { + if ($item->getId() == Item::BOOK) { + $item = Item::get(Item::ENCHANTED_BOOK, $level); + } + $ench = $item->getNamedTagEntry(Item::TAG_ENCH); + $found = false; + if (!($ench instanceof ListTag)) { + $ench = new ListTag(Item::TAG_ENCH, [], NBT::TAG_Compound); + } else { + foreach ($ench as $k => $entry) { + if ($entry->getShort("id") === $enchant->getId()) { + $ench->set($k, new CompoundTag("", [ + new ShortTag("id", $enchant->getId()), + new ShortTag("lvl", $level) + ])); + $item->setCustomName(str_replace($this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($entry["lvl"]), $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($level), $item->getName())); + $found = true; + break; + } + } + } + if (!$found) { + $ench->push(new CompoundTag("", [ + new ShortTag("id", $enchant->getId()), + new ShortTag("lvl", $level) + ])); + $item->setCustomName($item->getName() . "\n" . $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($level)); + } + $item->setNamedTagEntry($ench); + if ($sender !== null) { + $sender->sendMessage(TextFormat::GREEN . "Enchant thành công !"); + } + continue; + } + if ($sender !== null) { + switch ($result) { + case self::NOT_COMPATIBLE: + $sender->sendMessage(TextFormat::RED . "Item này không thể kết hợp với enchant !"); + break; + case self::NOT_COMPATIBLE_WITH_OTHER_ENCHANT: + $sender->sendMessage(TextFormat::RED . "Enchant này không thể kết hợp với các loại enchant khác !"); + break; + case self::MAX_LEVEL: + $sender->sendMessage(TextFormat::RED . "Cấp độ tối đa là " . $this->getEnchantMaxLevel($enchant) . "."); + break; + + case self::MORE_THAN_ONE: + $sender->sendMessage(TextFormat::RED . "Bạn chỉ có thể enchant item trong một khoảng thời gian nhất định !"); + break; + } + } + continue; + } + return $item; + } + + public function removeEnchantment(Item $item, $enchant, $level = -1) + { + if (!$item->hasEnchantments()) { + return false; + } + if ($enchant instanceof EnchantmentInstance) { + $enchant = $enchant->getType(); + } + $ench = $item->getNamedTagEntry(Item::TAG_ENCH); + if (!($ench instanceof ListTag)) { + return false; + } + foreach ($ench as $k => $entry) { + if ($entry->getShort("id") === $enchant->getId() and ($level === -1 or $entry->getShort("lvl") === $level)) { + $ench->remove($k); + $item->setCustomName(str_replace("\n" . $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($entry->getShort("lvl")), "", $item->getCustomName())); + break; + } + } + $item->setNamedTagEntry($ench); + return $item; + } + + public function getEnchantType(CustomEnchants $enchant) + { + foreach ($this->enchants as $id => $data) { + if ($enchant->getId() == $id) { + return $data[1]; + } + } + return "Unknown"; + } + + public function getEnchantRarity(CustomEnchants $enchant) + { + foreach ($this->enchants as $id => $data) { + if ($enchant->getId() == $id) { + return $data[3]; + } + } + return "Common"; + } + + public function getEnchantMaxLevel(CustomEnchants $enchant) + { + foreach ($this->enchants as $id => $data) { + if ($enchant->getId() == $id) { + return $data[4]; + } + } + return 5; + } + + public function getEnchantDescription(CustomEnchants $enchant) + { + foreach ($this->enchants as $id => $data) { + if ($enchant->getId() == $id) { + return $data[5]; + } + } + return "Unknown"; + } + + public function sortEnchants() + { + $sorted = []; + foreach ($this->enchants as $id => $data) { + $type = $data[1]; + if (!isset($sorted[$type])) { + $sorted[$type] = [$data[0]]; + } else { + array_push($sorted[$type], $data[0]); + } + } + return $sorted; + } + + public function getRomanNumber($integer) + { + $romanString = ""; + while ($integer > 0) { + foreach (self::ROMAN_CONVERSION_TABLE as $rom => $arb) { + if ($integer >= $arb) { + $integer -= $arb; + $romanString .= $rom; + break; + } + } + } + return $romanString; + } + + public function getRarityColor($rarity) + { + switch ($rarity) { + case CustomEnchants::RARITY_COMMON: + $color = strtoupper($this->getConfig()->getNested("color.common")); + return $this->translateColorNameToTextFormat($color) == false ? TextFormat::YELLOW : $this->translateColorNameToTextFormat($color); + case CustomEnchants::RARITY_UNCOMMON: + $color = strtoupper($this->getConfig()->getNested("color.uncommon")); + return $this->translateColorNameToTextFormat($color) == false ? TextFormat::BLUE : $this->translateColorNameToTextFormat($color); + case CustomEnchants::RARITY_RARE: + $color = strtoupper($this->getConfig()->getNested("color.rare")); + return $this->translateColorNameToTextFormat($color) == false ? TextFormat::GOLD : $this->translateColorNameToTextFormat($color); + case CustomEnchants::RARITY_MYTHIC: + $color = strtoupper($this->getConfig()->getNested("color.mythic")); + return $this->translateColorNameToTextFormat($color) == false ? TextFormat::LIGHT_PURPLE : $this->translateColorNameToTextFormat($color); + default: + return TextFormat::GRAY; + } + } + + public function translateColorNameToTextFormat($color) + { + foreach (self::COLOR_CONVERSION_TABLE as $name => $textformat) { + if ($color == $name) { + return $textformat; + } + } + return false; + } + + public function canBeEnchanted(Item $item, $enchant, $level) + { + if ($enchant instanceof EnchantmentInstance) { + $enchant = $enchant->getType(); + } elseif ($enchant instanceof CustomEnchants !== true) { + $this->getLogger()->error("Enchant '$enchant' phải là một cá thể EnchantmentInstance hoặc CustomEnchants."); + return false; + } + $type = $this->getEnchantType($enchant); + if ($this->getEnchantMaxLevel($enchant) < $level) { + return self::MAX_LEVEL; + } + foreach ($this->incompatibilities as $enchantment => $incompatibilities) { + if ($item->getEnchantment($enchantment) !== null) { + if (in_array($enchant->getId(), $incompatibilities)) { + return self::NOT_COMPATIBLE_WITH_OTHER_ENCHANT; + } + } else { + foreach ($incompatibilities as $incompatibility) { + if ($item->getEnchantment($incompatibility) !== null) { + if ($enchantment == $enchant->getId() || in_array($enchant->getId(), $incompatibilities)) { + return self::NOT_COMPATIBLE_WITH_OTHER_ENCHANT; + } + } + } + } + } + if ($item->getCount() > 1) { + return self::MORE_THAN_ONE; + } + if ($item->getId() == Item::BOOK) { + return true; + } + switch ($type) { + case "Global": + return true; + case "Damageable": + if ($item instanceof Durable) { + return true; + } + break; + case "Weapons": + if ($item instanceof Sword || $item instanceof Axe || $item->getId() == Item::BOW) { + return true; + } + break; + case "Bow": + if ($item->getId() == Item::BOW) { + return true; + } + break; + case "Tools": + if ($item instanceof Pickaxe || $item instanceof Axe || $item instanceof Shovel || $item instanceof Hoe || $item instanceof Shears) { + return true; + } + break; + case "Pickaxe": + if ($item instanceof Pickaxe) { + return true; + } + break; + case "Axe": + if ($item instanceof Axe) { + return true; + } + break; + case "Shovel": + if ($item instanceof Shovel) { + return true; + } + break; + case "Hoe": + if ($item instanceof Hoe) { + return true; + } + break; + case "Armor": + if ($item instanceof Armor) { + return true; + } + break; + case "Helmets": + switch ($item->getId()) { + case Item::LEATHER_CAP: + case Item::CHAIN_HELMET: + case Item::IRON_HELMET: + case Item::GOLD_HELMET: + case Item::DIAMOND_HELMET: + return true; + } + break; + case "Chestplate": + switch ($item->getId()) { + case Item::LEATHER_TUNIC: + case Item::CHAIN_CHESTPLATE; + case Item::IRON_CHESTPLATE: + case Item::GOLD_CHESTPLATE: + case Item::DIAMOND_CHESTPLATE: + case Item::ELYTRA: + return true; + } + break; + case "Leggings": + switch ($item->getId()) { + case Item::LEATHER_PANTS: + case Item::CHAIN_LEGGINGS: + case Item::IRON_LEGGINGS: + case Item::GOLD_LEGGINGS: + case Item::DIAMOND_LEGGINGS: + return true; + } + break; + case "Boots": + switch ($item->getId()) { + case Item::LEATHER_BOOTS: + case Item::CHAIN_BOOTS: + case Item::IRON_BOOTS: + case Item::GOLD_BOOTS: + case Item::DIAMOND_BOOTS: + return true; + } + break; + case "Compass": + if ($item->getId() == Item::COMPASS) { + return true; + } + break; + } + return self::NOT_COMPATIBLE; + } + + public function checkBlocks(Position $pos, $ids, $deep = 0) + { + if (!is_array($ids)) { + $ids = [$ids]; + } + if ($deep == 0) { + $block = $pos->getLevel()->getBlock($pos); + if (!in_array($block->getId(), $ids)) { + return false; + } + } else { + for ($i = 0; $deep < 0 ? $i >= $deep : $i <= $deep; $deep < 0 ? $i-- : $i++) { + $block = $pos->getLevel()->getBlock($pos->subtract(0, $i)); + if (!in_array($block->getId(), $ids)) { + return false; + } + } + } + return true; + } + + public function findNearestEntity(Position $position, int $range = 50, string $type = Player::class, Player $player = null) + { + assert(is_a($type, Entity::class, true)); + $nearestEntity = null; + $nearestEntityDistance = $range; + foreach ($position->getLevel()->getEntities() as $entity) { + $distance = $position->distance($entity); + if ($distance <= $range && $distance < $nearestEntityDistance && $entity instanceof $type && $player !== $entity && $entity->isAlive() && $entity->isClosed() !== true && $entity->isFlaggedForDespawn() !== true) { + $nearestEntity = $entity; + $nearestEntityDistance = $distance; + } + } + return $nearestEntity; + } +} diff --git a/src/PiggyCustomEnchants/PiggyExplosion.php b/src/PiggyCustomEnchants/PiggyExplosion.php new file mode 100644 index 0000000..6258eed --- /dev/null +++ b/src/PiggyCustomEnchants/PiggyExplosion.php @@ -0,0 +1,38 @@ +plugin = $plugin; + $this->player = $player; + parent::__construct($center, $size, $player); + } + + public function explodeB(): bool + { + $result = parent::explodeB(); + foreach ($this->affectedBlocks as $index => $block) { + $ev = new BlockBreakEvent($this->player, $block, $this->player->getInventory()->getItemInHand()); + $this->plugin->getServer()->getPluginManager()->callEvent($ev); + if ($ev->isCancelled()) { + unset($this->affectedBlocks[$index]); + } else { + foreach ($ev->getDrops() as $drop) { + $this->level->dropItem($block->add(0.5, 0.5, 0.5), $drop); + } + } + } + return $result; + } +} diff --git a/src/PiggyCustomEnchants/Tasks/AutoAimTask.php b/src/PiggyCustomEnchants/Tasks/AutoAimTask.php new file mode 100644 index 0000000..c08fae9 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/AutoAimTask.php @@ -0,0 +1,51 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::AUTOAIM); + if ($enchantment !== null) { + $detected = $this->plugin->findNearestEntity($player, $enchantment->getLevel() * 50, Player::class, $player); + if (!is_null($detected)) { + if (!isset($this->lastPosition[$player->getLowerCaseName()])) { + $this->lastPosition[$player->getLowerCaseName()] = $detected->asVector3(); + } + if ($detected instanceof Player) { + if ($detected->asVector3() == $this->lastPosition[$player->getLowerCaseName()] && isset($this->plugin->moved[$player->getLowerCaseName()]) !== true) { + break; + } + if (isset($this->plugin->moved[$player->getLowerCaseName()])) { + if ($this->plugin->moved[$player->getLowerCaseName()] < 15) { + $this->plugin->moved[$player->getLowerCaseName()]++; + break; + } + unset($this->plugin->moved[$player->getLowerCaseName()]); + } + $this->lastPosition[$player->getLowerCaseName()] = $detected->asVector3(); + $player->lookAt($detected); + $player->sendPosition($player); + break; + } + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/CactusTask.php b/src/PiggyCustomEnchants/Tasks/CactusTask.php new file mode 100644 index 0000000..113e032 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/CactusTask.php @@ -0,0 +1,35 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + foreach ($player->getArmorInventory()->getContents() as $item) { + if ($item->getEnchantment(CustomEnchantsIds::CACTUS) !== null) { + foreach ($player->getLevel()->getNearbyEntities($player->getBoundingBox()->grow(1, 0, 1), $player) as $p) { + $ev = new EntityDamageByEntityEvent($player, $p, EntityDamageEvent::CAUSE_CONTACT, 1); + $p->attack($ev); + } + break; + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/ChickenTask.php b/src/PiggyCustomEnchants/Tasks/ChickenTask.php new file mode 100644 index 0000000..1482a9f --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/ChickenTask.php @@ -0,0 +1,52 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::CHICKEN); + if ($enchantment !== null) { + if (!isset($this->plugin->chickenTick[$player->getLowerCaseName()])) { + $this->plugin->chickenTick[$player->getLowerCaseName()] = 0; + } + $this->plugin->chickenTick[$player->getLowerCaseName()]++; + if ($this->plugin->chickenTick[$player->getLowerCaseName()] >= 5 * 1200) { + $random = mt_rand(0, 100); + if ($random <= 5 * $enchantment->getLevel()) { + $drops = $this->plugin->getConfig()->getNested("chicken.rare-drop"); + if (!is_array($drops)) { + $drops = ["266:0:1"]; + } + $drop = array_rand($drops, 1); + $drop = explode(":", $drops[$drop]); + $item = count($drop) < 3 ? Item::get(Item::GOLD_INGOT, 0, 1) : Item::get($drop[0], $drop[1], $drop[2]); + $vowels = ["a", "e", "i", "o", "u"]; + $player->getLevel()->dropItem($player, $item, $player->getDirectionVector()->multiply(-0.4)); + $player->sendTip(TextFormat::GREEN . "Bạn đã đặt một" . (in_array(strtolower($item->getName()[0]), $vowels) ? "n " : " ") . $item->getName() . "..."); + } else { + $player->getLevel()->dropItem($player, Item::get(Item::EGG, 0, 1), $player->getDirectionVector()->multiply(-0.4)); + $player->sendTip(TextFormat::GREEN . "Bạn đã đặt một quả trứng !"); + } + $this->plugin->chickenTick[$player->getLowerCaseName()] = 0; + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/EffectTask.php b/src/PiggyCustomEnchants/Tasks/EffectTask.php new file mode 100644 index 0000000..d54a776 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/EffectTask.php @@ -0,0 +1,88 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::HASTE); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::HASTE), 10, $enchantment->getLevel() - 1, false); + $player->addEffect($effect); + } + $enchantment = $player->getInventory()->getItemInHand()->getEnchantment(CustomEnchantsIds::OXYGENATE); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::WATER_BREATHING), 10, 0, false); + $player->addEffect($effect); + } + $enchantment = $player->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::GLOWING); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), 220, 0, false); + $player->addEffect($effect); + $this->plugin->glowing[$player->getLowerCaseName()] = true; + } else { + if (isset($this->plugin->glowing[$player->getLowerCaseName()])) { + $player->removeEffect(Effect::NIGHT_VISION); + unset($this->plugin->glowing[$player->getLowerCaseName()]); + } + } + $enchantment = $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::ENRAGED); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::STRENGTH), 10, $enchantment->getLevel() - 1, false); + $player->addEffect($effect); + } + $enchantment = $player->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::GEARS); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::SPEED), 10, 0, false); + $player->addEffect($effect); + } + $shielded = 0; + foreach ($player->getArmorInventory()->getContents(true) as $slot => $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::OBSIDIANSHIELD); + if ($enchantment !== null) { + $effect = new EffectInstance(Effect::getEffect(Effect::FIRE_RESISTANCE), 10, 0, false); + $player->addEffect($effect); + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::OVERLOAD); + if ($enchantment !== null) { + if (!isset($this->plugin->overload[$player->getLowerCaseName() . "||" . $slot])) { + $player->setMaxHealth($player->getMaxHealth() + (2 * $enchantment->getLevel())); + $player->setHealth($player->getHealth() + (2 * $enchantment->getLevel()) < $player->getMaxHealth() ? $player->getHealth() + (2 * $enchantment->getLevel()) : $player->getMaxHealth()); + $this->plugin->overload[$player->getLowerCaseName() . "||" . $slot] = $enchantment->getLevel(); + } + } else { + if (isset($this->plugin->overload[$player->getLowerCaseName() . "||" . $slot])) { + $level = $this->plugin->overload[$player->getLowerCaseName() . "||" . $slot]; + $player->setMaxHealth($player->getMaxHealth() - (2 * $level)); + if ($player->isAlive()) { + $player->setHealth($player->getHealth() - (2 * $level) < $player->getMaxHealth() ? ($player->getHealth() - (2 * $level) <= 0 ? 1 : $player->getHealth() - (2 * $level)) : $player->getMaxHealth()); + } + unset($this->plugin->overload[$player->getLowerCaseName() . "||" . $slot]); + } + } + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SHIELDED); + if ($enchantment !== null) { + $shielded += $enchantment->getLevel(); + $effect = new EffectInstance(Effect::getEffect(Effect::RESISTANCE), 10, $shielded - 1, false); + $player->addEffect($effect); + } + } + } + } +} \ No newline at end of file diff --git a/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php b/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php new file mode 100644 index 0000000..d004519 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/ForcefieldTask.php @@ -0,0 +1,65 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $forcefields = 0; + foreach ($player->getArmorInventory()->getContents() as $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::FORCEFIELD); + if ($enchantment !== null) { + $forcefields += $enchantment->getLevel(); + } + } + if ($forcefields > 0) { + $radius = $forcefields * 0.75; + $entities = $player->getLevel()->getNearbyEntities($player->getBoundingBox()->grow($radius, $radius, $radius), $player); + foreach ($entities as $entity) { + if ($entity instanceof Projectile) { + if ($entity->getOwningEntity() !== $player) { + $entity->setMotion($entity->getMotion()->multiply(-1)); + } + } else { + if (!$entity instanceof ItemEntity && is_null($entity->namedtag->getString("SlapperVersion"))) { + $entity->setMotion(new Vector3($player->subtract($entity)->normalize()->multiply(-0.75)->x, 0, $player->subtract($entity)->normalize()->multiply(-0.75)->z)); + } + } + } + if (!isset($this->plugin->forcefieldParticleTick[$player->getLowerCaseName()])) { + $this->plugin->forcefieldParticleTick[$player->getLowerCaseName()] = 0; + } + $this->plugin->forcefieldParticleTick[$player->getLowerCaseName()]++; + if ($this->plugin->forcefieldParticleTick[$player->getLowerCaseName()] >= 7.5) { + $diff = $radius / $forcefields; + for ($theta = 0; $theta <= 360; $theta += $diff) { + $x = $radius * sin($theta); + $y = 0.5; + $z = $radius * cos($theta); + $pos = $player->add($x, $y, $z); + $player->getLevel()->addParticle(new FlameParticle($pos)); + } + $this->plugin->forcefieldParticleTick[$player->getLowerCaseName()] = 0; + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/GoeyTask.php b/src/PiggyCustomEnchants/Tasks/GoeyTask.php new file mode 100644 index 0000000..865e94c --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/GoeyTask.php @@ -0,0 +1,28 @@ +plugin = $plugin; + $this->entity = $entity; + $this->level = $level; + } + + public function onRun(int $currentTick) + { + $this->entity->setMotion(new Vector3($this->entity->getMotion()->x, (3 * $this->level * 0.05) + 0.75, $this->entity->getMotion()->z)); + } +} diff --git a/src/PiggyCustomEnchants/Tasks/GrapplingTask.php b/src/PiggyCustomEnchants/Tasks/GrapplingTask.php new file mode 100644 index 0000000..1abab06 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/GrapplingTask.php @@ -0,0 +1,40 @@ +plugin = $plugin; + $this->location = $location; + $this->entity = $entity; + } + + public function onRun(int $currentTick) + { + $location = $this->location; + $entityloc = $this->entity->getPosition(); + $g = -0.08; + $d = $location->distance($entityloc); + $t = $d; + if ($t > 0) { //$t is zero if collides with the shooter of the grappling arrow, we dont want the shooter to grapple themselves + $v_x = (1.0 + 0.07 * $t) * ($location->x - $entityloc->x) / $t; + $v_y = (1.0 + 0.03 * $t) * ($location->y - $entityloc->y) / $t - 0.5 * $g * $t; + $v_z = (1.0 + 0.07 * $t) * ($location->z - $entityloc->z) / $t; + $v = $this->entity->getMotion(); + $v->setComponents($v_x, $v_y, $v_z); + $this->entity->setMotion($v); + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/HallucinationTask.php b/src/PiggyCustomEnchants/Tasks/HallucinationTask.php new file mode 100644 index 0000000..52ac7b7 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/HallucinationTask.php @@ -0,0 +1,81 @@ +plugin = $plugin; + $this->player = $player; + $this->position = $position; + } + + public function onRun(int $currentTick) + { + $position = $this->position; + $this->time++; + for ($x = $position->x - 1; $x <= $position->x + 1; $x++) { + for ($y = $position->y - 1; $y <= $position->y + 2; $y++) { + for ($z = $position->z - 1; $z <= $position->z + 1; $z++) { + $pos = new Position($x, $y, $z, $position->getLevel()); + if ($this->time >= 20 * 60) { + $position->getLevel()->sendBlocks([$this->player], [$position->getLevel()->getBlock($pos)]); + } else { + if ($pos->equals($position) !== true) { + if ($pos->equals($position->add(0, 1)) !== true) { + $block = Block::get(Block::BEDROCK); + } else { + $block = Block::get(Block::WALL_SIGN); + $nbt = new LittleEndianNBTStream(); + $nbt->writeTag(new CompoundTag("", [ + new StringTag("id", Tile::SIGN), + new StringTag("Text1", TextFormat::RED . "Có vẻ như bạn đang"), + new StringTag("Text2", TextFormat::RED . "ảo giác..."), + new StringTag("Text3", ""), + new StringTag("Text4", ""), + new IntTag("x", $pos->x), + new IntTag("y", $pos->y), + new IntTag("z", $pos->z) + ])); + $pk = new BlockEntityDataPacket(); + $pk->x = (int)$pos->x; + $pk->y = (int)$pos->y; + $pk->z = (int)$pos->z; + $pk->namedtag = $nbt->write(); + $this->player->dataPacket($pk); + } + } else { + $block = Block::get(Block::LAVA); + } + $block->setComponents((int)$pos->x, (int)$pos->y, (int)$pos->z); + $position->getLevel()->sendBlocks([$this->player], [$block]); + } + } + } + } + if ($this->time >= 20 * 60) { + unset($this->plugin->hallucination[$this->player->getLowerCaseName()]); + $this->plugin->getServer()->getScheduler()->cancelTask($this->getHandler()->getTaskId()); + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/ImplantsTask.php b/src/PiggyCustomEnchants/Tasks/ImplantsTask.php new file mode 100644 index 0000000..8632035 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/ImplantsTask.php @@ -0,0 +1,49 @@ +plugin = $plugin; + $this->player = $player; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + $player = $this->player; + if ($player->isOnline() && $player->isAlive() && ($enchantment = $player->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::IMPLANTS)) !== null) { + if (!$this->plugin->checkBlocks($player, [Block::WATER, Block::STILL_WATER, Block::FLOWING_WATER], -1)) { + $this->cancel(); + return false; + } + if ($player->getAirSupplyTicks() < $player->getMaxAirSupplyTicks()) { + $player->setAirSupplyTicks($player->getAirSupplyTicks() + ($enchantment->getLevel() * 40) > $player->getMaxAirSupplyTicks() ? $player->getMaxAirSupplyTicks() : $player->getAirSupplyTicks() + ($enchantment->getLevel() * 40)); + } else { + $this->cancel(); + return false; + } + } else { + $this->cancel(); + return false; + } + return true; + } + + public function cancel() + { + unset($this->plugin->implants[$this->player->getLowerCaseName()]); + $this->plugin->getServer()->getScheduler()->cancelTask($this->getHandler()->getTaskId()); + } +} diff --git a/src/PiggyCustomEnchants/Tasks/JetpackTask.php b/src/PiggyCustomEnchants/Tasks/JetpackTask.php new file mode 100644 index 0000000..9468271 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/JetpackTask.php @@ -0,0 +1,69 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantsIds::JETPACK); + if ($enchantment !== null) { + if (isset($this->plugin->flying[$player->getLowerCaseName()]) && $this->plugin->flying[$player->getLowerCaseName()] > time()) { + if (!in_array($player->getLevel()->getName(), $this->plugin->jetpackDisabled)) { + if ($this->plugin->flying[$player->getLowerCaseName()] - 30 <= time()) { + $player->sendTip(TextFormat::RED . "NĂNG LƯỢNG SẮP HẾT!!!. " . floor($this->plugin->flying[$player->getLowerCaseName()] - time()) . " giây nữa tắt Jetpack..."); + } else { + $time = ($this->plugin->flying[$player->getLowerCaseName()] - time()); + $time = is_float($time / 15) ? floor($time / 15) + 1 : $time / 15; + $color = $time > 10 ? TextFormat::GREEN : ($time > 5 ? TextFormat::YELLOW : TextFormat::RED); + $player->sendTip($color . "Năng lượng: " . str_repeat("▌", $time)); + } + $this->fly($player, $enchantment->getLevel()); + continue; + } + } + } + if (isset($this->plugin->flying[$player->getLowerCaseName()])) { + if ($this->plugin->flying[$player->getLowerCaseName()] > time()) { + $this->plugin->flyremaining[$player->getLowerCaseName()] = $this->plugin->flying[$player->getLowerCaseName()] - time(); + unset($this->plugin->jetpackcd[$player->getLowerCaseName()]); + } + unset($this->plugin->flying[$player->getLowerCaseName()]); + $player->sendTip(TextFormat::RED . "Jetpack disabled."); + } + if (isset($this->plugin->flyremaining[$player->getLowerCaseName()])) { + if ($this->plugin->flyremaining[$player->getLowerCaseName()] < 300) { + if (!isset($this->plugin->jetpackChargeTick[$player->getLowerCaseName()])) { + $this->plugin->jetpackChargeTick[$player->getLowerCaseName()] = 0; + } + $this->plugin->jetpackChargeTick[$player->getLowerCaseName()]++; + if ($this->plugin->jetpackChargeTick[$player->getLowerCaseName()] >= 30) { + $this->plugin->flyremaining[$player->getLowerCaseName()]++; + } + } + } + } + } + + public function fly(Player $player, $level) + { + $player->setMotion($player->getDirectionVector()->multiply($level)); + $player->getLevel()->addParticle(new FlameParticle($player)); + } +} diff --git a/src/PiggyCustomEnchants/Tasks/MeditationTask.php b/src/PiggyCustomEnchants/Tasks/MeditationTask.php new file mode 100644 index 0000000..7bd3118 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/MeditationTask.php @@ -0,0 +1,43 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getHelmet()->getEnchantment(CustomEnchantsIds::MEDITATION); + if ($enchantment !== null) { + if (!isset($this->plugin->meditationTick[$player->getLowerCaseName()])) { + $this->plugin->meditationTick[$player->getLowerCaseName()] = 0; + } + $this->plugin->meditationTick[$player->getLowerCaseName()]++; + $time = $this->plugin->meditationTick[$player->getLowerCaseName()] / 40; + $player->sendTip(TextFormat::DARK_GREEN . "Đang thiền...\n " . TextFormat::GREEN . str_repeat("▌", $time)); + if ($this->plugin->meditationTick[$player->getLowerCaseName()] >= 20 * 20) { + $this->plugin->meditationTick[$player->getLowerCaseName()] = 0; + $event = new EntityRegainHealthEvent($player, $enchantment->getLevel(), EntityRegainHealthEvent::CAUSE_MAGIC); + if (!$event->isCancelled()) { + $player->heal($event); + } + $player->setFood($player->getFood() + $enchantment->getLevel() > 20 ? 20 : $player->getFood() + $enchantment->getLevel()); + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/MoltenTask.php b/src/PiggyCustomEnchants/Tasks/MoltenTask.php new file mode 100644 index 0000000..58b941c --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/MoltenTask.php @@ -0,0 +1,27 @@ +plugin = $plugin; + $this->entity = $entity; + $this->level = $level; + } + + public function onRun(int $currentTick) + { + $this->entity->setOnFire(3 * $this->level); + } +} diff --git a/src/PiggyCustomEnchants/Tasks/ParachuteTask.php b/src/PiggyCustomEnchants/Tasks/ParachuteTask.php new file mode 100644 index 0000000..236e6e6 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/ParachuteTask.php @@ -0,0 +1,34 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $chestplate = $player->getArmorInventory()->getChestplate(); + $enchantment = $chestplate->getEnchantment(CustomEnchantsIds::PARACHUTE); + if ($enchantment !== null) { + $motion = $player->getMotion(); + if ($this->plugin->checkBlocks($player, 0, 3)) { + $player->setMotion(new Vector3(0, $motion->y * 0.75, 0)); + $player->resetFallDistance(); + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/PlaceTask.php b/src/PiggyCustomEnchants/Tasks/PlaceTask.php new file mode 100644 index 0000000..aaa30a7 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/PlaceTask.php @@ -0,0 +1,35 @@ +plugin = $plugin; + $this->position = $position; + $this->level = $level; + $this->seed = $seed; + $this->player = $player; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + $this->level->useItemOn($this->position, $this->seed, 1, $this->position, $this->player); + $this->player->getInventory()->removeItem(Item::get($this->seed->getId(), 0, 1)); + } +} diff --git a/src/PiggyCustomEnchants/Tasks/PoisonousGasTask.php b/src/PiggyCustomEnchants/Tasks/PoisonousGasTask.php new file mode 100644 index 0000000..6e20b5e --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/PoisonousGasTask.php @@ -0,0 +1,56 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + foreach ($player->getArmorInventory()->getContents() as $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::POISONOUSCLOUD); + if ($enchantment !== null) { + $radius = $enchantment->getLevel() * 3; + foreach ($player->getLevel()->getEntities() as $entity) { + if ($entity !== $player && $entity instanceof Living && $entity->distance($player) <= $radius) { + $effect = new EffectInstance(Effect::getEffect(Effect::POISON), $enchantment->getLevel() * 100, $enchantment->getLevel() - 1, false); + $entity->addEffect($effect); + } + } + if (!isset($this->plugin->gasParticleTick[$player->getLowerCaseName()])) { + $this->plugin->gasParticleTick[$player->getLowerCaseName()] = 0; + } + $this->plugin->gasParticleTick[$player->getLowerCaseName()]++; + if ($this->plugin->gasParticleTick[$player->getLowerCaseName()] >= 20) { + for ($x = -$radius; $x <= $radius; $x += 0.25) { + for ($y = -$radius; $y <= $radius; $y += 0.25) { + for ($z = -$radius; $z <= $radius; $z += 0.25) { + $random = mt_rand(1, 800 * $enchantment->getLevel()); + if ($random == 800 * $enchantment->getLevel()) { + $player->getLevel()->addParticle(new DustParticle($player->add($x, $y, $z), 34, 139, 34)); + } + } + } + } + } + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/ProwlTask.php b/src/PiggyCustomEnchants/Tasks/ProwlTask.php new file mode 100644 index 0000000..7d6ef5f --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/ProwlTask.php @@ -0,0 +1,47 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::PROWL); + if ($enchantment !== null && $player->isSneaking()) { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $p) { + $p->hidePlayer($player); + } + $effect = new EffectInstance(Effect::getEffect(Effect::SLOWNESS), 5, 0, false); + $player->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, true); + $player->addEffect($effect); + $this->plugin->prowl[$player->getLowerCaseName()] = true; + } else { + if (isset($this->plugin->prowl[$player->getLowerCaseName()])) { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $p) { + $p->showPlayer($player); + $p->removeEffect(Effect::SLOWNESS); + if (!$player->hasEffect(Effect::INVISIBILITY)) { + $player->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, false); + } + } + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/RadarTask.php b/src/PiggyCustomEnchants/Tasks/RadarTask.php new file mode 100644 index 0000000..1f2eaf7 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/RadarTask.php @@ -0,0 +1,66 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $radar = false; + foreach ($player->getInventory()->getContents() as $item) { + $enchantment = $item->getEnchantment(CustomEnchantsIds::RADAR); + if ($enchantment !== null) { + $detected = $this->plugin->findNearestEntity($player, $enchantment->getLevel() * 50, Player::class, $player); + if (!is_null($detected)) { + $pk = new SetSpawnPositionPacket(); + $pk->x = (int)$detected->x; + $pk->y = (int)$detected->y; + $pk->z = (int)$detected->z; + $pk->spawnForced = true; + $pk->spawnType = SetSpawnPositionPacket::TYPE_WORLD_SPAWN; + $player->dataPacket($pk); + $radar = true; + $this->radars[$player->getLowerCaseName()] = true; + if ($item->equalsExact($player->getInventory()->getItemInHand())) { + $player->sendTip(TextFormat::GREEN . "Người chơi ở gần còn " . round($player->distance($detected), 1) . " blocks"); + } + break; + } else { + if ($item->equalsExact($player->getInventory()->getItemInHand())) { + $player->sendTip(TextFormat::RED . "Không tìm thấy người chơi !"); + } + } + } + } + if (!$radar) { + if (isset($this->radars[$player->getLowerCaseName()])) { + $pk = new SetSpawnPositionPacket(); + $pk->x = (int)$player->getLevel()->getSafeSpawn()->x; + $pk->y = (int)$player->getLevel()->getSafeSpawn()->y; + $pk->z = (int)$player->getLevel()->getSafeSpawn()->z; + $pk->spawnForced = true; + $pk->spawnType = SetSpawnPositionPacket::TYPE_WORLD_SPAWN; + $player->dataPacket($pk); + unset($this->radars[$player->getLowerCaseName()]); + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/SizeTask.php b/src/PiggyCustomEnchants/Tasks/SizeTask.php new file mode 100644 index 0000000..f2ae00d --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/SizeTask.php @@ -0,0 +1,57 @@ +plugin = $plugin; + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $shrinkpoints = 0; + $growpoints = 0; + foreach ($player->getArmorInventory()->getContents() as $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::SHRINK); + if ($enchantment !== null) { + $shrinkpoints++; + } + } + if (isset($this->plugin->shrunk[$player->getLowerCaseName()]) && ($this->plugin->shrunk[$player->getLowerCaseName()] <= time() || $shrinkpoints < 4)) { + if ($this->plugin->shrunk[$player->getLowerCaseName()] > time()) { + $this->plugin->shrinkremaining[$player->getLowerCaseName()] = $this->plugin->shrunk[$player->getLowerCaseName()] - time(); + unset($this->plugin->shrinkcd[$player->getLowerCaseName()]); + } + unset($this->plugin->shrunk[$player->getLowerCaseName()]); + $player->setScale(1); + $player->sendTip(TextFormat::RED . "Bạn đã trở lại kích thước cũ !"); + } + foreach ($player->getArmorInventory()->getContents() as $armor) { + $enchantment = $armor->getEnchantment(CustomEnchantsIds::GROW); + if ($enchantment !== null) { + $growpoints++; + } + } + if (isset($this->plugin->grew[$player->getLowerCaseName()]) && ($this->plugin->grew[$player->getLowerCaseName()] <= time() || $growpoints < 4)) { + if ($this->plugin->grew[$player->getLowerCaseName()] > time()) { + $this->plugin->growremaining[$player->getLowerCaseName()] = $this->plugin->grew[$player->getLowerCaseName()] - time(); + unset($this->plugin->growcd[$player->getLowerCaseName()]); + } + unset($this->plugin->grew[$player->getLowerCaseName()]); + $player->setScale(1); + $player->sendTip(TextFormat::RED . "Bạn đã trở lại kích thước cũ !"); + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/SpiderTask.php b/src/PiggyCustomEnchants/Tasks/SpiderTask.php new file mode 100644 index 0000000..8bf123a --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/SpiderTask.php @@ -0,0 +1,50 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::SPIDER); + if ($enchantment !== null) { + $blocks = array_merge($player->getLevel()->getBlock($player)->getHorizontalSides(), $player->getLevel()->getBlock($player->add(0, 1))->getHorizontalSides()); + $solid = 0; + foreach ($blocks as $block) { + if ($block->getId() !== Block::AIR && $block->isSolid()) { + $solid++; + } + } + if ($solid > 0) { + if (!$player->getGenericFlag(Entity::DATA_FLAG_WALLCLIMBING)) { + $player->setGenericFlag(Entity::DATA_FLAG_WALLCLIMBING, true); + } + $player->resetFallDistance(); + } else { + if ($player->getGenericFlag(Entity::DATA_FLAG_WALLCLIMBING)) { + $player->setGenericFlag(Entity::DATA_FLAG_WALLCLIMBING, false); + } + } + } else { + if ($player->getGenericFlag(Entity::DATA_FLAG_WALLCLIMBING)) { + $player->setGenericFlag(Entity::DATA_FLAG_WALLCLIMBING, false); + } + } + } + } +} diff --git a/src/PiggyCustomEnchants/Tasks/VacuumTask.php b/src/PiggyCustomEnchants/Tasks/VacuumTask.php new file mode 100644 index 0000000..840f352 --- /dev/null +++ b/src/PiggyCustomEnchants/Tasks/VacuumTask.php @@ -0,0 +1,36 @@ +plugin = $plugin; + parent::__construct($plugin); + } + + public function onRun(int $currentTick) + { + foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { + $enchantment = $player->getArmorInventory()->getChestplate()->getEnchantment(CustomEnchantsIds::VACUUM); + if ($enchantment !== null) { + foreach ($player->getLevel()->getEntities() as $entity) { + if ($entity instanceof ItemEntity) { + $distance = $player->distance($entity); + if ($distance <= 3 * $enchantment->getLevel()) { + $entity->setMotion($player->subtract($entity)->divide(3 * $enchantment->getLevel())->multiply($enchantment->getLevel())); + } + } + } + } + } + } +}