Made the machine run in our process, fixes

This commit is contained in:
Norbi Peti 2017-08-04 14:01:03 +02:00
parent 57a6ff818b
commit 042c67a30b
2 changed files with 18 additions and 13 deletions

View file

@ -4,11 +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.virtualbox_5_1.BitmapFormat; import org.virtualbox_5_1.*;
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 IDisplay display;
@ -35,7 +31,7 @@ public class MCFrameBuffer implements IFramebuffer {
@Override @Override
public long[] getCapabilities(long[] arg0) { public long[] getCapabilities(long[] arg0) {
return new long[] { FramebufferCapabilities.UpdateImage.value() }; return new long[] {};
} }
@Override @Override
@ -80,7 +76,7 @@ public class MCFrameBuffer implements IFramebuffer {
@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) {
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> { Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
display.querySourceBitmap(0L, holder); // TODO: Crashes here display.querySourceBitmap(0L, holder); // TODO: Test if it crashes here
holder.value.getTypedWrapped().queryBitmapInfo(PluginMain.allpixels, new long[] { width }, holder.value.getTypedWrapped().queryBitmapInfo(PluginMain.allpixels, new long[] { width },
new long[] { height }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() }, new long[] { height }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
new long[] { getPixelFormat() }); // These are out params but whatever new long[] { getPixelFormat() }); // These are out params but whatever

View file

@ -63,10 +63,13 @@ public class PluginMain extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
ConsoleCommandSender ccs = getServer().getConsoleSender(); ConsoleCommandSender ccs = getServer().getConsoleSender();
if (session.getState() == SessionState.Locked) {
if (session.getMachine().getState().equals(MachineState.Running)) {
ccs.sendMessage("§aSaving machine state..."); ccs.sendMessage("§aSaving machine state...");
if (session.getState() == SessionState.Locked && session.getMachine().getState().equals(MachineState.Running)) session.getMachine().saveState().waitForCompletion(10000);
session.getMachine().saveState(); }
session.unlockMachine();
}
ccs.sendMessage("§aHuh."); ccs.sendMessage("§aHuh.");
saveConfig(); saveConfig();
} }
@ -76,7 +79,10 @@ public class PluginMain extends JavaPlugin {
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); - This creates a *process*, we don't want that anymore
machine.lockMachine(session, LockType.Write); // We want the machine inside *our* process
machine = session.getMachine(); // This is the Machine object we can work with
session.getConsole().powerUp().waitForCompletion(10000);
session.getConsole().getDisplay().attachFramebuffer(0L, session.getConsole().getDisplay().attachFramebuffer(0L,
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay()))); new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
if (screenupdatetask == null) if (screenupdatetask == null)
@ -86,6 +92,8 @@ public class PluginMain extends JavaPlugin {
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L); session.getConsole().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
|| session.getConsole().getState().equals(MachineState.PoweredOff)) { || session.getConsole().getState().equals(MachineState.PoweredOff)) {
if (session.getState().equals(SessionState.Locked))
session.unlockMachine();
screenupdatetask.cancel(); screenupdatetask.cancel();
screenupdatetask = null; screenupdatetask = null;
} }
@ -99,6 +107,7 @@ public class PluginMain extends JavaPlugin {
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);
session.unlockMachine();
sender.sendMessage("§eComputer stopped."); sender.sendMessage("§eComputer stopped.");
} }
@ -121,7 +130,7 @@ public class PluginMain extends JavaPlugin {
public void Reset(CommandSender sender) { public void Reset(CommandSender sender) {
sender.sendMessage("§eResetting computer..."); sender.sendMessage("§eResetting computer...");
if (session.getState() == SessionState.Locked) if (session.getState() == SessionState.Locked)
session.getConsole().powerDown().waitForCompletion(10000); session.getConsole().reset();
sender.sendMessage("§eComputer reset."); sender.sendMessage("§eComputer reset.");
} }