commit
77afc5c638
6 changed files with 136 additions and 237 deletions
|
@ -1,9 +1,11 @@
|
||||||
---
|
|
||||||
name: Elytra
|
name: Elytra
|
||||||
author: Ad5001
|
author: Ad5001
|
||||||
version: 2.0
|
version: 2.1
|
||||||
api: [3.0.0-ALPHA1, 3.0.0, 2.0.0]
|
api:
|
||||||
|
- 3.0.0
|
||||||
|
- 3.0.0-ALPHA7
|
||||||
main: Ad5001\Elytra\Main
|
main: Ad5001\Elytra\Main
|
||||||
|
load: STARTUP
|
||||||
commands:
|
commands:
|
||||||
opelytra:
|
opelytra:
|
||||||
description: "Make your elytras your wear MAGIC !"
|
description: "Make your elytras your wear MAGIC !"
|
||||||
|
@ -19,4 +21,3 @@ permissions:
|
||||||
default: op
|
default: op
|
||||||
elytra.boost:
|
elytra.boost:
|
||||||
default: true
|
default: true
|
||||||
...
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# Welcome to Elytras 2.x.x config !
|
# Welcome to Elytra 2.x.x config !
|
||||||
|
|
||||||
# Here configure which block are considered "bouncable", enter their ids.
|
# Here configure which block are considered "bouncable", enter their ids.
|
||||||
# Try going on those blocks by usini the elytra and the see the magic.
|
# Try going on those blocks by using the elytra and the see the magic.
|
||||||
bouncable_blocks: [165, 88]
|
bouncable_blocks: [165, 88]
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Ad5001\Elytra;
|
namespace Ad5001\Elytra;
|
||||||
|
|
||||||
use pocketmine\item\Armor;
|
use pocketmine\item\Armor;
|
||||||
|
@ -9,16 +8,4 @@ class Elytra extends Armor{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(444, $meta, $count, "Elytra Wings");
|
parent::__construct(444, $meta, $count, "Elytra Wings");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArmorType(){
|
|
||||||
return Armor::TYPE_CHESTPLATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMaxDurability(){
|
|
||||||
return 431;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isChestplate(){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,154 +1,128 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Ad5001\Elytra;
|
namespace Ad5001\Elytra;
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\command\CommandSender;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\command\Command;
|
use pocketmine\command\Command;
|
||||||
|
use pocketmine\command\CommandSender;
|
||||||
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
|
use pocketmine\event\player\PlayerKickEvent;
|
||||||
|
use pocketmine\event\player\PlayerMoveEvent;
|
||||||
use pocketmine\plugin\PluginBase;
|
use pocketmine\event\server\DataPacketReceiveEvent;
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\Server;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\Player;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\plugin\PluginBase;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
use pocketmine\utils\BlockIterator;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\item\enchantment\Enchantment;
|
|
||||||
|
|
||||||
|
|
||||||
use Ad5001\Elytra\tasks\AdminGotoTask;
|
use Ad5001\Elytra\tasks\AdminGotoTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Main extends PluginBase implements Listener {
|
class Main extends PluginBase implements Listener {
|
||||||
|
|
||||||
protected $ops;
|
protected $ops = [];
|
||||||
|
|
||||||
/*
|
|
||||||
Called when the plugin enables
|
|
||||||
*/
|
|
||||||
public function onEnable() {
|
public function onEnable() {
|
||||||
$this->getServer()->getPluginManager()->registerEvents($this,$this);
|
$this->saveDefaultConfig();
|
||||||
|
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new AdminGotoTask($this), 10);
|
$this->getServer()->getScheduler()->scheduleRepeatingTask(new AdminGotoTask($this), 10);
|
||||||
Item::$list[444] = Elytra::class;
|
Item::$list[444] = Elytra::class;
|
||||||
Item::addCreativeItem(new Elytra());
|
Item::addCreativeItem(new Elytra());
|
||||||
$this->ops = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* @priority LOW
|
||||||
Prevent when someone is falling
|
*
|
||||||
@param $event \pocketmine\event\entity\EntityDamageEvent
|
* @param EntityDamageEvent $event
|
||||||
@return null
|
|
||||||
*/
|
*/
|
||||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
|
public function onEntityDamage(EntityDamageEvent $event) {
|
||||||
if($event->getCause() == 4 && $event->getEntity()->getInventory()->getChestplate()->getId() == 444) {
|
$damaged = $event->getEntity();
|
||||||
|
if($damaged instanceof Player) {
|
||||||
|
if($event->getCause() == 4 and $damaged->getInventory()->getChestplate()->getId() == 444) {
|
||||||
|
$event->setCancelled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @priority LOW
|
||||||
|
*
|
||||||
|
* @param PlayerKickEvent $event
|
||||||
|
*/
|
||||||
|
public function onPlayerKick(PlayerKickEvent $event) {
|
||||||
|
if(strpos(strtolower($event->getReason()), "flying") !== false and $event->getPlayer()->getInventory()->getChestplate()->getId() == 444) {
|
||||||
$event->setCancelled();
|
$event->setCancelled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* @priority LOW
|
||||||
Prevents the player from being kicked of flyign by using the elytras.
|
*
|
||||||
@param $event \pocketmine\event\player\PlayerKickEvent
|
* @param PlayerMoveEvent $event
|
||||||
*/
|
*/
|
||||||
public function onPlayerKick(\pocketmine\event\player\PlayerKickEvent $event) {
|
public function onPlayerMove(PlayerMoveEvent $event) {
|
||||||
if(strpos($event->getReason(), "Flying is not enabled on this server") !== false && $event->getPlayer()->getInventory()->getChestplate()->getId() == 444) {
|
|
||||||
$event->setCancelled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
When a player moves. To make it bounce with elytras.
|
|
||||||
@param $event \pocketmine\event\player\PlayerMoveEvent
|
|
||||||
*/
|
|
||||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
|
|
||||||
$player = $event->getPlayer();
|
$player = $event->getPlayer();
|
||||||
if($player->getInventory()->getChestplate()->getId() == 444) {
|
if($player->getInventory()->getChestplate()->getId() == 444) {
|
||||||
$flyingup = false;
|
$flyingUp = false;
|
||||||
|
// TODO: change Bounding Box of player depending on their angle of flight
|
||||||
for($i = 2; $i > 0; $i--) {
|
for($i = 2; $i > 0; $i--) {
|
||||||
if($player->getLevel()->getBlock(new \pocketmine\math\Vector3 (round($player->x), round($player->y) - $i, round($player->z)))->getId() !== 0) {
|
if($player->getLevel()->getBlock(new Vector3(round($player->x), round($player->y) - $i, round($player->z)))->getId() !== 0) {
|
||||||
$flyingup = true;
|
$flyingUp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isset($this->getAdminsModePlayers()[$player->getName()]) && $flyingup) {
|
if(isset($this->ops[$player->getName()]) and $flyingUp) {
|
||||||
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
$player->setMotion(new Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
||||||
}
|
}
|
||||||
$flyingup = false;
|
$flyingUp = false;
|
||||||
for($i = 4; $i > 0; $i--) {
|
for($i = 4; $i > 0; $i--) {
|
||||||
$id = $player->getLevel()->getBlock(new \pocketmine\math\Vector3 (round($player->x), round($player->y) - $i, round($player->z)))->getId();
|
$id = $player->getLevel()->getBlock(new Vector3 (round($player->x), round($player->y) - $i, round($player->z)))->getId();
|
||||||
if(in_array($id, $this->getConfig()->get("bouncable_blocks"))) {
|
if(in_array($id, $this->getConfig()->get("bouncable_blocks",[]))) {
|
||||||
$flyingup = true;
|
$flyingUp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($flyingup) {
|
if($flyingUp) {
|
||||||
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
$player->setMotion(new Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onDataPacket(DataPacketReceiveEvent $ev) {
|
||||||
|
$packet = $ev->getPacket();
|
||||||
|
if($packet instanceof PlayerActionPacket) {
|
||||||
|
if($packet->action === PlayerActionPacket::ACTION_START_GLIDE) {
|
||||||
|
$ev->getPlayer()->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_GLIDING, true, Player::DATA_TYPE_BYTE);
|
||||||
|
}elseif($packet->action === PlayerActionPacket::ACTION_STOP_GLIDE) {
|
||||||
|
$ev->getPlayer()->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_GLIDING, false, Player::DATA_TYPE_BYTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Called when one of the defined commands of the plugin has been called
|
* @param CommandSender $sender
|
||||||
@param $sender \pocketmine\command\CommandSender
|
* @param Command $cmd
|
||||||
@param $cmd \pocketmine\command\Command
|
* @param string $label
|
||||||
@param $label mixed
|
* @param array $args
|
||||||
@param $args array
|
* @return bool
|
||||||
return bool
|
|
||||||
*/
|
*/
|
||||||
public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd,$label, array $args): bool {
|
public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool {
|
||||||
switch($cmd->getName()) {
|
switch($cmd->getName()) {
|
||||||
case "opelytra":
|
case "opelytra":
|
||||||
if($sender instanceof Player) {
|
if($sender instanceof Player) {
|
||||||
if(isset($this->ops[$sender->getName()])) {
|
if(isset($this->ops[$sender->getName()])) {
|
||||||
unset($this->ops[$sender->getName()]);
|
unset($this->ops[$sender->getName()]);
|
||||||
$sender->sendMessage("§aYou are back to te original elytra !");
|
$sender->sendMessage(TextFormat::GREEN."You are back to the original elytra!");
|
||||||
} else {
|
} else {
|
||||||
$this->ops[$sender->getName()] = true;
|
$this->ops[$sender->getName()] = true;
|
||||||
$sender->sendMessage("§aYou are now in the admin elytra mode ! Go try out your powers !");
|
$sender->sendMessage(TextFormat::GREEN."You are now in the admin elytra mode! Go try out your powers!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "boost":
|
case "boost":
|
||||||
if($sender instanceof Player && $sender->getInventory()->getChestplate()->getId() == 444) {
|
if($sender instanceof Player and $sender->getInventory()->getChestplate()->getId() == 444) {
|
||||||
if(!isset($args[0])) $args[0] = 2;
|
if(!isset($args[0])) $args[0] = 2;
|
||||||
$sender->setMotion(new \pocketmine\math\Vector3($sender->getMotion()->x, $args[0], $sender->getMotion()->z));
|
$sender->setMotion(new Vector3($sender->getMotion()->x, $args[0], $sender->getMotion()->z));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Returns players in ADMIN mode
|
|
||||||
@return array
|
|
||||||
*/
|
|
||||||
public function getAdminsModePlayers() : array {
|
|
||||||
return $this->ops;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,88 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Ad5001\Elytra\tasks;
|
namespace Ad5001\Elytra\tasks;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\Server;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\scheduler\PluginTask;
|
use pocketmine\scheduler\PluginTask;
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\utils\BlockIterator;
|
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\Player;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use Ad5001\Elytra\Main;
|
use Ad5001\Elytra\Main;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AdminGotoTask extends PluginTask {
|
class AdminGotoTask extends PluginTask {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Main $main) {
|
public function __construct(Main $main) {
|
||||||
|
|
||||||
|
|
||||||
parent::__construct($main);
|
parent::__construct($main);
|
||||||
|
|
||||||
|
|
||||||
$this->main = $main;
|
|
||||||
|
|
||||||
|
|
||||||
$this->server = $main->getServer();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public function onRun(int $tick) {
|
||||||
|
foreach ($this->getOwner()->getServer()->getOnlinePlayers() as $player) {
|
||||||
|
//Part needed for players to fly upwards
|
||||||
|
|
||||||
public function onRun($tick) {
|
|
||||||
foreach ($this->server->getOnlinePlayers() as $player) {
|
|
||||||
|
|
||||||
|
|
||||||
//Part needed for player's good working
|
|
||||||
$ref = new \ReflectionClass("pocketmine\\Player");
|
$ref = new \ReflectionClass("pocketmine\\Player");
|
||||||
$prop = $ref->getProperty("gravity");
|
$prop = $ref->getProperty("gravity");
|
||||||
$prop->setAccessible(true);
|
$prop->setAccessible(true);
|
||||||
$prop->setValue($player, 0);
|
$prop->setValue($player, 0);
|
||||||
$prop->setAccessible(false);
|
$prop->setAccessible(false);
|
||||||
if($player->getMotion()->y !== 0) {
|
if($player->getMotion()->y !== 0) {
|
||||||
// echo "{$player->getName()}:" . $player->getMotion()->y . "\n";
|
$this->getOwner()->getLogger()->debug("{$player->getName()}'s y motion is {$player->getMotion()->y}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Inverts a number
|
|
||||||
@param $num int
|
|
||||||
@return int
|
|
||||||
*/
|
|
||||||
public function invert(int $num) : int {
|
|
||||||
if($num < 0) {
|
|
||||||
echo $num . " +> " . abs($num) . "\n";
|
|
||||||
return abs($num);
|
|
||||||
} else {
|
|
||||||
echo $num . " -> " . -$num . "\n";
|
|
||||||
return -$num;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue