Now one won't see subcmds they don't have access to

This commit is contained in:
Norbi Peti 2016-12-04 19:17:14 +01:00
parent 1e4c0df93d
commit 773bb66808
3 changed files with 36 additions and 4 deletions

10
pom.xml
View file

@ -75,6 +75,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
@ -100,6 +104,12 @@
<artifactId>Towny</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
<artifactId>VaultAPI</artifactId>
<version>master-SNAPSHOT</version> <!-- 1.6 -->
<scope>provided</scope>
</dependency>
</dependencies>
<organization>
<name>TBMCPlugins</name>

View file

@ -5,13 +5,16 @@ import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCPlayer;
import net.milkbowl.vault.permission.Permission;
public class MainPlugin extends JavaPlugin {
public static MainPlugin Instance;
public static Permission permission;
private PluginDescriptionFile pdfFile;
private Logger logger;
@ -22,7 +25,7 @@ public class MainPlugin extends JavaPlugin {
Instance = this;
pdfFile = getDescription();
logger = getLogger();
setupPermissions();
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
}
@ -35,4 +38,13 @@ public class MainPlugin extends JavaPlugin {
}
logger.info("Player data saved.");
}
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
.getRegistration(Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
}

View file

@ -8,12 +8,14 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import buttondevteam.core.MainPlugin;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
@ -30,10 +32,12 @@ public class TBMCChatAPI {
*
* @param command
* The command which we want the subcommands of
* @param sender
* The sender for permissions
* @return The subcommands
*/
public static String[] GetSubCommands(TBMCCommandBase command) {
return GetSubCommands(command.GetCommandPath());
public static String[] GetSubCommands(TBMCCommandBase command, CommandSender sender) {
return GetSubCommands(command.GetCommandPath(), sender);
}
/**
@ -41,9 +45,11 @@ public class TBMCChatAPI {
*
* @param command
* The command which we want the subcommands of
* @param sender
* The sender for permissions
* @return The subcommands
*/
public static String[] GetSubCommands(String command) {
public static String[] GetSubCommands(String command, CommandSender sender) {
ArrayList<String> cmds = new ArrayList<String>();
cmds.add("§6---- Subcommands ----");
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
@ -51,6 +57,10 @@ public class TBMCChatAPI {
int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2);
if (ind >= 0)
continue;
if (cmd.GetPlayerOnly() && !(sender instanceof Player))
continue;
if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin"))
continue;
cmds.add("/" + cmd.GetCommandPath());
}
}