Done! Stopping, render upd., fixes

Command aliases
This commit is contained in:
Norbi Peti 2017-11-19 22:27:36 +01:00
parent f925439328
commit 410e1351ee
4 changed files with 28 additions and 13 deletions

View file

@ -6,5 +6,6 @@ commands:
usage: Please give a number between 0 and 16. usage: Please give a number between 0 and 16.
singlemap: singlemap:
play: play:
aliases: [playsong, playmusic]
stopplay: stopplay:
aliases: stopsong aliases: [stopsong, stopmusic]

View file

@ -78,7 +78,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
private ByteBuffer buffer; private ByteBuffer buffer;
private TimerTask tt; private TimerTask tt;
public boolean run(CommandSender sender, String file) public boolean run(CommandSender sender)
{ {
if (!init) if (!init)
{ {
@ -89,7 +89,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
if (((BASS_GetVersion() & 0xFFFF0000) >> 16) != BassInit.BASSVERSION()) if (((BASS_GetVersion() & 0xFFFF0000) >> 16) != BassInit.BASSVERSION())
{ {
printfExit("An incorrect version of BASS.DLL was loaded"); printfExit("An incorrect version of BASS.DLL was loaded");
return false; //TODO: Decide whether to init in run, or move it out into init(), if no move, stop() should be used instead of stopPlaying() return false;
} }
// initialize BASS // initialize BASS
@ -99,6 +99,11 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
stop(); stop();
return false; return false;
} }
return true;
}
public boolean start(CommandSender sender, String file)
{
if (!playFile(sender, file)) if (!playFile(sender, file))
{ {
// start a file playing // start a file playing
@ -135,6 +140,8 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
BASS_Free(); BASS_Free();
} }
private boolean playing = false;
private boolean playFile(CommandSender sender, String file) private boolean playFile(CommandSender sender, String file)
{ {
if (!new File(file).exists()) if (!new File(file).exists())
@ -154,13 +161,18 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
chan = (stream != null) ? stream.asInt() : ((music != null) ? music.asInt() : 0); chan = (stream != null) ? stream.asInt() : ((music != null) ? music.asInt() : 0);
BASS_ChannelPlay(chan, false); BASS_ChannelPlay(chan, false);
return true; return playing = true;
} }
private Timer timer = new Timer(); private Timer timer = new Timer();
public boolean stopPlaying() public boolean stopPlaying()
{ {
return BASS_ChannelStop(chan); return !(playing = !(BASS_ChannelStop(chan) && tt.cancel()));
}
public boolean playing()
{
return playing;
} }
} }

View file

@ -9,12 +9,12 @@ import org.bukkit.map.*;
public class BarsRenderer extends BarsRendererBase public class BarsRenderer extends BarsRendererBase
{ {
private boolean single = true; private boolean single = true;
private Analyzer an;
public BarsRenderer(FloatBuffer bars) public BarsRenderer(FloatBuffer bars, Analyzer an)
{ {
super(bars); super(bars);
//System.out.println("black: " + MapPalette.matchColor(Color.black)); this.an = an;
//System.out.println("BLACK: " + MapPalette.matchColor(Color.BLACK));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -32,7 +32,7 @@ public class BarsRenderer extends BarsRendererBase
for (int i = 0; i < 16 && i < count; i++) for (int i = 0; i < 16 && i < count; i++)
for (int j = 0; j < 128; j++) for (int j = 0; j < 128; j++)
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
mc.setPixel(i * 8 + k, 128 - j, j < Math.sqrt(bars.get(i * 64)) * 1280 mc.setPixel(i * 8 + k, 128 - j, j < Math.sqrt(an.playing() ? bars.get(i * 64) : 0) * 1280
? MapPalette.matchColor(j, 255 - j * 2, 0) : MapPalette.matchColor(Color.BLACK)); ? MapPalette.matchColor(j, 255 - j * 2, 0) : MapPalette.matchColor(Color.BLACK));
return; return;
} }
@ -41,7 +41,7 @@ public class BarsRenderer extends BarsRendererBase
for (int j = 0; j < 128; j++) for (int j = 0; j < 128; j++)
for (int k = 0; k < 8; k++) for (int k = 0; k < 8; k++)
mc.setPixel(i * 16 + k, 128 - j, mc.setPixel(i * 16 + k, 128 - j,
j < Math.sqrt(bars.get((offsetx + i) * 64)) * 1280 + offsety j < Math.sqrt(an.playing() ? bars.get((offsetx + i) * 64) : 0) * 1280 + offsety
? MapPalette.matchColor(j - offsety, 255 - j + offsety, 0) ? MapPalette.matchColor(j - offsety, 255 - j + offsety, 0)
: MapPalette.matchColor(Color.BLACK)); : MapPalette.matchColor(Color.BLACK));
} }

View file

@ -34,7 +34,7 @@ public class PluginMain extends JavaPlugin
try try
{ {
//System.setProperty("org.jouvieje.libloader.debug", "true"); //System.setProperty("org.jouvieje.libloader.debug", "true");
Bukkit.getConsoleSender().sendMessage("§bInitializing analyzer..."); Bukkit.getConsoleSender().sendMessage("§bLoading...");
an = new Analyzer(); an = new Analyzer();
URL dirURL = getClassLoader().getResource("res"); URL dirURL = getClassLoader().getResource("res");
String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!"));
@ -56,7 +56,7 @@ public class PluginMain extends JavaPlugin
jar.close(); jar.close();
for (File f : getDataFolder().listFiles()) for (File f : getDataFolder().listFiles())
addLibraryPath(f.getAbsolutePath()); addLibraryPath(f.getAbsolutePath());
br = new BarsRenderer(bars = an.init()); br = new BarsRenderer(bars = an.init(), an);
for (short i = 0; i < 4; i++) for (short i = 0; i < 4; i++)
{ {
MapView map = Bukkit.getMap(i); MapView map = Bukkit.getMap(i);
@ -65,6 +65,8 @@ public class PluginMain extends JavaPlugin
map.getRenderers().clear(); map.getRenderers().clear();
map.addRenderer(br); map.addRenderer(br);
} }
Bukkit.getConsoleSender().sendMessage("§bInitializing...");
an.run(Bukkit.getConsoleSender());
Bukkit.getConsoleSender().sendMessage("§bDone!"); Bukkit.getConsoleSender().sendMessage("§bDone!");
} catch (Exception e) } catch (Exception e)
{ {
@ -102,7 +104,7 @@ public class PluginMain extends JavaPlugin
return true; return true;
} else if (command.getName().equalsIgnoreCase("play")) } else if (command.getName().equalsIgnoreCase("play"))
{ {
if (an.run(sender, Arrays.stream(args).collect(Collectors.joining(" ")))) if (an.start(sender, Arrays.stream(args).collect(Collectors.joining(" "))))
sender.sendMessage("Started playing music"); sender.sendMessage("Started playing music");
else else
sender.sendMessage("§cFailed to play music."); sender.sendMessage("§cFailed to play music.");