diff --git a/config.yml b/config.yml index 003358c..6ca1701 100644 --- a/config.yml +++ b/config.yml @@ -18,4 +18,5 @@ InGame4: "> > > CLICK TO SPECTATE < < <" # Now you can choose all worlds game's # Example: redstone: Example +spleef: Spleef ... \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index bd3d3b4..75ceb9c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -4,6 +4,18 @@ author: Ad5001 version: 1.0 api: [2.0.0] main: Ad5001\GameManager\Main -commands: [] -permissions: [] +commands: + games: + description: "Main GameManager command" + usage: "/games [game]" + permission: gamemanager.true +permissions: + gamemanager.true: + default: true + gamemanager.op: + default: op + gamemanager.false: + default: false + gamemanager.notop: + default: !op ... \ No newline at end of file diff --git a/src/Ad5001/GameManager/Game.php b/src/Ad5001/GameManager/Game.php index 86bac75..b5ce42d 100644 --- a/src/Ad5001/GameManager/Game.php +++ b/src/Ad5001/GameManager/Game.php @@ -147,14 +147,23 @@ abstract class Game { public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {} + public function onProjectileLauch(\pocketmine\event\entity\ProjectileLauchEvent $event) {} + + + public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) {} + + public function getConfig() { - return new Config($this->main->getDataFolder() . "games/$this->name"); + if(!isset($this->cfg)) { + $this->cfg = new Config($this->main->getDataFolder() . "games/$this->name/config.yml"); + } + return $this->cfg; } public function saveDefaultConfig() { @mkdir($this->main->getDataFolder() . "games/" . $this->name); - file_put_contents($this->main->getDataFolder() . "games/$this->name", ""); + file_put_contents($this->main->getDataFolder() . "games/$this->name/config.yml", ""); } @@ -172,12 +181,51 @@ abstract class Game { } - public function registerCommand(string $cmd, string $desc, string $usage, array $aliases, string $perm = "gamemanager.command.use") { + public function registerCommand(string $cmd, string $desc, string $usage, array $aliases = [], string $perm = "gamemanager.command.use") { if(!isset($this->main->cmds[$cmd])) { - $this->main->cmds[$cmd] = new GameCommand($this->main, $cmd, $desc, $usage, $aliases, $this->gm->getGames()[$this->getName()], $perm); - $this->getServer()->getCommandMap()->register($cmd, $this->main->cmds[$cmds]); + $this->main->cmds[$cmd] = new GameCommand($this->main, $cmd, $desc, $usage, $aliases, $this, $perm); + $this->getServer()->getCommandMap()->register($cmd, $this->main->cmds[$cmd]); } } + public function getServer() { + return $this->getPlugin()->getServer(); + } + + + public function getName() : string { + return explode(get_class($this))[count(explode(get_class($this))) - 1]; + } + + + public function broadcastMessage(string $message) { + foreach($this->getLevel()->getPlayers() as $p) { + $p->sendMessage($message); + } + } + + + public function getInGamePlayers() { + $p = []; + foreach($this->getLevel()->getPlayers() as $pl) { + if(!$pl->isSpecator()) { + $p[] = $pl; + } + } + return $p; + } + + + public function getSpectators() { + $p = []; + foreach($this->getLevel()->getPlayers() as $pl) { + if($pl->isSpecator()) { + $p[] = $pl; + } + } + return $p; + } + + } \ No newline at end of file diff --git a/src/Ad5001/GameManager/Main.php b/src/Ad5001/GameManager/Main.php index 8ea8bfa..d36f493 100644 --- a/src/Ad5001/GameManager/Main.php +++ b/src/Ad5001/GameManager/Main.php @@ -56,6 +56,28 @@ class Main extends PluginBase implements Listener { array_push($games, explode("\\", $g)[count(explode("\\", $g)) - 1]); } $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current existings games: " . implode(", ", $games) . ". \nUse /games to get all the levels of a game."); + } elseif($args[0] == "join" or $args[0] == "j") { + if(isset($args[1])) { + if(isset($this->manager->getLevels()[$args[1]])) { + $sender->sendMessage("§l§o§b[§r§a§l{$this->manager->getLevels()[$args[1]]->getName()}§o§b]§r Joining game {$this->manager->getLevels()[$args[1]]->getName()} in world {$this->manager->getLevels()[$args[1]]->getLevel()->getName()}"); + $sender->teleport($this->manager->getLevels()[$args[1]]->getLevel()->getSafeSpawn()); + + } + } + } elseif($args[0] == "quickjoin" or $args[0] == "qj") { + if(isset($args[1])) { + if(isset($this->manager->getLevels()[$args[1]])) { + foreach($this->manager->getLevels() as $levelname => $game) { + if(strtolower($game->getName()) == strtolower($args[1]) and !$game->isStarted()) { + $p = $this->getInGamePlayers($game->getLevel()); + if($p < $game->getMaxPlayers()) { + $sender->sendMessage("§l§o§b[§r§a§l{$game->getName()}§o§b]§r Joining game {$game->getName()} in world {$game->getLevel()->getName()}"); + $sender->teleport($game->getLevel()->getSafeSpawn()); + } + } + } + } + } } else { $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current levels running $args[0]:"); foreach($this->manager->getLevels() as $levelname => $game) { @@ -80,11 +102,11 @@ class Main extends PluginBase implements Listener { foreach($level->getPlayers() as $pl) { if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { if(!$this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { - array_push($p, $pl); + $p++; } } else { if(!$pl->isSpectator()) { - array_push($p, $pl); + $p++; } } } @@ -97,11 +119,11 @@ class Main extends PluginBase implements Listener { foreach($level->getPlayers() as $pl) { if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { - array_push($s, $pl); + $s++; } } else { if($pl->isSpectator()) { - array_push($s, $pl); + $s++; } } } @@ -262,6 +284,20 @@ public function onInteract(PlayerInteractEvent $event) { } + public function onProjectileLauch(\pocketmine\event\entity\ProjectileLauchEvent $event) { + if(isset($this->manager->getLevels()[$event->getEntity()->getLevel()->getName()])) { + $this->manager->getLevels()[$event->getEntity()->getLevel()->getName()]->onProjectileLauch($event); + } + } + + + public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) { + if(isset($this->manager->getLevels()[$event->getEntity()->getLevel()->getName()])) { + $this->manager->getLevels()[$event->getEntity()->getLevel()->getName()]->onProjectileHit($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);