Help with my Infinite items plugin

Discussion in 'Plugin Development' started by alex123099, Apr 22, 2011.

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

    alex123099

    I have made a plugin that maxes all your items until you turn it off
    The problem is that it maxes it only once and thats it
    and also each time I use it than I receive this error. The plugin works.
    I think that the error is cause because sometimes my inventory isnt full and thus some of the array cells are null. The code is below.

    Code:
    02:32:12 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'infi niteitems' in plugin infiniteItems v1 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80 ) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:2 54) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler. java:650) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:613) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:607) at net.minecraft.server.Packet3Chat.a(SourceFile:36) at net.minecraft.server.NetworkManager.a(NetworkManager.java:195) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:73) at net.minecraft.server.NetworkListenThread.a(SourceFile:100) at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:370) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:285) at net.minecraft.server.ThreadServerApplication.run(SourceFile:394) Caused by: java.lang.NullPointerException at com.alex.infiniteItems.infiniteItems.onCommand(infiniteItems.java:87) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35) ... 12 more
    and a question, how can I do that my items always stay stacked as 64 until i toggle off the plugin?
    I have tried using a while loop but it didnt help.
    here's the code i wrote:

    Code:
    public boolean onCommand(CommandSender sender,Command command,String label,String[] args) { if (sender instanceof Player) { Player p=(Player)sender; if (command.getName().equalsIgnoreCase("infiniteitems")){ toggleVision(p); while(enabled(p)){ ItemStack[] stack = p.getInventory().getContents(); for(int i=0;i<stack.length;i++) stack.setAmount(64); } return true; } } return false; }
     
  2. Try doing a check in the for loop that if the stack amount is already 64 then skip it.

    for(int i=0;i<stack.length;i++){
    if(!stack.getAmount() == 64){
    stack.setAmount(64);
    return true;
    }
    return false;
    }

    //I'm not sure if getAmount() works, never used it before. Might be stack.amount or something else.
     
  3. Offline

    Acrobot

    while(enabled(p)){ ItemStack[] stack = p.getInventory().getContents(); for(int i=0;i<stack.length;i++) stack.setAmount(64);

    This will probably lag/crash the server.

    Also, what does your 87th line look like?
     
  4. Offline

    Xaw4

    i don't think your infinite loop is a good idea.

    its probably better to react on an event (i.e. onBlockplaced()) and then stock the inventory up...
     
  5. Offline

    alex123099

    I know, but I have played the single player and I had a mod which had the infiniteitems command, so I wanted to make it for multiplayer.
     
Thread Status:
Not open for further replies.

Share This Page