refactor: improve vanish selfcare & BotVisibilityCommand

This commit is contained in:
ChomeNS
2025-03-30 16:30:12 +07:00
parent 7c6c2c23ce
commit 209cd1a6dd
3 changed files with 15 additions and 17 deletions

View File

@@ -30,13 +30,13 @@ public class BotVisibilityCommand extends Command {
final String action = context.getString(false, false, false);
if (action.isEmpty()) {
final boolean visibility = bot.selfCare.visibility;
bot.selfCare.visibility = !visibility;
final boolean visibility = bot.selfCare.visible;
bot.selfCare.visible = !visibility;
final NamedTextColor greenOrGold = bot.selfCare.visible ? NamedTextColor.GREEN : NamedTextColor.GOLD;
final String visibleOrInvisible = bot.selfCare.visible ? "visible" : "invisible";
final NamedTextColor greenOrGold = bot.selfCare.visibility ? NamedTextColor.GREEN : NamedTextColor.GOLD;
final String visibleOrInvisible = bot.selfCare.visibility ? "visible" : "invisible";
final String disableOrEnable = bot.selfCare.visibility ? "disable" : "enable";
bot.core.run("/essentials:vanish " + bot.profile.getName() + " " + disableOrEnable);
return Component.empty()
.append(Component.text("The bot's visibility is now "))
.append(Component.text(visibleOrInvisible).color(greenOrGold))
@@ -44,24 +44,22 @@ public class BotVisibilityCommand extends Command {
} else {
switch (action) {
case "on", "true" -> {
bot.selfCare.visibility = true;
bot.core.run("/essentials:vanish " + bot.profile.getName() + " disable");
bot.selfCare.visible = true;
return Component.empty()
.append(Component.text("The bot's visibility is now "))
.append(Component.text("visible").color(NamedTextColor.GREEN))
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
case "off", "false" -> {
bot.selfCare.visibility = false;
bot.core.run("/essentials:vanish " + bot.profile.getName() + " enable");
bot.selfCare.visible = false;
return Component.empty()
.append(Component.text("The bot's visibility is now "))
.append(Component.text("invisible").color(NamedTextColor.GOLD))
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
default -> {
throw new CommandException(Component.text("Invalid action"));
}
default -> throw new CommandException(Component.text("Invalid action"));
}
}
}

View File

@@ -31,7 +31,7 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener,
private ScheduledFuture<?> checkTask;
public boolean visibility = false;
public boolean visible = false;
private int entityId;
public GameMode gamemode;
@@ -126,8 +126,8 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener,
bot.username + " " :
"";
if (selfCares.vanish && !vanish && !visibility && !creayun) {
runEssentialsCommand("essentials:vanish " + usernameOrBlank + "enable");
if (selfCares.vanish && visible == vanish && !creayun) {
runEssentialsCommand("essentials:vanish " + usernameOrBlank + (visible ? "disable" : "enable"));
} else if (selfCares.nickname && !nickname) {
runEssentialsCommand("essentials:nickname " + usernameOrBlank + "off");
} else if (selfCares.socialspy && !socialspy && !creayun) {