Moving forward on scenarios

This commit is contained in:
Ad5001 2016-06-10 17:05:56 +02:00
parent 7de3e7aafa
commit 98db40563b
3 changed files with 125 additions and 0 deletions

View file

@ -163,6 +163,25 @@ switch($cmd->getName()){
} }
} }
break; break;
case "scenarios" {
if(isset($args[2])) {
if(isset($this->worlds[$sender->getLevel()->getName()]) and !isset($this->games[$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[1]) {
case "add":
$sl = new \pocketmine\plugin\ScriptPluginLoader($this->getServer());
$scenarios[$args[2]] = $sl->load(realpath($this->getDataFolder() . "scenarios/" . $args[2] . ".php"));
$scenarios[$args[2]]->onEnable();
break;
case "remove":
$scenarios[$args[2]]->onStop();
unset($scenarios[$args[2]]);
break;
}
}
}
}
}
} }
return false; return false;
} }

View file

@ -0,0 +1,67 @@
<?php
# _ _ _ _ _____
# | | | | | | |/ ____|
# | | | | |__| | |
# | | | | __ | |
# | |__| | | | | |____
# \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\scenario;
use pocketmine\command\CommandExecutor;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginIdentifiableCommand;
use pocketmine\Server;
use pocketmine\utils\Config;
use Ad5001\UHC\scenario\ScenarioInt;
abstract class Scenario implements ScenarioInt {
private $server;
private $name;
private $config;
public function onEnable() {}
public function onStop() {}
public function getServer() {
return Server::getInstance();
}
public function getConfig() {
return Main::getConfig()->get("Scenarios")[$this->name];
}
public function reloadConfig() {
Main::reloadConfig();
return Main::getConfig()->get("Scenarios")[$this->name];
}
public function saveConfig($cfg) {
$scenarios = Main::getConfig()->get("Scenarios");
$scenarios[$this->name] = $cfg;
Main::getConfig()->set("Scenarios", $scenarios);
return Main::getConfig->save();
}
public function getScenarioFolder() {
return realPath(Main::getDataFolder . "scenarios/");
}
}

View file

@ -0,0 +1,39 @@
<?php
# _ _ _ _ _____
# | | | | | | |/ ____|
# | | | | |__| | |
# | | | | __ | |
# | |__| | | | | |____
# \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\scenario;
use pocketmine\command\CommandExecutor;
interface ScenarioInt extends CommandExecutor {
/* When the scenario is activating */
public function onEnable();
/* When the scenario is stoping (end of UHC) */
public function onStop();
/* Getting the server methods */
public function getServer();
/* Get the config (which is a part of the config of the plugin) */
public function getConfig();
/* Save the config */
public function saveConfig();
/* Get the scenario folder */
public function getScenarioFolder();
/* Reload the config */
public function reloadConfig();
}