Fiiiiiiixes
This commit is contained in:
parent
0af3905f86
commit
a888795be5
6 changed files with 202 additions and 185 deletions
|
@ -36,7 +36,7 @@ public class BukkitRenderer extends MapRenderer implements IRenderer {
|
|||
MapView map = IRenderer.prepare(id, world);
|
||||
map.addRenderer(this);
|
||||
this.startindex = startindex;
|
||||
image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
|
||||
image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
|
||||
private int progress = 0;
|
||||
|
|
|
@ -1,135 +1,136 @@
|
|||
package sznp.virtualcomputer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
case "start":
|
||||
case "poweron":
|
||||
case "on":
|
||||
case "startup":
|
||||
PluginMain.Instance.Start(sender);
|
||||
break;
|
||||
case "stop":
|
||||
case "poweroff":
|
||||
case "off":
|
||||
case "shutdown":
|
||||
case "kill":
|
||||
PluginMain.Instance.Stop(sender);
|
||||
break;
|
||||
case "powerbutton":
|
||||
case "pwrbtn":
|
||||
case "powerbtn":
|
||||
PluginMain.Instance.PowerButton(sender);
|
||||
break;
|
||||
case "reset":
|
||||
case "restart":
|
||||
PluginMain.Instance.Reset(sender);
|
||||
break;
|
||||
case "fix":
|
||||
case "fixscreen":
|
||||
PluginMain.Instance.FixScreen(sender);
|
||||
break;
|
||||
case "key":
|
||||
case "press":
|
||||
case "presskey":
|
||||
case "keypress":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("§cUsage: /computer key <key> [down/up|duration(ticks)]");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3)
|
||||
PluginMain.Instance.PressKey(sender, args[1], "");
|
||||
else
|
||||
PluginMain.Instance.PressKey(sender, args[1], args[2]);
|
||||
break;
|
||||
case "mouse":
|
||||
boolean showusage = true;
|
||||
if (args.length < 6) {
|
||||
// Command overloading, because I can :P
|
||||
if (args.length > 4) // 4<x<6
|
||||
{
|
||||
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.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1], args[2].equals("down"));
|
||||
showusage = false;
|
||||
} else if (args.length == 2) {
|
||||
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1]);
|
||||
showusage = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showusage) {
|
||||
sender.sendMessage("§cUsage: /computer mouse <relx> <rely> <relz> <relw>");
|
||||
sender.sendMessage("§cOr: /computer mouse <button> [up/down]");
|
||||
}
|
||||
break;
|
||||
case "input":
|
||||
case "show":
|
||||
case "showinput":
|
||||
case "shinput": {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§cError: Only players can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("§cUsage: /computer input <key|mouse>");
|
||||
return true;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "key":
|
||||
case "keyboard":
|
||||
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\"}}]");
|
||||
case "mouse":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§cOnly ingame players can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (!MouseLockerPlayerListener.LockedPlayers.containsKey(sender)) {
|
||||
MouseLockerPlayerListener.LockedPlayers.put((Player) sender, ((Player) sender).getLocation());
|
||||
sender.sendMessage("§aMouse locked.");
|
||||
} else {
|
||||
MouseLockerPlayerListener.LockedPlayers.remove(sender);
|
||||
sender.sendMessage("§bMouse unlocked.");
|
||||
}
|
||||
case "mspeed":
|
||||
case "mousespeed":
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
||||
return true;
|
||||
}
|
||||
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
|
||||
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package sznp.virtualcomputer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
case "start":
|
||||
case "poweron":
|
||||
case "on":
|
||||
case "startup":
|
||||
PluginMain.Instance.Start(sender);
|
||||
break;
|
||||
case "stop":
|
||||
case "poweroff":
|
||||
case "off":
|
||||
case "shutdown":
|
||||
case "kill":
|
||||
PluginMain.Instance.Stop(sender);
|
||||
break;
|
||||
case "powerbutton":
|
||||
case "pwrbtn":
|
||||
case "powerbtn":
|
||||
PluginMain.Instance.PowerButton(sender);
|
||||
break;
|
||||
case "reset":
|
||||
case "restart":
|
||||
PluginMain.Instance.Reset(sender);
|
||||
break;
|
||||
case "fix":
|
||||
case "fixscreen":
|
||||
PluginMain.Instance.FixScreen(sender);
|
||||
break;
|
||||
case "key":
|
||||
case "press":
|
||||
case "presskey":
|
||||
case "keypress":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("§cUsage: /computer key <key> [down/up|duration(ticks)]");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3)
|
||||
PluginMain.Instance.PressKey(sender, args[1], "");
|
||||
else
|
||||
PluginMain.Instance.PressKey(sender, args[1], args[2]);
|
||||
break;
|
||||
case "mouse":
|
||||
boolean showusage = true;
|
||||
if (args.length < 6) {
|
||||
// Command overloading, because I can :P
|
||||
if (args.length > 4) // 4<x<6
|
||||
{
|
||||
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.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1], args[2].equals("down"));
|
||||
showusage = false;
|
||||
} else if (args.length == 2) {
|
||||
PluginMain.Instance.UpdateMouse(sender, 0, 0, 0, 0, args[1]);
|
||||
showusage = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showusage) {
|
||||
sender.sendMessage("§cUsage: /computer mouse <relx> <rely> <relz> <relw>");
|
||||
sender.sendMessage("§cOr: /computer mouse <button> [up/down]");
|
||||
}
|
||||
break;
|
||||
case "input":
|
||||
case "show":
|
||||
case "showinput":
|
||||
case "shinput": {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§cError: Only players can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("§cUsage: /computer input <key|mouse>");
|
||||
return true;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "key":
|
||||
case "keyboard":
|
||||
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\"}}]");
|
||||
case "mouse":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§cOnly ingame players can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (!MouseLockerPlayerListener.LockedPlayers.containsKey(sender)) {
|
||||
MouseLockerPlayerListener.LockedPlayers.put((Player) sender, ((Player) sender).getLocation());
|
||||
sender.sendMessage("§aMouse locked.");
|
||||
} else {
|
||||
MouseLockerPlayerListener.LockedPlayers.remove(sender);
|
||||
sender.sendMessage("§bMouse unlocked.");
|
||||
}
|
||||
break;
|
||||
case "mspeed":
|
||||
case "mousespeed":
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage("§cUsage: /computer input mspeed <integer>");
|
||||
return true;
|
||||
}
|
||||
MouseLockerPlayerListener.LockedSpeed = Float.parseFloat(args[2]);
|
||||
sender.sendMessage("§aMouse speed set to " + MouseLockerPlayerListener.LockedSpeed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package sznp.virtualcomputer;
|
|||
import java.awt.Color;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
@ -61,6 +62,11 @@ public class DirectRenderer implements IRenderer {
|
|||
WorldMap wmap = (WorldMap) field.get(map);
|
||||
wmap.flagDirty(0, 0);
|
||||
wmap.flagDirty(127, 127); // Send the whole image - TODO: Only send changes
|
||||
/*
|
||||
* final Field fieldf = map.getClass().getDeclaredField("renderCache"); fieldf.setAccessible(true);
|
||||
* @SuppressWarnings("unchecked") final Map<CraftPlayer, RenderData> renderCache = (Map<CraftPlayer, RenderData>) fieldf.get(map); RenderData render = renderCache.get(null);
|
||||
* System.out.println("==: " + (buffer == render.buffer)); System.out.println("equals:" + Arrays.equals(buffer, render.buffer));
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
if (ex != null && (e.getMessage() == ex.getMessage()
|
||||
|| (e.getMessage() != null && e.getMessage().equals(ex.getMessage()))))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package sznp.virtualcomputer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mozilla.interfaces.IFramebuffer;
|
||||
import org.mozilla.interfaces.IFramebufferOverlay;
|
||||
import org.mozilla.interfaces.nsISupports;
|
||||
|
@ -74,18 +75,28 @@ public class MCFrameBuffer implements IFramebuffer {
|
|||
public void notify3DEvent(long arg0, byte[] arg1) {
|
||||
}
|
||||
|
||||
private BukkitTask tt;
|
||||
|
||||
@Override
|
||||
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
||||
if (width > 640 || height > 480)
|
||||
return; // Don't even try to render too large resolutions
|
||||
System.out.println("Change - " + width + "x" + height);
|
||||
if (tt != null)
|
||||
tt.cancel();
|
||||
/*
|
||||
* if (width > 640 || height > 480) { tt = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.Instance, () -> display.setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L), 5, 5);
|
||||
* return; // Don't even try to render too large resolutions }
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
||||
display.querySourceBitmap(0L, holder);
|
||||
byte[] arr = PluginMain.allpixels.array();
|
||||
holder.value.getTypedWrapped().queryBitmapInfo(arr, new long[] { width }, new long[] { height },
|
||||
new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
|
||||
new long[] { getPixelFormat() }); // These are out params but whatever
|
||||
System.out.println("Arr0:" + arr[0]);
|
||||
PluginMain.allpixels.limit((int) (width * height * 4));
|
||||
long[] w = new long[1], h = new long[1], bpp = new long[1], bpl = new long[1], pf = new long[1];
|
||||
holder.value.getTypedWrapped().queryBitmapInfo(arr, w, h, bpp, bpl, pf);
|
||||
System.out.println("Arr10:" + arr[10]);
|
||||
System.out.println("whbppbplpf: " + w[0] + " " + h[0] + " " + bpp[0] + " " + bpl[0] + " " + pf[0]);
|
||||
if (width * height > 640 * 480)
|
||||
PluginMain.allpixels.limit(640 * 480 * 4);
|
||||
else
|
||||
PluginMain.allpixels.limit((int) (width * height * 4));
|
||||
for (IRenderer r : PluginMain.renderers)
|
||||
if (r instanceof BukkitRenderer)
|
||||
((BukkitRenderer) r).setAllPixels(PluginMain.allpixels);
|
||||
|
@ -100,7 +111,6 @@ public class MCFrameBuffer implements IFramebuffer {
|
|||
for (IRenderer r : PluginMain.renderers)
|
||||
if (r instanceof DirectRenderer)
|
||||
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
|
||||
System.out.println("Update!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,30 +1,31 @@
|
|||
package sznp.virtualcomputer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MouseLockerPlayerListener implements Runnable {
|
||||
public static Map<Player, Location> LockedPlayers = new HashMap<>();
|
||||
public static float LockedSpeed = 5;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entry<Player, Location> entry : LockedPlayers.entrySet()) {
|
||||
float yaw1 = entry.getValue().getYaw();
|
||||
float pitch1 = entry.getValue().getPitch();
|
||||
float yaw2 = entry.getKey().getLocation().getYaw();
|
||||
float pitch2 = entry.getKey().getLocation().getPitch();
|
||||
if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
|
||||
return;
|
||||
|
||||
PluginMain.Instance.UpdateMouse(null, (int) ((yaw2 - yaw1) * LockedSpeed),
|
||||
(int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
|
||||
|
||||
entry.setValue(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
package sznp.virtualcomputer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class MouseLockerPlayerListener implements Runnable {
|
||||
public static Map<Player, Location> LockedPlayers = new HashMap<>();
|
||||
public static float LockedSpeed = 5;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entry<Player, Location> entry : LockedPlayers.entrySet()) {
|
||||
float yaw1 = entry.getValue().getYaw();
|
||||
float pitch1 = entry.getValue().getPitch();
|
||||
float yaw2 = entry.getKey().getLocation().getYaw();
|
||||
float pitch2 = entry.getKey().getLocation().getPitch();
|
||||
if (yaw2 - yaw1 == 0 || pitch2 - pitch1 == 0)
|
||||
return;
|
||||
|
||||
PluginMain.Instance.UpdateMouse(null, (int) ((yaw2 - yaw1) * LockedSpeed),
|
||||
(int) ((pitch2 - pitch1) * LockedSpeed), 0, 0, "");
|
||||
|
||||
entry.getKey().teleport(entry.getValue(), TeleportCause.PLUGIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class PluginMain extends JavaPlugin {
|
|||
private BukkitTask mousetask;
|
||||
|
||||
public static PluginMain Instance;
|
||||
public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480); // It's set on each change
|
||||
public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
|
||||
public static ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
|
@ -57,9 +57,10 @@ public class PluginMain extends JavaPlugin {
|
|||
session = manager.getSessionObject(); // TODO: Events
|
||||
ccs.sendMessage("§bLoading Screen...");
|
||||
try {
|
||||
for (short i = 0; i < 20; i++)
|
||||
throw new NoClassDefFoundError("Test error pls ignore");
|
||||
/*for (short i = 0; i < 20; i++)
|
||||
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
|
||||
ccs.sendMessage("§bUsing Direct Renderer, all good");
|
||||
ccs.sendMessage("§bUsing Direct Renderer, all good");*/
|
||||
} catch (NoClassDefFoundError e) {
|
||||
for (short i = 0; i < 20; i++)
|
||||
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));
|
||||
|
@ -97,7 +98,6 @@ public class PluginMain extends JavaPlugin {
|
|||
session.setName("minecraft");
|
||||
// machine.launchVMProcess(session, "headless", "").waitForCompletion(10000); - This creates a *process*, we don't want that anymore
|
||||
machine.lockMachine(session, LockType.VM); // We want the machine inside *our* process <-- Need the VM type to have console access
|
||||
sender.sendMessage("A: " + machine.getState().toString());
|
||||
final Runnable tr = new Runnable() {
|
||||
public void run() {
|
||||
if (session.getState() != SessionState.Locked) { // https://www.virtualbox.org/sdkref/_virtual_box_8idl.html#ac82c179a797c0d7c249d1b98a8e3aa8f
|
||||
|
@ -105,24 +105,18 @@ public class PluginMain extends JavaPlugin {
|
|||
return; // "This state also occurs as a short transient state during an IMachine::lockMachine call."
|
||||
}
|
||||
machine = session.getMachine(); // This is the Machine object we can work with
|
||||
sender.sendMessage("B: " + machine.getState().toString());
|
||||
final IConsole console = session.getConsole();
|
||||
sender.sendMessage("1: " + console.getState().toString());
|
||||
console.powerUp(); // https://marc.info/?l=vbox-dev&m=142780789819967&w=2
|
||||
sender.sendMessage("2: " + console.getState().toString());
|
||||
console.getDisplay().attachFramebuffer(0L,
|
||||
new IFramebuffer(new MCFrameBuffer(console.getDisplay())));
|
||||
sender.sendMessage("3: " + console.getState().toString());
|
||||
if (screenupdatetask == null)
|
||||
screenupdatetask = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.this, () -> {
|
||||
sender.sendMessage("4: " + console.getState().toString());
|
||||
if (session.getState().equals(SessionState.Locked) // Don't run until the machine is running
|
||||
&& console.getState().equals(MachineState.Running))
|
||||
console.getDisplay().invalidateAndUpdateScreen(0L);
|
||||
if (session.getState().equals(SessionState.Unlocked) // Stop if the machine stopped fully
|
||||
|| console.getState().equals(MachineState.PoweredOff)
|
||||
|| console.getState().equals(MachineState.Saved)) {
|
||||
sender.sendMessage("5: " + console.getState().toString());
|
||||
if (session.getState().equals(SessionState.Locked)) {
|
||||
session.unlockMachine();
|
||||
sender.sendMessage("Computer powered off, released it.");
|
||||
|
@ -141,8 +135,13 @@ public class PluginMain extends JavaPlugin {
|
|||
public static int MouseSpeed = 1;
|
||||
|
||||
public void Stop(CommandSender sender) {
|
||||
if (!checkMachineRunning(sender))
|
||||
if (!checkMachineRunning(sender)) {
|
||||
if (session.getState().equals(SessionState.Locked)) {
|
||||
session.unlockMachine();
|
||||
sender.sendMessage("§eComputer powered off, released it.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("§eStopping computer...");
|
||||
session.getConsole().powerDown().waitForCompletion(2000);
|
||||
session.unlockMachine();
|
||||
|
|
Loading…
Reference in a new issue