Made the machine run in our process, fixes
This commit is contained in:
parent
57a6ff818b
commit
042c67a30b
2 changed files with 18 additions and 13 deletions
|
@ -4,11 +4,7 @@ import org.bukkit.Bukkit;
|
|||
import org.mozilla.interfaces.IFramebuffer;
|
||||
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;
|
||||
import org.virtualbox_5_1.*;
|
||||
|
||||
public class MCFrameBuffer implements IFramebuffer {
|
||||
private IDisplay display;
|
||||
|
@ -35,7 +31,7 @@ public class MCFrameBuffer implements IFramebuffer {
|
|||
|
||||
@Override
|
||||
public long[] getCapabilities(long[] arg0) {
|
||||
return new long[] { FramebufferCapabilities.UpdateImage.value() };
|
||||
return new long[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +76,7 @@ public class MCFrameBuffer implements IFramebuffer {
|
|||
@Override
|
||||
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
||||
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 },
|
||||
new long[] { height }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
|
||||
new long[] { getPixelFormat() }); // These are out params but whatever
|
||||
|
|
|
@ -63,10 +63,13 @@ 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();
|
||||
|
||||
if (session.getState() == SessionState.Locked) {
|
||||
if (session.getMachine().getState().equals(MachineState.Running)) {
|
||||
ccs.sendMessage("§aSaving machine state...");
|
||||
session.getMachine().saveState().waitForCompletion(10000);
|
||||
}
|
||||
session.unlockMachine();
|
||||
}
|
||||
ccs.sendMessage("§aHuh.");
|
||||
saveConfig();
|
||||
}
|
||||
|
@ -76,7 +79,10 @@ public class PluginMain extends JavaPlugin {
|
|||
sender.sendMessage("§eStarting computer...");
|
||||
if (machine == null)
|
||||
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,
|
||||
new IFramebuffer(new MCFrameBuffer(session.getConsole().getDisplay())));
|
||||
if (screenupdatetask == null)
|
||||
|
@ -86,6 +92,8 @@ public class PluginMain extends JavaPlugin {
|
|||
session.getConsole().getDisplay().invalidateAndUpdateScreen(0L);
|
||||
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
||||
|| session.getConsole().getState().equals(MachineState.PoweredOff)) {
|
||||
if (session.getState().equals(SessionState.Locked))
|
||||
session.unlockMachine();
|
||||
screenupdatetask.cancel();
|
||||
screenupdatetask = null;
|
||||
}
|
||||
|
@ -99,6 +107,7 @@ public class PluginMain extends JavaPlugin {
|
|||
public void Stop(CommandSender sender) {
|
||||
sender.sendMessage("§eStopping computer...");
|
||||
session.getConsole().powerDown().waitForCompletion(2000);
|
||||
session.unlockMachine();
|
||||
sender.sendMessage("§eComputer stopped.");
|
||||
}
|
||||
|
||||
|
@ -121,7 +130,7 @@ public class PluginMain extends JavaPlugin {
|
|||
public void Reset(CommandSender sender) {
|
||||
sender.sendMessage("§eResetting computer...");
|
||||
if (session.getState() == SessionState.Locked)
|
||||
session.getConsole().powerDown().waitForCompletion(10000);
|
||||
session.getConsole().reset();
|
||||
sender.sendMessage("§eComputer reset.");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue