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.
singlemap:
play:
aliases: [playsong, playmusic]
stopplay:
aliases: stopsong
aliases: [stopsong, stopmusic]

View file

@ -78,7 +78,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
private ByteBuffer buffer;
private TimerTask tt;
public boolean run(CommandSender sender, String file)
public boolean run(CommandSender sender)
{
if (!init)
{
@ -89,7 +89,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
if (((BASS_GetVersion() & 0xFFFF0000) >> 16) != BassInit.BASSVERSION())
{
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
@ -99,6 +99,11 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
stop();
return false;
}
return true;
}
public boolean start(CommandSender sender, String file)
{
if (!playFile(sender, file))
{
// start a file playing
@ -135,6 +140,8 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
BASS_Free();
}
private boolean playing = false;
private boolean playFile(CommandSender sender, String file)
{
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);
BASS_ChannelPlay(chan, false);
return true;
return playing = true;
}
private Timer timer = new Timer();
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
{
private boolean single = true;
private Analyzer an;
public BarsRenderer(FloatBuffer bars)
public BarsRenderer(FloatBuffer bars, Analyzer an)
{
super(bars);
//System.out.println("black: " + MapPalette.matchColor(Color.black));
//System.out.println("BLACK: " + MapPalette.matchColor(Color.BLACK));
this.an = an;
}
@SuppressWarnings("deprecation")
@ -32,7 +32,7 @@ public class BarsRenderer extends BarsRendererBase
for (int i = 0; i < 16 && i < count; i++)
for (int j = 0; j < 128; j++)
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));
return;
}
@ -41,7 +41,7 @@ public class BarsRenderer extends BarsRendererBase
for (int j = 0; j < 128; j++)
for (int k = 0; k < 8; k++)
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(Color.BLACK));
}

View file

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