Solved Open Iron Door? Door deprecated?

Discussion in 'Plugin Development' started by LegoPal92, Jan 1, 2014.

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

    LegoPal92

    Welp, here we go.

    I have to open an iron door, and my code for a wooden door using door still works, even though it is deprecated. However, the same code does not work for an iron door. I'm just using door.setOpen(true);
    What should I use for an iron door?
     
  2. Offline

    NathanWolf

    I'm guessing this is because an iron door won't stay open unless activated by redstone... ?
     
  3. Offline

    LegoPal92

    Well, I just tried changing the block below it to a redstone block, and it still would not open.
     
  4. Offline

    Oo-Zakk-oO

    LegoPal92 im not sure how it would work but i think you need to break the door and replace it with an opened iron door im not sure never done something like this
     
  5. Don't use Door, but use Openable. Door is deprecated for a reason. Like this:

    Code:java
    1. Block door; //Assume this is the bottom door block
    2. BlockState state = door.getState()
    3. MaterialData data =state.getData();
    4. Openable opn = (Openable) data //Cast data to Openable
    5. opn.setOpen(true) // Open the door
    6. state.setData(opn) // Add the data to the BlockState
    7. state.update() //Update the BlockState, the door will now open
    8.  
    9.  
    10.  


    https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/material/Openable.java
     
    LegoPal92 likes this.
  6. Offline

    LegoPal92

    Thank you! That should, hopefully work! I'll mark as solved if it does.

    Pulsior
    Well, it didn't work, the door still does not open. There are no errors in the console. I'm using Openable door = (Openable) block.getState().getData();
    door.setOpen(true);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. -Are you working with the lower door block?. For some reason, it does not work with the upper block, you need to get the lower block.

    -Do you also use block.getState().setData(openable); and block.getState().update();? Try adding these lines if you don't.
     
  8. Offline

    LegoPal92

    Whoops, I forgot the setData, let me try that real quick, and I'll edit this post.

    EDIT: Also did not work.
     
  9. Did you update the BlockState as well? Can you post all your code?
     
  10. Offline

    LegoPal92

    I can't post all of it, but I will post the relevant parts, its for a plugin that I don't like sharing the code from.

    PHP:
                        Block block e.getClickedBlock();
                        final 
    Openable door = (Openableblock.getState().getData();
     
                        if (
    r.nextInt(100) < 100){
                                                     
                            if (((
    Doordoor).isTopHalf()) {
                                
    block block.getRelative(BlockFace.DOWN);
                            }
                            
    door.setOpen(true);
                            
    block.getState().setData((MaterialData)door);
                            
    block.getState().update();
     
                            
    data.Player.giveExp(1);
                            
    this.getServer().getScheduler()
                                    .
    scheduleSyncDelayedTask(this, new Runnable() {
                                        @
    Override
                                        
    public void run() {
     
                                            
    Block block e.getClickedBlock();
                                            if (
    block.getType() == Material.TRAP_DOOR
                                                    
    || block.getType() == Material.WOOD_DOOR
                                                    
    || block.getType() == Material.IRON_DOOR_BLOCK) {
                                                
    data.Player.sendMessage("after check in runnable -D-");
                                                
    BlockState state block.getState();
                                                
    door.setOpen(false);
                                                
    state.update();
                                                
    block.getState().setData((MaterialData)door);
                                            } else {
                                                
    byte data block.getData();
                                                if ((
    data 0x8) == 0x8) {
                                                    
    block block
                                                            
    .getRelative(BlockFace.DOWN);
                                                    
    data block.getData();
                                                }
                                                if (!
    door.isOpen()) {
                                                    
    data = (byte) (data 0xb);
                                                    
    block.setData(datatrue);
                                                    
    block.getWorld().playEffect(
                                                            
    block.getLocation(),
                                                            
    Effect.DOOR_TOGGLE0);
                                                }
     
                                            }
     
                                        }
     
                                    }, 
    60L);
     
                        }
     
  11. Offline

    BillyGalbreath

  12. Try to get the BlockState once. By invoking getState() all the time, you get a new state and lose your changes. Like:
    BlockState state = block.getState();
    Openable o = (Openable) state.getData();
    o.setOpen(true)
    state.setData(o)
    state.update()

    By the way, you don't have to cast the openable back to MaterialData when setting the data.
     
    LegoPal92 likes this.
  13. Offline

    LegoPal92

    Well, it told me I have to. It wouldn't work otherwise.
    But, I just tried it, and That worked! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page