diff --git a/VirtualComputer/dependency-reduced-pom.xml b/VirtualComputer/dependency-reduced-pom.xml
index 05c6c60..f8a69ca 100644
--- a/VirtualComputer/dependency-reduced-pom.xml
+++ b/VirtualComputer/dependency-reduced-pom.xml
@@ -105,6 +105,12 @@
1.12-R0.1-SNAPSHOT
provided
+
+ com.hynnet
+ jacob
+ 1.18
+ compile
+
diff --git a/VirtualComputer/pom.xml b/VirtualComputer/pom.xml
index cc92fd7..2eb8e40 100644
--- a/VirtualComputer/pom.xml
+++ b/VirtualComputer/pom.xml
@@ -85,5 +85,11 @@
1.12-R0.1-SNAPSHOT
provided
+
+
+ com.hynnet
+ jacob
+ 1.18
+
\ No newline at end of file
diff --git a/VirtualComputer/src/sznp/virtualcomputer/Commands.java b/VirtualComputer/src/sznp/virtualcomputer/Commands.java
index 3fb6f89..e87b112 100644
--- a/VirtualComputer/src/sznp/virtualcomputer/Commands.java
+++ b/VirtualComputer/src/sznp/virtualcomputer/Commands.java
@@ -108,8 +108,8 @@ public class Commands implements CommandExecutor {
sender.sendMessage("§cOnly ingame players can use this command.");
return true;
}
- if (!MouseLockerPlayerListener.LockedPlayers.contains(sender)) {
- MouseLockerPlayerListener.LockedPlayers.add((Player) sender);
+ if (!MouseLockerPlayerListener.LockedPlayers.containsKey(sender)) {
+ MouseLockerPlayerListener.LockedPlayers.put((Player) sender, ((Player) sender).getLocation());
sender.sendMessage("§aMouse locked.");
} else {
MouseLockerPlayerListener.LockedPlayers.remove(sender);
diff --git a/VirtualComputer/src/sznp/virtualcomputer/MCFrameBuffer.java b/VirtualComputer/src/sznp/virtualcomputer/MCFrameBuffer.java
index e4adc2c..14da3af 100644
--- a/VirtualComputer/src/sznp/virtualcomputer/MCFrameBuffer.java
+++ b/VirtualComputer/src/sznp/virtualcomputer/MCFrameBuffer.java
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.mozilla.interfaces.IFramebuffer;
import org.mozilla.interfaces.IFramebufferOverlay;
import org.mozilla.interfaces.nsISupports;
+import org.mozilla.xpcom.Mozilla;
import org.virtualbox_5_1.*;
public class MCFrameBuffer implements IFramebuffer {
@@ -15,8 +16,8 @@ public class MCFrameBuffer implements IFramebuffer {
}
@Override
- public nsISupports queryInterface(String arg0) {
- return this;
+ public nsISupports queryInterface(String id) {
+ return Mozilla.queryInterface(this, id);
}
@Override
@@ -66,7 +67,7 @@ public class MCFrameBuffer implements IFramebuffer {
@Override
public long getWinId() {
- return 0;
+ return 0; // Zero means no win id
}
@Override
diff --git a/VirtualComputer/src/sznp/virtualcomputer/MouseLockerPlayerListener.java b/VirtualComputer/src/sznp/virtualcomputer/MouseLockerPlayerListener.java
index 05969fd..9843d7a 100644
--- a/VirtualComputer/src/sznp/virtualcomputer/MouseLockerPlayerListener.java
+++ b/VirtualComputer/src/sznp/virtualcomputer/MouseLockerPlayerListener.java
@@ -1,34 +1,30 @@
package sznp.virtualcomputer;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.bukkit.Location;
import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.player.PlayerMoveEvent;
-public class MouseLockerPlayerListener implements Listener
-{
- public static List LockedPlayers = new ArrayList();
- public static float LockedSpeed = 1;
+public class MouseLockerPlayerListener implements Runnable {
+ public static Map LockedPlayers = new HashMap<>();
+ public static float LockedSpeed = 5;
- @EventHandler
- public void onPlayerMoveMouse(PlayerMoveEvent e)
- {
- if (!LockedPlayers.contains(e.getPlayer()))
- return;
- float yaw1 = e.getFrom().getYaw();
- float pitch1 = e.getFrom().getPitch();
- float yaw2 = e.getTo().getYaw();
- float pitch2 = e.getTo().getPitch();
- if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
- return;
+ @Override
+ public void run() {
+ for (Entry entry : LockedPlayers.entrySet()) {
+ float yaw1 = entry.getValue().getYaw();
+ float pitch1 = entry.getValue().getPitch();
+ float yaw2 = entry.getKey().getLocation().getYaw();
+ float pitch2 = entry.getKey().getLocation().getPitch();
+ if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
+ return;
- PluginMain.Instance.UpdateMouse(null,
- (int) ((yaw2 - yaw1) * LockedSpeed),
- (int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
+ PluginMain.Instance.UpdateMouse(null, (int) ((yaw2 - yaw1) * LockedSpeed),
+ (int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
- e.setTo(e.getFrom());
+ entry.setValue(entry.getValue());
+ }
}
}
diff --git a/VirtualComputer/src/sznp/virtualcomputer/PluginMain.java b/VirtualComputer/src/sznp/virtualcomputer/PluginMain.java
index 6e66d0c..1c926cd 100644
--- a/VirtualComputer/src/sznp/virtualcomputer/PluginMain.java
+++ b/VirtualComputer/src/sznp/virtualcomputer/PluginMain.java
@@ -18,6 +18,7 @@ public class PluginMain extends JavaPlugin {
private ISession session;
private IMachine machine;
private BukkitTask screenupdatetask;
+ private BukkitTask mousetask;
public static PluginMain Instance;
public static byte[] allpixels = null; // It's set on each change
@@ -53,7 +54,7 @@ public class PluginMain extends JavaPlugin {
ccs.sendMessage("§6Compability error, using slower renderer");
}
ccs.sendMessage("§bLoaded!");
- getServer().getPluginManager().registerEvents(new MouseLockerPlayerListener(), this);
+ mousetask = getServer().getScheduler().runTaskTimer(this, new MouseLockerPlayerListener(), 0, 0);
} catch (final Exception e) {
e.printStackTrace();
}
@@ -63,6 +64,7 @@ public class PluginMain extends JavaPlugin {
@Override
public void onDisable() {
ConsoleCommandSender ccs = getServer().getConsoleSender();
+ mousetask.cancel();
if (session.getState() == SessionState.Locked) {
if (session.getMachine().getState().equals(MachineState.Running)) {
ccs.sendMessage("§aSaving machine state...");
@@ -91,6 +93,7 @@ public class PluginMain extends JavaPlugin {
screenupdatetask = null;
}
machine = session.getMachine(); // This is the Machine object we can work with
+ sender.sendMessage("B: " + machine.getState().toString());
final IConsole console = session.getConsole();
sender.sendMessage("1: " + console.getState().toString());
console.powerUp().waitForCompletion(10000);