diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b24f7a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.phar
+PocketMine-MP
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..7c528c3
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libcommon"]
+ path = libcommon
+ url = https://github.com/Muirfield/libcommon.git
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1c16a66
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,25 @@
+language: php
+php:
+- '7.0'
+script:
+- bash test
+
+# We don't really need sudo, the next
+# two lines enable Ubuntu 14 which is needed to run tests.
+sudo: required
+dist: trusty
+
+before_deploy:
+- bash libcommon/mkpp -o . . --ysed='s/^depend:.*//' -l libcommon/src:mf/common=aliuly/mw/common
+
+deploy:
+ provider: releases
+ api_key:
+ secure: Tfx540S6ikBh1k0SylE5JrxUlDNiYLEOVYQseJvQf6GuGfUaXBqfBQlt5KTjgqpUWA4Bmb4W5le/aSdCqoRZhigSIUTNy+Y7ack2KpdOVYFIN8B9eWlwNPwzCwxBOCcbMxcpG0A98YdAOHEBr8bDTM0b9oXZE4OX/wFaMX4Ja8BehueGby+8W500tMcMiZHi6C7cfhBiJyhTX4FyPdvWeg9LsKrfG4+rkd0/2VxJ7+Fo74D7Ch7FB2zdkcZt18EqrOVLH71pJYHMzh6vSXdGLEbw0mNaRioLNdxnOXQY/r3DelHCB/nFoT/WPIJb9Vj1kVuW/7efZtgJOqixg6LYIsmLMP2aRmBKF6Ks6EVLJyjl7ZHRqZuUkukvDBcuq5QzuGLS1yH0HrgbiIRYfGK4LzgUR/YN+aw0BhqUwsqe4jOVviqfb3g7czuzKa5JmI/eDpGU7djhN91HOy9TOYCxGnI5nRCf1zxED88XCLcylD3uE6N35ukRv2iONbVwFfHxUPoX3bJGpQM06/sfZuuA++cvfIqbGHzHSYDrDTAM5NNoY/AdgSRAtx/3hksk3neBFpoeYVeR79eyZqnXCJZnCxK8sW0OPFD7XaTpt4F9NMiTIpIDlgKPO2VkDIM0Cq7FSiqEU926TCAVbBrsiHXrNETQ1fScSYa4zzVMxNbpBQE=
+ file:
+ - "ManyWorlds_v*.phar"
+ - "ManyWorlds-lite_v*.phar"
+ file_glob: true
+ on:
+ tags: true
+ repo: Muirfield/ManyWorlds
diff --git a/README.md b/README.md
index cb1ea09..58f6ca4 100644
--- a/README.md
+++ b/README.md
@@ -1,30 +1,48 @@
-
+
+
+
+
+
+
# ManyWorlds
-* Summary: Manage Multiple Worlds
-* Dependency Plugins: n/a
-* PocketMine-MP version: 1.6+php7 (API:2.0.0)
-* OptionalPlugins: n/a
-* Categories: Admin Tools, Teleportation
-* Plugin Access: Commands, Manages Worlds
-* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/ManyWorlds)
+- Summary: Manage Multiple Worlds
+- PocketMine-MP API version: 2.0.0
+- DependencyPlugins: libcommon
+- OptionalPlugins:
+- Categories: N/A
+- WebSite: https://github.com/Muirfield/ManyWorlds
+
-## Overview
+
+
+
+
-**DO NOT POST QUESTION/BUG-REPORTS/REQUESTS IN THE REVIEWS**
+
-It is difficult to carry a conversation in the reviews. If you have a
-question/bug-report/request please use the
+**DO NOT POST QUESTIONS/BUG-REPORTS/REQUESTS IN THE REVIEWS**
+
+It is difficult to carry a conversation in the reviews. If you
+have a question/bug-report/request please use the
[Thread](http://forums.pocketmine.net/threads/manyworlds.7277/) for
that. You are more likely to get a response and help that way.
+_NOTE:_
+
+This documentation was last updated for version **2.2.0dev1**.
+
Please go to
-[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/ManyWorlds)
+[github](https://github.com/Muirfield/ManyWorlds)
for the most up-to-date documentation.
-Full feature set of commands to manage multiple worlds.
+You can also download this plugin from this [page](https://github.com/Muirfield/pocketmine-plugins/releases/tag/ManyWorlds-2.2.0dev1).
+
+
+
+ManyWorlds implements a full feature set of commands to manage multiple worlds.
Features:
* teleport
@@ -33,17 +51,23 @@ Features:
* world info
* edit level.dat
-### Basic Usage
+Available commands:
+
+
+
+* create: Create a new world
+* default: Sets the default world
+* fixname: fixes name mismatches
+* generators: List available world generators
+* load: Loads a world
+* ls: Provide world information
+* lvdat: Show/modify `level.dat` variables
+* tp: Teleport to another world
+* unloads: Unloads world
+
-* create : Creates a new world
-* default : Sets the default world
-* fixname : fixes name mismatches
-* generators : List available world generators
-* load : Loads a world
-* ls : Provide world information
-* lvdat : Show/Modify level.dat variables
-* tp : Teleport to another world
-* unload : Unloads world
+
+
## Documentation
@@ -54,76 +78,82 @@ worlds as well as teleport between worlds.
The following commands are available:
-* /mw **create** _<world>_ _[seed]_ _[generator]_ _[preset]_
- Creates a new world
-
- Creates a world named _world_. You can optionally specify a _seed_
- as number, the generator (_flat_ or _normal_) and a _preset_ string.
-
-* /mw **default** _<world>_
- Sets the default world
-
- Teleports you to another world. If _player_ is specified, that
- player will be teleported.
-* /mw **fixname** _<world>_
- fixes name mismatches
-
+
+* create: Create a new world
+ Usage: /mw **create** _<world>_ _[seed]_ _[generator]_ _[preset]_
+
+ Creates a world named _world_. You can optionally specify a _seed_
+ as number, the generator (_flat_ or _normal_) and a _preset_ string.
+
+* default: Sets the default world
+ Usage: /mw **default** _<world>_
+
+ Changes the default world for the server.
+
+* fixname: fixes name mismatches
+ Usage: /mw **fixname** _<world>_
+
Fixes a world's **level.dat** file so that the name matches the
folder name.
-* /mw **generators**
- List available world generators
-
+
+* generators: List available world generators
+ Usage: /mw **generators**
+
List registered world generators.
-* /mw **load** _<world>_
- Loads a world
-
+
+* load: Loads a world
+ Usage: /mw **load** _<world|--all>_
+
Loads _world_ directly. Use _--all_ to load **all** worlds.
-
-* /mw **ls** _[world]_
- Provide world information
-
+
+* ls: Provide world information
+ Usage: /mw **ls** _[world]_
+
If _world_ is not specified, it will list available worlds.
Otherwise, details for _world_ will be provided.
-* /mw **lvdat** _<world>_ _[attr=value]_
- Show/Modify level.dat variables
-
+
+* lvdat: Show/modify `level.dat` variables
+ Usage: /mw **lvdat** _<world>_ _[attr=value]_
+
Change directly some **level.dat** values/attributes. Supported
attributes:
+
- spawn=x,y,z : Sets spawn point
- seed=randomseed : seed used for terrain generation
- name=string : Level name
- generator=flat|normal : Terrain generator
- preset=string : Presets string.
-
-* /mw **tp** _[player]_ _<world>_
- Teleport to another world
-
+
+* tp: Teleport to another world
+ Usage: /mw **tp** _[player]_ _<world>_
+
Teleports you to another world. If _player_ is specified, that
player will be teleported.
-* /mw **unload** _[-f]_ _<world>_
- Unloads world
-
+
+* unloads: Unloads world
+ Usage: /mw **unload** _[-f]_ _<world>_
+
Unloads _world_. Use _-f_ to force unloads.
+
+
+
### Permission Nodes
-* mw.cmds : Allow all the ManyWorlds functionality
-* mw.cmd.tp : Allows users to travel to other worlds
- (Defaults to Op)
-* mw.cmd.tp.others : Allows users to make others travel to other worlds
- (Defaults to Op)
-* mw.cmd.ls : Allows users to list worlds
- (Defaults to Op)
-* mw.cmd.world.create : Allows users to create worlds
- (Defaults to Op)
-* mw.cmd.world.load : Allows users to load worlds
- (Defaults to Op)
-* mw.cmd.lvdat : Manipulate level.dat
- (Defaults to Op)
-* mw.cmd.default : Changes default world
- (Defaults to Op)
+
+* mw.cmds: Allow all the ManyWorlds functionality
+* mw.cmd.tp (op): Allows users to travel to other worlds
+* mw.cmd.tp.others (op): Allows users to make others travel to other worlds
+* mw.cmd.ls (op): Allows users to list worlds
+* mw.cmd.world.create (op): Allows users to create worlds
+* mw.cmd.world.load (op): Allows users to load worlds
+* mw.cmd.lvdat (op): Manipulate level.dat
+* mw.cmd.default (op): Changes default world
+
+
+
## Examples
@@ -145,17 +175,24 @@ Teleport a player to another world:
## Translations
-This plugin will follow the server language configuration. The
+
+
+This plugin will honour the server language configuration. The
languages currently available are:
* English
* Spanish
+
You can provide your own message file by creating a file called
-`messages.ini` in the pluginc config directory. Check
-[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/ManyWorlds/resources/messages/)
+**messages.ini** in the plugin config directory.
+
+Check [github](https://github.com/Muirfield/ManyWorlds/resources/messages/)
for sample files.
+
+
+
## Issues
* New world names can not contain spaces.
@@ -180,21 +217,37 @@ for sample files.
This will automatically load worlds: "world1" and "world2" on startup.
+# Notes
+
+- Tests
+ - [x] mw, manyworlds
+ - [x] generators
+ - [x] create
+ - [x] default
+ - [x] fixname
+ - [x] load
+ - [x] ls, ls [world]
+ - [x] lvdat (view|write)
+ - [x] unloads
+ - [x] tp (self, others, console)
+ - [x] permissions, op vs user
+
+# Known Issues
+
+- In MwCreate, it can not test properly when a generator does not exist
+- Permissions are still broken
+
# Changes
+* 2.2.0:
+ * Updating libcommon to 2.0.0dev1
* 2.1.0: Updating to new API
* 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
+ * Bug fixes, thanks to reporters: @thebigsmileXD, @SoyPro, @reyak.
+ * Updated libcommon.
* 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
@@ -202,50 +255,32 @@ for sample files.
* New `genlist` for list of generators
* tp command changed to more natural English.
* Translation: Spanish
-* 1.3.4: Updates for PM1.5
+* 1.3.4:
+ * Updated for PM1.5
* Removed CallbackTask deprecation warnings
-* 1.3.3: Updates for PM1.5
- * Minor cosmetic changes.
- * Changes default canUnload to true if running on PM1.5
- * Fixed use of WorldProtect limits + TeleportMgr
-* 1.3.2: API update
- * Allow WorldProtect to call our commands.
- * Simplified API and updated its documentation
-* 1.3.1:
- * Fixed a bug around not show who was teleported for 3rd party
- teleport
- * Fixed all bugs reported by [Crash Archive](http://crash.pocketmine.net/)
-* 1.3.0: Level.dat hacking.
- * Added `lvdat` command to change `level.dat` settings.
+ * WorldProtect integration
+ * Simple API added
+ * Added `lvdat` command to change `level.dat` settings.
* Added `fixname` command to fix `levelName` vs. `foldername`
mismatches.
- * Fixed critical error for teleport!
-* 1.2.0: Clean-ups
* Added a setting to control if to broadcast when people teleport.
- * Removed per-level `motd.txt`.
- * Code clean-up
- * Teleport functionality encapsulated in TeleportManager.
+ * Added TeleportManager to workaround teleport glitches
+ plugins use this.
* Added workaround to remove TileEntities that linger on when teleporting.
-* 1.1.0:
* Show better help messages.
* Added world unload. May cause core dumps.
* `ls` sub-command improvements:
* paginated output
* show number of players, autoloading and default status.
- * Per-level `motd.txt`. Worlds can contain a small `motd.txt` text
- file that will be displayed when the player enters or when they
- type the `/motd` command.
- * Workaround teleport glitches, with a minimal API to let other
- plugins use this.
* Added `loadall` functionality.
- * BugFix: given an invalid player name to teleport would crash server.
+ * Bug Fixes
* 1.0.0 : Initial release
-Copyright
----------
+
+# Copyright
ManyWorlds
- Copyright (C) 2015 Alejandro Liu
+ Copyright (C) 2016 Alejandro Liu
All Rights Reserved.
This program is free software: you can redistribute it and/or modify
@@ -261,3 +296,6 @@ Copyright
You should have received a copy of the GNU General Public License
along with this program. If not, see .
+
+
+
diff --git a/libcommon b/libcommon
new file mode 160000
index 0000000..efeea8c
--- /dev/null
+++ b/libcommon
@@ -0,0 +1 @@
+Subproject commit efeea8cdc7098a75304b2bf43d41bb2eaa39a01c
diff --git a/plugin.yml b/plugin.yml
index a39b751..d755410 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -2,10 +2,12 @@ main: aliuly\manyworlds\Main
api: 2.0.0
load: POSTWORLD
+depend: [ libcommon ]
name: ManyWorlds
description: Manage Multiple Worlds
-version: 2.1.0
+version: 2.2.0dev1
author: aliuly
+website: https://github.com/Muirfield/ManyWorlds
commands:
manyworlds:
diff --git a/precommit b/precommit
new file mode 100755
index 0000000..5e00fd2
--- /dev/null
+++ b/precommit
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Run this usually from a pre-commit hook...
+#
+. "$(dirname "$(readlink -f "$0")")/libcommon/utils/init.sh"
+
+[ ! -f plugin.yml ] && fatal "No plugin.yml"
+[ -f README.md ] && $gd3tool gen -w src
+
+if [ -d resource/messages ] ; then
+ $mcgen gen resources/messages src $([ -d libcommon/src ] && echo libcommon/src)
+ $mcgen enc resources/messages
+fi
+
+$mkver src
+phplint src || fatal "Failed lint"
diff --git a/resources/messages/messages.ini b/resources/messages/messages.ini
index ff7b08f..0bea17e 100644
--- a/resources/messages/messages.ini
+++ b/resources/messages/messages.ini
@@ -1,8 +1,12 @@
; messages.ini
+"%1% %2% [subcmd] [page]"=""
"%1%-mode"=""
+"%1% [options]"=""
+"%1% command set"=""
"%1% is already in %2%"=""
+"%1% is not an instance of %2%"=""
"%1% not found"=""
-"- /mw unload --enable"=""
+" (%1% of %2%)"=""
""=""
" [attr=value]"=""
" [seed] [generator] [preset]"=""
@@ -10,25 +14,27 @@
"> /mw fixname %1%"=""
"Adventure"=""
"Attempt to unload worlds"=""
-"Available sub-commands for %1%"=""
+"Available"=""
"CHANGES WILL NOT TAKE EFFECT UNTIL UNLOAD"=""
"Change failed!"=""
"Change level.dat values"=""
-"Changes default world"=""
+"Command %1% does not exist"=""
"Creates a new world"=""
"Creative"=""
"Default world changed to %1%"=""
-"Description: "=""
"Enabled %1% features"=""
"Enabled one feature"=""
"Error GetLevelByName %1%"=""
+"Error activating feature \"%1%\""=""
"Error getting %1%"=""
"Fixes world name"=""
"Folder Name and Level.Dat names do NOT match"=""
"Generator: "=""
"Generator Presets: "=""
"Generator unchanged"=""
-"Help: "=""
+"Generic command"=""
+"Generic sub command"=""
+"Help for %1%"=""
"Info for %1%"=""
"Invalid element: %1%, ignored"=""
"Invalid spawn location: %1%"=""
@@ -39,10 +45,9 @@
"Name: "=""
"Name unchanged"=""
"No change"=""
-"No help for %1%"=""
-"No sub-commands available"=""
-"No sub-command specified"=""
+"No sub command specified"=""
"Nothing happens"=""
+"Only %1% pages available"=""
"Path: "=""
"Players(%1%):"=""
"Preset unchanged"=""
@@ -50,9 +55,13 @@
"Running /mw lvdat %1% name=%1%"=""
"Seed: "=""
"Seed unchanged"=""
+"Sets the default world"=""
+"Show help for %1%"=""
"Spawn: "=""
"Spawn location is unchanged"=""
"Spectator"=""
+"Sub-commands for %1%"=""
+"Sub command \"%1%\" not recognized"=""
"Survival"=""
"Teleport across worlds"=""
"Teleport failed"=""
@@ -61,13 +70,12 @@
"This can cause intermitent problems"=""
"Unknown feature \"%1%\" ignored."=""
"Unknown key %1%, ignored"=""
-"Unknown sub-command %2% (try /%1% help)"=""
"Updating level.dat for %1%"=""
-"Usage: "=""
+"Usage: %1%"=""
+"Usage: %1% [options]"=""
"Use: "=""
"Worlds: %1%"=""
"You are already in %1%"=""
-"You are not allowed to do this"=""
"You can only do this in-game"=""
"You do not have permission to do that."=""
"[-f] "=""
@@ -83,22 +91,14 @@
"[MW] Missing path %1%"=""
"[MW] No levels to load"=""
"[MW] No world with the name %1% exists!"=""
-"[MW] Plugin provided world generators\n are not included in\n this list."=""
-"[MW] To activate use:"=""
-"[MW] To disable use: /mw unload --disable"=""
-"[MW] To enable use: /mw unload --enable"=""
"[MW] Unable to get %1%"=""
"[MW] Unable to load %1%"=""
"[MW] Unable to unload %1%"=""
"[MW] Unable to unload %1%. Try -f"=""
"[MW] Unexpected error"=""
"[MW] Unknown generator %1%"=""
-"[MW] Unload sub-command disabled"=""
-"[MW] Unload sub-command enabled"=""
-"[MW] Unload sub-command is disabled by default"=""
"[MW] Using %1%"=""
-"[MW] server to CRASH!"=""
-"[MW] this is because that it usually causes the"=""
+"[options]"=""
"[player] "=""
"[world]"=""
"auto"=""
@@ -108,3 +108,24 @@
"to fix this issue"=""
"mc.lang"="C"
"mc.version"="2.0"
+"#%1% %2% [options]"=""
+"#- /mw unload --enable"=""
+"#Available sub-commands for %1%"=""
+"#Changes default world"=""
+"#Description: "=""
+"#Help: "=""
+"#No help for %1%"=""
+"#No sub-commands available"=""
+"#No sub-command specified"=""
+"#Unknown sub-command %2% (try /%1% help)"=""
+"#Usage: "=""
+"#You are not allowed to do this"=""
+"#[MW] Plugin provided world generators\n are not included in\n this list."=""
+"#[MW] To activate use:"=""
+"#[MW] To disable use: /mw unload --disable"=""
+"#[MW] To enable use: /mw unload --enable"=""
+"#[MW] Unload sub-command disabled"=""
+"#[MW] Unload sub-command enabled"=""
+"#[MW] Unload sub-command is disabled by default"=""
+"#[MW] server to CRASH!"=""
+"#[MW] this is because that it usually causes the"=""
diff --git a/resources/messages/spa.ini b/resources/messages/spa.ini
index fb8a65d..26450fc 100644
--- a/resources/messages/spa.ini
+++ b/resources/messages/spa.ini
@@ -1,8 +1,12 @@
; spa.ini
+"%1% %2% [subcmd] [page]"=""
"%1%-mode"="modo-%1%"
+"%1% [options]"=""
+"%1% command set"=""
"%1% is already in %2%"="%1% ya está en %2%"
+"%1% is not an instance of %2%"=""
"%1% not found"=""
-"- /mw unload --enable"="- /mw unload --enable"
+" (%1% of %2%)"=""
""=""
" [attr=value]"=" [attr=valor]"
" [seed] [generator] [preset]"=" [semilla] [generador] [preset]"
@@ -10,25 +14,27 @@
"> /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%"
+"Available"=""
"CHANGES WILL NOT TAKE EFFECT UNTIL UNLOAD"="CAMBIOS NO TENDRAN EFECTO HASTA UNA DESCARGA"
"Change failed!"="Cambio no resultó"
"Change level.dat values"="Cambiando valores de level.dat"
-"Changes default world"="Cambia el mundo inicial"
+"Command %1% does not exist"=""
"Creates a new world"="Crea un nuevo mundo"
"Creative"="Creativo"
"Default world changed to %1%"="Mundo inicial es ahora %1% "
-"Description: "="Descripción"
"Enabled %1% features"="Activando %1% módulos"
"Enabled one feature"="Activando un módulo"
"Error GetLevelByName %1%"="Error de GetLevelByName %1%"
+"Error activating feature \"%1%\""=""
"Error getting %1%"="Error obteniendo %1%"
"Fixes world name"="Corrige el nombre de un mundo"
"Folder Name and Level.Dat names do NOT match"="Nombre de Carpeta y nombre de Level.Dat no concuerdan"
"Generator: "="Generador: "
"Generator Presets: "="Presets: "
"Generator unchanged"="Generador no ha cambiado"
-"Help: "="Ayuda: "
+"Generic command"=""
+"Generic sub command"=""
+"Help for %1%"=""
"Info for %1%"="Detalles de %1%"
"Invalid element: %1%, ignored"="Elemento invalido: %1%, ignorando"
"Invalid spawn location: %1%"="Lugar de aparción incorrecto: %1%"
@@ -39,10 +45,9 @@
"Name: "="Nombre: "
"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"
+"No sub command specified"=""
"Nothing happens"="No pasa nada"
+"Only %1% pages available"=""
"Path: "="Ruta: "
"Players(%1%):"="Jugadores(%1%):"
"Preset unchanged"="Preset no ha cambiado"
@@ -50,9 +55,13 @@
"Running /mw lvdat %1% name=%1%"="Corriendo /mwdat lvdat %1% name=%1%"
"Seed: "="Semilla: "
"Seed unchanged"="Semilla no ha cambiado"
+"Sets the default world"=""
+"Show help for %1%"=""
"Spawn: "="Punto de Aparición: "
"Spawn location is unchanged"="Punto de Aparición no ha cambiado"
"Spectator"="Espectador"
+"Sub-commands for %1%"=""
+"Sub command \"%1%\" not recognized"=""
"Survival"="Supervivencia"
"Teleport across worlds"="Teletransporta através de mundos"
"Teleport failed"="Teletransporte falló"
@@ -61,13 +70,12 @@
"This can cause intermitent problems"="Esto causa problemas intermitentes"
"Unknown feature \"%1%\" ignored."="Modulo %1% desconocido, ignorando"
"Unknown key %1%, ignored"="Clave %1% desconocida, ignorando"
-"Unknown sub-command %2% (try /%1% help)"="Comando %2% desconocido (Intente /try /%1% help)"
"Updating level.dat for %1%"="Actualizando level.dat para %1%"
-"Usage: "="Uso: "
+"Usage: %1%"=""
+"Usage: %1% [options]"=""
"Use: "="Use: "
"Worlds: %1%"="Mundos: %1%"
"You are already in %1%"="Usted ya está en %1%"
-"You are not allowed to do this"="Usted no está permitido para hacer esto"
"You can only do this in-game"="Solo se puede hacer eso dentro del juego"
"You do not have permission to do that."="Usted no está permitido para hacer esto"
"[-f] "="[-f] "
@@ -83,22 +91,14 @@
"[MW] Missing path %1%"="[MW] Ruta no disponible %1%"
"[MW] No levels to load"="[MW] No hay mundos por cargar"
"[MW] No world with the name %1% exists!"="[MW] %1% no existe!"
-"[MW] Plugin provided world generators\n are not included in\n this list."="[MW] Generadores cargados por Plugin no son encontrados en esta lista."
-"[MW] To activate use:"="[MW] para activar use:"
-"[MW] To disable use: /mw unload --disable"="Para des-activar use: /mw unload --disable"
-"[MW] To enable use: /mw unload --enable"="Para activar use: /mw unload --enable"
"[MW] Unable to get %1%"="[MW] No se puede obtener %1%"
"[MW] Unable to load %1%"="[MW] No se puede cargar %1%"
"[MW] Unable to unload %1%"="[MW] No se puede descargar %1%"
"[MW] Unable to unload %1%. Try -f"="[MW] No se puede descargar %1%. Intente con -f"
"[MW] Unexpected error"="[MW] Error inesperado"
"[MW] Unknown generator %1%"="[MW] Generador %1% desconosido"
-"[MW] Unload sub-command disabled"="[MW] Sub-comando Unload deshabilitado"
-"[MW] Unload sub-command enabled"="[MW] Sub-comando Unload habilitado"
-"[MW] Unload sub-command is disabled by default"="[MW] Sub-comando Unload no está disponibile por defecto"
"[MW] Using %1%"="[MW] Usando %1%"
-"[MW] server to CRASH!"="[MW] que el servidor se caiga."
-"[MW] this is because that it usually causes the"="[MW] por que usualmente esto causa"
+"[options]"=""
"[player] "="[jugador] "
"[world]"="[mundo]"
"auto"="automatico"
@@ -108,5 +108,26 @@
"to fix this issue"="para corrregir este problema"
"mc.lang"="spa"
"mc.version"="2.0"
+"#%1% %2% [options]"=""
+"#- /mw unload --enable"="- /mw unload --enable"
+"#Available sub-commands for %1%"="Sub-commandos disponibles para %1%"
+"#Changes default world"="Cambia el mundo inicial"
+"#Description: "="Descripción"
"#Enable %1% features"="Activando %1% módulos"
+"#Help: "="Ayuda: "
+"#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"
"#Restart server for changes to take effect!"="Re-inicia el servidor para que los cambios se apliquen"
+"#Unknown sub-command %2% (try /%1% help)"="Comando %2% desconocido (Intente /try /%1% help)"
+"#Usage: "="Uso: "
+"#You are not allowed to do this"="Usted no está permitido para hacer esto"
+"#[MW] Plugin provided world generators\n are not included in\n this list."="[MW] Generadores cargados por Plugin no son encontrados en esta lista."
+"#[MW] To activate use:"="[MW] para activar use:"
+"#[MW] To disable use: /mw unload --disable"="Para des-activar use: /mw unload --disable"
+"#[MW] To enable use: /mw unload --enable"="Para activar use: /mw unload --enable"
+"#[MW] Unload sub-command disabled"="[MW] Sub-comando Unload deshabilitado"
+"#[MW] Unload sub-command enabled"="[MW] Sub-comando Unload habilitado"
+"#[MW] Unload sub-command is disabled by default"="[MW] Sub-comando Unload no está disponibile por defecto"
+"#[MW] server to CRASH!"="[MW] que el servidor se caiga."
+"#[MW] this is because that it usually causes the"="[MW] por que usualmente esto causa"
diff --git a/src/aliuly/manyworlds/Main.php b/src/aliuly/manyworlds/Main.php
index 6b2d3f4..b69f1e4 100644
--- a/src/aliuly/manyworlds/Main.php
+++ b/src/aliuly/manyworlds/Main.php
@@ -1,104 +1,53 @@
getDataFolder())) mkdir($this->getDataFolder());
- mc::plugin_init($this,$this->getFile());
-
- if (MPMU::apiVersion("1.12.0")) {
- $this->canUnload = true;
- $this->tpMgr = null;
- } else {
- $this->canUnload = false;
- $this->tpMgr = new TeleportManager($this);
- }
- $this->modules = [];
- foreach ([
- "MwTp",
- "MwLs",
- "MwCreate",
- "MwGenLst",
- "MwLoader",
- "MwLvDat",
- "MwDefault",
- ] as $mod) {
- $mod = __NAMESPACE__."\\".$mod;
- $this->modules[] = new $mod($this);
- }
- $this->modules[] = new BasicHelp($this);
- }
-
- public function autoLoad(CommandSender $c,$world) {
- if ($this->getServer()->isLevelLoaded($world)) return true;
- if($c !== null && !MPMU::access($c, "mw.cmd.world.load")) return false;
- if(!$this->getServer()->isLevelGenerated($world)) {
- if ($c !== null) {
- $c->sendMessage(mc::_("[MW] No world with the name %1% exists!",
- $world));
- }
- return false;
- }
- $this->getServer()->loadLevel($world);
- return $this->getServer()->isLevelLoaded($world);
- }
+use pocketmine\command\CommandSender;
- //////////////////////////////////////////////////////////////////////
- //
- // Command dispatcher
- //
- //////////////////////////////////////////////////////////////////////
- public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) {
- if ($cmd->getName() != "manyworlds") return false;
- return $this->dispatchSCmd($sender,$cmd,$args);
- }
- //
- // Deprecated Public API
- //
- public function mwtp($pl,$pos) {
- if ($this->tpMgr && ($pos instanceof Position)) {
- // Using ManyWorlds for teleporting...
- return $this->teleport($pl,$pos->getLevel()->getName(),
- new Vector3($pos->getX(),
- $pos->getY(),
- $pos->getZ()));
- }
- $pl->teleport($pos);
- return true;
- }
- public function teleport($player,$world,$spawn=null) {
- if ($this->tpMgr) {
- return $this->tpMgr->teleport($player,$world,$spawn);
- }
- if (!$this->getServer()->isLevelLoaded($world)) return false;
- $level = $this->owner->getServer()->getLevelByName($world);
- if (!$level) return false;
- // Try to find a reasonable spawn location
- $location = $level->getSafeSpawn($spawn);
- $player->teleport($location);
- }
+use aliuly\manyworlds\MwTp;
+use aliuly\manyworlds\MwLs;
+use aliuly\manyworlds\MwCreate;
+use aliuly\manyworlds\MwGenLst;
+use aliuly\manyworlds\MwLoader;
+use aliuly\manyworlds\MwLvDat;
+use aliuly\manyworlds\MwDefault;
+
+class Main extends ModularPlugin {
+ public function onEnable() {
+ mc::init($this,$this->getFile());
+
+ $this->addModule("teleport",new MwTp($this,[]));
+ $this->addModule("lister",new MwLs($this,[]));
+ $this->addModule("creator",new MwCreate($this,[]));
+ $this->addModule("genlister",new MwGenLst($this,[]));
+ $this->addModule("loader",new MwLoader($this,[]));
+ $this->addModule("unloader",new MwUnload($this,[]));
+ $this->addModule("default",new MwDefault($this,[]));
+ $this->addModule("lvdat",new MwLvDat($this,[]));
+ $this->addModule("lvdat",new MwFixName($this,[]));
+ $this->addModule("mwhelp",new HelpSubCmd($this,"manyworlds"));
+ }
+
+ /**
+ * Autoload a world
+ *
+ * @param CommandSender $c - person attempting this operation
+ * @param str $world - world to load
+ * @return bool - TRUE on success, FALSE on ERROR
+ */
+ public function autoLoad(CommandSender $c,$world) {
+ if ($this->getServer()->isLevelLoaded($world)) return TRUE;
+ if($c !== NULL && !Perms::access($c, "mw.cmd.world.load")) return FALSE;
+ if(!$this->getServer()->isLevelGenerated($world)) {
+ if ($c !== NULL) $c->sendMessage(mc::_("[MW] No world with the name %1% exists!", $world));
+ return FALSE;
+ }
+ $this->getServer()->loadLevel($world);
+ return $this->getServer()->isLevelLoaded($world);
+ }
}
+
diff --git a/src/aliuly/manyworlds/MwCreate.php b/src/aliuly/manyworlds/MwCreate.php
index d86cb8f..de3be31 100644
--- a/src/aliuly/manyworlds/MwCreate.php
+++ b/src/aliuly/manyworlds/MwCreate.php
@@ -1,63 +1,53 @@
_ _[seed]_ _[generator]_ _[preset]_
- **
- ** Creates a world named _world_. You can optionally specify a _seed_
- ** as number, the generator (_flat_ or _normal_) and a _preset_ string.
- **
- **/
+//= cmd:create
+//: Create a new world
+//> Usage: /mw **create** __ _[seed]_ _[generator]_ _[preset]_
+//:
+//: Creates a world named _world_. You can optionally specify a _seed_
+//: as number, the generator (_flat_ or _normal_) and a _preset_ string.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
use pocketmine\level\generator\Generator;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\BasicCli;
+class MwCreate extends MwSubCmd {
+ public function getName() { return "create"; }
+ public function getAliases() { return ["new"]; }
+ public function getHelp() { return mc::_("Creates a new world"); }
+ public function getUsage() { return mc::_(" [seed] [generator] [preset]"); }
+ public function getPermission() { return "mw.cmd.world.create"; }
-class MwCreate extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("create",["usage" => mc::_(" [seed] [generator] [preset]"),
- "help" => mc::_("Creates a new world"),
- "permission" => "mw.cmd.world.create",
- "aliases" => ["new"]]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) < 1 || count($args)>4) return false;
- $world = array_shift($args);
- if ($this->owner->getServer()->isLevelGenerated($world)) {
- $c->sendMessage(TextFormat::RED.
- mc::_("[MW] A world named %1% already exists",$world));
- return true;
- }
- $seed = null;
- $generator = null;
- $opts = [];
- if (isset($args[0])) $seed = intval($args[0]);
- if (isset($args[1])) {
- $generator = Generator::getGenerator($args[1]);
- if (strtolower($args[1]) != Generator::getGeneratorName($generator)){
- $c->sendMessage(TextFormat::RED.
- mc::_("[MW] Unknown generator %1%",$args[1]));
- return true;
- }
- $c->sendMessage(TextFormat::GREEN.
- mc::_("[MW] Using %1%",
- Generator::getGeneratorName($generator)));
- }
- if(isset($args[2])) $opts = ["preset" => $args[2] ];
- $this->owner->getServer()->broadcastMessage(
- mc::_("[MW] Creating level %1%... (Expect Lag)", $world));
- $this->owner->getServer()->generateLevel($world,$seed,$generator,$opts);
- $this->owner->getServer()->loadLevel($world);
- return true;
- }
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) < 1 || count($args)>4) return FALSE;
+ $world = array_shift($args);
+ if ($this->getPlugin()->getServer()->isLevelGenerated($world)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] A world named %1% already exists",$world));
+ return TRUE;
+ }
+ $seed = NULL;
+ $generator = NULL;
+ $opts = [];
+ if (isset($args[0])) $seed = intval($args[0]);
+ if (isset($args[1])) {
+ $generator = Generator::getGenerator($args[1]);
+ if (strtolower($args[1]) != Generator::getGeneratorName($generator)){
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unknown generator %1%",$args[1]));
+ return TRUE;
+ }
+ $sender->sendMessage(TextFormat::GREEN.mc::_("[MW] Using %1%",Generator::getGeneratorName($generator)));
+ }
+ if(isset($args[2])) $opts = ["preset" => $args[2] ];
+ $this->getPlugin()->getServer()->broadcastMessage(mc::_("[MW] Creating level %1%... (Expect Lag)", $world));
+ $this->getPlugin()->getServer()->generateLevel($world,$seed,$generator,$opts);
+ $this->getPlugin()->getServer()->loadLevel($world);
+ return TRUE;
+ }
}
diff --git a/src/aliuly/manyworlds/MwDefault.php b/src/aliuly/manyworlds/MwDefault.php
index 99e41bb..4f7aa39 100644
--- a/src/aliuly/manyworlds/MwDefault.php
+++ b/src/aliuly/manyworlds/MwDefault.php
@@ -1,54 +1,49 @@
_
- **
- ** Teleports you to another world. If _player_ is specified, that
- ** player will be teleported.
- **/
+//= cmd:default
+//: Sets the default world
+//> Usage: /mw **default** __
+//:
+//: Changes the default world for the server.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\BasicCli;
+class MwDefault extends MwSubCmd {
+ public function getName() { return "default"; }
+ public function getAliases() { return ["def"]; }
+ public function getHelp() { return mc::_("Sets the default world"); }
+ public function getUsage() { return mc::_(""); }
+ public function getPermission() { return "mw.cmd.default"; }
-class MwDefault extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("default",["usage" => mc::_(""),
- "help" => mc::_("Changes default world"),
- "permission" => "mw.cmd.default"]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) == 0) return false;
- $wname =implode(" ",$args);
- $old = $this->owner->getServer()->getConfigString("level-name");
- if ($old == $wname) {
- $c->sendMessage(TextFormat::RED.mc::_("No change"));
- return true;
- }
- if (!$this->owner->autoLoad($c,$wname)) {
- $c->sendMessage(TextFormat::RED.
- mc::_("[MW] Unable to load %1%",$wname));
- $c->sendMessage(TextFormat::RED.mc::_("Change failed!"));
- return true;
- }
- $level = $this->owner->getServer()->getLevelByName($wname);
- if ($level === null) {
- $c->sendMessage(TextFormat::RED.mc::_("Error GetLevelByName %1%"));
- return true;
- }
- $this->owner->getServer()->setConfigString("level-name",$wname);
- $this->owner->getServer()->setDefaultLevel($level);
- $c->sendMessage(TextFormat::BLUE.mc::_("Default world changed to %1%",$wname));
- return true;
- }
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) == 0) return FALSE;
+ $wname =implode(" ",$args);
+ $old = $this->getPlugin()->getServer()->getConfigString("level-name");
+ if ($old == $wname) {
+ $sender->sendMessage(TextFormat::RED.mc::_("No change"));
+ return TRUE;
+ }
+ if (!$this->getPlugin()->autoLoad($sender,$wname)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to load %1%",$wname));
+ $sender->sendMessage(TextFormat::RED.mc::_("Change failed!"));
+ return TRUE;
+ }
+ $level = $this->getPlugin()->getServer()->getLevelByName($wname);
+ if ($level === NULL) {
+ $c->sendMessage(TextFormat::RED.mc::_("Error GetLevelByName %1%"));
+ return TRUE;
+ }
+ $this->getPlugin()->getServer()->setConfigString("level-name",$wname);
+ $this->getPlugin()->getServer()->setDefaultLevel($level);
+ $sender->sendMessage(TextFormat::BLUE.mc::_("Default world changed to %1%",$wname));
+ return TRUE;
+ }
}
diff --git a/src/aliuly/manyworlds/MwFixName.php b/src/aliuly/manyworlds/MwFixName.php
new file mode 100644
index 0000000..82e2793
--- /dev/null
+++ b/src/aliuly/manyworlds/MwFixName.php
@@ -0,0 +1,36 @@
+ Usage: /mw **fixname** __
+//:
+//: Fixes a world's **level.dat** file so that the name matches the
+//: folder name.
+//:
+
+namespace aliuly\manyworlds;
+
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+use aliuly\manyworlds\MwLvDat;
+
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
+use pocketmine\utils\TextFormat;
+
+class MwFixName extends MwSubCmd {
+ public function getName() { return "fixname"; }
+ public function getAliases() { return ["fix"]; }
+ public function getHelp() { return mc::_("Fixes world name"); }
+ public function getUsage() { return mc::_(""); }
+ public function getPermission() { return "mw.cmd.lvdat"; }
+
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ $world = implode(" ",$args);
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Running /mw lvdat %1% name=%1%",$world));
+ $args = [ $world, "name=$world" ];
+ return $this->getPlugin()->callModule(MwLvDat::class, "onCommand",
+ [ $sender, $command, $label, $args ]);
+ }
+}
diff --git a/src/aliuly/manyworlds/MwGenLst.php b/src/aliuly/manyworlds/MwGenLst.php
index 00cedc4..6e20f90 100644
--- a/src/aliuly/manyworlds/MwGenLst.php
+++ b/src/aliuly/manyworlds/MwGenLst.php
@@ -1,44 +1,31 @@
Usage: /mw **generators**
+//:
+//: List registered world generators.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+
+use aliuly\manyworlds\MwSubCmd;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
use pocketmine\level\generator\Generator;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\MPMU;
-use aliuly\manyworlds\common\BasicCli;
-
-class MwGenLst extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("generators",["usage" => "",
- "help" => mc::_("List world generators"),
- "permission" => "mw.cmd.world.create",
- "aliases" => ["gen","genlst"]]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) != 0) return false;
+class MwGenLst extends MwSubCmd {
+ public function getName() { return "generators"; }
+ public function getAliases() { return ["gen","genls"]; }
+ public function getHelp() { return mc::_("List world generators"); }
+ public function getUsage() { return ""; }
+ public function getPermission() { return "mw.cmd.world.create"; }
- if (MPMU::apiVersion("1.12.0")||MPMU::apiVersion("2.0.0")) {
- $c->sendMessage(implode(", ",Generator::getGeneratorList()));
- } else {
- $c->sendMessage("normal, flat");
- $c->sendMessage(TextFormat::RED.
- mc::_("[MW] Plugin provided world generators\n are not included in\n this list."));
- }
- return true;
- }
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) != 0) return FALSE;
+ $sender->sendMessage(implode(", ",Generator::getGeneratorList()));
+ return TRUE;
+ }
}
diff --git a/src/aliuly/manyworlds/MwLoader.php b/src/aliuly/manyworlds/MwLoader.php
index cf72553..f519c80 100644
--- a/src/aliuly/manyworlds/MwLoader.php
+++ b/src/aliuly/manyworlds/MwLoader.php
@@ -1,144 +1,63 @@
_
- **
- ** Loads _world_ directly. Use _--all_ to load **all** worlds.
- **
- ** * unload : Unloads world
- ** usage: /mw **unload** _[-f]_ __
- **
- ** Unloads _world_. Use _-f_ to force unloads.
- **/
+//= cmd:load
+//: Loads a world
+//> Usage: /mw **load** __
+//:
+//: Loads _world_ directly. Use _--all_ to load **all** worlds.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\MPMU;
-use aliuly\manyworlds\common\BasicCli;
+class MwLoader extends MwSubCmd {
+ public function getName() { return "load"; }
+ public function getAliases() { return ["ld"]; }
+ public function getHelp() { return mc::_("Load worlds"); }
+ public function getUsage() { return mc::_(""); }
+ public function getPermission() { return "mw.cmd.world.load"; }
-class MwLoader extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("load",["usage" => mc::_(""),
- "help" => mc::_("Load worlds"),
- "permission" => "mw.cmd.world.load",
- "aliases" => ["ld"]]);
- $this->enableSCmd("unload",["usage" => mc::_("[-f] "),
- "help" => mc::_("Attempt to unload worlds"),
- "permission" => "mw.cmd.world.load"]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) == 0) return false;
- switch ($scmd) {
- case "load":
- return $this->mwWorldLoadCmd($c,implode(" ",$args));
- case "unload":
- $force = false;
- if ($args[0] == "-f") {
- $force = true;
- array_shift($args);
- if (count($args) == 0) return false;
- }
- return $this->mwWorldUnloadCmd($c,implode(" ",$args),$force);
- }
- return false;
- }
- private function mwWorldLoadCmd(CommandSender $sender,$wname) {
- if ($wname == "--all") {
- $wlst = [];
- foreach (glob($this->owner->getServer()->getDataPath(). "worlds/*") as $f) {
- $world = basename($f);
- if ($this->owner->getServer()->isLevelLoaded($world)) continue;
- if (!$this->owner->getServer()->isLevelGenerated($world)) continue;
- $wlst[] = $world;
- }
- if (count($wlst) == 0) {
- $sender->sendMessage(TextFormat::RED.
- mc::_("[MW] No levels to load"));
- return true;
- }
- $sender->sendMessage(
- TextFormat::AQUA.
- mc::n(
- mc::_("[MW] Loading one level"),
- mc::_("[MW] Loading ALL %1% levels",count($wlst)),
- count($wlst)));
- } else {
- if ($this->owner->getServer()->isLevelLoaded($wname)) {
- $sender->sendMessage(TextFormat::RED.
- mc::_("[MW] %1% already loaded",$wname));
- return true;
- }
- if (!$this->owner->getServer()->isLevelGenerated($wname)) {
- $sender->sendMessage(TextFormat::RED.
- mc::_("[MW] %1% does not exists",$wname));
- return true;
- }
- $wlst = [ $wname ];
- }
- foreach ($wlst as $world) {
- if (!$this->owner->autoLoad($sender,$world)) {
- $sender->sendMessage(TextFormat::RED.
- mc::_("[MW] Unable to load %1%",$world));
- }
- }
- return true;
- }
- private function mwWorldUnloadCmd(CommandSender $sender,$wname,$force) {
- if (MPMU::apiVersion("<1.12.0")) {
- // For old stuff...
- if ($wname == "--enable") {
- $this->owner->canUnload = true;
- $sender->sendMessage(TextFormat::YELLOW.
- mc::_("[MW] Unload sub-command enabled"));
- $sender->sendMessage(TextFormat::YELLOW.
- mc::_("[MW] To disable use: /mw unload --disable"));
- return true;
- }
- if ($wname == "--disable") {
- $this->owner->canUnload = false;
- $sender->sendMessage(TextFormat::GREEN.
- mc::_("[MW] Unload sub-command disabled"));
- $sender->sendMessage(TextFormat::GREEN.
- mc::_("[MW] To enable use: /mw unload --enable"));
- return true;
- }
- if (!$this->owner->canUnload) {
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unload sub-command is disabled by default"));
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] this is because that it usually causes the"));
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] server to CRASH!"));
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] To activate use:"));
- $sender->sendMessage(TextFormat::BLUE.mc::_("- /mw unload --enable"));
- return true;
- }
- }
- // Actual implementation
- if (!$this->owner->getServer()->isLevelLoaded($wname)) {
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded.",$wname));
- return true;
- }
- $level = $this->owner->getServer()->getLevelByName($wname);
- if ($level === null) {
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to get %1%",$wname));
- return true;
- }
- if (!$this->owner->getServer()->unloadLevel($level,$force)) {
- if ($force)
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to unload %1%",$wname));
- else
- $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to unload %1%. Try -f",$wname));
- } else {
- $sender->sendMessage(TextFormat::GREEN.mc::_("[MW] %1% unloaded.",$wname));
- }
- return true;
- }
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) == 0) return FALSE;
+ $wname = implode(" ",$args);
+ if ($wname == "--all") {
+ $wlst = [];
+ foreach (glob($this->getPlugin()->getServer()->getDataPath(). "worlds/*") as $f) {
+ $world = basename($f);
+ if ($this->getPlugin()->getServer()->isLevelLoaded($world)) continue;
+ if (!$this->getPlugin()->getServer()->isLevelGenerated($world)) continue;
+ $wlst[] = $world;
+ }
+ if (count($wlst) == 0) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] No levels to load"));
+ return TRUE;
+ }
+ $sender->sendMessage(TextFormat::AQUA.mc::n(
+ mc::_("[MW] Loading one level"),
+ mc::_("[MW] Loading ALL %1% levels",count($wlst)),
+ count($wlst)));
+ } else {
+ if ($this->getPlugin()->getServer()->isLevelLoaded($wname)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] %1% already loaded",$wname));
+ return TRUE;
+ }
+ if (!$this->getPlugin()->getServer()->isLevelGenerated($wname)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] %1% does not exists",$wname));
+ return TRUE;
+ }
+ $wlst = [ $wname ];
+ }
+ foreach ($wlst as $world) {
+ if (!$this->getPlugin()->autoLoad($sender,$world)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to load %1%",$world));
+ }
+ }
+ return TRUE;
+ }
}
diff --git a/src/aliuly/manyworlds/MwLs.php b/src/aliuly/manyworlds/MwLs.php
index 580f321..37c73b0 100644
--- a/src/aliuly/manyworlds/MwLs.php
+++ b/src/aliuly/manyworlds/MwLs.php
@@ -1,132 +1,129 @@
Usage: /mw **ls** _[world]_
+//:
+//: If _world_ is not specified, it will list available worlds.
+//: Otherwise, details for _world_ will be provided.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
-
use pocketmine\utils\TextFormat;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\BasicCli;
+use mf\common\mc;
+use mf\common\Perms;
+use mf\common\Pager;
+
+use aliuly\manyworlds\MwSubCmd;
+
+class MwLs extends MwSubCmd {
+ public function getName() { return "list"; }
+ public function getAliases() { return ["ls","info"]; }
+ public function getHelp() { return mc::_("List world information"); }
+ public function getUsage() { return mc::_("[world]"); }
+ public function getPermission() { return "mw.cmd.ls"; }
-class MwLs extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("ls",["usage" => mc::_("[world]"),
- "help" => mc::_("List world information"),
- "permission" => "mw.cmd.ls",
- "aliases" => ["list","info"]]);
- }
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ $pageNumber = Pager::getPageNumber($args);
+ if (count($args) == 0) {
+ $txt = $this->mwWorldList($sender);
+ } else {
+ $wname = implode(" ",$args);
+ $txt = $this->mwWorldDetails($sender,$wname);
+ if ($txt === NULL) {
+ $sender->sendMessage(mc::_("[MW] error examining %1%", $wname));
+ return TRUE;
+ }
+ }
+ return Pager::paginateText($sender,$pageNumber,$txt);
+ }
+ private function mwWorldList(CommandSender $sender) {
+ $dir = $this->getPlugin()->getServer()->getDataPath(). "worlds";
+ if (!is_dir($dir)) {
+ $sender->sendMessage(mc::_("[MW] Missing path %1%",$dir));
+ return NULL;
+ }
+ $txt = ["HDR"];
- private function mwWorldList(CommandSender $sender) {
- $dir = $this->owner->getServer()->getDataPath(). "worlds";
- if (!is_dir($dir)) {
- $sender->sendMessage(mc::_("[MW] Missing path %1%",$dir));
- return null;
- }
- $txt = ["HDR"];
+ $auto = $this->getPlugin()->getServer()->getProperty("worlds",[]);
+ $default = $this->getPlugin()->getServer()->getDefaultLevel();
+ if ($default) $default = $default->getName();
- $auto = $this->owner->getServer()->getProperty("worlds",[]);
- $default = $this->owner->getServer()->getDefaultLevel();
- if ($default) $default = $default->getName();
+ $count = 0;
+ $dh = opendir($dir);
+ if (!$dh) return NULL;
+ while (($file = readdir($dh)) !== FALSE) {
+ if ($file == '.' || $file == '..') continue;
+ if (!$this->getPlugin()->getServer()->isLevelGenerated($file)) continue;
+ $attrs = [];
+ ++$count;
+ if (isset($auto[$file])) $attrs[] = mc::_("auto");
+ if ($default == $file) $attrs[]=mc::_("default");
+ if ($this->getPlugin()->getServer()->isLevelLoaded($file)) {
+ $attrs[] = mc::_("loaded");
+ $np = count($this->getPlugin()->getServer()->getLevelByName($file)->getPlayers());
+ if ($np) $attrs[] = mc::_("players:%1%",$np);
+ }
+ $ln = "- $file";
+ if (count($attrs)) $ln .= TextFormat::AQUA." (".implode(",",$attrs).")";
+ $txt[] = $ln;
+ }
+ closedir($dh);
+ $txt[0] = mc::_("Worlds: %1%",$count);
+ return $txt;
+ }
+ private function mwWorldDetails(CommandSender $sender,$world) {
+ $txt = [];
+ if ($this->getPlugin()->getServer()->isLevelLoaded($world)) {
+ $unload = FALSE;
+ } else {
+ if (!$this->getPlugin()->autoLoad($sender,$world)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("Error getting %1%",$world));
+ return NULL;
+ }
+ $unload = TRUE;
+ }
+ $level = $this->getPlugin()->getServer()->getLevelByName($world);
- $count = 0;
- $dh = opendir($dir);
- if (!$dh) return null;
- while (($file = readdir($dh)) !== false) {
- if ($file == '.' || $file == '..') continue;
- if (!$this->owner->getServer()->isLevelGenerated($file)) continue;
- $attrs = [];
- ++$count;
- if (isset($auto[$file])) $attrs[] = mc::_("auto");
- if ($default == $file) $attrs[]=mc::_("default");
- if ($this->owner->getServer()->isLevelLoaded($file)) {
- $attrs[] = mc::_("loaded");
- $np = count($this->owner->getServer()->getLevelByName($file)->getPlayers());
- if ($np) $attrs[] = mc::_("players:%1%",$np);
- }
- $ln = "- $file";
- if (count($attrs)) $ln .= TextFormat::AQUA." (".implode(",",$attrs).")";
- $txt[] = $ln;
- }
- closedir($dh);
- $txt[0] = mc::_("Worlds: %1%",$count);
- return $txt;
- }
- private function mwWorldDetails(CommandSender $sender,$world) {
- $txt = [];
- if ($this->owner->getServer()->isLevelLoaded($world)) {
- $unload = false;
- } else {
- if (!$this->owner->autoLoad($sender,$world)) {
- $sender->sendMessage(TextFormat::RED.mc::_("Error getting %1%",$world));
- return null;
- }
- $unload = true;
- }
- $level = $this->owner->getServer()->getLevelByName($world);
+ //==== provider
+ $provider = $level->getProvider();
+ $txt[] = mc::_("Info for %1%",$world);
+ $txt[] = TextFormat::AQUA.mc::_("Provider: ").TextFormat::WHITE. $provider::getProviderName();
+ $txt[] = TextFormat::AQUA.mc::_("Path: ").TextFormat::WHITE.$provider->getPath();
+ $txt[] = TextFormat::AQUA.mc::_("Name: ").TextFormat::WHITE.$provider->getName();
+ $txt[] = TextFormat::AQUA.mc::_("Seed: ").TextFormat::WHITE.$provider->getSeed();
+ $txt[] = TextFormat::AQUA.mc::_("Generator: ").TextFormat::WHITE.$provider->getGenerator();
+ $gopts = $provider->getGeneratorOptions();
+ if ($gopts["preset"] != "")
+ $txt[] = TextFormat::AQUA.mc::_("Generator Presets: ").TextFormat::WHITE.$gopts["preset"];
- //==== provider
- $provider = $level->getProvider();
- $txt[] = mc::_("Info for %1%",$world);
- $txt[] = TextFormat::AQUA.mc::_("Provider: ").TextFormat::WHITE. $provider::getProviderName();
- $txt[] = TextFormat::AQUA.mc::_("Path: ").TextFormat::WHITE.$provider->getPath();
- $txt[] = TextFormat::AQUA.mc::_("Name: ").TextFormat::WHITE.$provider->getName();
- $txt[] = TextFormat::AQUA.mc::_("Seed: ").TextFormat::WHITE.$provider->getSeed();
- $txt[] = TextFormat::AQUA.mc::_("Generator: ").TextFormat::WHITE.$provider->getGenerator();
- $gopts = $provider->getGeneratorOptions();
- if ($gopts["preset"] != "")
- $txt[] = TextFormat::AQUA.mc::_("Generator Presets: ").TextFormat::WHITE.
- $gopts["preset"];
- $spawn = $provider->getSpawn();
- $txt[] = TextFormat::AQUA.mc::_("Spawn: ").TextFormat::WHITE.$spawn->getX().",".$spawn->getY().",".$spawn->getZ();
- $plst = $level->getPlayers();
- $lst = "";
- if (count($plst)) {
- foreach ($plst as $p) {
- $lst .= (strlen($lst) ? ", " : "").$p->getName();
- }
- }
- $txt[] = TextFormat::AQUA.mc::_("Players(%1%):",count($plst)).
- TextFormat::WHITE.$lst;
+ $spawn = $provider->getSpawn();
+ $txt[] = TextFormat::AQUA.mc::_("Spawn: ").TextFormat::WHITE.$spawn->getX().",".$spawn->getY().",".$spawn->getZ();
+ $plst = $level->getPlayers();
+ $lst = "";
+ if (count($plst)) {
+ foreach ($plst as $p) {
+ $lst .= (strlen($lst) ? ", " : "").$p->getName();
+ }
+ }
+ $txt[] = TextFormat::AQUA.mc::_("Players(%1%):",count($plst)).TextFormat::WHITE.$lst;
- // Check for warnings...
- if ($provider->getName() != $world) {
- $txt[] = TextFormat::RED.mc::_("Folder Name and Level.Dat names do NOT match");
- $txt[] = TextFormat::RED.mc::_("This can cause intermitent problems");
- if($sender->hasPermission("mw.cmd.lvdat")) {
- $txt[] = TextFormat::RED.mc::_("Use: ");
- $txt[] = TextFormat::GREEN.mc::_("> /mw fixname %1%",$world);
- $txt[] = TextFormat::RED.mc::_("to fix this issue");
- }
- }
+ // Check for warnings...
+ if ($provider->getName() != $world) {
+ $txt[] = TextFormat::RED.mc::_("Folder Name and Level.Dat names do NOT match");
+ $txt[] = TextFormat::RED.mc::_("This can cause intermitent problems");
+ if($sender->hasPermission("mw.cmd.lvdat")) {
+ $txt[] = TextFormat::RED.mc::_("Use: ");
+ $txt[] = TextFormat::GREEN.mc::_("> /mw fixname %1%",$world);
+ $txt[] = TextFormat::RED.mc::_("to fix this issue");
+ }
+ }
- if ($unload) $this->owner->getServer()->unloadLevel($level);
+ if ($unload) $this->getPlugin()->getServer()->unloadLevel($level);
- return $txt;
- }
+ return $txt;
+ }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- $pageNumber = $this->getPageNumber($args);
- if (count($args) == 0) {
- $txt = $this->mwWorldList($c);
- } else {
- $wname = implode(" ",$args);
- $txt = $this->mwWorldDetails($c,$wname);
- }
- if ($txt == null) return true;
- return $this->paginateText($c,$pageNumber,$txt);
- }
}
diff --git a/src/aliuly/manyworlds/MwLvDat.php b/src/aliuly/manyworlds/MwLvDat.php
index ba04f5c..3f9a8a6 100644
--- a/src/aliuly/manyworlds/MwLvDat.php
+++ b/src/aliuly/manyworlds/MwLvDat.php
@@ -1,148 +1,137 @@
_ _[attr=value]_
- **
- ** Change directly some **level.dat** values/attributes. Supported
- ** attributes:
- ** - spawn=x,y,z : Sets spawn point
- ** - seed=randomseed : seed used for terrain generation
- ** - name=string : Level name
- ** - generator=flat|normal : Terrain generator
- ** - preset=string : Presets string.
- **
- ** * fixname : fixes name mismatches
- ** usage: /mw **fixname** __
- **
- ** Fixes a world's **level.dat** file so that the name matches the
- ** folder name.
- **/
+//= cmd:lvdat
+//: Show/modify `level.dat` variables
+//> Usage: /mw **lvdat** __ _[attr=value]_
+//:
+//: Change directly some **level.dat** values/attributes. Supported
+//: attributes:
+//:
+//: - spawn=x,y,z : Sets spawn point
+//: - seed=randomseed : seed used for terrain generation
+//: - name=string : Level name
+//: - generator=flat|normal : Terrain generator
+//: - preset=string : Presets string.
+//:
+
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+use mf\common\Perms;
-use pocketmine\utils\TextFormat;
+use aliuly\manyworlds\MwSubCmd;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\BasicCli;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
+use pocketmine\utils\TextFormat;
use pocketmine\level\generator\Generator;
use pocketmine\nbt\NBT;
-//use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
+use pocketmine\math\Vector3;
+//use pocketmine\nbt\tag\IntTag;
//use pocketmine\nbt\tag\LongTag;
//use pocketmine\nbt\tag\CompoundTag;
-use pocketmine\math\Vector3;
-class MwLvDat extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("lvdat",["usage" => mc::_(" [attr=value]"),
- "help" => mc::_("Change level.dat values"),
- "permission" => "mw.cmd.lvdat",
- "aliases" => ["lv"]]);
- $this->enableSCmd("fixname",["usage" => mc::_(""),
- "help" => mc::_("Fixes world name"),
- "permission" => "mw.cmd.lvdat",
- "aliases" => ["fix"]]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) == 0) return false;
- if ($scmd == "fixname") {
- $world = implode(" ",$args);
- $c->sendMessage(TextFormat::AQUA.mc::_("Running /mw lvdat %1% name=%1%",$world));
- $args = [ $world , "name=$world" ];
- }
- $world = array_shift($args);
- if(!$this->owner->autoLoad($c,$world)) {
- $c->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded!",$world));
- return true;
- }
- $level = $this->owner->getServer()->getLevelByName($world);
- if (!$level) {
- $c->sendMessage(TextFormat::RED.mc::_("[MW] Unexpected error"));
- return true;
- }
- //==== provider
- $provider = $level->getProvider();
- $changed = false; $unload = false;
- foreach ($args as $kv) {
- $kv = explode("=",$kv,2);
- if (count($kv) != 2) {
- $c->sendMessage(mc::_("Invalid element: %1%, ignored",$kv[0]));
- continue;
- }
- list($k,$v) = $kv;
- switch (strtolower($k)) {
- case "spawn":
- $pos = explode(",",$v);
- if (count($pos)!=3) {
- $c->sendMessage(mc::_("Invalid spawn location: %1%",implode(",",$pos)));
- continue;
- }
- list($x,$y,$z) = $pos;
- $cpos = $provider->getSpawn();
- if (($x=intval($x)) == $cpos->getX() &&
- ($y=intval($y)) == $cpos->getY() &&
- ($z=intval($z)) == $cpos->getZ()) {
- $c->sendMessage(mc::_("Spawn location is unchanged"));
- continue;
- }
- $changed = true;
- $provider->setSpawn(new Vector3($x,$y,$z));
- break;
- case "seed":
- if ($provider->getSeed() == intval($v)) {
- $c->sendMessage(mc::_("Seed unchanged"));
- continue;
- }
- $changed = true; $unload = true;
- $provider->setSeed($v);
- break;
- case "name": // LevelName String
- if ($provider->getName() == $v) {
- $c->sendMessage(mc::_("Name unchanged"));
- continue;
- }
- $changed = true; $unload = true;
- $provider->getLevelData()->LevelName = new StringTag("LevelName",$v);
- break;
- case "generator": // generatorName(String)
- if ($provider->getLevelData()->generatorName == $v) {
- $c->sendMessage(mc::_("Generator unchanged"));
- continue;
- }
- $changed=true; $unload=true;
- $provider->getLevelData()->generatorName=new StringTag("generatorName",$v);
- break;
- case "preset": // StringTag("generatorOptions");
- if ($provider->getLevelData()->generatorOptions == $v) {
- $c->sendMessage(mc::_("Preset unchanged"));
- continue;
- }
- $changed=true; $unload=true;
- $provider->getLevelData()->generatorOptions =new StringTag("generatorOptions",$v);
- break;
- default:
- $c->sendMessage(mc::_("Unknown key %1%, ignored",$k));
- continue;
- }
- }
- if ($changed) {
- $c->sendMessage(mc::_("Updating level.dat for %1%",$world));
- $provider->saveLevelData();
- if ($unload) {
- $c->sendMessage(TextFormat::RED.
- mc::_("CHANGES WILL NOT TAKE EFFECT UNTIL UNLOAD"));
- }
- } else {
- $c->sendMessage(mc::_("Nothing happens"));
- }
- return true;
- }
+class MwLvDat extends MwSubCmd {
+ public function getName() { return "lvdat"; }
+ public function getAliases() { return ["lv"]; }
+ public function getHelp() { return mc::_("Change level.dat values"); }
+ public function getUsage() { return mc::_(" [attr=value]"); }
+ public function getPermission() { return "mw.cmd.lvdat"; }
+
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) == 0) return FALSE;
+ $world = array_shift($args);
+ if(!$this->getPlugin()->autoLoad($sender,$world)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded!",$world));
+ return TRUE;
+ }
+ $level = $this->getPlugin()->getServer()->getLevelByName($world);
+ if (!$level) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unexpected error"));
+ return TRUE;
+ }
+ //==== provider
+ $provider = $level->getProvider();
+ $changed = FALSE; $unload = FALSE;
+ foreach ($args as $kv) {
+ $kv = explode("=",$kv,2);
+ if (count($kv) != 2) {
+ $sender->sendMessage(mc::_("Invalid element: %1%, ignored",$kv[0]));
+ continue;
+ }
+ list($k,$v) = $kv;
+ switch (strtolower($k)) {
+ case "spawn":
+ $pos = explode(",",$v);
+ if (count($pos)!=3) {
+ $sender->sendMessage(mc::_("Invalid spawn location: %1%",implode(",",$pos)));
+ continue;
+ }
+ list($x,$y,$z) = $pos;
+ $cpos = $provider->getSpawn();
+ if (($x=intval($x)) == $cpos->getX() &&
+ ($y=intval($y)) == $cpos->getY() &&
+ ($z=intval($z)) == $cpos->getZ()) {
+ $sender->sendMessage(mc::_("Spawn location is unchanged"));
+ continue;
+ }
+ $changed = TRUE;
+ $provider->setSpawn(new Vector3($x,$y,$z));
+ break;
+ case "seed":
+ if ($provider->getSeed() == intval($v)) {
+ $sender->sendMessage(mc::_("Seed unchanged"));
+ continue;
+ }
+ $changed = TRUE; $unload = TRUE;
+ $provider->setSeed($v);
+ break;
+ case "name": // LevelName String
+ if ($provider->getName() == $v) {
+ $c->sendMessage(mc::_("Name unchanged"));
+ continue;
+ }
+ $changed = TRUE; $unload = TRUE;
+ $provider->getLevelData()->LevelName = new StringTag("LevelName",$v);
+ break;
+ case "generator": // generatorName(String)
+ if ($provider->getLevelData()->generatorName == $v) {
+ $sender->sendMessage(mc::_("Generator unchanged"));
+ continue;
+ }
+ $changed=TRUE; $unload=TRUE;
+ $provider->getLevelData()->generatorName=new StringTag("generatorName",$v);
+ break;
+ case "preset": // StringTag("generatorOptions");
+ if ($provider->getLevelData()->generatorOptions == $v) {
+ $sender->sendMessage(mc::_("Preset unchanged"));
+ continue;
+ }
+ $changed=TRUE; $unload=TRUE;
+ $provider->getLevelData()->generatorOptions =new StringTag("generatorOptions",$v);
+ break;
+ default:
+ $sender->sendMessage(mc::_("Unknown key %1%, ignored",$k));
+ continue;
+ }
+ }
+ if ($changed) {
+ $sender->sendMessage(mc::_("Updating level.dat for %1%",$world));
+ $provider->saveLevelData();
+ if ($unload) $sender->sendMessage(TextFormat::RED.mc::_("CHANGES WILL NOT TAKE EFFECT UNTIL UNLOAD"));
+ } else {
+ $sender->sendMessage(mc::_("Nothing happens"));
+ }
+
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Name: %1%", TextFormat::WHITE.$provider->getName()));
+ $sp = $provider->getSpawn();
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Spawn: %1%(%2%,%3%,%4%)",TextFormat::WHITE,$sp->getX(),$sp->getY(),$sp->getZ()));
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Generator: %1%", TextFormat::WHITE.$provider->getLevelData()->generatorName));
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Seed: %1%", TextFormat::WHITE.$provider->getSeed()));
+ $sender->sendMessage(TextFormat::AQUA.mc::_("Preset: %1%", TextFormat::WHITE.$provider->getLevelData()->generatorOptions));
+
+ return TRUE;
+ }
}
+
diff --git a/src/aliuly/manyworlds/MwSubCmd.php b/src/aliuly/manyworlds/MwSubCmd.php
new file mode 100644
index 0000000..59f07c1
--- /dev/null
+++ b/src/aliuly/manyworlds/MwSubCmd.php
@@ -0,0 +1,7 @@
+_
- **
- ** Teleports you to another world. If _player_ is specified, that
- ** player will be teleported.
- **/
+//= cmd:tp
+//: Teleport to another world
+//> Usage: /mw **tp** _[player]_ __
+//:
+//: Teleports you to another world. If _player_ is specified, that
+//: player will be teleported.
+//:
namespace aliuly\manyworlds;
-use pocketmine\command\CommandSender;
-use pocketmine\command\Command;
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
-use aliuly\manyworlds\common\mc;
-use aliuly\manyworlds\common\MPMU;
-use aliuly\manyworlds\common\BasicCli;
+class MwTp extends MwSubCmd {
+ public function getName() { return "teleport"; }
+ public function getAliases() { return ["tp"]; }
+ public function getHelp() { return mc::_("Teleport across worlds"); }
+ public function getUsage() { return mc::_("[player] "); }
+ public function getPermission() { return "mw.cmd.tp"; }
-class MwTp extends BasicCli {
- public function __construct($owner) {
- parent::__construct($owner);
- $this->enableSCmd("tp",["usage" => mc::_("[player] "),
- "help" => mc::_("Teleport across worlds"),
- "permission" => "mw.cmd.tp",
- "aliases" => ["teleport"]]);
- }
- public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
- if (count($args) == 0) return false;
- $player = $c;
- if (count($args) > 1) {
- $player = $this->owner->getServer()->getPlayer($args[0]);
- if ($player !== null) {
- if (!MPMU::access($c,"mw.cmd.tp.others")) return true;
- array_shift($args);
- } else {
- // Compatibility with old versions...
- $player = $this->owner->getServer()->getPlayer($args[count($args)-1]);
- if ($player !== null) {
- if (!MPMU::access($c,"mw.cmd.tp.others")) return true;
- array_pop($args);
- } else {
- $player = $c;
- }
- }
- }
- if (!MPMU::inGame($player)) return true;
- $wname = implode(" ",$args);
- if ($player->getLevel() == $this->owner->getServer()->getLevelByName($wname)) {
- $c->sendMessage(
- $c == $player ?
- mc::_("You are already in %1%",$wname) :
- mc::_("%1% is already in %2%",$player->getName(),$wname));
- return true;
- }
- if (!$this->owner->autoLoad($c,$wname)) {
- $c->sendMessage(TextFormat::RED.mc::_("Teleport failed"));
- return true;
- }
- $level = $this->owner->getServer()->getLevelByName($wname);
- if ($level === null) {
- $c->sendMessage(TextFormat::RED.mc::_("Error GetLevelByName %1%"));
- return true;
- }
- if ($c != $player) {
- $player->sendMessage(TextFormat::YELLOW.mc::_("Teleporting you to %1% by %2%", $wname, $c->getName()));
- } else {
- $c->sendMessage(TextFormat::GREEN.mc::_("Teleporting to %1%",$wname));
- }
- $player->teleport($level->getSafeSpawn());
- return true;
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) == 0) return FALSE;
+ $player = $sender;
+ if (count($args) > 1) {
+ $player = $this->getPlugin()->getServer()->getPlayer($args[0]);
+ if ($player !== NULL) {
+ if (!Perms::access($sender,"mw.cmd.tp.others")) return TRUE;
+ array_shift($args);
+ } else {
+ // Compatibility with old versions...
+ $player = $this->getPlugin()->getServer()->getPlayer($args[count($args)-1]);
+ if ($player !== NULL) {
+ if (!Perms::access($sender,"mw.cmd.tp.others")) return TRUE;
+ array_pop($args);
+ } else {
+ $player = $sender;
}
+ }
+ }
+ if (!Perms::inGame($player)) return TRUE;
+ $wname = implode(" ",$args);
+ if ($player->getLevel() == $this->getPlugin()->getServer()->getLevelByName($wname)) {
+ $sender->sendMessage($sender == $player ?
+ mc::_("You are already in %1%",$wname) :
+ mc::_("%1% is already in %2%",$player->getName(),$wname));
+ return TRUE;
+ }
+ if (!$this->getPlugin()->autoLoad($sender,$wname)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("Teleport failed"));
+ return TRUE;
+ }
+ $level = $this->getPlugin()->getServer()->getLevelByName($wname);
+ if ($level === NULL) {
+ $sender->sendMessage(TextFormat::RED.mc::_("Error GetLevelByName %1%",$wname));
+ return TRUE;
+ }
+ if ($sender != $player) {
+ $player->sendMessage(TextFormat::YELLOW.mc::_("Teleporting you to %1% by %2%", $wname, $sender->getName()));
+ } else {
+ $sender->sendMessage(TextFormat::GREEN.mc::_("Teleporting to %1%",$wname));
+ }
+ $player->teleport($level->getSafeSpawn());
+ return TRUE;
+ }
}
diff --git a/src/aliuly/manyworlds/MwUnload.php b/src/aliuly/manyworlds/MwUnload.php
new file mode 100644
index 0000000..932a629
--- /dev/null
+++ b/src/aliuly/manyworlds/MwUnload.php
@@ -0,0 +1,59 @@
+ Usage: /mw **unload** _[-f]_ __
+//:
+//: Unloads _world_. Use _-f_ to force unloads.
+//:
+namespace aliuly\manyworlds;
+
+use mf\common\mc;
+use mf\common\Perms;
+
+use aliuly\manyworlds\MwSubCmd;
+
+use pocketmine\command\Command;
+use pocketmine\command\CommandSender;
+use pocketmine\utils\TextFormat;
+
+class MwUnload extends MwSubCmd {
+ public function getName() { return "unload"; }
+ public function getAliases() { return []; }
+ public function getHelp() { return mc::_("Attempt to unload worlds"); }
+ public function getUsage() { return mc::_("[-f] "); }
+ public function getPermission() { return "mw.cmd.world.load"; }
+
+ public function onCommand(CommandSender $sender, Command $command, $label, array $args) {
+ if (count($args) == 0) return FALSE;
+ $force = FALSE;
+ if ($args[0] == "-f") {
+ $force = TRUE;
+ array_shift($args);
+ if (count($args) == 0) return FALSE;
+ }
+ $wname = implode(" ",$args);
+
+ if (!$this->getPlugin()->getServer()->isLevelLoaded($wname)) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] %1% is not loaded.",$wname));
+ return TRUE;
+ }
+ $level = $this->getPlugin()->getServer()->getLevelByName($wname);
+ if ($level === NULL) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to get %1%",$wname));
+ return TRUE;
+ }
+ if ($level === $this->getPlugin()->getServer()->getDefaultLevel()) {
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable unload default level %1%",$wname));
+ return TRUE;
+ }
+ if (!$this->getPlugin()->getServer()->unloadLevel($level,$force)) {
+ if ($force)
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to unload %1%",$wname));
+ else
+ $sender->sendMessage(TextFormat::RED.mc::_("[MW] Unable to unload %1%. Try -f",$wname));
+ } else {
+ $sender->sendMessage(TextFormat::GREEN.mc::_("[MW] %1% unloaded.",$wname));
+ }
+ return TRUE;
+ }
+}
diff --git a/src/aliuly/manyworlds/TeleportManager.php b/src/aliuly/manyworlds/TeleportManager.php
deleted file mode 100644
index ed721dd..0000000
--- a/src/aliuly/manyworlds/TeleportManager.php
+++ /dev/null
@@ -1,95 +0,0 @@
-owner = $plugin;
- $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner);
- }
- /**
- * @priority LOWEST
- */
- public function onDamage(EntityDamageEvent $event) {
- // Try keep the player alive while on transit...
- $victim= $event->getEntity();
- if (!($victim instanceof Player)) return;
- $vname = $victim->getName();
- if (!isset($this->teleporters[$vname])) return;
- if (time() - $this->teleporters[$vname] > 2) {
- unset($this->teleporters[$vname()]);
- return;
- }
- $victim->heal($event->getDamage());
- $event->setDamage(0);
- $event->setCancelled(true);
- }
- public function teleport($player,$level,$spawn=null) {
- //
- // This CRAZY HACK is to remove Tile entities that seem to linger
- // whenever you teleport!
- //
- $current = $player->getLevel();
- if ($current->getName() != $level) {
- foreach ($current->getTiles() as $tile) {
- $pk = new \pocketmine\network\protocol\UpdateBlockPacket();
- $pk->x = $tile->x;
- $pk->y = $tile->y;
- $pk->z = $tile->z;
- $pk->block = 0;
- $pk->meta = 0;
- $player->dataPacket($pk);
- }
- }
-
- $world = $this->owner->getServer()->getLevelByName($level);
- if (!$world) {
- $player->sendMessage("Unable to teleport to $level");
- $player->sendMessage("Level $level was not found");
- return false;
- }
- // Try to find a reasonable spawn location
- $location = $world->getSafeSpawn($spawn);
- if (!$this->owner->is15) {
- $this->teleporters[$player->getName()] = time();
- // This shouldn't be needed in PocketMine-MP v1.5...
- foreach ([5,10,20] as $ticks) {
- // Try to keep the player in place until the chunk finish loading
- $this->after("delayedTP",[$player->getName(),
- $location->getX(),$location->getY(),
- $location->getZ(),
- $location->getLevel()->getName()],$ticks);
- }
- // Make sure that any damage he may have taken is restored
- $this->after("restoreHealth",[$player->getName(),$player->getHealth()],20);
- // Make sure the player survives the transfer...
- $player->setHealth($player->getMaxHealth());
- }
- $player->teleport($location); // Start the teleport
- return true;
- }
- public function after($method,$args,$ticks) {
- $this->owner->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this,$method],$args),$ticks);
- }
- public function restoreHealth($name,$health) {
- $player = $this->owner->getServer()->getPlayer($name);
- if (!$player) return;
- $player->setHealth($health);
- }
- public function delayedTP($name,$x,$y,$z,$level) {
- $player = $this->owner->getServer()->getPlayer($name);
- if (!$player) return;
- if($player->getLevel()->getName() != $level) return;
- $player->teleport(new Vector3($x,$y,$z));
- }
-
-
-}
diff --git a/src/aliuly/manyworlds/common/BasicCli.php b/src/aliuly/manyworlds/common/BasicCli.php
deleted file mode 100644
index 2ed49c6..0000000
--- a/src/aliuly/manyworlds/common/BasicCli.php
+++ /dev/null
@@ -1,178 +0,0 @@
-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"]))
- $newCmd->setDescription($yaml["description"]);
- if (isset($yaml["usage"]))
- $newCmd->setUsage($yaml["usage"]);
- if(isset($yaml["aliases"]) and is_array($yaml["aliases"])) {
- $aliasList = [];
- foreach($yaml["aliases"] as $alias) {
- if(strpos($alias,":")!== false) {
- $this->owner->getLogger()->info("Unable to load alias $alias");
- continue;
- }
- $aliasList[] = $alias;
- }
- $newCmd->setAliases($aliasList);
- }
- if(isset($yaml["permission"]))
- $newCmd->setPermission($yaml["permission"]);
- if(isset($yaml["permission-message"]))
- $newCmd->setPermissionMessage($yaml["permission-message"]);
- $newCmd->setExecutor($this);
- $cmdMap = $this->owner->getServer()->getCommandMap();
- $cmdMap->register($this->owner->getDescription()->getName(),$newCmd);
- }
- /**
- * 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])) {
- $pageNumber = (int)array_pop($args);
- if($pageNumber <= 0) $pageNumber = 1;
- }
- 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){
- $sender->sendMessage( TextFormat::GREEN.$hdr.TextFormat::RESET);
- foreach ($txt as $ln) $sender->sendMessage($ln);
- return true;
- }
- $pageHeight = 5;
- $lineCount = count($txt);
- $pageCount = intval($lineCount/$pageHeight) + ($lineCount % $pageHeight ? 1 : 0);
- $hdr = TextFormat::GREEN.$hdr. TextFormat::RESET;
- if ($pageNumber > $pageCount) {
- $sender->sendMessage($hdr);
- $sender->sendMessage("Only $pageCount pages available");
- return true;
- }
- $hdr .= TextFormat::RED." ($pageNumber of $pageCount)";
- $sender->sendMessage($hdr);
- for ($ln = ($pageNumber-1)*$pageHeight;$ln < $lineCount && $pageHeight--;++$ln) {
- $sender->sendMessage($txt[$ln]);
- }
- 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]);
- foreach ($tab as $row) {
- for($i=0;$i < count($row);$i++) {
- if (($l=strlen($row[$i])) > $cols[$i]) $cols[$i] = $l;
- }
- }
- $txt = [];
- $fmt = "";
- foreach ($cols as $c) {
- if (strlen($fmt) > 0) $fmt .= " ";
- $fmt .= "%-".$c."s";
- }
- foreach ($tab as $row) {
- $txt[] = sprintf($fmt,...$row);
- }
- return $this->paginateText($sender,$pageNumber,$txt);
- }
-
- //////////////////////////////////////////////////////////////////////
- /**
- * 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);
- }
-}
diff --git a/src/aliuly/manyworlds/common/BasicHelp.php b/src/aliuly/manyworlds/common/BasicHelp.php
deleted file mode 100644
index 2042b49..0000000
--- a/src/aliuly/manyworlds/common/BasicHelp.php
+++ /dev/null
@@ -1,78 +0,0 @@
-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 ($cm->getUsage($scmd) === null) return false;
- $c->sendMessage(TextFormat::RED.mc::_("Usage: ").
- sprintf($this->fmt,
- $cc->getName(),
- $scmd, $cm->getUsage($scmd)));
- return true;
- }
- $txt = [ "Help for ".$cc->getName() ];
-
- foreach ($args as $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 ($cm->getHelpMsg($i) !== null)
- $txt[] = TextFormat::YELLOW.mc::_("Description: ").
- TextFormat::WHITE.$cm->getHelpMsg($i);
- if ($cm->getUsage($i) !== null)
- $txt[] = TextFormat::YELLOW.mc::_("Usage: ").
- TextFormat::WHITE.
- sprintf($this->fmt,$cc->getName(),$i,$cm->getUsage($i));
- }
- return $this->paginateText($c,$pageNumber,$txt);
- }
-
- $txt = [ mc::_("Available sub-commands for %1%",$cc->getName()) ];
- foreach ($cm->getHelp() as $cn => $desc) {
- $ln = TextFormat::GREEN.$cn;
- foreach ($cm->getAliases() as $i => $j) {
- if ($j == $cn) $ln .= "|$i";
- }
- $ln .= ": ".TextFormat::WHITE.$desc;
- $txt[] = $ln;
- }
- return $this->paginateText($c,$pageNumber,$txt);
- }
-}
diff --git a/src/aliuly/manyworlds/common/BasicPlugin.php b/src/aliuly/manyworlds/common/BasicPlugin.php
deleted file mode 100644
index 2405759..0000000
--- a/src/aliuly/manyworlds/common/BasicPlugin.php
+++ /dev/null
@@ -1,192 +0,0 @@
- $j) {
- $defaults["features"][$i] = $j[1];
- }
- $cfg=(new Config($this->getDataFolder()."config.yml",
- Config::YAML,$defaults))->getAll();
- $this->modules = [];
- foreach ($cfg["features"] as $i=>$j) {
- if (!isset($mods[$i])) {
- $this->getLogger()->info(mc::_("Unknown feature \"%1%\" ignored.",$i));
- continue;
- }
- if (!$j) continue;
- $class = $mods[$i][0];
- if (is_array($class)) {
- while (count($class) > 1) {
- // All classes before the last one are dependencies...
- $classname = $dep = array_shift($class);
- if(strpos($classname,"\\") === false) $classname = $ns."\\".$classname;
- if (isset($this->modules[$dep])) continue; // Dependancy already loaded
- if(isset($cfg[strtolower($dep)])) {
- $this->modules[$dep] = new $classname($this,$cfg[strtolower($dep)]);
- } else {
- $this->modules[$dep] = new $classname($this);
- }
- }
- // The last class in the array implements the actual feature
- $class = array_shift($class);
- }
- if(strpos($class,"\\") === false) $class = $ns."\\".$class;
- if (isset($cfg[$i]))
- $this->modules[$i] = new $class($this,$cfg[$i]);
- else
- $this->modules[$i] = new $class($this);
- }
- $c = count($this->modules);
- if ($c == 0) {
- $this->getLogger()->info(mc::_("NO features enabled"));
- return;
- }
- $this->session = null;
- $this->getLogger()->info(mc::n(mc::_("Enabled one feature"),
- mc::_("Enabled %1% features",$c),
- $c));
- if ($this->scmdMap !== null && $this->scmdMap->getCommandCount() > 0) {
- $this->modules[] = new BasicHelp($this,$xhlp);
- }
- return $cfg;
- }
- /**
- * Get module
- * @param str $module - module to retrieve
- * @return mixed|null
- */
- public function getModule($str) {
- if (isset($this->modules[$str])) return $this->modules[$str];
- return null;
- }
- /**
- * Get Modules array
- * @return array
- */
- public function getModules() {
- return $this->modules;
- }
- /**
- * Save a config section to the plugins' config.yml
- *
- * @param str $key - section to save
- * @param mixed $settings - settings to save
- */
- public function cfgSave($key,$settings) {
- $cfg=new Config($this->getDataFolder()."config.yml",Config::YAML);
- $dat = $cfg->getAll();
- $dat[$key] = $settings;
- $cfg->setAll($dat);
- $cfg->save();
- }
- /**
- * Dispatch commands using sub command table
- */
- protected function dispatchSCmd(CommandSender $sender,Command $cmd,array $args,$data=null) {
- if ($this->scmdMap === null) {
- $sender->sendMessage(mc::_("No sub-commands available"));
- return false;
- }
- return $this->scmdMap->dispatchSCmd($sender,$cmd,$args,$data);
- }
- /** Look-up sub command map
- * @returns SubCommandMap
- */
- public function getSCmdMap() {
- return $this->scmdMap;
- }
- /**
- * Register a sub command
- * @param str $cmd - sub command
- * @param callable $callable - callable to execute
- * @param array $opts - additional options
- */
- public function registerSCmd($cmd,$callable,$opts) {
- if ($this->scmdMap === null) {
- $this->scmdMap = new SubCommandMap();
- }
- $this->scmdMap->registerSCmd($cmd,$callable,$opts);
- }
- /**
- * Get a player state for the desired module/$label.
- *
- * @param str $label - state variable to get
- * @param Player|str $player - Player instance or name
- * @param mixed $default - default value to return is no state found
- * @return mixed
- */
- public function getState($label,$player,$default) {
- if ($this->session === null) return $default;
- return $this->session->getState($label,$player,$default);
- }
- /**
- * Set a player related state
- *
- * @param str $label - state variable to set
- * @param Player|str $player - player instance or their name
- * @param mixed $val - value to set
- * @return mixed
- */
- public function setState($label,$player,$val) {
- if ($this->session === null) $this->session = new Session($this);
- return $this->session->setState($label,$player,$val);
- }
- /**
- * Clears a player related state
- *
- * @param str $label - state variable to clear
- * @param Player|str $player - intance of Player or their name
- */
- public function unsetState($label,$player) {
- if ($this->session === null) return;
- $this->session->unsetState($label,$player);
- }
-
- /**
- * Gets the contents of an embedded resource on the plugin file.
- *
- * @param string $filename
- * @return string|null
- */
- public function getResourceContents($filename){
- $fp = $this->getResource($filename);
- if($fp === null){
- return null;
- }
- $contents = stream_get_contents($fp);
- fclose($fp);
- return $contents;
- }
-}
diff --git a/src/aliuly/manyworlds/common/MPMU.php b/src/aliuly/manyworlds/common/MPMU.php
deleted file mode 100644
index 97126cb..0000000
--- a/src/aliuly/manyworlds/common/MPMU.php
+++ /dev/null
@@ -1,288 +0,0 @@
-=, <=, <> or !=, =, !|~, <, >
- *
- * @param str api Installed API version
- * @param str version API version to compare against
- *
- * @return bool
- */
- static public function apiCheck($api,$version) {
- switch (substr($version,0,2)) {
- case ">=":
- return version_compare($api,trim(substr($version,2))) >= 0;
- case "<=":
- return version_compare($api,trim(substr($version,2))) <= 0;
- case "<>":
- case "!=":
- return version_compare($api,trim(substr($version,2))) != 0;
- }
- switch (substr($version,0,1)) {
- case "=":
- return version_compare($api,trim(substr($version,1))) == 0;
- case "!":
- case "~":
- return version_compare($api,trim(substr($version,1))) != 0;
- case "<":
- return version_compare($api,trim(substr($version,1))) < 0;
- case ">":
- return version_compare($api,trim(substr($version,1))) > 0;
- }
- if (intval($api) != intval($version)) return 0;
- return version_compare($api,$version) >= 0;
- }
- /**
- * Returns a localized string for the gamemode
- *
- * @param int mode
- * @return str
- */
- static public function gamemodeStr($mode) {
- if (class_exists(__NAMESPACE__."\\mc",false)) {
- switch ($mode) {
- case 0: return mc::_("Survival");
- case 1: return mc::_("Creative");
- case 2: return mc::_("Adventure");
- case 3: return mc::_("Spectator");
- }
- return mc::_("%1%-mode",$mode);
- }
- switch ($mode) {
- case 0: return "Survival";
- case 1: return "Creative";
- case 2: return "Adventure";
- case 3: return "Spectator";
- }
- return "$mode-mode";
- }
- /**
- * Check's player or sender's permissions and shows a message if appropriate
- *
- * @param CommandSender $sender
- * @param str $permission
- * @param bool $msg If false, no message is shown
- * @return bool
- */
- static public function access(CommandSender $sender, $permission,$msg=true) {
- if($sender->hasPermission($permission)) return true;
- if ($msg)
- $sender->sendMessage(mc::_("You do not have permission to do that."));
- return false;
- }
- /**
- * Check's if $sender is a player in game
- *
- * @param CommandSender $sender
- * @param bool $msg If false, no message is shown
- * @return bool
- */
- static public function inGame(CommandSender $sender,$msg = true) {
- if (!($sender instanceof Player)) {
- if ($msg) $sender->sendMessage(mc::_("You can only do this in-game"));
- return false;
- }
- return true;
- }
- /**
- * Takes a player and creates a string suitable for indexing
- *
- * @param Player|str $player - Player to index
- * @return str
- */
- static public function iName($player) {
- if ($player instanceof CommandSender) {
- $player = strtolower($player->getName());
- }
- return $player;
- }
- /**
- * Lile file_get_contents but for a Plugin resource
- *
- * @param Plugin $plugin
- * @param str $filename
- * @return str|null
- */
- static public function getResourceContents($plugin,$filename) {
- $fp = $plugin->getResource($filename);
- if($fp === null){
- return null;
- }
- $contents = stream_get_contents($fp);
- fclose($fp);
- return $contents;
- }
- /**
- * Call a plugin's function.
- *
- * If the $plug parameter is given a string, it will simply look for that
- * plugin. If an array is provided, it is assumed to be of the form:
- *
- * [ "plugin", "version" ]
- *
- * So then it will check that the plugin exists, and the version number
- * matches according to the rules from **apiCheck**.
- *
- * Also, if plugin contains an **api** property, it will use that as
- * the class for method calling instead.
- *
- * @param Server $server - pocketmine server instance
- * @param str|array $plug - plugin to call
- * @param str $method - method to call
- * @param mixed $default - If the plugin does not exist or it is not enable, this value is returned
- * @return mixed
- */
- static public function callPlugin($server,$plug,$method,$args,$default = null) {
- $v = null;
- if (is_array($plug)) list($plug,$v) = $plug;
- if (($plugin = $server->getPluginManager()->getPlugin($plug)) === null
- || !$plugin->isEnabled()) return $default;
-
- if ($v !== null && !self::apiCheck($plugin->getDescription()->getVersion(),$v)) return $default;
- if (property_exists($plugin,"api")) {
- $fn = [ $plugin->api , $method ];
- } else {
- $fn = [ $plugin, $method ];
- }
- if (!is_callable($fn)) return $default;
- return $fn(...$args);
- }
- /**
- * Register a command
- *
- * @param Plugin $plugin - plugin that "owns" the command
- * @param CommandExecutor $executor - object that will be called onCommand
- * @param str $cmd - Command name
- * @param array $yaml - Additional settings for this command.
- * @deprecated Moved to Cmd class
- */
- static public function addCommand($plugin, $executor, $cmd, $yaml) {
- $newCmd = new \pocketmine\command\PluginCommand($cmd,$plugin);
- if (isset($yaml["description"]))
- $newCmd->setDescription($yaml["description"]);
- if (isset($yaml["usage"]))
- $newCmd->setUsage($yaml["usage"]);
- if(isset($yaml["aliases"]) and is_array($yaml["aliases"])) {
- $aliasList = [];
- foreach($yaml["aliases"] as $alias) {
- if(strpos($alias,":")!== false) {
- $this->owner->getLogger()->info("Unable to load alias $alias");
- continue;
- }
- $aliasList[] = $alias;
- }
- $newCmd->setAliases($aliasList);
- }
- if(isset($yaml["permission"]))
- $newCmd->setPermission($yaml["permission"]);
- if(isset($yaml["permission-message"]))
- $newCmd->setPermissionMessage($yaml["permission-message"]);
- $newCmd->setExecutor($executor);
- $cmdMap = $plugin->getServer()->getCommandMap();
- $cmdMap->register($plugin->getDescription()->getName(),$newCmd);
- }
- /**
- * Unregisters a command
- * @param Server|Plugin $obj - Access path to server instance
- * @param str $cmd - Command name to remove
- * @deprecated Moved to Cmd class
- */
- static public function rmCommand($srv, $cmd) {
- $cmdMap = $srv->getCommandMap();
- $oldCmd = $cmdMap->getCommand($cmd);
- if ($oldCmd === null) return false;
- $oldCmd->setLabel($cmd."_disabled");
- $oldCmd->unregister($cmdMap);
- return true;
- }
- /**
- * Send a PopUp, but takes care of checking if there are some
- * plugins that might cause issues.
- *
- * Currently only supports SimpleAuth and BasicHUD.
- *
- * @param Player $player
- * @param str $msg
- */
- static public function sendPopup($player,$msg) {
- $pm = $player->getServer()->getPluginManager();
- if (($sa = $pm->getPlugin("SimpleAuth")) !== null) {
- // SimpleAuth also has a HUD when not logged in...
- if ($sa->isEnabled() && !$sa->isPlayerAuthenticated($player)) return;
- }
- if (($hud = $pm->getPlugin("BasicHUD")) !== null) {
- // Send pop-ups through BasicHUD
- $hud->sendPopup($player,$msg);
- return;
- }
- $player->sendPopup($msg);
- }
- /**
- * Check prefixes
- * @param str $txt - input text
- * @param str $tok - keyword to test
- * @return str|null
- */
- static public function startsWith($txt,$tok) {
- $ln = strlen($tok);
- if (strtolower(substr($txt,0,$ln)) != $tok) return null;
- return trim(substr($txt,$ln));
- }
- /**
- * Look-up player
- * @param CommandSender $req
- * @param str $n
- */
- static public function getPlayer(CommandSender $c,$n) {
- $pl = $c->getServer()->getPlayer($n);
- if ($pl === null) $c->sendMessage(mc::_("%1% not found", $n));
- return $pl;
- }
-
-}
diff --git a/src/aliuly/manyworlds/common/Session.php b/src/aliuly/manyworlds/common/Session.php
deleted file mode 100644
index d190fb2..0000000
--- a/src/aliuly/manyworlds/common/Session.php
+++ /dev/null
@@ -1,77 +0,0 @@
-plugin = $owner;
- $this->plugin->getServer()->getPluginManager()->registerEvents($this,$this->plugin);
- $this->state = [];
- }
- /**
- * Handle player quit events. Free's data used by the state tracking
- * code.
- *
- * @param PlayerQuitEvent $ev - Quit event
- */
- public function onPlayerQuit(PlayerQuitEvent $ev) {
- $n = MPMU::iName($ev->getPlayer());
- if (isset($this->state[$n])) unset($this->state[$n]);
- }
- /**
- * Get a player state for the desired module/$label.
- *
- * @param str $label - state variable to get
- * @param Player|str $player - Player instance or name
- * @param mixed $default - default value to return is no state found
- * @return mixed
- */
- public function getState($label,$player,$default) {
- $player = MPMU::iName($player);
- if (!isset($this->state[$player])) return $default;
- if (!isset($this->state[$player][$label])) return $default;
- return $this->state[$player][$label];
- }
- /**
- * Set a player related state
- *
- * @param str $label - state variable to set
- * @param Player|str $player - player instance or their name
- * @param mixed $val - value to set
- * @return mixed
- */
- public function setState($label,$player,$val) {
- $player = MPMU::iName($player);
- if (!isset($this->state[$player])) $this->state[$player] = [];
- $this->state[$player][$label] = $val;
- return $val;
- }
- /**
- * Clears a player related state
- *
- * @param str $label - state variable to clear
- * @param Player|str $player - intance of Player or their name
- */
- public function unsetState($label,$player) {
- $player = MPMU::iName($player);
- if (!isset($this->state[$player])) return;
- if (!isset($this->state[$player][$label])) return;
- unset($this->state[$player][$label]);
- }
-
-}
diff --git a/src/aliuly/manyworlds/common/SubCommandMap.php b/src/aliuly/manyworlds/common/SubCommandMap.php
deleted file mode 100644
index 9254e31..0000000
--- a/src/aliuly/manyworlds/common/SubCommandMap.php
+++ /dev/null
@@ -1,93 +0,0 @@
-executors = [];
- $this->help = [];
- $this->usage = [];
- $this->aliases = [];
- $this->permission = [];
- }
- /**
- * Returns the number of commands configured
- */
- public function getCommandCount() {
- return count($this->executors);
- }
- /**
- * Dispatch commands using sub command table
- */
- public function dispatchSCmd(CommandSender $sender,Command $cmd,array $args,$data=null) {
- if (count($args) == 0) {
- $sender->sendMessage(mc::_("No sub-command specified"));
- return false;
- }
- $scmd = strtolower(array_shift($args));
- if (isset($this->aliases[$scmd])) {
- $scmd = $this->aliases[$scmd];
- }
- if (!isset($this->executors[$scmd])) {
- $sender->sendMessage(mc::_("Unknown sub-command %2% (try /%1% help)",$cmd->getName(),$scmd));
- return false;
- }
- if (isset($this->permission[$scmd])) {
- if (!$sender->hasPermission($this->permission[$scmd])) {
- $sender->sendMessage(mc::_("You are not allowed to do this"));
- return true;
- }
- }
- $callback = $this->executors[$scmd];
- if ($callback($sender,$cmd,$scmd,$data,$args)) return true;
- if (isset($this->executors["help"])) {
- $callback = $this->executors["help"];
- return $callback($sender,$cmd,$scmd,$data,["usage"]);
- }
- return false;
- }
- /**
- * Register a sub command
- * @param str $cmd - sub command
- * @param callable $callable - callable to execute
- * @param array $opts - additional options
- */
- public function registerSCmd($cmd,$callable,$opts) {
- $cmd = strtolower($cmd);
- $this->executors[$cmd] = $callable;
-
- if (isset($opts["help"])) {
- $this->help[$cmd] = $opts["help"];
- ksort($this->help);
- }
- if (isset($opts["usage"])) $this->usage[$cmd] = $opts["usage"];
- if (isset($opts["permission"])) $this->permission[$cmd] = $opts["permission"];
- if (isset($opts["aliases"])) {
- foreach ($opts["aliases"] as $alias) {
- $this->aliases[$alias] = $cmd;
- }
- }
- }
-
- public function getUsage($scmd) {
- return isset($this->usage[$scmd]) ? $this->usage[$scmd] : null;
- }
- public function getAlias($scmd) {
- return isset($this->aliases[$scmd]) ? $this->aliases[$scmd] : null;
- }
- public function getHelpMsg($scmd) {
- return isset($this->help[$scmd]) ? $this->help[$scmd] : null;
- }
- public function getHelp() {
- return $this->help;
- }
- public function getAliases() {
- return $this->aliases;
- }
-}
diff --git a/src/aliuly/manyworlds/common/mc.php b/src/aliuly/manyworlds/common/mc.php
deleted file mode 100644
index 9d6f597..0000000
--- a/src/aliuly/manyworlds/common/mc.php
+++ /dev/null
@@ -1,110 +0,0 @@
-getFile());
- * * mc::_("string to translate\n")
- * * mc::_("string to translate %1% %2%\n",$arg1,$arg2)
- * * mc::n(mc::\_("singular form"),mc::\_("Plural form"),$count)
- */
-abstract class mc {
- /** @var str[] $txt Message translations */
- public static $txt = [];
- /** Main translation function
- *
- * This translates strings. The naming of "_" is to make it compatible
- * with gettext utilities. The string can contain "%1%", "%2%, etc...
- * These are inserted from the following arguments. Use "%%" to insert
- * a single "%".
- *
- * @param str[] $args - messages
- * @return str translated string
- */
- public static function _(...$args) {
- $fmt = array_shift($args);
- if (isset(self::$txt[$fmt])) $fmt = self::$txt[$fmt];
- if (count($args)) {
- $vars = [ "%%" => "%" ];
- $i = 1;
- foreach ($args as $j) {
- $vars["%$i%"] = $j;
- ++$i;
- }
- $fmt = strtr($fmt,$vars);
- }
- return $fmt;
- }
- /**
- * Plural and singular forms.
- *
- * @param str $a - Singular form
- * @param str $b - Plural form
- * @param int $c - the number to test to select between $a or $b
- * @return str - Either plural or singular forms depending on the value of $c
- */
- public static function n($a,$b,$c) {
- return $c == 1 ? $a : $b;
- }
- /**
- * Load a message file for a PocketMine plugin. Only uses .ini files.
- *
- * @param Plugin $plugin - owning plugin
- * @param str $path - output of $plugin->getFile()
- * @return int|false - false on error or the number of messages loaded
- */
- public static function plugin_init($plugin,$path) {
- if (file_exists($plugin->getDataFolder()."messages.ini")) {
- return self::load($plugin->getDataFolder()."messages.ini");
- }
- $msgs = $path."resources/messages/".
- $plugin->getServer()->getProperty("settings.language").
- ".ini";
- if (!file_exists($msgs)) return false;
- return self::load($msgs);
- }
-
- /**
- * Load the specified message catalogue.
- * Can read .ini or .po files.
- * @param str $f - Filename to load
- * @return int|false - returns the number of strings loaded or false on error
- */
- public static function load($f) {
- $potxt = "\n".file_get_contents($f)."\n";
- if (preg_match('/\nmsgid\s/',$potxt)) {
- $potxt = preg_replace('/\\\\n"\n"/',"\\n",
- preg_replace('/\s+""\s*\n\s*"/'," \"",
- $potxt));
- }
- foreach (['/\nmsgid "(.+)"\nmsgstr "(.+)"\n/',
- '/^\s*"(.+)"\s*=\s*"(.+)"\s*$/m'] as $re) {
- $c = preg_match_all($re,$potxt,$mm);
- if ($c) {
- for ($i=0;$i<$c;++$i) {
- if ($mm[2][$i] == "") continue;
- eval('$a = "'.$mm[1][$i].'";');
- eval('$b = "'.$mm[2][$i].'";');
- self::$txt[$a] = $b;
- }
- return $c;
- }
- }
- return false;
- }
-}
diff --git a/t/calls/mw1.pms b/t/calls/mw1.pms
new file mode 100644
index 0000000..40bd91a
--- /dev/null
+++ b/t/calls/mw1.pms
@@ -0,0 +1,48 @@
+#
+# Test aliases
+#
+mw generators
+manyworlds genls
+mw gen
+#
+# test create world
+#
+mw create testworld1
+mw create testworld2 100
+mw create testworld3 4 flat
+mw create tst_hell1 940305 hell
+
+#
+# List worlds...
+#
+mw ls
+mw ls tst_hell1
+mw ls testworld3
+
+#
+# Change default
+#
+mw default tst_hell1
+mw ls
+mw default world
+mw ls
+
+#
+# Load unload
+#
+mw unload testworld3
+mw ls
+mw load testworld3
+mw ls
+
+#
+# Level data editing
+#
+mw lvdat testworld3
+mw unload testworld3
+mw lvdat testworld3 spawn=20,20,20 name=my_good_name seed=9849 generator=normal
+mw ls testworld3
+
+mw fixname testworld3
+mw ls testworld3
+
diff --git a/t/calls/perms.pms b/t/calls/perms.pms
new file mode 100644
index 0000000..bc92f62
--- /dev/null
+++ b/t/calls/perms.pms
@@ -0,0 +1,26 @@
+@ $sp = new \specter\api\DummyPlayer('player1')
+@ $op = new \specter\api\DummyPlayer('sysop1')
+
+mw create tst_pworld 4 flat
+
+@ $sp->getPlayer()->setOp(FALSE)
+@ $op->getPlayer()->setOp(TRUE)
+
+@ $i = 0
+@ foreach ([$sp,$op] as $pl):
+
+ @ ++$i;
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw genls")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw create tst_w$i 1 flat")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw lvdat tst_pworld")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw lvdat tst_pworld spawn=$i,$i,$i")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw unload tst_pworld")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw load tst_pworld")
+
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw default tst_pworld")
+ @ $server->dispatchCommand( $pl->getPlayer(),"mw default world")
+
+@ endforeach
+
+@ $sp->close()
+@ $op->close()
diff --git a/t/calls/tps.pms b/t/calls/tps.pms
new file mode 100644
index 0000000..b88cc14
--- /dev/null
+++ b/t/calls/tps.pms
@@ -0,0 +1,21 @@
+@ $sp = new \specter\api\DummyPlayer('playertp')
+@ $op = new \specter\api\DummyPlayer('sysoptp')
+@ $sp->getPlayer()->setOp(FALSE)
+@ $op->getPlayer()->setOp(TRUE)
+
+mw create tst_tpw1 4 flat
+mw create tst_tpw2 4 flat
+mw create tst_tpw3 4 flat
+
+mw tp playertp tst_tpw1
+mw tp sysoptp tst_tpw1
+mw tp tst_tpw1
+
+@ $server->dispatchCommand( $op->getPlayer(),"mw tp tst_tpw2")
+@ $server->dispatchCommand( $op->getPlayer(),"mw tp playertp tst_tpw2")
+
+@ $server->dispatchCommand( $sp->getPlayer(),"mw tp tst_tpw3")
+@ $server->dispatchCommand( $sp->getPlayer(),"mw tp sysoptp tst_tpw3")
+
+@ $sp->close()
+@ $op->close()
diff --git a/t/calls/worlds.sh b/t/calls/worlds.sh
new file mode 100755
index 0000000..670f0d5
--- /dev/null
+++ b/t/calls/worlds.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+phars="modular modcmd subcmd"
+
+pre() {
+ rm -rf $MPDIR/worlds/t*
+}
+
+post() {
+ rm -rf $MPDIR/worlds/t*
+}
+
+case "$1" in
+ pre)
+ pre "$@"
+ ;;
+ post)
+ post "$@"
+ ;;
+esac
+
\ No newline at end of file
diff --git a/t/unload/mw1.pms b/t/unload/mw1.pms
new file mode 100644
index 0000000..302cdcb
--- /dev/null
+++ b/t/unload/mw1.pms
@@ -0,0 +1,4 @@
+#
+# Test aliases
+#
+mw unload world
diff --git a/test b/test
new file mode 100755
index 0000000..2ca97a1
--- /dev/null
+++ b/test
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+. "$(dirname "$(readlink -f "$0")")/libcommon/utils/init.sh"
+. $utlib/pm.sh
+. $utlib/unitest.sh
+
+trap 'exit $retcode' EXIT
+
+[ ! -f plugin.yml ] && fatal "No plugin.yml"
+[ -f README.md ] && $gd3tool gen -w src
+
+if [ -d resource/messages ] ; then
+ $mcgen gen resources/messages src $([ -d libcommon/src ] && echo libcommon/src)
+ $mcgen enc resources/messages
+fi
+$mkver src
+
+phplint src || fatal "Failed lint"
+
+install_pocketmine
+testgroup="$(default_tests t "$@")"
+[ -z "$testgroup" ] && exit
+
+#
+# Lite version test...
+#
+rm -f $MPDIR/plugins/*.phar
+pm_plugins
+$mkplugin -o $MPDIR/plugins libcommon/
+$mkpp -o $MPDIR/plugins -L .
+runtests $testgroup
+
+rm -f $MPDIR/plugins/*.phar
+pm_plugins
+$mkplugin -o $MPDIR/plugins libcommon/
+$mkpp -o $MPDIR/plugins -F . \
+ --ysed=s/^depend:.*// \
+ -l libcommon/src:mf/common=aliuly/mw/common
+runtests $testgroup
+
+show_results