Solved Using the Cauldron Class

Discussion in 'Plugin Development' started by mobkinz78, May 18, 2015.

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

    mobkinz78

    Hi there, I am VERY new to Bukkit development and was curious about the Cauldron Class. If I wanted to check if a cauldron was full, what would be the most efficient way to check a specific cauldron? I'm confused as to how I would check any cauldron, but even more so about a specific one.

    Ex. Two cauldrons on opposite ends of an arena, and I want to check both of them. I don't know how to check a specific cauldron, however.

    Thanks in advance!
     
  2. Firstly, you could store the Location of the cauldron(s) into a Map of arenas and their Location. However, I think storing Locations is bad practice because the Location contains the 'world' variable, leading to memory leaks. So you could make your own kind of Location class. Then, you could do:

    Code:
    Block block = location.getBlock(); // Get the block where the location is.
    if (block.getState().getData() instanceof Cauldron) { // Check if the block has the data of a cauldron.
        Cauldron cauldron = (Cauldron) block.getState().getData(); // Get the cauldron data from the block.
        if (cauldron.isFull()) {
            // Do code
        }
    }
    

    Or if you want to do it the easy way, but may change because of new data states:
    Code:
    Block block = location.getBlock();
    if (block.getType() == Material.CAULDRON) {
        if (block.getData() == 3) {
            // It is full
        }
    }
    
     
    Last edited: May 18, 2015
  3. Offline

    mobkinz78

    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page