Gone waaaayyy too far ! Admin tools bouncy everywhere + bouncy blocks !
This commit is contained in:
parent
2e2c1df038
commit
ca46db5931
3 changed files with 80 additions and 28 deletions
|
@ -6,7 +6,7 @@ api: [3.0.0]
|
||||||
main: Ad5001\Elytra\Main
|
main: Ad5001\Elytra\Main
|
||||||
commands:
|
commands:
|
||||||
opelytra:
|
opelytra:
|
||||||
description: "Get an OP elytra"
|
description: "Make your elytras your wear MAGIC !"
|
||||||
usage: "/opelytra"
|
usage: "/opelytra"
|
||||||
permission: elytra.getopelytra
|
permission: elytra.getopelytra
|
||||||
boost:
|
boost:
|
||||||
|
|
|
@ -29,6 +29,9 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
|
|
||||||
|
|
||||||
|
use pocketmine\utils\BlockIterator;
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\item\enchantment\Enchantment;
|
use pocketmine\item\enchantment\Enchantment;
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,14 +44,17 @@ use Ad5001\Elytra\tasks\AdminGotoTask;
|
||||||
|
|
||||||
class Main extends PluginBase implements Listener {
|
class Main extends PluginBase implements Listener {
|
||||||
|
|
||||||
|
protected $ops;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Called when the plugin enables
|
Called when the plugin enables
|
||||||
*/
|
*/
|
||||||
public function onEnable() {
|
public function onEnable() {
|
||||||
$this->getServer()->getPluginManager()->registerEvents($this,$this);
|
$this->getServer()->getPluginManager()->registerEvents($this,$this);
|
||||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new AdminGotoTask($this), 20);
|
$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 = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,6 +81,36 @@ class Main extends PluginBase implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
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();
|
||||||
|
if($player->getInventory()->getChestplate()->getId() == 444) {
|
||||||
|
$flyingup = false;
|
||||||
|
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) {
|
||||||
|
$flyingup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(isset($this->getAdminsModePlayers()[$player->getName()]) && $flyingup) {
|
||||||
|
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
||||||
|
}
|
||||||
|
$flyingup = false;
|
||||||
|
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();
|
||||||
|
if($id == 165 || $id == 88) {
|
||||||
|
$flyingup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($flyingup) {
|
||||||
|
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 3, $player->getMotion()->z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Called when one of the defined commands of the plugin has been called
|
Called when one of the defined commands of the plugin has been called
|
||||||
@param $sender \pocketmine\command\CommandSender
|
@param $sender \pocketmine\command\CommandSender
|
||||||
|
@ -87,30 +123,41 @@ class Main extends PluginBase implements Listener {
|
||||||
switch($cmd->getName()) {
|
switch($cmd->getName()) {
|
||||||
case "opelytra":
|
case "opelytra":
|
||||||
if($sender instanceof Player) {
|
if($sender instanceof Player) {
|
||||||
$item = new Elytra();
|
if(isset($this->ops[$sender->getName()])) {
|
||||||
$nbt = new CompoundTag("", [
|
unset($this->ops[$sender->getName()]);
|
||||||
"isAdminPowered" => new StringTag("isAdminPowered", 1)
|
$sender->sendMessage("§aYou are back to te original elytra !");
|
||||||
]);
|
} else {
|
||||||
$item->setCompoundTag($nbt);
|
$this->ops[$sender->getName()] = true;
|
||||||
$item->addEnchantment(Enchantment::getEnchantement(0)->setLevel(0));
|
$sender->sendMessage("§aYou are now in the admin elytra mode ! Go try out your powers !");
|
||||||
$sender->getInventory()->addItem($item);
|
}
|
||||||
$sender->sendMessage("§aYou got your brand new elytra !");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "boost":
|
case "boost":
|
||||||
if($sender instanceof Player && $sender->getInventory()->getChestplate()->getId() == 444) {
|
if($sender instanceof Player && $sender->getInventory()->getChestplate()->getId() == 444) {
|
||||||
$itr = new BlockIterator($sender->getLevel(), $sender->getPosition(), $sender->getDirectionVector(), $sender->getEyeHeight(), 7);
|
$itr = new BlockIterator($sender->getLevel(), $sender->getPosition(), $sender->getDirectionVector(), $sender->getEyeHeight(), 4);
|
||||||
$itr->next();
|
$itr->next();
|
||||||
$itr->next();
|
$itr->next();
|
||||||
$itr->next();
|
$itr->next();
|
||||||
$itr->next();
|
$x = sqrt((new \pocketmine\math\Vector3($sender->x, 0, 0))->distanceSquared(new \pocketmine\math\Vector3($itr->current()->x, 0, 0)));
|
||||||
$itr->next();
|
$y = sqrt((new \pocketmine\math\Vector3($sender->y, 0, 0))->distanceSquared(new \pocketmine\math\Vector3($itr->current()->y, 0, 0)));
|
||||||
$itr->next();
|
$z = sqrt((new \pocketmine\math\Vector3($sender->z, 0, 0))->distanceSquared(new \pocketmine\math\Vector3($itr->current()->z, 0, 0)));
|
||||||
$sender->setMotion($itr->current());
|
// $x -= $x * 2;
|
||||||
|
// $y -= $y * 2;
|
||||||
|
// $z -= $z * 2; // Inverting the number to go in the right direction.
|
||||||
|
$sender->setMotion(new \pocketmine\math\Vector3($x, $y, $z));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns players in ADMIN mode
|
||||||
|
@return array
|
||||||
|
*/
|
||||||
|
public function getAdminsModePlayers() : array {
|
||||||
|
return $this->ops;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -50,19 +50,6 @@ class AdminGotoTask extends PluginTask {
|
||||||
|
|
||||||
public function onRun($tick) {
|
public function onRun($tick) {
|
||||||
foreach ($this->server->getOnlinePlayers() as $player) {
|
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
|
//Part needed for player's good working
|
||||||
|
@ -79,5 +66,23 @@ class AdminGotoTask extends PluginTask {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
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