Development Assistance Help with ammo!

Discussion in 'Plugin Help/Development/Requests' started by VictoryShot, Dec 6, 2014.

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

    VictoryShot

    Hello! I am getting this error. There were errors in the code below too someone help!

    Code:java
    1. [17:43:14 ERROR]: null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'give
    3. ammo2' in plugin HubPlugin v1.0
    4. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    5. ftbukkit.jar:git-Spigot-"606148f"]
    6. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    7. 1) ~[craftbukkit.jar:git-Spigot-"606148f"]
    8. at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    9. r.java:643) ~[craftbukkit.jar:git-Spigot-"606148f"]
    10. at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    11. nection.java:1105) [craftbukkit.jar:git-Spigot-"606148f"]
    12. at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    13. :940) [craftbukkit.jar:git-Spigot-"606148f"]
    14. at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    15. :26) [craftbukkit.jar:git-Spigot-"606148f"]
    16. at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    17. :53) [craftbukkit.jar:git-Spigot-"606148f"]
    18. at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
    19. ftbukkit.jar:git-Spigot-"606148f"]
    20. at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    21. ?:1.7.0_25]
    22. at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [?:1.7.
    23. 0_25]
    24. at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_25]
    25. at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    26. 84) [craftbukkit.jar:git-Spigot-"606148f"]
    27. at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    28. 16) [craftbukkit.jar:git-Spigot-"606148f"]
    29. at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    30. 25) [craftbukkit.jar:git-Spigot-"606148f"]
    31. at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    32. :528) [craftbukkit.jar:git-Spigot-"606148f"]
    33. at java.lang.Thread.run(Unknown Source) [?:1.7.0_25]
    34. Caused by: java.lang.NullPointerException
    35. at me.mike1665.commands.AmmoTest.onCommand(AmmoTest.java:45) ~[?:?]
    36. at me.mike1665.Main.Main.onCommand(Main.java:318) ~[?:?]
    37. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    38. ftbukkit.jar:git-Spigot-"606148f"]
    39. ... 15 more
    40.  


    I have no idea why its cuasing this error here is the current code:

    Code:java
    1. public class AmmoTest implements Listener{
    2.  
    3. public static Main plugin;
    4.  
    5. public static void setup(Main instance) {
    6. plugin = instance;
    7. }
    8. public static boolean onCommand(CommandSender sender, Command cmd,
    9. String label, String[] a) {
    10. if(!(sender instanceof Player)) return false;
    11. Player p = (Player) sender;
    12. if (cmd.getName().equalsIgnoreCase("giveammo")) {
    13. int i = 20;
    14. giveAmmo(p, i);
    15. p.sendMessage("This " + i);
    16.  
    17. }if (cmd.getName().equalsIgnoreCase("giveammo2")) {
    18. ItemStack snow = new ItemStack(Material.SNOW_BALL);
    19. ItemMeta sno = snow.getItemMeta();
    20. //LINE 45 int ammo = plugin.getConfig().getInt(p.getUniqueId() + ".MeowAmmo");
    21. sno.setDisplayName(ChatColor.GREEN + "MeowBall" + ammo);
    22. snow.setItemMeta(sno);
    23. p.getInventory().addItem(snow);
    24.  
    25. } else {
    26. sender.sendMessage(StringManager.getPrefix(MessageType.ERROR)
    27. + "Something Failed");
    28. }
    29.  
    30. return false;
    31. }
    32.  
    33. @SuppressWarnings("deprecation")
    34. @EventHandler
    35. public void projectiles(ProjectileHitEvent event)
    36. {
    37. Projectile projectile = event.getEntity();
    38. if ((projectile instanceof Snowball))
    39. {
    40. Snowball snowball = (Snowball)projectile;
    41. if ((snowball.getShooter() instanceof Player))
    42. {
    43. Player player = (Player)snowball.getShooter();
    44. if ((disName(player.getItemInHand()) != null) && (disName(player.getItemInHand()).equalsIgnoreCase(ChatColor.GREEN + "MeowBall" + plugin.getConfig().getString(player.getPlayer().getUniqueId() + ".MeowAmmo")))){
    45. Snowball s = (Snowball)event.getEntity();
    46. s.getWorld().playSound(s.getLocation(), Sound.CAT_MEOW, 1.0F, 1.0F);
    47. ParticleLib18 lava = new ParticleLib18(me.mike1665.particles18.ParticleLib18.ParticleType.LAVA, 0.0F, 20, 0);
    48. ParticleLib18 hearts = new ParticleLib18(me.mike1665.particles18.ParticleLib18.ParticleType.HEART, 0.0F, 2, 0);
    49. ParticleLib18 largesmoke = new ParticleLib18(me.mike1665.particles18.ParticleLib18.ParticleType.SMOKE_LARGE, 0.0F, 10, 0);
    50. lava.sendToLocation(s.getLocation());
    51. hearts.sendToLocation(s.getLocation());
    52. largesmoke.sendToLocation(s.getLocation());
    53. s.getWorld().playEffect(s.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
    54. s.getWorld().playEffect(s.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
    55. player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
    56. if (player.getItemInHand().getAmount() == 1) {
    57. player.setItemInHand(null);
    58. }
    59. }
    60. }
    61. }
    62. }
    63.  
    64. public static void giveAmmo(OfflinePlayer p, int i) {
    65. i = i * Multiplier.ammo(p);
    66. // THERE WAS ERRORS HERE plugin.getConfig().set(p.getUniqueId() + ".MeowAmmo",
    67. plugin.getConfig().getInt(p.getUniqueId() + ".MeowAmmo", 0) + i);
    68. plugin.saveFile();
    69. }
    70.  
    71. public String disName(ItemStack i)
    72. {
    73. if (i == null) {
    74. return null;
    75. }
    76. if (!i.hasItemMeta()) {
    77. return null;
    78. }
    79. if (!i.getItemMeta().hasDisplayName()) {
    80. return null;
    81. }
    82. return i.getItemMeta().getDisplayName();
    83. }
    84.  
    85. }
    86.  
     
  2. Offline

    Monkey_Swag

    ~[craftbukkit.jar:git-Spigot-"606148f"]

    Look for help on the spigot forums. Not here : (
     
  3. Offline

    VictoryShot

    Spigot and bukkit are similar.
     
  4. Offline

    SuperOriginal

    VictoryShot The values you're getting from the config are null.. Make sure you set it correctly, and saved the config.
     
  5. Offline

    mythbusterma

    VictoryShot

    Let's see:

    1. Your reference to the main class of the plugin is public and static, it should be neither of those.
    2. You have an onCommand() method that will never be invoked because this is not a CommandHandler
    3. Your onCommand() is static when it shouldn't be
    4. Everything is referenced statically, and it's starting to hurt my eyes
    5. It's quite likely you made a mistake in your "setup()" (completely unnecessary method, as it's basically doing the job of a constructor, but not OOP) method and plugin is null
    Alternatively, the value in config is null, add a default parameter to avoid unboxing null.
     
    PreFiXAUT and SuperOriginal like this.
  6. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
Thread Status:
Not open for further replies.

Share This Page