Browse Source

Moving forward on scenarios

pull/1/head
Ad5001 3 years ago
parent
commit
98db40563b

+ 19
- 0
src/Ad5001/UHC/Main.php View File

@@ -163,6 +163,25 @@ switch($cmd->getName()){
}
}
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;
}

+ 67
- 0
src/Ad5001/UHC/scenario/Scenario.php 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/");
}
}

+ 39
- 0
src/Ad5001/UHC/scenario/ScenarioInt.php 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();
}

Loading…
Cancel
Save