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);
}
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));
}
}
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);
}
}
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()));
}
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;
}
Aggregations