Solved Chest fill not working

Discussion in 'Plugin Development' started by The Fancy Whale, Jul 13, 2014.

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

    The Fancy Whale

    Here is the current code:
    Code:java
    1. package tfw.SG;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Random;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.Chunk;
    8. import org.bukkit.Material;
    9. import org.bukkit.World;
    10. import org.bukkit.block.BlockState;
    11. import org.bukkit.block.Chest;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15.  
    16.  
    17. public class Reset {
    18. //leather armor, wood sword, arrows, bows, feathers, flint, stone axe, wood axe
    19.  
    20. static ArrayList<Material> tierone = new ArrayList<Material> ();
    21.  
    22. public static ItemStack randomMaterial(){
    23. tierone.clear();
    24. tierone.add(Material.LEATHER_BOOTS);
    25. tierone.add(Material.LEATHER_CHESTPLATE);
    26. tierone.add(Material.LEATHER_LEGGINGS);
    27. tierone.add(Material.LEATHER_HELMET);
    28. tierone.add(Material.WOOD_SWORD);
    29. tierone.add(Material.ARROW);
    30. tierone.add(Material.BOW);
    31. tierone.add(Material.FEATHER);
    32. tierone.add(Material.FLINT);
    33. tierone.add(Material.STONE_AXE);
    34. tierone.add(Material.WOOD_AXE);
    35. Random r = new Random();
    36. ItemStack rand = new ItemStack(tierone.get(r.nextInt(tierone.size())), 1);
    37. return rand;
    38. }
    39.  
    40. public static void fill(Inventory inv){
    41.  
    42. inv.clear();
    43. for(int i = 0; i <= 35; i++){
    44. Random r = new Random();
    45.  
    46. if(i == r.nextInt(36)){
    47. inv.setItem(i, randomMaterial());
    48. }}}
    49. public static void blocks(){
    50. for (World w : Bukkit.getWorlds()){
    51. for(Chunk c : w.getLoadedChunks()){
    52. for(BlockState b : c.getTileEntities()){
    53. if(b instanceof Chest){
    54. Inventory inv = ((Chest) b).getBlockInventory();
    55. fill(inv);
    56. }}}
    57. }
    58. }
    59.  
    60. }
    61.  

    Here is the error:
    Code:
    13.07 14:50:02 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
    13.07 14:50:02 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
    13.07 14:50:02 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
    13.07 14:50:02 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
    13.07 14:50:02 [Server] INFO at tfw.SG.Join.onJoine(Join.java:33) ~[?:?]
    13.07 14:50:02 [Server] INFO at tfw.SG.Game.startWait(Game.java:219) ~[?:?]
    13.07 14:50:02 [Server] INFO at tfw.SG.Reset.blocks(Reset.java:55) ~[?:?]
    13.07 14:50:02 [Server] INFO at tfw.SG.Reset.fill(Reset.java:47) ~[?:?]
    13.07 14:50:02 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.setItem(CraftInventory.java:82) ~[spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.TileEntityChest.setItem(TileEntityChest.java:96) ~[spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 30
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:489) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:583) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:720) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:183) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.LoginListener.a(LoginListener.java:43) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.LoginListener.c(LoginListener.java:105) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.PlayerList.a(PlayerList.java:152) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at net.minecraft.server.v1_7_R3.PlayerList.c(PlayerList.java:265) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[spigot.jar:git-Spigot-1501]
    13.07 14:50:02 [Server] INFO org.bukkit.event.EventException
    13.07 14:50:02 [Server] ERROR Could not pass event PlayerJoinEvent to Survival_Games v1.0
    And line 47 of reset is:
    Code:java
    1. inv.setItem(i, randomMaterial());

    Any help is greatly appreciated! Thanks!
     
  2. Offline

    MrKeals

    Maybe because i is a random number between 0 and 36 and for ChestInventory is between 0 and 26
     
    The Fancy Whale likes this.
  3. Offline

    The Fancy Whale

    MrKeals Just noticed that after posting but thanks anyway!
     
Thread Status:
Not open for further replies.

Share This Page