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

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Dec 5, 2016
1 parent b2e9a28 commit 73ab0a5
Show file tree
Hide file tree
Showing 50 changed files with 3,744 additions and 2,235 deletions.
615 changes: 367 additions & 248 deletions README.md

Large diffs are not rendered by default.

55 changes: 41 additions & 14 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
main: grabbag\Main
main: aliuly\grabbag\Main
api: 1.10.0
load: POSTWORLD

name: GrabBag
description: Collection of miscellaneous commands and listener modules
version: 1.4.1
version: 2.0.1
author: aliuly

permissions:
gb.module.repeater:
default: true
description: "Access to repeater module"
gb.cmd.players:
default: true
description: "allow players command"
Expand Down Expand Up @@ -53,15 +56,6 @@ permissions:
gb.cmd.get:
default: op
description: "Get blocks"
gb.spawnarmor.receive:
default: true
description: "allows to receive armor when you spawn"
gb.spawnitems.receive:
default: true
description: "allows to receive items when you spawn"
gb.compasstp.allow:
default: op
description: "Allow players to use Compass to Teleport"
gb.cmd.shield:
default: op
description: "Allow players to become invulnerable"
Expand Down Expand Up @@ -92,12 +86,45 @@ permissions:
gb.cmd.rpt.read:
default: op
description: "Read reported issues"
gb.ubab.override:
default: false
description: "Blocks that can not be broken"
gb.cmd.summon:
default: op
description: "Summon|Dismiss command"
gb.cmd.pushpoptp:
default: op
description: "push/pop teleport"
gb.cmd.prefix:
default: true
description: "Allow the use of /prefix"
gb.cmd.spawn:
default: op
description: "Allow to teleport to spawn"
gb.cmd.burn:
default: op
description: "Allow the use of burn command"
gb.cmd.throw:
default: op
description: "Allow to throw players up in the air"
gb.cmd.blowup:
default: op
description: "Allow to blow-up players"
gb.cmd.setarmor:
default: op
description: "Allow you to set your armor"
gb.cmd.setarmor.others:
default: op
description: "Allow you to set others armor"
gb.cmd.spectator:
default: op
description: "Turn players into spectators"
gb.cmd.follow:
default: op
description: "Let players can follow others"
gb.cmd.followme:
default: op
description: "Make players follow you"
gb.cmd.rcon:
default: op
description: "use RCON client"
gb.cmd.rcon.config:
default: op
description: "Modify the RCON configuration"
134 changes: 0 additions & 134 deletions resources/modules.yml

This file was deleted.

169 changes: 169 additions & 0 deletions src/aliuly/grabbag/BaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
namespace aliuly\grabbag;

use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\command\PluginCommand;
use pocketmine\utils\Config;

use pocketmine\utils\TextFormat;
use pocketmine\Player;
use pocketmine\item\Item;

abstract class BaseCommand implements CommandExecutor {
protected $owner;

public function __construct($owner) {
$this->owner = $owner;
}

static $items = [];

public function itemName(Item $item) {
if (count(self::$items) == 0) {
$constants = array_keys((new \ReflectionClass("pocketmine\\item\\Item"))->getConstants());
foreach ($constants as $constant) {
$id = constant("pocketmine\\item\\Item::$constant");
$constant = str_replace("_", " ", $constant);
self::$items[$id] = $constant;
}
}
$n = $item->getName();
if ($n != "Unknown") return $n;
if (isset(self::$items[$item->getId()]))
return self::$items[$item->getId()];
return $n;
}

public function mwteleport($pl,$pos) {
if (($pos instanceof Position) &&
($mw = $this->owner->getServer()->getPluginManager()->getPlugin("ManyWorlds")) != null) {
// Using ManyWorlds for teleporting...
$mw->mwtp($pl,$pos);
} else {
$pl->teleport($pos);
}
}

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

public function inGame(CommandSender $sender,$msg = true) {
if (!($sender instanceof Player)) {
if ($msg) $sender->sendMessage("You can only do this in-game");
return false;
}
return true;
}

// Access and other permission related checks
protected function access(CommandSender $sender, $permission) {
if($sender->hasPermission($permission)) return true;
$sender->sendMessage("You do not have permission to do that.");
return false;
}

public function iName($player) {
if ($player instanceof Player) {
$player = strtolower($player->getName());
}
return $player;
}

public function getState(CommandSender $player,$default) {
return $this->owner->getState(get_class($this),$player,$default);
}
public function setState(CommandSender $player,$val) {
$this->owner->setState(get_class($this),$player,$val);
}
public function unsetState(CommandSender $player) {
$this->owner->unsetState(get_class($this),$player);
}

// Paginate output
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;
}
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;
}
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);
}

protected function cfgSave($key,$settings) {
$cfg=new Config($this->owner->getDataFolder()."config.yml",Config::YAML);
$dat = $cfg->getAll();
$dat[$key] = $settings;
$cfg->setAll($dat);
$cfg->save();
}

//public function onCommand(CommandSender $sender,Command $command,$label, array $args);
}
Loading

0 comments on commit 73ab0a5

Please sign in to comment.