Started integrating with Chroma-Core
This commit is contained in:
parent
26d8cc1ff0
commit
559b2989c6
5 changed files with 91 additions and 27 deletions
|
@ -2,12 +2,9 @@ package sznp.virtualcomputer;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
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.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import me.lucko.commodore.Commodore;
|
|
||||||
import me.lucko.commodore.CommodoreProvider;
|
import me.lucko.commodore.CommodoreProvider;
|
||||||
import me.lucko.commodore.file.CommodoreFileFormat;
|
import me.lucko.commodore.file.CommodoreFileFormat;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -76,7 +73,7 @@ public class Commands implements CommandExecutor, TabCompleter {
|
||||||
Boolean seamless;
|
Boolean seamless;
|
||||||
if (args.length < 2) seamless = null;
|
if (args.length < 2) seamless = null;
|
||||||
else seamless = args[1].equalsIgnoreCase("true");
|
else seamless = args[1].equalsIgnoreCase("true");
|
||||||
Computer.getInstance().FixScreen(sender, seamless);
|
Computer.getInstance().FixScreen(sender);
|
||||||
break;
|
break;
|
||||||
case "key":
|
case "key":
|
||||||
case "press":
|
case "press":
|
||||||
|
|
|
@ -163,25 +163,20 @@ public final class Computer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixScreen(CommandSender sender, Boolean seamless) {
|
public void FixScreen(CommandSender sender) {
|
||||||
if (checkMachineNotRunning(sender))
|
if (checkMachineNotRunning(sender))
|
||||||
return;
|
return;
|
||||||
if (framebuffer == null) {
|
if (framebuffer == null) {
|
||||||
sender.sendMessage("§cFramebuffer is null...");
|
sender.sendMessage("§cFramebuffer is null...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val lastUpdated = new Holder<Long>();
|
|
||||||
var status = session.getConsole().getGuest().getFacilityStatus(AdditionsFacilityType.Seamless, lastUpdated);
|
|
||||||
sendMessage(sender, "Seamless status: " + status);
|
|
||||||
sendMessage(sender, "§eFixing screen...");
|
sendMessage(sender, "§eFixing screen...");
|
||||||
try {
|
try {
|
||||||
synchronized (session) {
|
synchronized (session) {
|
||||||
if (seamless == null)
|
|
||||||
session.getConsole().getDisplay().setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L, false);
|
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
|
} //Last param: notify - send PnP notification - stops updates but not changes for some reason
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
||||||
synchronized (session) {
|
synchronized (session) {
|
||||||
sendMessage(sender, "Needs host cursor: " + session.getConsole().getMouse().getNeedsHostCursor());
|
|
||||||
session.getConsole().getMouse().putMouseEventAbsolute(-1, -1, 0, 0, 0);
|
session.getConsole().getMouse().putMouseEventAbsolute(-1, -1, 0, 0, 0);
|
||||||
session.getConsole().getMouse().putMouseEvent(0, 0, 0, 0, 0); //Switch to relative mode
|
session.getConsole().getMouse().putMouseEvent(0, 0, 0, 0, 0); //Switch to relative mode
|
||||||
sendMessage(sender, "§eScreen fixed.");
|
sendMessage(sender, "§eScreen fixed.");
|
||||||
|
@ -190,8 +185,6 @@ public final class Computer {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
status = session.getConsole().getGuest().getFacilityStatus(AdditionsFacilityType.Seamless, lastUpdated);
|
|
||||||
sendMessage(sender, "Seamless status: " + status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkMachineNotRunning(@Nullable CommandSender sender) {
|
public boolean checkMachineNotRunning(@Nullable CommandSender sender) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
|
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||||
import jnr.ffi.LibraryLoader;
|
import jnr.ffi.LibraryLoader;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.virtualbox_6_1.IVirtualBox;
|
import org.virtualbox_6_1.IVirtualBox;
|
||||||
import org.virtualbox_6_1.VirtualBoxManager;
|
import org.virtualbox_6_1.VirtualBoxManager;
|
||||||
|
@ -21,33 +21,27 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.function.Predicate;
|
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 MCX = 5;
|
||||||
private static final int MCY = 4;
|
private static final int MCY = 4;
|
||||||
private BukkitTask mousetask;
|
private BukkitTask mousetask;
|
||||||
private VBoxEventHandler listener;
|
private VBoxEventHandler listener;
|
||||||
|
|
||||||
public static PluginMain Instance;
|
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.
|
* Only used if {@link #direct} is false.
|
||||||
*/
|
*/
|
||||||
public static ByteBuffer allpixels; // It's set on each change
|
public static ByteBuffer allpixels; // It's set on each change
|
||||||
private static final ArrayList<IRenderer> renderers = new ArrayList<>();
|
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 direct;
|
||||||
public static boolean sendAll;
|
public static boolean sendAll;
|
||||||
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void pluginEnable() {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
try {
|
try {
|
||||||
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
||||||
this.getCommand("computer").setExecutor(new Commands());
|
getCommand2MC().registerCommand(new ComputerCommand());
|
||||||
sendAll = getConfig().getBoolean("sendAll", true);
|
sendAll = getConfig().getBoolean("sendAll", true);
|
||||||
ccs.sendMessage("§bInitializing VirtualBox...");
|
ccs.sendMessage("§bInitializing VirtualBox...");
|
||||||
String osname = System.getProperty("os.name").toLowerCase();
|
String osname = System.getProperty("os.name").toLowerCase();
|
||||||
|
@ -106,8 +100,9 @@ public class PluginMain extends JavaPlugin {
|
||||||
getServer().getPluginManager().registerEvents(mlpl, this);
|
getServer().getPluginManager().registerEvents(mlpl, this);
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
getLogger().severe("A fatal error occured, disabling plugin!");
|
||||||
error(e.getMessage());
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,9 +112,8 @@ public class PluginMain extends JavaPlugin {
|
||||||
throw new RuntimeException(message);
|
throw new RuntimeException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void pluginDisable() {
|
||||||
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
ConsoleCommandSender ccs = getServer().getConsoleSender();
|
||||||
if (mousetask != null)
|
if (mousetask != null)
|
||||||
mousetask.cancel();
|
mousetask.cancel();
|
||||||
|
|
5
pom.xml
5
pom.xml
|
@ -80,6 +80,11 @@
|
||||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency> -->
|
</dependency> -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
|
||||||
|
<artifactId>Chroma-Core</artifactId>
|
||||||
|
<version>master-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
Loading…
Reference in a new issue