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

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Nov 8, 2016
1 parent 6882f1a commit 3688bd6
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 5 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Features:
* Create limits in your limitless worlds
* Limit the number of players in a world
* Show a text file when players enter a world
* Stops explosions from happening in a world

Basic Usage:

Expand All @@ -29,6 +30,7 @@ Basic Usage:
* /wp lock [level]
* /wp protect [level]
* /wp pvp [level] [on|off]
* /wp noexplode [level] [off|world|spawn]
* /wp border [level] [x1 z1 x2 z2|none]
* /wp max [level] [count]
* /wp add [level] *player*
Expand Down Expand Up @@ -89,6 +91,14 @@ Per-world PvP:
If nothing is specified it will show the PvP status of the current
level. Otherwise PvP will either be activated|de-activated.

No Explode:

* /wp noexplode [level] [off|world|spawn]
If nothing is specified it will show the NoExplode status of the current
level. If off, allows explosions (default). If world, explosions are
prevented in the whole world. If spawn, explosions are prevented in
the spawn area.

World borders:

* wp border [level] [x1 z1 x2 z2|none]
Expand Down Expand Up @@ -123,11 +133,13 @@ In the plugin's config.yml file you can have:
world-protect: true
per-world-pvp: true
motd: true
no-explode: true

* player-limits: Enables the per world player limits
* world-borders: Enables the world border module
* world-protect: Enables the anti-griefing module
* per-world-pvp: Enables per world PvP functionality
* no-explode: Enables explosion protection
* motd : Enable per world MOTD text

### Permission Nodes:
Expand All @@ -140,6 +152,7 @@ In the plugin's config.yml file you can have:
* wp.cmd.pvp - Allow PvP controls
* wp.cmd.limit - Allow control to limit functionality
* wp.cmd.wpmotd - Allow editing the motd
* wp.cmd.noexplode - no explode command access

### ManyWorlds

Expand All @@ -150,16 +163,23 @@ Also, if ManyWorlds is installed, the

Will show additional information.

Issues
------
### Issues

* World names can not contain spaces.
* Placing a sign on worlds that do not allow placing blocks will crash
the MCPE client.

### TODO

* Prevent PvP in spawn. pvp spawn


Changes
-------

* 1.1.0: no-explode
* Added NoExplode functionality
* Fixed stupid typo about /mw subcommands
* 1.0.0 : Initial release

Copyright
Expand Down
5 changes: 4 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ softdepend: [ManyWorlds]

name: WorldProtect
description: protect worlds from griefers, pvp, limits and borders
version: 1.0.0
version: 1.1.0
author: aliuly

commands:
Expand Down Expand Up @@ -38,6 +38,9 @@ permissions:
wp.cmd.pvp:
default: op
description: "Allow PvP controls"
wp.cmd.noexplode:
default: op
description: "Allow NoExplode controls"
wp.cmd.limit:
default: op
description: "Allow control to limit functionality"
Expand Down
92 changes: 90 additions & 2 deletions src/aliuly/worldprotect/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use pocketmine\Player;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Config;

use pocketmine\math\Vector3;

