Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the Jinglenote library inside CommandBook, to use the same
version as in CraftBook. This has been modified a little to remove the SearchArea dependency. (CommandBook just plays it to the player anyway)
- Loading branch information
Showing
8 changed files
with
533 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sk89q.jinglenote; | ||
|
||
public enum Instrument { | ||
|
||
GUITAR, PIANO, BASS, BASS_GUITAR, STICKS, BASS_DRUM, SNARE_DRUM; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 32 additions & 57 deletions
89
src/main/java/com/sk89q/jinglenote/JingleNoteManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,64 @@ | ||
// $Id$ | ||
/* | ||
* Tetsuuuu plugin for SK's Minecraft Server | ||
* Copyright (C) 2010 sk89q <http://www.sk89q.com> | ||
* All rights reserved. | ||
*/ | ||
* Tetsuuuu plugin for SK's Minecraft Server Copyright (C) 2010 sk89q <http://www.sk89q.com> All rights reserved. | ||
*/ | ||
|
||
package com.sk89q.jinglenote; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.entity.Player; | ||
import com.sk89q.worldedit.blocks.BlockType; | ||
import com.sk89q.jinglenote.bukkit.BukkitJingleNotePlayer; | ||
|
||
/** | ||
* A manager of play instances. | ||
* | ||
* | ||
* @author sk89q | ||
*/ | ||
public class JingleNoteManager { | ||
|
||
/** | ||
* List of instances. | ||
*/ | ||
protected final Map<String, JingleNotePlayer> instances | ||
= new HashMap<String, JingleNotePlayer>(); | ||
|
||
public void play(Player player, JingleSequencer sequencer, int delay) { | ||
String name = player.getName(); | ||
Location loc = findLocation(player); | ||
|
||
protected final Map<String, JingleNotePlayer> instances = new HashMap<String, JingleNotePlayer>(); | ||
|
||
public void play(String player, JingleSequencer sequencer) { | ||
|
||
// Existing player found! | ||
if (instances.containsKey(name)) { | ||
JingleNotePlayer existing = instances.get(name); | ||
Location existingLoc = existing.getLocation(); | ||
|
||
existing.stop( | ||
existingLoc.getBlockX() == loc.getBlockX() | ||
&& existingLoc.getBlockY() == loc.getBlockY() | ||
&& existingLoc.getBlockZ() == loc.getBlockZ()); | ||
|
||
instances.remove(name); | ||
if (instances.containsKey(player)) { | ||
JingleNotePlayer existing = instances.get(player); | ||
existing.stop(); | ||
instances.remove(player); | ||
} | ||
JingleNotePlayer notePlayer = new JingleNotePlayer(player, loc, sequencer, delay); | ||
|
||
JingleNotePlayer notePlayer = new BukkitJingleNotePlayer(player, sequencer); | ||
Thread thread = new Thread(notePlayer); | ||
thread.setName("JingleNotePlayer for " + player.getName()); | ||
thread.setDaemon(true); | ||
thread.setPriority(Thread.MAX_PRIORITY); | ||
thread.setName("JingleNotePlayer for " + player); | ||
thread.start(); | ||
instances.put(name, notePlayer); | ||
|
||
instances.put(player, notePlayer); | ||
} | ||
|
||
public boolean stop(Player player) { | ||
String name = player.getName(); | ||
|
||
|
||
public boolean stop(String player) { | ||
|
||
// Existing player found! | ||
if (instances.containsKey(name)) { | ||
JingleNotePlayer existing = instances.get(name); | ||
existing.stop(false); | ||
instances.remove(name); | ||
if (instances.containsKey(player)) { | ||
JingleNotePlayer existing = instances.get(player); | ||
existing.stop(); | ||
instances.remove(player); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void stopAll() { | ||
|
||
for (JingleNotePlayer notePlayer : instances.values()) { | ||
notePlayer.stop(false); | ||
notePlayer.stop(); | ||
} | ||
|
||
instances.clear(); | ||
} | ||
|
||
private Location findLocation(Player player) { | ||
World world = player.getWorld(); | ||
Location loc = player.getLocation(); | ||
loc.setY(loc.getY() - 2); | ||
|
||
if (!BlockType.canPassThrough(world.getBlockTypeIdAt(loc))) { | ||
return loc; | ||
} | ||
|
||
loc.setY(loc.getY() + 4); | ||
|
||
return loc; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,62 @@ | ||
// $Id$ | ||
/* | ||
* Tetsuuuu plugin for SK's Minecraft Server | ||
* Copyright (C) 2010 sk89q <http://www.sk89q.com> | ||
* All rights reserved. | ||
*/ | ||
* Tetsuuuu plugin for SK's Minecraft Server Copyright (C) 2010 sk89q <http://www.sk89q.com> All rights reserved. | ||
*/ | ||
|
||
package com.sk89q.jinglenote; | ||
|
||
import com.sk89q.commandbook.CommandBook; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import com.sk89q.jinglenote.JingleSequencer.Note; | ||
|
||
public class JingleNotePlayer implements Runnable { | ||
protected final Player player; | ||
protected final Location loc; | ||
public abstract class JingleNotePlayer implements Runnable { | ||
|
||
protected final String player; | ||
protected JingleSequencer sequencer; | ||
protected final int delay; | ||
|
||
protected boolean keepMusicBlock = false; | ||
|
||
public JingleNotePlayer(Player player, | ||
Location loc, JingleSequencer seq, int delay) { | ||
|
||
/** | ||
* Constructs a new JingleNotePlayer | ||
* | ||
* @param player The player who is hearing this's name. | ||
* @param seq The JingleSequencer to play. | ||
* @param area The SearchArea for this player. (optional) | ||
*/ | ||
public JingleNotePlayer(String player, JingleSequencer seq) { | ||
|
||
this.player = player; | ||
this.loc = loc; | ||
this.sequencer = seq; | ||
this.delay = delay; | ||
sequencer = seq; | ||
} | ||
|
||
|
||
@Override | ||
public void run() { | ||
|
||
if(sequencer == null) | ||
return; | ||
try { | ||
if (delay > 0) { | ||
Thread.sleep(delay); | ||
} | ||
|
||
// Create a fake note block | ||
player.sendBlockChange(loc, 25, (byte) 0); | ||
Thread.sleep(100); | ||
|
||
try { | ||
sequencer.run(this); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
|
||
Thread.sleep(500); | ||
|
||
if (!keepMusicBlock) { | ||
// Restore music block | ||
CommandBook.server().getScheduler().scheduleSyncDelayedTask(CommandBook.inst(), new Runnable() { | ||
|
||
public void run() { | ||
int prevId = player.getWorld().getBlockTypeIdAt(loc); | ||
byte prevData = player.getWorld().getBlockAt(loc).getData(); | ||
player.sendBlockChange(loc, prevId, prevData); | ||
} | ||
}); | ||
} | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
sequencer.stop(); | ||
sequencer = null; | ||
} | ||
} | ||
|
||
public boolean isActive() { | ||
return player.isOnline(); | ||
} | ||
|
||
public Player getPlayer() { | ||
|
||
public String getPlayer() { | ||
|
||
return player; | ||
} | ||
|
||
public Location getLocation() { | ||
return loc; | ||
} | ||
public void stop() { | ||
|
||
public void stop(boolean keepMusicBlock) { | ||
this.keepMusicBlock = keepMusicBlock; | ||
|
||
if (sequencer != null) { | ||
sequencer.stop(); | ||
} | ||
} | ||
|
||
public void play(byte instrument, byte note) { | ||
if (!player.isOnline()) { | ||
return; | ||
} | ||
|
||
player.playNote(loc, instrument, note); | ||
} | ||
} | ||
|
||
public abstract void play(Note note); | ||
} |
Oops, something went wrong.