Starting 1.0.1 with DefaultScenarios and bugfixes

This commit is contained in:
Ad5001 2016-08-22 15:26:53 +03:00
parent 899278162b
commit 47628cbff6
No known key found for this signature in database
GPG key ID: C9622754F6196EB7
7 changed files with 59 additions and 7 deletions

View file

@ -1,5 +1,6 @@
LobbyWorld: world LobbyWorld: world
worlds: worlds:
uhc: uhc:
maxplayers: 8 maxplayers: 8
radius: 1000 radius: 1000
default_scenarios: [UHCWorldReseter]

View file

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

View 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++;
}
}
}
}
}
}

View file

@ -93,7 +93,7 @@ class Main extends PluginBase implements Listener{
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
switch($cmd->getName()){ switch($cmd->getName()){
case "uhc": case "uhc":
if(isset($args[0]) and $sender instanceof Player) { if(isset($args[0]) and $sender instanceof Player) {
switch($args[0]) { switch($args[0]) {
@ -115,7 +115,7 @@ switch($cmd->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->stopUHC($sender->getLevel()); $this->UHCManager->stopUHC($sender->getLevel());
} 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");
} }

View file

@ -173,7 +173,7 @@ abstract class Scenario implements ScenarioInt, Listener {
public function getScenarioFolder() { public function getScenariosFolder() {
return $this->getMain()->getDataFolder() . "scenarios/"; return $this->getMain()->getDataFolder() . "scenarios/";
} }
} }

View file

@ -33,7 +33,7 @@ interface ScenarioInt {
/* Get the scenario folder */ /* Get the scenario folder */
public function getScenarioFolder(); public function getScenariosFolder();
/* Reload the config */ /* Reload the config */

View file

@ -42,6 +42,13 @@ class ScenarioManager {
@mkdir($this->main->getDataFolder() . "scenarios/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]); @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);
}
}
}
} }