opefully fix(es) and always running mouse task
This commit is contained in:
parent
5b9a6c5b4a
commit
f031fc0b9a
6 changed files with 42 additions and 30 deletions
|
@ -105,6 +105,12 @@
|
|||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hynnet</groupId>
|
||||
<artifactId>jacob</artifactId>
|
||||
<version>1.18</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -85,5 +85,11 @@
|
|||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.hynnet/jacob -->
|
||||
<dependency>
|
||||
<groupId>com.hynnet</groupId>
|
||||
<artifactId>jacob</artifactId>
|
||||
<version>1.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Player> LockedPlayers = new ArrayList<Player>();
|
||||
public static float LockedSpeed = 1;
|
||||
public class MouseLockerPlayerListener implements Runnable {
|
||||
public static Map<Player, Location> 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();
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entry<Player, Location> 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),
|
||||
PluginMain.Instance.UpdateMouse(null, (int) ((yaw2 - yaw1) * LockedSpeed),
|
||||
(int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
|
||||
|
||||
e.setTo(e.getFrom());
|
||||
entry.setValue(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue