some screenshare
This commit is contained in:
parent
a8f2dd59f0
commit
11927ac373
3 changed files with 243 additions and 222 deletions
|
@ -126,7 +126,7 @@ public class Bot {
|
||||||
this.tag = new TagPlugin(this);
|
this.tag = new TagPlugin(this);
|
||||||
this.world = new WorldPlugin(this);
|
this.world = new WorldPlugin(this);
|
||||||
this.auth = new AuthPlugin(this);
|
this.auth = new AuthPlugin(this);
|
||||||
this.screenshare = new ScreensharePlugin(this);
|
// this.screenshare = new ScreensharePlugin(this);
|
||||||
|
|
||||||
for (Listener listener : listeners) listener.loadedPlugins();
|
for (Listener listener : listeners) listener.loadedPlugins();
|
||||||
|
|
||||||
|
|
|
@ -1,76 +1,87 @@
|
||||||
package land.chipmunk.chayapak.chomens_bot.commands;
|
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||||
|
|
||||||
public class ScreenshareCommand { // extends Command {
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
// public ScreenshareCommand () {
|
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||||
// super(
|
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||||
// "screenshare",
|
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||||
// "Shares my screen",
|
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||||
// new String[] {
|
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||||
// "<start> <x> <y> <z>",
|
import net.kyori.adventure.text.Component;
|
||||||
// "<stop>",
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
// "<setres> <width> <height>",
|
|
||||||
// "<setfps> <fps>"
|
|
||||||
// },
|
|
||||||
// new String[] {},
|
|
||||||
// TrustLevel.TRUSTED,
|
|
||||||
// false
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Override
|
public class ScreenshareCommand extends Command {
|
||||||
// public Component execute(CommandContext context) throws CommandException {
|
public ScreenshareCommand () {
|
||||||
// final Bot bot = context.bot;
|
super(
|
||||||
//
|
"screenshare",
|
||||||
// try {
|
"Shares my screen",
|
||||||
// switch (args[0]) {
|
new String[] {
|
||||||
// case "start" -> {
|
"<start> <x> <y> <z>",
|
||||||
// final int x = Integer.parseInt(args[1]);
|
"<stop>",
|
||||||
// final int y = Integer.parseInt(args[2]);
|
"<setres> <width> <height>",
|
||||||
// final int z = Integer.parseInt(args[3]);
|
"<setfps> <fps>"
|
||||||
//
|
},
|
||||||
// bot.screenshare.start(Vector3i.from(x, y, z));
|
new String[] {},
|
||||||
//
|
TrustLevel.TRUSTED,
|
||||||
// return Component
|
false
|
||||||
// .text("Started screen sharing")
|
);
|
||||||
// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
}
|
||||||
// }
|
|
||||||
// case "stop" -> {
|
@Override
|
||||||
// bot.screenshare.stop();
|
public Component execute(CommandContext context) throws CommandException {
|
||||||
//
|
final Bot bot = context.bot;
|
||||||
// return Component
|
|
||||||
// .text("Stopped screen sharing")
|
final String action = context.getString(false, true);
|
||||||
// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
|
||||||
// }
|
try {
|
||||||
// case "setres" -> {
|
switch (action) {
|
||||||
// final int width = Integer.parseInt(args[1]);
|
case "start" -> {
|
||||||
// final int height = Integer.parseInt(args[2]);
|
final int x = context.getInteger(true);
|
||||||
//
|
final int y = context.getInteger(true);
|
||||||
// bot.screenshare.width = width;
|
final int z = context.getInteger(true);
|
||||||
// bot.screenshare.height = height;
|
|
||||||
//
|
bot.screenshare.start(Vector3i.from(x, y, z));
|
||||||
// bot.screenshare.screen.screen = new String[width][height];
|
|
||||||
//
|
return Component
|
||||||
// return Component
|
.text("Started screen sharing")
|
||||||
// .text("Set the resolution to ")
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||||
// .append(Component.text(width + "x" + height).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)))
|
}
|
||||||
// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
case "stop" -> {
|
||||||
// }
|
bot.screenshare.stop();
|
||||||
// case "setfps" -> {
|
|
||||||
// final int fps = Integer.parseInt(args[1]);
|
return Component
|
||||||
//
|
.text("Stopped screen sharing")
|
||||||
// bot.screenshare.fps = fps;
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||||
//
|
}
|
||||||
// return Component
|
case "setres" -> {
|
||||||
// .text("Set the FPS to ")
|
final int width = context.getInteger(true);
|
||||||
// .append(Component.text(fps).color(ColorUtilities.getColorByString(bot.config.colorPalette.number)))
|
final int height = context.getInteger(true);
|
||||||
// .color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
|
||||||
// }
|
bot.screenshare.width = width;
|
||||||
// default -> {
|
bot.screenshare.height = height;
|
||||||
// throw new CommandException(Component.text("Invalid action"));
|
|
||||||
// }
|
bot.screenshare.screen.screen = new String[width][height];
|
||||||
// }
|
|
||||||
// } catch (NumberFormatException e) {
|
return Component
|
||||||
// throw new CommandException(Component.text("Invalid integer"));
|
.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 = context.getInteger(true);
|
||||||
|
|
||||||
|
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 -> {
|
||||||
|
throw new CommandException(Component.text("Invalid action"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new CommandException(Component.text("Invalid integer"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,48 @@
|
||||||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ScreensharePlugin {
|
public class ScreensharePlugin {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
// private ScheduledFuture<?> future;
|
private ScheduledFuture<?> future;
|
||||||
//
|
|
||||||
// public int fps = 15;
|
public int fps = 15;
|
||||||
//
|
|
||||||
// public int width = 35;
|
public int width = 35;
|
||||||
// public int height = 18;
|
public int height = 18;
|
||||||
//
|
|
||||||
// public Screen screen;
|
public Screen screen;
|
||||||
//
|
|
||||||
// public Robot robot;
|
public Robot robot;
|
||||||
//
|
|
||||||
// public FFmpegFrameGrabber grabber;
|
// public FFmpegFrameGrabber grabber;
|
||||||
|
|
||||||
public ScreensharePlugin (Bot bot) {
|
public ScreensharePlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// robot = new Robot();
|
robot = new Robot();
|
||||||
// } catch (AWTException e) {
|
} catch (AWTException e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
//
|
}
|
||||||
// public void start (Vector3i position) {
|
|
||||||
// screen = new Screen(bot, width, height, position);
|
public void start (Vector3i position) {
|
||||||
//
|
screen = new Screen(bot, width, height, position);
|
||||||
// screen.update();
|
|
||||||
//
|
screen.update();
|
||||||
|
|
||||||
// try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("/tmp/rick.mp4")) {
|
// try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("/tmp/rick.mp4")) {
|
||||||
// this.grabber = grabber;
|
// this.grabber = grabber;
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
|
@ -40,138 +50,138 @@ public class ScreensharePlugin {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// try { grabber.start(); } catch (Exception ignored) {}
|
// try { grabber.start(); } catch (Exception ignored) {}
|
||||||
//
|
|
||||||
// future = bot.executor.scheduleAtFixedRate(this::drawScreen, 0, 1000 / fps, TimeUnit.MILLISECONDS); // frame. per. second.
|
future = bot.executor.scheduleAtFixedRate(this::drawScreen, 0, 1000 / fps, TimeUnit.MILLISECONDS); // frame. per. second.
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void stop () {
|
public void stop () {
|
||||||
// future.cancel(false);
|
future.cancel(false);
|
||||||
//
|
|
||||||
// screen.kill();
|
screen.kill();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private void drawScreen () {
|
private void drawScreen () {
|
||||||
//// Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||||
//
|
|
||||||
//// BufferedImage capture = robot.createScreenCapture(screenRect);
|
BufferedImage capture = robot.createScreenCapture(screenRect);
|
||||||
//
|
|
||||||
// try (Java2DFrameConverter frameConverter = new Java2DFrameConverter()) {
|
// try (Java2DFrameConverter frameConverter = new Java2DFrameConverter()) {
|
||||||
// final Frame grabbed = grabber.grab();
|
// final Frame grabbed = grabber.grab();
|
||||||
//
|
|
||||||
// final BufferedImage capture = frameConverter.convert(grabbed);
|
// final BufferedImage capture = frameConverter.convert(grabbed);
|
||||||
//
|
|
||||||
// if (capture == null) return;
|
if (capture == null) return;
|
||||||
//
|
|
||||||
// BufferedImage resized = resize(capture, screen.width, screen.height);
|
BufferedImage resized = resize(capture, screen.width, screen.height);
|
||||||
//
|
|
||||||
// for (int y = 0; y < resized.getHeight(); y++) {
|
for (int y = 0; y < resized.getHeight(); y++) {
|
||||||
// for (int x = 0; x < resized.getWidth(); x++) {
|
for (int x = 0; x < resized.getWidth(); x++) {
|
||||||
// int rgba = resized.getRGB(x, y);
|
int rgba = resized.getRGB(x, y);
|
||||||
// int red = (rgba >> 16) & 255;
|
int red = (rgba >> 16) & 255;
|
||||||
// int green = (rgba >> 8) & 255;
|
int green = (rgba >> 8) & 255;
|
||||||
// int blue = rgba & 255;
|
int blue = rgba & 255;
|
||||||
//
|
|
||||||
// screen.screen[x][y] = String.format("#%02x%02x%02x", red, green, blue);
|
screen.screen[x][y] = String.format("#%02x%02x%02x", red, green, blue);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// screen.draw();
|
screen.draw();
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// System.err.println("EXCEPTION ::::");
|
// System.err.println("EXCEPTION ::::");
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // move this to util?
|
// move this to util?
|
||||||
// private BufferedImage resize(BufferedImage img, int newW, int newH) {
|
private BufferedImage resize(BufferedImage img, int newW, int newH) {
|
||||||
// Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
|
Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);
|
||||||
// BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB);
|
||||||
//
|
|
||||||
// Graphics2D g2d = dimg.createGraphics();
|
Graphics2D g2d = dimg.createGraphics();
|
||||||
// g2d.drawImage(tmp, 0, 0, null);
|
g2d.drawImage(tmp, 0, 0, null);
|
||||||
// g2d.dispose();
|
g2d.dispose();
|
||||||
//
|
|
||||||
// return dimg;
|
return dimg;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static class Screen {
|
public static class Screen {
|
||||||
// private final Bot bot;
|
private final Bot bot;
|
||||||
//
|
|
||||||
// public String[][] screen;
|
public String[][] screen;
|
||||||
// public int width;
|
public int width;
|
||||||
// public int height;
|
public int height;
|
||||||
// public Vector3i pos;
|
public Vector3i pos;
|
||||||
//
|
|
||||||
// public ArrayList<String> tags = new ArrayList<>();
|
public ArrayList<String> tags = new ArrayList<>();
|
||||||
//
|
|
||||||
// public Screen(Bot bot, int width, int height, Vector3i pos) {
|
public Screen(Bot bot, int width, int height, Vector3i pos) {
|
||||||
// screen = new String[width][height];
|
screen = new String[width][height];
|
||||||
//
|
|
||||||
// this.bot = bot;
|
this.bot = bot;
|
||||||
//
|
|
||||||
// this.width = width;
|
this.width = width;
|
||||||
// this.height = height;
|
this.height = height;
|
||||||
//
|
|
||||||
// this.pos = pos;
|
this.pos = pos;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void draw () {
|
public void draw () {
|
||||||
// final ArrayList<Component> names = new ArrayList<>();
|
final ArrayList<Component> names = new ArrayList<>();
|
||||||
//
|
|
||||||
// for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
// Component name = Component.empty();
|
Component name = Component.empty();
|
||||||
//
|
|
||||||
// for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
// final Component pixel = Component.text("█").color(TextColor.fromHexString(screen[x][y]));
|
final Component pixel = Component.text("█").color(TextColor.fromHexString(screen[x][y]));
|
||||||
//
|
|
||||||
// name = name.append(pixel);
|
name = name.append(pixel);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// names.add(name);
|
names.add(name);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for (int i = 0; i < names.size(); i++) {
|
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)) + "'}");
|
bot.core.run("minecraft:data merge entity @e[tag=" + tags.get(i) + ",limit=1] {text:'" + GsonComponentSerializer.gson().serialize(names.get(i)) + "'}");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void kill () {
|
public void kill () {
|
||||||
// for(String i : tags) {
|
for(String i : tags) {
|
||||||
// bot.core.run("minecraft:kill @e[tag=" + i + "]");
|
bot.core.run("minecraft:kill @e[tag=" + i + "]");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// tags.clear();
|
tags.clear();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void update() {
|
public void update() {
|
||||||
// double startY = pos.getY();
|
double startY = pos.getY();
|
||||||
//
|
|
||||||
// kill();
|
kill();
|
||||||
//
|
|
||||||
// for (int i = 0; i < this.height; i++) {
|
for (int i = 0; i < this.height; i++) {
|
||||||
// final String actualTag = "chomens_bot_" + Math.random();
|
final String actualTag = "chomens_bot_" + Math.random();
|
||||||
//
|
|
||||||
// tags.add(actualTag);
|
tags.add(actualTag);
|
||||||
// startY -= 0.3f;
|
startY -= 0.3f;
|
||||||
//
|
|
||||||
// bot.core.run(
|
bot.core.run(
|
||||||
// String.format(
|
String.format(
|
||||||
// "minecraft:summon minecraft:text_display %s %s %s %s",
|
"minecraft:summon minecraft:text_display %s %s %s %s",
|
||||||
// pos.getX(),
|
pos.getX(),
|
||||||
// startY,
|
startY,
|
||||||
// pos.getZ(),
|
pos.getZ(),
|
||||||
// "{Tags:[\"" + actualTag + "\"],text:'\"\"',line_width:32767}"
|
"{Tags:[\"" + actualTag + "\"],text:'\"\"',line_width:32767}"
|
||||||
// )
|
)
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void setPixel(String hexColor, int x, int y) { screen[x][y] = hexColor; }
|
public void setPixel(String hexColor, int x, int y) { screen[x][y] = hexColor; }
|
||||||
//
|
|
||||||
// public void setRow(String[] hexColor, int row) {
|
public void setRow(String[] hexColor, int row) {
|
||||||
// for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
// screen[x][row] = hexColor[x];
|
screen[x][row] = hexColor[x];
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue