Wohoo! Working elytras ! only need theadmins tools !

This commit is contained in:
Ad5001 2016-12-23 19:17:08 +01:00
commit 2e2c1df038
5 changed files with 258 additions and 0 deletions

2
LICENSE Normal file
View file

@ -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

22
plugin.yml Normal file
View file

@ -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
...

View file

@ -0,0 +1,35 @@
<?php
namespace Ad5001\Elytra;
use pocketmine\Server;
use pocketmine\Player;
use pocketmine\item\Armor;
use Ad5001\Elytra\Main;
class Elytra extends Armor {
public function __construct($meta = 0, $count = 1){
parent::__construct(444, $meta, $count, "Elytra");
}
}

116
src/Ad5001/Elytra/Main.php Normal file
View file

@ -0,0 +1,116 @@
<?php
namespace Ad5001\Elytra;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\Player;
use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\item\enchantment\Enchantment;
use Ad5001\Elytra\tasks\AdminGotoTask;
class Main extends PluginBase implements Listener {
/*
Called when the plugin enables
*/
public function onEnable() {
$this->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;
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace Ad5001\Elytra\tasks;
use pocketmine\Server;
use pocketmine\scheduler\PluginTask;
use pocketmine\utils\BlockIterator;
use pocketmine\Player;
use Ad5001\Elytra\Main;
class AdminGotoTask extends PluginTask {
public function __construct(Main $main) {
parent::__construct($main);
$this->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";
}
}
}
}