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

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Nov 8, 2016
1 parent 5e32dce commit ae92bc0
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ If `true` the feature is enabled. if `false` the feature is disabled.
#### motd

* ticks: line delay when showing multi-line motd texts.
* auto-motd: Automatically shows motd when entering world


### Permission Nodes
Expand Down Expand Up @@ -279,6 +280,11 @@ for sample files.

# Changes

* 2.0.3: Minor bug fix
* Fixed bug: Configuration is not applied when reloading
* 2.0.2: Feature request
* Feature Request(@Nifo2000): Option to control if MOTD is shown
automatically
* 2.0.1: critical bug fix
* Fixed a crash
* Can now add to auth list when players are off-line
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load: STARTUP

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

commands:
Expand Down
4 changes: 4 additions & 0 deletions src/aliuly/worldprotect/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function onEnable() {
"motd" => WpMotdMgr::defaults(),
],mc::_("/%s [world] %s %s"));
$this->modules[] = new WpList($this);
// Make sure that loaded worlds are inded loaded...
foreach ($this->getServer()->getLevels() as $lv) {
$this->loadCfg($lv);
}
}

//////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions src/aliuly/worldprotect/WpMotdMgr.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@

class WpMotdMgr extends BaseWp implements Listener, CommandExecutor {
protected $ticks;
protected $auto;

static public function defaults() {
return [
"# ticks" => "line delay when showing multi-line motd texts.",
"ticks" => 15,
"# auto-motd" => "Automatically shows motd when entering world",
"auto-motd" => true,
];
}
public function __construct(Plugin $plugin,$cfg) {
parent::__construct($plugin);
$this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner);
$this->ticks = $cfg["ticks"];
$this->auto = $cfg["auto-motd"];
$this->enableSCmd("motd",["usage" => mc::_("[text]"),
"help" => mc::_("Edits world motd text"),
"permission" => "wp.cmd.wpmotd"]);
Expand Down Expand Up @@ -124,10 +128,12 @@ private function showMotd($c,$world) {
}

public function onJoin(PlayerJoinEvent $ev) {
if (!$this->auto) return;
$pl = $ev->getPlayer();
$this->showMotd($pl,$pl->getLevel()->getName());
}
public function onLevelChange(EntityLevelChangeEvent $ev) {
if (!$this->auto) return;
$pl = $ev->getEntity();
if (!($pl instanceof Player)) return;
$level = $ev->getTarget()->getName();
Expand Down
17 changes: 16 additions & 1 deletion src/aliuly/worldprotect/common/BasicPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,20 @@ public function unsetState($label,$player) {
unset($this->state[$player][$label]);
}


/**
* Gets the contents of an embedded resource on the plugin file.
*
* @param string $filename
*
* @return string, or null
*/
public function getResourceContents($filename){
$fp = $this->getResource($filename);
if($fp === null){
return null;
}
$contents = stream_get_contents($fp);
fclose($fp);
return $contents;
}
}
120 changes: 117 additions & 3 deletions src/aliuly/worldprotect/common/MPMU.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,47 @@
use pocketmine\command\CommandSender;
use pocketmine\Player;

/**
* My PocketMine Utils class
*/
abstract class MPMU {
// My PocketMine Utils
static protected $items = [];
const VERSION = "0.0.1";
const VERSION = "0.0.2";

/**
* libcommon library version. If a version is provided it will check
* the version using apiCheck.
*
* @param str version Version to check
*
* @return str|bool
*/
static public function version($version = "") {
if ($version == "") return self::VERSION;
return self::apiCheck(self::VERSION,$version);
}
/**
* Used to check the PocketMine API version
*
* @param str version Version to check
*
* @return str|bool
*/
static public function apiVersion($version = "") {
if ($version == "") return \pocketmine\API_VERSION;
return self::apiCheck(\pocketmine\API_VERSION,$version);
}
/**
* Checks API compatibility from $api against $version. $version is a
* string containing the version. It can contain the following operators:
*
* >=, <=, <> 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 ">=":
Expand All @@ -43,6 +71,13 @@ static public function apiCheck($api,$version) {
if (intval($api) != intval($version)) return 0;
return version_compare($api,$version) >= 0;
}
/**
* Given an pocketmine\item\Item object, it returns a friendly name
* for it.
*
* @param Item item
* @return str
*/
static public function itemName(Item $item) {
$n = $item->getName();
if ($n != "Unknown") return $n;
Expand All @@ -58,6 +93,12 @@ static public function itemName(Item $item) {
return self::$items[$item->getId()];
return $n;
}
/**
* 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) {
Expand All @@ -76,13 +117,27 @@ static public function gamemodeStr($mode) {
}
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"));
Expand All @@ -96,4 +151,63 @@ static public function iName($player) {
}
return $player;
}
static public function getResourceContents($plugin,$filename) {
$fp = $plugin->getResource($filename);
if($fp === null){
return null;
}
$contents = stream_get_contents($fp);
fclose($fp);
return $contents;
}

static public function callPlugin($server,$plug,$method,$args,$default = null) {
if (($plugin = $server->getPluginManager()->getPlugin($plug)) !== null
&& $plugin->isEnabled()) {
$fn = [ $plugin, $method ];
return $fn(...$args);
}
return $default;
}
static public function addCommand($plugin, $executor, $cmd, $yaml) {
$newCmd = new 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);
}

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);
}


}

0 comments on commit ae92bc0

Please sign in to comment.