Starting custom events.
This commit is contained in:
parent
6a533249ff
commit
7318c9f1be
4 changed files with 21 additions and 2 deletions
|
@ -81,6 +81,8 @@ class Main extends PluginBase implements Listener{
|
||||||
$this->saveDefaultConfig();
|
$this->saveDefaultConfig();
|
||||||
mkdir($this->getDataFolder() . "scenarios");
|
mkdir($this->getDataFolder() . "scenarios");
|
||||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
$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->UHCManager = new UHCManager($this);
|
||||||
$this->games = [];
|
$this->games = [];
|
||||||
$this->quit = [];
|
$this->quit = [];
|
||||||
|
|
|
@ -36,7 +36,7 @@ class UHCGame implements Listener{
|
||||||
public function __construct(Plugin $plugin, UHCWorld $world) {
|
public function __construct(Plugin $plugin, UHCWorld $world) {
|
||||||
$this->m = $plugin;
|
$this->m = $plugin;
|
||||||
$this->world = $world;
|
$this->world = $world;
|
||||||
$plugin->getServer()->registerEvets($this, $plugin);
|
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
|
||||||
$this->players = $world->getLevel()->getPlayers();
|
$this->players = $world->getLevel()->getPlayers();
|
||||||
$event = new GameStartEvent($this, $world, $this->players);
|
$event = new GameStartEvent($this, $world, $this->players);
|
||||||
$this->m->getServer()->getPluginManager()->callEvent($event);
|
$this->m->getServer()->getPluginManager()->callEvent($event);
|
||||||
|
|
|
@ -15,21 +15,34 @@ use Ad5001\UHC\UHCWorld;
|
||||||
protected $game;
|
protected $game;
|
||||||
protected $world;
|
protected $world;
|
||||||
protected $winner;
|
protected $winner;
|
||||||
class GameFinishEvent extends UHCEvent implements Cancellable {
|
|
||||||
|
|
||||||
|
class GameStopEvent extends UHCEvent implements Cancellable {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct($game, $world, $winner) {
|
public function __construct($game, $world, $winner) {
|
||||||
$this->game = $game;
|
$this->game = $game;
|
||||||
$this->world = $world;
|
$this->world = $world;
|
||||||
$this->winner = $winner;
|
$this->winner = $winner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getWorld() {
|
public function getWorld() {
|
||||||
return $this->world;
|
return $this->world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getLevel() {
|
public function getLevel() {
|
||||||
return $this->world;
|
return $this->world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getWinner() {
|
public function getWinner() {
|
||||||
return $this->winner;
|
return $this->winner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setWinner(Player $winner) {
|
public function setWinner(Player $winner) {
|
||||||
$this->winner = $winner;
|
$this->winner = $winner;
|
||||||
}
|
}
|
|
@ -9,7 +9,11 @@
|
||||||
namespace Ad5001\UHC\event;
|
namespace Ad5001\UHC\event;
|
||||||
use pocketmine\event\Event;
|
use pocketmine\event\Event;
|
||||||
abstract class UHCEvent extends Event {
|
abstract class UHCEvent extends Event {
|
||||||
|
|
||||||
|
|
||||||
public function getGame() {
|
public function getGame() {
|
||||||
return $this->game;
|
return $this->game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue