mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +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
@@ -5,10 +5,19 @@ import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public interface CarbonChat {
|
||||
|
||||
LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder()
|
||||
.extractUrls()
|
||||
.hexColors()
|
||||
.character('§')
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
|
||||
@NonNull UserService userService();
|
||||
|
||||
@NonNull MessageProcessor messageProcessor();
|
||||
|
||||
@@ -79,4 +79,5 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
public void message(@NonNull final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,4 +45,5 @@ public class ReceiverContextEvent implements CarbonEvent, Cancellable {
|
||||
public @NonNull ChatUser recipient() {
|
||||
return this.recipient;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.draycia.carbon.api.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.event.Cancellable;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class UserEvent implements CarbonEvent, Cancellable {
|
||||
|
||||
private final @NonNull ChatUser user;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public UserEvent(final @NonNull ChatUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public ChatUser user() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public static class Join extends UserEvent {
|
||||
public Join(final @NonNull ChatUser user) {
|
||||
super(user);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Leave extends UserEvent {
|
||||
public Leave(final @NonNull ChatUser user) {
|
||||
super(user);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,23 +18,22 @@ import net.draycia.carbon.listeners.contexts.TownyContext;
|
||||
import net.draycia.carbon.listeners.contexts.WorldGuardContext;
|
||||
import net.draycia.carbon.listeners.contexts.mcMMOContext;
|
||||
import net.draycia.carbon.listeners.events.BukkitChatListener;
|
||||
import net.draycia.carbon.listeners.events.CapsHandler;
|
||||
import net.draycia.carbon.listeners.events.CustomPlaceholderHandler;
|
||||
import net.draycia.carbon.listeners.events.IgnoredPlayerHandler;
|
||||
import net.draycia.carbon.common.listeners.events.CapsHandler;
|
||||
import net.draycia.carbon.common.listeners.events.CustomPlaceholderHandler;
|
||||
import net.draycia.carbon.common.listeners.events.IgnoredPlayerHandler;
|
||||
import net.draycia.carbon.listeners.events.ItemLinkHandler;
|
||||
import net.draycia.carbon.listeners.events.LegacyFormatHandler;
|
||||
import net.draycia.carbon.listeners.events.MuteHandler;
|
||||
import net.draycia.carbon.listeners.events.OfflineNameHandler;
|
||||
import net.draycia.carbon.listeners.events.PingHandler;
|
||||
import net.draycia.carbon.common.listeners.events.LegacyFormatHandler;
|
||||
import net.draycia.carbon.common.listeners.events.MuteHandler;
|
||||
import net.draycia.carbon.common.listeners.events.PingHandler;
|
||||
import net.draycia.carbon.listeners.events.PlaceholderHandler;
|
||||
import net.draycia.carbon.listeners.events.PlayerJoinListener;
|
||||
import net.draycia.carbon.common.listeners.events.PlayerJoinListener;
|
||||
import net.draycia.carbon.listeners.events.RelationalPlaceholderHandler;
|
||||
import net.draycia.carbon.listeners.events.ShadowMuteHandler;
|
||||
import net.draycia.carbon.listeners.events.UrlLinkHandler;
|
||||
import net.draycia.carbon.listeners.events.UserFormattingHandler;
|
||||
import net.draycia.carbon.listeners.events.WhisperPingHandler;
|
||||
import net.draycia.carbon.common.listeners.events.ShadowMuteHandler;
|
||||
import net.draycia.carbon.common.listeners.events.UrlLinkHandler;
|
||||
import net.draycia.carbon.common.listeners.events.UserFormattingHandler;
|
||||
import net.draycia.carbon.common.listeners.events.WhisperPingHandler;
|
||||
import net.draycia.carbon.common.adventure.AdventureManager;
|
||||
import net.draycia.carbon.managers.CommandManager;
|
||||
import net.draycia.carbon.common.commands.misc.CommandRegistrar;
|
||||
import net.draycia.carbon.common.messaging.MessageManager;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.draycia.carbon.storage.impl.JSONUserService;
|
||||
@@ -65,8 +64,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
private Permission permission;
|
||||
|
||||
private CommandManager commandManager;
|
||||
|
||||
private ChannelRegistry channelRegistry;
|
||||
private CommandSettingsRegistry commandSettings;
|
||||
private AdventureManager messageProcessor;
|
||||
@@ -118,7 +115,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
// Initialize managers
|
||||
this.channelRegistry = new ChannelRegistry();
|
||||
this.messageManager = new MessageManager(this, new EmptyMessageService()); // TODO: get message service from config
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
final String storageType = this.getConfig().getString("storage.type");
|
||||
|
||||
@@ -154,21 +150,21 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
// Register chat listeners
|
||||
pluginManager.registerEvents(new BukkitChatListener(this), this);
|
||||
new CapsHandler(this);
|
||||
new CustomPlaceholderHandler(this);
|
||||
|
||||
new CapsHandler();
|
||||
new CustomPlaceholderHandler();
|
||||
new IgnoredPlayerHandler();
|
||||
new ItemLinkHandler();
|
||||
new LegacyFormatHandler();
|
||||
new MuteHandler();
|
||||
new OfflineNameHandler();
|
||||
new PingHandler(this);
|
||||
new PingHandler();
|
||||
new PlaceholderHandler();
|
||||
pluginManager.registerEvents(new PlayerJoinListener(this), this);
|
||||
new PlayerJoinListener();
|
||||
new RelationalPlaceholderHandler();
|
||||
new ShadowMuteHandler(this);
|
||||
new ShadowMuteHandler();
|
||||
new UrlLinkHandler();
|
||||
new UserFormattingHandler();
|
||||
new WhisperPingHandler(this);
|
||||
new WhisperPingHandler();
|
||||
}
|
||||
|
||||
private void setupCommands() {
|
||||
@@ -184,7 +180,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
CommandRegistrar.registerCommands(manager);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -259,8 +255,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CommandManager commandManager() {
|
||||
return this.commandManager;
|
||||
public CommandRegistrar commandManager() {
|
||||
return this.commandRegistrar;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class OfflineNameHandler {
|
||||
|
||||
public OfflineNameHandler() {
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.LATE, false, event -> {
|
||||
// If the player isn't online (cross server message), use their normal name
|
||||
if (Bukkit.getOfflinePlayer(event.user().uuid()) == null) {
|
||||
event.format(event.format().replace("%player_displayname%", "%player_name%"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public PlayerJoinListener(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
||||
|
||||
this.carbonChat.userService().validate(user);
|
||||
|
||||
if (user.nickname() != null) {
|
||||
user.nickname(user.nickname());
|
||||
}
|
||||
|
||||
final String channel = this.carbonChat.getConfig().getString("channel-on-join");
|
||||
|
||||
if (channel == null || channel.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel.equals("DEFAULT")) {
|
||||
user.selectedChannel(this.carbonChat.channelRegistry().defaultChannel());
|
||||
return;
|
||||
}
|
||||
|
||||
final ChatChannel chatChannel = this.carbonChat.channelRegistry().get(channel);
|
||||
|
||||
if (chatChannel != null) {
|
||||
user.selectedChannel(chatChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(event.getPlayer().getUniqueId());
|
||||
|
||||
if (user != null) {
|
||||
this.carbonChat.userService().invalidate(user);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package net.draycia.carbon.managers;
|
||||
|
||||
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.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.common.commands.ShadowMuteCommand;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public CommandManager(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
this.reloadCommands();
|
||||
}
|
||||
|
||||
private void reloadCommands() {
|
||||
new ChannelCommand(this.carbonChat, this.commandSettings("channel"));
|
||||
new ChannelListCommand(this.carbonChat, this.commandSettings("channellist"));
|
||||
new ChatReloadCommand(this.carbonChat, this.commandSettings("chatreload"));
|
||||
new ClearChatCommand(this.carbonChat, this.commandSettings("clearchat"));
|
||||
new IgnoreCommand(this.carbonChat, this.commandSettings("ignore"));
|
||||
new MeCommand(this.carbonChat, this.commandSettings("me"));
|
||||
new MessageCommand(this.carbonChat, this.commandSettings("message"));
|
||||
new MuteCommand(this.carbonChat, this.commandSettings("mute"));
|
||||
new NicknameCommand(this.carbonChat, this.commandSettings("nickname"));
|
||||
new ReplyCommand(this.carbonChat, this.commandSettings("reply"));
|
||||
new SetColorCommand(this.carbonChat, this.commandSettings("setcolor"));
|
||||
new ShadowMuteCommand(this.carbonChat, this.commandSettings("shadowmute"));
|
||||
new SpyChannelCommand(this.carbonChat, this.commandSettings("spy"));
|
||||
new SudoChannelCommand(this.carbonChat, this.commandSettings("sudochannel"));
|
||||
new ToggleCommand(this.carbonChat, this.commandSettings("toggle"));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CommandSettings commandSettings(@NonNull final String command) {
|
||||
return this.carbonChat.commandSettingsRegistry().get(command);
|
||||
}
|
||||
|
||||
}
|
||||
+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);
|
||||
}
|
||||
|
||||
}
|
||||
+6
-4
@@ -1,14 +1,16 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CapsHandler {
|
||||
|
||||
public CapsHandler(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public CapsHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (!carbonChat.moderationConfig().getBoolean("caps-protection.enabled")) {
|
||||
return;
|
||||
+6
-5
@@ -1,15 +1,16 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CustomPlaceholderHandler {
|
||||
|
||||
public CustomPlaceholderHandler(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public CustomPlaceholderHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
final ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
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.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PrivateMessageEvent;
|
||||
+7
-10
@@ -1,17 +1,18 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class PingHandler {
|
||||
|
||||
public PingHandler(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public PingHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
|
||||
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
|
||||
return;
|
||||
@@ -21,14 +22,10 @@ public class PingHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
final String targetName = Bukkit.getOfflinePlayer(event.target().uuid()).getName();
|
||||
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 (targetName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (caseSensitive) {
|
||||
if (!event.originalMessage().contains(prefix + targetName)) {
|
||||
return;
|
||||
+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());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+6
-4
@@ -1,15 +1,17 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ShadowMuteHandler {
|
||||
|
||||
public ShadowMuteHandler(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
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);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
@@ -20,7 +20,7 @@ public class UserFormattingHandler {
|
||||
this.suppressFormatting(event);
|
||||
} else {
|
||||
// Swap the &-style codes for minimessage-compatible strings
|
||||
event.message(MiniMessage.get().serialize(CarbonChatBukkit.LEGACY.deserialize(event.message())));
|
||||
event.message(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.message())));
|
||||
}
|
||||
});
|
||||
}
|
||||
+6
-8
@@ -1,26 +1,24 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
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;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class WhisperPingHandler {
|
||||
|
||||
public WhisperPingHandler(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public WhisperPingHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PrivateMessageEvent.class, PostOrders.LAST, false, event -> {
|
||||
if (event.sender().uuid().equals(event.target().uuid())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String senderName = Bukkit.getOfflinePlayer(event.sender().uuid()).getName();
|
||||
|
||||
if (senderName == null || !event.message().contains(senderName)) {
|
||||
if (!event.message().contains(event.sender().name())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user