From 751cc5eb92d500c310eb6bb9a58c20d8ab401b31 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 8 May 2019 17:49:11 +0200 Subject: [PATCH] Some fixes, some errors --- .../java/sznp/virtualcomputer/Computer.java | 3 +- .../java/sznp/virtualcomputer/PluginMain.java | 11 +++-- .../sznp/virtualcomputer/EventHandler.java | 9 ++--- .../sznp/virtualcomputer/util/COMUtils.java | 40 +++++++++++-------- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java index 065eb07..4bf50f9 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/Computer.java @@ -9,6 +9,7 @@ import org.virtualbox_6_0.*; import sznp.virtualcomputer.events.MachineEventHandler; import sznp.virtualcomputer.events.VBoxEventHandler; import sznp.virtualcomputer.renderer.GPURenderer; +import sznp.virtualcomputer.util.COMUtils; import sznp.virtualcomputer.util.Scancode; import javax.annotation.Nullable; @@ -85,7 +86,7 @@ public final class Computer { handler.setProgress(progress); handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way? 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) { diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java index 89e462b..00099b4 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/PluginMain.java @@ -6,14 +6,13 @@ import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import org.virtualbox_6_0.IEventListener; import org.virtualbox_6_0.IVirtualBox; import org.virtualbox_6_0.VirtualBoxManager; import sznp.virtualcomputer.events.VBoxEventHandler; import sznp.virtualcomputer.renderer.BukkitRenderer; import sznp.virtualcomputer.renderer.GPURenderer; import sznp.virtualcomputer.renderer.IRenderer; -import sznp.virtualcomputer.util.COMUtils; +import sznp.virtualcomputer.util.Utils; import sznp.virtualcomputer.util.VBoxLib; import java.io.File; @@ -26,7 +25,7 @@ public class PluginMain extends JavaPlugin { private static final int MCX = 5; private static final int MCY = 4; private BukkitTask mousetask; - private IEventListener listener; + private VBoxEventHandler listener; public static PluginMain Instance; //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); if (System.getProperty("java.library.path") == null || System.getProperty("java.library.path").isEmpty()) System.setProperty("java.library.path", vbpath); - COMUtils.addLibraryPath(vbpath); + Utils.addLibraryPath(vbpath); final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath()); VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); //TODO: Test for MSCOM vbl.RTR3InitExe(0, "", 0); IVirtualBox vbox = manager.getVBox(); - listener = new VBoxEventHandler().registerTo(vbox.getEventSource()); + (listener = new VBoxEventHandler()).registerTo(vbox.getEventSource()); new Computer(this, manager, vbox); //Saves itself ccs.sendMessage("§bLoading Screen..."); try { @@ -119,7 +118,7 @@ public class PluginMain extends JavaPlugin { e.printStackTrace(); - VBox claims the listener was never registered (can double register as well) }*/ 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) Computer.getInstance().pluginDisable(ccs); ccs.sendMessage("§aHuh."); diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java index e62ec9f..e74bb66 100644 --- a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/EventHandler.java @@ -3,14 +3,13 @@ package sznp.virtualcomputer; import org.mozilla.interfaces.IEvent; import org.mozilla.interfaces.IEventListener; import sznp.virtualcomputer.util.COMObjectBase; - -import java.util.function.Consumer; +import sznp.virtualcomputer.util.IEventHandler; /** * A Bukkit-like event system which calls the appropriate methods on an event. */ public final class EventHandler extends COMObjectBase implements IEventListener { - private final Consumer handler; + private final IEventHandler handler; 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 */ - public EventHandler(Consumer handler) { + public EventHandler(IEventHandler handler) { this.handler = handler; } @@ -26,7 +25,7 @@ public final class EventHandler extends COMObjectBase implements IEventListener public final void handleEvent(IEvent iEvent) { if (!enabled) return; - handler.accept(new org.virtualbox_6_0.IEvent(iEvent)); + handler.handleEvent(new org.virtualbox_6_0.IEvent(iEvent)); } public void disable() { diff --git a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java index dafeca7..f2570df 100644 --- a/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java +++ b/VirtualComputerXPCOM/src/main/java/sznp/virtualcomputer/util/COMUtils.java @@ -3,6 +3,7 @@ package sznp.virtualcomputer.util; import lombok.val; import org.virtualbox_6_0.IEvent; import org.virtualbox_6_0.IEventSource; +import org.virtualbox_6_0.IFramebuffer; import org.virtualbox_6_0.VBoxEventType; import org.virtualbox_6_0.xpcom.IUnknown; import sznp.virtualcomputer.EventHandler; @@ -11,23 +12,28 @@ import java.lang.reflect.InvocationTargetException; import java.util.List; public final class COMUtils { - private COMUtils() {} + private COMUtils() { + } - //public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) { - public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List types) { - val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener::handleEvent)); - source.registerListener(ret, types, true); - return ret; - } + //public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) { + public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List types) { + val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener)); + source.registerListener(ret, types, true); + return ret; + } - @SuppressWarnings("unchecked") - public static T getEvent(IEvent event, Class cl) { - try { - val method = cl.getMethod("queryInterface", IUnknown.class); - return (T) method.invoke(null, event); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } + @SuppressWarnings("unchecked") + public static T getEvent(IEvent event, Class cl) { + try { + val method = cl.getMethod("queryInterface", IUnknown.class); + return (T) method.invoke(null, event); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } + + public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) { + return new IFramebuffer(frameBuffer); //TODO + } }