Skip to content
This repository was archived by the owner on Jan 9, 2018. It is now read-only.

Commit 6883902

Browse files
committed
v1.3.0, added /checkperm
1 parent d60f7a1 commit 6883902

3 files changed

Lines changed: 60 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
## Usage
1010
* _/makeplugin <pluginName>_: Creates a Phar plugin archive for its distribution
11-
* _/makeserver_: Creates a PocketMine-MP Phar archive
11+
* _/makeserver_: Creates a PocketMine-MP Phar archive
12+
* _/checkperm <node> [playerName]_: Checks a permission node

plugin.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: DevTools
22
main: DevTools\DevTools
3-
version: 1.2.0
3+
version: 1.3.0
44
api: [1.0.0]
55
load: STARTUP
66
author: PocketMine Team
@@ -16,18 +16,29 @@ commands:
1616
description: Creates a Phar plugin from a unarchived one
1717
usage: "/makeplugin <pluginName>"
1818
permission: devtools.command.makeplugin
19+
checkperm:
20+
description: Checks a permission value for the current sender, or a player
21+
usage: "/checkperm <node> [playerName]"
22+
permission: devtools.command.checkperm
1923
permissions:
2024
devtools:
2125
default: op
2226
description: "Allows using all the DevTools things"
23-
childs:
27+
children:
2428
devtools.command:
2529
default: op
2630
description: "Allows using all the DevTools commands"
27-
childs:
31+
children:
2832
devtools.command.makeplugin:
2933
default: op
3034
description: "Allows the creation of Phar plugins"
3135
devtools.command.makeserver:
3236
default: op
33-
description: "Allows the creation of a PocketMine-MP Phar"
37+
description: "Allows the creation of a PocketMine-MP Phar"
38+
devtools.command.checkperm:
39+
default: true
40+
description: "Allows checking a permission value"
41+
children:
42+
devtools.command.checkperm.other:
43+
default: op
44+
description: "Allows checking others permission value"

src/DevTools/DevTools.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use pocketmine\command\Command;
66
use pocketmine\command\CommandSender;
77
use pocketmine\network\protocol\Info;
8+
use pocketmine\permission\Permission;
9+
use pocketmine\Player;
810
use pocketmine\plugin\FolderPluginLoader;
911
use pocketmine\plugin\Plugin;
1012
use pocketmine\plugin\PluginBase;
@@ -24,11 +26,52 @@ public function onCommand(CommandSender $sender, Command $command, $label, array
2426
case "makeserver":
2527
return $this->makeServerCommand($sender, $command, $label, $args);
2628
break;
29+
case "checkperm":
30+
return $this->permissionCheckCommand($sender, $command, $label, $args);
31+
break;
2732
default:
2833
return false;
2934
}
3035
}
3136

37+
private function permissionCheckCommand(CommandSender $sender, Command $command, $label, array $args){
38+
$target = $sender;
39+
if(!isset($args[0])){
40+
return false;
41+
}
42+
$node = strtolower($args[0]);
43+
if(isset($args[1])){
44+
if(($player = Player::get($args[1])) instanceof Player){
45+
$target = $player;
46+
}else{
47+
return false;
48+
}
49+
}
50+
51+
if($target !== $sender and !$sender->hasPermission("devtools.command.checkperm.other")){
52+
$sender->sendMessage(TextFormat::RED . "You do not have permissions to check other players.");
53+
return true;
54+
}else{
55+
$sender->sendMessage(TextFormat::GREEN . "---- ".TextFormat::WHITE . "Permission node ".$node.TextFormat::GREEN. " ----");
56+
$perm = $this->getServer()->getPluginManager()->getPermission($node);
57+
if($perm instanceof Permission){
58+
$desc = TextFormat::GOLD . "Description: ".TextFormat::WHITE . $perm->getDescription()."\n";
59+
$desc .= TextFormat::GOLD . "Default: ".TextFormat::WHITE . $perm->getDefault()."\n";
60+
$children = "";
61+
foreach($perm->getChildren() as $name => $true){
62+
$children .= $name . ", ";
63+
}
64+
$desc .= TextFormat::GOLD . "Children: ".TextFormat::WHITE . substr($children, 0, -2)."\n";
65+
}else{
66+
$desc = TextFormat::RED . "Permission does not exist\n";
67+
$desc .= TextFormat::GOLD . "Default: ".TextFormat::WHITE . Permission::$DEFAULT_PERMISSION."\n";
68+
}
69+
$sender->sendMessage($desc);
70+
$sender->sendMessage(TextFormat::YELLOW . $target->getName() . TextFormat::WHITE . " has it set to ".($target->hasPermission($node) === true ? TextFormat::GREEN . "true" : TextFormat::RED . "false"));
71+
return true;
72+
}
73+
}
74+
3275
private function makePluginCommand(CommandSender $sender, Command $command, $label, array $args){
3376
$pluginName = trim(implode(" ", $args));
3477
if($pluginName === "" or !(($plugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName)) instanceof Plugin)){

0 commit comments

Comments
 (0)