Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Jul 2, 2016
1 parent e475423 commit b30b823
Show file tree
Hide file tree
Showing 13 changed files with 702 additions and 144 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# ManyWorlds

* Summary: Full Suite for MultiWorld functionality
* Summary: Manage Multiple Worlds
* Dependency Plugins: n/a
* PocketMine-MP version: 1.4 - API 1.10.0
* PocketMine-MP version: 1.4 (API:1.10.0)
* OptionalPlugins: n/a
* Categories: World Editing and Management, Teleportation
* Categories: Admin Tools, Teleportation
* Plugin Access: Commands, Manages Worlds
* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/ManyWorlds)

Expand Down Expand Up @@ -166,12 +166,34 @@ for sample files.
* A: You must be using PocketMine-MP v1.4.1. Set the `generator` to
`flat`.
* Q: How do I load multiple worlds on start-up?
A: That functionality is provided by PocketMine-MP core by default.
* A: That functionality is provided by PocketMine-MP core by default.
In the `pocketmine.yml` file there is a `worlds` section where you
can define which worlds to load on start-up.
can define which worlds to load on start-up. Examples:

[CODE]

# pocketmine.yml
worlds:
world1: []
world2: []
[/CODE]

This will automatically load worlds: "world1" and "world2" on startup.

# Changes

