rewrite for 1.18, updated libraries
This commit is contained in:
1 parent
1f940aea14
commit
1c15d0358f
6 files changed
+99
-100
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
.gradle
|
||||||
|
.idea
|
||||||
|
build
|
||||||
|
gradle
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Minecraft bot stress tester
|
# Minecraft bot stress tester
|
||||||
🤖 A simple open source app written in Java used for stress testing Minecraft servers with bots (fake players).
|
🤖 A simple open source app written in Java used for stress testing Minecraft servers with bots (fake players).
|
||||||
💥 It can be also used to test plugins or minigames.
|
💥 It can be also used to test plugins or minigames.
|
||||||
✔️ The MC version of the bots is 1.16.4 (supports 1.16.5).
|
✔️ The MC version of the bots is 1.18 (supports 1.18.1).
|
||||||
|
|
||||||
## 🆒 Features
|
## 🆒 Features
|
||||||
- ✅ Connect as many bots as you want
|
- ✅ Connect as many bots as you want
|
||||||
|
|||||||
+9
-6
@@ -3,7 +3,10 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'me.creepermaxcz.mc-bots'
|
group 'me.creepermaxcz.mc-bots'
|
||||||
version '1.0.0'
|
version '1.1.0'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -11,11 +14,11 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.Steveice10:MCProtocolLib:1.16.4-1'
|
implementation 'com.github.Steveice10:MCProtocolLib:1.18-2'
|
||||||
implementation 'commons-cli:commons-cli:1.4'
|
implementation 'commons-cli:commons-cli:1.5.0'
|
||||||
implementation 'com.diogonunes:JColor:5.0.1'
|
implementation 'com.diogonunes:JColor:5.2.0'
|
||||||
implementation 'dnsjava:dnsjava:3.3.1'
|
implementation 'dnsjava:dnsjava:3.4.3'
|
||||||
implementation 'org.slf4j:slf4j-nop:1.7.30'
|
implementation 'org.slf4j:slf4j-nop:1.7.32'
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package me.creepermaxcz.mcbots;
|
package me.creepermaxcz.mcbots;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||||
import com.github.steveice10.packetlib.Client;
|
|
||||||
import com.github.steveice10.packetlib.ProxyInfo;
|
import com.github.steveice10.packetlib.ProxyInfo;
|
||||||
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||||
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
|
||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||||
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
|
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public class Bot extends Thread {
|
|||||||
private String nickname;
|
private String nickname;
|
||||||
private ProxyInfo proxy;
|
private ProxyInfo proxy;
|
||||||
private InetSocketAddress address;
|
private InetSocketAddress address;
|
||||||
private Client client;
|
private Session client;
|
||||||
private boolean hasMainListener;
|
private boolean hasMainListener;
|
||||||
|
|
||||||
public Bot(String nickname, InetSocketAddress address, ProxyInfo proxy) {
|
public Bot(String nickname, InetSocketAddress address, ProxyInfo proxy) {
|
||||||
@@ -29,18 +29,18 @@ public class Bot extends Thread {
|
|||||||
|
|
||||||
Log.info("Creating bot", nickname);
|
Log.info("Creating bot", nickname);
|
||||||
protocol = new MinecraftProtocol(nickname);
|
protocol = new MinecraftProtocol(nickname);
|
||||||
client = new Client(address.getHostString(), address.getPort(), protocol, new TcpSessionFactory(proxy));
|
client = new TcpClientSession(address.getHostString(), address.getPort(), protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (!Main.isMinimal()) {
|
if (!Main.isMinimal()) {
|
||||||
client.getSession().addListener(new SessionAdapter() {
|
client.addListener(new SessionAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived(PacketReceivedEvent event) {
|
public void packetReceived(Session session, Packet packet) {
|
||||||
if (event.getPacket() instanceof ServerJoinGamePacket) {
|
if (packet instanceof ClientboundLoginPacket) {
|
||||||
Log.info(nickname + " connected");
|
Log.info(nickname + " connected");
|
||||||
if (Main.joinMessage != null) {
|
if (Main.joinMessage != null) {
|
||||||
sendChat(Main.joinMessage);
|
sendChat(Main.joinMessage);
|
||||||
@@ -52,7 +52,7 @@ public class Bot extends Thread {
|
|||||||
public void disconnected(DisconnectedEvent event) {
|
public void disconnected(DisconnectedEvent event) {
|
||||||
Log.info();
|
Log.info();
|
||||||
Log.info(nickname + " disconnected");
|
Log.info(nickname + " disconnected");
|
||||||
Log.info(event.getReason());
|
Log.info(" -> " + event.getReason());
|
||||||
if(event.getCause() != null) {
|
if(event.getCause() != null) {
|
||||||
event.getCause().printStackTrace();
|
event.getCause().printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -62,11 +62,11 @@ public class Bot extends Thread {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
client.getSession().connect();
|
client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChat(String text) {
|
public void sendChat(String text) {
|
||||||
client.getSession().send(new ClientChatPacket(text));
|
client.send(new ServerboundChatPacket(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ public class Bot extends Thread {
|
|||||||
public void registerMainListener() {
|
public void registerMainListener() {
|
||||||
hasMainListener = true;
|
hasMainListener = true;
|
||||||
if (Main.isMinimal()) return;
|
if (Main.isMinimal()) return;
|
||||||
client.getSession().addListener(new MainListener(nickname));
|
client.addListener(new MainListener(nickname));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMainListener() {
|
public boolean hasMainListener() {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package me.creepermaxcz.mcbots;
|
package me.creepermaxcz.mcbots;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundChatPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
|
|
||||||
import com.github.steveice10.packetlib.event.session.*;
|
import com.github.steveice10.packetlib.event.session.*;
|
||||||
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
|
|
||||||
public class MainListener implements SessionListener {
|
public class MainListener implements SessionListener {
|
||||||
|
|
||||||
@@ -13,18 +15,17 @@ public class MainListener implements SessionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived(PacketReceivedEvent event) {
|
public void packetReceived(Session session, Packet packet) {
|
||||||
if(event.getPacket() instanceof ServerChatPacket) {
|
if(packet instanceof ClientboundChatPacket) {
|
||||||
Message message = event.<ServerChatPacket>getPacket().getMessage();
|
Component message = ((ClientboundChatPacket) packet).getMessage();
|
||||||
if (message instanceof TextMessage) {
|
//Log.chat(message.toString());
|
||||||
if (Main.coloredChat) {
|
if (message instanceof TextComponent) {
|
||||||
Log.chat(Utils.getFormattedFullText(message));
|
TextComponent msg = (TextComponent) message;
|
||||||
} else {
|
Log.chat(Utils.getFullText(msg, Main.coloredChat));
|
||||||
Log.chat(Utils.getFullText((TextMessage) message));
|
|
||||||
}
|
}
|
||||||
|
if (message instanceof TranslatableComponent) {
|
||||||
} else if (message instanceof TranslationMessage) {
|
TranslatableComponent msg = (TranslatableComponent) message;
|
||||||
Log.chat("[T]", Utils.translate((TranslationMessage) message));
|
Log.chat("[T]", Utils.translate(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +36,7 @@ public class MainListener implements SessionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetSent(PacketSentEvent event) {
|
public void packetSent(Session session, Packet packet) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
package me.creepermaxcz.mcbots;
|
package me.creepermaxcz.mcbots;
|
||||||
|
|
||||||
import com.diogonunes.jcolor.Attribute;
|
import com.diogonunes.jcolor.Attribute;
|
||||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.style.ChatColor;
|
|
||||||
import com.github.steveice10.mc.protocol.data.message.style.ChatFormat;
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.diogonunes.jcolor.Ansi.colorize;
|
import static com.diogonunes.jcolor.Ansi.colorize;
|
||||||
|
|
||||||
@@ -22,89 +23,76 @@ public class Utils {
|
|||||||
|
|
||||||
private static JsonObject lang;
|
private static JsonObject lang;
|
||||||
|
|
||||||
public static String getFullText(TextMessage message) {
|
public static String getFullText(TextComponent message, boolean colored) {
|
||||||
if (message.getExtra().size() > 0) {
|
if (message.children().size() > 0) {
|
||||||
StringBuilder text = new StringBuilder();
|
StringBuilder text = new StringBuilder();
|
||||||
for (Message extra : message.getExtra()) {
|
for (Component child : message.children()) {
|
||||||
text.append(getFullText((TextMessage) extra));
|
text.append(getFullText((TextComponent) child, colored));
|
||||||
}
|
}
|
||||||
return text.toString();
|
return text.toString();
|
||||||
} else {
|
} else {
|
||||||
return ((TextMessage)message).getText();
|
String out = message.content();
|
||||||
}
|
if (colored) {
|
||||||
}
|
if (message.style().color() != null) {
|
||||||
|
List<Attribute> formats = new ArrayList<>(getFormats(message.style().decorations()));
|
||||||
public static String getFormattedFullText(Message message) {
|
formats.add(getColor((NamedTextColor) message.style().color()));
|
||||||
if (message.getExtra().size() > 0) {
|
|
||||||
StringBuilder text = new StringBuilder();
|
|
||||||
for (Message extra : message.getExtra()) {
|
|
||||||
text.append(getFormattedFullText(extra));
|
|
||||||
}
|
|
||||||
return text.toString();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
String out = ((TextMessage) message).getText();
|
|
||||||
|
|
||||||
List<Attribute> formats = new ArrayList<>(getFormat(message.getStyle().getFormats()));
|
|
||||||
formats.add(getColor(message.getStyle().getColor()));
|
|
||||||
|
|
||||||
out = colorize(out, formats.toArray(new Attribute[0]));
|
out = colorize(out, formats.toArray(new Attribute[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Attribute getColor(String name) {
|
public static Attribute getColor(NamedTextColor color) {
|
||||||
switch (name) {
|
switch (color.toString()) {
|
||||||
case ChatColor.RED:
|
case "red":
|
||||||
return Attribute.BRIGHT_RED_TEXT();
|
return Attribute.BRIGHT_RED_TEXT();
|
||||||
case ChatColor.DARK_RED:
|
case "dark_red":
|
||||||
return Attribute.RED_TEXT();
|
return Attribute.RED_TEXT();
|
||||||
|
|
||||||
case ChatColor.BLUE:
|
case "blue":
|
||||||
return Attribute.BRIGHT_BLUE_TEXT();
|
return Attribute.BRIGHT_BLUE_TEXT();
|
||||||
case ChatColor.DARK_BLUE:
|
case "dark_blue":
|
||||||
return Attribute.BLUE_TEXT();
|
return Attribute.BLUE_TEXT();
|
||||||
|
|
||||||
case ChatColor.WHITE:
|
case "white":
|
||||||
return Attribute.BRIGHT_WHITE_TEXT();
|
return Attribute.BRIGHT_WHITE_TEXT();
|
||||||
case ChatColor.BLACK:
|
case "black":
|
||||||
return Attribute.BLACK_TEXT();
|
return Attribute.BLACK_TEXT();
|
||||||
case ChatColor.GRAY:
|
case "gray":
|
||||||
return Attribute.WHITE_TEXT();
|
return Attribute.WHITE_TEXT();
|
||||||
case ChatColor.DARK_GRAY:
|
case "dark_gray":
|
||||||
return Attribute.BRIGHT_BLACK_TEXT();
|
return Attribute.BRIGHT_BLACK_TEXT();
|
||||||
|
|
||||||
case ChatColor.AQUA:
|
case "aqua":
|
||||||
return Attribute.BRIGHT_CYAN_TEXT();
|
return Attribute.BRIGHT_CYAN_TEXT();
|
||||||
case ChatColor.DARK_AQUA:
|
case "dark_aqua":
|
||||||
return Attribute.CYAN_TEXT();
|
return Attribute.CYAN_TEXT();
|
||||||
|
|
||||||
case ChatColor.YELLOW:
|
case "yellow":
|
||||||
return Attribute.BRIGHT_YELLOW_TEXT();
|
return Attribute.BRIGHT_YELLOW_TEXT();
|
||||||
case ChatColor.GOLD:
|
case "gold":
|
||||||
return Attribute.YELLOW_TEXT();
|
return Attribute.YELLOW_TEXT();
|
||||||
|
|
||||||
case ChatColor.GREEN:
|
case "green":
|
||||||
return Attribute.BRIGHT_GREEN_TEXT();
|
return Attribute.BRIGHT_GREEN_TEXT();
|
||||||
case ChatColor.DARK_GREEN:
|
case "dark_green":
|
||||||
return Attribute.GREEN_TEXT();
|
return Attribute.GREEN_TEXT();
|
||||||
|
|
||||||
case ChatColor.LIGHT_PURPLE:
|
case "purple":
|
||||||
return Attribute.BRIGHT_MAGENTA_TEXT();
|
return Attribute.BRIGHT_MAGENTA_TEXT();
|
||||||
case ChatColor.DARK_PURPLE:
|
case "dark_purple":
|
||||||
return Attribute.MAGENTA_TEXT();
|
return Attribute.MAGENTA_TEXT();
|
||||||
}
|
}
|
||||||
return Attribute.NONE();
|
return Attribute.NONE();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Attribute> getFormat(List<ChatFormat> formats) {
|
public static List<Attribute> getFormats(Map<TextDecoration, TextDecoration.State> decorations) {
|
||||||
List<Attribute> list = new ArrayList<>();
|
List<Attribute> list = new ArrayList<>();
|
||||||
formats.forEach(format -> {
|
decorations.forEach((format, state) -> {
|
||||||
|
if (state.equals(TextDecoration.State.TRUE)) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case BOLD:
|
|
||||||
list.add(Attribute.BOLD());
|
|
||||||
break;
|
|
||||||
case ITALIC:
|
case ITALIC:
|
||||||
list.add(Attribute.ITALIC());
|
list.add(Attribute.ITALIC());
|
||||||
break;
|
break;
|
||||||
@@ -115,22 +103,24 @@ public class Utils {
|
|||||||
list.add(Attribute.STRIKETHROUGH());
|
list.add(Attribute.STRIKETHROUGH());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String translate(TranslationMessage message) {
|
|
||||||
|
public static String translate(TranslatableComponent message) {
|
||||||
if (lang == null) {
|
if (lang == null) {
|
||||||
try {
|
try {
|
||||||
InputStream resource = Utils.class.getClass().getResourceAsStream("/files/lang.json");
|
InputStream resource = Utils.class.getResourceAsStream("/files/lang.json");
|
||||||
lang = new JsonParser().parse(new InputStreamReader(resource)).getAsJsonObject();
|
lang = new JsonParser().parse(new InputStreamReader(resource)).getAsJsonObject();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.error(e);
|
Log.crit(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.info(message.toString());
|
//Log.info(message.toString());
|
||||||
|
|
||||||
String key = message.getKey();
|
String key = message.key();
|
||||||
String base = key;
|
String base = key;
|
||||||
|
|
||||||
JsonElement value = lang.get(key);
|
JsonElement value = lang.get(key);
|
||||||
@@ -140,19 +130,20 @@ public class Utils {
|
|||||||
|
|
||||||
ArrayList<String> placeholders = new ArrayList<>();
|
ArrayList<String> placeholders = new ArrayList<>();
|
||||||
|
|
||||||
if (message.getWith().size() > 0) {
|
if (message.args().size() > 0) {
|
||||||
for (Message with : message.getWith()) {
|
for (Component component : message.args()) {
|
||||||
if (with instanceof TranslationMessage) {
|
if (component instanceof TranslatableComponent) {
|
||||||
placeholders.add(translate((TranslationMessage) with));
|
placeholders.add(translate((TranslatableComponent) component));
|
||||||
}
|
}
|
||||||
else if (with instanceof TextMessage) {
|
else if (component instanceof TextComponent) {
|
||||||
placeholders.add(((TextMessage) with).getText());
|
placeholders.add(getFullText((TextComponent) component, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.info(Arrays.toString(placeholders.toArray()));
|
//Log.info(Arrays.toString(placeholders.toArray()));
|
||||||
return String.format(base, placeholders.toArray());
|
return String.format(base, placeholders.toArray());
|
||||||
} else {
|
} else {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user