下面列出了org.bukkit.Material#NOTE_BLOCK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void playTick(Player p, int tick) {
if (noteBlock.getType() != Material.NOTE_BLOCK) {
return;
}
if (!p.getWorld().getName().equals(noteBlock.getWorld().getName())) {
// not in same world
return;
}
byte playerVolume = NoteBlockPlayerMain.getPlayerVolume(p);
for (Layer l : song.getLayerHashMap().values()) {
Note note = l.getNote(tick);
if (note == null) {
continue;
}
p.playNote(noteBlock.getLocation(), Instrument.getBukkitInstrument(note.getInstrument()),
new org.bukkit.Note(note.getKey() - 33));
p.playSound(noteBlock.getLocation(),
Instrument.getInstrument(note.getInstrument()),
(l.getVolume() * (int) volume * (int) playerVolume) / 1000000f,
NotePitch.getPitch(note.getKey() - 33));
}
}
@Override
public boolean play() {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
TileEntityNote note = (TileEntityNote) this.getTileEntityFromWorld();
CraftWorld world = (CraftWorld) this.getWorld();
note.triggerNote(world.getHandle(), new BlockPos(getX(), getY(), getZ()));
return true;
} else {
return false;
}
}
@Override
public boolean play(byte instrument, byte note) {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
CraftWorld world = (CraftWorld) this.getWorld();
world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument, note);
return true;
} else {
return false;
}
}
@Override
public boolean play(Instrument instrument, Note note) {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
CraftWorld world = (CraftWorld) this.getWorld();
world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
return true;
} else {
return false;
}
}
public boolean play() {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
note.triggerNote(world.getHandle(), getX(), getY(), getZ());
return true;
} else {
return false;
}
}
@Override
public boolean play(byte instrument, byte note) {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
world.getHandle().addBlockEvent(getX(), getY(), getZ(), CraftMagicNumbers.getBlock(block), instrument, note);
return true;
} else {
return false;
}
}
@Override
public boolean play(Instrument instrument, Note note) {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
world.getHandle().addBlockEvent(getX(), getY(), getZ(), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
return true;
} else {
return false;
}
}
@Override
public void playTick(Player player, int tick) {
if (noteBlock.getType() != Material.NOTE_BLOCK) {
return;
}
if (!player.getWorld().getName().equals(noteBlock.getWorld().getName())) {
// not in same world
return;
}
byte playerVolume = NoteBlockAPI.getPlayerVolume(player);
for (Layer layer : song.getLayerHashMap().values()) {
Note note = layer.getNote(tick);
if (note == null) {
continue;
}
player.playNote(noteBlock.getLocation(), InstrumentUtils.getBukkitInstrument(note.getInstrument()),
new org.bukkit.Note(note.getKey() - 33));
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
* ((1F / 16F) * getDistance());
float pitch = NotePitch.getPitch(note.getKey() - 33);
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
CustomInstrument instrument = song.getCustomInstruments()
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
if (instrument.getSound() != null) {
CompatibilityUtils.playSound(player, noteBlock.getLocation(),
instrument.getSound(), this.soundCategory, volume, pitch);
} else {
CompatibilityUtils.playSound(player, noteBlock.getLocation(),
instrument.getSoundfile(), this.soundCategory, volume, pitch);
}
} else {
CompatibilityUtils.playSound(player, noteBlock.getLocation(),
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory, volume, pitch);
}
if (isPlayerInRange(player)) {
if (!this.playerList.get(player.getName())) {
playerList.put(player.getName(), true);
Bukkit.getPluginManager().callEvent(new PlayerRangeStateChangeEvent(this, player, true));
}
} else {
if (this.playerList.get(player.getName())) {
playerList.put(player.getName(), false);
Bukkit.getPluginManager().callEvent(new PlayerRangeStateChangeEvent(this, player, false));
}
}
}
}