org.bukkit.block.data.Openable Java Examples

The following examples show how to use org.bukkit.block.data.Openable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EffToggle.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(final Event e) {
	if (!flattening) {
		executeLegacy(e);
		return;
	}
	
	// 1.13 and newer: use BlockData
	for (Block b : blocks.getArray(e)) {
		BlockData data = b.getBlockData();
		if (toggle == -1) {
			if (data instanceof Openable)
				((Openable) data).setOpen(false);
			else if (data instanceof Powerable)
				((Powerable) data).setPowered(false);
		} else if (toggle == 1) {
			if (data instanceof Openable)
				((Openable) data).setOpen(true);
			else if (data instanceof Powerable)
				((Powerable) data).setPowered(true);
		} else {
			if (data instanceof Openable) // open = NOT was open
				((Openable) data).setOpen(!((Openable) data).isOpen());
			else if (data instanceof Powerable) // power = NOT power
				((Powerable) data).setPowered(!((Powerable) data).isPowered());
		}
		
		b.setBlockData(data);
	}
}
 
Example #2
Source File: BlockAdapterBlockData.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void openDoor(Block block) {
    if (!(block.getBlockData() instanceof Openable)) {
        throw new IllegalArgumentException("Block is not Openable");
    }
    Openable data = (Openable) block.getBlockData();
    data.setOpen(true);
    block.setBlockData(data);
}
 
Example #3
Source File: BlockAdapterBlockData.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void closeDoor(Block block) {
    if (!(block.getBlockData() instanceof Openable)) {
        throw new IllegalArgumentException("Block is not Openable");
    }
    Openable data = (Openable) block.getBlockData();
    data.setOpen(false);
    block.setBlockData(data);
}
 
Example #4
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void toggleDoor(Block b) {
    if (b.getBlockData() instanceof Openable) {
        Openable openable = (Openable) b.getBlockData();
        openable.setOpen(!openable.isOpen());
        b.setBlockData(openable);
    }
}
 
Example #5
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOpenable(Block b) {
    return b.getBlockData() instanceof Openable;
}