Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JavaPlugin {
- Logger pluginLogger = Bukkit.getLogger();
- @Override
- public void onEnable() {
- pluginLogger.info("[TestPerms] Loading config file...");
- loadConfig();
- pluginLogger.info("[TestPerms] Config file loaded!");
- pluginLogger.info("[TestPerms] TestPerms enabled.");
- }
- @Override
- public void onDisable() {
- pluginLogger.info("[TestPerms] Saving config file...");
- saveConfig();
- pluginLogger.info("[TestPerms] Config file saved!");
- pluginLogger.info("[TestPerms] TestPerms disabled.");
- }
- public void loadConfig() {
- getConfig().options().copyDefaults(true);
- saveConfig();
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(cmd.getName().equalsIgnoreCase("testperms")) {
- if(sender instanceof Player) {
- Player p = (Player) sender;
- if(args.length == 0) {
- p.sendMessage(ChatColor.GOLD + "[TestPerms] TestPerms by X21_Eagle_X21. Try using "
- + "\"/testperms help\" for information on how to use the commands.");
- return true;
- } else if(args.length == 1) {
- if(args[0].equalsIgnoreCase("reset")) {
- if(p.hasPermission("testperms.reset")) {
- List<String> resetTo = getConfig().getStringList("players." + p.getUniqueId() + ".actualgroups");
- if(resetTo.isEmpty()) {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command "
- + "testperms: groups could not be reset as no groups are listed "
- + "in the configuration file!");
- return true;
- }
- getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent set " + resetTo.get(0));
- if(resetTo.size() > 1) {
- for(int i = 1; i < resetTo.size(); i++) {
- getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent add " + resetTo.get(i));
- }
- }
- p.sendMessage(ChatColor.GREEN + "[TestPerms] Group(s) reset successfully!");
- return true;
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "you don't have the required permission(s) to execute this command!");
- return true;
- }
- } else if(args[0].equalsIgnoreCase("help")) {
- if(p.hasPermission("testperms.help")) {
- p.sendMessage(ChatColor.GOLD + "[TestPerms] You can test a group\'s permissions"
- + " using the \"/testperms test [group]\" command. To get your "
- + "actual permissions back, use the \"/testperms reset\" command. Make sure "
- + "to set your actual groups before using these commands with the \"/testperms "
- + "setactual\" command! You may list as many groups as you want as arguments for "
- + "the setactual and test commands. Note that the first group listed will be the primary "
- + "group.");
- return true;
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "you don't have the required permission(s) to execute this command!");
- return true;
- }
- } else if(args[0].equalsIgnoreCase("test") || args[0].equalsIgnoreCase("setactual")) {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "you must specify a group!");
- return false;
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "invalid argument(s)!");
- return false;
- }
- } else {
- if(args[0].equalsIgnoreCase("test")) {
- if(p.hasPermission("testperms.test")) {
- ArrayList<String> testGroups = new ArrayList<String>();
- for(int i = 1; i < args.length; i++) {
- testGroups.add(args[i]);
- }
- getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent set " + testGroups.get(0));
- if(testGroups.size() > 1) {
- for(int i = 1; i < testGroups.size(); i++) {
- getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent add " + testGroups.get(i));
- }
- }
- getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " permission set testperms.* true");
- p.sendMessage(ChatColor.GREEN + "[TestPerms] Test mode enabled successfully! "
- + "Note that all TestPerms commands are still available in test mode "
- + "regardless of group permissions.");
- return true;
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "you don't have the required permission(s) to execute this command!");
- return true;
- }
- } else if(args[0].equalsIgnoreCase("setactual")) {
- if(p.hasPermission("testperms.setactual")) {
- ArrayList<String> actualGroups = new ArrayList<String>();
- for(int i = 1; i < args.length; i++) {
- actualGroups.add(args[i]);
- }
- getConfig().set("players." + p.getUniqueId() + ".actualgroups", actualGroups);
- p.sendMessage(ChatColor.GREEN + "[TestPerms] Actual groups set!");
- return true;
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "you don't have the required permission(s) to execute this command!");
- return true;
- }
- } else {
- p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "invalid argument(s)!");
- return false;
- }
- }
- } else {
- sender.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
- + "command sender must be a player!");
- return true;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement