added permission support for commands

This commit is contained in:
2018-09-05 18:26:21 +02:00
parent 8795e6d9cc
commit 91460c8367
3 changed files with 29 additions and 2 deletions

View File

@ -54,5 +54,9 @@ public class MarwCore extends JavaPlugin {
public Feature getFeature(String name) {
return this.features.get(name);
}
public String getPermissionPath() {
return "marw.core";
}
}

View File

@ -5,11 +5,13 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import cz.marwland.mc.core.MarwCore;
import net.md_5.bungee.api.ChatColor;
public abstract class Feature implements Listener {
protected final MarwCore plugin;
@ -20,6 +22,9 @@ public abstract class Feature implements Listener {
public Feature(MarwCore plugin, String name) {
this.plugin = plugin;
this.name = name;
if (name == null) {
this.name = this.getClass().getSimpleName().toLowerCase();
}
Method commandMap;
try {
commandMap = plugin.getServer().getClass().getMethod("getCommandMap");
@ -27,7 +32,6 @@ public abstract class Feature implements Listener {
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
public void onEnable() {
@ -74,4 +78,15 @@ public abstract class Feature implements Listener {
return plugin.getConfigManager().getConfig(path);
}
public String getPermissionPath() {
return plugin.getPermissionPath() + "." + this.getName();
}
public boolean permissionMissingCheck(CommandSender sender, String permission) {
if (sender.hasPermission(permission))
return true;
sender.sendMessage(ChatColor.RED + "You don't have permission " + ChatColor.YELLOW + permission + ChatColor.RED + "!");
return false;
}
}