mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Move more things to common
This commit is contained in:
1 parent
16d3589773
commit
74ebee707c
35 files changed
+264
-214
No files matched your search
+4
-1
@@ -4,6 +4,7 @@ import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
@@ -18,9 +19,11 @@ public class ChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ChannelCommand(final @NonNull CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("channel");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -23,9 +23,11 @@ public class ChannelListCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ChannelListCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("channellist");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-1
@@ -3,6 +3,7 @@ package net.draycia.carbon.common.commands;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
@@ -15,9 +16,11 @@ public class ChatReloadCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ChatReloadCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("chatreload");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-1
@@ -3,6 +3,7 @@ package net.draycia.carbon.common.commands;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
@@ -15,9 +16,11 @@ public class ClearChatCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ClearChatCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("clearchat");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,9 +16,11 @@ public class IgnoreCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public IgnoreCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("ignore");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,11 @@ public class MeCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public MeCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("me");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+6
-1
@@ -4,6 +4,8 @@ import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
@@ -11,7 +13,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
public MessageCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public MessageCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
final CommandSettings commandSettings = carbonChat.commandSettingsRegistry().get("message");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@ public class MuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public MuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("mute");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,9 +16,11 @@ public class NicknameCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public NicknameCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("nickname");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -24,9 +24,11 @@ public class ReplyCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ReplyCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("reply");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@ package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
@@ -25,9 +26,11 @@ public class SetColorCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public SetColorCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("setcolor");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@ package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
@@ -28,9 +29,11 @@ public class ShadowMuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("shadowmute");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -27,9 +27,11 @@ public class SpyChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public SpyChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("spy");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -29,9 +29,11 @@ public class SudoChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public SudoChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("sudochannel");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -29,9 +29,11 @@ public class ToggleCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
public ToggleCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("toggle");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package net.draycia.carbon.common.commands.misc;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.commands.ChannelCommand;
|
||||
import net.draycia.carbon.common.commands.ChannelListCommand;
|
||||
import net.draycia.carbon.common.commands.ChatReloadCommand;
|
||||
import net.draycia.carbon.common.commands.ClearChatCommand;
|
||||
import net.draycia.carbon.common.commands.IgnoreCommand;
|
||||
import net.draycia.carbon.common.commands.MeCommand;
|
||||
import net.draycia.carbon.common.commands.MessageCommand;
|
||||
import net.draycia.carbon.common.commands.MuteCommand;
|
||||
import net.draycia.carbon.common.commands.NicknameCommand;
|
||||
import net.draycia.carbon.common.commands.ReplyCommand;
|
||||
import net.draycia.carbon.common.commands.SetColorCommand;
|
||||
import net.draycia.carbon.common.commands.SpyChannelCommand;
|
||||
import net.draycia.carbon.common.commands.SudoChannelCommand;
|
||||
import net.draycia.carbon.common.commands.ToggleCommand;
|
||||
import net.draycia.carbon.common.commands.ShadowMuteCommand;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CommandRegistrar {
|
||||
|
||||
private CommandRegistrar() {
|
||||
|
||||
}
|
||||
|
||||
public static <Meta extends CommandMeta, Manager extends CommandManager<ChatUser, Meta>> void registerCommands(final @NonNull Manager commandManager) {
|
||||
new ChannelCommand(commandManager);
|
||||
new ChannelListCommand(commandManager);
|
||||
new ChatReloadCommand(commandManager);
|
||||
new ClearChatCommand(commandManager);
|
||||
new IgnoreCommand(commandManager);
|
||||
new MeCommand(commandManager);
|
||||
new MessageCommand(commandManager);
|
||||
new MuteCommand(commandManager);
|
||||
new NicknameCommand(commandManager);
|
||||
new ReplyCommand(commandManager);
|
||||
new SetColorCommand(commandManager);
|
||||
new ShadowMuteCommand(commandManager);
|
||||
new SpyChannelCommand(commandManager);
|
||||
new SudoChannelCommand(commandManager);
|
||||
new ToggleCommand(commandManager);
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class CapsHandler {
|
||||
|
||||
public CapsHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (!carbonChat.moderationConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.message().length() >= carbonChat.moderationConfig().getInt("caps-protection.minimum-length"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amountOfCaps = 0;
|
||||
|
||||
for (final char letter : event.message().toCharArray()) {
|
||||
if (Character.isUpperCase(letter)) {
|
||||
amountOfCaps++;
|
||||
}
|
||||
}
|
||||
|
||||
final double capsPercentage = (amountOfCaps * 100.0) / event.message().length();
|
||||
|
||||
if (!(capsPercentage >= carbonChat.moderationConfig().getDouble("caps-protection.percent-caps"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (carbonChat.moderationConfig().getBoolean("block-message")) {
|
||||
event.cancelled(true);
|
||||
} else {
|
||||
event.message(event.message().toLowerCase());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class CustomPlaceholderHandler {
|
||||
|
||||
public CustomPlaceholderHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
final ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||
|
||||
for (final String key : placeholders.getKeys(false)) {
|
||||
final String value = placeholders.getString(key);
|
||||
|
||||
event.format(event.format().replace("<" + key + ">", value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class IgnoredPlayerHandler {
|
||||
|
||||
public IgnoredPlayerHandler() {
|
||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (event.target() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target().ignoringUser(event.sender())) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LegacyFormatHandler {
|
||||
|
||||
private final @NonNull Pattern pattern =
|
||||
Pattern.compile("[§&]x[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])");
|
||||
|
||||
public LegacyFormatHandler() {
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
// Legacy RGB
|
||||
event.format(this.pattern.matcher(event.format()).replaceAll("<#$1$2$3$4$5$6>"));
|
||||
|
||||
// Legacy Colors
|
||||
for (final char c : "0123456789abcdef".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextColor color = format.color();
|
||||
|
||||
event.format(event.format().replaceAll("[§&]" + c, "<" + color.asHexString() + ">"));
|
||||
}
|
||||
|
||||
// Legacy Formatting
|
||||
for (final char c : "klmno".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextDecoration decoration = format.decoration();
|
||||
|
||||
event.format(event.format().replaceAll("[§&]" + c, "<" + decoration.name() + ">"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PrivateMessageEvent;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
|
||||
public class MuteHandler {
|
||||
|
||||
public MuteHandler() {
|
||||
CarbonEvents.register(PrivateMessageEvent.class, event -> {
|
||||
if (event.sender().muted()) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
if (event.user().muted()) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class PingHandler {
|
||||
|
||||
public PingHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
|
||||
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String targetName = event.target().name();
|
||||
final String prefix = carbonChat.getConfig().getString("pings.prefix", "");
|
||||
final boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
|
||||
|
||||
if (caseSensitive) {
|
||||
if (!event.originalMessage().contains(prefix + targetName)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!event.originalMessage().toLowerCase().contains((prefix + targetName).toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
||||
final Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
||||
final float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
||||
final float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
||||
|
||||
event.target().playSound(Sound.of(key, source, volume, pitch));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.UserEvent;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
|
||||
public class PlayerJoinListener {
|
||||
|
||||
public PlayerJoinListener() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(UserEvent.Join.class, event -> {
|
||||
final ChatUser user = event.user();
|
||||
|
||||
carbonChat.userService().validate(user);
|
||||
|
||||
if (user.nickname() != null) {
|
||||
user.nickname(user.nickname());
|
||||
}
|
||||
|
||||
final String channel = carbonChat.getConfig().getString("channel-on-join");
|
||||
|
||||
if (channel == null || channel.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel.equals("DEFAULT")) {
|
||||
user.selectedChannel(carbonChat.channelRegistry().defaultChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
final ChatChannel chatChannel = carbonChat.channelRegistry().get(channel);
|
||||
|
||||
if (chatChannel != null) {
|
||||
user.selectedChannel(chatChannel);
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(UserEvent.Leave.class, event -> {
|
||||
carbonChat.userService().invalidate(event.user());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class ShadowMuteHandler {
|
||||
|
||||
public ShadowMuteHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (event.sender().shadowMuted() && event.sender().equals(event.target())) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (event.target() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.sender().shadowMuted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String prefix = carbonChat.moderationConfig().getString("shadow-mute-prefix", "[SM] ");
|
||||
|
||||
event.format(prefix + event.format());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class UrlLinkHandler {
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
|
||||
public UrlLinkHandler() {
|
||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.NORMAL, true, event -> {
|
||||
final TextComponent newComponent = (TextComponent) event.component()
|
||||
.replaceText(URL_PATTERN, url -> url.clickEvent(ClickEvent.openUrl(url.content())));
|
||||
|
||||
event.component(newComponent);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class UserFormattingHandler {
|
||||
|
||||
public UserFormattingHandler() {
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (!event.user().permissible()) {
|
||||
this.suppressFormatting(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.user().hasPermission("carbonchat.formatting") &&
|
||||
!event.user().hasPermission("carbonchat.channels." + event.channel().key() + ".formatting")) {
|
||||
this.suppressFormatting(event);
|
||||
} else {
|
||||
// Swap the &-style codes for minimessage-compatible strings
|
||||
event.message(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.message())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void suppressFormatting(final PreChatFormatEvent event) {
|
||||
event.format(event.format().replace("<message>", "<pre><message></pre>"));
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PrivateMessageEvent;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class WhisperPingHandler {
|
||||
|
||||
public WhisperPingHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PrivateMessageEvent.class, PostOrders.LAST, false, event -> {
|
||||
if (event.sender().uuid().equals(event.target().uuid())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.message().contains(event.sender().name())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!carbonChat.getConfig().getBoolean("whisper.pings.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Key key = Key.of(carbonChat.getConfig().getString("whisper.pings.sound"));
|
||||
final Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("whisper.pings.source"));
|
||||
final float volume = (float) carbonChat.getConfig().getDouble("whisper.pings.volume");
|
||||
final float pitch = (float) carbonChat.getConfig().getDouble("whisper.pings.pitch");
|
||||
|
||||
event.sender().playSound(Sound.of(key, source, volume, pitch));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user