How Do I fix this

Discussion in 'Plugin Development' started by Sil3nt_Aassassin, Aug 14, 2014.

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

    XrusherX

    What line are you getting the error on?
     
  2. Offline

    XrusherX

    Sil3nt_Aassassin
    Try this:
    World w = Bukkit.getServer().getWorld(getConfig().getString("world"));
     
  3. nope still get the same error XrusherX
     
  4. Offline

    XrusherX

    Is your config file empty?
     
  5. Offline

    XrusherX

  6. XrusherX What is the code for that again?
     
  7. Offline

    Necrodoom

  8. Offline

    Necrodoom

  9. Anyone else help?
     
  10. Offline

    PureGero

    You are calling random.nextInt with the max value from localContents.size().
    The error "n must be positive" simply means localContents.size() is returning a number smaller than 1 (ie 0).
    To fix this error simply add an if statement to check if localContents.size() is larger than 0.
    Code:
            List<ItemStack> localContents = new ArrayList(this.contents);
            if ( localContent.size() > 0 ) // Check if n is positive
            for (int i = 0; i < this.maxUnique; i++) {
              do
              {
                ItemStack stack = ((ItemStack)localContents.get(random.nextInt(localContents.size()))).clone();
                if (!chest.getInventory().contains(stack.getType()))
                {
                  chest.getInventory().setItem(i, stack);
                  localContents.remove(stack);
                }
              } while (chest.getInventory().getItem(i) == null);
            }
     
Thread Status:
Not open for further replies.

Share This Page