mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
Allow changing color palette in config & change colors
This commit is contained in:
@@ -10,12 +10,12 @@ import de.shiewk.smoderation.paper.punishments.Kick;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.translation.TranslatorManager;
|
||||
import de.shiewk.smoderation.paper.util.ColorPalette;
|
||||
import de.shiewk.smoderation.paper.util.SModLegacy;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -42,14 +42,11 @@ import static org.bukkit.Bukkit.getPluginManager;
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
||||
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
||||
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
||||
|
||||
public static final Gson gson = new Gson();
|
||||
public static ComponentLogger LOGGER = null;
|
||||
public static SModerationPaper PLUGIN = null;
|
||||
private static SkinTextureProvider textureProvider = null;
|
||||
private ColorPalette colors;
|
||||
|
||||
private final TranslatorManager translatorManager = new TranslatorManager(
|
||||
Key.key("smoderation", "translations"),
|
||||
@@ -67,6 +64,10 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
return PLUGIN.getConfig();
|
||||
}
|
||||
|
||||
public static ColorPalette colors() {
|
||||
return PLUGIN.colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
LOGGER = getComponentLogger();
|
||||
@@ -81,6 +82,12 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
this.punishmentManager.registerType("ban", new Ban.Factory());
|
||||
this.punishmentManager.registerType("kick", new Kick.Factory());
|
||||
|
||||
this.colors = new ColorPalette(
|
||||
parseColor(config().getString("colors.primary")),
|
||||
parseColor(config().getString("colors.secondary")),
|
||||
parseColor(config().getString("colors.detail"))
|
||||
);
|
||||
|
||||
SModLegacy.migrateV1PunishmentsFile(
|
||||
this.punishmentManager,
|
||||
getDataPath().resolve("container.gz"),
|
||||
@@ -88,6 +95,17 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
private TextColor parseColor(String string) {
|
||||
if (string == null || string.length() != 7) {
|
||||
throw new IllegalArgumentException("Color not formatted correctly: " + string);
|
||||
}
|
||||
TextColor color = TextColor.fromHexString(string);
|
||||
if (color == null) {
|
||||
throw new IllegalArgumentException("Color not formatted correctly: " + string);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isFeatureEnabled(String feature){
|
||||
return getConfig().getBoolean("features."+feature, true);
|
||||
}
|
||||
@@ -170,8 +188,9 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
private MiniMessage createMiniMessage() {
|
||||
return MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolver(TagResolver.resolver("primary", Tag.styling(style -> style.color(PRIMARY_COLOR))))
|
||||
.resolver(TagResolver.resolver("secondary", Tag.styling(style -> style.color(SECONDARY_COLOR))))
|
||||
.resolver(TagResolver.resolver("primary", Tag.styling(style -> style.color(colors().primary()))))
|
||||
.resolver(TagResolver.resolver("secondary", Tag.styling(style -> style.color(colors().secondary()))))
|
||||
.resolver(TagResolver.resolver("detail", Tag.styling(style -> style.color(colors().detail()))))
|
||||
.resolver(TagResolver.standard())
|
||||
.build()
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.event.VanishToggleEvent;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
@@ -150,11 +151,11 @@ public final class VanishCommand implements CommandProvider {
|
||||
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||
Player vanishedPlayer = iterator.next();
|
||||
vanishList = vanishList.append(
|
||||
vanishedPlayer.teamDisplayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
vanishedPlayer.teamDisplayName().colorIfAbsent(SModerationPaper.colors().secondary())
|
||||
);
|
||||
if (iterator.hasNext()){
|
||||
vanishList = vanishList.append(
|
||||
text().content(", ").color(PRIMARY_COLOR)
|
||||
text().content(", ").color(SModerationPaper.colors().primary())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.shiewk.smoderation.paper.input;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,7 +11,6 @@ import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.PRIMARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ChatInput {
|
||||
|
||||
public static void prompt(Player player, Consumer<Component> consumer, Component prompt, int timeSeconds){
|
||||
runningInputs.put(player, new ChatInput(player, prompt, consumer, timeSeconds));
|
||||
player.sendMessage(prompt.colorIfAbsent(PRIMARY_COLOR));
|
||||
player.sendMessage(prompt.colorIfAbsent(SModerationPaper.colors().primary()));
|
||||
}
|
||||
|
||||
public Component getPrompt() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.SkinTextureProvider;
|
||||
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
@@ -126,7 +127,7 @@ public class SModMenu extends PageableCustomInventory {
|
||||
// chat event is async
|
||||
SchedulerUtil.scheduleForEntity(PLUGIN, player, this::open);
|
||||
}
|
||||
}, translatable("smod.menu.search.query").color(SECONDARY_COLOR), 30);
|
||||
}, translatable("smod.menu.search.query").color(SModerationPaper.colors().secondary()), 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,13 +200,13 @@ public class SModMenu extends PageableCustomInventory {
|
||||
private ItemStack createFilterItem(){
|
||||
final Filter filter = getFilter();
|
||||
final ItemStack stack = new ItemStack(Filter.ICON);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.filter", filter.name).color(PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.filter", filter.name).color(SModerationPaper.colors().primary())));
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
|
||||
loreBuilder.addLine(empty());
|
||||
for (Filter value : Filter.values()) {
|
||||
final boolean selected = filter == value;
|
||||
Component filterText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||
Component filterText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value.name)));
|
||||
loreBuilder.addLine(filterText);
|
||||
}
|
||||
loreBuilder.addLine(empty());
|
||||
@@ -218,13 +219,13 @@ public class SModMenu extends PageableCustomInventory {
|
||||
private ItemStack createTypeItem(){
|
||||
final String type = getType();
|
||||
final ItemStack stack = new ItemStack(Material.CHEST);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + type)))).color(PRIMARY_COLOR));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + type)))).color(SModerationPaper.colors().primary()));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLine(empty());
|
||||
final Consumer<String> addToLore = value -> {
|
||||
final boolean selected = Objects.equals(type, value);
|
||||
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + value))));
|
||||
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + value))));
|
||||
loreBuilder.addLine(typeText);
|
||||
};
|
||||
addToLore.accept(null);
|
||||
@@ -242,14 +243,14 @@ public class SModMenu extends PageableCustomInventory {
|
||||
private ItemStack createSortItem(){
|
||||
final Sort sort = getSort();
|
||||
final ItemStack stack = new ItemStack(Sort.ICON);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.sort", sort.name).color(PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.sort", sort.name).color(SModerationPaper.colors().primary())));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLine(empty());
|
||||
|
||||
for (Sort value : Sort.values()) {
|
||||
final boolean selected = sort == value;
|
||||
Component sortText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||
Component sortText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value.name)));
|
||||
loreBuilder.addLine(sortText);
|
||||
}
|
||||
|
||||
@@ -270,12 +271,12 @@ public class SModMenu extends PageableCustomInventory {
|
||||
// we just create the stack without it instead of throwing
|
||||
}
|
||||
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.search", PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.search", SModerationPaper.colors().primary())));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLines(List.of(
|
||||
empty(),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.current", searchQuery == null ? translatable("smod.menu.search.none") : text('"' + searchQuery + '"'))).color(SECONDARY_COLOR)),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.current", searchQuery == null ? translatable("smod.menu.search.none") : text('"' + searchQuery + '"'))).color(SModerationPaper.colors().secondary())),
|
||||
empty(),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.new", NamedTextColor.GOLD)))
|
||||
));
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.PRIMARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class PunishmentListener implements Listener {
|
||||
@@ -41,7 +40,7 @@ public class PunishmentListener implements Listener {
|
||||
List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
|
||||
if (!list.isEmpty()) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(list.getFirst().infoMessage().colorIfAbsent(PRIMARY_COLOR));
|
||||
player.sendMessage(list.getFirst().infoMessage().colorIfAbsent(SModerationPaper.colors().primary()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ public class PunishmentListener implements Listener {
|
||||
|| message.toLowerCase().startsWith(str.toLowerCase()+" ")
|
||||
)){
|
||||
Bukkit.getConsoleSender().sendMessage(player.getName() + " tried to run forbidden command while muted");
|
||||
player.sendMessage(translatable("smod.punishment.playerMessage.mute.chat", PRIMARY_COLOR));
|
||||
player.sendMessage(translatable("smod.punishment.playerMessage.mute.chat", SModerationPaper.colors().primary()));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,12 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.SECONDARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class VanishListener implements Listener {
|
||||
|
||||
public static final Component PREFIX = text("[VANISH] ").color(SECONDARY_COLOR);
|
||||
public static final Component PREFIX = text("[VANISH] ").color(SModerationPaper.colors().secondary());
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public record ColorPalette(TextColor primary, TextColor secondary, TextColor detail) {
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ default-reason: No reason provided.
|
||||
features:
|
||||
# Should punishments be tracked and executed?
|
||||
# Note that disabling this will also disable the SMod menu and
|
||||
# /modlogs command since their only use is viewing punishments
|
||||
# /modlogs command since their only use is viewing punishments.
|
||||
punishments: true
|
||||
# Should commands for opening the SMod menu be registered?
|
||||
smodmenu: true
|
||||
@@ -24,6 +24,13 @@ features:
|
||||
# Should players be able to enable vanish mode?
|
||||
vanish: true
|
||||
|
||||
# Allows you to customize plugin colors.
|
||||
# Colors have to be formatted #rrggbb.
|
||||
colors:
|
||||
primary: '#e26c04'
|
||||
secondary: '#fc9e07'
|
||||
detail: '#ababab'
|
||||
|
||||
# A list of commands which will be captured and broadcast
|
||||
# to players which have SocialSpy enabled (/socialspy).
|
||||
socialspy-commands:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"smod.argument.duration.fail.pattern": "Bitte gib eine gültige Zeit an, z.B. '1d6h30min'",
|
||||
"smod.argument.offlinePlayer.fail.notCached": "Die Daten des Spielers sind nicht gespeichert.",
|
||||
"smod.argument.uuid.fail.notCached": "Die Daten des Spielers sind nicht gespeichert. Versuche, stattdessen seine UUID anzugeben.",
|
||||
"smod.chatInput.remainingTime": "<gray><arg:0> Sekunden",
|
||||
"smod.chatInput.remainingTime": "<detail><arg:0> Sekunden",
|
||||
"smod.command.ban.fail.alreadyBanned": "Dieser Spieler ist schon gebannt.",
|
||||
"smod.command.ban.fail.forceReason": "Bitte gib einen Grund an.",
|
||||
"smod.command.ban.fail.protect": "Dieser Spieler kann nicht gebannt werden.",
|
||||
@@ -18,10 +18,10 @@
|
||||
"smod.command.kick.fail.forceReason": "Bitte gib einen Grund an.",
|
||||
"smod.command.kick.fail.protect": "Dieser Spieler kann nicht gekickt werden.",
|
||||
"smod.command.kick.fail.self": "Du kannst dich nicht selbst kicken.",
|
||||
"smod.command.modlogs.ban": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> gebannt. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban": "<primary>- ist bis <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail> gebannt. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban.permanent": "<primary>- ist <secondary>permanent</secondary> gebannt. Grund: <secondary><arg:0>",
|
||||
"smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <gray>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> stummgeschaltet. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <detail>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail> stummgeschaltet. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.mute.permanent": "<primary>- ist <secondary>permanent</secondary> stummgeschaltet. Grund: <secondary><arg:0>",
|
||||
"smod.command.modlogs.none": "<primary>- ist momentan nicht gebannt oder stummgeschaltet.",
|
||||
"smod.command.mute.fail.alreadyMuted": "Dieser Spieler ist schon stummgeschaltet.",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'",
|
||||
"smod.argument.offlinePlayer.fail.notCached": "That player's data is not saved.",
|
||||
"smod.argument.uuid.fail.notCached": "That player's data is not saved. Try providing an UUID instead.",
|
||||
"smod.chatInput.remainingTime": "<gray><arg:0> seconds",
|
||||
"smod.chatInput.remainingTime": "<detail><arg:0> seconds",
|
||||
"smod.command.ban.fail.alreadyBanned": "This player is already banned.",
|
||||
"smod.command.ban.fail.forceReason": "Please provide a reason.",
|
||||
"smod.command.ban.fail.protect": "This player can't be banned.",
|
||||
@@ -18,10 +18,10 @@
|
||||
"smod.command.kick.fail.forceReason": "Please provide a reason.",
|
||||
"smod.command.kick.fail.protect": "This player can't be kicked.",
|
||||
"smod.command.kick.fail.self": "You can't kick yourself.",
|
||||
"smod.command.modlogs.ban": "<primary>- is banned until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban": "<primary>- is banned until <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban.permanent": "<primary>- is banned <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||
"smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <gray>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <detail>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.mute.permanent": "<primary>- is muted <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||
"smod.command.modlogs.none": "<primary>- is not currently muted or banned.",
|
||||
"smod.command.mute.fail.alreadyMuted": "This player is already muted.",
|
||||
|
||||
Reference in New Issue
Block a user