Search in sources :

Example 1 with NoteBlock

use of org.bukkit.block.data.type.NoteBlock in project oraxen by oraxen.

the class NoteBlockMechanicListener method onBreakingCustomBlock.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreakingCustomBlock(final BlockBreakEvent event) {
    final Block block = event.getBlock();
    if (block.getType() != Material.NOTE_BLOCK || event.isCancelled() || !event.isDropItems())
        return;
    final NoteBlock noteBlok = (NoteBlock) block.getBlockData();
    final NoteBlockMechanic noteBlockMechanic = NoteBlockMechanicFactory.getBlockMechanic((int) (noteBlok.getInstrument().getType()) * 25 + (int) noteBlok.getNote().getId() + (noteBlok.isPowered() ? 400 : 0) - 26);
    if (noteBlockMechanic == null)
        return;
    if (noteBlockMechanic.hasBreakSound())
        block.getWorld().playSound(block.getLocation(), noteBlockMechanic.getBreakSound(), 1.0f, 0.8f);
    if (noteBlockMechanic.getLight() != -1)
        WrappedLightAPI.removeBlockLight(block.getLocation());
    noteBlockMechanic.getDrop().spawns(block.getLocation(), event.getPlayer().getInventory().getItemInMainHand());
    event.setDropItems(false);
}
Also used : NoteBlock(org.bukkit.block.data.type.NoteBlock) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) EventHandler(org.bukkit.event.EventHandler)

Example 2 with NoteBlock

use of org.bukkit.block.data.type.NoteBlock in project oraxen by oraxen.

the class NoteBlockMechanicListener method onInteract.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInteract(final PlayerInteractEvent event) {
    final Block block = event.getClickedBlock();
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || block == null || block.getType() != Material.NOTE_BLOCK) {
        return;
    }
    final NoteBlock noteBlock = (NoteBlock) block.getBlockData();
    final NoteBlockMechanic noteBlockMechanic = NoteBlockMechanicFactory.getBlockMechanic((int) (noteBlock.getInstrument().getType()) * 25 + (int) noteBlock.getNote().getId() + (noteBlock.isPowered() ? 400 : 0) - 26);
    if (noteBlockMechanic != null) {
        noteBlockMechanic.runClickActions(event.getPlayer());
    }
    final ItemStack clicked = event.getItem();
    event.setCancelled(true);
    if (clicked == null) {
        return;
    }
    Material type = clicked.getType();
    if (type.isInteractable()) {
        return;
    }
    if (type == Material.LAVA_BUCKET) {
        type = Material.LAVA;
    } else if (type == Material.WATER_BUCKET) {
        type = Material.WATER;
    }
    if (type.isBlock()) {
        makePlayerPlaceBlock(event.getPlayer(), event.getHand(), clicked, block, event.getBlockFace(), Bukkit.createBlockData(type));
    }
}
Also used : NoteBlock(org.bukkit.block.data.type.NoteBlock) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 3 with NoteBlock

use of org.bukkit.block.data.type.NoteBlock in project Nexus by ProjectEdenGG.

the class Pugmas21Command method randomizePresents.

@Path("randomizePresents")
@Permission(Group.ADMIN)
@Description("Randomizes the presents in your selection")
void randomizePresents() {
    List<Instrument> instruments = List.of(Instrument.DIDGERIDOO, Instrument.PLING);
    WorldEditUtils WEUtils = new WorldEditUtils(player());
    Region selection = WEUtils.getPlayerSelection(player());
    for (Block block : WEUtils.getBlocks(selection)) {
        if (block.getType() != Material.NOTE_BLOCK)
            continue;
        NoteBlock noteBlock = (NoteBlock) block.getBlockData();
        noteBlock.setInstrument(RandomUtils.randomElement(instruments));
        noteBlock.setNote(new Note(RandomUtils.randomInt(0, 24)));
        block.setBlockData(noteBlock);
    }
}
Also used : NoteBlock(org.bukkit.block.data.type.NoteBlock) WorldEditUtils(gg.projecteden.nexus.utils.WorldEditUtils) Note(org.bukkit.Note) Instrument(org.bukkit.Instrument) Region(com.sk89q.worldedit.regions.Region) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission)

Example 4 with NoteBlock

use of org.bukkit.block.data.type.NoteBlock in project Glowstone by GlowstoneMC.

the class BlockNote method updateInstrument.

public void updateInstrument(GlowBlock block) {
    NoteBlock noteBlockData = getNoteBlockData(block);
    noteBlockData.setInstrument(instrumentOf(block.getRelative(BlockFace.DOWN).getType()));
}
Also used : NoteBlock(org.bukkit.block.data.type.NoteBlock)

Example 5 with NoteBlock

use of org.bukkit.block.data.type.NoteBlock in project Glowstone by GlowstoneMC.

the class BlockNote method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    NoteBlock noteBlockData = getNoteBlockData(block);
    Note note = noteBlockData.getNote();
    noteBlockData.setNote(note.getId() == NOTES_COUNT ? new Note(0) : note.sharped());
    block.setBlockData(noteBlockData);
    return false;
}
Also used : NoteBlock(org.bukkit.block.data.type.NoteBlock) Note(org.bukkit.Note)

Aggregations

NoteBlock (org.bukkit.block.data.type.NoteBlock)7 Block (org.bukkit.block.Block)5 EventHandler (org.bukkit.event.EventHandler)3 Note (org.bukkit.Note)2 ItemStack (org.bukkit.inventory.ItemStack)2 ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)1 Region (com.sk89q.worldedit.regions.Region)1 Description (gg.projecteden.nexus.framework.commands.models.annotations.Description)1 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)1 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)1 WorldEditUtils (gg.projecteden.nexus.utils.WorldEditUtils)1 HardnessModifier (io.th0rgal.oraxen.utils.breaker.HardnessModifier)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Instrument (org.bukkit.Instrument)1 Location (org.bukkit.Location)1 Tone (org.bukkit.Note.Tone)1 BlockFace (org.bukkit.block.BlockFace)1 Player (org.bukkit.entity.Player)1