Fixing some errors between the old format and the new one + adding command /scenario.

This commit is contained in:
Ad5001 2016-08-20 11:26:38 +03:00
parent 7318c9f1be
commit 32837ca6cd
4 changed files with 55 additions and 16 deletions

View file

@ -1,6 +1,12 @@
--- ---
# Set your worlds here ! # Set your worlds here !
worlds: [] worlds:
# Example:
# world:
# radius: 1000
# maxplayers: 32
# Will be added if you add scenarios # Will be added if you add scenarios
scenarios: [] scenarios: []
... ...

View file

@ -61,10 +61,6 @@ class Main extends PluginBase implements Listener{
public function onPlayerJoin(PlayerJoinEvent $event) { public function onPlayerJoin(PlayerJoinEvent $event) {
if(!isset($this->ft)) { if(!isset($this->ft)) {
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->worlds), 10); $this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->worlds), 10);
foreach($this->getConfig()->get("worlds") as $lvl) {
$this->worlds[$lvl["name"]] = new UHCWorld($this, $this->getServer()->getLevelByName($lvl["name"]), $lvl["name"], $lvl["maxplayers"], $lvl["radius"]);
$this->getLogger()->debug("Processing {$lvl["name"]}");
}
} }
if(isset($this->quit[$event->getPlayer()->getName()])) { if(isset($this->quit[$event->getPlayer()->getName()])) {
$quit = explode("/", $this->quit[$event->getPlayer()->getName()]); $quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
@ -130,12 +126,12 @@ switch($cmd->getName()){
if(isset($args[0]) and $sender instanceof Player) { if(isset($args[0]) and $sender instanceof Player) {
switch($args[0]) { switch($args[0]) {
case "start": case "start":
if(isset($this->worlds[$sender->getLevel()->getName()]) and !isset($this->games[$sender->getLevel()->getName()])) { if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedUHCs()[$sender->getLevel()->getName()])) {
$this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); $this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}");
foreach($sender->getLevel()->getPlayers() as $player) { foreach($sender->getLevel()->getPlayers() as $player) {
$player->sendMessage(self::PREFIX . "Starting game..."); $player->sendMessage(self::PREFIX . "Starting game...");
} }
$this->startGame($this->worlds[$sender->getLevel()->getName()]); $this->startGame($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]);
} else { } else {
$sender->sendMessage("You are not in a UHC world or UHC is already started"); $sender->sendMessage("You are not in a UHC world or UHC is already started");
} }
@ -145,19 +141,56 @@ switch($cmd->getName()){
} }
break; break;
case "scenarios": case "scenarios":
if(isset($args[2])) { if(isset($args[0])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$sender->getLevel()->getName()])) { if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$sender->getLevel()->getName()])) {
if(file_exists($this->getDataFolder() . "scenarios/" . $args[2] . ".php")) { // yes, I'm treating args[2] before args[1] but who cares x) ? switch($args[0]) {
switch($args[1]) {
case "add": case "add":
require_once(realpath($this->getDataFolder() . "scenarios/" . $args[2] . ".php")); if(isset($args[1])) {
$scenarios[$args[2]] = new $args[2](); if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(!isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($args[1]);
foreach($sender->getLevel()->getPlayers() as $p) {
$p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]);
}
$sender->sendMessage(self::PREFIX . C::GREEN . " Succefully added scenario $args[1] !");
} else {
$sender->sendMessage(slef::PREFIX . C::DARK_RED . "Scenario $args[1] has already been added !");
}
} else {
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !");
}
} else {
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Usage: /scenarios add <scenario>");
}
break; break;
case "remove": case "remove":
unset($scenarios[$args[2]]); case "rm":
case "delete":
case "del":
if(isset($args[1])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]);
foreach($sender->getLevel()->getPlayers() as $p) {
$p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]);
}
$sender->sendMessage(self::PREFIX . C::GREEN . " Succefully removed scenario $args[1] !");
} else {
$sender->sendMessage(slef::PREFIX . C::DARK_RED . "Scenario $args[1] hasn't been added yet !");
}
} else {
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !");
}
} else {
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Usage: /scenarios rm <scenario>");
}
break;
case "list":
$sender->sendMessage(self::PREFIX . "Current server's scenarios: " . implode(", " $this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()));
break; break;
} }
} } else {
$sender->sendMessage(self::PREFIX . "You're not in a UHC world !")
} }
} }
break; break;

View file

@ -60,7 +60,7 @@ class UHCManager {
public function registerLevel(Level $level) { public function registerLevel(Level $level) {
if(!array_key_exists($level->getName(), $this->levels)) { if(!array_key_exists($level->getName(), $this->levels)) {
$this->levels[$level->getName()] = new UHCWorld($this->m,$level); $this->levels[$level->getName()] = new UHCWorld($this->m,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]);
} else { } else {
$this->main->getLogger()->warning("{$level->getName()} is already registered."); $this->main->getLogger()->warning("{$level->getName()} is already registered.");
} }

View file

@ -15,5 +15,5 @@ abstract class UHCEvent extends Event {
return $this->game; return $this->game;
} }
} }