From 3688bd6eaa8f7c46ffee01fac65fdc6c890ecbb8 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Tue, 8 Nov 2016 06:35:53 +0100 Subject: [PATCH] 1.1.0 --- README.md | 24 ++++++- plugin.yml | 5 +- src/aliuly/worldprotect/Main.php | 92 +++++++++++++++++++++++- src/aliuly/worldprotect/NoExplodeMgr.php | 24 +++++++ 4 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 src/aliuly/worldprotect/NoExplodeMgr.php diff --git a/README.md b/README.md index a844441..d55bba9 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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* @@ -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] @@ -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: @@ -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 @@ -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 diff --git a/plugin.yml b/plugin.yml index e3e1d45..c8e1eaa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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: @@ -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" diff --git a/src/aliuly/worldprotect/Main.php b/src/aliuly/worldprotect/Main.php index 7cc52fb..45c5d6e 100644 --- a/src/aliuly/worldprotect/Main.php +++ b/src/aliuly/worldprotect/Main.php @@ -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; @@ -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 @@ -43,6 +44,7 @@ public function onEnable(){ "world-protect" => true, "per-world-pvp" => true, "motd" => true, + "no-explode" => true, ], ]; @mkdir($this->getDataFolder()); @@ -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 = []; @@ -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) { @@ -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; @@ -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]", @@ -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"; } @@ -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) { @@ -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"]); } diff --git a/src/aliuly/worldprotect/NoExplodeMgr.php b/src/aliuly/worldprotect/NoExplodeMgr.php new file mode 100644 index 0000000..e33defc --- /dev/null +++ b/src/aliuly/worldprotect/NoExplodeMgr.php @@ -0,0 +1,24 @@ +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()); + } +}