Skip to content

Commit

Permalink
Some fix and update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuongaz committed Nov 29, 2020
1 parent 3d2789d commit 18c4286
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 14 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,37 @@

Wing particle plugin for Pocketmine-MP

# Feature
+ Add and custom wing in config
+ FormAPI Support

# Example Config
```
shape: [
[0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0],
[0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1],
[1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1],
[1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1]]
Wing-Name: "Example Wing"
```

# List Particles
```
0: space
4 : Red Dust
2: Green Dust
x: Redstone
f: Flame
b: Blue Flame
h: Villager Happy
p: Villager Angry
```

# How to get a wing
+ Add permision to player `wing.on.<wing name>`

![117837516_1453484918179354_1316757255971479986_n.png](https://www.upsieutoc.com/images/2020/08/18/117837516_1453484918179354_1316757255971479986_n.png)
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: EasyWing
main: phuongaz\EasyWing\Loader
author: phuongaz
version: 1.0.2
api: 3.15.0
version: 1.0.3
api: 3.0.0
6 changes: 6 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tick-update: 10 #0.5s

title: "WINGS FORM"

turn-on: "Turn on wing"
turn-off: "Turn off wing"
52 changes: 41 additions & 11 deletions src/phuongaz/EasyWing/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
use pocketmine\Player;
use phuongaz\EasyWing\task\WingTask;
use phuongaz\EasyWing\command\WingsCommand;

use phuongaz\EasyWing\utils\Particles;
use pocketmine\level\particle\{
DustParticle,
FlameParticle,
RedstoneParticle,
Particle
};
use pocketmine\math\Vector3;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerQuitEvent;

Class Loader extends PluginBase{
Class Loader extends PluginBase implements Listener{

/** @var array */
private static $equip_players = [];
Expand All @@ -25,13 +27,25 @@
private static $instance;

public function onEnable() :void{
$this->saveDefaultConfig();
$this->saveResource("wings/example.yml");
foreach(glob($this->getDataFolder(). "wings/*.yml") as $wingPath){
$wingName = pathinfo($wingPath, PATHINFO_FILENAME);
self::$wings[$wingName] = yaml_parse_file($wingPath);
}
self::$instance = $this;
$this->getServer()->getCommandMap()->register("wings", new WingsCommand());
$this->getServer()->getCommandMap()->register("EasyWing", new WingsCommand());
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}

/**
* @param PlayerQuitEvent $event
*
* @return void
*/
public function onQuit(PlayerQuitEvent $event) :void {
$player = $event->getPlayer();
$this->unEquip($player);
}

/**
Expand All @@ -48,6 +62,14 @@ public static function getWings() :array{
return self::$wings;
}

/**
* @return array
*/
public function getSetting() :array
{
return yaml_parse_file($this->getDataFolder(). "config.yml");
}

/**
* @param Player $player
* @param string $wing
Expand Down Expand Up @@ -75,8 +97,17 @@ public function parseWing(Vector3 $pos, $character) :Particle{
case "4":
$particle = new DustParticle($pos, 179, 0, 0);
break;
default:
$particle = new FlameParticle($pos);
case "b":
$particle = new Particles(Particles::BLUE_FLAME, $pos);
break;
case "h":
$particle = new Particles(Particles::VILLAGER_HAPPY, $pos);
break;
case "p":
$particle = new Particles(Particles::VILLAGER_ANGRY, $pos);
break;
case "f":
$particle = new Particles(Particles::FLAME, $pos);
break;
}
return $particle;
Expand All @@ -94,24 +125,23 @@ public function equipWing(Player $player, string $wing) :void {
$shape = self::getWings()[$wing]["shape"];
$lowername = $player->getLowerCaseName();
$wingtask = new WingTask($player, $shape);

if(!isset(self::$equip_players[$lowername])){
$this->getScheduler()->scheduleRepeatingTask($wingtask, $this->getSetting()["tick-update"]);
self::$equip_players[$lowername]["id"] = $wingtask->getTaskId();
self::$equip_players[$lowername]["name"] = $wing;
$player->sendMessage("Turn on $wing wing");
$this->getScheduler()->scheduleRepeatingTask($wingtask, 5);
$player->sendMessage($this->getSetting()["turn-on"]);
return;
}
if(self::$equip_players[$lowername]["name"] == $wing){
$player->sendMessage("Turn off $wing wing");
$player->sendMessage($this->getSetting()["turn-off"]);
$this->unEquip($player);
return;
}else{
$this->unEquip($player);
$this->getScheduler()->scheduleRepeatingTask($wingtask, $this->getSetting()["tick-update"]);
self::$equip_players[$lowername]["id"] = $wingtask->getTaskId();
self::$equip_players[$lowername]["name"] = $wing;
$player->sendMessage("Turn on $wing wing");
$this->getScheduler()->scheduleRepeatingTask($wingtask, 5);
$player->sendMessage($this->getSetting()["turn-on"]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/phuongaz/EasyWing/form/WingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function send() :void{
$wing = array_keys(Loader::getWings())[$data];
$loader->equipWing($player, $wing);
});
$form->setTitle("WINGS FORM");
$form->setTitle($loader->getSetting()["title"]);
foreach($loader->getWings() as $wingName){
$form->addButton($wingName["Wing-Name"]);
}
Expand Down
38 changes: 38 additions & 0 deletions src/phuongaz/EasyWing/utils/Particles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace phuongaz\EasyWing\utils;

use pocketmine\level\particle\Particle;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\SpawnParticleEffectPacket;

class Particles extends Particle {

public const DRAGON_BREATH_TRAIL = "minecraft:dragon_breath_trail";
public const DRAGON_BREATH_LINGERING = "minecraft:dragon_breath_lingering";
public const VILLAGER_HAPPY = "minecraft:villager_happy";
public const MOBSPELL_EMITTER = "minecraft:mobspell_emitter";
public const FLAME = "minecraft:basic_flame_particle";
public const VILLAGER_ANGRY = "minecraft:villager_angry";
public const BLUE_FLAME = "minecraft:blue_flame_particle";

/** @var string $name */
private $name;

/**
* CustomParticle constructor.
* @param string $particleName
* @param Vector3 $pos
*/
public function __construct(string $particleName, Vector3 $pos) {
$this->name = $particleName;
parent::__construct($pos->getX(), $pos->getY(), $pos->getZ());
}

public function encode() {
$pk = new SpawnParticleEffectPacket();
$pk->position = $this->asVector3();
$pk->particleName = $this->name;
return $pk;
}
}

0 comments on commit 18c4286

Please sign in to comment.