Browse Source

Starting 1.0.1 with DefaultScenarios and bugfixes

master
Ad5001 3 years ago
parent
commit
47628cbff6
No account linked to committer's email address

+ 3
- 2
config.yml View File

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

+ 2
- 1
resources/config.yml View File

@@ -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
- 0
scenarios/WorldReseter.php 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++;
}
}
}
}
}
}

+ 2
- 2
src/Ad5001/UHC/Main.php View File

@@ -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");
}

+ 1
- 1
src/Ad5001/UHC/scenario/Scenario.php View File

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

+ 1
- 1
src/Ad5001/UHC/scenario/ScenarioInt.php View File

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

+ 7
- 0
src/Ad5001/UHC/scenario/ScenarioManager.php View File

@@ -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…
Cancel
Save