Search in sources :

Example 1 with Tone

use of org.bukkit.Note.Tone 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

ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Location (org.bukkit.Location)1 Tone (org.bukkit.Note.Tone)1 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1 NoteBlock (org.bukkit.block.data.type.NoteBlock)1 EventHandler (org.bukkit.event.EventHandler)1