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(p.hasPermission("cmd.adddev")){

    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("sb.dev", 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(PluginCommand.java:46) ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand(PlayerConnection.java:1349) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1184) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
    at java.util.concurrent.FutureTask.run(Unknown 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(MinecraftServer.java:726) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot.jar:git-Spigot-8a048fe-a022dd2]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    at org.bukkit.permissions.PermissibleBase.addAttachment(PermissibleBase.java:116) ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity.addAttachment(CraftHumanEntity.java:121) ~[spigot.jar:git-Spigot-8a048fe-a022dd2]
    at de.erebos.Commands.addDev.onCommand(addDev.java:33) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[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.hasPermision(permname)){
    DOSTUFF();

    }
    //If player does not have perm
    else{
    DoSTUff():
    }
     
  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 {
        camelCase();
    }
     
    • 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.