Command not registering

Discussion in 'Plugin Development' started by Skify, Sep 4, 2015.

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

    SuperSniper

    1. forgot the "{" at the end
    2. you forgot the "." before the "build", so that would just search for this:
    playerbuild: true/false

    do this:
    Code:
    if (plugin.getConfig().getBoolean(event.getPlayer().getName() + ".build")) {
    
    EDIT: it was caused by NullPointerException because of #2, you forgot the "." so it would search for something inside the config that's not there
     
  2. Offline

    Skify

    @SuperSniper

    Code:
    06.09 19:56:37 [Server] INFO ... 15 more06.09 19:56:37 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:37 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]06.09 19:56:37 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]06.09 19:56:37 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]06.09 19:56:37 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]06.09 19:56:37 [Server] INFO at me.shuma.main.commands.build.breakBlockEvent(build.java:72) ~[?:?]06.09 19:56:37 [Server] INFO Caused by: java.lang.NullPointerException06.09 19:56:37 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(PacketPlayInBlockDig.java:65) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(PacketPlayInBlockDig.java:41) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:552) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:164) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:264) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.8-old.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]06.09 19:56:36 [Server] INFO org.bukkit.event.EventException06.09 19:56:36 [Server] ERROR Could not pass event BlockBreakEvent to ShumaAPI v1.0
     
  3. Offline

    stormneo7

    Nothing to do with your command.

    Edit: Sorry didn't scroll.
    If it's throwing a NullPointerException, that means that that subsection does not exist.
    Make sure that there's a value at evt.getPlayer().getName() + ".build" prior to getting the boolean.
    You can do a null check with config.containsSection(path) or.contains(path) [can't remember which one].
     
  4. Offline

    Skify

    Sorry, not solved yet.

    Code:
      togglebuild:
        description: Toggles build mode.
        aliases: [buildtoggle]
        permission: shuma.build
    
    Code:java
    1.  
    2. getCommand("togglebuild").setExecutor(newbuild());
    3.  


    Code:java
    1.  
    2. package me.shuma.main.commands;
    3.  
    4.  
    5. import me.shuma.main.core;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandExecutor;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.BlockBreakEvent;
    15. import org.bukkit.event.block.BlockPlaceEvent;
    16. import org.bukkit.event.player.PlayerLoginEvent;
    17. import org.bukkit.plugin.Plugin;
    18.  
    19. public class build implements CommandExecutor, Listener{
    20.  
    21. private static String prefix = "§8[§eBuild§8] §f";
    22. private core plugin;
    23.  
    24. @Override
    25. public boolean onCommand(CommandSender sender, Command cmd, String label,
    26. String[] args) {
    27. if ((sender instanceof Player)) {
    28. Player p = (Player) sender;
    29. if(cmd.getName().equalsIgnoreCase("togglebuild")) {
    30. if(p.hasPermission("shuma.build")) {
    31. if(plugin.getConfig().getBoolean(p.getName() + ".build")) {
    32. p.sendMessage(prefix + "Building privilege: Enabled");
    33. plugin.getConfig().set(p.getName() + ".build", Boolean.FALSE);
    34. plugin.saveConfig();
    35. } else {
    36. p.sendMessage(prefix + "Building privilege: Disabled");
    37. plugin.getConfig().set(p.getName() + ".build", Boolean.TRUE);
    38. plugin.saveConfig();
    39. }
    40. } else {
    41. p.sendMessage(prefix + "You do not have permission to use /togglebuild");
    42. }
    43. }
    44. }
    45. return false;
    46. }
    47.  
    48. @EventHandler
    49. public void onLogin(final PlayerLoginEvent event) {
    50. if (event.getPlayer().isOp())
    51. Bukkit.getServer().getScheduler()
    52. .runTaskLater((Plugin) this, new Runnable() {
    53. public void run() {
    54. event.getPlayer().sendMessage(
    55. prefix + "Build toggle has been disabled.");
    56. build.this.plugin.getConfig().set(event.getPlayer().getName() + " build", Boolean.valueOf(false));
    57. build.this.plugin.saveConfig();
    58. }
    59. }, 40L);
    60. }
    61.  
    62. @EventHandler
    63. public void breakBlockEvent(BlockBreakEvent event) {
    64. if (plugin.getConfig().getBoolean(event.getPlayer().getName() + ".build")) {
    65. event.setCancelled(true);
    66. }
    67. }
    68.  
    69. @EventHandler
    70. public void placeBlockEvent(BlockPlaceEvent event) {
    71. if (plugin.getConfig().getBoolean(event.getPlayer().getName() + ".build"))
    72. event.setCancelled(true);
    73. }
    74. }
     
  5. Offline

    SuperSniper

    @Skify
    In your PlayerLoginEvent, you forgot the "." before the "build" when you are setting it to false.
    Code:
    build.this.plugin.getConfig().set(event.getPlayer().getName() + " build", [URL='http://www.google.com/search?hl=en&q=allinurl%3Aboolean+java.sun.com&btnI=I%27m%20Feeling%20Lucky'][U]Boolean[/U][/URL].valueOf(false));
    
    Also, does the error have a stacktrace inside the console?
     
  6. Offline

    Skify

    @SuperSniper

    Still does not work? Do I need the http://www.google.com/search?hl=en&q=allinurl:boolean+java.sun.com&btnI=I'm Feeling Lucky part? lol
    Code:java
    1.  
    2. public class build implements CommandExecutor, Listener{
    3.  
    4. private static String prefix = "§8[§eBuild§8] §f";
    5. private core plugin;
    6.  
    7. @Override
    8. public boolean onCommand(CommandSender sender, Command cmd, String label,
    9. String[] args) {
    10. if ((sender instanceof Player)) {
    11. Player p = (Player) sender;
    12. if(cmd.getName().equalsIgnoreCase("togglebuild")) {
    13. if(p.hasPermission("shumaapi.build")) {
    14. if(plugin.getConfig().getBoolean(p.getName() + ".build")) {
    15. p.sendMessage(prefix + "Building privilege: Enabled");
    16. plugin.getConfig().set(p.getName() + ".build", Boolean.FALSE);
    17. plugin.saveConfig();
    18. } else {
    19. p.sendMessage(prefix + "Building privilege: Disabled");
    20. plugin.getConfig().set(p.getName() + ".build", Boolean.TRUE);
    21. plugin.saveConfig();
    22. }
    23. } else {
    24. p.sendMessage(prefix + "You do not have permission to use /togglebuild");
    25. }
    26. }
    27. }
    28. return false;
    29. }
    30.  
    31. @EventHandler
    32. public void onLogin(final PlayerLoginEvent event) {
    33. if (event.getPlayer().isOp())
    34. Bukkit.getServer().getScheduler()
    35. .runTaskLater((Plugin) this, new Runnable() {
    36. public void run() {
    37. event.getPlayer().sendMessage(
    38. prefix + "Build toggle has been disabled.");
    39. build.this.plugin.getConfig().set(event.getPlayer().getName() + ".build", Boolean.valueOf(false));
    40. build.this.plugin.saveConfig();
    41. }
    42. }, 40L);
    43. }
    44.  
    45. @EventHandler
    46. public void breakBlockEvent(BlockBreakEvent event) {
    47. if (plugin.getConfig().getBoolean(event.getPlayer().getName() + ".build")) {
    48. event.setCancelled(true);
    49. }
    50. }
    51.  
    52. @EventHandler
    53. public void placeBlockEvent(BlockPlaceEvent event) {
    54. if (plugin.getConfig().getBoolean(event.getPlayer().getName() + ".build"))
    55. event.setCancelled(true);
    56. }
    57. }
     
  7. Offline

    Zombie_Striker

    @Skify
    1. plugin is never equal to anything, so it is null.
    2. JAVA NAMING CONVENTION: The first letter of any class is Capital, but your class names are all lower case.
    3. Why are you doing Boolean.true or Boolean.false? Why not use "true" OR "false"
    4. final PlayerLoginEvent. Do you know what the final modifier means? Adding final to the onLogin constructor stop it from working;
    5. THAT CLASS DOES NOT EXTEND JAVAPLUGIN! IT CAN NOT BE CASTED TO A PLUGIN. GET THE CORE INSTANCE.
    6. You swapped from Boolean.FALSE to Boolean.valueOf. Please change that to only true or false.
    No one post on this thread till he has taken care of everything above.
     
    mythbusterma likes this.
  8. Offline

    teej107

    Do YOU know what final means? Your said statement is completely false and BTW, that "constructor" is not a constructor.
     
  9. Offline

    boomboompower

    You can't stop people trying to help others and you cannot control what other developers do.
     
    mythbusterma likes this.
  10. Offline

    meguy26

    @Skify @boomboompower
    People have tried to help for approx. 35 posts. Its time the OP decides to go learn some more Java.
     
Thread Status:
Not open for further replies.

Share This Page