Block manipulation in public void run()

Discussion in 'Plugin Development' started by ReadySetPawn, Jul 21, 2014.

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

    ReadySetPawn

    I've been trying all last night to make a mingame where lava rises one block every 5 seconds but I cannot target specific blocks in a public void run() method.

    Anybody know how I could duplicate every block of lava in the world and place it one block higher than the previous lava block?

    Thanks :)
     
  2. Offline

    Saladoc

    In the whole world would be a lot of blocks to check, since you have to loop over all the blocks there are. You may want to limit that to an arena.
    Also there should not be any problem if you get blocks by accessing the API as long as your task runs synchronously.
     
  3. Offline

    TeeePeee

    Why can't you target specific blocks in a Runnable#run() method? Seems to me you can just do this:

    Code:java
    1. public class LavaRaiser implements BukkitRunnable {
    2.  
    3. private final World world;
    4.  
    5. public LavaRaiser(World world) {
    6. this.world = world;
    7. }
    8.  
    9. @Override
    10. public void run() {
    11. // Use the world to find blocks and manipulate to your heart's desire.
    12. }
    13. }


    Code:java
    1. /**
    2. * Returns a BukkitTask of the LavaRaiser...
    3. *
    4. */
    5. public BukkitTask startGame(JavaPlugin plugin, World world) {
    6. LavaRaiser raiser = new LavaRaiser(world);
    7. return plugin.getServer().getScheduler().runTaskTimer(plugin, raiser, ...);
    8. }


    You can only manipulate synchronously anyways, so you can just use
    Code:java
    1. Bukkit.getWorld(...);

    to manipulate blocks... I don't understand your issue.
     
  4. Offline

    ReadySetPawn

    What if it's in a void world? Would it still loop through the air blocks?
     
  5. Offline

    Saladoc

    What the hell is a void world?
     
  6. Offline

    fireblast709

    Saladoc likes this.
  7. Offline

    ReadySetPawn

    Thanks :)

    I'll try that

    Here's my code:

    private final World world;

    public Lava(World world){
    this.world = world;
    }

    private final Block block;

    public Lava(Block block){
    this.block = block;
    }

    When I only have one private final, it has no errors but when I add another, it gives "The blank final field world may not have been initialized" error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    fireblast709

  9. Offline

    ReadySetPawn

  10. Offline

    xTrollxDudex

  11. Offline

    fireblast709

    ReadySetPawn in the Block constructor you can use getWorld(), but the World constructor doesn't have a specific block, so you have to scrap that one
     
  12. Offline

    TeeePeee

    ReadySetPawn
    In the Lava(World world), make block = null. In the Lava(Block block), make world = null.
     
  13. Offline

    fireblast709

    TeeePeee NullPointerExceptions for you sir
     
  14. Offline

    TeeePeee

    fireblast709
    if(world==null) { block isn't null. }
    else { world isn't null. }

    Easily distinguished. NPEs go byebye.

    Perhaps I initially misunderstood. I see in your post each Lava has a certain block associated with it. The way I'm suggesting, it's possible to have a world (to scan an area perhaps for blocks) or just specify one block.
     
  15. Offline

    DevilMental

    Doesn't a Block have a Location and a Location have a World ? What is the use of the constructor with the World arg ?

    ~DevilMental
     
  16. Offline

    fireblast709

    DevilMental optimally they would be merged in one constructor. Since Block has a World reference, the Block constructor would suffice
     
  17. Offline

    mythbusterma

    But you have to know which world to operate on, unless he's making a scheduled task for each lava block 0.0
     
  18. Offline

    DevilMental

    fireblast709 Yes, that's what I pointed out ;)
    mythbusterma Actually, you can get the block's location, in which you can get the world, so why having two constructors ?

    ~DevilMental

    Oh, that's what I meant in my previous posts, but thank you for telling me ;)
    fireblast709
    EDIT : I made a doublepost, sorry for that, I thought you replied to me so I answered ;)

    ~DevilMental

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  19. Offline

    fireblast709

  20. Offline

    mythbusterma

    I understand that , but I was under the impression he was creating one scheduler per World, and passing in a Block for that wouldn't make any sense. I don't think two constructors makes any sense either.
     
Thread Status:
Not open for further replies.

Share This Page