Issue with adding permission with Ingame Command

Discussion in 'Spigot Plugin Development' started by Erebos, May 23, 2016.

Thread Status:
Not open for further replies.
  1. I got a Problem, i wrote a code that should add Permission to the target Player to Promote his In Game Rank.
    For Example to Developer or Admin.

    I used this Post to help me out but i still get Errors.

    public class addDev implements CommandExecutor{

    HashMap<UUID, PermissionAttachment> perms = new HashMap<UUID, PermissionAttachment>();
    Main m;
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args){
    if(cs instanceof ConsoleCommandSender){
    cs.sendMessage("§cDu musst ein Spieler sein!");
    return true;
    Player p = (Player) cs;

    if(args.length == 1){

    Player target = Bukkit.getServer().getPlayer(args[0]);
    PermissionAttachment attachment = target.addAttachment(m);
    perms.put(target.getUniqueId(), attachment);
    PermissionAttachment pperms = perms.get(target.getUniqueId());
    pperms.setPermission("", true);

    } else {
    p.sendMessage("§c/adddev <Player>");

    } else {
    p.sendMessage("§cAccess Denied!");
    return false;


    [21:08:14 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'adddev' in plugin StaffChat v1.0
    at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.command.SimpleCommandMap.dispatch( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnection.a( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PacketPlayInChat.a( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PacketPlayInChat.a( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$ [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at java.util.concurrent.Executors$ Source) [?:1.8.0_91]
    at Source) [?:1.8.0_91]
    at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.D( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.DedicatedServer.D( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.C( [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at Source) [?:1.8.0_91]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    at org.bukkit.permissions.PermissibleBase.addAttachment( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity.addAttachment( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at de.erebos.Commands.addDev.onCommand( ~[?:?]
    at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    ... 15 more
  2. Use pastebin or the code tag on here when postin gcode, so it keeps the indents because thats just aids to read.
  3. Code (Text):
    Permissions permname = new Permissions("your.perm")
    Code (Text):

    //If player does not have perm
  4. In the tutorial you specifically linked, it shows you that you require an instance of your Plugin, so Bukkit knows who is registering the permission. You need to pass that along. It seems you don't have a great knowledge of Java, you should really go back to the books.

    What the hell is this? Did you even read the thread?
    That is some really bad code.
    Code (Text):
    if(player.hasPermission("permission.perm")) {
        // do
    } else {
    • Useful Useful x 1
  5. My code is bad! it works.
  6. PermissionAttachment attachment = player.addAttachment(/* class that extends JavaPlugin here */);

    I die this, i importet my Main Class and defined it as 'm'

    PermissionAttachment attachment = target.addAttachment(m);
  7. Well I dont know maybe there is a easier way to add Players Permission with a Command like /Pex User Player1 add sb.admin just with the difference that i only want to type in the Player Name and Set the permission in the Code.
  8. Push. I still need help :(
  9. K got it. Im dumb xD
Thread Status:
Not open for further replies.