* 2.0.3: Bugfix update
* Fixes bug reported by @thebigsmileXD
* 2.0.2: Bug fix
* Updated libcommon to 1.2.0dev1
* This fixes a bug reported by @SoyPro. (#23)
* Note this means that permissions defined in `plugin.yml` are applied
properly which means all **ManyWorlds** sub commands are **OP only**.
* 2.0.1: Bug fix
* Changed command to manyworlds and mw is an alias. This is to
prevent possible name collisions.
* Completed Spanish translation.
* Fixed crash (reported by @reyak)
* 2.0.0: Modularization
* Re-written for modularity
* teleport manager API deprecated
Expand Down
5 changes: 3 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ load: POSTWORLD

name: ManyWorlds
description: Manage Multiple Worlds
version: 2.0.0
version: 2.0.3
author: aliuly

commands:
mw:
manyworlds:
description: Manage worlds
usage: "/mw <help|sub-cmd> [options]"
permission: mw.cmds
aliases: [mw]

permissions:
mw.cmds:
Expand Down
9 changes: 5 additions & 4 deletions resources/messages/messages.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; messages.ini
"%1%-mode"=""
"%1% is already in %2%"=""
"%1% not found"=""
"- /mw unload --enable"=""
"<world>"=""
"<world> [attr=value]"=""
Expand All @@ -18,7 +19,7 @@
"Creative"=""
"Default world changed to %1%"=""
"Description: "=""
"Enable %1% features"=""
"Enabled %1% features"=""
"Enabled one feature"=""
"Error GetLevelByName %1%"=""
"Error getting %1%"=""
Expand All @@ -39,6 +40,7 @@
"Name unchanged"=""
"No change"=""
"No help for %1%"=""
"No sub-commands available"=""
"No sub-command specified"=""
"Nothing happens"=""
"Path: "=""
Expand Down Expand Up @@ -104,6 +106,5 @@
"loaded"=""
"players:%1%"=""
"to fix this issue"=""
"#<world> [player]"=""
"#List world ifnormation"=""
"#Restart server for changes to take effect!"=""
"mc.lang"="C"
"mc.version"="2.0"
11 changes: 8 additions & 3 deletions resources/messages/spa.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
; spa.ini
"%1%-mode"="modo-%1%"
"%1% is already in %2%"="%1% ya está en %2%"
"- /mw unload --enable"=""
"%1% not found"=""
"- /mw unload --enable"="- /mw unload --enable"
"<world>"="<mundo>"
"<world> [attr=value]"="<mundo> [attr=valor]"
"<world> [seed] [generator] [preset]"="<mundo> [semilla] [generador] [preset]"
"<world|--all>"="<mundo|--all>"
"> /mw fixname %1%"=""
"> /mw fixname %1%"="> /mw fixname %1%"
"Adventure"="Aventura"
"Attempt to unload worlds"="Intentando descargar mundos"
"Available sub-commands for %1%"="Sub-commandos disponibles para %1%"
Expand All @@ -18,7 +19,7 @@
"Creative"="Creativo"
"Default world changed to %1%"="Mundo inicial es ahora %1% "
"Description: "="Descripción"
"Enable %1% features"="Activando %1% módulos"
"Enabled %1% features"="Activando %1% módulos"
"Enabled one feature"="Activando un módulo"
"Error GetLevelByName %1%"="Error de GetLevelByName %1%"
"Error getting %1%"="Error obteniendo %1%"
Expand All @@ -39,6 +40,7 @@
"Name unchanged"="Nombre no ha cambiado"
"No change"="No hay cambios"
"No help for %1%"="No hay ayuda para %1%"
"No sub-commands available"="No sub-comandos disponibles"
"No sub-command specified"="No sub-comando especificado"
"Nothing happens"="No pasa nada"
"Path: "="Ruta: "
Expand Down Expand Up @@ -104,4 +106,7 @@
"loaded"="cargado"
"players:%1%"="jugadores:%1%"
"to fix this issue"="para corrregir este problema"
"mc.lang"="spa"
"mc.version"="2.0"
"#Enable %1% features"="Activando %1% módulos"
"#Restart server for changes to take effect!"="Re-inicia el servidor para que los cambios se apliquen"
2 changes: 1 addition & 1 deletion src/aliuly/manyworlds/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function autoLoad(CommandSender $c,$world) {
//
//////////////////////////////////////////////////////////////////////
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) {
if ($cmd->getName() != "mw") return false;
if ($cmd->getName() != "manyworlds") return false;
return $this->dispatchSCmd($sender,$cmd,$args);
}
//
Expand Down
3 changes: 2 additions & 1 deletion src/aliuly/manyworlds/MwLvDat.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\Compound;
use pocketmine\math\Vector3;

class MwLvDat extends BasicCli {
public function __construct($owner) {
Expand All @@ -59,7 +60,7 @@ public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args)
}
$world = array_shift($args);
if(!$this->owner->autoLoad($c,$world)) {
$c->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded!",$worl));
$c->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded!",$world));
return true;
}
$level = $this->owner->getServer()->getLevelByName($world);
Expand Down
75 changes: 72 additions & 3 deletions src/aliuly/manyworlds/common/BasicCli.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
//= api-features
//: - Paginated output
//: - Command and sub command dispatchers

namespace aliuly\manyworlds\common;

use pocketmine\command\ConsoleCommandSender;
Expand All @@ -9,15 +13,33 @@

use pocketmine\utils\TextFormat;

/**
* Implements Basic CLI common functionality. It is useful for plugins
* that implement multiple commands or sub-commands
*/
abstract class BasicCli {
protected $owner;
/**
* @param BasicPlugin @owner - Plugin that owns this module
*/
public function __construct($owner) {
$this->owner = $owner;
}

/**
* Register this class as a sub-command. See BasicPlugin for details.
*
* @param str $cmd - sub-command to register
* @param mixed[] $opts - additional options for registering sub-command
*/
public function enableSCmd($cmd,$opts) {
$this->owner->registerScmd($cmd,[$this,"onSCommand"],$opts);
}
/**
* Register this class as a command.
*
* @param str $cmd - command to register
* @param mixed[] $yaml - options for command
*/
public function enableCmd($cmd,$yaml) {
$newCmd = new PluginCommand($cmd,$this->owner);
if (isset($yaml["description"]))
Expand All @@ -43,8 +65,13 @@ public function enableCmd($cmd,$yaml) {
$cmdMap = $this->owner->getServer()->getCommandMap();
$cmdMap->register($this->owner->getDescription()->getName(),$newCmd);
}

// Paginate output
/**
* Use for paginaged output implementation.
* This gets the player specified page number that we want to Display
*
* @param str[] $args - Passed arguments
* @return int page number
*/
protected function getPageNumber(array &$args) {
$pageNumber = 1;
if (count($args) && is_numeric($args[count($args)-1])) {
Expand All @@ -53,6 +80,15 @@ protected function getPageNumber(array &$args) {
}
return $pageNumber;
}
/**
* Use for paginaged output implementation.
* Shows a bunch of line in paginated output.
*
* @param CommandSender $sender - entity that we need to display text to
* @param int $pageNumber - page that we need to display
* @param str[] $txt - Array containing one element per output line
* @return bool true
*/
protected function paginateText(CommandSender $sender,$pageNumber,array $txt) {
$hdr = array_shift($txt);
if($sender instanceof ConsoleCommandSender){
Expand All @@ -76,6 +112,15 @@ protected function paginateText(CommandSender $sender,$pageNumber,array $txt) {
}
return true;
}
/**
* Use for paginaged output implementation.
* Formats and paginates a table
*
* @param CommandSender $sender - entity that we need to display text to
* @param int $pageNumber - page that we need to display
* @param str[][] $txt - Array containing one element per cell
* @return bool true
*/
protected function paginateTable(CommandSender $sender,$pageNumber,array $tab) {
$cols = [];
for($i=0;$i < count($tab[0]);$i++) $cols[$i] = strlen($tab[0][$i]);
Expand All @@ -97,12 +142,36 @@ protected function paginateTable(CommandSender $sender,$pageNumber,array $tab) {
}

//////////////////////////////////////////////////////////////////////
/**
* Entry point for BasicPlugin state functionality. This makes it module
* specific.
* Retrieves the state.
*
* @param CommandSender $player - entity that we need state from
* @param mixed $default - Default value to return if no state found
* @return mixed $state
*/
public function getState(CommandSender $player,$default) {
return $this->owner->getState(get_class($this),$player,$default);
}
/**
* Entry point for BasicPlugin state functionality. This makes it module
* specific.
* Sets the state.
*
* @param CommandSender $player - entity that we need to set state
* @param mixed $val - Value to use for the state
*/
public function setState(CommandSender $player,$val) {
$this->owner->setState(get_class($this),$player,$val);
}
/**
* Entry point for BasicPlugin state functionality. This makes it module
* specific.
* UnSets the state.
*
* @param CommandSender $player - entity that we need to unset state
*/
public function unsetState(CommandSender $player) {
$this->owner->unsetState(get_class($this),$player);
}
Expand Down
40 changes: 27 additions & 13 deletions src/aliuly/manyworlds/common/BasicHelp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,69 @@
use pocketmine\command\Command;
use pocketmine\utils\TextFormat;
use aliuly\manyworlds\common\mc;
use aliuly\manyworlds\common\Cli;
use aliuly\manyworlds\common\BasicCli;

/**
* Implements simple help functionality for sub-commands
*/
class BasicHelp extends BasicCli {
protected $fmt;
/**
* @param PluginBase $owner - plugin that owns this command
*/
public function __construct($owner,$fmt = "/%s %s %s") {
parent::__construct($owner);
$this->enableSCmd("help",["aliases"=>["?"]]);
$this->fmt = $fmt;
}
/**
* Entry point for sub-commands. Will show the help or usage messages
*
* @param CommandSender $c - Entity issuing the command
* @param Command $cc - actual command that was issued
* @param str $scmd - sub-command being executed
* @param mixed $data - Additional data passed to sub-command (global options)
* @param str[] $args - arguments for sub-command
*/
public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
$cm = $this->owner->getSCmdMap();
$pageNumber = $this->getPageNumber($args);

if (count($args)) {
if ($args[0] == "usage") {
if (!isset($cm["usage"][$scmd])) return false;
if ($cm->getUsage($scmd) === null) return false;
$c->sendMessage(TextFormat::RED.mc::_("Usage: ").
sprintf($this->fmt,
$cc->getName(),
$scmd,
$cm["usage"][$scmd]));
$scmd, $cm->getUsage($scmd)));
return true;
}
$txt = [ "Help for ".$cc->getName() ];

foreach ($args as $i) {
if (isset($cm["alias"][$i])) $i=$cm["alias"][$i];
if (!isset($cm["help"][$i]) && !isset($cm["usage"][$i])) {
if ($cm->getAlias($i) !== null) $i=$cm->getAlias($i);
if ($cm->getHelpMsg($i) === null && $cm->getUsage($i) === null) {
$txt[] = TextFormat::RED.mc::_("No help for %1%",$i);
continue;
}

$txt[] = TextFormat::YELLOW.mc::_("Help: ").TextFormat::WHITE.
"/".$cc->getName()." $i";
if (isset($cm["help"][$i]))
if ($cm->getHelpMsg($i) !== null)
$txt[] = TextFormat::YELLOW.mc::_("Description: ").
TextFormat::WHITE.$cm["help"][$i];
if (isset($cm["usage"][$i]))
TextFormat::WHITE.$cm->getHelpMsg($i);
if ($cm->getUsage($i) !== null)
$txt[] = TextFormat::YELLOW.mc::_("Usage: ").
TextFormat::WHITE.
sprintf($this->fmt,$cc->getName(),$i,$cm["usage"][$i]);
sprintf($this->fmt,$cc->getName(),$i,$cm->getUsage($i));
}
return $this->paginateText($c,$pageNumber,$txt);
}
ksort($cm["help"]);

$txt = [ mc::_("Available sub-commands for %1%",$cc->getName()) ];
foreach ($cm["help"] as $cn => $desc) {
foreach ($cm->getHelp() as $cn => $desc) {
$ln = TextFormat::GREEN.$cn;
foreach ($cm["alias"] as $i => $j) {
foreach ($cm->getAliases() as $i => $j) {
if ($j == $cn) $ln .= "|$i";
}
$ln .= ": ".TextFormat::WHITE.$desc;
Expand Down
Loading

0 comments on commit b30b823

Please sign in to comment.