Changing the implementation way to make it clearer

This commit is contained in:
Ad5001 2016-08-20 08:59:12 +03:00
parent c2c8901feb
commit 88ee2575a9
7 changed files with 23 additions and 134 deletions

View file

@ -3,13 +3,13 @@ PLEASE NOTE THAT THE PLUGIN IS ***NOT*** COMPLETE YET! SO DO NOT USE THIS IN A P
# UHC
The most customisable UHC plugin for Minecraft PE!
Welcome here, owner/player! You may know what the UHC is but if not, carefully read [this](wiki/What-is-UHC).
Welcome here owner/player ! You may know what the UHC is but if not, read carfully [this](wiki/What-is-UHC).
This is a recreation of the well known UHC for Minecraft PE servers software in PHP!
### Why is this plugin better?
**This plugins allows you:**
- Creating simple but highly customisable UHC matchs
- MultiWorld Compatibility
- Scenario compatible! [What are scenarios](https://github.com/Ad5001/UHC/wiki/What-are-Scenarios%3F)
- Scenario compatible! [What are scenarios](wiki/scenarios)
Current complete features:
[WIP] Playing UHC (damage without regen and golden apples)

View file

@ -31,21 +31,12 @@ use Ad5001\UHC\event\GameStartEvent;
use Ad5001\UHC\event\GameFinishEvent;
class Main extends PluginBase implements Listener{
public $self;
const PREFIX = C::GOLD . "[" . C::DARK_RED . "UHC" . C::GOLD . "] ". C::RESET;
public function startGame(UHCWorld $world) {
$ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new StartGameTask($this, $world), 20);
// $this->games[$world->getName()] = new UHCGame($this, $world);
}
public function onLevelChange(EntityLevelChangeEvent $event) {
foreach($this->worlds as $world) {
foreach($this->UHCManager->getLevels() as $world) {
if($event->getLevel()->getName() === $world->getName() and !isset($this->games[$world->getName()])) {
if(count($world->getLevel()->getPlayers) > $world->maxplayers) {
$event->setCancelled();
@ -86,20 +77,22 @@ class Main extends PluginBase implements Listener{
}
public static function getSelf() {
return $this;
}
public function onEnable(){
$this->saveDefaultConfig();
mkdir($this->getDataFolder() . "scenarios");
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->worlds = [];
$this->UHCManager = new UHCManager($this);
$this->games = [];
$this->quit = [];
}
public function onLevelLoad(\pocketmine\event\level\LevelLoadEvent $event) {
if(isset($this->getConfig()->get("worlds")[$event->getLevel()->getName()])) {
$this->UHCManager->registerLevel($event->getLevel());
}
}
@ -146,29 +139,12 @@ switch($cmd->getName()){
}
return true;
break;
case "tp":
if(isset($this->worlds[$sender->getLevel()->getName()]) and isset($this->games[$sender->getLevel()->getName()]) and $sender->getGamemode() === 3) {
if(isset($args[1])) {
if($this->getServer()->getPlayer($args[1])->getName() ===! null) {
$player = $this->getServer()->getPlayer($args[1]);
$sender->teleport(new Vector3($player->x, $player->y, $player->z), $player->yaw, $player->pitch);
} else {
$sender->sendMessage(self::PREFIX . "Player {$args[1]} does NOT exist!");
}
} else {
$sender->sendMessage(self::PREFIX . "Usage: /uhc tp <player>");
}
} else {
$sender->sendMessage(self::PREFIX . "Either you're not in a UHC Game or in gamemode 3");
}
return true;
break;
}
}
break;
case "scenarios":
if(isset($args[2])) {
if(isset($this->worlds[$sender->getLevel()->getName()]) and !isset($this->games[$sender->getLevel()->getName()])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$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":

View file

@ -30,20 +30,14 @@ class UHCManager {
$this->games = [];
$this->levels = [];
$this->startedgames = [];
foreach ($files as $file) {
if(!is_dir($this->main->getDataFolder() . "games/" . $file)) {
require($this->main->getDataFolder() . "games/" . $file);
$classn = $this->main->getClasses(file_get_contents($this->main->getDataFolder() . "games/" . $file));
$this->games[explode("\\", $classn)[count(explode("\\", $classn)) - 1]] = $classn;
@mkdir($this->main->getDataFolder() . "games/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]);
}
}
}
public function startUHC(Level $level) {
if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) {
$ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this, $this->levels[$level->getName()]), 20);
$t->setHandler($ft);
$this->startedgames[$level->getName()] = true;
$this->levels[$level->getName()]->onUHCStart();
return true;
@ -78,69 +72,9 @@ class UHCManager {
}
public function getUHCs() {
return $this->games;
}
public function getStartedUHCs() {
return $this->startedgames;
}
public function restoreBackup(Level $level) {
$this->rrmdir($this->server->getFilePath() . "worlds/" . $level->getFolderName());
@mkdir($this->server->getFilePath() . "worlds/{$level->getFolderName()}");
$this->copydir($this->server->getFilePath() . "worldsBackups/{$level->getName()}", $this->server->getFilePath() . "worlds/" . $level->getFolderName());
}
public function backup(Level $level) {
$this->rrmdir($this->server->getFilePath() . "worldsBackups/{$level->getName()}");
@mkdir($this->server->getFilePath() . "worldsBackup/{$level->getName()}");
$this->copydir($this->server->getFilePath() . "worlds/" . $level->getFolderName(), $this->server->getFilePath() . "worldsBackup/{$level->getName()}");
}
private function rrmdir($dir) { // This is from PHP.NET
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") $this->rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
private function copydir($source, $target) {
if (is_dir($source)) {
@mkdir($target);
@mkdir($target . "region");
$d = dir($source);
while ( FALSE !== ( $entry = $d->read() ) ) {
if ($entry == '.' || $entry == '..') {
continue;
}
$Entry = $source . '/' . $entry;
if (is_dir($Entry)) {
$this->copydir($Entry, $target . '/' . $entry);
continue;
}
@copy($Entry, $target . '/' . $entry);
}
$d->close();
} else {
copy($source, $target);
}
}
}

View file

@ -43,6 +43,11 @@ class UHCWorld {
}
public function getName() {
return $this->level->getName();
}
public function getMaxPlayers() {
return $this->maxplayers;
}

View file

@ -1,27 +0,0 @@
<?php
namespace Ad5001\UHC\Utils;
use pocketmine\level\particle\FloatingTextParticle;
use pocketmine\level\Level;
use pocketmine\Player;
class TextParticle {
public function __construct(FloatingTextParticle $particle, Level $level, Player $player) {
$pk = $particle->encode();
if ($player === null) {
if ($pk !== null) {
if (!is_array($pk)) {
$level->addChunkPacket($particle->x >> 4, $particle->z >> 4, $pk);
} else {
foreach ($pk as $e) {
$level->addChunkPacket($particle->x >> 4, $particle->z >> 4, $e);
}
}
}
} else {
if ($pk !== null) {
$player->dataPacket($packet);
}
}
}

View file

@ -36,6 +36,7 @@ abstract class Scenario implements ScenarioInt, Listener {
public function onStop() {}
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}
@ -148,6 +149,6 @@ abstract class Scenario implements ScenarioInt, Listener {
public function getScenarioFolder() {
return realPath($this->getMain()->getDataFolder . "scenarios/");
return realPath($this->getMain()->getDataFolder() . "scenarios/");
}
}

View file

@ -36,7 +36,7 @@ class FetchPlayersTask extends PluginTask {
}
$world->setPlayers($wpls);
if(count($wpls) > $world->getMaxPlayers()*0.75 and count($wpls) < $world->getMaxPlayers()) {
$this->m->startGame($world);
$this->m->UHCManager->startGame($world);
}
}
}