Some fixes, some errors
This commit is contained in:
parent
9ba0c3e820
commit
751cc5eb92
4 changed files with 34 additions and 29 deletions
|
@ -9,6 +9,7 @@ import org.virtualbox_6_0.*;
|
||||||
import sznp.virtualcomputer.events.MachineEventHandler;
|
import sznp.virtualcomputer.events.MachineEventHandler;
|
||||||
import sznp.virtualcomputer.events.VBoxEventHandler;
|
import sznp.virtualcomputer.events.VBoxEventHandler;
|
||||||
import sznp.virtualcomputer.renderer.GPURenderer;
|
import sznp.virtualcomputer.renderer.GPURenderer;
|
||||||
|
import sznp.virtualcomputer.util.COMUtils;
|
||||||
import sznp.virtualcomputer.util.Scancode;
|
import sznp.virtualcomputer.util.Scancode;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -85,7 +86,7 @@ public final class Computer {
|
||||||
handler.setProgress(progress);
|
handler.setProgress(progress);
|
||||||
handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way?
|
handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way?
|
||||||
console.getDisplay().attachFramebuffer(0L,
|
console.getDisplay().attachFramebuffer(0L,
|
||||||
new IFramebuffer(new COMFrameBuffer(console.getDisplay(), true)));
|
COMUtils.gimmeAFramebuffer(new COMFrameBuffer(console.getDisplay(), true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(@Nullable CommandSender sender, String message) {
|
private void sendMessage(@Nullable CommandSender sender, String message) {
|
||||||
|
|
|
@ -6,14 +6,13 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.virtualbox_6_0.IEventListener;
|
|
||||||
import org.virtualbox_6_0.IVirtualBox;
|
import org.virtualbox_6_0.IVirtualBox;
|
||||||
import org.virtualbox_6_0.VirtualBoxManager;
|
import org.virtualbox_6_0.VirtualBoxManager;
|
||||||
import sznp.virtualcomputer.events.VBoxEventHandler;
|
import sznp.virtualcomputer.events.VBoxEventHandler;
|
||||||
import sznp.virtualcomputer.renderer.BukkitRenderer;
|
import sznp.virtualcomputer.renderer.BukkitRenderer;
|
||||||
import sznp.virtualcomputer.renderer.GPURenderer;
|
import sznp.virtualcomputer.renderer.GPURenderer;
|
||||||
import sznp.virtualcomputer.renderer.IRenderer;
|
import sznp.virtualcomputer.renderer.IRenderer;
|
||||||
import sznp.virtualcomputer.util.COMUtils;
|
import sznp.virtualcomputer.util.Utils;
|
||||||
import sznp.virtualcomputer.util.VBoxLib;
|
import sznp.virtualcomputer.util.VBoxLib;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -26,7 +25,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
private static final int MCX = 5;
|
private static final int MCX = 5;
|
||||||
private static final int MCY = 4;
|
private static final int MCY = 4;
|
||||||
private BukkitTask mousetask;
|
private BukkitTask mousetask;
|
||||||
private IEventListener listener;
|
private VBoxEventHandler listener;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
//public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
|
//public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
|
||||||
|
@ -67,12 +66,12 @@ public class PluginMain extends JavaPlugin {
|
||||||
System.setProperty("sun.boot.library.path", vbpath);
|
System.setProperty("sun.boot.library.path", vbpath);
|
||||||
if (System.getProperty("java.library.path") == null || System.getProperty("java.library.path").isEmpty())
|
if (System.getProperty("java.library.path") == null || System.getProperty("java.library.path").isEmpty())
|
||||||
System.setProperty("java.library.path", vbpath);
|
System.setProperty("java.library.path", vbpath);
|
||||||
COMUtils.addLibraryPath(vbpath);
|
Utils.addLibraryPath(vbpath);
|
||||||
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
||||||
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); //TODO: Test for MSCOM
|
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); //TODO: Test for MSCOM
|
||||||
vbl.RTR3InitExe(0, "", 0);
|
vbl.RTR3InitExe(0, "", 0);
|
||||||
IVirtualBox vbox = manager.getVBox();
|
IVirtualBox vbox = manager.getVBox();
|
||||||
listener = new VBoxEventHandler().registerTo(vbox.getEventSource());
|
(listener = new VBoxEventHandler()).registerTo(vbox.getEventSource());
|
||||||
new Computer(this, manager, vbox); //Saves itself
|
new Computer(this, manager, vbox); //Saves itself
|
||||||
ccs.sendMessage("§bLoading Screen...");
|
ccs.sendMessage("§bLoading Screen...");
|
||||||
try {
|
try {
|
||||||
|
@ -119,7 +118,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
e.printStackTrace(); - VBox claims the listener was never registered (can double register as well)
|
e.printStackTrace(); - VBox claims the listener was never registered (can double register as well)
|
||||||
}*/
|
}*/
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
((VBoxEventHandler) listener.getTypedWrapped()).disable(); //The save progress wait locks with the event
|
listener.disable(); //The save progress wait locks with the event
|
||||||
if (Computer.getInstance() != null)
|
if (Computer.getInstance() != null)
|
||||||
Computer.getInstance().pluginDisable(ccs);
|
Computer.getInstance().pluginDisable(ccs);
|
||||||
ccs.sendMessage("§aHuh.");
|
ccs.sendMessage("§aHuh.");
|
||||||
|
|
|
@ -3,14 +3,13 @@ package sznp.virtualcomputer;
|
||||||
import org.mozilla.interfaces.IEvent;
|
import org.mozilla.interfaces.IEvent;
|
||||||
import org.mozilla.interfaces.IEventListener;
|
import org.mozilla.interfaces.IEventListener;
|
||||||
import sznp.virtualcomputer.util.COMObjectBase;
|
import sznp.virtualcomputer.util.COMObjectBase;
|
||||||
|
import sznp.virtualcomputer.util.IEventHandler;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Bukkit-like event system which calls the appropriate methods on an event.
|
* A Bukkit-like event system which calls the appropriate methods on an event.
|
||||||
*/
|
*/
|
||||||
public final class EventHandler extends COMObjectBase implements IEventListener {
|
public final class EventHandler extends COMObjectBase implements IEventListener {
|
||||||
private final Consumer<org.virtualbox_6_0.IEvent> handler;
|
private final IEventHandler handler;
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +17,7 @@ public final class EventHandler extends COMObjectBase implements IEventListener
|
||||||
*
|
*
|
||||||
* @param handler The handle method that handles what needs to be handled
|
* @param handler The handle method that handles what needs to be handled
|
||||||
*/
|
*/
|
||||||
public EventHandler(Consumer<org.virtualbox_6_0.IEvent> handler) {
|
public EventHandler(IEventHandler handler) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ public final class EventHandler extends COMObjectBase implements IEventListener
|
||||||
public final void handleEvent(IEvent iEvent) {
|
public final void handleEvent(IEvent iEvent) {
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
handler.accept(new org.virtualbox_6_0.IEvent(iEvent));
|
handler.handleEvent(new org.virtualbox_6_0.IEvent(iEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package sznp.virtualcomputer.util;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.virtualbox_6_0.IEvent;
|
import org.virtualbox_6_0.IEvent;
|
||||||
import org.virtualbox_6_0.IEventSource;
|
import org.virtualbox_6_0.IEventSource;
|
||||||
|
import org.virtualbox_6_0.IFramebuffer;
|
||||||
import org.virtualbox_6_0.VBoxEventType;
|
import org.virtualbox_6_0.VBoxEventType;
|
||||||
import org.virtualbox_6_0.xpcom.IUnknown;
|
import org.virtualbox_6_0.xpcom.IUnknown;
|
||||||
import sznp.virtualcomputer.EventHandler;
|
import sznp.virtualcomputer.EventHandler;
|
||||||
|
@ -11,23 +12,28 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class COMUtils {
|
public final class COMUtils {
|
||||||
private COMUtils() {}
|
private COMUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
//public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) {
|
//public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) {
|
||||||
public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
|
public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
|
||||||
val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener::handleEvent));
|
val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener));
|
||||||
source.registerListener(ret, types, true);
|
source.registerListener(ret, types, true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends IEvent> T getEvent(IEvent event, Class<T> cl) {
|
public static <T extends IEvent> T getEvent(IEvent event, Class<T> cl) {
|
||||||
try {
|
try {
|
||||||
val method = cl.getMethod("queryInterface", IUnknown.class);
|
val method = cl.getMethod("queryInterface", IUnknown.class);
|
||||||
return (T) method.invoke(null, event);
|
return (T) method.invoke(null, event);
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) {
|
||||||
|
return new IFramebuffer(frameBuffer); //TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue