improve the stuff

This commit is contained in:
Chayapak 2023-08-20 15:47:18 +07:00
parent e521c6b671
commit 8a8d6cc102
5 changed files with 37 additions and 40 deletions

View file

@ -54,7 +54,6 @@ public class Bot {
public CommandSpyPlugin commandSpy;
public PositionPlugin position;
public ServerPluginsManagerPlugin serverPluginsManager;
public PluginCheckerPlugin pluginChecker;
public SelfCarePlugin selfCare;
public CorePlugin core;
public TeamPlugin team;
@ -103,7 +102,6 @@ public class Bot {
this.commandSpy = new CommandSpyPlugin(this);
this.position = new PositionPlugin(this);
this.serverPluginsManager = new ServerPluginsManagerPlugin(this);
this.pluginChecker = new PluginCheckerPlugin(this);
this.selfCare = new SelfCarePlugin(this);
this.core = new CorePlugin(this);
this.team = new TeamPlugin(this);

View file

@ -122,7 +122,7 @@ public class CorePlugin extends PositionPlugin.Listener {
}
private void forceRun (String command) {
if (bot.pluginChecker.hasExtras) {
if (bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS)) {
bot.session.send(new ServerboundSetCommandBlockPacket(
block,
command,
@ -205,7 +205,18 @@ public class CorePlugin extends PositionPlugin.Listener {
);
final Session session = bot.session;
session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(bot.pluginChecker.hasExtras ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag)));
session.send(
new ServerboundSetCreativeModeSlotPacket(
36,
new ItemStack(
bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS) ?
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 ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1));
}

View file

@ -1,18 +0,0 @@
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,7 +86,8 @@ public class SelfCarePlugin extends Bot.Listener {
public void check () {
final Configuration.SelfCare selfCares = bot.config.selfCare;
final boolean kaboom = bot.pluginChecker.hasExtras;
final boolean kaboom = bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS);
final boolean hasEssentials = bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.ESSENTIALS);
// chat only
if (selfCares.op && permissionLevel < 2) bot.chat.send("/minecraft:op @s[type=player]");
@ -96,25 +97,25 @@ public class SelfCarePlugin extends Bot.Listener {
else if (selfCares.username && !username && kaboom) bot.chat.send("/extras:username " + bot.username);
// core
// 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.vanish && !vanish && !visibility && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable");
else bot.core.run("essentials:vanish " + bot.username + " enable");
}
else if (selfCares.nickname && !nickname && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off");
else bot.core.run("essentials:nickname " + bot.username + " off");
}
else if (selfCares.socialspy && !socialspy && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable");
else bot.core.run("essentials:socialspy " + bot.username + " enable");
}
else if (selfCares.mute && muted && bot.pluginChecker.hasEssentials) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString());
else bot.core.run("essentials:mute " + bot.profile.getIdAsString());
else if (hasEssentials) {
// TODO: improve lol, this is ohio
muted = false; // too lazy fix and probably the worst fix?
if (selfCares.vanish && !vanish && !visibility) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable");
else bot.core.run("essentials:vanish " + bot.username + " enable");
} else if (selfCares.nickname && !nickname) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off");
else bot.core.run("essentials:nickname " + bot.username + " off");
} else if (selfCares.socialspy && !socialspy) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable");
else bot.core.run("essentials:socialspy " + bot.username + " enable");
} else if (selfCares.mute && muted) {
if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString());
else bot.core.run("essentials:mute " + bot.profile.getIdAsString());
muted = false; // too lazy fix
}
}
}

View file

@ -10,6 +10,9 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
public class ServerPluginsManagerPlugin extends Bot.Listener {
public static final String EXTRAS = "Extras";
public static final String ESSENTIALS = "Essentials";
private final Bot bot;
public List<String> plugins = new ArrayList<>();
@ -33,4 +36,6 @@ public class ServerPluginsManagerPlugin extends Bot.Listener {
return packet;
});
}
public boolean hasPlugin (String plugin) { return plugins.contains(plugin); }
}