Directly using VirtualBox from Java #5
6 changed files with 202 additions and 185 deletions
|
@ -36,7 +36,7 @@ public class BukkitRenderer extends MapRenderer implements IRenderer {
|
||||||
MapView map = IRenderer.prepare(id, world);
|
MapView map = IRenderer.prepare(id, world);
|
||||||
map.addRenderer(this);
|
map.addRenderer(this);
|
||||||
this.startindex = startindex;
|
this.startindex = startindex;
|
||||||
image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
|
image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int progress = 0;
|
private int progress = 0;
|
||||||
|
|
|
@ -1,135 +1,136 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
public class Commands implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
switch (cmd.getName().toLowerCase()) {
|
switch (cmd.getName().toLowerCase()) {
|
||||||
case "computer": {
|
case "computer": {
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
return false;
|
return false;
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "start":
|
case "start":
|
||||||
case "poweron":
|
case "poweron":
|
||||||
case "on":
|
case "on":
|
||||||
case "startup":
|
case "startup":
|
||||||
PluginMain.Instance.Start(sender);
|
PluginMain.Instance.Start(sender);
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
case "poweroff":
|
case "poweroff":
|
||||||
case "off":
|
case "off":
|
||||||
case "shutdown":
|
case "shutdown":
|
||||||
case "kill":
|
case "kill":
|
||||||
PluginMain.Instance.Stop(sender);
|
PluginMain.Instance.Stop(sender);
|
||||||
break;
|
break;
|
||||||
case "powerbutton":
|
case "powerbutton":
|
||||||
case "pwrbtn":
|
case "pwrbtn":
|
||||||
case "powerbtn":
|
case "powerbtn":
|
||||||
PluginMain.Instance.PowerButton(sender);
|
PluginMain.Instance.PowerButton(sender);
|
||||||
break;
|
break;
|
||||||
case "reset":
|
case "reset":
|
||||||
case "restart":
|
case "restart":
|
||||||
PluginMain.Instance.Reset(sender);
|
PluginMain.Instance.Reset(sender);
|
||||||
break;
|
break;
|
||||||
case "fix":
|
case "fix":
|
||||||
case "fixscreen":
|
case "fixscreen":
|
||||||
PluginMain.Instance.FixScreen(sender);
|
PluginMain.Instance.FixScreen(sender);
|
||||||
break;
|
break;
|
||||||
case "key":
|
case "key":
|
||||||
case "press":
|
case "press":
|
||||||
case "presskey":
|
case "presskey":
|
||||||
case "keypress":
|
case "keypress":
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sender.sendMessage("§cUsage: /computer key <key> [down/up|duration(ticks)]");
|
sender.sendMessage("§cUsage: /computer key <key> [down/up|duration(ticks)]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length < 3)
|
if (args.length < 3)
|
||||||
PluginMain.Instance.PressKey(sender, args[1], "");
|
PluginMain.Instance.PressKey(sender, args[1], "");
|
||||||
else
|
else
|
||||||
PluginMain.Instance.PressKey(sender, args[1], args[2]);
|
PluginMain.Instance.PressKey(sender, args[1], args[2]);
|
||||||
break;
|
break;
|
||||||
case "mouse":
|
case "mouse":
|
||||||
boolean showusage = true;
|
boolean showusage = true;
|
||||||
if (args.length < 6) {
|
if (args.length < 6) {
|
||||||
// Command overloading, because I can :P
|
// Command overloading, because I can :P
|
||||||
if (args.length > 4) // 4<x<6
|
if (args.length > 4) // 4<x<6
|
||||||
{
|
{
|
||||||
PluginMain.Instance.UpdateMouse(sender, Integer.parseInt(args[1]), Integer.parseInt(args[2]),
|
PluginMain.Instance.UpdateMouse(sender, Integer.parseInt(args[1]), Integer.parseInt(args[2]),
|
||||||
Integer.parseInt(args[3]), Integer.parseInt(args[4]), "", false);
|
Integer.parseInt(args[3]), Integer.parseInt(args[4]), "", false);
|
||||||
showusage = false;
|
showusage = false;
|
||||||
} else {
|
} else {
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1], args[2].equals("down"));
|
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1], args[2].equals("down"));
|
||||||
showusage = false;
|
showusage = false;
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1]);
|
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1]);
|
||||||
showusage = false;
|
showusage = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (showusage) {
|
if (showusage) {
|
||||||
sender.sendMessage("§cUsage: /computer mouse <relx> <rely> <relz> <relw>");
|
sender.sendMessage("§cUsage: /computer mouse <relx> <rely> <relz> <relw>");
|
||||||
sender.sendMessage("§cOr: /computer mouse <button> [up/down]");
|
sender.sendMessage("§cOr: /computer mouse <button> [up/down]");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "input":
|
case "input":
|
||||||
case "show":
|
case "show":
|
||||||
case "showinput":
|
case "showinput":
|
||||||
case "shinput": {
|
case "shinput": {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage("§cError: Only players can use this command.");
|
sender.sendMessage("§cError: Only players can use this command.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sender.sendMessage("§cUsage: /computer input <key|mouse>");
|
sender.sendMessage("§cUsage: /computer input <key|mouse>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
case "key":
|
case "key":
|
||||||
case "keyboard":
|
case "keyboard":
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
+ " [\"\",{\"text\":\" [0]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D0\"}},{\"text\":\" [1]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D1\"}},{\"text\":\" [2]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D2\"}},{\"text\":\" [3]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D3\"}},{\"text\":\" [4]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D4\"}},{\"text\":\" [5]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D5\"}},{\"text\":\" [6]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D6\"}},{\"text\":\" [7]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D7\"}},{\"text\":\" [8]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D8\"}},{\"text\":\" [9]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D9\"}}]");
|
+ " [\"\",{\"text\":\" [0]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D0\"}},{\"text\":\" [1]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D1\"}},{\"text\":\" [2]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D2\"}},{\"text\":\" [3]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D3\"}},{\"text\":\" [4]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D4\"}},{\"text\":\" [5]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D5\"}},{\"text\":\" [6]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D6\"}},{\"text\":\" [7]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D7\"}},{\"text\":\" [8]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D8\"}},{\"text\":\" [9]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D9\"}}]");
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
+ " [\"\",{\"text\":\" [Tab]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Tab\"}},{\"text\":\" [Q]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Q\"}},{\"text\":\" [W]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key W\"}},{\"text\":\" [E]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key E\"}},{\"text\":\" [R]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key R\"}},{\"text\":\" [T]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key T\"}},{\"text\":\" [Y]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Y\"}},{\"text\":\" [U]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key U\"}},{\"text\":\" [I]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key I\"}},{\"text\":\" [O]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key O\"}},{\"text\":\" [P]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key P\"}}]");
|
+ " [\"\",{\"text\":\" [Tab]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Tab\"}},{\"text\":\" [Q]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Q\"}},{\"text\":\" [W]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key W\"}},{\"text\":\" [E]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key E\"}},{\"text\":\" [R]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key R\"}},{\"text\":\" [T]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key T\"}},{\"text\":\" [Y]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Y\"}},{\"text\":\" [U]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key U\"}},{\"text\":\" [I]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key I\"}},{\"text\":\" [O]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key O\"}},{\"text\":\" [P]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key P\"}}]");
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
+ " [\"\",{\"text\":\" [CapsLock]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key CapsLock\"}},{\"text\":\" [A]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key A\"}},{\"text\":\" [S]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key S\"}},{\"text\":\" [D]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D\"}},{\"text\":\" [F]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key F\"}},{\"text\":\" [G]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key G\"}},{\"text\":\" [H]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key H\"}},{\"text\":\" [J]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key J\"}},{\"text\":\" [K]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key K\"}},{\"text\":\" [L]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key L\"}},{\"text\":\" [Return]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Return\"}}]");
|
+ " [\"\",{\"text\":\" [CapsLock]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key CapsLock\"}},{\"text\":\" [A]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key A\"}},{\"text\":\" [S]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key S\"}},{\"text\":\" [D]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key D\"}},{\"text\":\" [F]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key F\"}},{\"text\":\" [G]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key G\"}},{\"text\":\" [H]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key H\"}},{\"text\":\" [J]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key J\"}},{\"text\":\" [K]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key K\"}},{\"text\":\" [L]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key L\"}},{\"text\":\" [Return]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Return\"}}]");
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
+ " [\"\",{\"text\":\" [Z]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Z\"}},{\"text\":\" [X]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key X\"}},{\"text\":\" [C]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key C\"}},{\"text\":\" [V]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key V\"}},{\"text\":\" [B]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key B\"}},{\"text\":\" [N]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key N\"}},{\"text\":\" [M]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key M\"}}]");
|
+ " [\"\",{\"text\":\" [Z]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Z\"}},{\"text\":\" [X]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key X\"}},{\"text\":\" [C]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key C\"}},{\"text\":\" [V]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key V\"}},{\"text\":\" [B]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key B\"}},{\"text\":\" [N]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key N\"}},{\"text\":\" [M]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key M\"}}]");
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
+ " [\"\",{\"text\":\" [Ctrl]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key ControlLeft\"}},{\"text\":\" [Alt]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key AltLeft\"}},{\"text\":\" [Space]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Space\"}},{\"text\":\" [AltGr]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key AltRight\"}},{\"text\":\" [Ctrl]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key ControlRight\"}}]");
|
+ " [\"\",{\"text\":\" [Ctrl]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key ControlLeft\"}},{\"text\":\" [Alt]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key AltLeft\"}},{\"text\":\" [Space]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key Space\"}},{\"text\":\" [AltGr]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key AltRight\"}},{\"text\":\" [Ctrl]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/computer key ControlRight\"}}]");
|
||||||
case "mouse":
|
case "mouse":
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
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.containsKey(sender)) {
|
if (!MouseLockerPlayerListener.LockedPlayers.containsKey(sender)) {
|
||||||
MouseLockerPlayerListener.LockedPlayers.put((Player) sender, ((Player) sender).getLocation());
|
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);
|
||||||
sender.sendMessage("§bMouse unlocked.");
|
sender.sendMessage("§bMouse unlocked.");
|
||||||
}
|
}
|
||||||
case "mspeed":
|
break;
|
||||||
case "mousespeed":
|
case "mspeed":
|
||||||
if (args.length < 3) {
|
case "mousespeed":
|
||||||
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
if (args.length < 3) {
|
||||||
return true;
|
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
||||||
}
|
return true;
|
||||||
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
|
}
|
||||||
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
|
||||||
}
|
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package sznp.virtualcomputer;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -61,6 +62,11 @@ public class DirectRenderer implements IRenderer {
|
||||||
WorldMap wmap = (WorldMap) field.get(map);
|
WorldMap wmap = (WorldMap) field.get(map);
|
||||||
wmap.flagDirty(0, 0);
|
wmap.flagDirty(0, 0);
|
||||||
wmap.flagDirty(127, 127); // Send the whole image - TODO: Only send changes
|
wmap.flagDirty(127, 127); // Send the whole image - TODO: Only send changes
|
||||||
|
/*
|
||||||
|
* final Field fieldf = map.getClass().getDeclaredField("renderCache"); fieldf.setAccessible(true);
|
||||||
|
* @SuppressWarnings("unchecked") final Map<CraftPlayer, RenderData> renderCache = (Map<CraftPlayer, RenderData>) fieldf.get(map); RenderData render = renderCache.get(null);
|
||||||
|
* System.out.println("==: " + (buffer == render.buffer)); System.out.println("equals:" + Arrays.equals(buffer, render.buffer));
|
||||||
|
*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (ex != null && (e.getMessage() == ex.getMessage()
|
if (ex != null && (e.getMessage() == ex.getMessage()
|
||||||
|| (e.getMessage() != null && e.getMessage().equals(ex.getMessage()))))
|
|| (e.getMessage() != null && e.getMessage().equals(ex.getMessage()))))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
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;
|
||||||
|
@ -74,18 +75,28 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
public void notify3DEvent(long arg0, byte[] arg1) {
|
public void notify3DEvent(long arg0, byte[] arg1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BukkitTask tt;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
||||||
if (width > 640 || height > 480)
|
System.out.println("Change - " + width + "x" + height);
|
||||||
return; // Don't even try to render too large resolutions
|
if (tt != null)
|
||||||
|
tt.cancel();
|
||||||
|
/*
|
||||||
|
* if (width > 640 || height > 480) { tt = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.Instance, () -> display.setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L), 5, 5);
|
||||||
|
* return; // Don't even try to render too large resolutions }
|
||||||
|
*/
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
||||||
display.querySourceBitmap(0L, holder);
|
display.querySourceBitmap(0L, holder);
|
||||||
byte[] arr = PluginMain.allpixels.array();
|
byte[] arr = PluginMain.allpixels.array();
|
||||||
holder.value.getTypedWrapped().queryBitmapInfo(arr, new long[] { width }, new long[] { height },
|
long[] w = new long[1], h = new long[1], bpp = new long[1], bpl = new long[1], pf = new long[1];
|
||||||
new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
|
holder.value.getTypedWrapped().queryBitmapInfo(arr, w, h, bpp, bpl, pf);
|
||||||
new long[] { getPixelFormat() }); // These are out params but whatever
|
System.out.println("Arr10:" + arr[10]);
|
||||||
System.out.println("Arr0:" + arr[0]);
|
System.out.println("whbppbplpf: " + w[0] + " " + h[0] + " " + bpp[0] + " " + bpl[0] + " " + pf[0]);
|
||||||
PluginMain.allpixels.limit((int) (width * height * 4));
|
if (width * height > 640 * 480)
|
||||||
|
PluginMain.allpixels.limit(640 * 480 * 4);
|
||||||
|
else
|
||||||
|
PluginMain.allpixels.limit((int) (width * height * 4));
|
||||||
for (IRenderer r : PluginMain.renderers)
|
for (IRenderer r : PluginMain.renderers)
|
||||||
if (r instanceof BukkitRenderer)
|
if (r instanceof BukkitRenderer)
|
||||||
((BukkitRenderer) r).setAllPixels(PluginMain.allpixels);
|
((BukkitRenderer) r).setAllPixels(PluginMain.allpixels);
|
||||||
|
@ -100,7 +111,6 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
for (IRenderer r : PluginMain.renderers)
|
for (IRenderer r : PluginMain.renderers)
|
||||||
if (r instanceof DirectRenderer)
|
if (r instanceof DirectRenderer)
|
||||||
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
|
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
|
||||||
System.out.println("Update!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
public class MouseLockerPlayerListener implements Runnable {
|
|
||||||
public static Map<Player, Location> LockedPlayers = new HashMap<>();
|
public class MouseLockerPlayerListener implements Runnable {
|
||||||
public static float LockedSpeed = 5;
|
public static Map<Player, Location> LockedPlayers = new HashMap<>();
|
||||||
|
public static float LockedSpeed = 5;
|
||||||
@Override
|
|
||||||
public void run() {
|
@Override
|
||||||
for (Entry<Player, Location> entry : LockedPlayers.entrySet()) {
|
public void run() {
|
||||||
float yaw1 = entry.getValue().getYaw();
|
for (Entry<Player, Location> entry : LockedPlayers.entrySet()) {
|
||||||
float pitch1 = entry.getValue().getPitch();
|
float yaw1 = entry.getValue().getYaw();
|
||||||
float yaw2 = entry.getKey().getLocation().getYaw();
|
float pitch1 = entry.getValue().getPitch();
|
||||||
float pitch2 = entry.getKey().getLocation().getPitch();
|
float yaw2 = entry.getKey().getLocation().getYaw();
|
||||||
if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
|
float pitch2 = entry.getKey().getLocation().getPitch();
|
||||||
return;
|
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, "");
|
||||||
entry.setValue(entry.getValue());
|
|
||||||
}
|
entry.getKey().teleport(entry.getValue(), TeleportCause.PLUGIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
private BukkitTask mousetask;
|
private BukkitTask mousetask;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480); // It's set on each change
|
public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
|
||||||
public static ArrayList<IRenderer> renderers = new ArrayList<>();
|
public static ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||||
|
|
||||||
// Fired when plugin is first enabled
|
// Fired when plugin is first enabled
|
||||||
|
@ -57,9 +57,10 @@ public class PluginMain extends JavaPlugin {
|
||||||
session = manager.getSessionObject(); // TODO: Events
|
session = manager.getSessionObject(); // TODO: Events
|
||||||
ccs.sendMessage("§bLoading Screen...");
|
ccs.sendMessage("§bLoading Screen...");
|
||||||
try {
|
try {
|
||||||
for (short i = 0; i < 20; i++)
|
throw new NoClassDefFoundError("Test error pls ignore");
|
||||||
|
/*for (short i = 0; i < 20; i++)
|
||||||
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
|
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
|
||||||
ccs.sendMessage("§bUsing Direct Renderer, all good");
|
ccs.sendMessage("§bUsing Direct Renderer, all good");*/
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (NoClassDefFoundError e) {
|
||||||
for (short i = 0; i < 20; i++)
|
for (short i = 0; i < 20; i++)
|
||||||
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));
|
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));
|
||||||
|
@ -97,7 +98,6 @@ public class PluginMain extends JavaPlugin {
|
||||||
session.setName("minecraft");
|
session.setName("minecraft");
|
||||||
// machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); - This creates a *process*, we don't want that anymore
|
// machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); - This creates a *process*, we don't want that anymore
|
||||||
machine.lockMachine(session, LockType.VM); // We want the machine inside *our* process <-- Need the VM type to have console access
|
machine.lockMachine(session, LockType.VM); // We want the machine inside *our* process <-- Need the VM type to have console access
|
||||||
sender.sendMessage("A: " + machine.getState().toString());
|
|
||||||
final Runnable tr = new Runnable() {
|
final Runnable tr = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (session.getState() != SessionState.Locked) { // https://www.virtualbox.org/sdkref/_virtual_box_8idl.html#ac82c179a797c0d7c249d1b98a8e3aa8f
|
if (session.getState() != SessionState.Locked) { // https://www.virtualbox.org/sdkref/_virtual_box_8idl.html#ac82c179a797c0d7c249d1b98a8e3aa8f
|
||||||
|
@ -105,24 +105,18 @@ public class PluginMain extends JavaPlugin {
|
||||||
return; // "This state also occurs as a short transient state during an IMachine::lockMachine call."
|
return; // "This state also occurs as a short transient state during an IMachine::lockMachine call."
|
||||||
}
|
}
|
||||||
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());
|
|
||||||
console.powerUp(); // https://marc.info/?l=vbox-dev&m=142780789819967&w=2
|
console.powerUp(); // https://marc.info/?l=vbox-dev&m=142780789819967&w=2
|
||||||
sender.sendMessage("2: " + console.getState().toString());
|
|
||||||
console.getDisplay().attachFramebuffer(0L,
|
console.getDisplay().attachFramebuffer(0L,
|
||||||
new IFramebuffer(new MCFrameBuffer(console.getDisplay())));
|
new IFramebuffer(new MCFrameBuffer(console.getDisplay())));
|
||||||
sender.sendMessage("3: " + console.getState().toString());
|
|
||||||
if (screenupdatetask == null)
|
if (screenupdatetask == null)
|
||||||
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.this, () -> {
|
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.this, () -> {
|
||||||
sender.sendMessage("4: " + console.getState().toString());
|
|
||||||
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
||||||
&& console.getState().equals(MachineState.Running))
|
&& console.getState().equals(MachineState.Running))
|
||||||
console.getDisplay().invalidateAndUpdateScreen(0L);
|
console.getDisplay().invalidateAndUpdateScreen(0L);
|
||||||
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
||||||
|| console.getState().equals(MachineState.PoweredOff)
|
|| console.getState().equals(MachineState.PoweredOff)
|
||||||
|| console.getState().equals(MachineState.Saved)) {
|
|| console.getState().equals(MachineState.Saved)) {
|
||||||
sender.sendMessage("5: " + console.getState().toString());
|
|
||||||
if (session.getState().equals(SessionState.Locked)) {
|
if (session.getState().equals(SessionState.Locked)) {
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
sender.sendMessage("Computer powered off, released it.");
|
sender.sendMessage("Computer powered off, released it.");
|
||||||
|
@ -141,8 +135,13 @@ public class PluginMain extends JavaPlugin {
|
||||||
public static int MouseSpeed = 1;
|
public static int MouseSpeed = 1;
|
||||||
|
|
||||||
public void Stop(CommandSender sender) {
|
public void Stop(CommandSender sender) {
|
||||||
if (!checkMachineRunning(sender))
|
if (!checkMachineRunning(sender)) {
|
||||||
|
if (session.getState().equals(SessionState.Locked)) {
|
||||||
|
session.unlockMachine();
|
||||||
|
sender.sendMessage("§eComputer powered off, released it.");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
sender.sendMessage("§eStopping computer...");
|
sender.sendMessage("§eStopping computer...");
|
||||||
session.getConsole().powerDown().waitForCompletion(2000);
|
session.getConsole().powerDown().waitForCompletion(2000);
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
|
Loading…
Reference in a new issue