Java Code Examples for org.bukkit.Material#NOTE_BLOCK

The following examples show how to use org.bukkit.Material#NOTE_BLOCK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NoteBlockSongPlayer.java    From NoteBlockAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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));
    }
}
 
Example 2
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 3
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 4
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 5
Source File: CraftNoteBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean play() {
    Block block = getBlock();

    if (block.getType() == Material.NOTE_BLOCK) {
        note.triggerNote(world.getHandle(), getX(), getY(), getZ());
        return true;
    } else {
        return false;
    }
}
 
Example 6
Source File: CraftNoteBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 7
Source File: CraftNoteBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 8
Source File: NoteBlockSongPlayer.java    From NoteBlockAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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));
			}
		}
	}
}