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>
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.hynnet</groupId>
|
||||||
|
<artifactId>jacob</artifactId>
|
||||||
|
<version>1.18</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -85,5 +85,11 @@
|
||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
<version>1.12-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.hynnet/jacob -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.hynnet</groupId>
|
||||||
|
<artifactId>jacob</artifactId>
|
||||||
|
<version>1.18</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -108,8 +108,8 @@ public class Commands implements CommandExecutor {
|
||||||
sender.sendMessage("§cOnly ingame players can use this command.");
|
sender.sendMessage("§cOnly ingame players can use this command.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!MouseLockerPlayerListener.LockedPlayers.contains(sender)) {
|
if (!MouseLockerPlayerListener.LockedPlayers.containsKey(sender)) {
|
||||||
MouseLockerPlayerListener.LockedPlayers.add((Player) sender);
|
MouseLockerPlayerListener.LockedPlayers.put((Player) sender, ((Player) sender).getLocation());
|
||||||
sender.sendMessage("§aMouse locked.");
|
sender.sendMessage("§aMouse locked.");
|
||||||
} else {
|
} else {
|
||||||
MouseLockerPlayerListener.LockedPlayers.remove(sender);
|
MouseLockerPlayerListener.LockedPlayers.remove(sender);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
||||||
import org.mozilla.interfaces.IFramebuffer;
|
import org.mozilla.interfaces.IFramebuffer;
|
||||||
import org.mozilla.interfaces.IFramebufferOverlay;
|
import org.mozilla.interfaces.IFramebufferOverlay;
|
||||||
import org.mozilla.interfaces.nsISupports;
|
import org.mozilla.interfaces.nsISupports;
|
||||||
|
import org.mozilla.xpcom.Mozilla;
|
||||||
import org.virtualbox_5_1.*;
|
import org.virtualbox_5_1.*;
|
||||||
|
|
||||||
public class MCFrameBuffer implements IFramebuffer {
|
public class MCFrameBuffer implements IFramebuffer {
|
||||||
|
@ -15,8 +16,8 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public nsISupports queryInterface(String arg0) {
|
public nsISupports queryInterface(String id) {
|
||||||
return this;
|
return Mozilla.queryInterface(this, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,7 +67,7 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getWinId() {
|
public long getWinId() {
|
||||||
return 0;
|
return 0; // Zero means no win id
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,34 +1,30 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
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 class MouseLockerPlayerListener implements Runnable {
|
||||||
{
|
public static Map<Player, Location> LockedPlayers = new HashMap<>();
|
||||||
public static List<Player> LockedPlayers = new ArrayList<Player>();
|
public static float LockedSpeed = 5;
|
||||||
public static float LockedSpeed = 1;
|
|
||||||
|
|
||||||
@EventHandler
|
@Override
|
||||||
public void onPlayerMoveMouse(PlayerMoveEvent e)
|
public void run() {
|
||||||
{
|
for (Entry<Player, Location> entry : LockedPlayers.entrySet()) {
|
||||||
if (!LockedPlayers.contains(e.getPlayer()))
|
float yaw1 = entry.getValue().getYaw();
|
||||||
return;
|
float pitch1 = entry.getValue().getPitch();
|
||||||
float yaw1 = e.getFrom().getYaw();
|
float yaw2 = entry.getKey().getLocation().getYaw();
|
||||||
float pitch1 = e.getFrom().getPitch();
|
float pitch2 = entry.getKey().getLocation().getPitch();
|
||||||
float yaw2 = e.getTo().getYaw();
|
|
||||||
float pitch2 = e.getTo().getPitch();
|
|
||||||
if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
|
if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PluginMain.Instance.UpdateMouse(null,
|
PluginMain.Instance.UpdateMouse(null, (int) ((yaw2 - yaw1) * LockedSpeed),
|
||||||
(int) ((yaw2 - yaw1) * LockedSpeed),
|
|
||||||
(int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
|
(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 ISession session;
|
||||||
private IMachine machine;
|
private IMachine machine;
|
||||||
private BukkitTask screenupdatetask;
|
private BukkitTask screenupdatetask;
|
||||||
|
private BukkitTask mousetask;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
public static byte[] allpixels = null; // It's set on each change
|
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("§6Compability error, using slower renderer");
|
||||||
}
|
}
|
||||||
ccs.sendMessage("§bLoaded!");
|
ccs.sendMessage("§bLoaded!");
|
||||||
getServer().getPluginManager().registerEvents(new MouseLockerPlayerListener(), this);
|
mousetask = getServer().getScheduler().runTaskTimer(this, new MouseLockerPlayerListener(), 0, 0);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +64,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
||||||
|
mousetask.cancel();
|
||||||
if (session.getState() == SessionState.Locked) {
|
if (session.getState() == SessionState.Locked) {
|
||||||
if (session.getMachine().getState().equals(MachineState.Running)) {
|
if (session.getMachine().getState().equals(MachineState.Running)) {
|
||||||
ccs.sendMessage("§aSaving machine state...");
|
ccs.sendMessage("§aSaving machine state...");
|
||||||
|
@ -91,6 +93,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
screenupdatetask = null;
|
screenupdatetask = null;
|
||||||
}
|
}
|
||||||
machine = session.getMachine(); // This is the Machine object we can work with
|
machine = session.getMachine(); // This is the Machine object we can work with
|
||||||
|
sender.sendMessage("B: " + machine.getState().toString());
|
||||||
final IConsole console = session.getConsole();
|
final IConsole console = session.getConsole();
|
||||||
sender.sendMessage("1: " + console.getState().toString());
|
sender.sendMessage("1: " + console.getState().toString());
|
||||||
console.powerUp().waitForCompletion(10000);
|
console.powerUp().waitForCompletion(10000);
|
||||||
|
|
Loading…
Reference in a new issue