add trusted and rename clear chat plugin
why do i totallynotskid™ ideas from other bot lmao
This commit is contained in:
parent
fbf9f3e2f1
commit
1795eea74a
7 changed files with 82 additions and 6 deletions
|
@ -23,6 +23,7 @@ public class Bot {
|
|||
@Getter private final int port;
|
||||
private final String _username;
|
||||
@Getter private final boolean kaboom;
|
||||
@Getter private final String serverName;
|
||||
@Getter private final List<Bot> allBots;
|
||||
@Getter private final Configuration config;
|
||||
|
||||
|
@ -44,13 +45,15 @@ public class Bot {
|
|||
@Getter private final MusicPlayerPlugin music;
|
||||
@Getter private final TPSPlugin tps;
|
||||
@Getter private final EvalRunnerPlugin eval;
|
||||
@Getter private final AntiClearChatPlugin antiClearChat;
|
||||
@Getter private final ClearChatUsernamePlugin clearChatUsername;
|
||||
@Getter private final TrustedPlugin trusted;
|
||||
|
||||
public Bot (String host, int port, String _username, boolean kaboom, List<Bot> allBots, Configuration config) {
|
||||
public Bot (String host, int port, String _username, boolean kaboom, String serverName, List<Bot> allBots, Configuration config) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this._username = _username;
|
||||
this.kaboom = kaboom;
|
||||
this.serverName = serverName;
|
||||
this.allBots = allBots;
|
||||
this.config = config;
|
||||
|
||||
|
@ -70,7 +73,8 @@ public class Bot {
|
|||
this.music = new MusicPlayerPlugin(this);
|
||||
this.tps = new TPSPlugin(this);
|
||||
this.eval = new EvalRunnerPlugin(this);
|
||||
this.antiClearChat = new AntiClearChatPlugin(this);
|
||||
this.clearChatUsername = new ClearChatUsernamePlugin(this);
|
||||
this.trusted = new TrustedPlugin(this);
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot;
|
|||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -18,6 +19,7 @@ public class Configuration {
|
|||
|
||||
@Getter public Core core = new Core();
|
||||
@Getter public Discord discord = new Discord();
|
||||
@Getter public List<String> trusted = new ArrayList<>();
|
||||
@Getter public SelfCare selfCare = new SelfCare();
|
||||
@Getter public Bots[] bots = new Bots[]{};
|
||||
|
||||
|
@ -60,5 +62,6 @@ public class Configuration {
|
|||
@Getter public int port;
|
||||
@Getter public String username;
|
||||
@Getter public boolean kaboom = false;
|
||||
@Getter public String serverName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,9 +58,10 @@ public class Main {
|
|||
final int port = botOption.port();
|
||||
final String username = botOption.username();
|
||||
final boolean kaboom = botOption.kaboom();
|
||||
final String serverName = botOption.serverName();
|
||||
|
||||
new Thread(() -> {
|
||||
final Bot bot = new Bot(host, port, username, kaboom, allBots, config);
|
||||
final Bot bot = new Bot(host, port, username, kaboom, serverName, allBots, config);
|
||||
allBots.add(bot);
|
||||
|
||||
latch.countDown();
|
||||
|
|
|
@ -7,10 +7,10 @@ import net.kyori.adventure.text.TextComponent;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
// idea totallynotskidded™ from chipmunkbot (the js one)
|
||||
public class AntiClearChatPlugin extends ChatPlugin.ChatListener {
|
||||
public class ClearChatUsernamePlugin extends ChatPlugin.ChatListener {
|
||||
private final Bot bot;
|
||||
|
||||
public AntiClearChatPlugin (Bot bot) {
|
||||
public ClearChatUsernamePlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.chat().addListener(this);
|
|
@ -53,6 +53,8 @@ public class CorePlugin extends PositionPlugin.PositionListener {
|
|||
}
|
||||
|
||||
public void run (String command) {
|
||||
if (!ready) return;
|
||||
|
||||
bot.session().send(new ServerboundSetCommandBlockPacket(
|
||||
absoluteCorePosition(),
|
||||
"",
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrustedPlugin extends PlayersPlugin.PlayerListener {
|
||||
private final Bot bot;
|
||||
|
||||
@Getter private final List<String> trusted;
|
||||
|
||||
public TrustedPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.trusted = bot.config().trusted();
|
||||
|
||||
bot.players().addListener(this);
|
||||
}
|
||||
|
||||
public void broadcast (Component message) {
|
||||
for (Bot allBot : bot.allBots()) {
|
||||
for (String player : trusted) {
|
||||
final Component component = Component.translatable(
|
||||
"[%s] [%s] %s",
|
||||
Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW),
|
||||
Component.text(bot.serverName()).color(NamedTextColor.GRAY),
|
||||
message.color(NamedTextColor.WHITE)
|
||||
).color(NamedTextColor.DARK_GRAY);
|
||||
|
||||
allBot.chat().tellraw(component, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerJoined (MutablePlayerListEntry target) {
|
||||
if (!trusted.contains(target.profile().getName())) return;
|
||||
|
||||
broadcast(
|
||||
Component.translatable(
|
||||
"Trusted player %s is now online",
|
||||
Component.text(target.profile().getName()).color(NamedTextColor.GREEN)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLeft (MutablePlayerListEntry target) {
|
||||
if (!trusted.contains(target.profile().getName())) return;
|
||||
|
||||
broadcast(
|
||||
Component.translatable(
|
||||
"Trusted player %s is now offline",
|
||||
Component.text(target.profile().getName()).color(NamedTextColor.GREEN)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,9 @@ discord:
|
|||
servers:
|
||||
localhost:25565: 'channel id'
|
||||
|
||||
trusted:
|
||||
- 'player name'
|
||||
|
||||
keys:
|
||||
normalKey: 'normal hash key here'
|
||||
ownerKey: 'OwnerHash™ key here'
|
||||
|
@ -50,3 +53,4 @@ bots:
|
|||
port: 25565
|
||||
username: 'ChomeNS_Bot'
|
||||
kaboom: false
|
||||
serverName: 'Localhost' # name it whatever you like, it will be used as server name in trusted broadcast
|
||||
|
|
Loading…
Reference in a new issue