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