make colors configurable mabe

hopefully i didn't miss any
also it is intentional that i did not change the music bossbar name
This commit is contained in:
Chayapak 2023-05-13 18:15:21 +07:00
parent 7907be971f
commit c84b9ea8c3
27 changed files with 234 additions and 89 deletions

View file

@ -24,6 +24,8 @@ public class Configuration {
@Getter public Core core = new Core();
@Getter public Discord discord = new Discord();
@Getter public ColorPalette colorPalette = new ColorPalette();
@Getter public String ownerName = "chayapak"; // mabe mabe
@ -44,6 +46,17 @@ public class Configuration {
@Getter public int z = 0;
}
public static class ColorPalette {
@Getter public String primary = "yellow";
@Getter public String secondary = "gold";
@Getter public String defaultColor = "white";
@Getter public String username = "gold";
@Getter public String uuid = "aqua";
@Getter public String string = "aqua";
@Getter public String number = "gold";
@Getter public String ownerName = "green";
}
public static class Discord {
@Getter public boolean enabled = true;
@Getter public String prefix = "default!";

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
@ -56,7 +57,7 @@ public class BotUserCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(username)
)
.color(NamedTextColor.GOLD),
.color(ColorUtilities.getColorByString(bot.config().colorPalette().username())),
Component
.text(uuid)
.hoverEvent(
@ -69,7 +70,7 @@ public class BotUserCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(uuid)
)
.color(NamedTextColor.AQUA)
);
.color(ColorUtilities.getColorByString(bot.config().colorPalette().uuid()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
}

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -59,14 +60,16 @@ public class BotVisibilityCommand implements Command {
bot.chat().send("/essentials:vanish disable");
return Component.empty()
.append(Component.text("The bot's visibility is now "))
.append(Component.text("visible").color(NamedTextColor.GREEN));
.append(Component.text("visible").color(NamedTextColor.GREEN))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "off", "false" -> {
bot.selfCare().visibility(false);
bot.chat().send("/essentials:vanish enable");
return Component.empty()
.append(Component.text("The bot's visibility is now "))
.append(Component.text("invisible").color(NamedTextColor.GOLD));
.append(Component.text("invisible").color(NamedTextColor.GOLD))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
default -> {
return Component.text("Invalid argument").color(NamedTextColor.RED);

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.data.CommandLoop;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
@ -60,9 +61,9 @@ public class CloopCommand implements Command {
return Component.translatable(
"Added %s with interval %s to the cloops",
Component.text(command).color(NamedTextColor.AQUA),
Component.text(interval).color(NamedTextColor.GOLD)
);
Component.text(command).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())),
Component.text(interval).color(ColorUtilities.getColorByString(bot.config().colorPalette().number()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "remove" -> {
try {
@ -71,15 +72,15 @@ public class CloopCommand implements Command {
return Component.translatable(
"Removed cloop %s",
Component.text(index).color(NamedTextColor.GOLD)
);
Component.text(index).color(ColorUtilities.getColorByString(bot.config().colorPalette().number()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
} catch (IndexOutOfBoundsException | IllegalArgumentException | NullPointerException ignored) {
return Component.text("Invalid index").color(NamedTextColor.RED);
}
}
case "clear" -> {
bot.cloop().clear();
return Component.text("Cleared all cloops");
return Component.text("Cleared all cloops").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "list" -> {
final List<Component> cloopsComponent = new ArrayList<>();
@ -89,9 +90,9 @@ public class CloopCommand implements Command {
cloopsComponent.add(
Component.translatable(
"%s %s (%s)",
Component.text(index).color(NamedTextColor.GREEN),
Component.text(command.command()).color(NamedTextColor.AQUA),
Component.text(command.interval()).color(NamedTextColor.GOLD)
Component.text(index).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())),
Component.text(command.command()).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())),
Component.text(command.interval()).color(ColorUtilities.getColorByString(bot.config().colorPalette().number()))
).color(NamedTextColor.DARK_GRAY)
);
index++;

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -38,8 +39,8 @@ public class CreatorCommand implements Command {
final Bot bot = context.bot();
return Component.empty()
.append(Component.text("ChomeNS Bot ").color(NamedTextColor.YELLOW))
.append(Component.text("was created by ").color(NamedTextColor.WHITE))
.append(Component.text("chayapak").color(NamedTextColor.GREEN));
.append(Component.text("ChomeNS Bot ").color(ColorUtilities.getColorByString(bot.config().colorPalette().primary())))
.append(Component.text("was created by ").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())))
.append(Component.text("chayapak").color(ColorUtilities.getColorByString(bot.config().colorPalette().ownerName())));
}
}

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -40,7 +41,7 @@ public class DiscordCommand implements Command {
final String link = bot.config().discord().inviteLink();
return Component.empty()
.append(Component.text("The Discord invite is ").color(NamedTextColor.WHITE))
.append(Component.text("The Discord invite is ").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())))
.append(
Component
.text(link)

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.data.FilteredPlayer;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
@ -76,8 +77,8 @@ public class FilterCommand implements Command {
bot.filter().add(player, regex, ignoreCase);
return Component.translatable(
"Added %s to the filters",
Component.text(player).color(NamedTextColor.AQUA)
);
Component.text(player).color(ColorUtilities.getColorByString(bot.config().colorPalette().username()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "remove" -> {
try {
@ -87,15 +88,15 @@ public class FilterCommand implements Command {
return Component.translatable(
"Removed %s from the filters",
Component.text(removed.playerName).color(NamedTextColor.AQUA)
);
Component.text(removed.playerName).color(ColorUtilities.getColorByString(bot.config().colorPalette().username()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
} catch (IndexOutOfBoundsException | IllegalArgumentException | NullPointerException ignored) {
return Component.text("Invalid index").color(NamedTextColor.RED);
}
}
case "clear" -> {
bot.filter().clear();
return Component.text("Cleared the filter");
return Component.text("Cleared the filter").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "list" -> {
final List<Component> filtersComponents = new ArrayList<>();
@ -105,8 +106,8 @@ public class FilterCommand implements Command {
filtersComponents.add(
Component.translatable(
"%s %s",
Component.text(index).color(NamedTextColor.GREEN),
Component.text(player.playerName).color(NamedTextColor.AQUA)
Component.text(index).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())),
Component.text(player.playerName).color(ColorUtilities.getColorByString(bot.config().colorPalette().username()))
).color(NamedTextColor.DARK_GRAY)
);

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.HoverEvent;
@ -124,7 +125,7 @@ public class HelpCommand implements Command {
usages.add(
Component.empty()
.append(Component.text(prefix + commandName).color(NamedTextColor.GOLD))
.append(Component.text(prefix + commandName).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary())))
.append(Component.text(
(command.alias().size() > 0 && !command.alias().get(0).equals("")) ?
" (" + String.join(", ", command.alias()) + ")" :
@ -144,7 +145,7 @@ public class HelpCommand implements Command {
Component.empty()
.append(Component.text(prefix + commandName).color(NamedTextColor.GOLD))
.append(Component.text(" "))
.append(Component.text(usage).color(NamedTextColor.AQUA))
.append(Component.text(usage).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())))
);
}

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -50,6 +51,7 @@ public class KickCommand implements Command {
return Component.empty()
.append(Component.text("Kicking player "))
.append(Component.text(name).color(NamedTextColor.GOLD));
.append(Component.text(name).color(ColorUtilities.getColorByString(bot.config().colorPalette().username())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
}

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent;
@ -59,7 +60,7 @@ public class ListCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(entry.profile().getName())
)
.color(NamedTextColor.YELLOW),
.color(ColorUtilities.getColorByString(bot.config().colorPalette().username())),
Component
.text(entry.profile().getIdAsString())
.hoverEvent(
@ -70,7 +71,7 @@ public class ListCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(entry.profile().getIdAsString())
)
.color(NamedTextColor.AQUA)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().uuid()))
).color(NamedTextColor.DARK_GRAY)
);
}

View file

@ -6,6 +6,7 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.plugins.MusicPlayerPlugin;
import land.chipmunk.chayapak.chomens_bot.song.Loop;
import land.chipmunk.chayapak.chomens_bot.song.Song;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent;
@ -167,7 +168,7 @@ public class MusicCommand implements Command {
bot.music().stopPlaying();
bot.music().songQueue().clear();
return Component.text("Cleared the song queue");
return Component.text("Cleared the song queue").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
public Component loop (CommandContext context, String[] args) {
@ -183,6 +184,7 @@ public class MusicCommand implements Command {
Component.empty()
.append(Component.text("Looping is now "))
.append(Component.text("disabled").color(NamedTextColor.RED))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
}
case "current" -> {
@ -190,12 +192,13 @@ public class MusicCommand implements Command {
context.sendOutput(
Component.empty()
.append(Component.text("Now looping "))
.append(bot.music().currentSong().name.color(NamedTextColor.GOLD))
.append(bot.music().currentSong().name.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
}
case "all" -> {
loop = Loop.ALL;
context.sendOutput(Component.text("Now looping every song"));
context.sendOutput(Component.text("Now looping every song").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())));
}
default -> {
return Component.text("Invalid argument").color(NamedTextColor.RED);
@ -208,6 +211,8 @@ public class MusicCommand implements Command {
}
public Component list (CommandContext context, String[] args) {
final Bot bot = context.bot();
final String prefix = context.prefix();
final Path _path = Path.of(root.toString(), String.join(" ", Arrays.copyOfRange(args, 1, args.length)));
@ -241,7 +246,7 @@ public class MusicCommand implements Command {
final String joinedPath = (args.length < 2) ? filename : Paths.get(location.getFileName().toString(), filename).toString();
fullList.add(
Component
.text(filename, (i++ & 1) == 0 ? NamedTextColor.YELLOW : NamedTextColor.GOLD)
.text(filename, (i++ & 1) == 0 ? ColorUtilities.getColorByString(bot.config().colorPalette().primary()) : ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
.clickEvent(
ClickEvent.suggestCommand(
prefix +
@ -272,13 +277,15 @@ public class MusicCommand implements Command {
}
public Component skip (CommandContext context) {
final MusicPlayerPlugin music = context.bot().music();
final Bot bot = context.bot();
final MusicPlayerPlugin music = bot.music();
if (music.currentSong() == null) return Component.text("No song is currently playing").color(NamedTextColor.RED);
context.sendOutput(
Component.empty()
.append(Component.text("Skipping "))
.append(music.currentSong().name.color(NamedTextColor.GOLD))
.append(music.currentSong().name.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
music.skip();
@ -293,7 +300,8 @@ public class MusicCommand implements Command {
return Component.empty()
.append(Component.text("Now playing "))
.append(song.name.color(NamedTextColor.GOLD));
.append(song.name.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
public Component queue (CommandContext context) {
@ -301,11 +309,16 @@ public class MusicCommand implements Command {
final LinkedList<Song> queue = bot.music().songQueue();
final List<Component> queueWithNames = new ArrayList<>();
for (Song song : queue) queueWithNames.add(song.name);
int i = 0;
for (Song song : queue) {
queueWithNames.add(
song.name.color((i++ & 1) == 0 ? ColorUtilities.getColorByString(bot.config().colorPalette().primary()) : ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
);
}
return Component.empty()
.append(Component.text("Queue: ").color(NamedTextColor.GREEN))
.append(Component.join(JoinConfiguration.separator(Component.text(", ")), queueWithNames).color(NamedTextColor.AQUA));
.append(Component.join(JoinConfiguration.separator(Component.text(", ")), queueWithNames));
}
// lazy fix for java using "goto" as keyword real
@ -342,7 +355,8 @@ public class MusicCommand implements Command {
return Component.empty()
.append(Component.text("Set the pitch to "))
.append(Component.text(pitch).color(NamedTextColor.GOLD));
.append(Component.text(pitch).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
public Component speed (CommandContext context, String[] args) {
@ -359,7 +373,8 @@ public class MusicCommand implements Command {
return Component.empty()
.append(Component.text("Set the speed to "))
.append(Component.text(speed).color(NamedTextColor.GOLD));
.append(Component.text(speed).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
public Component pause (CommandContext context) {

View file

@ -4,6 +4,7 @@ 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.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -58,7 +59,7 @@ public class NetMessageCommand implements Command {
)
),
Component.text(" "),
Component.text(context.sender().profile().getName()).color(NamedTextColor.GRAY),
context.sender().displayName().color(NamedTextColor.GRAY),
Component.text(" "),
Component.text(String.join(" ", args)).color(NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY);

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import land.chipmunk.chayapak.chomens_bot.util.MathUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -49,9 +50,10 @@ public class RandomTeleportCommand implements Command {
return Component.empty()
.append(Component.text("Teleporting "))
.append(Component.text(sender.profile().getName()).color(NamedTextColor.AQUA))
.append(Component.text(sender.profile().getName()).color(ColorUtilities.getColorByString(bot.config().colorPalette().username())))
.append(Component.text(" to ").color(NamedTextColor.WHITE))
.append(Component.text(stringPosition).color(NamedTextColor.GREEN))
.append(Component.text("...").color(NamedTextColor.WHITE));
.append(Component.text("...").color(NamedTextColor.WHITE))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
}

View file

@ -1,9 +1,12 @@
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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import java.io.IOException;
import java.io.RandomAccessFile;
@ -45,6 +48,8 @@ public class ServerInfoCommand implements Command {
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) throws UnknownHostException {
final Bot bot = context.bot();
// totallynotskidded from extras' serverinfo
final Component component;
@ -75,13 +80,15 @@ public class ServerInfoCommand implements Command {
file.close();
} catch (IOException ignored) {}
final TextColor color = ColorUtilities.getColorByString(bot.config().colorPalette().string());
final String[] lines = builder.toString().split("\n");
final Optional<String> modelName = Arrays.stream(lines)
.filter(line -> line.startsWith("model name"))
.findFirst();
final Component cpuModel = modelName
.map(s -> Component.text(s.split("\t: ")[1]).color(NamedTextColor.AQUA))
.orElseGet(() -> Component.text("N/A").color(NamedTextColor.AQUA));
.map(s -> Component.text(s.split("\t: ")[1]).color(color))
.orElseGet(() -> Component.text("N/A").color(color));
component = Component.translatable(
"""
@ -93,20 +100,20 @@ public class ServerInfoCommand implements Command {
CPU cores: %s
CPU model: %s
Heap memory usage: %s""",
Component.text(InetAddress.getLocalHost().getHostName()).color(NamedTextColor.AQUA),
Component.text(System.getProperty("user.dir")).color(NamedTextColor.AQUA),
Component.text(os.getArch()).color(NamedTextColor.AQUA),
Component.text(os.getVersion()).color(NamedTextColor.AQUA),
Component.text(os.getName()).color(NamedTextColor.AQUA),
Component.text(String.valueOf(Runtime.getRuntime().availableProcessors())).color(NamedTextColor.AQUA),
Component.text(InetAddress.getLocalHost().getHostName()).color(color),
Component.text(System.getProperty("user.dir")).color(color),
Component.text(os.getArch()).color(color),
Component.text(os.getVersion()).color(color),
Component.text(os.getName()).color(color),
Component.text(String.valueOf(Runtime.getRuntime().availableProcessors())).color(color),
cpuModel,
Component
.translatable(
"%s MB / %s MB",
Component.text(heapUsage.getUsed() / 1024L / 1024L),
Component.text(heapUsage.getMax() / 1024L / 1024L)
).color(NamedTextColor.AQUA)
).color(NamedTextColor.GOLD);
).color(color)
).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()));
return component;
}

View file

@ -3,6 +3,7 @@ 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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -42,13 +43,15 @@ public class TPSBarCommand implements Command {
bot.tps().on();
return Component.empty()
.append(Component.text("TPSBar is now "))
.append(Component.text("enabled").color(NamedTextColor.GREEN));
.append(Component.text("enabled").color(NamedTextColor.GREEN))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
case "off" -> {
bot.tps().off();
return Component.empty()
.append(Component.text("TPSBar is now "))
.append(Component.text("disabled").color(NamedTextColor.RED));
.append(Component.text("disabled").color(NamedTextColor.RED))
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
default -> {
return Component.text("Invalid argument").color(NamedTextColor.RED);

View file

@ -1,7 +1,9 @@
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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.joda.time.DateTime;
@ -39,6 +41,8 @@ public class TimeCommand implements Command {
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();
final String timezone = args[0];
DateTimeZone zone;
@ -55,8 +59,8 @@ public class TimeCommand implements Command {
return Component.translatable(
"The current time for %s is: %s",
Component.text(timezone).color(NamedTextColor.AQUA),
Component.text(timezone).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())),
Component.text(formattedTime).color(NamedTextColor.GREEN)
);
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
}

View file

@ -3,8 +3,10 @@ package land.chipmunk.chayapak.chomens_bot.commands;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -42,6 +44,8 @@ public class TranslateCommand implements Command {
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();
final String from = args[0];
final String to = args[1];
@ -79,7 +83,7 @@ public class TranslateCommand implements Command {
"Result: %s",
Component.text(output).color(NamedTextColor.GREEN)
)
.color(NamedTextColor.GOLD);
.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()));
} catch (Exception e) {
return Component.text(e.toString()).color(NamedTextColor.RED);
}

View file

@ -4,6 +4,7 @@ import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
@ -61,7 +62,7 @@ public class UUIDCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(uuid)
)
.color(NamedTextColor.AQUA)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().uuid()))
).color(NamedTextColor.GREEN);
} else {
final MutablePlayerListEntry entry = context.sender();
@ -80,7 +81,7 @@ public class UUIDCommand implements Command {
.clickEvent(
ClickEvent.copyToClipboard(uuid)
)
.color(NamedTextColor.AQUA)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().uuid()))
).color(NamedTextColor.GREEN);
}
}

View file

@ -1,7 +1,9 @@
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 land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -36,6 +38,8 @@ public class UptimeCommand implements Command {
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();
final long uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000;
long days = TimeUnit.SECONDS.toDays(uptime);
@ -44,7 +48,7 @@ public class UptimeCommand implements Command {
long seconds = TimeUnit.SECONDS.toSeconds(uptime) - (TimeUnit.SECONDS.toMinutes(uptime) * 60);
return Component.translatable(
"The bot's uptime is: %s",
"The bots uptime is: %s",
Component.translatable(
"%s days, %s hours, %s minutes, %s seconds",
Component.text(days),
@ -52,6 +56,6 @@ public class UptimeCommand implements Command {
Component.text(minutes),
Component.text(seconds)
).color(NamedTextColor.GREEN)
);
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
}
}

View file

@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -75,13 +76,12 @@ public class WeatherCommand implements Command {
return Component.translatable(
"Weather forecast for %s, %s:\n%s, feels like %s\nTime: %s",
Component.text(jsonObject.get("location").getAsJsonObject().get("name").getAsString()).color(NamedTextColor.AQUA),
Component.text(jsonObject.get("location").getAsJsonObject().get("country").getAsString()).color(NamedTextColor.AQUA),
Component.text(jsonObject.get("current").getAsJsonObject().get("temp_c").getAsString() + "°C").color(NamedTextColor.GOLD),
Component.text(jsonObject.get("location").getAsJsonObject().get("name").getAsString()).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())),
Component.text(jsonObject.get("location").getAsJsonObject().get("country").getAsString()).color(ColorUtilities.getColorByString(bot.config().colorPalette().string())),
Component.text(jsonObject.get("current").getAsJsonObject().get("temp_c").getAsString() + "°C").color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary())),
Component.text(jsonObject.get("current").getAsJsonObject().get("feelslike_c").getAsString() + "°C").color(NamedTextColor.GREEN),
Component.text(time).color(NamedTextColor.AQUA)
);
Component.text(time).color(ColorUtilities.getColorByString(bot.config().colorPalette().string()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
} catch (Exception e) {
return Component.text("Location \"" + location + "\" not found").color(NamedTextColor.RED);
}

View file

@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.Configuration;
import land.chipmunk.chayapak.chomens_bot.command.ConsoleCommandContext;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import lombok.Getter;
import net.dv8tion.jda.api.JDA;
import net.kyori.adventure.text.Component;
@ -101,7 +102,7 @@ public class ConsolePlugin {
Component.translatable(
"[%s] %s %s",
Component.text(bot.username() + " Console").color(NamedTextColor.GRAY),
Component.text(bot.config().ownerName()).color(NamedTextColor.GREEN),
Component.text(bot.config().ownerName()).color(ColorUtilities.getColorByString(bot.config().colorPalette().ownerName())),
Component.text(line).color(NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY)
);

View file

@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.Logger;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.TextChannel;
@ -71,8 +72,8 @@ public class GrepLogPlugin {
bot.chat().tellraw(
Component.translatable(
"Collecting %s in logs...",
Component.text(query).color(NamedTextColor.GOLD)
)
Component.text(query).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
final File[] fileList = Logger.logDir.listFiles();
@ -170,7 +171,7 @@ public class GrepLogPlugin {
bot.chat().tellraw(
Component.translatable(
"Log query finished, found %s matches. Results were sent in Discord",
Component.text(matches).color(NamedTextColor.AQUA)
Component.text(matches).color(ColorUtilities.getColorByString(bot.config().colorPalette().number()))
)
);

View file

@ -1,6 +1,7 @@
package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import land.chipmunk.chayapak.chomens_bot.util.MazeGenerator;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
@ -18,10 +19,10 @@ public class MazePlugin {
bot.chat().tellraw(
Component.translatable(
"Generating maze at %s %s %s...",
Component.text(startX).color(NamedTextColor.AQUA),
Component.text(startY).color(NamedTextColor.AQUA),
Component.text(startZ).color(NamedTextColor.AQUA)
)
Component.text(startX).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())),
Component.text(startY).color(ColorUtilities.getColorByString(bot.config().colorPalette().number())),
Component.text(startZ).color(ColorUtilities.getColorByString(bot.config().colorPalette().number()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
final int[][] maze = generator.maze();
@ -168,6 +169,7 @@ public class MazePlugin {
)
)
)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
}
}

View file

@ -6,6 +6,7 @@ import land.chipmunk.chayapak.chomens_bot.data.BossBar;
import land.chipmunk.chayapak.chomens_bot.data.BossBarColor;
import land.chipmunk.chayapak.chomens_bot.data.BossBarStyle;
import land.chipmunk.chayapak.chomens_bot.song.*;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import land.chipmunk.chayapak.chomens_bot.util.MathUtilities;
import lombok.Getter;
import lombok.Setter;
@ -18,7 +19,7 @@ import java.nio.file.Path;
import java.text.DecimalFormat;
import java.util.LinkedList;
// Author: _ChipMC_ with some stuff added
// Author: _ChipMC_ & chayapak <3
public class MusicPlayerPlugin extends Bot.Listener {
private final Bot bot;
@ -59,7 +60,14 @@ public class MusicPlayerPlugin extends Bot.Listener {
try {
final SongLoaderThread _loaderThread = new SongLoaderThread(location, bot);
bot.chat().tellraw(Component.translatable("Loading %s", Component.text(location.getFileName().toString(), NamedTextColor.GOLD)));
bot.chat().tellraw(
Component
.translatable(
"Loading %s",
Component.text(location.getFileName().toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
_loaderThread.start();
loaderThread = _loaderThread;
} catch (SongLoaderException e) {
@ -77,7 +85,14 @@ public class MusicPlayerPlugin extends Bot.Listener {
try {
final SongLoaderThread _loaderThread = new SongLoaderThread(location, bot);
bot.chat().tellraw(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.GOLD)));
bot.chat().tellraw(
Component
.translatable(
"Loading %s",
Component.text(location.toString(), ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
)
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
_loaderThread.start();
loaderThread = _loaderThread;
} catch (SongLoaderException e) {
@ -95,7 +110,12 @@ public class MusicPlayerPlugin extends Bot.Listener {
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
} else {
songQueue.add(loaderThread.song);
bot.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.GOLD)));
bot.chat().tellraw(
Component.translatable(
"Added %s to the song queue",
Component.empty().append(loaderThread.song.name).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
}
loaderThread = null;
}
@ -106,7 +126,12 @@ public class MusicPlayerPlugin extends Bot.Listener {
addBossBar();
currentSong = songQueue.get(0); // songQueue.poll();
bot.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
bot.chat().tellraw(
Component.translatable(
"Now playing %s",
Component.empty().append(currentSong.name).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
currentSong.play();
}
@ -135,7 +160,12 @@ public class MusicPlayerPlugin extends Bot.Listener {
return;
}
bot.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
bot.chat().tellraw(
Component.translatable(
"Finished playing %s",
Component.empty().append(currentSong.name).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
if (loop == Loop.ALL) {
skip();
@ -147,7 +177,11 @@ public class MusicPlayerPlugin extends Bot.Listener {
if (songQueue.size() == 0) {
stopPlaying();
removeBossBar();
bot.chat().tellraw(Component.text("Finished playing every song in the queue"));
bot.chat().tellraw(
Component
.text("Finished playing every song in the queue")
.color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
return;
}
if (currentSong.size() > 0) {

View file

@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -28,7 +29,7 @@ public class TrustedPlugin extends PlayersPlugin.Listener {
final Component component = Component.translatable(
"[%s] [%s] %s",
Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW),
Component.text("ChomeNS Bot").color(ColorUtilities.getColorByString(bot.config().colorPalette().primary())),
Component.text(this.bot.options().serverName()).color(NamedTextColor.GRAY),
message.color(NamedTextColor.WHITE)
).color(NamedTextColor.DARK_GRAY);
@ -60,7 +61,7 @@ public class TrustedPlugin extends PlayersPlugin.Listener {
bot.chat().tellraw(
Component.empty()
.append(Component.text("Hello, ").color(NamedTextColor.GREEN))
.append(Component.text(target.profile().getName()).color(NamedTextColor.GOLD))
.append(Component.text(target.profile().getName()).color(ColorUtilities.getColorByString(bot.config().colorPalette().username())))
.append(Component.text("!").color(NamedTextColor.GREEN)),
target.profile().getId()
);
@ -81,8 +82,8 @@ public class TrustedPlugin extends PlayersPlugin.Listener {
broadcast(
Component.translatable(
"Trusted player %s is now offline",
Component.text(target.profile().getName()).color(NamedTextColor.GREEN)
)
Component.text(target.profile().getName()).color(ColorUtilities.getColorByString(bot.config().colorPalette().username()))
).color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()))
);
}
}

View file

@ -1,9 +1,39 @@
package land.chipmunk.chayapak.chomens_bot.util;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import java.awt.*;
// Author: ChatGPT
public class ColorUtilities {
public static TextColor getColorByString (String _color) {
final String color = _color.toLowerCase();
if (color.startsWith("#")) return TextColor.fromHexString(color);
else {
// am i reinventing the wheel here?
return switch (color) {
case "black" -> NamedTextColor.BLACK;
case "dark_blue" -> NamedTextColor.DARK_BLUE;
case "dark_green" -> NamedTextColor.DARK_GREEN;
case "dark_aqua" -> NamedTextColor.DARK_AQUA;
case "dark_red" -> NamedTextColor.DARK_RED;
case "dark_purple" -> NamedTextColor.DARK_PURPLE;
case "gold" -> NamedTextColor.GOLD;
case "gray" -> NamedTextColor.GRAY;
case "dark_gray" -> NamedTextColor.DARK_GRAY;
case "blue" -> NamedTextColor.BLUE;
case "green" -> NamedTextColor.GREEN;
case "aqua" -> NamedTextColor.AQUA;
case "red" -> NamedTextColor.RED;
case "light_purple" -> NamedTextColor.LIGHT_PURPLE;
case "yellow" -> NamedTextColor.YELLOW;
default -> NamedTextColor.WHITE;
};
}
}
// Author: ChatGPT
public static int hsvToRgb (int hue, int saturation, int value) {
Color color = Color.getHSBColor(hue / 360.0f, saturation / 100.0f, value / 100.0f);
return color.getRGB() & 0xFFFFFF;

View file

@ -24,6 +24,16 @@ discord:
servers:
localhost:25565: 'channel id'
colorPalette:
primary: 'yellow'
secondary: 'gold'
defaultColor: 'white' # ig java has the `default` keyword so i need to use defaultColor
username: 'gold'
uuid: 'aqua'
string: 'aqua'
number: 'gold'
ownerName: 'green'
ownerName: 'chayapak' # currently this is only used in the console
trusted: