Fixes, figuring things out, copied features

Added screen update task and the save state code from CSharp and things
like that.
This commit is contained in:
Norbi Peti 2017-07-14 02:58:01 +02:00
parent 02f3883c12
commit 3e1691f4e9
5 changed files with 96 additions and 150 deletions

View file

@ -7,6 +7,6 @@
<versions>
<version>5.1</version>
</versions>
<lastUpdated>20170111200516</lastUpdated>
<lastUpdated>20170706160733</lastUpdated>
</versioning>
</metadata>

View file

@ -10,183 +10,124 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands implements CommandExecutor
{
public class Commands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args)
{
switch (cmd.getName().toLowerCase())
{
case "computer":
{
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
switch (cmd.getName().toLowerCase()) {
case "computer": {
if (args.length == 0)
return false;
switch (args[0].toLowerCase())
{
switch (args[0].toLowerCase()) {
case "start":
PluginMain.getPlugin(PluginMain.class).Start(sender);
PluginMain.Instance.Start(sender);
break;
case "stop":
PluginMain.getPlugin(PluginMain.class).Stop(sender);
PluginMain.Instance.Stop(sender);
break;
case "debug":
World w = Bukkit.getWorlds().get(0);
Craft[] crafts = CraftManager.getInstance().getCraftsInWorld(w);
sender.sendMessage("World: " + w);
sender.sendMessage("Crafts: " + crafts);
sender.sendMessage("Craft type: "
+ crafts[0].getType().getCraftName());
sender.sendMessage("Craft type: " + crafts[0].getType().getCraftName());
sender.sendMessage("DX: " + crafts[0].getLastDX());
sender.sendMessage("DY: " + crafts[0].getLastDY());
sender.sendMessage("DZ: " + crafts[0].getLastDZ());
sender.sendMessage("MouseSpeed: " + PluginMain.MouseSpeed);
sender.sendMessage("Block: "
+ Bukkit.getWorlds()
.get(0)
.getBlockAt(crafts[0].getMinX(),
crafts[0].getMinY() - 1,
crafts[0].getMinZ()).getType()); // Block:
// AIR
sender.sendMessage("Block: " + Bukkit.getWorlds().get(0)
.getBlockAt(crafts[0].getMinX(), crafts[0].getMinY() - 1, crafts[0].getMinZ()).getType()); // Block:
// AIR
break;
case "powerbutton":
PluginMain.getPlugin(PluginMain.class).PowerButton(sender);
PluginMain.Instance.PowerButton(sender);
break;
case "reset":
PluginMain.getPlugin(PluginMain.class).Reset(sender);
PluginMain.Instance.Reset(sender);
break;
case "fix":
PluginMain.getPlugin(PluginMain.class).FixScreen(sender);
PluginMain.Instance.FixScreen(sender);
break;
case "key":
if (args.length < 2)
{
if (args.length < 2) {
sender.sendMessage("§cUsage: /computer key <key> [down/up|duration(ticks)]");
return true;
}
if (args.length < 3)
PluginMain.getPlugin(PluginMain.class).PressKey(sender,
args[1], "");
PluginMain.Instance.PressKey(sender, args[1], "");
else
PluginMain.getPlugin(PluginMain.class).PressKey(sender,
args[1], args[2]);
PluginMain.Instance.PressKey(sender, args[1], args[2]);
break;
case "mouse":
boolean showusage = true;
if (args.length < 6)
{
if (args.length < 6) {
// Command overloading, because I can :P
if (args.length > 4) // 4<x<6
{
PluginMain.getPlugin(PluginMain.class).UpdateMouse(
sender, Integer.parseInt(args[1]),
Integer.parseInt(args[2]),
Integer.parseInt(args[3]),
Integer.parseInt(args[4]), "", false);
PluginMain.Instance.UpdateMouse(sender, Integer.parseInt(args[1]), Integer.parseInt(args[2]),
Integer.parseInt(args[3]), Integer.parseInt(args[4]), "", false);
showusage = false;
} else
{
if (args.length == 3)
{
PluginMain.getPlugin(PluginMain.class).UpdateMouse(
sender, 0, 0, 0, 0, args[1],
(args[2].equals("down")));
} else {
if (args.length == 3) {
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1], (args[2].equals("down")));
showusage = false;
} else if (args.length == 2)
{
PluginMain.getPlugin(PluginMain.class).UpdateMouse(
sender, 0, 0, 0, 0, args[1]);
} else if (args.length == 2) {
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1]);
showusage = false;
}
}
}
if (showusage)
{
if (showusage) {
sender.sendMessage("§cUsage: /computer mouse <relx> <rely> <relz> <relw>");
sender.sendMessage("§cOr: /computer mouse <button> [up/down]");
}
break;
case "mspeed":
if (args.length < 2)
{
if (args.length < 2) {
sender.sendMessage("§cUsage: /computer mspeed <speed>");
return true;
}
PluginMain.MouseSpeed = Integer.parseInt(args[1]);
sender.sendMessage("Mouse speed set to " + args[1]);
break;
case "input":
{
if (!(sender instanceof Player))
{
case "input": {
if (!(sender instanceof Player)) {
sender.sendMessage("§cError: Only players can use this command.");
return true;
}
if (args.length < 2)
{
if (args.length < 2) {
sender.sendMessage("§cUsage: /computer input <key|mouse>");
return true;
}
if (args[1].equalsIgnoreCase("key"))
{
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\"}}]");
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\"}}]");
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\"}}]");
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\"}}]");
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\"}}]");
} else if (args[1].equalsIgnoreCase("mouse"))
{
if (!(sender instanceof Player))
{
if (args[1].equalsIgnoreCase("key")) {
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\"}}]");
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\"}}]");
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\"}}]");
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\"}}]");
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\"}}]");
} else if (args[1].equalsIgnoreCase("mouse")) {
if (!(sender instanceof Player)) {
sender.sendMessage("§cOnly ingame players can use this command.");
return true;
}
if (!MouseLockerPlayerListener.LockedPlayers
.contains(sender))
{
MouseLockerPlayerListener.LockedPlayers
.add((Player) sender);
if (!MouseLockerPlayerListener.LockedPlayers.contains(sender)) {
MouseLockerPlayerListener.LockedPlayers.add((Player) sender);
sender.sendMessage("§aMouse locked.");
} else
{
} else {
MouseLockerPlayerListener.LockedPlayers.remove(sender);
sender.sendMessage("§bMouse unlocked.");
}
} else if (args[1].equalsIgnoreCase("mspeed"))
{
if (args.length < 3)
{
} else if (args[1].equalsIgnoreCase("mspeed")) {
if (args.length < 3) {
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
return true;
}
MouseLockerPlayerListener.LockedSpeed = Float
.parseFloat(args[2]);
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
}
break;

View file

@ -5,12 +5,21 @@ import org.mozilla.interfaces.IFramebufferOverlay;
import org.mozilla.interfaces.nsISupports;
import org.virtualbox_5_1.BitmapFormat;
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 {
private IDisplay display;
private Holder<IDisplaySourceBitmap> holder;
public MCFrameBuffer(IDisplay display) {
this.display = display;
}
@Override
public nsISupports queryInterface(String arg0) {
return null;
return this;
}
@Override
@ -68,16 +77,22 @@ public class MCFrameBuffer implements IFramebuffer {
}
@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
public void notifyUpdate(long arg0, long arg1, long arg2, long arg3) {
System.out.println("Update!");
}
@Override
public void notifyUpdateImage(long arg0, long arg1, long arg2, long arg3, byte[] arg4) {
System.out.println("Update!");
System.out.println("Update image!");
}
@Override

View file

@ -4,14 +4,11 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.virtualbox_5_1.*;
import com.google.common.collect.Lists;
@ -21,6 +18,7 @@ public class PluginMain extends JavaPlugin {
private ISession session;
private ArrayList<IRenderer> renderers = new ArrayList<>();
private IMachine machine;
private BukkitTask screenupdatetask;
public static PluginMain Instance;
public static byte[] allpixels = new byte[640 * 480];
@ -43,7 +41,7 @@ public class PluginMain extends JavaPlugin {
addLibraryPath(vbpath);
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
vbox = manager.getVBox();
session = manager.getSessionObject();
session = manager.getSessionObject(); // TODO: Events
ccs.sendMessage("§bLoading Screen...");
try {
for (short i = 0; i < 20; i++)
@ -56,7 +54,6 @@ public class PluginMain extends JavaPlugin {
}
ccs.sendMessage("§bLoaded!");
getServer().getPluginManager().registerEvents(new MouseLockerPlayerListener(), this);
DoStart();
} catch (final Exception e) {
e.printStackTrace();
}
@ -66,46 +63,39 @@ public class PluginMain extends JavaPlugin {
@Override
public void onDisable() {
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.");
saveConfig();
}
public void Start(CommandSender sender) {
sender.sendMessage("§eStarting computer...");
if (machine == null)
machine = vbox.getMachines().get(0);
machine.launchVMProcess(session, "headless", "").waitForCompletion(10000);
session.getConsole().getDisplay().attachFramebuffer(0L, new IFramebuffer(new MCFrameBuffer()));
sender.sendMessage("§eComputer started.");
DoStart();
public void Start(CommandSender sender) {// TODO: Add touchscreen support (#2)
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
sender.sendMessage("§eStarting computer...");
if (machine == null)
machine = vbox.getMachines().get(0);
machine.launchVMProcess(session, "headless", "").waitForCompletion(10000);
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.");
});
}
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) {
sender.sendMessage("§eStopping computer...");
session.getConsole().powerDown().waitForCompletion(2000);