My plugin crashes clients and corrupts maps...why?

Discussion in 'Plugin Development' started by Lookatmego, Sep 14, 2011.

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

    Lookatmego

    This new plugin ive been working on basically does what the title says...here is the main class: http://pastie.org/2534317


    and the blocklistener: http://pastie.org/2534318


    soo any idea?i dont know whats causing it i also have no idea what to do to stop it please help thanks



    (ps. the point of the plugin is to check if the random number chosen is 1-10 if it is any of those numbers it drops the designated food item if it is above 10 then drops air meaning drops nothing at all.....)
     
  2. Offline

    Taco

    This is your issue:
    b.getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.AIR, 0));
    A stack of air is a null item and will cause a client to crash because it can't process an item that's trying to exist yet it doesn't.

    Edit: You can probably remove that line entirely. I also suggest that long chunk of if statements to contain else if rather than if so that it doesn't have to do all the work every time.

    By that I mean the line where it says:

    if (rand == 1)

    if (rand == 2)

    if (rand == 3)

    if (rand == 4)

    I suggest making it like this:

    if (rand == 1)

    else if (rand == 2)

    else if (rand ==3)

    else if (rand ==4)

    etc...
     
  3. Offline

    Lookatmego

    hmm i thought that would cause a problem so how would i make it so if the random number is bigger than 10 it drops nothing??
     
  4. Offline

    Taco

    Simply don't have a statement for a number bigger than 10. If it's bigger than 10, there will be nothing for it to do, therefore nothing will drop.
     
  5. Offline

    Lookatmego

    alright thanks dude!:D
     
  6. Offline

    Taco

    No problem! :D
     
  7. Offline

    ALFONSO

    that or just use switch :p
     
  8. Offline

    Choelian

    That's what I was thinkin'

     
  9. Offline

    DrAgonmoray

    that is also what i was thinking :D
     
Thread Status:
Not open for further replies.

Share This Page