Starting custom events.

This commit is contained in:
Ad5001 2016-08-20 10:24:06 +03:00
rodzic 6a533249ff
commit 7318c9f1be
4 zmienionych plików z 21 dodań i 2 usunięć

Wyświetl plik

@ -81,6 +81,8 @@ class Main extends PluginBase implements Listener{
$this->saveDefaultConfig();
mkdir($this->getDataFolder() . "scenarios");
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getServer()->getPluginManager()->registerEvent("\Ad5001\UHC\event\GameStartEvent", $this, \pocketmine\plugin\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStart"), $this, true);
$this->getServer()->getPluginManager()->registerEvent("\Ad5001\UHC\event\GameStopEvent", $this, \pocketmine\plugin\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, true);
$this->UHCManager = new UHCManager($this);
$this->games = [];
$this->quit = [];

Wyświetl plik

@ -36,7 +36,7 @@ class UHCGame implements Listener{
public function __construct(Plugin $plugin, UHCWorld $world) {
$this->m = $plugin;
$this->world = $world;
$plugin->getServer()->registerEvets($this, $plugin);
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
$this->players = $world->getLevel()->getPlayers();
$event = new GameStartEvent($this, $world, $this->players);
$this->m->getServer()->getPluginManager()->callEvent($event);

Wyświetl plik

@ -15,21 +15,34 @@ use Ad5001\UHC\UHCWorld;
protected $game;
protected $world;
protected $winner;
class GameFinishEvent extends UHCEvent implements Cancellable {
class GameStopEvent extends UHCEvent implements Cancellable {
public function __construct($game, $world, $winner) {
$this->game = $game;
$this->world = $world;
$this->winner = $winner;
}
public function getWorld() {
return $this->world;
}
public function getLevel() {
return $this->world;
}
public function getWinner() {
return $this->winner;
}
public function setWinner(Player $winner) {
$this->winner = $winner;
}

Wyświetl plik

@ -9,7 +9,11 @@
namespace Ad5001\UHC\event;
use pocketmine\event\Event;
abstract class UHCEvent extends Event {
public function getGame() {
return $this->game;
}
}