Directly using VirtualBox from Java #5
5 changed files with 96 additions and 150 deletions
Binary file not shown.
|
@ -7,6 +7,6 @@
|
||||||
<versions>
|
<versions>
|
||||||
<version>5.1</version>
|
<version>5.1</version>
|
||||||
</versions>
|
</versions>
|
||||||
<lastUpdated>20170111200516</lastUpdated>
|
<lastUpdated>20170706160733</lastUpdated>
|
||||||
</versioning>
|
</versioning>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|
|
@ -10,183 +10,124 @@ 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,
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
String[] args)
|
switch (cmd.getName().toLowerCase()) {
|
||||||
{
|
case "computer": {
|
||||||
switch (cmd.getName().toLowerCase())
|
|
||||||
{
|
|
||||||
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":
|
||||||
PluginMain.getPlugin(PluginMain.class).Start(sender);
|
PluginMain.Instance.Start(sender);
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
PluginMain.getPlugin(PluginMain.class).Stop(sender);
|
PluginMain.Instance.Stop(sender);
|
||||||
break;
|
break;
|
||||||
case "debug":
|
case "debug":
|
||||||
World w = Bukkit.getWorlds().get(0);
|
World w = Bukkit.getWorlds().get(0);
|
||||||
Craft[] crafts = CraftManager.getInstance().getCraftsInWorld(w);
|
Craft[] crafts = CraftManager.getInstance().getCraftsInWorld(w);
|
||||||
sender.sendMessage("World: " + w);
|
sender.sendMessage("World: " + w);
|
||||||
sender.sendMessage("Crafts: " + crafts);
|
sender.sendMessage("Crafts: " + crafts);
|
||||||
sender.sendMessage("Craft type: "
|
sender.sendMessage("Craft type: " + crafts[0].getType().getCraftName());
|
||||||
+ crafts[0].getType().getCraftName());
|
|
||||||
sender.sendMessage("DX: " + crafts[0].getLastDX());
|
sender.sendMessage("DX: " + crafts[0].getLastDX());
|
||||||
sender.sendMessage("DY: " + crafts[0].getLastDY());
|
sender.sendMessage("DY: " + crafts[0].getLastDY());
|
||||||
sender.sendMessage("DZ: " + crafts[0].getLastDZ());
|
sender.sendMessage("DZ: " + crafts[0].getLastDZ());
|
||||||
sender.sendMessage("MouseSpeed: " + PluginMain.MouseSpeed);
|
sender.sendMessage("MouseSpeed: " + PluginMain.MouseSpeed);
|
||||||
sender.sendMessage("Block: "
|
sender.sendMessage("Block: " + Bukkit.getWorlds().get(0)
|
||||||
+ Bukkit.getWorlds()
|
.getBlockAt(crafts[0].getMinX(), crafts[0].getMinY() - 1, crafts[0].getMinZ()).getType()); // Block:
|
||||||
.get(0)
|
|
||||||
.getBlockAt(crafts[0].getMinX(),
|
|
||||||
crafts[0].getMinY() - 1,
|
|
||||||
crafts[0].getMinZ()).getType()); // Block:
|
|
||||||
// AIR
|
// AIR
|
||||||
break;
|
break;
|
||||||
case "powerbutton":
|
case "powerbutton":
|
||||||
PluginMain.getPlugin(PluginMain.class).PowerButton(sender);
|
PluginMain.Instance.PowerButton(sender);
|
||||||
break;
|
break;
|
||||||
case "reset":
|
case "reset":
|
||||||
PluginMain.getPlugin(PluginMain.class).Reset(sender);
|
PluginMain.Instance.Reset(sender);
|
||||||
break;
|
break;
|
||||||
case "fix":
|
case "fix":
|
||||||
PluginMain.getPlugin(PluginMain.class).FixScreen(sender);
|
PluginMain.Instance.FixScreen(sender);
|
||||||
break;
|
break;
|
||||||
case "key":
|
case "key":
|
||||||
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.getPlugin(PluginMain.class).PressKey(sender,
|
PluginMain.Instance.PressKey(sender, args[1], "");
|
||||||
args[1], "");
|
|
||||||
else
|
else
|
||||||
PluginMain.getPlugin(PluginMain.class).PressKey(sender,
|
PluginMain.Instance.PressKey(sender, args[1], args[2]);
|
||||||
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.getPlugin(PluginMain.class).UpdateMouse(
|
PluginMain.Instance.UpdateMouse(sender, Integer.parseInt(args[1]), Integer.parseInt(args[2]),
|
||||||
sender, Integer.parseInt(args[1]),
|
Integer.parseInt(args[3]), Integer.parseInt(args[4]), "", false);
|
||||||
Integer.parseInt(args[2]),
|
|
||||||
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.getPlugin(PluginMain.class).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.getPlugin(PluginMain.class).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 "mspeed":
|
case "mspeed":
|
||||||
if (args.length < 2)
|
if (args.length < 2) {
|
||||||
{
|
|
||||||
sender.sendMessage("§cUsage: /computer mspeed <speed>");
|
sender.sendMessage("§cUsage: /computer mspeed <speed>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PluginMain.MouseSpeed = Integer.parseInt(args[1]);
|
PluginMain.MouseSpeed = Integer.parseInt(args[1]);
|
||||||
sender.sendMessage("Mouse speed set to " + args[1]);
|
sender.sendMessage("Mouse speed set to " + args[1]);
|
||||||
break;
|
break;
|
||||||
case "input":
|
case "input": {
|
||||||
{
|
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;
|
||||||
}
|
}
|
||||||
if (args[1].equalsIgnoreCase("key"))
|
if (args[1].equalsIgnoreCase("key")) {
|
||||||
{
|
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()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
.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()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
.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()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
.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()
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName()
|
||||||
.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\"}}]");
|
||||||
} else if (args[1].equalsIgnoreCase("mouse"))
|
} else if (args[1].equalsIgnoreCase("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
|
if (!MouseLockerPlayerListener.LockedPlayers.contains(sender)) {
|
||||||
.contains(sender))
|
MouseLockerPlayerListener.LockedPlayers.add((Player) sender);
|
||||||
{
|
|
||||||
MouseLockerPlayerListener.LockedPlayers
|
|
||||||
.add((Player) sender);
|
|
||||||
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.");
|
||||||
}
|
}
|
||||||
} else if (args[1].equalsIgnoreCase("mspeed"))
|
} else if (args[1].equalsIgnoreCase("mspeed")) {
|
||||||
{
|
if (args.length < 3) {
|
||||||
if (args.length < 3)
|
|
||||||
{
|
|
||||||
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MouseLockerPlayerListener.LockedSpeed = Float
|
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
|
||||||
.parseFloat(args[2]);
|
|
||||||
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,12 +5,21 @@ import org.mozilla.interfaces.IFramebufferOverlay;
|
||||||
import org.mozilla.interfaces.nsISupports;
|
import org.mozilla.interfaces.nsISupports;
|
||||||
import org.virtualbox_5_1.BitmapFormat;
|
import org.virtualbox_5_1.BitmapFormat;
|
||||||
import org.virtualbox_5_1.FramebufferCapabilities;
|
import org.virtualbox_5_1.FramebufferCapabilities;
|
||||||
|
import org.virtualbox_5_1.Holder;
|
||||||
|
import org.virtualbox_5_1.IDisplay;
|
||||||
|
import org.virtualbox_5_1.IDisplaySourceBitmap;
|
||||||
|
|
||||||
public class MCFrameBuffer implements IFramebuffer {
|
public class MCFrameBuffer implements IFramebuffer {
|
||||||
|
private IDisplay display;
|
||||||
|
private Holder<IDisplaySourceBitmap> holder;
|
||||||
|
|
||||||
|
public MCFrameBuffer(IDisplay display) {
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public nsISupports queryInterface(String arg0) {
|
public nsISupports queryInterface(String arg0) {
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,16 +77,22 @@ public class MCFrameBuffer implements IFramebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyChange(long arg0, long arg1, long arg2, long arg3, long arg4) {
|
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
||||||
|
display.querySourceBitmap(0L, holder); // TODO: Crashes here
|
||||||
|
holder.value.getTypedWrapped().queryBitmapInfo(PluginMain.allpixels, new long[] { width },
|
||||||
|
new long[] { height }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
|
||||||
|
new long[] { getPixelFormat() }); // These are out params but whatever
|
||||||
|
System.out.println("Change!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyUpdate(long arg0, long arg1, long arg2, long arg3) {
|
public void notifyUpdate(long arg0, long arg1, long arg2, long arg3) {
|
||||||
|
System.out.println("Update!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) {
|
public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) {
|
||||||
System.out.println("Update!");
|
System.out.println("Update image!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,14 +4,11 @@ import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import net.countercraft.movecraft.craft.Craft;
|
|
||||||
import net.countercraft.movecraft.craft.CraftManager;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.virtualbox_5_1.*;
|
import org.virtualbox_5_1.*;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -21,6 +18,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
private ISession session;
|
private ISession session;
|
||||||
private ArrayList<IRenderer> renderers = new ArrayList<>();
|
private ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||||
private IMachine machine;
|
private IMachine machine;
|
||||||
|
private BukkitTask screenupdatetask;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
public static byte[] allpixels = new byte[640 * 480];
|
public static byte[] allpixels = new byte[640 * 480];
|
||||||
|
@ -43,7 +41,7 @@ public class PluginMain extends JavaPlugin {
|
||||||
addLibraryPath(vbpath);
|
addLibraryPath(vbpath);
|
||||||
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
||||||
vbox = manager.getVBox();
|
vbox = manager.getVBox();
|
||||||
session = manager.getSessionObject();
|
session = manager.getSessionObject(); // TODO: Events
|
||||||
ccs.sendMessage("§bLoading Screen...");
|
ccs.sendMessage("§bLoading Screen...");
|
||||||
try {
|
try {
|
||||||
for (short i = 0; i < 20; i++)
|
for (short i = 0; i < 20; i++)
|
||||||
|
@ -56,7 +54,6 @@ public class PluginMain extends JavaPlugin {
|
||||||
}
|
}
|
||||||
ccs.sendMessage("§bLoaded!");
|
ccs.sendMessage("§bLoaded!");
|
||||||
getServer().getPluginManager().registerEvents(new MouseLockerPlayerListener(), this);
|
getServer().getPluginManager().registerEvents(new MouseLockerPlayerListener(), this);
|
||||||
DoStart();
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -66,46 +63,39 @@ public class PluginMain extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
||||||
|
ccs.sendMessage("§aSaving machine state...");
|
||||||
|
if (session.getState() == SessionState.Locked && session.getMachine().getState().equals(MachineState.Running))
|
||||||
|
session.getMachine().saveState();
|
||||||
|
|
||||||
ccs.sendMessage("§aHuh.");
|
ccs.sendMessage("§aHuh.");
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(CommandSender sender) {
|
public void Start(CommandSender sender) {// TODO: Add touchscreen support (#2)
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
sender.sendMessage("§eStarting computer...");
|
sender.sendMessage("§eStarting computer...");
|
||||||
if (machine == null)
|
if (machine == null)
|
||||||
machine = vbox.getMachines().get(0);
|
machine = vbox.getMachines().get(0);
|
||||||
machine.launchVMProcess(session, "headless", "").waitForCompletion(10000);
|
machine.launchVMProcess(session, "headless", "").waitForCompletion(10000);
|
||||||
session.getConsole().getDisplay().attachFramebuffer(0L, new IFramebuffer(new MCFrameBuffer()));
|
session.getConsole().getDisplay().attachFramebuffer(0L,
|
||||||
|
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
|
||||||
|
if (screenupdatetask == null)
|
||||||
|
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||||
|
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
||||||
|
&& session.getConsole().getState().equals(MachineState.Running))
|
||||||
|
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L);
|
||||||
|
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
||||||
|
|| session.getConsole().getState().equals(MachineState.PoweredOff)) {
|
||||||
|
screenupdatetask.cancel();
|
||||||
|
screenupdatetask = null;
|
||||||
|
}
|
||||||
|
}, 100, 100); // Do a full update every 2 seconds
|
||||||
sender.sendMessage("§eComputer started.");
|
sender.sendMessage("§eComputer started.");
|
||||||
DoStart();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MouseSpeed = 1;
|
public static int MouseSpeed = 1;
|
||||||
|
|
||||||
private void DoStart() {
|
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Movecraft")) {
|
|
||||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
Craft[] crafts = CraftManager.getInstance().getCraftsInWorld(Bukkit.getWorlds().get(0));
|
|
||||||
if (crafts == null)
|
|
||||||
return;
|
|
||||||
for (Craft c : crafts) {
|
|
||||||
if (c.getType().getCraftName().equalsIgnoreCase("mouse")) {
|
|
||||||
int dx = c.getLastDX();
|
|
||||||
// int dy = c.getLastDY();
|
|
||||||
int dz = c.getLastDZ();
|
|
||||||
if (Bukkit.getWorlds().get(0).getBlockAt(c.getMinX(), c.getMinY() - 1, c.getMinZ())
|
|
||||||
.getType() != Material.AIR && (dx != 0 || dz != 0))
|
|
||||||
UpdateMouse(null, dx * MouseSpeed, dz * MouseSpeed, 0, 0, "");
|
|
||||||
c.setLastDX(0);
|
|
||||||
c.setLastDZ(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop(CommandSender sender) {
|
public void Stop(CommandSender sender) {
|
||||||
sender.sendMessage("§eStopping computer...");
|
sender.sendMessage("§eStopping computer...");
|
||||||
session.getConsole().powerDown().waitForCompletion(2000);
|
session.getConsole().powerDown().waitForCompletion(2000);
|
||||||
|
|
Loading…
Reference in a new issue