Why is this damn thing null!

Discussion in 'Plugin Development' started by rymate1234, Mar 3, 2012.

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

    rymate1234

    Ok, I have this error in my code, and was wondering if anyone could help.
    The actual code:
    Code:java
    1. /*
    2. * bChatManager - bPermissions chat management plugin for Bukkit
    3. * Originally - PermissionsEx chat management plugin for Bukkit
    4. * Copyright (C) 2011 t3hk0d3 [url]http://www.tehkode.ru[/url]
    5. *
    6. * This program is free software; you can redistribute it and/or
    7. * modify it under the terms of the GNU General Public License
    8. * as published by the Free Software Foundation; either version 2
    9. * of the License, or (at your option) any later version.
    10. *
    11. * This program is distributed in the hope that it will be useful,
    12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14. * GNU General Public License for more details.
    15. *
    16. * You should have received a copy of the GNU General Public License
    17. * along with this program; if not, write to the Free Software
    18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    19. */
    20. package net.rymate.bchatmanager;
    21.  
    22. import java.util.logging.Logger;
    23. import org.bukkit.configuration.file.YamlConfiguration;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25.  
    26. /**
    27. * Main class for bChatManager
    28. *
    29. * @oldauthor t3hk0d3
    30. * @author rymate1234
    31. */
    32. public class bChatManager extends JavaPlugin {
    33.  
    34. protected final static Logger logger = Logger.getLogger("Minecraft");
    35. protected bChatListener listener;
    36.  
    37. @Override
    38. public void onEnable() {
    39. setupConfig();
    40. setupCommands();
    41. this.getServer().getPluginManager().registerEvents(this.listener, this);
    42. try {
    43. // create a new metrics object
    44. Metrics metrics = new Metrics();
    45. // 'this' in this context is the Plugin object
    46. metrics.beginMeasuringPlugin(this);
    47. } catch (Exception e) {
    48. System.out.println(e);
    49. // Failed to submit the stats :-(
    50. }
    51. logger.info("[bChatManager] bChatManager enabled.");
    52. }
    53.  
    54. @Override
    55. public void onDisable() {
    56. this.listener = null;
    57. logger.info("[bChatManager] bChatManager disabled!");
    58. }
    59.  
    60. public void setupConfig() {
    61. this.getConfig().options().copyDefaults(true);
    62. this.saveConfig();
    63. this.listener = new bChatListener((YamlConfiguration) this.getConfig(), this);
    64. }
    65.  
    66. public void setupCommands() {
    67. boolean use = this.getConfig().getBoolean("me-format", true);
    68. if (use == true) {
    69. MeCommand me = new MeCommand(this.getConfig(), this);
    70. System.out.println(me);
    71. System.out.println(this.getConfig());
    72. System.out.println(this);
    73. this.getCommand("me").setExecutor(me);
    74. }
    75. }
    76. }
    77.  



    The thing is that the code throwing the error HAS NOT CHANGED since the version when I added it, which has really confused me :eek:
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    You forgot to register "me" in your plugin.yml
     
  3. Offline

    Taco

    If there's an empty line in your plugin.yml, that could do it.
     
  4. Offline

    rymate1234

    Here's my plugin.yml
    Code:
    name: bChatManager
    main: net.rymate.bchatmanager.bChatManager
    depend: [ bPermissions ]
    version: 1.4.1
    author: rymate1234
    website: www.rymate.co.uk
    description: Chat management plugin for bPermissions based of PEX ChatManager
    commands:
      me:
        description: Sends a message in the third person!
        usage: /me <message>
        aliases: [m, moi]
    
     
  5. shouldn't it be
    usage: /<command> <message> ? I'm not sure.
     
  6. Offline

    rymate1234

    changed it to that - no effect
     
  7. Offline

    heisan213

    MeCommand me = new MeCommand(this.getConfig(), this);

    False!!!
    The type has to be CommandExecutor and it has to be a new instance of the class the command is in. So in your case:
    CommandExecutor me = new MeCommand();
    And your me command class would implement CommandExecutor and have the onCommand() method in it.

    Also the stack trace sais:

    at net.rymate.bchatmanager.bChatManager.setupCommands(bChatManager.java:73)
    at net.rymate.bchatmanager.bChatManager.onEnable(bChatManager.java:40)

    The read text shows you where the problem is. Go to this topic to learn how to easilly understand stack traces
    Final edit: It shows the class witch the problem is in, then after the colon what line it is in ( : <--- Colon right?)
     
  8. you can't say it's wrong because you don't know the constructor.
    And btw: we already know where the error is, you don't need to say it again.
     
  9. Offline

    heisan213

    Ah, constructor, sorry!
    Edit, wait...
    The Command.setExecutor(CommandExecutor) has to take a CommandExecutor not MeCommand, right? Did you trY?


    PHP:
    /*
    * bChatManager - bPermissions chat management plugin for Bukkit
    * Originally - PermissionsEx chat management plugin for Bukkit
    * Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    */
    package net.rymate.bchatmanager;
     
    import java.util.logging.Logger;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
     
    /**
    * Main class for bChatManager
    *
    * @oldauthor t3hk0d3
    * @author rymate1234
    */
    public class bChatManager extends JavaPlugin {
     
        protected final static 
    Logger logger Logger.getLogger("Minecraft");
        protected 
    bChatListener listener;
     
        @
    Override
        
    public void onEnable() {
            
    setupConfig();
            
    setupCommands();
            
    this.getServer().getPluginManager().registerEvents(this.listenerthis);
            try {
                
    // create a new metrics object
                
    Metrics metrics = new Metrics();
                
    // 'this' in this context is the Plugin object
                
    metrics.beginMeasuringPlugin(this);
            } catch (
    Exception e) {
                
    System.out.println(e);
                
    // Failed to submit the stats :-(
            
    }
            
    logger.info("[bChatManager] bChatManager enabled.");
        }
     
        @
    Override
        
    public void onDisable() {
            
    this.listener null;
            
    logger.info("[bChatManager] bChatManager disabled!");
        }
     
        public 
    void setupConfig() {
            
    this.getConfig().options().copyDefaults(true);
            
    this.saveConfig();
            
    this.listener = new bChatListener((YamlConfigurationthis.getConfig(), this);
        }
     
        public 
    void setupCommands() {
            
    boolean use = this.getConfig().getBoolean("me-format"true);
            if (use == 
    true) {
                
    MeCommand me = new MeCommand(this.getConfig(), this);
                
    System.out.println(me);
                
    System.out.println(this.getConfig());
                
    System.out.println(this);
                
    this.getCommand("me").setExecutor(new MeCommandExecutorClass()); //This is all that needed change
            
    }
        }
    }
    Whats the name of the class you keep the code for the MeCommand?
     
  10. MeCommand can still implement command executor ....
     
  11. Offline

    nisovin

    heisan213 MeCommand is obviously the name of the class, and it is already a CommandExecutor. You also don't have to use the CommandExecutor type when declaring it, as long as the class you are using implements CommandExecutor.
     
  12. Offline

    heisan213

    Oh, I will go slap myself with a slimeball for not trying out the code before saying anything! Sorry guys :(

    Oh, did you try decompiling the .jar file? Sometimes Eclipse doesnt update the classes, only the java source files. It happens all the time to me
     
  13. Offline

    rymate1234

    Well, I use netbeans :p
     
  14. In your plugin.yml you have person! shouldn't it be person:

    ?

    Keir
     
  15. Offline

    rymate1234

    And also, i know how to read stack traces, which is why I only posted the relevant code.

    I am only posting here because I have absolutely no idea what is null

    removed exclamation mark - no effect

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  16. Oops accidentally liked the post lol. Did you replace ! with : ? And it would have an effect because once the null error is corrected it would be giving errors for the person! bit.

    Keir
     
  17. Offline

    rymate1234

    There should be no : as its a yaml string
     
  18. You might wanna read the bukkit wiki to see how a plugin.yml should be setup. I can't post the link to it atm though.

    Keir
     
  19. No offense, but the things that you mentioned aren't correct so I would suggest that you read about yaml yourself. rymate1234 is correct. Since it's a normal yaml string you can use ! for sure.
     
  20. Offline

    rymate1234

    Maybe you should! http://wiki.bukkit.org/Plugin_YAML

    I don't always do this,umping this, but I'm bumping this topic

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  21. like he did in his .yml. nothing wrong there. do you see any : after the description in the example? I don't.
     
  22. I am talking about the bit that goes like this

    command
    description: Bla Bla

    Where it should actually be

    command:
    description: Bla Bla
     
  23. Offline

    Sir Savary

    rymate1234
    Do me a favor and change your code BB tags to syntax=java BB tags.
     
  24. Yeah, but you say something is wrong when it is not. I don't see the problem you're talking about in his plugin.yml... And also you talked about the ! at the end of the description and said that it's wrong which it is not.
     
  25. Offline

    rymate1234

    Done that :)
    but it is like that....
    Code:
    commands:
      me:
        description: Sends a message in the third person
        usage: /<command> <message>
        aliases: [moi]
     
  26. Offline

    Sir Savary

  27. Offline

    rymate1234

    MeCommand.java
    Code:java
    1.  
    2. package net.rymate.bchatmanager;
    3.  
    4. import java.util.List;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11.  
    12. /**
    13.  *
    14.  * @author Ryan
    15.  */
    16. class MeCommand implements CommandExecutor {
    17.  
    18. private final bChatManager plugin;
    19. private final String meFormat;
    20. private final Functions f;
    21. private final boolean rangedMode;
    22. private final double chatRange;
    23.  
    24. public MeCommand(FileConfiguration config, bChatManager aThis) {
    25. this.meFormat = config.getString("me-format", this.meFormat);
    26. this.chatRange = config.getDouble("chat-range", this.chatRange);
    27. this.rangedMode = config.getBoolean("ranged-mode", this.rangedMode);
    28. this.plugin = aThis;
    29. this.f = new Functions(plugin);
    30. }
    31.  
    32. @Override
    33. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    34. if (args.length < 1) {
    35. sender.sendMessage(ChatColor.RED + "Ya need to type something after it :P");
    36. return false;
    37. }
    38. if (!(sender instanceof Player)) {
    39. sender.sendMessage(ChatColor.RED + "You are not an in-game player!");
    40. return true;
    41. }
    42. Player player = (Player) sender;
    43. int i;
    44. StringBuilder me = new StringBuilder();
    45. for (i = 0; i < args.length; i++) {
    46. me.append(args[i]);
    47. me.append(" ");
    48. }
    49. String meMessage = me.toString();
    50. String message = meFormat;
    51. message = f.colorize(message);
    52.  
    53. if (sender.hasPermission("bchatmanager.chat.color")) {
    54. meMessage = f.colorize(meMessage);
    55. }
    56.  
    57. message = message.replace("%message", meMessage).replace("%displayname", "%1$s");
    58. message = f.replacePlayerPlaceholders(player, message);
    59. message = f.replaceTime(message);
    60.  
    61. if (rangedMode) {
    62. List<Player> pl = f.getLocalRecipients(player, message, chatRange);
    63. for (int j = 0; j < pl.size(); j++) {
    64. pl.get(j).sendMessage(message);
    65. }
    66. sender.sendMessage(message);
    67. System.out.println(message);
    68. } else {
    69. plugin.getServer().broadcastMessage(message);
    70. }
    71. return true;
    72. }
    73. }
    74. [/i]
     
  28. I don't think it's related to the mecommand because the stack trace doesn't point to it at all. the only thing I could think of is the plugin.yml, but it looks correct to me.
     
Thread Status:
Not open for further replies.

Share This Page