#Teasing...

This commit is contained in:
Ad5001 2016-08-08 12:21:52 +03:00
parent 060069e479
commit f2fed8228e
4 changed files with 108 additions and 11 deletions

View file

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

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

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,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;
}
}

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