Solved Plugin not working

Discussion in 'Plugin Development' started by josh12341, Nov 5, 2013.

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

    josh12341

    This is very strange, I created a test plugin for another plugin.
    I got everything to work fine, then I copied everything exactly (except change the names in it for the plugin) to the main plugin and it didn't work.
    The first command works which is
    Code:
    /server or /server <anything random>
    but the other commands don't, It says:
    Code:
    An internal error occured while attempting to perform this command.
    I found a error in the console:
    Code:
    2013-11-06 01:29:58 [INFO] joshepic_1234 issued server command: /server THIS WORKS
    2013-11-06 01:30:02 [INFO] joshepic_1234 issued server command: /server dshs THIS IS THE RANDOM STUFF AFTER AND THIS WORKS
    2013-11-06 01:30:06 [INFO] joshepic_1234 issued server command: /server info THIS IS WHERE IT SAYS ERROR
    2013-11-06 01:30:06 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'server' in plugin SimpleInfo v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    Caused by: java.lang.NullPointerException
    at me.joshepic_1234.SimpleInfo.Main.onCommand(Main.java:34)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more
    
    AND THIS IS NOT MY CODING BECAUSE THE EXACT SAME THING WORKED ON A DIFFERENT PLUGIN!
     
  2. Offline

    NinjaWAffles

    Whenever the command is being processed, something is null and it can't continue further, thus you getting the error. For anyone to really help you, you'll need to post the source code to your plugin.
     
  3. Offline

    josh12341

    Fine.... here:
    Main.java:
    Code:java
    1. package me.joshepic_1234.(My plugin name: I don't want it to be stolen! :P); //remember to export and reload!
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin {
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. public void onEnable() {
    16. PluginDescriptionFile pdfFile = this.getDescription();
    17. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled!"); //console message to say that plugin has been enabled
    18. saveDefaultConfig();
    19. }
    20. public void onDisable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been disabled!"); //console message to say that plugin has been disabled
    23. }
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25. Player player = (Player) sender;
    26. if(commandLabel.equalsIgnoreCase("server")) {
    27. if(args.length == 0) {
    28. player.sendMessage(ChatColor.DARK_RED + "Invalid Command!");
    29. player.sendMessage(ChatColor.DARK_RED + "Commands For " + this.getDescription().getName());
    30. player.sendMessage(ChatColor.AQUA + "/server info - Tells the player more about the server!");
    31. player.sendMessage(ChatColor.AQUA + "/server rules - Tells the player the server rules!");
    32. player.sendMessage(ChatColor.AQUA + "/server staff - Tells the player the server staff!");
    33. } else if(args[0].equalsIgnoreCase("info")) {
    34. player.sendMessage(getConfig().getString("Info").replaceAll("&0", ChatColor.BLACK + "" ).replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "" ).replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "" ).replaceAll("&c", ChatColor.RED + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "" ).replaceAll("&l", ChatColor.BOLD + "").replaceAll("&m", ChatColor.STRIKETHROUGH + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&r", ChatColor.RESET + "" ));
    35. } else if(args[0].equalsIgnoreCase("rules")) {
    36. player.sendMessage(getConfig().getString("Rules").replaceAll("&0", ChatColor.BLACK + "" ).replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "" ).replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "" ).replaceAll("&c", ChatColor.RED + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "" ).replaceAll("&l", ChatColor.BOLD + "").replaceAll("&m", ChatColor.STRIKETHROUGH + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&r", ChatColor.RESET + "" ));
    37. } else if(args[0].equalsIgnoreCase("staff")) {
    38. player.sendMessage(getConfig().getString("Staff").replaceAll("&0", ChatColor.BLACK + "" ).replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "" ).replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "" ).replaceAll("&c", ChatColor.RED + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "" ).replaceAll("&l", ChatColor.BOLD + "").replaceAll("&m", ChatColor.STRIKETHROUGH + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&r", ChatColor.RESET + "" ));
    39. }else{
    40. player.sendMessage(ChatColor.DARK_RED + "Invalid Command!");
    41. player.sendMessage(ChatColor.DARK_RED + "Commands For " + this.getDescription().getName());
    42. player.sendMessage(ChatColor.AQUA + "/server info - Tells the player more about the server!");
    43. player.sendMessage(ChatColor.AQUA + "/server rules - Tells the player the server rules!");
    44. player.sendMessage(ChatColor.AQUA + "/server staff - Tells the player the server staff!");
    45.  
    46. }
    47. }
    48. return false;
    49. }
    50.  
    51. }

    plugin.yml:
    Code:java
    1. name: (My plugin name: I don't want it stolen! :P)
    2. main: me.joshepic_1234.(My plugin name: I don't want it stolen! :P).Main
    3. version: 1.0
    4. description: >
    5. A simple plugin to inform players more about your server!
    6. commands:
    7. server:
    8. description: The main command for (My plugin name: I don't want it stolen! :P)
    9.  

    config.yml:
    Code:java
    1. ##################################################################################
    2. # #
    3. # (My plugin name: I don't want it stolen! :P)#
    4. # Default Configuration File #
    5. # #
    6. # #
    7. ##################################################################################
    8. # Commands for (My plugin name: I don't want it stolen! :P):
    9. # All commands are used with /server <command>
    10. # DON'T DELETE THE SPEECH MARKS!
    11.  
    12. Info: 'Default Info!'
    13. Rules: 'Default Rules!'
    14. Staff: 'Default Staff!'
    15.  
    16. # Color Codes:
    17. # &0 - Black
    18. # &1 - Dark Blue
    19. # &2 - Dark Green
    20. # &3 - Teal
    21. # &4 - Dark Red
    22. # &5 - Purple
    23. # &6 - Gold
    24. # &7 - Gray
    25. # &8 - Dark Gray
    26. # &9 - Blue
    27. # &a - Bright Green
    28. # &b - Aqua
    29. # &c - Red
    30. # &d - Pink
    31. # &e - Yellow
    32. # &f - White
    33. # &k - Magic
    34. # &l - Bold
    35. # &m - Strike
    36. # &n - Underline
    37. # &o - Italic
    38. # &r - Reset
     
  4. Offline

    amhokies

    josh12341
    Woah man, replacing all the & codes like that is definitely taking the hard way. Bukkit has a built in method for just this thing.
    ChatColor.translateAlternateColorCodes('&', textToTranslate);

    EDIT: Even if they didn't have that method, you could do something like
    Code:java
    1. private String translateColorCodes(String message) {
    2. return message.replace('&', '§');
    3. }
     
  5. Offline

    josh12341

    Ye I know i'll change it but that's not why it's not working
     
  6. Offline

    xTrollxDudex

    The latter produces a bunch of Unicode or UTF stuff...
     
  7. Offline

    amhokies

    How so?
     
  8. Offline

    josh12341

    JUST SOMEONE PLEASE TELL ME HOW TO FIX IT OR I'LL REPOST!!!
     
  9. Offline

    amhokies

    josh12341
    We're all volunteers here. We're helping you with our free time. Demanding in all caps that someone help you isn't the way to get someone to help you.
     
  10. Offline

    josh12341

    ok, i'm sorry.
    Do you know how to fix this problem?
     
  11. Offline

    josh12341

    It doesn't matter now, it suddenly started working......Java Eclipse is very strange sometimes...
     
Thread Status:
Not open for further replies.

Share This Page