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

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Nov 8, 2016
1 parent ae92bc0 commit 913d08b
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 58 deletions.
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@

* Summary: protect worlds from griefers, pvp, limits and borders
* Dependency Plugins: n/a
* PocketMine-MP version: 1.4 - API 1.10.0
* PocketMine-MP version: 1.4 (API:1.10.0), 1.5 (API:1.12.0)
* OptionalPlugins: n/a
* Categories: World Editing and Management, Admin Tools
* Plugin Access: Commands, Data Saving, World Editing, Manages Worlds
* WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/WorldProtect)
* WebSite: https://github.com/alejandroliu/pocketmine-plugins/tree/master/WorldProtect

## Overview

<!-- php: $v_forum_thread = "http://forums.pocketmine.net/threads/worldprotect.7517/"; -->
<!-- template: prologue.md -->

**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
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/worldprotect.7517/) for
that. You are more likely to get a response and help that way.

**NOTE:**

This documentation was last updated for version **2.1.0**.

Please go to
[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/WorldProtect)
for the most up-to-date documentation.

You can also download this plugin from this [page](https://github.com/alejandroliu/pocketmine-plugins/releases/tag/WorldProtect-2.1.0).

<!-- template-end -->

A full featured World protection plugin.

Features:
Expand Down Expand Up @@ -201,7 +212,7 @@ inventory.

### Configuration

Configuration is throug the `config.yml` file.
Configuration is through the `config.yml` file.
The following sections are defined:

#### features
Expand Down Expand Up @@ -269,9 +280,24 @@ languages currently available are:

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/WorldProtect/resources/messages/)
[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/WorldProtect)
for sample files.

# API

There is a minimal API to determine the max number of players per world:

```PHP
$this->getServer()->getPluginManager()->getPlugin("WorldProtect")->getMaxPlayers($world);
```

Where:

* $this - plugin pointer
* $world - either a world name or an instance of Level.

Returns an integer or null.

# FAQ

* Q: How do I keep my inventory so that it does not get clear when I
Expand All @@ -280,6 +306,8 @@ for sample files.

# Changes

* 2.1.0: API
* Added API to determine max players
* 2.0.3: Minor bug fix
* Fixed bug: Configuration is not applied when reloading
* 2.0.2: Feature request
Expand Down
5 changes: 3 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
main: aliuly\worldprotect\Main
api: [1.10.0]
api: [1.10.0,1.12.0]
load: STARTUP

name: WorldProtect
description: protect worlds from griefers, pvp, limits and borders
version: 2.0.3
version: 2.1.0
author: aliuly
website: https://github.com/alejandroliu/pocketmine-plugins/tree/master/WorldProtect

commands:
worldprotect:
Expand Down
3 changes: 2 additions & 1 deletion resources/messages/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Details for %1%"=""
"Disable explosions in world or spawn area"=""
"Edits world motd text"=""
"Enable %1% features"=""
"Enabled %1% features"=""
"Enabled one feature"=""
"Error loading level %1%"=""
"Explosion was stopped in %1%"=""
Expand Down Expand Up @@ -135,4 +135,5 @@
"spawn-off"=""
"ubab:"=""
"world"=""
"#Enable %1% features"=""
"#Usage: /%%s [world] %%s %%s"=""
3 changes: 2 additions & 1 deletion resources/messages/spa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Details for %1%"="Detalles para %1%"
"Disable explosions in world or spawn area"="Desactiva explosiones en mundo ó zona de aparición"
"Edits world motd text"="Edita el texto de bienvenida a mundo"
"Enable %1% features"="%1% módulos activados"
"Enabled %1% features"=""
"Enabled one feature"="Activando un módulo"
"Error loading level %1%"="Error cargando nivel %1%"
"Explosion was stopped in %1%"="Explosión fue detenida en %1%"
Expand Down Expand Up @@ -135,4 +135,5 @@
"spawn-off"="no en punto de aparición"
"ubab:"="irrompible:"
"world"="mundo"
"#Enable %1% features"="%1% módulos activados"
"#Usage: /%%s [world] %%s %%s"="Uso: /%%s [world] %%s %%s"
12 changes: 10 additions & 2 deletions src/aliuly/worldprotect/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function onEnable() {
"no-explode" => [ "NoExplodeMgr", false ],
"unbreakable" => [ "Unbreakable", false ],
"banitem" => [ "BanItem", true ],
"gamemode" => [ "GmMgr", true ],
"gm-save-inv" => [ "GmSaveInv", true ],
"gamemode" => [ "GmMgr", false ],
"gm-save-inv" => [ "GmSaveInv", false ],
], [
"version" => $this->getDescription()->getVersion(),
"motd" => WpMotdMgr::defaults(),
Expand Down Expand Up @@ -268,4 +268,12 @@ public function msg($pl,$txt) {
$this->setState("spam",$pl,[time(),$txt]);
$pl->sendMessage($txt);
}
/**
* @API
*/
public function getMaxPlayers($world){
if (isset($this->modules["max-players"]))
return $this->modules["max-players"]->getMaxPlayers($world);
return null;
}
}
6 changes: 5 additions & 1 deletion src/aliuly/worldprotect/MaxPlayerMgr.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\Player;
use aliuly\worldprotect\common\mc;
use pocketmine\level\Level;

class MaxPlayerMgr extends BaseWp implements Listener {
public function __construct(Plugin $plugin) {
Expand All @@ -32,7 +33,10 @@ public function __construct(Plugin $plugin) {
"permission" => "wp.cmd.limit",
"aliases" => ["limit"]]);
}

public function getMaxPlayers($world) {
if ($world instanceof Level) $world = $world->getName();
return $this->getCfg($world,null);
}
public function onSCommand(CommandSender $c,Command $cc,$scmd,$world,array $args) {
if ($scmd != "max") return false;
if (count($args) == 0) {
Expand Down
71 changes: 68 additions & 3 deletions src/aliuly/worldprotect/common/BasicCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@

use pocketmine\utils\TextFormat;

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

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

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

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

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

0 comments on commit 913d08b

Please sign in to comment.