diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index 794c1fb..71bda59 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -78,6 +78,7 @@ public class Bot { public TagPlugin tag; public WorldPlugin world; public AuthPlugin auth; + public ScreensharePlugin screenshare; public Bot (Configuration.BotOption botOption, List bots, Configuration config) { this.host = botOption.host; @@ -127,6 +128,7 @@ public class Bot { this.tag = new TagPlugin(this); this.world = new WorldPlugin(this); this.auth = new AuthPlugin(this); + this.screenshare = new ScreensharePlugin(this); for (Listener listener : listeners) listener.loadedPlugins(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ScreenshareCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ScreenshareCommand.java new file mode 100644 index 0000000..4b94a85 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ScreenshareCommand.java @@ -0,0 +1,76 @@ +package land.chipmunk.chayapak.chomens_bot.commands; + +public class ScreenshareCommand { // extends Command { +// public ScreenshareCommand () { +// super( +// "screenshare", +// "Shares my screen", +// new String[] { +// " ", +// "", +// " ", +// " " +// }, +// new String[] {}, +// TrustLevel.TRUSTED, +// false +// ); +// } + +// @Override +// public Component execute(CommandContext context, String[] args, String[] fullArgs) { +// final Bot bot = context.bot; +// +// try { +// switch (args[0]) { +// case "start" -> { +// final int x = Integer.parseInt(args[1]); +// final int y = Integer.parseInt(args[2]); +// final int z = Integer.parseInt(args[3]); +// +// bot.screenshare.start(Vector3i.from(x, y, z)); +// +// return Component +// .text("Started screen sharing") +// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); +// } +// case "stop" -> { +// bot.screenshare.stop(); +// +// return Component +// .text("Stopped screen sharing") +// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); +// } +// case "setres" -> { +// final int width = Integer.parseInt(args[1]); +// final int height = Integer.parseInt(args[2]); +// +// bot.screenshare.width = width; +// bot.screenshare.height = height; +// +// bot.screenshare.screen.screen = new String[width][height]; +// +// return Component +// .text("Set the resolution to ") +// .append(Component.text(width + "x" + height).color(ColorUtilities.getColorByString(bot.config.colorPalette.string))) +// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); +// } +// case "setfps" -> { +// final int fps = Integer.parseInt(args[1]); +// +// bot.screenshare.fps = fps; +// +// return Component +// .text("Set the FPS to ") +// .append(Component.text(fps).color(ColorUtilities.getColorByString(bot.config.colorPalette.number))) +// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); +// } +// default -> { +// return Component.text("Invalid action").color(NamedTextColor.RED); +// } +// } +// } catch (NumberFormatException e) { +// return Component.text("Invalid integer").color(NamedTextColor.RED); +// } +// } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index 3bdf7b7..386152d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -53,6 +53,7 @@ public class CommandHandlerPlugin { registerCommand(new InfoCommand()); registerCommand(new ConsoleCommand()); registerCommand(new PCrashCommand()); +// registerCommand(new ScreenshareCommand()); } public boolean disabled = false; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ScreensharePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ScreensharePlugin.java new file mode 100644 index 0000000..7e8bdaf --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ScreensharePlugin.java @@ -0,0 +1,177 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import land.chipmunk.chayapak.chomens_bot.Bot; + +public class ScreensharePlugin { + private final Bot bot; + +// private ScheduledFuture future; +// +// public int fps = 15; +// +// public int width = 35; +// public int height = 18; +// +// public Screen screen; +// +// public Robot robot; +// +// public FFmpegFrameGrabber grabber; + + public ScreensharePlugin (Bot bot) { + this.bot = bot; + +// try { +// robot = new Robot(); +// } catch (AWTException e) { +// e.printStackTrace(); +// } + } +// +// public void start (Vector3i position) { +// screen = new Screen(bot, width, height, position); +// +// screen.update(); +// +// try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("/tmp/rick.mp4")) { +// this.grabber = grabber; +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// try { grabber.start(); } catch (Exception ignored) {} +// +// future = bot.executor.scheduleAtFixedRate(this::drawScreen, 0, 1000 / fps, TimeUnit.MILLISECONDS); // frame. per. second. +// } +// +// public void stop () { +// future.cancel(false); +// +// screen.kill(); +// } +// +// private void drawScreen () { +//// Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); +// +//// BufferedImage capture = robot.createScreenCapture(screenRect); +// +// try (Java2DFrameConverter frameConverter = new Java2DFrameConverter()) { +// final Frame grabbed = grabber.grab(); +// +// final BufferedImage capture = frameConverter.convert(grabbed); +// +// if (capture == null) return; +// +// BufferedImage resized = resize(capture, screen.width, screen.height); +// +// for (int y = 0; y < resized.getHeight(); y++) { +// for (int x = 0; x < resized.getWidth(); x++) { +// int rgba = resized.getRGB(x, y); +// int red = (rgba >> 16) & 255; +// int green = (rgba >> 8) & 255; +// int blue = rgba & 255; +// +// screen.screen[x][y] = String.format("#%02x%02x%02x", red, green, blue); +// } +// } +// +// screen.draw(); +// } catch (Exception e) { +// System.err.println("EXCEPTION ::::"); +// e.printStackTrace(); +// } +// } +// +// // move this to util? +// private BufferedImage resize(BufferedImage img, int newW, int newH) { +// Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH); +// BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB); +// +// Graphics2D g2d = dimg.createGraphics(); +// g2d.drawImage(tmp, 0, 0, null); +// g2d.dispose(); +// +// return dimg; +// } +// +// public static class Screen { +// private final Bot bot; +// +// public String[][] screen; +// public int width; +// public int height; +// public Vector3i pos; +// +// public ArrayList tags = new ArrayList<>(); +// +// public Screen(Bot bot, int width, int height, Vector3i pos) { +// screen = new String[width][height]; +// +// this.bot = bot; +// +// this.width = width; +// this.height = height; +// +// this.pos = pos; +// } +// +// public void draw () { +// final ArrayList names = new ArrayList<>(); +// +// for (int y = 0; y < height; y++) { +// Component name = Component.empty(); +// +// for (int x = 0; x < width; x++) { +// final Component pixel = Component.text("█").color(TextColor.fromHexString(screen[x][y])); +// +// name = name.append(pixel); +// } +// +// names.add(name); +// } +// +// for (int i = 0; i < names.size(); i++) { +// bot.core.run("minecraft:data merge entity @e[tag=" + tags.get(i) + ",limit=1] {text:'" + GsonComponentSerializer.gson().serialize(names.get(i)) + "'}"); +// } +// } +// +// public void kill () { +// for(String i : tags) { +// bot.core.run("minecraft:kill @e[tag=" + i + "]"); +// } +// +// tags.clear(); +// } +// +// public void update() { +// double startY = pos.getY(); +// +// kill(); +// +// for (int i = 0; i < this.height; i++) { +// final String actualTag = "chomens_bot_" + Math.random(); +// +// tags.add(actualTag); +// startY -= 0.3f; +// +// bot.core.run( +// String.format( +// "minecraft:summon minecraft:text_display %s %s %s %s", +// pos.getX(), +// startY, +// pos.getZ(), +// "{Tags:[\"" + actualTag + "\"],text:'\"\"',line_width:32767}" +// ) +// ); +// } +// } +// +// public void setPixel(String hexColor, int x, int y) { screen[x][y] = hexColor; } +// +// public void setRow(String[] hexColor, int row) { +// for (int x = 0; x < width; x++) { +// screen[x][row] = hexColor[x]; +// } +// } +// } +}