change permission group

Discussion in 'Plugin Development' started by ruwen, Feb 17, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    ruwen

    I wonder how I can make it, so people can change permission group on speciel commands.
    eg.
    /mycommandtojoingroup all it need to do, is the same as /pex user myname group add specielgroup.
    Any suggestion on how to do it?
     
  2. Offline

    Bisa

    I guess you could send a console command, I'm unable to give you any specific code suggestions but there is a ConsoleCommandSender, might have something to do with invoking commands as if they were sent by the console. As such you could grab the name of the player typing your command and translate it using for example (Player) sender.getName() and send the longer version as a console command?

    Or there might be a way for one plugin to invoke methods on other plugins I guess.

    I suspect that I might not have given you any direct help, but perhaps this gave you an idea of what you could do and allows you to continue your search more effectively =)
     
  3. Offline

    Father Of Time

    I was wondering about this myself awhile ago, something to knock my staff down to player level to help with complaints of staff killing players during pvp, but I digress... I decided to reverse engineer this a little bit to see if we can make any progress. First I decided to see if permissionsbukkit had commands to add and remove people from groups, because if they have commands to handle this it's likely that their API supports external support for this.

    Sure enough permissions bukkit has commands for adding and removing players from groups:

    Which lead me to the PermissionsBukkit source code for these commands:

    Code:
    else if (subcommand.equals("addgroup")) {
                if (!checkPerm(sender, "player.addgroup")) return true;
                if (split.length != 4) return usage(sender, command, "player addgroup");
                String player = split[2].toLowerCase();
                String group = split[3];
                
                if (plugin.getNode("users." + player) == null) {
                    createPlayerNode(player);
                }
                
                List<String> list = plugin.getNode("users." + player).getStringList("groups", new ArrayList<String>());
                if (list.contains(group)) {
                    sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " was already in " + ChatColor.WHITE + group + ChatColor.GREEN + ".");
                    return true;
                }
                list.add(group);
                plugin.getNode("users." + player).setProperty("groups", list);
                
                plugin.refreshPermissions();
                
                sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is now in " + ChatColor.WHITE + group + ChatColor.GREEN + ".");
                return true;
            } else if (subcommand.equals("removegroup")) {
                if (!checkPerm(sender, "player.removegroup")) return true;
                if (split.length != 4) return usage(sender, command, "player removegroup");
                String player = split[2].toLowerCase();
                String group = split[3];
                
                if (plugin.getNode("users." + player) == null) {
                    createPlayerNode(player);
                }
                
                List<String> list = plugin.getNode("users." + player).getStringList("groups", new ArrayList<String>());
                if (!list.contains(group)) {
                    sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " was not in " + ChatColor.WHITE + group + ChatColor.GREEN + ".");
                    return true;
                }
                list.remove(group);
                plugin.getNode("users." + player).setProperty("groups", list);
                
                plugin.refreshPermissions();
                
                sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is no longer in " + ChatColor.WHITE + group + ChatColor.GREEN + ".");
                return true;
            }
    
    I've not had a chance to read through this code at all, so it may or may not be able to help you; but I figured I would post what I have found this far so that you can work at your own pace and not be reliant on what I find.

    Good luck, I hope this helps!
     
Thread Status:
Not open for further replies.

Share This Page