Skip to content
Snippets Groups Projects
Commit 76aeadc9 authored by tobias's avatar tobias
Browse files

Add NativeAudioMac as plugin

parent 0942c9eb
No related branches found
No related tags found
No related merge requests found
......@@ -124,11 +124,15 @@ public class PlayPadMain extends Application implements LocalizationDelegate {
// Load Plugin Path
Path pluginFolder;
if (getParameters().getNamed().containsKey("plugin")) {
pluginFolder = Paths.get(getParameters().getNamed().get("plugin"));
String pluginParam = getParameters().getNamed().get("plugin");
for (String part : pluginParam.split(":")) {
pluginFolder = Paths.get(part);
setupPlugins(pluginFolder);
}
} else {
pluginFolder = ApplicationUtils.getApplication().getPath(PathType.LIBRARY);
}
setupPlugins(pluginFolder);
}
/*
* Load Data
......
......@@ -3,7 +3,10 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/YML"/>
<classpathentry combineaccessrules="false" kind="src" path="/PlayWallCore"/>
<classpathentry combineaccessrules="false" kind="src" path="/libUtils"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Plugins"/>
<classpathentry combineaccessrules="false" kind="src" path="/Updater"/>
<classpathentry kind="output" path="bin"/>
</classpath>
package de.tobias.playpad;
package de.tobias.playpad.namac;
import java.nio.file.Path;
import de.tobias.playpad.NativeAudio;
import de.tobias.playpad.audio.AudioHandler;
import de.tobias.playpad.audio.Peakable;
import de.tobias.playpad.pad.PadStatus;
......
package de.tobias.playpad;
package de.tobias.playpad.namac;
import java.util.HashMap;
import de.tobias.playpad.NativeAudio;
import de.tobias.playpad.NativeAudio.NativeAudioDelegate;
import de.tobias.playpad.audio.AudioCapability;
import de.tobias.playpad.audio.AudioHandler;
......
package de.tobias.playpad.namac;
import de.tobias.playpad.plugin.AdvancedPlugin;
public interface NativeAudioMacPlugin extends AdvancedPlugin {
}
package de.tobias.playpad.namac;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import de.tobias.playpad.PlayPadPlugin;
import de.tobias.playpad.audio.AudioRegistry;
import de.tobias.playpad.plugin.Module;
import de.tobias.updater.client.Updatable;
import de.tobias.utils.application.App;
import de.tobias.utils.application.ApplicationUtils;
import de.tobias.utils.application.container.PathType;
import de.tobias.utils.util.IOUtils;
import de.tobias.utils.util.OS;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
import net.xeoh.plugins.base.annotations.events.Shutdown;
@PluginImplementation
public class NativeAudioMacPluginImpl implements NativeAudioMacPlugin {
private static final String ASSETS = "de/tobias/playpad/";
private static final String NAME = "NativeAudioMac";
private static final String IDENTIFIER = "de.tobias.playpad.namac.NativeAudioMacPluginImpl";
private Module module;
private Updatable updatable;
@PluginLoaded
public void onLoaded(NativeAudioMacPlugin plugin) {
module = new Module(NAME, IDENTIFIER);
updatable = new NativeAudioMacUpdater();
try {
prepareBridging();
if (OS.isMacOS()) {
AudioRegistry registry = PlayPadPlugin.getRegistryCollection().getAudioHandlers();
registry.registerComponent(new NativeAudioMacHandlerConnect(), "NativeMac", module);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void prepareBridging() throws IOException {
App app = ApplicationUtils.getApplication();
Path resourceFolder = app.getPath(PathType.LIBRARY, "namac");
if (Files.notExists(resourceFolder)) {
Files.createDirectories(resourceFolder);
}
Path dest = copyResource(resourceFolder, ASSETS, "libNativeAudio.dylib");
System.load(dest.toString());
}
private Path copyResource(Path resourceFolder, String packageName, String file) throws IOException {
Path dest = resourceFolder.resolve(file);
IOUtils.copy(getClass().getClassLoader().getResourceAsStream(packageName + file), dest);
System.out.println("Copied: " + file);
return dest;
}
@Shutdown
public void onShutdown() {
}
@Override
public Module getModule() {
return module;
}
@Override
public Updatable getUpdatable() {
return updatable;
}
}
package de.tobias.playpad.namac;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import de.tobias.updater.client.Updatable;
import de.tobias.updater.client.UpdateChannel;
import de.tobias.utils.application.App;
import de.tobias.utils.application.ApplicationUtils;
import de.tobias.utils.application.container.PathType;
public class NativeAudioMacUpdater implements Updatable {
private int newBuild;
private String newVersion;
private URL remotePath;
private String localFileName;
private String name;
@Override
public int getCurrentBuild() {
return 1;
}
@Override
public String getCurrentVersion() {
return "1.0";
}
@Override
public int getNewBuild() {
return newBuild;
}
@Override
public String getNewVersion() {
return newVersion;
}
@Override
public void loadInformation(UpdateChannel channel) throws IOException {
App app = ApplicationUtils.getMainApplication();
URL url = new URL(app.getInfo().getUpdateURL() + "/" + channel + "/plugins.yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(url.openStream());
newBuild = config.getInt("plugins.namac.build");
newVersion = config.getString("plugins.namac.version");
remotePath = new URL(config.getString("plugins.namac.url"));
localFileName = config.getString("plugins.namac.filename");
name = config.getString("plugins.namac.name");
}
@Override
public boolean isUpdateAvailable() {
return getCurrentBuild() < getNewBuild();
}
@Override
public URL getDownloadPath() {
return remotePath;
}
@Override
public Path getLocalPath() {
return ApplicationUtils.getApplication().getPath(PathType.LIBRARY, localFileName);
}
@Override
public String name() {
return name;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment