remove kaboom and hasEssentials from config and make it d y n a m i c

This commit is contained in:
Chayapak 2023-08-15 19:51:25 +07:00
parent fe1b0e12af
commit 848efd3431
7 changed files with 71 additions and 20 deletions

View file

@ -75,6 +75,8 @@ public class Bot {
public PacketSnifferPlugin packetSniffer; public PacketSnifferPlugin packetSniffer;
public VoiceChatPlugin voiceChat; public VoiceChatPlugin voiceChat;
public TagPlugin tag; public TagPlugin tag;
public ServerPluginsManagerPlugin serverPluginsManager;
public PluginCheckerPlugin pluginChecker;
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) { public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
this.host = botOption.host; this.host = botOption.host;
@ -121,6 +123,8 @@ public class Bot {
this.packetSniffer = new PacketSnifferPlugin(this); this.packetSniffer = new PacketSnifferPlugin(this);
this.voiceChat = new VoiceChatPlugin(this); this.voiceChat = new VoiceChatPlugin(this);
this.tag = new TagPlugin(this); this.tag = new TagPlugin(this);
this.serverPluginsManager = new ServerPluginsManagerPlugin(this);
this.pluginChecker = new PluginCheckerPlugin(this);
for (Listener listener : listeners) listener.loadedPlugins(); for (Listener listener : listeners) listener.loadedPlugins();

View file

@ -127,12 +127,10 @@ public class Configuration {
public String host; public String host;
public int port; public int port;
public String username; public String username;
public boolean kaboom = false;
public boolean creayun = false; public boolean creayun = false;
public String serverName; public String serverName;
public boolean useCore = true; public boolean useCore = true;
public boolean useChat = false; public boolean useChat = false;
public boolean hasEssentials = true;
public int reconnectDelay = 2000; public int reconnectDelay = 2000;
public boolean removeNamespaces = false; public boolean removeNamespaces = false;
public int chatQueueDelay = 125; public int chatQueueDelay = 125;

View file

@ -52,15 +52,12 @@ public class CorePlugin extends PositionPlugin.Listener {
private int nextTransactionId = 0; private int nextTransactionId = 0;
private final Map<Integer, CompletableFuture<CompoundTag>> transactions = new HashMap<>(); private final Map<Integer, CompletableFuture<CompoundTag>> transactions = new HashMap<>();
private final boolean kaboom;
private int commandsPerSecond = 0; private int commandsPerSecond = 0;
private boolean shouldRefill = false; private boolean shouldRefill = false;
public CorePlugin (Bot bot) { public CorePlugin (Bot bot) {
this.bot = bot; this.bot = bot;
this.kaboom = bot.options.kaboom;
this.fromSize = Vector3i.from( this.fromSize = Vector3i.from(
bot.config.core.start.x, bot.config.core.start.x,
@ -124,7 +121,7 @@ public class CorePlugin extends PositionPlugin.Listener {
} }
private void forceRun (String command) { private void forceRun (String command) {
if (kaboom) { if (bot.pluginChecker.hasExtras) {
bot.session.send(new ServerboundSetCommandBlockPacket( bot.session.send(new ServerboundSetCommandBlockPacket(
block, block,
command, command,
@ -207,7 +204,7 @@ public class CorePlugin extends PositionPlugin.Listener {
); );
final Session session = bot.session; final Session session = bot.session;
session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(kaboom ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag))); session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(bot.pluginChecker.hasExtras ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag)));
session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0)); session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0));
session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1)); session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1));
} }

View file

@ -0,0 +1,18 @@
package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import java.util.concurrent.TimeUnit;
public class PluginCheckerPlugin extends Bot.Listener {
public boolean hasExtras;
public boolean hasEssentials;
public PluginCheckerPlugin(Bot bot) {
// dumb
bot.executor.scheduleAtFixedRate(() -> {
hasExtras = bot.serverPluginsManager.plugins.contains("Extras");
hasEssentials = bot.serverPluginsManager.plugins.contains("Essentials");
}, 0, 5, TimeUnit.SECONDS);
}
}

View file

@ -86,29 +86,31 @@ public class SelfCarePlugin extends Bot.Listener {
public void check () { public void check () {
final Configuration.SelfCare selfCares = bot.config.selfCare; final Configuration.SelfCare selfCares = bot.config.selfCare;
final boolean kaboom = bot.pluginChecker.hasExtras;
// chat only // chat only
if (selfCares.op && permissionLevel < 2) bot.chat.send("/minecraft:op @s[type=player]"); if (selfCares.op && permissionLevel < 2) bot.chat.send("/minecraft:op @s[type=player]");
else if (selfCares.gamemode && gamemode != GameMode.CREATIVE) bot.chat.send("/minecraft:gamemode creative @s[type=player]"); else if (selfCares.gamemode && gamemode != GameMode.CREATIVE) bot.chat.send("/minecraft:gamemode creative @s[type=player]");
else if (selfCares.cspy && !cspy && bot.options.kaboom) bot.chat.send("/commandspy:commandspy on"); else if (selfCares.cspy && !cspy && kaboom) bot.chat.send("/commandspy:commandspy on");
else if (selfCares.prefix.enabled && !prefix && bot.options.kaboom) bot.chat.send("/extras:prefix " + bot.config.selfCare.prefix.prefix); else if (selfCares.prefix.enabled && !prefix && kaboom) bot.chat.send("/extras:prefix " + bot.config.selfCare.prefix.prefix);
else if (selfCares.username && !username && bot.options.kaboom) bot.chat.send("/extras:username " + bot.username); else if (selfCares.username && !username && kaboom) bot.chat.send("/extras:username " + bot.username);
// core // core
// TODO: improve lol // TODO: improve lol, this is ohio
else if (selfCares.icu.enabled && positionPacketsPerSecond > selfCares.icu.positionPacketsPerSecond) bot.core.run("essentials:sudo * icu stop"); else if (selfCares.icu.enabled && positionPacketsPerSecond > selfCares.icu.positionPacketsPerSecond) bot.core.run("essentials:sudo * icu stop");
else if (selfCares.vanish && !vanish && !visibility && bot.options.hasEssentials) { else if (selfCares.vanish && !vanish && !visibility && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable"); if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable");
else bot.core.run("essentials:vanish " + bot.username + " enable"); else bot.core.run("essentials:vanish " + bot.username + " enable");
} }
else if (selfCares.nickname && !nickname && bot.options.hasEssentials) { else if (selfCares.nickname && !nickname && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off"); if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off");
else bot.core.run("essentials:nickname " + bot.username + " off"); else bot.core.run("essentials:nickname " + bot.username + " off");
} }
else if (selfCares.socialspy && !socialspy && bot.options.hasEssentials) { else if (selfCares.socialspy && !socialspy && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable"); if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable");
else bot.core.run("essentials:socialspy " + bot.username + " enable"); else bot.core.run("essentials:socialspy " + bot.username + " enable");
} }
else if (selfCares.mute && muted && bot.options.hasEssentials) { else if (selfCares.mute && muted && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString()); if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString());
else bot.core.run("essentials:mute " + bot.profile.getIdAsString()); else bot.core.run("essentials:mute " + bot.profile.getIdAsString());

View file

@ -0,0 +1,36 @@
package land.chipmunk.chayapak.chomens_bot.plugins;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCommandSuggestionsPacket;
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
import land.chipmunk.chayapak.chomens_bot.Bot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class ServerPluginsManagerPlugin extends Bot.Listener {
private final Bot bot;
public List<String> plugins = new ArrayList<>();
public ServerPluginsManagerPlugin (Bot bot) {
this.bot = bot;
bot.addListener(this);
}
@Override
public void connected(ConnectedEvent event) {
final CompletableFuture<ClientboundCommandSuggestionsPacket> future = bot.tabComplete.tabComplete("/ver ");
future.thenApply((packet) -> {
final String[] matches = packet.getMatches();
// should i just use the plugins as the String array instead of a list?
plugins = new ArrayList<>(Arrays.asList(matches));
return packet;
});
}
}

View file

@ -101,24 +101,20 @@ eval:
bots: bots:
# username - optional, if not specified it will just use a random username # username - optional, if not specified it will just use a random username
# kaboom - defaults to false # creayun - defaults to false
# creayun - same as kaboom
# serverName - name it whatever you like, it will be used as server name in trusted broadcast and in console # serverName - name it whatever you like, it will be used as server name in trusted broadcast and in console
# useCore - if enabled it just sends the command using chat instead of using core. recommended to enable useChat too when this is enabled # useCore - if enabled it just sends the command using chat instead of using core. recommended to enable useChat too when this is enabled
# useChat - when the bot tellraws it will chat instead of using the core to run tellraw # useChat - when the bot tellraws it will chat instead of using the core to run tellraw
# hasEssentials - if the server has essentials plugin just set it to true!! ! !!31
# removeNamespaces - when the bot sends a command it will remove like `minecraft:` for example if set to true # removeNamespaces - when the bot sends a command it will remove like `minecraft:` for example if set to true
# coreRateLimit - will ignore commands if reached the ratelimit # coreRateLimit - will ignore commands if reached the ratelimit
- host: 'localhost' - host: 'localhost'
port: 25565 port: 25565
username: 'ChomeNS_Bot' username: 'ChomeNS_Bot'
kaboom: false
creayun: false creayun: false
serverName: 'Localhost' serverName: 'Localhost'
useCore: true useCore: true
useChat: false useChat: false
hasEssentials: false
reconnectDelay: 2000 reconnectDelay: 2000
removeNamespaces: false removeNamespaces: false
chatQueueDelay: 125 chatQueueDelay: 125