Unknown Error

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Dec 25, 2013.

Thread Status:
Not open for further replies.
  1. Why am I getting this error??
    Code:
    [20:46:33] [Server thread/INFO]: [kevyandazzas server] Loading kevyandazzas server v1.0
    [20:46:33] [Server thread/INFO]: [kevyandazzas server] Enabling kevyandazzas server v1.0
    [20:46:33] [Server thread/INFO]: [KEVY] Enabled KEVYANDAZZA
    [20:46:33] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:46:33] [Server thread/INFO]: Kevy_Porter: Reload complete.
    [20:46:36] [Server thread/INFO]: Kevy_Porter issued server command: /rank Kevy_Porter vip
    [20:46:36] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'rank' in plugin kevyandazzas server v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.NullPointerException
        at org.bukkit.permissions.PermissibleBase.addAttachment(PermissibleBase.java:103) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity.addAttachment(CraftHumanEntity.java:119) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at me.kevyporter.kevyandazza.commands.RankCommands.onCommand(RankCommands.java:35) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        ... 13 more
    
    Main:
    Code:java
    1. package me.kevyporter.kevyandazza;
    2.  
    3.  
    4. import me.kevyporter.kevyandazza.commands.RankCommands;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.plugin.PluginManager;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin implements Listener{
    12.  
    13. public void onEnable(){
    14. System.out.println("[KEVY] Enabled KEVYANDAZZA");
    15.  
    16. PluginManager pm = Bukkit.getPluginManager();
    17. pm.registerEvents(this, this);
    18.  
    19. pm.registerEvents(new BlockListener(), this);
    20. pm.registerEvents(new ChatFormat(), this);
    21.  
    22. RankCommands commands = new RankCommands();
    23. getCommand("rank").setExecutor(commands);
    24. }
    25.  
    26. public void onDisable(){
    27. System.out.println("[KEVY] Disabled KEVYANDAZZA");
    28. }
    29.  
    30. }
    31.  

    RankCommands:
    Code:java
    1. package me.kevyporter.kevyandazza.commands;
    2.  
    3. import java.io.File;
    4. import java.io.InputStream;
    5. import java.util.List;
    6. import java.util.logging.Logger;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Server;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandExecutor;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.configuration.file.FileConfiguration;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.generator.ChunkGenerator;
    17. import org.bukkit.plugin.Plugin;
    18. import org.bukkit.plugin.PluginDescriptionFile;
    19. import org.bukkit.plugin.PluginLoader;
    20.  
    21. import com.avaje.ebean.EbeanServer;
    22.  
    23. public class RankCommands implements CommandExecutor, Plugin {
    24.  
    25. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    26.  
    27. Player s = (Player)sender;
    28.  
    29. if(cmd.getName().equalsIgnoreCase("rank")){
    30. if(args.length < 2){
    31. s.sendMessage(ChatColor.RED + "Usage: /rank <name> <vip,vipplus,elite,helper,mod,admin>");
    32. }else if(args.length == 2){
    33. Player p = Bukkit.getServer().getPlayer(args[0]);
    34.  
    35. p.addAttachment(this, args[1], true);
    36. if(p.hasPermission(args[1].toLowerCase())){
    37. p.sendMessage(ChatColor.YELLOW + "Successfully apllied " + args[1].toUpperCase());
    38. }else{
    39. s.sendMessage(ChatColor.RED + "Error!");
    40. }
    41. }else{
    42. s.sendMessage(ChatColor.RED + "Specified player is not online!");
    43. }
    44. }
    45. return false;
    46. }
    47.  
    48. @Override
    49. public List<String> onTabComplete(CommandSender arg0, Command arg1,
    50. String arg2, String[] arg3) {
    51. // TODO Auto-generated method stub
    52. return null;
    53. }
    54.  
    55. @Override
    56. public FileConfiguration getConfig() {
    57. // TODO Auto-generated method stub
    58. return null;
    59. }
    60.  
    61. @Override
    62. public File getDataFolder() {
    63. // TODO Auto-generated method stub
    64. return null;
    65. }
    66.  
    67. @Override
    68. public EbeanServer getDatabase() {
    69. // TODO Auto-generated method stub
    70. return null;
    71. }
    72.  
    73. @Override
    74. public ChunkGenerator getDefaultWorldGenerator(String arg0, String arg1) {
    75. // TODO Auto-generated method stub
    76. return null;
    77. }
    78.  
    79. @Override
    80. public PluginDescriptionFile getDescription() {
    81. // TODO Auto-generated method stub
    82. return null;
    83. }
    84.  
    85. @Override
    86. public Logger getLogger() {
    87. // TODO Auto-generated method stub
    88. return null;
    89. }
    90.  
    91. @Override
    92. public String getName() {
    93. // TODO Auto-generated method stub
    94. return null;
    95. }
    96.  
    97. @Override
    98. public PluginLoader getPluginLoader() {
    99. // TODO Auto-generated method stub
    100. return null;
    101. }
    102.  
    103. @Override
    104. public InputStream getResource(String arg0) {
    105. // TODO Auto-generated method stub
    106. return null;
    107. }
    108.  
    109. @Override
    110. public Server getServer() {
    111. // TODO Auto-generated method stub
    112. return null;
    113. }
    114.  
    115. @Override
    116. public boolean isEnabled() {
    117. // TODO Auto-generated method stub
    118. return false;
    119. }
    120.  
    121. @Override
    122. public boolean isNaggable() {
    123. // TODO Auto-generated method stub
    124. return false;
    125. }
    126.  
    127. @Override
    128. public void onDisable() {
    129. // TODO Auto-generated method stub
    130.  
    131. }
    132.  
    133. @Override
    134. public void onEnable() {
    135. // TODO Auto-generated method stub
    136.  
    137. }
    138.  
    139. @Override
    140. public void onLoad() {
    141. // TODO Auto-generated method stub
    142.  
    143. }
    144.  
    145. @Override
    146. public void reloadConfig() {
    147. // TODO Auto-generated method stub
    148.  
    149. }
    150.  
    151. @Override
    152. public void saveConfig() {
    153. // TODO Auto-generated method stub
    154.  
    155. }
    156.  
    157. @Override
    158. public void saveDefaultConfig() {
    159. // TODO Auto-generated method stub
    160.  
    161. }
    162.  
    163. @Override
    164. public void saveResource(String arg0, boolean arg1) {
    165. // TODO Auto-generated method stub
    166.  
    167. }
    168.  
    169. @Override
    170. public void setNaggable(boolean arg0) {
    171. // TODO Auto-generated method stub
    172.  
    173. }
    174.  
    175. }
    176.  
     
  2. Offline

    Rocoty

    Code:java
    1. p.addAttachment(this, args[1], true);

    On that line you are passing a Plugin (this) which is not enabled and does not have a description file or anything else, and is basically not instantiated by the PluginManager. Don't implement Plugin or extend JavaPlugin in any other class than the main one.

    What you want to do in this case is to pass the main instance through a constructor in the RankCommands class and use that instead when invoking addAttachment.
     
  3. Offline

    1Rogue Retired Staff

    RankCommands implements Plugin when it isn't a plugin. You then pass it to the permissions attachment method as a plugin, so it attempts to get a non-existant description and throws an NPE:

    https://github.com/Bukkit/Bukkit/bl.../bukkit/permissions/PermissibleBase.java#L103

    Don't extend JavaPlugin / implement Plugin in classes other than your main class. You should be passing your main class instance to .addAttachment(), not a fake Plugin instance.
     
  4. 1Rogue implementing Plugin was a ctrl + shift + o mistake.

    I'm still confused on what to do :oops:

    .addAttatchment() is giving me 2 suggestions:
    Cast argument 'this' to 'Plugin'
    Let 'RankCommands' implement 'Plugin'

    I've tried both but I get the same error each time
     
  5. Offline

    Rocoty

    You shouldn't be passing 'this' in the first place. You should be passing the instance of your main class.
     
  6. Rocoty Ah, OK. How would I do this?

    sorry I have only made small single class plugins and or I just make it all in 1 class (stupid idea)
     
  7. Offline

    Rocoty

  8. Rocoty Thanks I'll try it out
     
Thread Status:
Not open for further replies.

Share This Page