Browse Source

#Teasing...

tags/1.0
Ad5001 3 years ago
parent
commit
f2fed8228e
4 changed files with 108 additions and 11 deletions
  1. 1
    0
      config.yml
  2. 14
    2
      plugin.yml
  3. 53
    5
      src/Ad5001/GameManager/Game.php
  4. 40
    4
      src/Ad5001/GameManager/Main.php

+ 1
- 0
config.yml View File

@@ -18,4 +18,5 @@ InGame4: "> > > CLICK TO SPECTATE < < <"
# Now you can choose all worlds game's
# Example:
redstone: Example
spleef: Spleef
...

+ 14
- 2
plugin.yml View File

@@ -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
...

+ 53
- 5
src/Ad5001/GameManager/Game.php View File

@@ -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,11 +181,50 @@ 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;
}



+ 40
- 4
src/Ad5001/GameManager/Main.php View File

@@ -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 <game_name> 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);

Loading…
Cancel
Save