Compare commits
52
Commits
v1.2.4
...
939ed09bdb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
939ed09bdb | ||
|
|
8417fd7b45 | ||
|
|
60e624e47e | ||
|
|
e8e3b4f9c0 | ||
|
|
7c1eb7cf24 | ||
|
|
ce9d01a47f | ||
|
|
b81b61187f | ||
|
|
5e109efc56 | ||
|
|
91e4d44170 | ||
|
|
e2a477e56f | ||
|
|
1ce1f98801 | ||
|
|
9865364919 | ||
|
|
fb99076f88 | ||
|
|
da26ec8a99 | ||
|
|
8b2dddf8d6 | ||
|
|
c57febbd0a | ||
|
|
78cf07636d | ||
|
|
3311f0889a | ||
|
|
c05b7ffef4 | ||
|
|
d8c2139df6 | ||
|
|
5c12776348 | ||
|
|
896c320dd7 | ||
|
|
d8cd699012 | ||
|
|
d550c69583 | ||
|
|
4c239b9b5b | ||
|
|
f82eb34588 | ||
|
|
ea0efd88bb | ||
|
|
2d78e85544 | ||
|
|
1fbadaba9c | ||
|
|
f8e2f2d95a | ||
|
|
d205bd7923 | ||
|
|
f5503b8fc0 | ||
|
|
6473d53fd7 | ||
|
|
07445c06b4 | ||
|
|
d441647ff8 | ||
|
|
c3830fc86b | ||
|
|
d6f0adfd57 | ||
|
|
6092a5f8f9 | ||
|
|
5346989a92 | ||
|
|
4cd46e8cac | ||
|
|
8db9603313 | ||
|
|
48bef04212 | ||
|
|
af4e915421 | ||
|
|
191373c430 | ||
|
|
2c2e413d72 | ||
|
|
9d8800a671 | ||
|
|
67354e0917 | ||
|
|
73c51871c9 | ||
|
|
5b520dc774 | ||
|
|
4475f6ce7a | ||
|
|
704af34048 | ||
|
|
f0a2ce1c56 |
No files matched your search
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshot or app console output**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Whole command used to start the app**
|
||||
Please insert the whole command you used to start the app.
|
||||
Censoring ip address is recommended.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -1,24 +1,28 @@
|
||||
# Minecraft bot stress tester
|
||||
🤖 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.
|
||||
✔️ The MC version of the bots is 1.19. (Does not support 1.19.1 yet)
|
||||
✔️ The MC version of the bots is 1.21.7 (supports server 1.21.8)
|
||||
For older MC versions please look in the [releases](https://github.com/crpmax/mc-bots/releases " releases").
|
||||
|
||||
## 🆒 Features
|
||||
- ✅ Connect as many bots as you want
|
||||
- ✅ Use SOCKS4 or SOCKS5 proxies from file or URL
|
||||
- ✅ Receive colored or noncolored chat
|
||||
- ✅ Set connection delay
|
||||
- ✅ Set message or command on join
|
||||
- ✅ Set messages or commands on join
|
||||
- ✅ Generate random or real looking nicknames or load from file
|
||||
- ✅ Online (premium) account support with login using Microsoft
|
||||
- ✅ Control all or selected bots
|
||||
|
||||
## 📖 Usage
|
||||
Minimal Java version: 8
|
||||
Minimal Java version: 17
|
||||
Use of pre-compiled jar from [releases](https://github.com/crpmax/mc-bots/releases " releases"):
|
||||
`java -jar mc-bots.jar -s <server address> [arguments]`
|
||||
When running, you can write a chat message to the terminal to send it by all bots.
|
||||
|
||||
## 🧪 Example
|
||||
`java -jar mc-bots-1.2.0.jar -s 192.168.0.189:25565 -d 10 11 -r -p BOT_ -c 30`
|
||||
`java -jar mc-bots-1.2.17.jar -s 192.168.0.189:25565 -p BOT_ -d 4000 5000 -c 30 -r`
|
||||
This will connect 30 bots to server at 192.168.0.189:25565 with delay 4000-5000 ms and will use real-looking nicknames prefixed with BOT_
|
||||
|
||||
<img src="https://imgur.com/XWcckas.png" title="Connected bots" width="350px"/>
|
||||
<img src="https://imgur.com/CvJq1Io.gif" title="Sending chat message by bots" width="350px"/>
|
||||
@@ -27,16 +31,26 @@ When running, you can write a chat message to the terminal to send it by all bot
|
||||
## ⚡ Options
|
||||
`-c <count>` The count of bots to connect, default is 1
|
||||
`-d <min> <max>` Set the minimum and maximum connection delay range in ms, default is 4000-5000
|
||||
`-j <message>` The message or command to send on join, does not work with `-m` or `-x` option
|
||||
`-j <message>` Messages or commands to send on join, separated by `&&`, does not work with `-m` or `-x` option
|
||||
`-p <prefix>` Custom bot nickname prefix eg. `BOT_`
|
||||
`-r` Generate real looking nicknames instead of random ones
|
||||
`-n` Do not use color in terminal - useful when the terminal does not support it
|
||||
`-m` Minimal run - do not use any listeners, will not receive chat, useful for large amounts of bots
|
||||
`-x` The most minimal run - No listeners, no control, no chat - useful for large amounts of bots for better performance
|
||||
`-t` Set proxy type - SOCKS4 or SOCKS5
|
||||
`-l` Set proxy list file
|
||||
`-t <type>` Set proxy type - SOCKS4 or SOCKS5
|
||||
`-l <path>` Set proxy list file
|
||||
`-g` Try to simulate gravity by falling down
|
||||
`--nicks` Set nicknames file
|
||||
`-o` Use online (premium) account (login with Microsoft OAuth)
|
||||
`-ar <delay>` Set auto-respawn delay (default is 100 ms, set to -1 to disable)
|
||||
`--nicks <file>` Set nicknames file
|
||||
|
||||
|
||||
## Commands
|
||||
Commands can be typed to the console. They are prefixed with `.` or `!`.
|
||||
Without the prefix it will be sent as a chat message!
|
||||
`.list` or `.ls` - list all connected bots
|
||||
`.control <nick>` or `.ctrl <nick>` - select one or multiple bots to control
|
||||
`.exit <limit>` or `.leave <limit>` - disconnect all or specified number of bots
|
||||
|
||||
## ⚠ DISCLAIMER
|
||||
**This app is made for educational and testing purposes only.
|
||||
|
||||
+16
-10
@@ -3,23 +3,29 @@ plugins {
|
||||
}
|
||||
|
||||
group 'me.creepermaxcz.mc-bots'
|
||||
version '1.2.4'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
version '1.2.18'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url 'https://repo.opencollab.dev/maven-releases' }
|
||||
maven { url 'https://repo.opencollab.dev/maven-snapshots/' }
|
||||
maven { url 'https://repo.opencollab.dev/maven-releases/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.GeyserMC:MCProtocolLib:1.19-1'
|
||||
implementation 'commons-cli:commons-cli:1.5.0'
|
||||
implementation 'com.diogonunes:JColor:5.2.0'
|
||||
implementation 'dnsjava:dnsjava:3.4.3'
|
||||
implementation 'org.slf4j:slf4j-nop:1.7.32'
|
||||
implementation 'org.geysermc.mcprotocollib:protocol:1.21.11-SNAPSHOT'
|
||||
implementation 'net.kyori:adventure-text-serializer-gson:4.24.0'
|
||||
implementation 'commons-cli:commons-cli:1.9.0'
|
||||
implementation 'com.diogonunes:JColor:5.5.1'
|
||||
implementation 'dnsjava:dnsjava:3.5.3'
|
||||
implementation 'org.slf4j:slf4j-nop:2.0.17'
|
||||
implementation 'org.jline:jline:3.30.4'
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,47 +1,63 @@
|
||||
package me.creepermaxcz.mcbots;
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.*;
|
||||
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.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.auth.SessionService;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
import org.geysermc.mcprotocollib.network.ProxyInfo;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.data.UnexpectedEncryptionException;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.ClientCommand;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Bot extends Thread {
|
||||
|
||||
MinecraftProtocol protocol = null;
|
||||
|
||||
private String nickname;
|
||||
private ProxyInfo proxy;
|
||||
private InetSocketAddress address;
|
||||
private Session client;
|
||||
private ClientSession client;
|
||||
private boolean hasMainListener;
|
||||
|
||||
private double lastX, lastY, lastZ = -1;
|
||||
|
||||
private boolean connected;
|
||||
|
||||
public Bot(String nickname, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.nickname = nickname;
|
||||
private boolean manualDisconnecting = false;
|
||||
|
||||
public Bot(MinecraftProtocol protocol, InetSocketAddress address, ProxyInfo proxy) {
|
||||
this.nickname = protocol.getProfile().getName();
|
||||
this.address = address;
|
||||
this.proxy = proxy;
|
||||
|
||||
Log.info("Creating bot", nickname);
|
||||
protocol = new MinecraftProtocol(nickname);
|
||||
client = new TcpClientSession(address.getHostString(), address.getPort(), protocol, proxy);
|
||||
|
||||
client = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(address.getHostString(), address.getPort())
|
||||
.setProtocol(protocol)
|
||||
.setProxy(proxy)
|
||||
.create();
|
||||
|
||||
SessionService sessionService = new SessionService();
|
||||
client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,32 +71,54 @@ public class Bot extends Thread {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
connected = true;
|
||||
Log.info(nickname + " connected");
|
||||
if (Main.joinMessage != null) {
|
||||
sendChat(Main.joinMessage);
|
||||
|
||||
if (Main.joinMessages.size() > 0) {
|
||||
for (String msg : Main.joinMessages) {
|
||||
sendChat(msg);
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet instanceof ClientboundPlayerPositionPacket) {
|
||||
ClientboundPlayerPositionPacket p = (ClientboundPlayerPositionPacket) packet;
|
||||
|
||||
lastX = p.getX();
|
||||
lastY = p.getY();
|
||||
lastZ = p.getZ();
|
||||
lastX = p.getPosition().getX();
|
||||
lastY = p.getPosition().getY();
|
||||
lastZ = p.getPosition().getZ();
|
||||
|
||||
client.send(new ServerboundAcceptTeleportationPacket(p.getTeleportId()));
|
||||
client.send(new ServerboundAcceptTeleportationPacket(p.getId()));
|
||||
}
|
||||
else if (packet instanceof ClientboundPlayerCombatKillPacket){
|
||||
if (Main.autoRespawnDelay >= 0) {
|
||||
Log.info("Bot " + nickname + " died. Respawning in " + Main.autoRespawnDelay + " ms.");
|
||||
new Timer().schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
client.send(new ServerboundClientCommandPacket(ClientCommand.RESPAWN));
|
||||
}
|
||||
},
|
||||
Main.autoRespawnDelay
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(DisconnectedEvent event) {
|
||||
connected = false;
|
||||
Log.info();
|
||||
Log.info(nickname + " disconnected");
|
||||
|
||||
//Log.info(" -> " + event.getReason());
|
||||
|
||||
//fix broken reason string by finding the content with regex
|
||||
// Do not write disconnect reason if disconnected by command
|
||||
if (!manualDisconnecting) {
|
||||
// Fix broken reason string by finding the content with regex
|
||||
Pattern pattern = Pattern.compile("content=\"(.*?)\"");
|
||||
Matcher matcher = pattern.matcher(event.getReason());
|
||||
Matcher matcher = pattern.matcher(String.valueOf(event.getReason()));
|
||||
|
||||
StringBuilder reason = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
@@ -91,9 +129,17 @@ public class Bot extends Thread {
|
||||
|
||||
if(event.getCause() != null) {
|
||||
event.getCause().printStackTrace();
|
||||
|
||||
if (event.getCause() instanceof UnexpectedEncryptionException) {
|
||||
Log.warn("Server is running in online (premium) mode. Please use the -o option to use online mode bot.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
Log.info();
|
||||
}
|
||||
|
||||
Main.removeBot(Bot.this);
|
||||
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
@@ -102,32 +148,28 @@ public class Bot extends Thread {
|
||||
}
|
||||
|
||||
public void sendChat(String text) {
|
||||
// timeStamp will provide when this message was sent by the user. If this value was not set or was set to 0,
|
||||
// The server console will print out that the message was "expired". To avoid this, set timeStamp as now.
|
||||
long timeStamp = Instant.now().toEpochMilli();
|
||||
|
||||
//send command
|
||||
// Send command
|
||||
if (text.startsWith("/")) {
|
||||
|
||||
client.send(new ServerboundChatCommandPacket(
|
||||
text.substring(1), //remove slash on start
|
||||
timeStamp,
|
||||
0,
|
||||
new HashMap<>(),
|
||||
true
|
||||
text.substring(1)
|
||||
));
|
||||
} else {
|
||||
//send chat message
|
||||
|
||||
// Send chat message
|
||||
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
|
||||
// tmpSignature will provide an empty byte array that can pretend it as signature.
|
||||
byte[] tmpSignature = new byte[0]; // Set it empty byte array.
|
||||
// salt is set 0 since this is offline server and no body will check it.
|
||||
client.send(new ServerboundChatPacket(text, timeStamp, 0, tmpSignature, true));
|
||||
}
|
||||
|
||||
client.send(new ServerboundChatPacket(
|
||||
text,
|
||||
Instant.now().toEpochMilli(),
|
||||
0L,
|
||||
null,
|
||||
0,
|
||||
new BitSet(),
|
||||
0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
@@ -160,10 +202,16 @@ public class Bot extends Thread {
|
||||
|
||||
public void moveTo(double x, double y, double z)
|
||||
{
|
||||
client.send(new ServerboundMovePlayerPosPacket(true, x, y, z));
|
||||
client.send(new ServerboundMovePlayerPosPacket(true, false, x, y, z));
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public void disconnect()
|
||||
{
|
||||
manualDisconnecting = true;
|
||||
client.disconnect("Leaving");
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public class Log {
|
||||
|
||||
public static void log(String in) {
|
||||
System.out.println("\r[" + formatter.format(new Date()) + "] " + in);
|
||||
System.out.print(Main.getPrompt() + "> ");
|
||||
}
|
||||
|
||||
public static void error(String in) {
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
package me.creepermaxcz.mcbots;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.github.steveice10.packetlib.ProxyInfo;
|
||||
import net.lenni0451.commons.httpclient.HttpClient;
|
||||
import net.raphimc.minecraftauth.MinecraftAuth;
|
||||
import net.raphimc.minecraftauth.java.JavaAuthManager;
|
||||
import net.raphimc.minecraftauth.java.model.MinecraftProfile;
|
||||
import net.raphimc.minecraftauth.msa.model.MsaDeviceCode;
|
||||
import net.raphimc.minecraftauth.msa.service.impl.DeviceCodeMsaAuthService;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.ProxyInfo;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.UserInterruptException;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
import org.xbill.DNS.Lookup;
|
||||
import org.xbill.DNS.Record;
|
||||
import org.xbill.DNS.SRVRecord;
|
||||
@@ -11,10 +24,9 @@ import org.xbill.DNS.Type;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class Main {
|
||||
@@ -29,7 +41,11 @@ public class Main {
|
||||
private static int delayMax = 5000;
|
||||
private static boolean minimal = false;
|
||||
private static boolean mostMinimal = false;
|
||||
public static String joinMessage;
|
||||
public static ArrayList<String> joinMessages = new ArrayList<>();
|
||||
|
||||
public static String prompt = "?";
|
||||
|
||||
public static int autoRespawnDelay = 100;
|
||||
|
||||
private static boolean useProxies = false;
|
||||
private static final ArrayList<InetSocketAddress> proxies = new ArrayList<>();
|
||||
@@ -37,7 +53,10 @@ public class Main {
|
||||
private static int proxyCount = 0;
|
||||
private static ProxyInfo.Type proxyType;
|
||||
|
||||
private static final String CLIENT_ID = "8bef943e-5a63-429e-a93a-96391d2e32a9";
|
||||
|
||||
private static Timer timer = new Timer();
|
||||
private static final HashSet<Bot> controlledBots = new HashSet<>();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -58,7 +77,7 @@ public class Main {
|
||||
options.addOption("p", "prefix", true, "bot nick prefix");
|
||||
options.addOption("m", "minimal", false, "minimal run without any listeners");
|
||||
options.addOption("x", "most-minimal", false, "minimal run without any control, just connect the bots");
|
||||
options.addOption("j", "join-msg", true, "join message / command");
|
||||
options.addOption("j", "join-msg", true, "join messages / commands, separated by &&");
|
||||
|
||||
options.addOption("l", "proxy-list", true, "Path or URL to proxy list file with proxy:port on every line");
|
||||
options.addOption("t", "proxy-type", true, "Proxy type: SOCKS4 or SOCKS5");
|
||||
@@ -67,6 +86,10 @@ public class Main {
|
||||
|
||||
options.addOption("g", "gravity", false, "Try to simulate gravity by falling down");
|
||||
|
||||
options.addOption("o", "online", false, "Use online mode (premium) account");
|
||||
|
||||
options.addOption("ar", "auto-respawn", true, "Set autorespawn delay (-1 to disable)");
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine cmd = null;
|
||||
|
||||
@@ -78,6 +101,8 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
autoRespawnDelay = Integer.parseInt(cmd.getOptionValue("ar", "100"));
|
||||
|
||||
if (cmd.hasOption('t') && cmd.hasOption('l')) {
|
||||
String typeStr = cmd.getOptionValue('t').toUpperCase();
|
||||
|
||||
@@ -85,7 +110,7 @@ public class Main {
|
||||
try {
|
||||
proxyType = ProxyInfo.Type.valueOf(typeStr);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.error("Inavlid proxy type, use SOCKS4 or SOCKS5.");
|
||||
Log.error("Invalid proxy type, use SOCKS4 or SOCKS5.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -173,7 +198,14 @@ public class Main {
|
||||
String address = cmd.getOptionValue('s');
|
||||
coloredChat = !cmd.hasOption('n');
|
||||
|
||||
joinMessage = cmd.getOptionValue('j');
|
||||
if (cmd.hasOption('j')) {
|
||||
// Split messages by &&, trim and append to arraylist
|
||||
String[] messages = cmd.getOptionValue('j').split("&&");
|
||||
for (String msg : messages) {
|
||||
joinMessages.add(msg.trim());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int port = 25565;
|
||||
if (address.contains(":")) {
|
||||
@@ -242,6 +274,26 @@ public class Main {
|
||||
Log.warn("There was an error retrieving server status information. The server may be offline or running on a different version.");
|
||||
}
|
||||
|
||||
MinecraftProtocol protocol;
|
||||
if (cmd.hasOption("o")) {
|
||||
Log.warn("Online mode enabled. The bot count will be set to 1.");
|
||||
botCount = 1;
|
||||
|
||||
HttpClient httpClient = MinecraftAuth.createHttpClient();
|
||||
JavaAuthManager authManager = JavaAuthManager.create(httpClient)
|
||||
.login(DeviceCodeMsaAuthService::new, (Consumer<MsaDeviceCode>) msaDeviceCode -> {
|
||||
Log.info("Authorize your Microsoft account on " + msaDeviceCode.getDirectVerificationUri());
|
||||
Log.info("Waiting for authorization.");
|
||||
});
|
||||
|
||||
MinecraftProfile mcProfile = authManager.getMinecraftProfile().getUpToDate();
|
||||
Log.info("Logged in with username: " + mcProfile.getName());
|
||||
|
||||
GameProfile gameProfile = new GameProfile(mcProfile.getId(), mcProfile.getName());
|
||||
protocol = new MinecraftProtocol(gameProfile, authManager.getMinecraftToken().getUpToDate().getToken());
|
||||
} else {
|
||||
protocol = null;
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
for (int i = 0; i < botCount; i++) {
|
||||
@@ -271,11 +323,21 @@ public class Main {
|
||||
|
||||
}
|
||||
|
||||
Bot bot = new Bot(
|
||||
nickGen.nextNick(),
|
||||
Bot bot = null;
|
||||
if (protocol != null) {
|
||||
bot = new Bot(
|
||||
protocol,
|
||||
inetAddr,
|
||||
proxyInfo
|
||||
);
|
||||
} else {
|
||||
bot = new Bot(
|
||||
new MinecraftProtocol(nickGen.nextNick()),
|
||||
inetAddr,
|
||||
proxyInfo
|
||||
);
|
||||
}
|
||||
|
||||
bot.start();
|
||||
|
||||
if (!mostMinimal) bots.add(bot);
|
||||
@@ -310,16 +372,131 @@ public class Main {
|
||||
}, 1000L, 500L);
|
||||
}
|
||||
|
||||
Terminal terminal = TerminalBuilder.builder().build();
|
||||
LineReader lineReader = LineReaderBuilder.builder()
|
||||
.terminal(terminal)
|
||||
.parser(new org.jline.reader.impl.DefaultParser())
|
||||
.build();
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
prompt = "ALL";
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.isEmpty()) continue;
|
||||
while (true) {
|
||||
String line;
|
||||
try {
|
||||
line = lineReader.readLine();
|
||||
} catch (UserInterruptException e) {
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
if (line.isEmpty()) {
|
||||
System.out.print(getPrompt() + "> ");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("!") || line.startsWith(".")) {
|
||||
String command = line.substring(1);
|
||||
String[] split = command.split(" ");
|
||||
String commandName = split[0];
|
||||
|
||||
// Bot control selection
|
||||
if (
|
||||
commandName.equalsIgnoreCase("control") || commandName.equalsIgnoreCase("ctrl")
|
||||
) {
|
||||
if (split.length >= 2) {
|
||||
|
||||
controlledBots.clear();
|
||||
int newBotCount = 0;
|
||||
|
||||
// Search for all bot names, from index 1 - skip command name
|
||||
for (int i = 1; i < split.length; i++) {
|
||||
String searchedName = split[i];
|
||||
Bot bot = findBotByName(searchedName);
|
||||
|
||||
if (bot != null) {
|
||||
controlledBots.add(bot);
|
||||
newBotCount++;
|
||||
} else {
|
||||
Log.warn("Bot not found: " + searchedName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (newBotCount > 0) {
|
||||
// Join bot nicknames
|
||||
String botNames = controlledBots
|
||||
.stream()
|
||||
.map(Bot::getNickname)
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
if (newBotCount == 1) {
|
||||
Log.info("Now controlling 1 bot: " + botNames);
|
||||
} else {
|
||||
Log.info("Now controlling " + newBotCount + " bots: " + botNames);
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.warn("No bots found.");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// If no bot names are supplied, remove all bots
|
||||
controlledBots.clear();
|
||||
Log.info("No bots selected - now controlling all bots.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// List command
|
||||
else if (commandName.equalsIgnoreCase("list") || commandName.equalsIgnoreCase("ls")) {
|
||||
Log.info("There are " + bots.size() + " bots connected:");
|
||||
for (Bot bot : bots) {
|
||||
Log.info(bot.getNickname(), bot.hasMainListener() ? "[MainListener]" : "");
|
||||
}
|
||||
} else if (commandName.equalsIgnoreCase("leave") || commandName.equalsIgnoreCase("exit")) {
|
||||
int limit = -1;
|
||||
if (split.length >= 2) {
|
||||
try {
|
||||
limit = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
limit = 0;
|
||||
Log.warn("Invalid limit.");
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
if (!controlledBots.isEmpty()) {
|
||||
Log.info("Disconnecting controlled bots.");
|
||||
for (Bot bot : controlledBots) {
|
||||
if (i++ == limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
bot.disconnect();
|
||||
}
|
||||
} else {
|
||||
Log.info("Disconnecting all bots.");
|
||||
for (Bot bot : bots) {
|
||||
if (i++ == limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
bot.disconnect();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.warn("Invalid command");
|
||||
}
|
||||
} else if (controlledBots.size() > 0) {
|
||||
controlledBots.forEach(bot -> bot.sendChat(line));
|
||||
} else {
|
||||
bots.forEach(bot -> bot.sendChat(line));
|
||||
}
|
||||
|
||||
Thread.sleep(50);
|
||||
|
||||
//System.out.print("\r" +prompt + "> ");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,6 +506,7 @@ public class Main {
|
||||
|
||||
public static synchronized void removeBot(Bot bot) {
|
||||
bots.remove(bot);
|
||||
controlledBots.remove(bot);
|
||||
if (bot.hasMainListener()) {
|
||||
Log.info("Bot with MainListener removed");
|
||||
isMainListenerMissing = true;
|
||||
@@ -355,4 +533,30 @@ public class Main {
|
||||
public static boolean isMinimal() {
|
||||
return minimal;
|
||||
}
|
||||
|
||||
public static Bot findBotByName(String text) {
|
||||
for (Bot bot : bots) {
|
||||
// Starts with and ignore case
|
||||
// https://stackoverflow.com/a/38947571/11787611
|
||||
if (bot.getNickname().regionMatches(true, 0, text, 0, text.length())) {
|
||||
return bot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPrompt()
|
||||
{
|
||||
int count = controlledBots.size();
|
||||
if (count == 0) {
|
||||
return "ALL";
|
||||
} else if (count == 1)
|
||||
{
|
||||
//If controlling only one bot, return its nickname
|
||||
return controlledBots.iterator().next().getNickname();
|
||||
}
|
||||
else {
|
||||
return count + " BOTS";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.creepermaxcz.mcbots;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.*;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.*;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
@@ -20,17 +20,34 @@ public class MainListener implements SessionListener {
|
||||
// From 1.19.1 (as well as 1.19), the class ClientboundChatPacket was removed.
|
||||
// Instead, they use ClientboundPlayerChatPacket and ClientboundSystemChatPacket for taking care of chat packets.
|
||||
Component message = null;
|
||||
Component sender;
|
||||
boolean chatPrintedOut = false;
|
||||
|
||||
if (packet instanceof ClientboundPlayerChatPacket) {
|
||||
// Since we are working on offline server, salt will be 0.
|
||||
message = ((ClientboundPlayerChatPacket) packet).getSignedContent(); // getSignedContent
|
||||
} else if (packet instanceof ClientboundSystemChatPacket) {
|
||||
ClientboundPlayerChatPacket clientboundPlayerChatPacket = ((ClientboundPlayerChatPacket) packet);
|
||||
message = clientboundPlayerChatPacket.getUnsignedContent();
|
||||
sender = clientboundPlayerChatPacket.getName();
|
||||
|
||||
// Sometimes the message's body gets null.
|
||||
// For example, some commands like /say makes the message content as null.
|
||||
// However, the message exists as in getMessagePlain(), thus can retrieve message using the method.
|
||||
if (message == null) {
|
||||
Log.chat(Utils.getFullText((TextComponent) sender, Component.text(clientboundPlayerChatPacket.getContent()), Main.coloredChat));
|
||||
} else {
|
||||
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat));
|
||||
}
|
||||
chatPrintedOut = true;
|
||||
|
||||
} else if (packet instanceof ClientboundSystemChatPacket) { // When this was SystemChat packet.
|
||||
message = ((ClientboundSystemChatPacket) packet).getContent();
|
||||
}
|
||||
//Log.chat(message.toString());
|
||||
if (message instanceof TextComponent) {
|
||||
|
||||
// For output of commands, this is the case where this program prints out the message to user.
|
||||
if (message instanceof TextComponent && !chatPrintedOut) {
|
||||
TextComponent msg = (TextComponent) message;
|
||||
Log.chat(Utils.getFullText(msg, Main.coloredChat));
|
||||
}
|
||||
|
||||
if (message instanceof TranslatableComponent) {
|
||||
TranslatableComponent msg = (TranslatableComponent) message;
|
||||
Log.chat("[T]", Utils.translate(msg));
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package me.creepermaxcz.mcbots;
|
||||
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandler;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
|
||||
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoHandler;
|
||||
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerPingTimeHandler;
|
||||
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class ServerInfo {
|
||||
|
||||
private final Session client;
|
||||
private final ClientSession client;
|
||||
private ServerStatusInfo serverStatusInfo;
|
||||
private long ping;
|
||||
private boolean done;
|
||||
@@ -23,7 +25,11 @@ public class ServerInfo {
|
||||
public ServerInfo(InetSocketAddress address) {
|
||||
|
||||
MinecraftProtocol protocol = new MinecraftProtocol();
|
||||
client = new TcpClientSession(address.getHostString(), address.getPort(), protocol, null);
|
||||
|
||||
client = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(address.getHostString(), address.getPort())
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
|
||||
client.setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
|
||||
this.serverStatusInfo = info;
|
||||
|
||||
@@ -7,12 +7,16 @@ 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.TranslationArgument;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -25,6 +29,7 @@ public class Utils {
|
||||
public static String getFullText(TextComponent message, boolean colored) {
|
||||
if (message.children().size() > 0) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.append(parseColor(message, colored));
|
||||
for (Component child : message.children()) {
|
||||
if (child instanceof TextComponent) {
|
||||
text.append(getFullText((TextComponent) child, colored));
|
||||
@@ -35,61 +40,66 @@ public class Utils {
|
||||
}
|
||||
return text.toString();
|
||||
} else {
|
||||
return parseColor(message, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A static function that gets full text from text components.
|
||||
* From 1.19.1 the protocol does not include sender's information in the message.
|
||||
* Thus, we need to merge two TextComponent (sender and message) and generate a text that consists of sent message.
|
||||
* This means using old getFullText will just send the message. Which does NOT contain username who sent this message
|
||||
*
|
||||
* @param sender The TextComponent for sender.
|
||||
* @param message The TextComponent for message.
|
||||
* @param colored Whether if this output was colored or not.
|
||||
* @return Returns String in "Username : Message" format.
|
||||
*/
|
||||
public static String getFullText(@Nullable TextComponent sender, TextComponent message, boolean colored) {
|
||||
if (colored) {
|
||||
Style messageStyle = message.style();
|
||||
StringBuilder outString = new StringBuilder();
|
||||
|
||||
if (sender != null) {
|
||||
Style senderStyle = sender.style();
|
||||
if (senderStyle.color() != null) { // Generate sender text with color.
|
||||
outString.append(colorizeText(sender.content(), senderStyle.color()));
|
||||
} else {
|
||||
outString.append(sender.content());
|
||||
}
|
||||
outString.append(" : "); // Add delimiter as : between sender and message.
|
||||
}
|
||||
|
||||
if (messageStyle.color() != null && sender != null) { // Generate message text with color.
|
||||
outString.append(colorizeText(sender.content(), messageStyle.color()));
|
||||
} else {
|
||||
outString.append(message.content());
|
||||
}
|
||||
|
||||
return outString.toString();
|
||||
} else {
|
||||
if (sender == null)
|
||||
return message.content();
|
||||
else
|
||||
return sender.content() + " : " + message.content();
|
||||
}
|
||||
}
|
||||
|
||||
private static String parseColor(TextComponent message, boolean colored) {
|
||||
String out = message.content();
|
||||
if (colored) {
|
||||
if (message.style().color() != null) {
|
||||
List<Attribute> formats = new ArrayList<>(getFormats(message.style().decorations()));
|
||||
formats.add(getColor((NamedTextColor) message.style().color()));
|
||||
TextColor color = message.style().color();
|
||||
formats.add(Attribute.TEXT_COLOR(color.red(), color.green(), color.blue()));
|
||||
out = colorize(out, formats.toArray(new Attribute[0]));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Attribute getColor(NamedTextColor color) {
|
||||
switch (color.toString()) {
|
||||
case "red":
|
||||
return Attribute.BRIGHT_RED_TEXT();
|
||||
case "dark_red":
|
||||
return Attribute.RED_TEXT();
|
||||
|
||||
case "blue":
|
||||
return Attribute.BRIGHT_BLUE_TEXT();
|
||||
case "dark_blue":
|
||||
return Attribute.BLUE_TEXT();
|
||||
|
||||
case "white":
|
||||
return Attribute.BRIGHT_WHITE_TEXT();
|
||||
case "black":
|
||||
return Attribute.BLACK_TEXT();
|
||||
case "gray":
|
||||
return Attribute.WHITE_TEXT();
|
||||
case "dark_gray":
|
||||
return Attribute.BRIGHT_BLACK_TEXT();
|
||||
|
||||
case "aqua":
|
||||
return Attribute.BRIGHT_CYAN_TEXT();
|
||||
case "dark_aqua":
|
||||
return Attribute.CYAN_TEXT();
|
||||
|
||||
case "yellow":
|
||||
return Attribute.BRIGHT_YELLOW_TEXT();
|
||||
case "gold":
|
||||
return Attribute.YELLOW_TEXT();
|
||||
|
||||
case "green":
|
||||
return Attribute.BRIGHT_GREEN_TEXT();
|
||||
case "dark_green":
|
||||
return Attribute.GREEN_TEXT();
|
||||
|
||||
case "purple":
|
||||
return Attribute.BRIGHT_MAGENTA_TEXT();
|
||||
case "dark_purple":
|
||||
return Attribute.MAGENTA_TEXT();
|
||||
}
|
||||
return Attribute.NONE();
|
||||
private static String colorizeText(String text, TextColor color) {
|
||||
return colorize(text, Attribute.TEXT_COLOR(color.red(), color.green(), color.blue()));
|
||||
}
|
||||
|
||||
public static List<Attribute> getFormats(Map<TextDecoration, TextDecoration.State> decorations) {
|
||||
@@ -112,11 +122,14 @@ public class Utils {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static String translate(TranslatableComponent message) {
|
||||
try {
|
||||
if (lang == null) {
|
||||
try {
|
||||
InputStream resource = Utils.class.getResourceAsStream("/files/lang.json");
|
||||
if (resource == null) {
|
||||
throw new Exception("Failed to load lang resource.");
|
||||
}
|
||||
lang = new JsonParser().parse(new InputStreamReader(resource)).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
Log.crit(e);
|
||||
@@ -134,20 +147,28 @@ public class Utils {
|
||||
|
||||
ArrayList<String> placeholders = new ArrayList<>();
|
||||
|
||||
if (message.args().size() > 0) {
|
||||
for (Component component : message.args()) {
|
||||
if (message.arguments().size() > 0) {
|
||||
for (TranslationArgument arg : message.arguments()) {
|
||||
Component component = arg.asComponent();
|
||||
if (component instanceof TranslatableComponent) {
|
||||
placeholders.add(translate((TranslatableComponent) component));
|
||||
}
|
||||
else if (component instanceof TextComponent) {
|
||||
} else if (arg instanceof TextComponent) {
|
||||
placeholders.add(getFullText((TextComponent) component, false));
|
||||
}
|
||||
}
|
||||
//Log.info(Arrays.toString(placeholders.toArray()));
|
||||
try {
|
||||
return String.format(base, placeholders.toArray());
|
||||
} catch (Exception e) {
|
||||
Log.error("Error formatting '"+base+"' with placeholders " + Arrays.toString(placeholders.toArray()));
|
||||
}
|
||||
} else {
|
||||
return base;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+5698
-4494
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user