From 7246f0a36f6e071d53e9ddccc3238b6b461adede Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Tue, 21 Mar 2023 11:57:12 +0700 Subject: [PATCH] add random username --- src/main/java/me/chayapak1/chomensbot_mabe/Bot.java | 12 +++++++++--- src/main/resources/default-config.yml | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/Bot.java b/src/main/java/me/chayapak1/chomensbot_mabe/Bot.java index 2b4b72d..56d1377 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/Bot.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/Bot.java @@ -9,6 +9,7 @@ import com.github.steveice10.packetlib.tcp.TcpClientSession; import lombok.Getter; import lombok.Setter; import me.chayapak1.chomensbot_mabe.plugins.*; +import org.apache.commons.lang3.RandomStringUtils; import java.util.ArrayList; import java.util.List; @@ -22,10 +23,12 @@ public class Bot { @Getter private final String host; @Getter private final int port; - @Getter private final String username; + private final String _username; @Getter private final List allBots; @Getter private final Map keys; + @Getter private String username; + @Getter private Session session; @Getter private final int reconnectDelay; @@ -43,11 +46,11 @@ public class Bot { @Getter private final HashingPlugin hashing = new HashingPlugin(this); @Getter private final MusicPlayerPlugin music = new MusicPlayerPlugin(this); - public Bot (String host, int port, int reconnectDelay, String username, List allBots, Map keys) { + public Bot (String host, int port, int reconnectDelay, String _username, List allBots, Map keys) { this.host = host; this.port = port; this.reconnectDelay = reconnectDelay; - this.username = username; + this._username = _username; this.allBots = allBots; this.keys = keys; @@ -55,6 +58,9 @@ public class Bot { } public void reconnect () { + if (_username == null) username = RandomStringUtils.randomAlphabetic(8); + else username = _username; + Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null); this.session = session; diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index d7f61f2..3227a99 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -1,8 +1,9 @@ reconnectDelay: 7000 keys: - normalKey: '�iB_D���k��j8H�{?[/ڭ�f�}Ѣ�^-=�Ț��v]��g>��=c' - ownerKey: 'b)R��nF�CW���#�\\[�S*8"t^eia�Z��k����K1�8zȢ�' + normalKey: 'normal hash key here' + ownerKey: 'OwnerHash™ key here' bots: + # username is optional, if doesn't exist it will default to random username - host: 'localhost' port: 25565 username: 'ChomeNS_Bot' \ No newline at end of file