Solved NullPointerException confusion

Discussion in 'Plugin Development' started by minepress, Aug 12, 2014.

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

    minepress

    Hi all,

    Writing a basic script where if someone joins a team, they're disguised and then placed into a team.

    Here is the error:


    Code:
    [22:07:52 INFO]: Beakaa2 issued server command: /joinmonster
    [22:07:52 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'join
    monster' in plugin Minevolve v0.0.3
    Caused by: java.lang.NullPointerException
            at io.github.bradly_spicer.minevolve.MinevolveCommandExecutor.onCommand(
    MinevolveCommandExecutor.java:28) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            ... 13 more
    >
    
    Here is MinevolveCommandExecutor:

    Code:java
    1. package io.github.bradly_spicer.minevolve;
    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 pgDev.bukkit.DisguiseCraft.DisguiseCraft;
    10. import pgDev.bukkit.DisguiseCraft.api.DisguiseCraftAPI;
    11. import pgDev.bukkit.DisguiseCraft.disguise.Disguise;
    12. import pgDev.bukkit.DisguiseCraft.disguise.DisguiseType;
    13.  
    14. public class MinevolveCommandExecutor implements CommandExecutor {
    15. private final Minevolve plugin;
    16. Team humanTeam = new Team("Humans");
    17. Team monsterTeam = new Team("Monsters");
    18. int monstercount = 0;
    19.  
    20. public MinevolveCommandExecutor(Minevolve plugin) {
    21. this.plugin = plugin; // Store the plugin in situations where you need it.
    22. }
    23.  
    24. @Override
    25. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    26. // VARIABLES
    27. Player p = (Player)sender;
    28. Disguise monster1 = new Disguise(Minevolve.dcAPI.newEntityID(),"MONSTER", DisguiseType.Cow); // This line is the error
    29.  
    30. //TEAM ORGANISER
    31. if(cmd.getName().equalsIgnoreCase("joinhuman")){
    32. humanTeam.addPlayer(p);
    33. p.sendMessage("You are a HUMAN");
    34. }
    35. if(cmd.getName().equalsIgnoreCase("joinmonster")){
    36. if(monstercount > 1) {
    37. p.sendMessage("There is already a monster, moving to human team");
    38. humanTeam.addPlayer(p);
    39. } else if (monstercount < 1){
    40. monstercount++;
    41.  
    42. monsterTeam.addPlayer(p);
    43. p.sendMessage("DESTROY THEM");
    44. }
    45. }
    46. return true;
    47. }
    48. }


    And advice? using the following api:
    http://dev.bukkit.org/bukkit-plugins/disguisecraft/pages/developer-api/
     
  2. Offline

    TheDarkLord197

    minepress My guess is this parameter inside the constructor on line 28 returned null..
    Code:java
    1. Minevolve.dcAPI.newEntityID()
     
  3. Offline

    minepress


    Hey TheDarkLord197 thanks for posting. I'm not sure what to put in that to be honest. The documentation doesn't stand anything
     
  4. Offline

    TheDarkLord197

    minepress Actually, Can you show us the Minevolve class?
     
  5. Offline

    minepress


    Code:java
    1. package io.github.bradly_spicer.minevolve;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7.  
    8. import pgDev.bukkit.DisguiseCraft.DisguiseCraft;
    9. import pgDev.bukkit.DisguiseCraft.api.DisguiseCraftAPI;
    10.  
    11. public class Minevolve extends JavaPlugin implements Listener{
    12. //Setup DisguiseCraft
    13. static DisguiseCraftAPI dcAPI;
    14. public void setupDisguiseCraft() {
    15. dcAPI = DisguiseCraft.getAPI();
    16. }
    17.  
    18.  
    19. //Is Player Diguised?
    20. public void checkDisguise(Player p) {
    21. if (dcAPI.isDisguised(p)) {
    22. System.out.println(p.getName() + " is disguised!");
    23. } else {
    24. System.out.println(p.getName() + " is not disguised!");
    25. }
    26. }
    27.  
    28. @Override
    29. public void onEnable() {
    30. getLogger().info("onEnable has been invoked!");
    31. // This will throw a NullPointerException if you don't have the command defined in your plugin.yml file!
    32. this.getCommand("join").setExecutor(new MinevolveCommandExecutor(this));
    33. this.getCommand("joinhuman").setExecutor(new MinevolveCommandExecutor(this));
    34. this.getCommand("joinmonster").setExecutor(new MinevolveCommandExecutor(this));
    35. }
    36. @Override
    37. public void onDisable() {
    38. getLogger().info("onDisable has been invoked!");
    39. }
    40. }
     
  6. Offline

    TheDarkLord197

    minepress You never call the method "setupDisguiseCraft()". Call it in onEnable.
     
    minepress likes this.
  7. Offline

    minepress


    Ahh! that slipped my mind! Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page