Search in sources :

Example 6 with NoteBlock

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

the class NoteBlockMechanicListener method getHardnessModifier.

private HardnessModifier getHardnessModifier() {
    return new HardnessModifier() {

        @Override
        @SuppressWarnings("deprecation")
        public boolean isTriggered(final Player player, final Block block, final ItemStack tool) {
            if (block.getType() != Material.NOTE_BLOCK)
                return false;
            final NoteBlock noteBlok = (NoteBlock) block.getBlockData();
            final int code = (int) (noteBlok.getInstrument().getType()) * 25 + (int) noteBlok.getNote().getId() + (noteBlok.isPowered() ? 400 : 0) - 26;
            final NoteBlockMechanic noteBlockMechanic = NoteBlockMechanicFactory.getBlockMechanic(code);
            return noteBlockMechanic != null && noteBlockMechanic.hasHardness;
        }

        @Override
        public void breakBlock(final Player player, final Block block, final ItemStack tool) {
            block.setType(Material.AIR);
        }

        @SuppressWarnings("deprecation")
        @Override
        public long getPeriod(final Player player, final Block block, final ItemStack tool) {
            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);
            final long period = noteBlockMechanic.getPeriod();
            double modifier = 1;
            if (noteBlockMechanic.getDrop().canDrop(tool)) {
                modifier *= 0.4;
                final int diff = noteBlockMechanic.getDrop().getDiff(tool);
                if (diff >= 1)
                    modifier *= Math.pow(0.9, diff);
            }
            return (long) (period * modifier);
        }
    };
}
Also used : Player(org.bukkit.entity.Player) NoteBlock(org.bukkit.block.data.type.NoteBlock) HardnessModifier(io.th0rgal.oraxen.utils.breaker.HardnessModifier) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with NoteBlock

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

the class NoteBlockDisplay method onUseNoteBlock.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR)
public void onUseNoteBlock(PlayerInteractEvent event) {
    Block block = event.getClickedBlock();
    if (block == null) {
        return;
    }
    if (!block.getType().equals(Material.NOTE_BLOCK)) {
        return;
    }
    boolean holdingAir = event.getPlayer().getEquipment().getItemInMainHand() == null || (event.getPlayer().getEquipment().getItemInMainHand().getType().equals(Material.AIR));
    if (event.getPlayer().isSneaking() && !holdingAir) {
        return;
    }
    BlockFace face = event.getBlockFace();
    Location textLocation = getFaceOffset(block, face);
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        if (!block.getType().equals(Material.NOTE_BLOCK)) {
            return;
        }
        ConcurrentHashMap<String, Object> map = displayingNotes.get(block);
        ArmorStand stand = map == null ? new ArmorStand(textLocation.clone().add(0.0, -0.3, 0.0)) : (ArmorStand) map.get("Stand");
        stand.teleport(textLocation.clone().add(0.0, -0.3, 0.0));
        setStand(stand);
        map = map == null ? new ConcurrentHashMap<String, Object>() : map;
        map.put("Stand", stand);
        map.put("Timeout", System.currentTimeMillis() + 3000);
        displayingNotes.put(block, map);
        String text = "";
        if (!InteractionVisualizer.version.isLegacy()) {
            NoteBlock state = (NoteBlock) block.getBlockData();
            Tone tone = state.getNote().getTone();
            String inst = MusicManager.getMusicConfig().getString("Instruments." + state.getInstrument().toString().toUpperCase());
            text = ChatColor.GOLD + inst + " " + getColor(tone) + tone.toString().toUpperCase();
            text = state.getNote().isSharped() ? text + "#" : text;
            text = state.getNote().getOctave() == 0 ? text : text + " ^";
        } else {
            org.bukkit.block.NoteBlock state = (org.bukkit.block.NoteBlock) block.getState();
            Tone tone = state.getNote().getTone();
            String inst = MusicManager.getMusicConfig().getString("Instruments." + LegacyInstrumentUtils.getInstrumentNameFromLegacy(block.getRelative(BlockFace.DOWN).getType().toString().toUpperCase()));
            text = ChatColor.GOLD + inst + " " + getColor(tone) + tone.toString().toUpperCase();
            text = state.getNote().isSharped() ? text + "#" : text;
            text = state.getNote().getOctave() == 0 ? text : text + " ^";
        }
        stand.setCustomName(text);
        PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), stand);
        PacketManager.updateArmorStand(stand);
    }, 1);
}
Also used : BlockFace(org.bukkit.block.BlockFace) NoteBlock(org.bukkit.block.data.type.NoteBlock) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Tone(org.bukkit.Note.Tone) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

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