Solved CrackShot API help

Discussion in 'Spigot Plugin Development' started by NiekGC, Jan 13, 2018.

  1. Hello,

    I am making an plugin where are refille chests but, if i want guns in the chest i got an error in the console

    Code:
    Code (Text):
    public static void refullStart() {
            Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.pl, new Runnable(){
                @SuppressWarnings({"unused" })
                @Override
                 public void run(){
                    for (Chunk c : Bukkit.getWorld("world").getLoadedChunks()) {

                        for (BlockState b : c.getTileEntities()) {

                            if (b instanceof Chest) {
                                Chest chest = (Chest) b;
                             
                                Inventory inventory = chest.getBlockInventory();
                                if(inventory.getName().contains("Supply")) {
                                 
                                } else {
                                inventory.clear();

                                List<String> list = Main.pl.getConfig().getStringList("itemsInChest");
                                List<String> list2 = Main.pl.getConfig().getStringList("gunsInChest");
                                for(String st : list) {
                                ItemStack air = new ItemStack(Material.AIR);
                                ItemStack items = new ItemStack(Material.valueOf(st));
                                ItemStack gun = Main.guns.generateWeapon("BAZOOKA");
                                ItemStack[] randomItens = {air, air, air, air, items, gun};
                             

                             
                                for (int i = 0; i < 4; i++) {
                                    Random rand = new Random();
                                    //int intRandom1 = rand.nextInt(35) + 9;
                                    //int intItens = rand.nextInt(randomItens.length);

                                    Random slotnum = new Random();
                                    int slot = slotnum.nextInt(inventory.getSize());
                                    int max = 3;
                                    for (int amountOfItems = 0; amountOfItems < max; amountOfItems++) {
                                        inventory.setItem(slot, new ItemStack(randomItens[rand.nextInt(randomItens.length)]));

                                        }
                                }
                                    }
                                    }
                                }
                                }
                     
                             
                       
                         
                        }
                    for(Player p : Bukkit.getOnlinePlayers()) {
                    p.sendMessage(ChatColor.GREEN + "Chest reflilled");
                    }
                }
             
             
            }, 20, 20 * (60 * 4));
         
        }
    Error:
    Code (Text):
    [PUBG] Task #6540 for PUBG v1.0 generated an exception
    java.lang.NullPointerException
            at me.NiekGC.PUBG.Chests.Refill$1.run(Refill.java:44) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[1.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [1.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [1.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [1.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [1.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [1.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    Error is at this line:
    Code (Text):
    ItemStack gun = Main.guns.generateWeapon("BAZOOKA");
     
    #1 NiekGC, Jan 13, 2018
    Last edited: Jan 13, 2018
  2. Can Someone help?
     
  3. What's your generateWeapon method like, could you post that void please.
     
  4. I doubt its getting to 'guns', do a null check for both Main and 'guns'
     
  5. Now i see Main.guns is null
     
  6. But i can't found out how to fix it?
     
  7. Without seeing all (yes... all) your code we can't help! You have to see how and where 'guns' gets initialised, whether a value is set, how a value is set etc..
     
  8. Have you added the weapon "bazooka" into the crackshot config?
     
    • Useful Useful x 1
  9. I don't remember was it case sensitive when it came to weapons, but it would have to be BAZOOKA with caps because

    Code (Text):
    ItemStack gun = Main.guns.generateWeapon("BAZOOKA");
     
  10. I already fixed it
     
  11. Mark it as solved and if you could explain what you did to fix it so others with this problem can solve their issue aswell, thanks.
     
  12. I did it so
    I added
    Code (Text):
    classOne = ((CSDirector)Bukkit.getServer().getPluginManager().getPlugin("CrackShot"));
            classTwo = classOne.csminion;
    and as example you do classTwo.vendingMachine(TYPE) instead of classTwo.generateWeapon(TYPE)
     

Share This Page