Getting errors for all of my commands..

Discussion in 'Plugin Development' started by DirtyStarfish, Sep 13, 2011.

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

    DirtyStarfish

    Hey

    I'm trying to make a simple plugin that has different chat commands. Mainly doing this so I can learn how to write the commands.

    No errors are showing in the code, but theres a problem somewhere!
    If you got a spare minute to have a look I would love some advice!

    Heres a link to the pasted code, here.

    There are 4 commands.
    /me is supposed to be like the usual /me command.
    /do same as /me, but the message will be gray.

    /sh and /low are to send the message to players in a certian radius.

    Any help is much appreciated!

    Thanks,
     
  2. Offline

    Pandemoneus

    And what is your problem?
     
  3. Offline

    DirtyStarfish

    The problem is they don't work. I get a message in the chat and console saying theres an error has occurred.
     
  4. Offline

    stelar7

    and whats the error?
     
  5. Offline

    Lolmewn Retired Staff

    And give some code pl0x.
     
  6. Offline

    Pandemoneus

    Code:java
    1. Player player;

    Delete that.

    Code:java
    1.  
    2. if (sender instanceof Player) {
    3. Player player = (Player) sender;
    4. if (command.getName().equalsIgnoreCase("me")) {
    5. final StringBuilder message = new StringBuilder();
    6. for (int i = 0; i < args.length; i++) {
    7. message.append(args[I]);[/I]
    8. message.append(' ');
    9. }
    10. getServer().broadcastMessage(player.getName() + " " + message);
    11. return true;
    12. } else if (command.getName().equalsIgnoreCase("do")) {
    13. final StringBuilder message = new StringBuilder();
    14. for (int i = 0; i < args.length; i++) {
    15. message.append(args);
    16. message.append(' ');
    17. }
    18. getServer().broadcastMessage(ChatColor.GRAY + "OOC" + player.getName() + " " + message);
    19. return true;
    20. } else if (command.getName().equalsIgnoreCase("sh")) {
    21. final StringBuilder message = new StringBuilder();
    22. for (int i = 0; i < args.length; i++) {
    23. message.append(args);
    24. message.append(' ');
    25. }
    26. Player[] list = getServer().getOnlinePlayers();
    27. for (int i = 0; i < list.length; i++) {
    28. if (list.getLocation().distance(player.getLocation()) <= 40.00 {
    29. list.sendMessage(player.getName() + ": " + message);
    30. }
    31. }
    32. return true;
    33. } else if (command.getName().equalsIgnoreCase("low")) {
    34. final StringBuilder message = new StringBuilder();
    35. for (int i = 0; i < args.length; i++) {
    36. message.append(args);
    37. message.append(' ');
    38. }
    39. Player[] list = getServer().getOnlinePlayers();
    40. for (int i = 0; i < list.length; i++) {
    41. if (list.getLocation().distance(player.getLocation()) <= 5.00) {
    42. list.sendMessage(player.getName() + ": " + message); } } return true;
    43. }
    44. }
    45. return false;


    Though for me, you sometimes don't seem to know what you are doing.
     
  7. Offline

    DirtyStarfish

    The error in the console is:
    show message

    2011-09-13 16:38:12 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'me' in plugin rpgChat v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:129)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:320)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:713)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:677)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:670)
    at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:85)
    at net.minecraft.server.NetworkListenThread.a(SourceFile:105)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:451)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:361)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.NullPointerException
    at me.dirtystarfish.plugins.rpgchat.Rpgchat.onCommand(Rpgchat.java:36)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
    ... 12 more


    And the error in the in-game chat is:
    "An internal error occurred when attempting to perform this command. "
     
  8. Offline

    ItsHarry

    Caused by: java.lang.NullPointerException
    at me.dirtystarfish.plugins.rpgchat.Rpgchat.onCommand(Rpgchat.java:36)
     
  9. Offline

    Pandemoneus

    I already posted the correct code up there.
     
Thread Status:
Not open for further replies.

Share This Page