add botuser and username self care

This commit is contained in:
Chayapak 2023-04-06 11:07:56 +07:00
parent a957a281b1
commit 55a9d6a746
6 changed files with 96 additions and 8 deletions

View file

@ -57,6 +57,7 @@ public class Configuration {
@Getter public boolean mute = true;
@Getter public boolean prefix = true;
@Getter public boolean username = true;
}
public static class Bots {

View file

@ -0,0 +1,79 @@
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 net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.ArrayList;
import java.util.List;
public class BotUserCommand implements Command {
public String name() { return "botuser"; }
public String description() {
return "Shows the bot's username and UUID";
}
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("");
return aliases;
}
public int trustLevel() {
return 0;
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();
final String username = bot.username();
final String uuid = bot.players().getBotEntry().profile().getIdAsString();
context.sendOutput(
Component.translatable(
"The bot's username is: %s and the UUID is: %s",
Component
.text(username)
.hoverEvent(
HoverEvent.showText(
Component
.text("Click here to copy the username to your clipboard")
.color(NamedTextColor.GREEN)
)
)
.clickEvent(
ClickEvent.copyToClipboard(username)
)
.color(NamedTextColor.GOLD),
Component
.text(uuid)
.hoverEvent(
HoverEvent.showText(
Component
.text("Click here to copy the UUID to your clipboard")
.color(NamedTextColor.GREEN)
)
)
.clickEvent(
ClickEvent.copyToClipboard(uuid)
)
.color(NamedTextColor.AQUA)
)
);
return Component.text("success");
}
}

View file

@ -49,6 +49,7 @@ public class CommandHandlerPlugin {
registerCommand(new CloopCommand());
registerCommand(new WeatherCommand());
registerCommand(new ServerInfoCommand());
registerCommand(new BotUserCommand());
}
public void registerCommand (Command command) {

View file

@ -73,6 +73,8 @@ public class PlayersPlugin extends SessionAdapter {
return null;
}
public MutablePlayerListEntry getBotEntry () { return getEntry(bot.username()); }
private MutablePlayerListEntry getEntry (PlayerListEntry other) {
return getEntry(other.getProfile().getId());
}

View file

@ -41,6 +41,7 @@ public class SelfCarePlugin extends SessionAdapter {
private boolean socialspy = false;
private boolean muted = false;
private boolean prefix = false;
private boolean username = true;
public SelfCarePlugin (Bot bot) {
this.bot = bot;
@ -67,12 +68,12 @@ public class SelfCarePlugin extends SessionAdapter {
else if (message.equals("You now have the tag: [ChomeNS Bot]") || // for 1.19.2 (or 1.19?) and older clones
message.equals("You now have the tag: &8[&eChomeNS Bot&8]")
) {
prefix = true;
return;
}
if (message.startsWith("You no longer have a tag")) prefix = false;
if (message.startsWith("You now have the tag: ")) prefix = false;
) prefix = true;
else if (message.startsWith("You no longer have a tag")) prefix = false;
else if (message.startsWith("You now have the tag: ")) prefix = false;
else if (message.equals("Successfully set your username to \"" + bot.username() + "\"")) username = true;
else if (message.startsWith("Successfully set your username to \"")) username = false;
}
});
}
@ -88,6 +89,7 @@ public class SelfCarePlugin extends SessionAdapter {
else if (selfCares.socialspy() && !socialspy) bot.chat().send("/essentials:socialspy enable");
else if (selfCares.mute() && muted) bot.chat().send("/essentials:mute " + bot.username());
else if (selfCares.prefix() && !prefix && bot.kaboom()) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]");
else if (selfCares.username() && !username && bot.kaboom()) bot.chat().send("/extras:username " + bot.username());
}
@Override

View file

@ -32,7 +32,7 @@ core:
# PLEASE give valid JSON component here else the core don't refill at all
customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]'
selfCare:
checkInterval: 1000,
checkInterval: 1000
# vanilla
op: true
@ -45,9 +45,12 @@ selfCare:
socialspy: true
mute: true
# extras
# commandspy
cspy: true
# extras
prefix: true
username: true # do NOT set this to false unless you know what you are doing
bots:
# username and kaboom are optional.
# for username if it doesn't exist it will default to random username