Please help!

Discussion in 'Plugin Development' started by RangerNuk, Sep 25, 2012.

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

    RangerNuk

    Ok, so I made a plugin called massgrief for fun, and eclipse shows NO errors, but it cant load it, here is the error log below, and can anyone tell me how to spawn multiple mobs at once, I know the method for spawning a single mob, but how do you spawn multiple ones? Here is the error log.

    18:17:38 [SEVERE] Could not load 'plugins/MassGrief.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:153)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:222)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:198)
    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at MassGrief.MassGriefMain.<init>(MassGriefMain.java:66)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:149)
    ... 9 more
     
  2. Offline

    javoris767

    Could you provide the plugin.yml / main class.
     
  3. Offline

    RangerNuk

    yeah, heres the main class,

    package MassGrief;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;


    public class MassGriefMain extends JavaPlugin {


    public void onEnable(){
    getLogger().info("MassGrief has been enabled, you better hope you have rollback");

    }


    public void onDisable(){
    getLogger().info("MassGrief has been disabled, are you to scared to use it?");

    }


    public void onPlayerMove(PlayerMoveEvent evt) {
    Location loc = evt.getPlayer().getLocation();
    World w = loc.getWorld();
    loc.setY(loc.getY() - 1);
    Block b = w.getBlockAt(loc);
    b.setTypeId(46);
    b.setData((byte)1);
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if(cmd.getName().equalsIgnoreCase("BOOM")){
    if (args.length > 1) {
    sender.sendMessage("Too many arguments!");
    returnfalse;
    }
    if (args.length < 1) {
    sender.sendMessage("Not enough arguments!");
    returnfalse;
    }
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    if (target == null) {
    sender.sendMessage("The specified player is not online.");
    returnfalse;
    }
    target.setHealth(0);
    target.getWorld().spawnCreature(target.getLocation(), CreatureType.CREEPER);
    returntrue;
    }

    returnfalse;

    }{



    for(Player player: getServer().getOnlinePlayers()) {

    if(player.hasPermission("massgrief.boomrepeat")) {
    float explosionPower = 10F;
    player.getWorld().createExplosion(player.getLocation(), (Float) explosionPower);

    }

    }











    }

    public void onPlyerJoin(PlayerJoinEvent evt) {
    Player player = evt.getPlayer();
    PlayerInventory inventory = player.getInventory();
    ItemStack itemstack = new ItemStack(Material.TNT, 1728);

    if (inventory.contains(itemstack)) {
    inventory.addItem(itemstack);
    player.sendMessage("Ready to Grief? Have fun!");
    }
    }




    }
    and heres the plugin yml,


    name: MassGrief
    main: MassGrief.MassGriefMain
    version: 1.0

    commands:
    BOOM:
    description: This spawns a creeper on a specified player.
    usage: /<command> [player]
    permission: massgrief.BOOM
    permission-message: You can't spawn creepers!

    permissions:
    massgrief.*:
    description: Gives all access to the massgrief plugin.
    children:
    massgrief.BOOM
    massgrief.BoomRepeat
    massgrief.BOOM:
    description: Allows usage of the BOOM command.
    default: op
    massgrief.BoomRepeat:
    description: Bypasses BoomRepeat death.
    default: op


    the yml is properly spaced, it just got rearranged.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    javoris767

    Well... Lots of stuff o-O
    You need to implement Listener, register the events onEnable, and add @EventHandler on each of the events.
    If you still have problems please put the code in code lol.
    Code:
    
    
     
  5. Offline

    RangerNuk

    Um, I'm a newb to that, if u ould show me the code, that would be nice...
     
  6. Offline

    Tirelessly

    After extends JavaPlugin write implements Listener.
    Then in onEnable put getServer().getPluginManager().registerEvents(this, this);
    Then before your events just write @EventHandler.
     
  7. Offline

    RangerNuk


    I tried it, heres the error log, the code will be below. I couldn't put @EventHandler before the if permission thing cause it wanted an enum identifier, so i didn't. Heres the error log.
    13:47:38 [SEVERE] Could not load 'plugins/MassGrief.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:153)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:222)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:198)
    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at MassGrief.MassGriefMain.<init>(MassGriefMain.java:75)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:149)
    ... 9 more


    Here is the code.


    package MassGrief;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;

    public class MassGriefMain extends JavaPlugin implements Listener{



    public void onEnable(){
    getLogger().info("MassGrief has been enabled, you better hope you have rollback");

    getServer().getPluginManager().registerEvents(this, this);

    }


    public void onDisable(){
    getLogger().info("MassGrief has been disabled, are you to scared to use it?");

    }

    @EventHandler
    public void onPlayerMove(PlayerMoveEvent evt) {
    Location loc = evt.getPlayer().getLocation();
    World w = loc.getWorld();
    loc.setY(loc.getY() - 1);
    Block b = w.getBlockAt(loc);
    b.setTypeId(46);
    b.setData((byte)1);
    }

    @EventHandler
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if(cmd.getName().equalsIgnoreCase("BOOM")){
    if (args.length > 1) {
    sender.sendMessage("Too many arguments!");
    return false;
    }
    if (args.length < 1) {
    sender.sendMessage("Not enough arguments!");
    return false;
    }
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    if (target == null) {
    sender.sendMessage("The specified player is not online.");
    return false;
    }
    target.setHealth(0);
    target.getWorld().spawnCreature(target.getLocation(), CreatureType.CREEPER);
    return true;
    }

    return false;

    }


    {for(Player player: getServer().getOnlinePlayers()) {

    if(player.hasPermission("massgrief.DeathByBomb")) {
    float explosionPower = 10F;
    player.getWorld().createExplosion(player.getLocation(), (Float) explosionPower);

    }

    }











    }

    public void onPlyerJoin(PlayerJoinEvent evt) {
    Player player = evt.getPlayer();
    PlayerInventory inventory = player.getInventory();
    ItemStack itemstack = new ItemStack(Material.TNT, 1728);

    if (inventory.contains(itemstack)) {
    inventory.addItem(itemstack);
    player.sendMessage("Ready to Grief? Have fun!");
    }
    }




    }
     
  8. Offline

    Tirelessly

    MassGriefMain.java:75


    And I didn't tell you to put @EventHandler for your health, you need it. And don't put it before onCommand, as that's not an event.
     
  9. Offline

    RangerNuk

    Changed it, Im probably doing something very wrong, Im a newb.

    Error log \/

    19:57:22 [SEVERE] Could not load 'plugins/MassGrief.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:153)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:222)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:198)
    at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
    at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
    at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at MassGrief.MassGriefMain.<init>(MassGriefMain.java:75)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:149)
    ... 9 more
    Source Code \/
    package MassGrief;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;
    public class MassGriefMain extends JavaPlugin implements Listener{

    public void onEnable(){
    getLogger().info("MassGrief has been enabled, you better hope you have rollback");

    getServer().getPluginManager().registerEvents(this, this);

    }
    public void onDisable(){
    getLogger().info("MassGrief has been disabled, are you to scared to use it?");

    }
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent evt) {
    Location loc = evt.getPlayer().getLocation();
    World w = loc.getWorld();
    loc.setY(loc.getY() - 1);
    Block b = w.getBlockAt(loc);
    b.setTypeId(46);
    b.setData((byte)1);
    }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if(cmd.getName().equalsIgnoreCase("BOOM")){
    if (args.length > 1) {
    sender.sendMessage("Too many arguments!");
    return false;
    }
    if (args.length < 1) {
    sender.sendMessage("Not enough arguments!");
    return false;
    }
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    if (target == null) {
    sender.sendMessage("The specified player is not online.");
    return false;
    }
    target.setHealth(0);
    target.getWorld().spawnCreature(target.getLocation(), CreatureType.CREEPER);
    return true;
    }

    return false;

    }
    {for(Player player: getServer().getOnlinePlayers()) {

    if(player.hasPermission("massgrief.DeathByBomb")) {
    float explosionPower = 10F;
    player.getWorld().createExplosion(player.getLocation(), (Float) explosionPower);

    }

    }
    }
    public void onPlyerJoin(PlayerJoinEvent evt) {
    Player player = evt.getPlayer();
    PlayerInventory inventory = player.getInventory();
    ItemStack itemstack = new ItemStack(Material.TNT, 1728);

    if (inventory.contains(itemstack)) {
    inventory.addItem(itemstack);
    player.sendMessage("Ready to Grief? Have fun!");
    }
    }


    }
     
  10. Offline

    MrFigg

    Just poking my head into this thread for a second, didn't really read anything.

    You might wanna use [ CODE ] tags or [ SYNTAX=JAVA ] tags to make the code your posts easier to read.

    Code:
    [CODE]Example[/CODE ]
    Code:JAVA
    1. [SYNTAX=JAVA]Example[/SYNTAX]
     
  11. Offline

    RangerNuk

    ok, thx, but that doesn't help me. I'm kinda looking for plugin developers, so far the most helpful people have also made some of the best plugins. One made battle night, it was sniperzxx or something, also zavoris helped, he made auto announcer, its used on my server, its awesome, point is, people who have experiance r helpful, do u have experience? ur advice was helpful, but not what im looking for. Sorry :(
     
  12. Offline

    Muddr

    This will help you learn to read the stack traces.
    http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/

    from the last one you posted your error is on line 75.
    Code:
    Caused by: java.lang.NullPointerException
    at MassGrief.MassGriefMain.<init>(MassGriefMain.java:75)
    Also.. it really is a good idea to use [ CODE ] or [ SYNTAX=JAVA ] tags.. cause now anyone that wants to help is gonna have to reformat your code before they can read it.
     
  13. Offline

    MrFigg

    Yea, after I cleaned up your code I found a bunch of stuff wrong with it that would have been easy to spot if you had used [ CODE ] or [ SYNTAX=JAVA ] tags. Here's what I've got after some cleaning;

    plugin.yml
    - Cleaned up the plugin.yml code
    - Added default group for massgrief.*
    - Corrected format of massgrief.* children
    - Removed massgrief.BoomRepeat as it's not used
    Code:
    name: MassGrief
    main: MassGrief.MassGriefMain
    version: 1.0
     
    commands:
      BOOM:
        description: This spawns a creeper on a specified player.
        permission: massgrief.BOOM
        permission-message: You can't spawn creepers!
     
    permissions:
      massgrief.*:
        description: Gives all access to the massgrief plugin.
        default: op
        children:
          massgrief.BOOM: true
      massgrief.BOOM:
        description: Allows usage of the BOOM command.
        default: op
    MassGriefMain.java
    - Cleaned up the MassGriefMain code
    - Changed target.getWorld().spawnCreature(target.getLocation(), CreatureType.CREEPER); to target.getWorld().spawnEntity(target.getLocation(), EntityType.CREEPER); as spawnCreature is depreciated
    - Added @EventHandler to onPlayerJoin
    - Changed new ItemStack(Material.TNT, 1728) in onPlayerJoin to new ItemStack(Material.TNT, 64) as a number that high might break something
    - Changed if(inventory.contains(itemstack)) in onPlayerJoin to if(!inventory.contains(itemstack))
    - Removed the massgrief.DeathByBomb part as it's not referenced anywhere else, and I'm not even sure what you wanted to trigger it
    Code:JAVA
    1. package MassGrief;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.World;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.EntityType;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.event.player.PlayerMoveEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.inventory.PlayerInventory;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class MassGriefMain extends JavaPlugin implements Listener {
    20. public void onEnable() {
    21. getLogger().info("MassGrief has been enabled, you better hope you have rollback");
    22.  
    23. getServer().getPluginManager().registerEvents(this, this);
    24. }
    25.  
    26. public void onDisable(){
    27. getLogger().info("MassGrief has been disabled, are you to scared to use it?");
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    31. if(cmd.getName().equalsIgnoreCase("BOOM")){
    32. if(args.length > 1) {
    33. sender.sendMessage("Too many arguments!");
    34. return false;
    35. }
    36. if(args.length < 1) {
    37. sender.sendMessage("Not enough arguments!");
    38. return false;
    39. }
    40. Player s = (Player) sender;
    41. Player target = s.getServer().getPlayer(args[0]);
    42. if(target == null) {
    43. sender.sendMessage("The specified player is not online.");
    44. return false;
    45. }
    46. target.setHealth(0);
    47. target.getWorld().spawnEntity(target.getLocation(), EntityType.CREEPER);
    48. return true;
    49. }
    50. return false;
    51. }
    52.  
    53. @EventHandler
    54. public void onPlayerMove(PlayerMoveEvent evt) {
    55. Location loc = evt.getPlayer().getLocation();
    56. loc.setY(loc.getY() - 1);
    57. World w = loc.getWorld();
    58. Block b = w.getBlockAt(loc);
    59. b.setTypeId(46);
    60. b.setData((byte)1);
    61. }
    62.  
    63. @EventHandler
    64. public void onPlyerJoin(PlayerJoinEvent evt) {
    65. Player player = evt.getPlayer();
    66. PlayerInventory inventory = player.getInventory();
    67. ItemStack itemstack = new ItemStack(Material.TNT, 64);
    68. if(!inventory.contains(itemstack)) {
    69. inventory.addItem(itemstack);
    70. player.sendMessage("Ready to Grief? Have fun!");
    71. }
    72. }
    73. }


    See how much proper presentation helps?
     
    RangerNuk and Muddr like this.
  14. Offline

    RangerNuk

    Thanks, it works now. I'm just wreaking havoc on my private server.
     
  15. Offline

    exload

    Add solved tag to title pwease :)
     
Thread Status:
Not open for further replies.

Share This Page