Starting 1.0.1 with DefaultScenarios and bugfixes
This commit is contained in:
parent
899278162b
commit
47628cbff6
7 changed files with 59 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
LobbyWorld: world
|
||||
worlds:
|
||||
uhc:
|
||||
maxplayers: 8
|
||||
radius: 1000
|
||||
maxplayers: 8
|
||||
radius: 1000
|
||||
default_scenarios: [UHCWorldReseter]
|
|
@ -1,11 +1,12 @@
|
|||
---
|
||||
LobbyWorld: world
|
||||
# Set your worlds here !
|
||||
worlds:
|
||||
# Example:
|
||||
# world:
|
||||
# radius: 1000
|
||||
# maxplayers: 32
|
||||
|
||||
# default_scenarios: []
|
||||
|
||||
# Will be added if you add scenarios
|
||||
scenarios: []
|
||||
|
|
43
scenarios/WorldReseter.php
Normal file
43
scenarios/WorldReseter.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
USE pocketmine\item\Item;
|
||||
|
||||
class UHCWorldReseter extends \Ad5001\UHC\scenario\Scenario{
|
||||
|
||||
public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
|
||||
$args = explode($event->getMessage());
|
||||
if($args[0] == "/savelobby"){
|
||||
$bs = [];
|
||||
if(isset($args[1])) {
|
||||
@mkdir($this->getScenariosFoler() . "LobbysBackups");
|
||||
for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) {
|
||||
for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) {
|
||||
for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) {
|
||||
$b = $this->world->getLevel()->getBlock(new \pocketmine\math\Vector3($x, $y, $z));
|
||||
array_push($bs, $b->getId() . ":" . $b->getDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
file_put_contents($this->getScenariosFolder() . "LobbysBackups/" .$this->world->getName() . ".json", json_encode(["radius" => $args[1], "blocks" => $bs]));
|
||||
$event->getPlayer()->sendMessage("Lobby saved in a radius of $args[1] of the spawn");
|
||||
$event->setCancelled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __construct(\pocketmine\Server $serv, \Ad5001\UHC\UHCWorld $w) {
|
||||
parent::__construct($serv,$w);
|
||||
if(file_exists($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json")) {
|
||||
$bs = json_decode(file_get_contents($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json"), true);
|
||||
$i = 0;
|
||||
for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) {
|
||||
for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) {
|
||||
for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) {
|
||||
$w->getLevel()->setBlock(new \pocketmine\math\Vector3($x, $y, $z), new \pocketmine\block\Block(Item::fromString($bs[$i])));
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -93,7 +93,7 @@ class Main extends PluginBase implements Listener{
|
|||
|
||||
|
||||
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
|
||||
switch($cmd->getName()){
|
||||
switch($cmd->getName()){
|
||||
case "uhc":
|
||||
if(isset($args[0]) and $sender instanceof Player) {
|
||||
switch($args[0]) {
|
||||
|
@ -115,7 +115,7 @@ switch($cmd->getName()){
|
|||
foreach($sender->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(self::PREFIX . "Starting game...");
|
||||
}
|
||||
$this->stopUHC($sender->getLevel());
|
||||
$this->UHCManager->stopUHC($sender->getLevel());
|
||||
} else {
|
||||
$sender->sendMessage("You are not in a UHC world or UHC is already started");
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ abstract class Scenario implements ScenarioInt, Listener {
|
|||
|
||||
|
||||
|
||||
public function getScenarioFolder() {
|
||||
public function getScenariosFolder() {
|
||||
return $this->getMain()->getDataFolder() . "scenarios/";
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ interface ScenarioInt {
|
|||
|
||||
|
||||
/* Get the scenario folder */
|
||||
public function getScenarioFolder();
|
||||
public function getScenariosFolder();
|
||||
|
||||
|
||||
/* Reload the config */
|
||||
|
|
|
@ -42,6 +42,13 @@ class ScenarioManager {
|
|||
@mkdir($this->main->getDataFolder() . "scenarios/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]);
|
||||
}
|
||||
}
|
||||
if(isset($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])) {
|
||||
if(is_array($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])){
|
||||
foreach($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"] as $sc) {
|
||||
$this->addScenario($sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue