Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Oct 31, 2016
1 parent 830a283 commit ebaf2e0
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 5 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<img src="https://raw.githubusercontent.com/Muirfield/FireBlade/master/media/FireBlade-icon.png" style="width:64px;height:64px" width="64" height="64"/>

# 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
File renamed without changes
3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 31 additions & 4 deletions src/aliuly/fireblade/FireBlade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions src/aliuly/fireblade/PluginCallbackTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
*
*
*/
namespace aliuly\fireblade;

use pocketmine\scheduler\PluginTask;
use pocketmine\plugin\Plugin;

/**
* Allows the creation of simple callbacks with extra data
* The last parameter in the callback will be this object
*
*/
class PluginCallbackTask extends PluginTask{

/** @var callable */
protected $callable;

/** @var array */
protected $args;

/**
* @param Plugin $owner
* @param callable $callable
* @param array $args
*/
public function __construct(Plugin $owner, callable $callable, array $args = []){
parent::__construct($owner);
$this->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);
}

}

0 comments on commit ebaf2e0

Please sign in to comment.