diff --git a/VirtualComputer/dependency-reduced-pom.xml b/VirtualComputer/dependency-reduced-pom.xml
index 61136e3..3e0d028 100644
--- a/VirtualComputer/dependency-reduced-pom.xml
+++ b/VirtualComputer/dependency-reduced-pom.xml
@@ -129,7 +129,7 @@
org.virtualbox
- VirtualBox
+ VirtualBox-MSCOM
6.0
compile
diff --git a/VirtualComputer/pom.xml b/VirtualComputer/pom.xml
index e8a19ae..fc2f807 100644
--- a/VirtualComputer/pom.xml
+++ b/VirtualComputer/pom.xml
@@ -61,11 +61,6 @@
VirtualBox-MSCOM
6.0
-
- com.jacob
- Jacob
- 1.19
-
org.bukkit
craftbukkit
diff --git a/VirtualComputer/src/main/java/sznp/virtualcomputer/PluginMain.java b/VirtualComputer/src/main/java/sznp/virtualcomputer/PluginMain.java
index 6d9767d..f38ab70 100644
--- a/VirtualComputer/src/main/java/sznp/virtualcomputer/PluginMain.java
+++ b/VirtualComputer/src/main/java/sznp/virtualcomputer/PluginMain.java
@@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.function.Predicate;
public class PluginMain extends JavaPlugin {
- public static final boolean MSCOM = true; //TODO: Implement
private static final int MCX = 5;
private static final int MCY = 4;
private BukkitTask mousetask;
diff --git a/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java b/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java
index 2a24975..2aafd3d 100644
--- a/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java
+++ b/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBase.java
@@ -1,13 +1,16 @@
package sznp.virtualcomputer.events;
+import lombok.val;
+import org.bukkit.Bukkit;
import org.mozilla.interfaces.IEvent;
import org.mozilla.interfaces.IEventListener;
import org.virtualbox_6_0.IEventSource;
import org.virtualbox_6_0.VBoxEventType;
-import sznp.virtualcomputer.PluginMain;
import sznp.virtualcomputer.util.COMObjectBase;
import sznp.virtualcomputer.util.Utils;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Map;
@@ -28,16 +31,30 @@ public abstract class EventHandlerBase extends COMObjectBase implements IEventLi
@Override
public final void handleEvent(IEvent iEvent) {
+ //val cl=eventMap.get((int)iEvent.getType()); - We can afford to search through the events for this handler
if (!enabled)
return;
- Utils.handleEvent(this, eventMap, iEvent, false);
+ val kv = eventMap.entrySet().stream().filter(e -> e.getKey().value() == iEvent.getType()).findAny();
+ if (!kv.isPresent()) return; //Event not supported
+ val cl = kv.get().getValue();
+ for (Method method : getClass().getMethods()) {
+ if (method.isAnnotationPresent(org.bukkit.event.EventHandler.class)
+ && method.getParameterCount() == 1 && method.getParameterTypes()[0] == cl) {
+ try {
+ method.invoke(this, Utils.getEvent(iEvent, cl));
+ return;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ Bukkit.getLogger().warning("Error while handling VirtualBox event!");
+ e.getCause().printStackTrace();
+ }
+ }
+ }
}
public org.virtualbox_6_0.IEventListener registerTo(IEventSource source) {
- if (PluginMain.MSCOM)
- return Utils.registerListenerMSCOM(source, this, new ArrayList<>(eventMap.keySet()));
- else
- return Utils.registerListener(source, this, new ArrayList<>(eventMap.keySet()));
+ return Utils.registerListener(source, this, new ArrayList<>(eventMap.keySet()));
}
public void disable() {
diff --git a/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBaseMSCOM.java b/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBaseMSCOM.java
deleted file mode 100644
index 611d113..0000000
--- a/VirtualComputer/src/main/java/sznp/virtualcomputer/events/EventHandlerBaseMSCOM.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package sznp.virtualcomputer.events;
-
-public class EventHandlerBaseMSCOM {
-}
diff --git a/VirtualComputer/src/main/java/sznp/virtualcomputer/util/Utils.java b/VirtualComputer/src/main/java/sznp/virtualcomputer/util/Utils.java
index 4210670..dfe919e 100644
--- a/VirtualComputer/src/main/java/sznp/virtualcomputer/util/Utils.java
+++ b/VirtualComputer/src/main/java/sznp/virtualcomputer/util/Utils.java
@@ -1,21 +1,16 @@
package sznp.virtualcomputer.util;
-import com.jacob.com.Variant;
import lombok.val;
-import org.bukkit.Bukkit;
import org.mozilla.interfaces.IEventListener;
import org.virtualbox_6_0.IEvent;
import org.virtualbox_6_0.IEventSource;
import org.virtualbox_6_0.VBoxEventType;
import org.virtualbox_6_0.xpcom.IUnknown;
-import sznp.virtualcomputer.events.EventHandlerBase;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
public class Utils {
/**
@@ -44,20 +39,17 @@ public class Utils {
usrPathsField.set(null, newPaths);
}
+ //public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) {
public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventListener listener, List types) {
val ret = new org.virtualbox_6_0.IEventListener(listener);
source.registerListener(ret, types, true);
return ret;
}
- public static org.virtualbox_6_0.IEventListener registerListenerMSCOM(IEventSource source, Object listener, List types) {
- val ret = new org.virtualbox_6_0.IEventListener(new Variant(listener).toDispatch());
- source.registerListener(ret, types, true);
- return ret;
- }
-
@SuppressWarnings("unchecked")
public static T getEvent(org.mozilla.interfaces.IEvent event, Class cl) {
+ //if (event.getType() != type.value()) return null;
+ //return (T) T.queryInterface(new IEvent(event)); - Probably won't work
try {
val method = cl.getMethod("queryInterface", IUnknown.class);
return (T) method.invoke(null, new IEvent(event));
@@ -66,42 +58,4 @@ public class Utils {
return null;
}
}
-
- @SuppressWarnings("unchecked")
- public static T getEventMSCOM(Object event, Class cl) {
- try {
- val method = cl.getMethod("queryInterface", org.virtualbox_6_0.mscom.IUnknown.class);
- return (T) method.invoke(null, new IEvent(new Variant(event).toDispatch()));
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static void handleEvent(EventHandlerBase handler, Map> eventMap, Object iEvent, boolean mscom) {
- Class> cl;
- if (mscom) {
- val kv = eventMap.entrySet().stream().filter(e -> e.getKey().value() == iEvent.getType().value()).findAny();
- if (!kv.isPresent()) return; //Event not supported
- cl = kv.get().getValue();
- } else {
- val kv = eventMap.entrySet().stream().filter(e -> e.getKey().value() == iEvent.getType()).findAny();
- if (!kv.isPresent()) return; //Event not supported
- cl = kv.get().getValue();
- }
- for (Method method : handler.getClass().getMethods()) {
- if (method.isAnnotationPresent(org.bukkit.event.EventHandler.class)
- && method.getParameterCount() == 1 && method.getParameterTypes()[0] == cl) {
- try {
- method.invoke(handler, Utils.getEvent(iEvent, cl));
- return;
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- Bukkit.getLogger().warning("Error while handling VirtualBox event!");
- e.getCause().printStackTrace();
- }
- }
- }
- }
}