Fixing some stuff
I don't want to finsh my 4G so not anymore today.
This commit is contained in:
parent
a3db81931b
commit
9f94f63559
6 changed files with 78 additions and 51 deletions
1
scenarios/LobbysBackups/uhc.json
Normal file
1
scenarios/LobbysBackups/uhc.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,43 +1,58 @@
|
|||
<?php
|
||||
USE pocketmine\item\Item;
|
||||
|
||||
class UHCWorldReseter extends \Ad5001\UHC\scenario\Scenario{
|
||||
class UHCWorldReseter extends \Ad5001\UHC\scenario\Scenario {
|
||||
|
||||
public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
|
||||
$args = explode($event->getMessage());
|
||||
if($args[0] == "/savelobby"){
|
||||
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {
|
||||
if(strpos($event->getMessage(), "/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));
|
||||
@mkdir($this->getScenariosFolder() . "LobbysBackups");
|
||||
for($x = $this->getLevel()->getLevel()->getSafeSpawn()->x + 10; $x >= $this->getLevel()->getLevel()->getSafeSpawn()->x - 10;$x--) {
|
||||
for($y = $this->getLevel()->getLevel()->getSafeSpawn()->y + 10; $y >= $this->getLevel()->getLevel()->getSafeSpawn()->y - 10;$y--) {
|
||||
for($z = $this->getLevel()->getLevel()->getSafeSpawn()->z + 10; $z >= $this->getLevel()->getLevel()->getSafeSpawn()->z - 10;$z--) {
|
||||
$b = $this->getLevel()->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();
|
||||
}
|
||||
file_put_contents($this->getScenariosFolder() . "LobbysBackups/" .$this->getLevel()->getName() . ".json", json_encode(["radius" => 10, "blocks" => $bs]));
|
||||
$event->getPlayer()->sendMessage("Lobby saved in a radius of 10 of the spawn");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
public function onStop() {
|
||||
$this->getLevel()->getLevel()->unload();
|
||||
$this->delDir($this->getServer()->getFilePath() . "worlds/" . $this->getLevel()->getLevel()->getName());
|
||||
$this->getServer()->generateLevel($this->getLevel()->getName(), intval(sha1(rand(0, 999999))), "pocketmine\\level\\generator\\normal\\Normal");
|
||||
$this->getServer()->loadLevel($this->getLevel()->getName());
|
||||
if(file_exists($this->getScenariosFolder() . "LobbysBackups/" .$this->getWorld()->getName() . ".json")) {
|
||||
$bs = json_decode(file_get_contents($this->getScenariosFolder() . "LobbysBackups/" .$this->getWorld()->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])));
|
||||
for($x = $this->getLevel()->getLevel()->getSafeSpawn()->x + 10; $x >= $this->getLevel()->getLevel()->getSafeSpawn()->x - 10;$x++) {
|
||||
for($y = $this->getLevel()->getLevel()->getSafeSpawn()->y + 10; $y >= $this->getLevel()->getLevel()->getSafeSpawn()->y - 10;$y++) {
|
||||
for($z = $this->getLevel()->getLevel()->getSafeSpawn()->z + 10; $z >= $this->getLevel()->getLevel()->getSafeSpawn()->z - 10;$z++) {
|
||||
$this->getWorld()->getLevel()->setBlock(new \pocketmine\math\Vector3($x, $y, $z), new \pocketmine\block\Block(Item::fromString($bs[$i])));
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delDir(string $path) {
|
||||
foreach(array_diff(scandir($path),[".", ".."]) as $p) {
|
||||
if(is_dir($path . "/" . $p)) {
|
||||
if(count(array_diff(scandir($path . "/". $p),[".", ".."])) == 0) {
|
||||
rmdir($path . "/" . $p);
|
||||
} else {
|
||||
$this->delDir($path . "/" . $p);
|
||||
}
|
||||
} else {
|
||||
unlink($path . "/" . $p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,19 +39,22 @@ class Main extends PluginBase implements Listener{
|
|||
|
||||
public function onLevelChange(EntityLevelChangeEvent $event) {
|
||||
foreach($this->UHCManager->getLevels() as $world) {
|
||||
if($event->getTarget()->getName() === $world->getName() and !isset($this->UHCManager->getStartedUHCs()[$world->getName()])) {
|
||||
if($event->getTarget()->getName() == $world->getName() and !isset($this->UHCManager->getStartedUHCs()[$world->getName()])) {
|
||||
if(count($world->getLevel()->getPlayers()) > $world->maxplayers) {
|
||||
$event->setCancelled();
|
||||
}
|
||||
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and !isset($this->quit[$event->getEntity()])) {
|
||||
} elseif($event->getTarget()->getName() == $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and !isset($this->quit[$event->getEntity()->getName()])) {
|
||||
$event->getEntity()->setGamemode(3);
|
||||
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()])) {
|
||||
$quit = explode("/", $this->quit[$event->getEntity()]);
|
||||
if($quit[3] === $world->getName()) {
|
||||
$event->getPlayer()->teleport(new Vector3($quit[0], $quit[1], $quit[2]));
|
||||
} elseif($event->getTarget()->getName() == $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()->getName()])) {
|
||||
$this->quit = explode("/", $this->quit[$event->getEntity()->getName()]);
|
||||
if($this->quit[3] === $world->getName()) {
|
||||
$event->getEntity()->teleport(new \pocketmine\level\Location($this->quit[0], $this->quit[1], $this->quit[2], $event->getTarget()));
|
||||
foreach($world->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(self::PREFIX . C::GREEN . "{$event->getPlayer()->getName()} back to game !");
|
||||
}
|
||||
$event->setCancelled();
|
||||
} else {
|
||||
$event->getEntity()->setGamemode(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +141,10 @@ class Main extends PluginBase implements Listener{
|
|||
$sender->sendMessage(self::PREFIX . "Scenarios are 'addons' to the UHC that modify some mechanics or some parts of the game. You can download them or create them yourself. Look at ccommands if you want to know how to add a scenario to a game and look at https://github.com/Ad5001/UHC/wiki/What-are-Scenarios%3F. If you want to know more about a scenario, use /uhc howtoplay <scenario name>.\n" . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n");
|
||||
break;
|
||||
default:
|
||||
if(in_array($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios(), $args[0])) {
|
||||
$sender->sendMessage(self::PREFIX . "Help for $args[0]. " . $args[0]::help);
|
||||
if(in_array($args[1], $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())) {
|
||||
$sender->sendMessage(self::PREFIX . "Help for $args[1]. " . $args[1]::help());
|
||||
} else {
|
||||
$sender->sendMessage(self::PREFIX . "No help for $args[0]");
|
||||
$sender->sendMessage(self::PREFIX . "No help for $args[1]");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -234,6 +237,7 @@ return false;
|
|||
|
||||
public function onEntityLevelChange(EntityLevelChangeEvent $event) {
|
||||
if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
|
||||
$this->quit[$event->getEntity()->getName()] = $event->getEntity()->x . "/" . $event->getEntity()->y . "/" . $event->getEntity()->z. "/" . $event->getOrigin()->getName();
|
||||
foreach($this->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||
$sc->onQuit($event->getEntity());
|
||||
}
|
||||
|
@ -392,11 +396,11 @@ return false;
|
|||
if(!isset($this->ft)) {
|
||||
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->UHCManager->getStartedUHCs()), 10);
|
||||
}
|
||||
if(isset($this->quit[$event->getPlayer()->getName()])) {
|
||||
$quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
|
||||
$event->getPlayer()->teleport($this->getServer()->getLevelByName($quit[4]));
|
||||
$event->getPlayer()->teleport(new Vector3($quit[0], $quit[1], $quit[2]));
|
||||
foreach($this->getServer()->getLevelByName($quit[4])->getLevel()->getPlayers() as $player) {
|
||||
if(isset($this->quit[$event->getPlayer()->getName()]) and $event->getPlayer()->getLevel()->getName() == $this->quit[3]) {
|
||||
$this->quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
|
||||
$event->getPlayer()->teleport($this->getServer()->getLevelByName($this->quit[3]));
|
||||
$event->getPlayer()->teleport(new Vector3($this->quit[0], $this->quit[1], $this->quit[2]));
|
||||
foreach($this->getServer()->getLevelByName($this->quit[3])->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(self::PREFIX . C::GREEN . "{$event->getPlayer()->getName()} back to game !");
|
||||
}
|
||||
}
|
||||
|
@ -410,8 +414,9 @@ return false;
|
|||
|
||||
public function onPlayerQuit(\pocketmine\event\player\PlayerQuitEvent $event) {
|
||||
if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
|
||||
$this->quit[$event->getPlayer()->getName()] = $event->getPlayer()->x . "/" . $event->getPlayer()->y . "/" . $event->getPlayer()->z. "/" . $event->getPlayer()->getLevel()->getName();
|
||||
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||
$sc->onQuit($event->getPlayers());
|
||||
$sc->onQuit($event->getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ use pocketmine\event\player\PlayerChatEvent;
|
|||
use pocketmine\event\player\PlayerQuitEvent;
|
||||
use pocketmine\event\player\PlayerRespawnEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use Ad5001\UHC\event\GameStopEvent;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\math\Vector3;
|
||||
|
@ -29,6 +28,7 @@ use Ad5001\UHC\UHCWorld;
|
|||
use Ad5001\UHC\task\StopResTask;
|
||||
use Ad5001\UHC\Main;
|
||||
use Ad5001\UHC\event\GameStartEvent;
|
||||
use Ad5001\UHC\event\GameStopEvent;
|
||||
|
||||
|
||||
|
||||
|
@ -39,8 +39,7 @@ class UHCGame implements Listener{
|
|||
$this->world = $world;
|
||||
$world->getLevel()->setTime(0);
|
||||
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
|
||||
$this->players = $world->getLevel()->getPlayers();
|
||||
$event = new GameStartEvent($this, $world, $this->players);
|
||||
$event = new GameStartEvent($this, $world, $world->getLevel()->getPlayers());
|
||||
$this->m->getServer()->getPluginManager()->callEvent($event);
|
||||
$this->cancelled = false;
|
||||
$this->kills = [];
|
||||
|
@ -48,7 +47,7 @@ class UHCGame implements Listener{
|
|||
$this->cancelled = true;
|
||||
} else {
|
||||
$radius = $world->radius;
|
||||
foreach($this->players as $player) {
|
||||
foreach($world->getLevel()->getPlayers() as $player) {
|
||||
$player->getInventory()->clearAll();
|
||||
$player->setGamemode(0);
|
||||
for($e = 1; $e < 24; $e++) {$player->removeEffect($e);}
|
||||
|
@ -103,7 +102,7 @@ class UHCGame implements Listener{
|
|||
}
|
||||
$this->respawn[$event->getPlayer()->getName()] = true;
|
||||
$pls = [];
|
||||
foreach($this->players as $pl) {
|
||||
foreach($event->getPlayer()->getLevel()->getPlayers() as $pl) {
|
||||
array_push($pls, $pl);
|
||||
}
|
||||
$cause = $event->getEntity()->getLastDamageCause();
|
||||
|
@ -129,18 +128,25 @@ class UHCGame implements Listener{
|
|||
$this->kills[C::GREEN . "P" . C::BLUE . "v" . C::RED . "E"] = 1;
|
||||
}
|
||||
}
|
||||
if(count($pls === 1)) {
|
||||
$this->stop($pls[0]);
|
||||
if(count($pls) == 2) {
|
||||
foreach($pls as $p) {
|
||||
if($p !== $event->getPlayer()) {
|
||||
$this->stop($p);
|
||||
}
|
||||
}
|
||||
} elseif(count($pls) == 1) {
|
||||
$this->stop($event->getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function stop(Player $winner) {
|
||||
if(!$this->cancelled) {
|
||||
$this->m->getServer()->getPluginManager()->callEvent($ev = new GameStopEvent($this, $this->world, $winner));
|
||||
if(!$ev->cancelled) {
|
||||
$this->m->getServer()->getPluginManager()->callEvent($event = new GameStopEvent($this, $this->world, $winner));
|
||||
if(!$event->isCancelled()) {
|
||||
foreach($this->players as $player) {
|
||||
foreach($winner->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(Main::PREFIX . C::YELLOW . $winner->getName() . " won the game ! Teleporting back to lobby...");
|
||||
$player->teleport($this->m->getServer()->getLevelByName($this->m->getConfig()->get("LobbyWorld"))->getSafeSpawn());
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ class UHCManager {
|
|||
|
||||
|
||||
public function stopUHC(Level $level) {
|
||||
if(isset($this->startedgames[$level->getName()])) {
|
||||
unset($this->startedgames[$level->getName()]);
|
||||
if(isset($this->getStartedUHCs()[$level->getName()])) {
|
||||
foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||
$sc->onQuit();
|
||||
$sc->onStop();
|
||||
}
|
||||
unset($this->startedgames[$level->getName()]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -136,7 +136,7 @@ abstract class Scenario implements ScenarioInt, Listener {
|
|||
|
||||
|
||||
public function getServer() {
|
||||
return $this->main->getServer();
|
||||
return $this->getMain()->getServer();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue