Need a hand with Vault

Discussion in 'Plugin Development' started by HeadGam3z, Jul 31, 2014.

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

    HeadGam3z

    I'm trying to move a player to the group "Builder" via Vault if they aren't already in that group, but I cannot seem to get it to work. Does anyone have any experience with Vault? I'm puzzled.

    Code:java
    1. package com.gmail.mcheadgam3z.commands;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8.  
    9. import com.gmail.mcheadgam3z.misc.Handler;
    10.  
    11. public class Builder implements CommandExecutor {
    12.  
    13. Handler h = new Handler();
    14.  
    15. @SuppressWarnings("deprecation")
    16. public boolean onCommand(CommandSender cs, Command c, String s, String[] a) {
    17. if (c.getName().equalsIgnoreCase("builder")) {
    18. if (cs instanceof Player) {
    19. Player p = (Player) cs;
    20. if (p.hasPermission("builder.cmd")) {
    21. if (a.length == 1) {
    22. Player target = Bukkit.getServer().getPlayer(a[0]);
    23. if (target.hasPlayedBefore()) {
    24. if (!(h.perms.playerInGroup(target, "Builder"))) {
    25. h.perms.playerAddGroup(target, "Builder");
    26. p.sendMessage("yey");
    27. return true;
    28. }
    29. return false;
    30. // already in group.
    31. }
    32. // never joined the server
    33. return false;
    34. }
    35. // invalid syntax
    36. return false;
    37. }
    38. // no perms
    39. return false;
    40. }
    41. // not a player
    42. return false;
    43. }
    44. return false;
    45. }
    46.  
    47. /*private String getString(String s) {
    48.   return Main.plugin.getConfig().getString(s);
    49.   }*/
    50.  
    51. }
    52.  


    Oh, and here's the stack trace:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'builder' in plugin Builder v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) ~[bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    Caused by: java.lang.NullPointerException
        at com.gmail.mcheadgam3z.commands.Builder.onCommand(Builder.java:24) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[bukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
        ... 13 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    TheMcScavenger

    You're getting an NPE at line 24, no idea why. Not experienced with Vault & Permissions.
     
  3. Offline

    Necrodoom

  4. Offline

    HeadGam3z

  5. Offline

    Necrodoom

    HeadGam3z perms is null, because you create a new handler instance, which did not have setupPlugin() called.

    Did you want to pass the one from main class instead?
     
  6. Offline

    HeadGam3z

    Necrodoom
    I just noticed that it was null as I was posting it, haha. And yeah, I was gonna pass the one from the main class, but I need to read up on how to do that efficiently.

    Also, I rearranged a few things and did some debug messages.
    Code:
    Code:java
    1. package com.gmail.mcheadgam3z.builder;
    2.  
    3. import net.milkbowl.vault.permission.Permission;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.Plugin;
    10. import org.bukkit.plugin.RegisteredServiceProvider;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin {
    14.  
    15. public static Plugin plugin;
    16.  
    17. public Permission perms = null;
    18.  
    19. private boolean setupPermissions() {
    20. RegisteredServiceProvider<Permission> rsp = Main.plugin.getServer().getServicesManager().getRegistration(Permission.class);
    21. perms = rsp.getProvider();
    22. return perms != null;
    23. }
    24.  
    25. public void onEnable() {
    26. plugin = this;
    27. setupPermissions();
    28. }
    29.  
    30. @SuppressWarnings("deprecation")
    31. public boolean onCommand(CommandSender cs, Command c, String s, String[] a) {
    32. if (c.getName().equalsIgnoreCase("builder")) {
    33. if (cs instanceof Player) {
    34. d("2");
    35. Player p = (Player) cs;
    36. if (p.hasPermission("builder.cmd")) {
    37. d("3");
    38. if (a.length == 1) {
    39. d("4");
    40. Player target = Bukkit.getServer().getPlayer(a[0]);
    41. if (target.hasPlayedBefore()) {
    42. d("5");
    43. if (!(perms.playerInGroup(target, "Builder"))) {
    44. d("6");
    45. perms.playerAddGroup(target, "Builder");
    46. d("7");
    47. p.sendMessage("yey");
    48. return true;
    49. }
    50. d("-6");
    51. return false;
    52. // already in group.
    53. }
    54. d("-5");
    55. // never joined the server
    56. return false;
    57. }
    58. d("-4");
    59. // invalid syntax
    60. return false;
    61. }
    62. d("-3");
    63. // no perms
    64. return false;
    65. }
    66. d("-2");
    67. // not a player
    68. return false;
    69. }
    70. return false;
    71. }
    72.  
    73. private void d(String s) {
    74. System.out.println(s);
    75. }
    76.  
    77. }
    78.  

    The numbers 2-5 are printing, which is good, but then I got -6 to paste, which isn't good because I am not in the group "Builder". Any suggestions?
     
  7. Offline

    Necrodoom

    HeadGam3z seems to venture to vault API territory, but try list permission plugin and make sure you are really not in builder group.
     
  8. Offline

    HeadGam3z

    Necrodoom
    Already have. In no way am I in builder, unfortunately.
     
Thread Status:
Not open for further replies.

Share This Page