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