Events !
This commit is contained in:
parent
a550fa1f8d
commit
e09914ef19
3 changed files with 216 additions and 28 deletions
|
@ -14,7 +14,17 @@ class Example extends Game {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public function onJoin(Player $player) {
|
||||
parent::onJoin($player);
|
||||
$this->getPlugin()->getLogger()->info($player->getName() . " joined the game " . $this->getName() . " in world " . $this->getLevel()->getName());
|
||||
}
|
||||
|
||||
|
||||
public function onQuit(Player $player) {
|
||||
parent::onJoin($player);
|
||||
$this->getPlugin()->getLogger()->info($player->getName() . " left the game " . $this->getName() . " in world " . $this->getLevel()->getName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getName() : string {
|
||||
|
|
|
@ -56,6 +56,12 @@ abstract class Game {
|
|||
}
|
||||
|
||||
|
||||
public function start() {
|
||||
$this->gm->stopGame($this->level);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function onJoin(Player $player) {
|
||||
if($this->getLevel()->getPlayers() >= $this->getMinPlayers() and !$this->isStarted()) {
|
||||
$this->gm->startGame($this->getLevel());
|
||||
|
@ -73,13 +79,67 @@ abstract class Game {
|
|||
}
|
||||
|
||||
|
||||
public function onInteract(\pocketmine\event\player\PlayerInteract $event) {}
|
||||
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}
|
||||
|
||||
|
||||
public function onChat(\pocketmine\event\player\PlayerChatEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {}
|
||||
|
||||
|
||||
public function onDeath(\pocketmine\event\player\PlayerDeathEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {}
|
||||
|
||||
|
||||
public function onDrop(\pocketmine\event\player\PlayerDropItemEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {}
|
||||
|
||||
|
||||
public function onMove(\pocketmine\event\player\PlayerMoveEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {}
|
||||
|
||||
|
||||
public function onItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {}
|
||||
|
||||
|
||||
public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {}
|
||||
|
||||
|
||||
public function onItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {}
|
||||
|
||||
|
||||
public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {}
|
||||
|
||||
|
||||
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {}
|
||||
|
||||
|
||||
public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockPlace(\pocketmine\event\entity\EntityDamageEvent $event) {}
|
||||
public function onBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockPlace(\pocketmine\event\entit\block\BlockPlaceEvent $event) {}
|
||||
|
||||
|
||||
public function onPlace(\pocketmine\event\entit\block\BlockPlaceEvent $event) {}
|
||||
|
||||
|
||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {}
|
||||
|
|
|
@ -8,6 +8,7 @@ use pocketmine\plugin\PluginBase;
|
|||
use pocketmine\Server;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\entity\EntityLevelChangeEvent;
|
||||
use pocketmine\Player;
|
||||
use Ad5001\GameManager\GameManager;
|
||||
use Ad5001\GameManager\tasks\SignReloadTask;
|
||||
|
@ -34,31 +35,6 @@ class Main extends PluginBase implements Listener {
|
|||
}
|
||||
|
||||
|
||||
public function onInteract(PlayerInteractEvent $event) {
|
||||
echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN;
|
||||
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
|
||||
$t = $event->getBlock()->getLevel()->getTile($event->getBlock());
|
||||
echo "Sign.";
|
||||
foreach($this->manager->getLevels() as $class) {
|
||||
if(str_ireplace("{game}", $class->getName(), $this->getConfig()->get("Game1")) == $t->getText()[0]) {
|
||||
$lvlex = explode("{level}", $this->getConfig()->get("Game2"));
|
||||
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
|
||||
$lvl = str_ireplace($lvlex[1], "", $lvl);
|
||||
if($name == $lvl) {
|
||||
if($this->manager->getLevels()[$lvl->getName()]->isStarted()) {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
$event->getPlayer()->setGamemode(3);
|
||||
} else {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
$this->gameManager->getLevels()[$lvl->getName()]->onJoin($event->getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onLoad(){
|
||||
$this->saveDefaultConfig();
|
||||
}
|
||||
|
@ -91,4 +67,146 @@ class Main extends PluginBase implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
############################
|
||||
# #
|
||||
# Events for games #
|
||||
# #
|
||||
############################
|
||||
|
||||
public function onInteract(PlayerInteractEvent $event) {
|
||||
// echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN;
|
||||
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
|
||||
$t = $event->getBlock()->getLevel()->getTile($event->getBlock());
|
||||
// echo "Sign.";
|
||||
foreach($this->manager->getLevels() as $class) {
|
||||
if(str_ireplace("{game}", $class->getName(), $this->getConfig()->get("Game1")) == $t->getText()[0]) {
|
||||
$lvlex = explode("{level}", $this->getConfig()->get("Game2"));
|
||||
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
|
||||
$lvl = str_ireplace($lvlex[1], "", $lvl);
|
||||
if($name == $lvl) {
|
||||
if($this->manager->getLevels()[$lvl->getName()]->isStarted()) {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
$event->getPlayer()->setGamemode(3);
|
||||
} else {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onInteract($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onEntityLevelChange(EntityLevelChangeEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
|
||||
$this->gameManager->getLevels()[$event->getOrigin()->getName()]->onQuit($event->getPlayer());
|
||||
}
|
||||
if(isset($this->manager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) {
|
||||
$this->gameManager->getLevels()[$event->getTarget()->getName()]->onJoin($event->getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerChat($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onChat($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerCommandPreprocess(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerCommand($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerDeath($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onDeath($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerDropItem($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onDrop($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerMove($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onMove($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerItemConsume($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onItemConsume($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlayerItemHeld($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onItemHeld($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onBlockBreak(\pocketmine\event\player\PlayerBreakEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onBlockBreak($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onBreak($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onBlockPlace(\pocketmine\event\player\PlayerPlaceEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onBlockPlace($event);
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onPlace($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getEntity()->getLevel()->getName()]->onEntityDamage($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onDataPacketReceive($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {
|
||||
if(isset($this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->manager->getLevels()[$event->getPlayer()->getLevel()->getName()]->onDataPacketSend($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onServerCommand(\pocketmine\event\server\DataPacketReceiveEvent $event) {
|
||||
foreach($this->manager->getLevels() as $lvl => $class) {
|
||||
$class->onServerCommand($event);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue