Can't get chest

Discussion in 'Plugin Development' started by cdnyassuo34, Dec 4, 2019 at 2:55 PM.

  1. Offline

    cdnyassuo34

    Hi, I am making a plugin which recquires to get chest and register them on start.
    but , it is not working, Here is the code:
    Code:
    getServer().getPluginManager().registerEvents(this, this);
            getCommand("createcrate").setExecutor(this);
            getCommand("editcrate").setExecutor(this);
            getCommand("getkeycrate").setExecutor(this);
            getCommand("destroycrate").setExecutor(this);
            saveDefaultConfig();
            System.out.println(RED + "[" +  BLUE + "SnowCrates" + RED + "]" + BLUE + " plugin started with no errors. if you need any help to setup the plugin contact me with discord: LON Snowdingerr#3265" + RESET);
            for(String s : getConfig().getStringList("crates"))
            {
                System.out.println("[SnowCrates] Loading a Crate...");
                String[] str = s.split("&");
                Location loc = new Location(Bukkit.getWorld(str[0]), Integer.parseInt(str[1]), Integer.parseInt(str[2]), Integer.parseInt(str[3]));
                crates.add(loc);
                Chest chest = (Chest) loc.getWorld().getBlockAt(loc).getState(); // here is line 156
                ArmorStand armorStand = (ArmorStand) chest.getWorld().spawnEntity(new Location(chest.getWorld(),chest.getLocation().getX() + 0.5,chest.getLocation().getY(),chest.getLocation().getZ() + 0.5) , EntityType.ARMOR_STAND);
                armorStand.setCustomName(str[4]);
                armorStand.setCustomNameVisible(true);
                armorStand.setVisible(false);
                armorStand.setGravity(false);
                armorStand.setInvulnerable(true);
                armorStand.setSmall(true);
                crates.add(chest.getLocation());
                ExistingCrates.put(chest,armorStand);
                System.out.println("crate has been loaded");   
            }
    
    and the error:
    Code:
    [23:48:10] [Server thread/ERROR]: Error occurred while enabling SnowCrates v1.1 (Is it up to date?)
    java.lang.NullPointerException: null
        at fr.snowdingerr.snowcrates.mainclass.onEnable(mainclass.java:156) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.14.4.jar:git-Paper-225]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:338) ~[patched_1.14.4.jar:git-Paper-225]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:420) ~[patched_1.14.4.jar:git-Paper-225]
        at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:467) ~[patched_1.14.4.jar:git-Paper-225]
        at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:381) ~[patched_1.14.4.jar:git-Paper-225]
        at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:474) ~[patched_1.14.4.jar:git-Paper-225]
        at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:290) ~[patched_1.14.4.jar:git-Paper-225]
        at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:876) ~[patched_1.14.4.jar:git-Paper-225]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
    
    
    if anyone find a solution for this I would be very happy ^^
    thanks for any help that will be given^^
     
  2. Offline

    yPedx

    @cdnyassuo34
    What is line 156 in mainClass? Keep in mind that you r classnames should be PascalCased.
     
    Last edited: Dec 5, 2019 at 11:25 AM
  3. Online

    timtower Moderator Moderator

    @yPedx He commented the line.

    @cdnyassuo34 Get the block first, then check the type of the block, then get the state.
     
  4. Offline

    Strahan

    *shudder* Relying on string splits is a sh**t way to store data. YAML is hierarchical, use that to your advantage.

    That's PascalCase. camelCase is like this.
     
  5. Offline

    yPedx

    Ah, didn't notice.

    Hehe woops, my fault. I'll edit that in, just in case.
     

Share This Page