add/improve/fix stuff

ig mabe mabe mabe
useCore!1!1!
This commit is contained in:
ChomeNS
2023-04-21 13:53:59 +07:00
parent d733da420f
commit 2b9d29e52e
10 changed files with 113 additions and 68 deletions

View File

@@ -25,6 +25,7 @@ public class Bot {
private final String _username;
@Getter private final boolean kaboom;
@Getter private final String serverName;
@Getter @Setter private boolean useCore;
@Getter @Setter private boolean useChat;
@Getter private final boolean hasEssentials;
@Getter private final List<Bot> allBots;
@@ -63,12 +64,13 @@ public class Bot {
@Getter private MazePlugin maze;
@Getter private ExploitsPlugin exploits;
public Bot (String host, int port, String _username, boolean kaboom, String serverName, boolean useChat, boolean hasEssentials, List<Bot> allBots, Configuration config) {
public Bot (String host, int port, String _username, boolean kaboom, String serverName, boolean useCore, boolean useChat, boolean hasEssentials, List<Bot> allBots, Configuration config) {
this.host = host;
this.port = port;
this._username = _username;
this.kaboom = kaboom;
this.serverName = serverName;
this.useCore = useCore;
this.useChat = useChat;
this.hasEssentials = hasEssentials;
this.allBots = allBots;

View File

@@ -79,7 +79,8 @@ public class Configuration {
@Getter public String username;
@Getter public boolean kaboom = false;
@Getter public String serverName;
@Getter public boolean useCore = true;
@Getter public boolean useChat = false;
@Getter public boolean hasEssentials = false;
@Getter public boolean hasEssentials = true;
}
}

View File

@@ -70,10 +70,11 @@ public class Main {
final String username = botOption.username();
final boolean kaboom = botOption.kaboom();
final String serverName = botOption.serverName();
final boolean useCore = botOption.useCore();
final boolean useChat = botOption.useChat();
final boolean hasEssentials = botOption.hasEssentials();
final Bot bot = new Bot(host, port, username, kaboom, serverName, useChat, hasEssentials, allBots, config);
final Bot bot = new Bot(host, port, username, kaboom, serverName, useCore, useChat, hasEssentials, allBots, config);
allBots.add(bot);
}

View File

@@ -0,0 +1,43 @@
package land.chipmunk.chayapak.chomens_bot.commands;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import net.kyori.adventure.text.Component;
import java.util.ArrayList;
import java.util.List;
public class ClearChatQueueCommand implements Command {
public String name() { return "clearchatqueue"; }
public String description() {
return "Clears the bot's chat queue";
}
public List<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> aliases = new ArrayList<>();
aliases.add("ccq");
return aliases;
}
public int trustLevel() {
return 0;
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();
bot.chat().queue().clear();
return Component.text("success");
}
}

View File

@@ -52,6 +52,7 @@ public class BossbarManagerPlugin extends SessionAdapter {
}
private void update() {
if (!enabled) return;
for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) {
final String name = _bossBar.getKey();
final BossBar bossBar = _bossBar.getValue();
@@ -84,6 +85,7 @@ public class BossbarManagerPlugin extends SessionAdapter {
}
private void createBossBar (String name, String players) {
if (!enabled) return;
bot.core().run("minecraft:bossbar add " + bossBarPrefix + name + " \"\"");
bot.core().run("minecraft:bossbar set " + bossBarPrefix + name + " players " + players);
}

View File

@@ -17,6 +17,7 @@ import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntr
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.PlayerMessage;
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
@@ -32,6 +33,8 @@ public class ChatPlugin extends SessionAdapter {
private final CommandSpyParser commandSpyParser;
@Getter private final List<String> queue = new ArrayList<>();
private final List<ChatListener> listeners = new ArrayList<>();
public ChatPlugin (Bot bot) {
@@ -45,6 +48,8 @@ public class ChatPlugin extends SessionAdapter {
chatParsers.add(new MinecraftChatParser(bot));
chatParsers.add(new KaboomChatParser(bot));
chatParsers.add(new ChomeNSCustomChatParser(bot));
bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, 125, TimeUnit.MILLISECONDS);
}
@Override
@@ -131,26 +136,28 @@ public class ChatPlugin extends SessionAdapter {
}
}
public void send (String message) {
final String[] splitted = message.split("(?<=\\G.{100})|\\n");
private void sendChatTick () {
if (queue.size() == 0) return;
final String message = queue.get(0);
final String[] splitted = message.split("(?<=\\G.{255})|\\n");
int i = 200;
for (String splitMessage : splitted) {
if (splitMessage.trim().equals("")) continue;
bot.executor().schedule(() -> {
if (splitMessage.startsWith("/")) {
bot.session().send(new ServerboundChatCommandPacket(
splitMessage.substring(1),
Instant.now().toEpochMilli(),
0L,
Collections.emptyList(),
0,
new BitSet()
));
} else {
// Temporary fix for the bot getting kicked instead of chatting
bot.core().run("essentials:sudo " + bot.players().getBotEntry().profile().getIdAsString() + " c:" + splitMessage);
if (splitMessage.startsWith("/")) {
bot.session().send(new ServerboundChatCommandPacket(
splitMessage.substring(1),
Instant.now().toEpochMilli(),
0L,
Collections.emptyList(),
0,
new BitSet()
));
} else {
// Temporary fix for the bot getting kicked instead of chatting
bot.core().run("essentials:sudo " + bot.players().getBotEntry().profile().getIdAsString() + " c:" + splitMessage);
// bot.session().send(new ServerboundChatPacket(
// splitMessage,
// Instant.now().toEpochMilli(),
@@ -159,11 +166,14 @@ public class ChatPlugin extends SessionAdapter {
// 0,
// new BitSet()
// ));
}
}, i, TimeUnit.MILLISECONDS);
i = i + 200;
}
}
queue.remove(0);
}
public void send (String message) {
queue.add(message);
}
public void tellraw (Component component, String targets) {

View File

@@ -58,6 +58,7 @@ public class CommandHandlerPlugin {
registerCommand(new GenerateMazeCommand());
registerCommand(new TranslateCommand());
registerCommand(new KickCommand());
registerCommand(new ClearChatQueueCommand());
}
public void registerCommand (Command command) {

View File

@@ -78,16 +78,20 @@ public class CorePlugin extends PositionPlugin.PositionListener {
public void run (String command) {
if (!ready) return;
bot.session().send(new ServerboundSetCommandBlockPacket(
absoluteCorePosition(),
command,
kaboom ? CommandBlockMode.AUTO : CommandBlockMode.REDSTONE,
true,
false,
true
));
if (bot.useCore()) {
bot.session().send(new ServerboundSetCommandBlockPacket(
absoluteCorePosition(),
command,
kaboom ? CommandBlockMode.AUTO : CommandBlockMode.REDSTONE,
true,
false,
true
));
incrementBlock();
incrementBlock();
} else if (command.length() < 256) {
bot.chat().send("/" + command);
}
}
public CompletableFuture<CompoundTag> runTracked (String command) {