Solved How to set certain blocks to obsidian without involving a player in code.

Discussion in 'Plugin Development' started by Honeyjuice14, Dec 19, 2014.

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

    Honeyjuice14

    What i am trying to do is make the blocks in a 6 block radius from (0,0) change to obsidian every hour or so. The problem is that 'Block b = p.getLocation().getWorld().getBlockAt(x,y,z);' this works when i involve a player, but i would like it to run even when no one is online and i dont want it to have to involve any player variables.
    Ultimately, what should i put on line 6 instead?

    Code:
        public void resetChest() {
            int radius = 6;
            for (int y = 70; y < 82; y++) {
                for (int x = -radius; x < radius; x++) {
                    for (int z = -radius; z < radius; z++) {
                        Block b = p.getLocation().getWorld().getBlockAt(x,y,z);
                        if ((x == 0) && (z == 0) && (y == 76)){ //first chest
                            b.setType(Material.CHEST);
                        }
                        if ((x == -0) && (z == -0) && (y == 76)){ //2nd chset
                            b.setType(Material.CHEST);
                        }else{
                            b.setType(Material.AIR);//Air for testing, change later
                        }
                    }
                }
            }
        }
     
  2. Offline

    NathanWolf

    You will need to either hard-code or put in a config the world you want to do this in. (e.g. 'world')

    You can then call getServer().getWorld('world').getBlockAt().
     
    Honeyjuice14 likes this.
  3. Offline

    Honeyjuice14

    Thank you, i simply replaced line 6 with
    Block b = getServer().getWorld("world").getBlockAt(x,y,z);
    and it works perfectly.
     
    NathanWolf likes this.
  4. Offline

    NathanWolf

    Great! Just be aware that not all servers use "world" as their default world. And please mark the thread as Solved so everyone knows you're good :)
     
Thread Status:
Not open for further replies.

Share This Page