Fixed loading error etc. PLAY WORKS
Ain't nobody needs a second init
This commit is contained in:
parent
58e5cb0536
commit
b5ee3f0244
2 changed files with 23 additions and 21 deletions
|
@ -80,18 +80,18 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
|
|||
private ByteBuffer buffer;
|
||||
private TimerTask tt;
|
||||
|
||||
public void run(CommandSender sender, String file)
|
||||
public boolean run(CommandSender sender, String file)
|
||||
{
|
||||
if (!init)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// check the correct BASS was loaded
|
||||
if (((BASS_GetVersion() & 0xFFFF0000) >> 16) != BassInit.BASSVERSION())
|
||||
{
|
||||
printfExit("An incorrect version of BASS.DLL was loaded");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// initialize BASS
|
||||
|
@ -99,14 +99,14 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
|
|||
{
|
||||
error("Can't initialize device", sender);
|
||||
stop();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!playFile(sender, file))
|
||||
{
|
||||
// start a file playing
|
||||
BASS_Free();
|
||||
stop();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// setup update timer (50hz)
|
||||
timer.scheduleAtFixedRate(tt = new TimerTask()
|
||||
|
@ -117,6 +117,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
|
|||
BASS_ChannelGetData(chan, buffer, BASS_DATA_FFT2048); //Get the FFT data
|
||||
}
|
||||
}, 50, 50);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
|
@ -141,6 +142,7 @@ public class Analyzer //Based on NativeBass example 'Spectrum'
|
|||
if (!new File(file).exists())
|
||||
{
|
||||
sender.sendMessage("§cFile not found: " + file);
|
||||
return false;
|
||||
}
|
||||
HSTREAM stream = null;
|
||||
HMUSIC music = null;
|
||||
|
|
|
@ -33,19 +33,9 @@ public class PluginMain extends JavaPlugin
|
|||
{
|
||||
try
|
||||
{
|
||||
System.setProperty("org.jouvieje.libloader.debug", "true");
|
||||
an = new Analyzer();
|
||||
//System.setProperty("org.jouvieje.libloader.debug", "true");
|
||||
Bukkit.getConsoleSender().sendMessage("§bInitializing analyzer...");
|
||||
br = new BarsRenderer(bars = an.init());
|
||||
for (short i = 0; i < 4; i++)
|
||||
{
|
||||
MapView map = Bukkit.getMap(i);
|
||||
if (map == null)
|
||||
map = Bukkit.createMap(Bukkit.getWorlds().get(0));
|
||||
map.getRenderers().clear();
|
||||
map.addRenderer(br);
|
||||
}
|
||||
//an.init(); - It's a good idea to use the libraries *after* they are loaded
|
||||
an = new Analyzer();
|
||||
URL dirURL = getClassLoader().getResource("res");
|
||||
String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!"));
|
||||
JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
|
||||
|
@ -66,7 +56,15 @@ public class PluginMain extends JavaPlugin
|
|||
jar.close();
|
||||
for (File f : getDataFolder().listFiles())
|
||||
addLibraryPath(f.getAbsolutePath());
|
||||
an.init();
|
||||
br = new BarsRenderer(bars = an.init());
|
||||
for (short i = 0; i < 4; i++)
|
||||
{
|
||||
MapView map = Bukkit.getMap(i);
|
||||
if (map == null)
|
||||
map = Bukkit.createMap(Bukkit.getWorlds().get(0));
|
||||
map.getRenderers().clear();
|
||||
map.addRenderer(br);
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("§bDone!");
|
||||
} catch (Exception e)
|
||||
{
|
||||
|
@ -104,8 +102,10 @@ public class PluginMain extends JavaPlugin
|
|||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("play"))
|
||||
{
|
||||
an.run(sender, Arrays.stream(args).skip(1).collect(Collectors.joining(" ")));
|
||||
if (an.run(sender, Arrays.stream(args).collect(Collectors.joining(" "))))
|
||||
sender.sendMessage("Started playing music");
|
||||
else
|
||||
sender.sendMessage("§cFailed to play music.");
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
|
@ -123,7 +123,6 @@ public class PluginMain extends JavaPlugin
|
|||
*/
|
||||
public static void addLibraryPath(String pathToAdd) throws Exception
|
||||
{
|
||||
//System.out.println("Adding " + pathToAdd);
|
||||
final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
|
||||
usrPathsField.setAccessible(true);
|
||||
|
||||
|
@ -143,5 +142,6 @@ public class PluginMain extends JavaPlugin
|
|||
final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
|
||||
newPaths[newPaths.length - 1] = pathToAdd;
|
||||
usrPathsField.set(null, newPaths);
|
||||
System.setProperty("java.library.path", Arrays.stream(newPaths).collect(Collectors.joining(";")));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue