From 2e2c1df03890413677e22afa2c4605230904e2ba Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 23 Dec 2016 19:17:08 +0100 Subject: [PATCH] Wohoo! Working elytras ! only need theadmins tools ! --- LICENSE | 2 + plugin.yml | 22 ++++ src/Ad5001/Elytra/Elytra.php | 35 +++++++ src/Ad5001/Elytra/Main.php | 116 ++++++++++++++++++++++ src/Ad5001/Elytra/tasks/AdminGotoTask.php | 83 ++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 LICENSE create mode 100644 plugin.yml create mode 100644 src/Ad5001/Elytra/Elytra.php create mode 100644 src/Ad5001/Elytra/Main.php create mode 100644 src/Ad5001/Elytra/tasks/AdminGotoTask.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1532639 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +This software is running under the Creative Commons LICENSE Attribution-NonCommercial-ShareAlike 4.0 International +which can be found at https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..32bc97c --- /dev/null +++ b/plugin.yml @@ -0,0 +1,22 @@ +--- +name: Elytra +author: Ad5001 +version: 2.0 +api: [3.0.0] +main: Ad5001\Elytra\Main +commands: + opelytra: + description: "Get an OP elytra" + usage: "/opelytra" + permission: elytra.getopelytra + boost: + description: "Boost yourself in elytra !" + usage: "/boost [strength = 2]" + permission: elytra.boost + aliases: [b] +permissions: + elytra.getopelytra: + default: op + elytra.boost: + default: true +... \ No newline at end of file diff --git a/src/Ad5001/Elytra/Elytra.php b/src/Ad5001/Elytra/Elytra.php new file mode 100644 index 0000000..6148f67 --- /dev/null +++ b/src/Ad5001/Elytra/Elytra.php @@ -0,0 +1,35 @@ +getServer()->getPluginManager()->registerEvents($this,$this); + $this->getServer()->getScheduler()->scheduleRepeatingTask(new AdminGotoTask($this), 20); + Item::$list[444] = Elytra::class; + Item::addCreativeItem(new Elytra()); + } + + + /* + Prevent when someone is falling + @param $event \pocketmine\event\entity\EntityDamageEvent + @return null + */ + public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) { + if($event->getCause() == 4 && $event->getEntity()->getInventory()->getChestplate()->getId() == 444) { + $event->setCancelled(); + } + } + + + /* + Prevents the player from being kicked of flyign by using the elytras. + @param $event \pocketmine\event\player\PlayerKickEvent + */ + public function onPlayerKick(\pocketmine\event\player\PlayerKickEvent $event) { + if(strpos($event->getReason(), "Flying is not enabled on this server") !== false && $event->getPlayer()->getInventory()->getChestplate()->getId() == 444) { + $event->setCancelled(); + } + } + + + /* + Called when one of the defined commands of the plugin has been called + @param $sender \pocketmine\command\CommandSender + @param $cmd \pocketmine\command\Command + @param $label mixed + @param $args array + return bool + */ + public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd,$label, array $args): bool { + switch($cmd->getName()) { + case "opelytra": + if($sender instanceof Player) { + $item = new Elytra(); + $nbt = new CompoundTag("", [ + "isAdminPowered" => new StringTag("isAdminPowered", 1) + ]); + $item->setCompoundTag($nbt); + $item->addEnchantment(Enchantment::getEnchantement(0)->setLevel(0)); + $sender->getInventory()->addItem($item); + $sender->sendMessage("§aYou got your brand new elytra !"); + } + break; + case "boost": + if($sender instanceof Player && $sender->getInventory()->getChestplate()->getId() == 444) { + $itr = new BlockIterator($sender->getLevel(), $sender->getPosition(), $sender->getDirectionVector(), $sender->getEyeHeight(), 7); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $sender->setMotion($itr->current()); + } + break; + } + return false; + } + +} \ No newline at end of file diff --git a/src/Ad5001/Elytra/tasks/AdminGotoTask.php b/src/Ad5001/Elytra/tasks/AdminGotoTask.php new file mode 100644 index 0000000..62a9779 --- /dev/null +++ b/src/Ad5001/Elytra/tasks/AdminGotoTask.php @@ -0,0 +1,83 @@ +main = $main; + + + $this->server = $main->getServer(); + + + } + + + + + public function onRun($tick) { + foreach ($this->server->getOnlinePlayers() as $player) { + if($player->getInventory()->getChestplate()->getId() == 444) { + if($player->getInventory()->getChestplate()->getNamedTagEntry("isAdminPowered") !== null) { + $itr = new BlockIterator($player->getLevel(), $player->getPosition(), $player->getDirectionVector(), $player->getEyeHeight(), 7); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $itr->next(); + $player->setMotion($itr->current); + } + // $player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 0, $player->getMotion()->z)); + } + + + //Part needed for player's good working + $ref = new \ReflectionClass("pocketmine\\Player"); + $prop = $ref->getProperty("gravity"); + $prop->setAccessible(true); + $prop->setValue($player, 0); + $prop->setAccessible(false); + if($player->getMotion()->y !== 0) { + // echo "{$player->getName()}:" . $player->getMotion()->y . "\n"; + } + } + } + + + + +} \ No newline at end of file