Started integrating with Chroma-Core

This commit is contained in:
Norbi Peti 2020-09-03 02:01:25 +02:00
parent 26d8cc1ff0
commit 559b2989c6
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 91 additions and 27 deletions

View file

@ -2,12 +2,9 @@ package sznp.virtualcomputer;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode;
import lombok.val;
import me.lucko.commodore.Commodore;
import me.lucko.commodore.CommodoreProvider;
import me.lucko.commodore.file.CommodoreFileFormat;
import org.bukkit.Bukkit;
@ -76,7 +73,7 @@ public class Commands implements CommandExecutor, TabCompleter {
Boolean seamless;
if (args.length < 2) seamless = null;
else seamless = args[1].equalsIgnoreCase("true");
Computer.getInstance().FixScreen(sender, seamless);
Computer.getInstance().FixScreen(sender);
break;
case "key":
case "press":

View file

@ -163,25 +163,20 @@ public final class Computer {
}
}
public void FixScreen(CommandSender sender, Boolean seamless) {
public void FixScreen(CommandSender sender) {
if (checkMachineNotRunning(sender))
return;
if (framebuffer == null) {
sender.sendMessage("§cFramebuffer is null...");
return;
}
val lastUpdated = new Holder<Long>();
var status = session.getConsole().getGuest().getFacilityStatus(AdditionsFacilityType.Seamless, lastUpdated);
sendMessage(sender, "Seamless status: " + status);
sendMessage(sender, "§eFixing screen...");
try {
synchronized (session) {
if (seamless == null)
session.getConsole().getDisplay().setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L, false);
} //Last param: notify - send PnP notification - stops updates but not changes for some reason
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
synchronized (session) {
sendMessage(sender, "Needs host cursor: " + session.getConsole().getMouse().getNeedsHostCursor());
session.getConsole().getMouse().putMouseEventAbsolute(-1, -1, 0, 0, 0);
session.getConsole().getMouse().putMouseEvent(0, 0, 0, 0, 0); //Switch to relative mode
sendMessage(sender, "§eScreen fixed.");
@ -190,8 +185,6 @@ public final class Computer {
} catch (Exception e) {
e.printStackTrace();
}
status = session.getConsole().getGuest().getFacilityStatus(AdditionsFacilityType.Seamless, lastUpdated);
sendMessage(sender, "Seamless status: " + status);
}
public boolean checkMachineNotRunning(@Nullable CommandSender sender) {

View file

@ -0,0 +1,75 @@
package sznp.virtualcomputer;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import org.bukkit.command.CommandSender;
import org.virtualbox_6_1.VBoxException;
@CommandClass
public class ComputerCommand extends ICommand2MC {
@Command2.Subcommand
public void def(CommandSender sender) {
}
@Command2.Subcommand(aliases = {"poweron", "on"})
public void start(CommandSender sender, @Command2.OptionalArg int index) {
Computer.getInstance().Start(sender, index);
}
@Command2.Subcommand
public void list(CommandSender sender) {
Computer.getInstance().List(sender);
}
@Command2.Subcommand(aliases = {"poweroff", "off", "kill"})
public void stop(CommandSender sender) {
Computer.getInstance().Stop(sender);
}
@Command2.Subcommand(aliases = {"powerbtn", "pwrbtn"})
public void powerbutton(CommandSender sender, @Command2.OptionalArg int index) {
Computer.getInstance().PowerButton(sender, index);
}
@Command2.Subcommand(aliases = "restart")
public void reset(CommandSender sender) {
Computer.getInstance().Reset(sender);
}
@Command2.Subcommand(aliases = "savestate")
public void save(CommandSender sender) {
Computer.getInstance().SaveState(sender);
}
@Command2.Subcommand(aliases = "fixscreen")
public void fix(CommandSender sender) {
Computer.getInstance().FixScreen(sender);
}
@Command2.Subcommand(aliases = {"press", "presskey", "keypress"}, helpText = {
"Press key",
"Presses the specified key. Valid values for the last param are 'down', 'up' and amount of ticks to hold."
})
public void key(CommandSender sender, String key, @Command2.OptionalArg String stateorduration) {
if (stateorduration == null) stateorduration = "";
Computer.getInstance().PressKey(sender, key, stateorduration);
}
@Command2.Subcommand(helpText = {
"Mouse event",
"Move the mouse by the specified offset or press the given button."
})
public void mouse(CommandSender sender, String keyOrX, @Command2.OptionalArg int y, @Command2.OptionalArg int z, @Command2.OptionalArg int w) {
try {
if (y != 0 || z != 0 || w != 0) {
int x = Integer.parseInt(keyOrX);
Computer.getInstance().UpdateMouse(sender, x, y, z, w, "");
} else
Computer.getInstance().UpdateMouse(sender, 0, 0, 0, 0, keyOrX);
} catch (VBoxException e) {
throw e;
} catch (Exception ignored) {
}
}
}

View file

@ -1,10 +1,10 @@
package sznp.virtualcomputer;
import buttondevteam.lib.architecture.ButtonPlugin;
import jnr.ffi.LibraryLoader;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.virtualbox_6_1.IVirtualBox;
import org.virtualbox_6_1.VirtualBoxManager;
@ -21,33 +21,27 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Predicate;
public class PluginMain extends JavaPlugin {
public class PluginMain extends ButtonPlugin {
private static final int MCX = 5;
private static final int MCY = 4;
private BukkitTask mousetask;
private VBoxEventHandler listener;
public static PluginMain Instance;
//public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
/**
* Only used if {@link #direct} is false.
*/
public static ByteBuffer allpixels; // It's set on each change
private static final ArrayList<IRenderer> renderers = new ArrayList<>();
/*
* Only used if {@link #direct} is true.
*/
//public static PXCLib pxc;
public static boolean direct;
public static boolean sendAll;
// Fired when plugin is first enabled
@Override
public void onEnable() {
public void pluginEnable() {
Instance = this;
try {
ConsoleCommandSender ccs = getServer().getConsoleSender();
this.getCommand("computer").setExecutor(new Commands());
getCommand2MC().registerCommand(new ComputerCommand());
sendAll = getConfig().getBoolean("sendAll", true);
ccs.sendMessage("§bInitializing VirtualBox...");
String osname = System.getProperty("os.name").toLowerCase();
@ -106,8 +100,9 @@ public class PluginMain extends JavaPlugin {
getServer().getPluginManager().registerEvents(mlpl, this);
} catch (final Exception e) {
e.printStackTrace();
error(e.getMessage());
getLogger().severe("A fatal error occured, disabling plugin!");
Bukkit.getPluginManager().disablePlugin(this);
throw new RuntimeException(e);
}
}
@ -117,9 +112,8 @@ public class PluginMain extends JavaPlugin {
throw new RuntimeException(message);
}
// Fired when plugin is disabled
@Override
public void onDisable() {
public void pluginDisable() {
ConsoleCommandSender ccs = getServer().getConsoleSender();
if (mousetask != null)
mousetask.cancel();

View file

@ -80,6 +80,11 @@
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency> -->
<dependency>
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
<artifactId>Chroma-Core</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
<build>