Now one won't see subcmds they don't have access to
This commit is contained in:
parent
1e4c0df93d
commit
773bb66808
3 changed files with 36 additions and 4 deletions
10
pom.xml
10
pom.xml
|
@ -75,6 +75,10 @@
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io/</url>
|
<url>https://jitpack.io/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>vault-repo</id>
|
||||||
|
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -100,6 +104,12 @@
|
||||||
<artifactId>Towny</artifactId>
|
<artifactId>Towny</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>master-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>master-SNAPSHOT</version> <!-- 1.6 -->
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<organization>
|
<organization>
|
||||||
<name>TBMCPlugins</name>
|
<name>TBMCPlugins</name>
|
||||||
|
|
|
@ -5,13 +5,16 @@ import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.TBMCPlayer;
|
import buttondevteam.lib.TBMCPlayer;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
public class MainPlugin extends JavaPlugin {
|
public class MainPlugin extends JavaPlugin {
|
||||||
public static MainPlugin Instance;
|
public static MainPlugin Instance;
|
||||||
|
public static Permission permission;
|
||||||
|
|
||||||
private PluginDescriptionFile pdfFile;
|
private PluginDescriptionFile pdfFile;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
@ -22,7 +25,7 @@ public class MainPlugin extends JavaPlugin {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
pdfFile = getDescription();
|
pdfFile = getDescription();
|
||||||
logger = getLogger();
|
logger = getLogger();
|
||||||
|
setupPermissions();
|
||||||
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
|
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||||
}
|
}
|
||||||
|
@ -35,4 +38,13 @@ public class MainPlugin extends JavaPlugin {
|
||||||
}
|
}
|
||||||
logger.info("Player data saved.");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.reflections.scanners.SubTypesScanner;
|
import org.reflections.scanners.SubTypesScanner;
|
||||||
import org.reflections.util.ClasspathHelper;
|
import org.reflections.util.ClasspathHelper;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
|
import buttondevteam.core.MainPlugin;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
|
||||||
|
@ -30,10 +32,12 @@ public class TBMCChatAPI {
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command
|
||||||
* The command which we want the subcommands of
|
* The command which we want the subcommands of
|
||||||
|
* @param sender
|
||||||
|
* The sender for permissions
|
||||||
* @return The subcommands
|
* @return The subcommands
|
||||||
*/
|
*/
|
||||||
public static String[] GetSubCommands(TBMCCommandBase command) {
|
public static String[] GetSubCommands(TBMCCommandBase command, CommandSender sender) {
|
||||||
return GetSubCommands(command.GetCommandPath());
|
return GetSubCommands(command.GetCommandPath(), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,9 +45,11 @@ public class TBMCChatAPI {
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command
|
||||||
* The command which we want the subcommands of
|
* The command which we want the subcommands of
|
||||||
|
* @param sender
|
||||||
|
* The sender for permissions
|
||||||
* @return The subcommands
|
* @return The subcommands
|
||||||
*/
|
*/
|
||||||
public static String[] GetSubCommands(String command) {
|
public static String[] GetSubCommands(String command, CommandSender sender) {
|
||||||
ArrayList<String> cmds = new ArrayList<String>();
|
ArrayList<String> cmds = new ArrayList<String>();
|
||||||
cmds.add("§6---- Subcommands ----");
|
cmds.add("§6---- Subcommands ----");
|
||||||
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
|
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
|
||||||
|
@ -51,6 +57,10 @@ public class TBMCChatAPI {
|
||||||
int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2);
|
int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2);
|
||||||
if (ind >= 0)
|
if (ind >= 0)
|
||||||
continue;
|
continue;
|
||||||
|
if (cmd.GetPlayerOnly() && !(sender instanceof Player))
|
||||||
|
continue;
|
||||||
|
if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin"))
|
||||||
|
continue;
|
||||||
cmds.add("/" + cmd.GetCommandPath());
|
cmds.add("/" + cmd.GetCommandPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue