Java 类org.bukkit.material.Openable 实例源码

项目:LapisPortals    文件:PlayerListener.java   
@EventHandler(priority = EventPriority.HIGH)
public void onRightClickDoor(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block block = event.getClickedBlock();

        if (block.getType() == Material.IRON_DOOR_BLOCK) {
            if (block.getRelative(BlockFace.DOWN).getType() == Material.IRON_DOOR_BLOCK)
                block = block.getRelative(BlockFace.DOWN);

            if (EnderPortals.getFileHandler().isPortalDoor(block)) {
                BlockState state = block.getState();
                Openable door = (Openable) state.getData();
                door.setOpen(!door.isOpen());
                state.update();
            }
        }
    }
}
项目:BlockLocker    文件:ContainerProtectionImpl.java   
private boolean setBlockOpen(Block block, boolean open) {
    MaterialData materialData = BlockData.get(block);
    if (!(materialData instanceof Openable)) {
        return false;
    }

    Openable openable = (Openable) materialData;
    if (openable.isOpen() == open) {
        return false;
    }

    // Change the state
    openable.setOpen(open);
    BlockData.set(block, materialData);
    return true;
}
项目:BlockLocker    文件:AttachedProtectionImpl.java   
@Override
public void setOpen(boolean open, SoundCondition playSound) {
    MaterialData materialData = BlockData.get(protecionBlock);
    if (!(materialData instanceof Openable)) {
        return;
    }

    Openable openable = (Openable) materialData;

    if (openable.isOpen() == open) {
        return;
    }

    openable.setOpen(open);
    BlockData.set(protecionBlock, materialData);

    if (playSound == SoundCondition.ALWAYS) {
        Sound sound = OpenBlockSound.get(materialData.getItemType(), open);
        protecionBlock.getWorld().playSound(protecionBlock.getLocation(), sound, 1f, 0.7f);
    }
}
项目:BetonQuest    文件:DoorEvent.java   
@Override
public void run(String playerID) throws QuestRuntimeException {
    Block block = loc.getLocation(playerID).getBlock();
    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Openable) {
        Openable openable = (Openable) data;
        switch (type) {
        case ON:
            openable.setOpen(true);
            break;
        case OFF:
            openable.setOpen(false);
            break;
        case TOGGLE:
            openable.setOpen(!openable.isOpen());
            break;
        }
        state.setData((MaterialData) openable);
        state.update();
    }
}
项目:KingdomFactions    文件:PlayerInteractEventListener.java   
public void onPlayerInteract(PlayerInteractEvent e) {
    if (e.isCancelled()) return;
     KingdomFactionsPlayer p = PlayerModule.getInstance().getPlayer(e.getPlayer());        
        if(p.getSettingsProfile().hasAdminMode()) return;
    if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        if (e.getClickedBlock() == null) return;

        Block clickedBlock = e.getClickedBlock();


        if (clickedBlock.getType().equals(Material.CHEST) || clickedBlock.getType().equals(Material.TRAPPED_CHEST) || clickedBlock.getType().equals(Material.BEACON)) {
            e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 500));
            return;
        }

        if (clickedBlock.getType().equals(Material.BURNING_FURNACE) || clickedBlock.getType().equals(Material.FURNACE) || clickedBlock.getType().equals(Material.DISPENSER) || clickedBlock.getType().equals(Material.HOPPER) || clickedBlock.getType().equals(Material.DROPPER)) {
            e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
            return;
        }

        MaterialData data = clickedBlock.getState() != null ? clickedBlock.getState().getData() : null;
        if (data instanceof Openable) {
            if (clickedBlock.getType() == Material.IRON_TRAPDOOR || clickedBlock.getType() == Material.IRON_DOOR) return;
            e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
            return;
        }
    }
}
项目:RedProtect    文件:RPDoor.java   
private static void toggleDoor(Block b){
    if (b.getRelative(BlockFace.DOWN).getType().equals(b.getType())){
        b = b.getRelative(BlockFace.DOWN);          
    } 
    BlockState state = b.getState();
    Openable op = (Openable) state.getData();
    op.setOpen(!op.isOpen());
    state.setData((MaterialData)op);
    state.update(); 
}
项目:BlockLocker    文件:ContainerProtectionImpl.java   
@Override
public boolean canBeOpened() {
    for (Block block : blocks) {
        if (Openable.class.isAssignableFrom(block.getType().getData())) {
            return true;
        }
        // Only try first block, as all blocks should be of the same type
        return false;
    }
    return false;
}
项目:BlockLocker    文件:ContainerProtectionImpl.java   
@Override
public boolean isOpen() {
    for (Block block : blocks) {
        MaterialData materialData = BlockData.get(block);
        if (materialData instanceof Openable) {
            return ((Openable) materialData).isOpen();
        }
    }
    return false;
}
项目:BlockLocker    文件:AttachedProtectionImpl.java   
@Override
public boolean isOpen() {
    MaterialData materialData = BlockData.get(protecionBlock);
    if (materialData instanceof Openable) {
        return ((Openable) materialData).isOpen();
    }
    return false;
}
项目:RedProtect    文件:RPDoor.java   
public static boolean isOpenable(Block b){
    return b.getState().getData() instanceof Openable;  
}
项目:BlockLocker    文件:AttachedProtectionImpl.java   
@Override
public boolean canBeOpened() {
    return Openable.class.isAssignableFrom(protecionBlock.getType().getData());
}