class Main extends PluginBase implements CommandExecutor {
const MIN_BORDER = 32;
Expand All @@ -21,6 +21,7 @@ class Main extends PluginBase implements CommandExecutor {
static private $aliases = [
"unprotect" => "unlock",
"open" => "unlock",
"notnt" => "noexplode",
];

// Access and other permission related checks
Expand All @@ -43,6 +44,7 @@ public function onEnable(){
"world-protect" => true,
"per-world-pvp" => true,
"motd" => true,
"no-explode" => true,
],
];
@mkdir($this->getDataFolder());
Expand All @@ -66,6 +68,9 @@ public function onEnable(){
$this->listeners["borders"] = new WpBordersMgr($this);
if ($cfg["settings"]["per-world-pvp"])
$this->listeners["pvp"] = new WpPvpMgr($this);
if ($cfg["settings"]["no-explode"])
$this->listeners["no-explode"] = new NoExplodeMgr($this);

$this->settings = $cfg["settings"];

$this->wcfg = [];
Expand Down Expand Up @@ -142,6 +147,20 @@ public function checkBlockPlaceBreak($pname,$level) {
return false;
}
//
// No explode callback
//
public function checkNoExplode($x,$y,$z,$level) {
if (!isset($this->wcfg[$level]["no-explode"])) return true;
if ($this->wcfg[$level]["no-explode"] == "world") return false;
if ($this->wcfg[$level]["no-explode"] != "spawn") return true;
$lv = $this->getServer()->getLevelByName($level);
if (!$lv) return true;
$sp = $lv->getSpawnLocation();
$dist = $sp->distance(new Vector3($x,$y,$z));
if ($dist < $this->getServer()->getSpawnRadius()) return false;
return true;
}
//
// PvP callback
//
public function checkPvP($level) {
Expand Down Expand Up @@ -207,6 +226,10 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
if (!$this->access($sender,"wp.cmd.protect")) return false;
if (!$this->settings["world-protect"]) return false;
return $this->worldProtectMode($sender,$scmd,$args);
case "noexplode":
if (!$this->access($sender,"wp.cmd.noexplode")) return false;
if (!$this->settings["no-explode"]) return false;
return $this->worldNoExplodeMode($sender,$args);
case "pvp":
if (!$this->access($sender,"wp.cmd.pvp")) return false;
if (!$this->settings["per-world-pvp"]) return false;
Expand Down Expand Up @@ -256,6 +279,8 @@ private function helpCmd(CommandSender $sender,$args) {
"lock"=>["[level]","Locked. Nobody (including op) can build"],
"protect"=>["[level]","Only authorized people can build"],
"pvp"=>["[level] [on|off]","Enable|disable pvp"],
"noexplode" =>["[level] [off|world|spawn]",
"Stop explosions in world or spawn area"],
"border" => ["[level] [x1 z1 x2 z2|none]",
"Creates a border in [level] defined by x1,z1 to x2,z2"],
"max" => ["[level] [value]",
Expand All @@ -275,7 +300,7 @@ private function helpCmd(CommandSender $sender,$args) {
}
$sender->sendMessage("WorldProtect sub-commands");
foreach ($cmds as $a => $b) {
$ln = "- ".TextFormat::GREEN."/mw ".$a;
$ln = "- ".TextFormat::GREEN."/wp ".$a;
foreach (self::$aliases as $i => $j) {
if ($j == $a) $ln .= "|$i";
}
Expand Down Expand Up @@ -407,6 +432,60 @@ private function worldProtectMode(CommandSender $sender,$mode,$args) {
$this->getServer()->broadcastMessage("[WP] World $level protection mode changed to $mode");
return true;
}
// No Explode controls
private function worldNoExplodeMode(CommandSender $sender,$args) {
if (count($args) == 0) {
if (!$this->inGame($sender)) return true;
$level = $sender->getLevel()->getName();
$mode = "show";
} elseif (count($args) == 1) {
if (in_array(strtolower($args[0]),["off","world","spawn"])) {
if (!$this->inGame($sender)) return true;
$mode = strtolower($args[0]);
$level = $sender->getLevel()->getName();
} else {
$mode = "show";
$level = $args[0];
}
} elseif (count($args) == 2) {
list($level,$mode) = $args;
$mode = strtolower($mode);
} else {
return $this->helpCmd($sender,["noexplode"]);
}
if (!$this->doLoadWorldConfig($sender,$level)) return true;
if ($mode == "show") {
$m = "NoExplode status for $level is ";
if (!isset($this->wcfg[$level]["no-explode"])) {
$m .= TextFormat::RED."OFF".TextFormat::RESET." (explosions allowed)";
} elseif ($this->wcfg[$level]["no-explode"] == "world") {
$m .= TextFormat::GREEN."world";
} elseif ($this->wcfg[$level]["no-explode"] == "spawn") {
$m .= TextFormat::YELLOW."spawn";
} else {
$m .= TextFormat::RED."Unknown".TextFormat::RESET.
" (explosions allowed)";
}
$sender->sendMessage($m);
return true;
}
if (!$this->isAuth($sender,$level)) return true;
if ($mode == "off") {
if (!isset($this->wcfg[$level]["no-explode"])) {
$sender->sendMessage("no-explode status unchanged");
return;
}
unset($this->wcfg[$level]["no-explode"]);
} elseif ($mode == "world" || $mode == "spawn") {
$this->wcfg[$level]["no-explode"] = $mode;
} else {
$this->sendMessage("Invalid no-explode mode $mode");
return;
}
$this->saveWorldConfig($level);
$this->getServer()->broadcastMessage("[WP] World $level no-explode changed to $mode");
return true;
}
// pvp mode
private function worldPvpMode(CommandSender $sender,$args) {
if (count($args) == 0) {
Expand Down Expand Up @@ -622,6 +701,15 @@ public function getWorldInfo($level) {
} else {
$txt[] = "PvP: ".TextFormat::GREEN."OFF";
}
if (isset($this->wcfg[$level]["no-explode"])) {
if ($this->wcfg[$level]["no-explode"] == "world") {
$txt[] = "NoExplode: ".TextFormat::GREEN."world";
} elseif ($this->wcfg[$level]["no-explode"] == "spawn") {
$txt[] = "NoExplode: ".TextFormat::YELLOW."spawn";
} else {
$txt[]= "NoExplode: ".TextFormat::RED.$this->wcfg[$level]["no-explode"];
}
}
if (isset($this->wcfg[$level]["border"])) {
$txt[] = "World Borders:".implode(",",$this->wcfg[$level]["border"]);
}
Expand Down
24 changes: 24 additions & 0 deletions src/aliuly/worldprotect/NoExplodeMgr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace aliuly\worldprotect;

use pocketmine\plugin\PluginBase as Plugin;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityExplodeEvent;
use pocketmine\utils\TextFormat;

class NoExplodeMgr implements Listener {
public $owner;
public function __construct(Plugin $plugin) {
$this->owner = $plugin;
$this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner);
}
public function onExplode(EntityExplodeEvent $ev){
//echo __METHOD__.",".__LINE__."\n";
$et = $ev->getEntity();
if ($this->owner->checkNoExplode($et->getX(),$et->getY(),$et->getZ(),
$et->getLevel()->getName())) return;
$ev->setCancelled();
$this->owner->getLogger()->info(TextFormat::RED.
"Explosion was stopped in ".$et->getLevel()->getName());
}
}

0 comments on commit 3688bd6

Please sign in to comment.