From ebaf2e01f57f9888b2d52f1f37f5498795d8beb9 Mon Sep 17 00:00:00 2001 From: alejandroliu Date: Mon, 31 Oct 2016 13:49:11 +0100 Subject: [PATCH] 1.0.2 --- README.md | 23 +++++++ .../FireBlade-icon.png | Bin plugin.yml | 3 +- src/aliuly/fireblade/FireBlade.php | 35 ++++++++-- src/aliuly/fireblade/PluginCallbackTask.php | 65 ++++++++++++++++++ 5 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 README.md rename FireBlade-icon.png => media/FireBlade-icon.png (100%) create mode 100644 src/aliuly/fireblade/PluginCallbackTask.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..dec3a49 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ + + +# FireBlade + +FireBlade gives you a flaming sword. When you have an Iron or a Golden +sword on hand you can enter: + + /fireblade + +This will turn on your flaming sword. Which will toggle colors to +indicate its active state. When you hit another player (or mobs +perhaps) with it, it will deal damage but also will set the target on +fire. + +Changes +======= + +* 1.0.2: + * Added forgotten permission +* 1.0.1: + * Better configuration + * Removed CallbackTask deprecation warning +* 1.0.0: First release diff --git a/FireBlade-icon.png b/media/FireBlade-icon.png similarity index 100% rename from FireBlade-icon.png rename to media/FireBlade-icon.png diff --git a/plugin.yml b/plugin.yml index 84bc308..c25800c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -4,13 +4,14 @@ load: POSTWORLD name: FireBlade description: Turn a Sword into a flaming sword -version: 1.0.0 +version: 1.0.2 author: aliuly commands: fireblade: description: Turn your sword into a flaming sword usage: "/fireblade" + permission: fireblade.cmd permissions: fireblade.cmd: diff --git a/src/aliuly/fireblade/FireBlade.php b/src/aliuly/fireblade/FireBlade.php index 55bc63b..7625805 100644 --- a/src/aliuly/fireblade/FireBlade.php +++ b/src/aliuly/fireblade/FireBlade.php @@ -8,7 +8,6 @@ use pocketmine\command\Command; use pocketmine\Player; use pocketmine\item\Item; -use pocketmine\scheduler\CallbackTask; use pocketmine\event\Listener; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\event\player\PlayerItemHeldEvent; @@ -25,20 +24,45 @@ private function inGame(CommandSender $sender,$msg = true) { if ($msg) $sender->sendMessage("You can only use this command in-game"); return false; } + public function getItem($txt,$default) { + $r = explode(":",$txt); + if (count($r)) { + if (!isset($r[1])) $r[1] = 0; + $item = Item::fromString($r[0].":".$r[1]); + if (isset($r[2])) $item->setCount(intval($r[2])); + if ($item->getId() != Item::AIR) { + return $item; + } + } + $this->getLogger()->info("$msg: Invalid item $txt, using default"); + $item = Item::fromString($default.":0"); + $item->setCount(1); + return $item; + } + public function onEnable(){ if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder()); $defaults = [ - "sword1" => Item::IRON_SWORD, - "sword2" => Item::GOLD_SWORD, + "version" => $this->getDescription()->getVersion(), + + "sword1" => "IRON_SWORD", + "sword2" => "GOLD_SWORD", "sword_txt" => "You must be holding an Iron Sword\nor a Gold Sword", "timer" => 5, "effect" => 10, ]; $this->cf = (new Config($this->getDataFolder()."config.yml", Config::YAML,$defaults))->getAll(); + $this->cf["sword1"] = $this->getItem($this->cf["sword1"], + Item::IRON_SWORD, + "sword1")->getId(); + $this->cf["sword2"] = $this->getItem($this->cf["sword2"], + Item::GOLD_SWORD, + "sword2")->getId(); + $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->players = []; - $tt = new CallbackTask([$this,"updateTimer"],[]); + $tt = new PluginCallbackTask($this,[$this,"updateTimer"],[]); $this->getServer()->getScheduler()->scheduleRepeatingTask($tt,$this->cf["timer"]); } public function onQuit(PlayerQuitEvent $ev) { @@ -48,6 +72,9 @@ public function onQuit(PlayerQuitEvent $ev) { unset($this->players[$n]); } } + /** + * @priority HIGH + */ public function onAttack(EntityDamageEvent $ev) { if ($ev->isCancelled()) return; if(!($ev instanceof EntityDamageByEntityEvent)) return; diff --git a/src/aliuly/fireblade/PluginCallbackTask.php b/src/aliuly/fireblade/PluginCallbackTask.php new file mode 100644 index 0000000..75d5fb2 --- /dev/null +++ b/src/aliuly/fireblade/PluginCallbackTask.php @@ -0,0 +1,65 @@ +callable = $callable; + $this->args = $args; + $this->args[] = $this; + } + + /** + * @return callable + */ + public function getCallable(){ + return $this->callable; + } + + public function onRun($currentTicks){ + $c = $this->callable; + $args = $this->args; + $args[] = $currentTicks; + $c(...$args); + } + +}