### Basic Player Channel Permissions Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Example configuration for a basic player granting read and write access to global and local channels. ```yaml permissions: chatcontrol.channel.read.global: default: true chatcontrol.channel.write.global: default: true chatcontrol.channel.read.local: default: true chatcontrol.channel.write.local: default: true ``` -------------------------------- ### Example Channel Configuration Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Defines various chat channels with specific formatting, range, and integration settings. Includes global, staff, and faction chat examples. ```yaml Channels: List: # Global chat channel global: Format: "&7[&fGLOBAL&7] {player}&7: {message}" Format_Console: "[GLOBAL] {player}: {message}" Range: "*" Range_Worlds: - world - world_nether Min_Players_For_Range: 20 Message_Delay: "3 seconds" Discord_Channel_Id: 123456789 Sound: Type: ENTITY_EXPERIENCE_ORB_PICKUP Volume: 1.0 Pitch: 1.0 # Staff-only channel staff: Format: "&c[&4STAFF&c] {player}&7: {message}" Format_Console: "[STAFF] {player}: {message}" Message_Delay: "1 second" Discord_Channel_Id: 987654321 Cancel_Event: true # Faction chat faction: Format: "&5[&dFACTION&5] {player}&7: {message}" Party: "factions-faction" Range: "300" Proxy: true ``` -------------------------------- ### Staff Member Permissions Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Example YAML configuration for staff member permissions, including channel access and bypass options. ```yaml permissions: chatcontrol.channel.read.staff: default: false chatcontrol.channel.write.staff: default: false chatcontrol.channel.read.global: default: true chatcontrol.channel.write.global: default: true chatcontrol.bypass.antispam: default: false chatcontrol.tag: default: true chatcontrol.tag.colors: default: false ``` -------------------------------- ### Example: First Integration with ChatControl API Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/README.md Demonstrates how to send a message through a specific channel after checking its existence, player cache, and message filters. This is a basic example for integrating ChatControl's core features into a plugin. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.mineacademy.chatcontrol.model.Channel; import org.mineacademy.chatcontrol.model.ChannelMode; public class MyPlugin extends JavaPlugin { public void sendMessage(Player player, String channelName, String message) { // Check if channel exists if (!ChatControlAPI.isChannelInstalled(channelName)) { player.sendMessage("Channel not available"); return; } // Get player cache var cache = ChatControlAPI.getCache(player); // Check message against filters var checker = ChatControlAPI.checkMessage(player, message); if (checker.hasFailed()) { player.sendMessage("Message blocked: " + checker.getFailReason()); return; } // Send through channel ChatControlAPI.sendMessage(player, channelName, message); } } ``` -------------------------------- ### YAML Configuration Example for Permission Groups Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Example YAML snippet showing how to define permission groups (default, moderator, staff, admin) and assign permissions to them, including user-specific overrides. ```yaml # In your permission plugin config groups: default: permissions: - chatcontrol.channel.read.global - chatcontrol.channel.write.global - chatcontrol.channel.read.local - chatcontrol.channel.write.local - chatcontrol.tell - chatcontrol.reply - chatcontrol.mail - chatcontrol.me - chatcontrol.tag - chatcontrol.list - chatcontrol.toggle - chatcontrol.motd moderator: permissions: - chatcontrol.spy - chatcontrol.spy.chat - chatcontrol.spy.command - chatcontrol.spy.private - chatcontrol.mute - chatcontrol.mute.channel - chatcontrol.mute.player - chatcontrol.realname - chatcontrol.admin - chatcontrol.admin.info - chatcontrol.admin.announce staff: permissions: - group.moderator - chatcontrol.channel.read.staff - chatcontrol.channel.write.staff - chatcontrol.bypass.antispam - chatcontrol.tag.colors admin: permissions: - chatcontrol.* users: PlayerName: permissions: - chatcontrol.channel.write.custom - -chatcontrol.channel.read.admin ``` -------------------------------- ### Moderator Permissions Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Example YAML configuration for moderator permissions, granting access to spy, mute, and admin functionalities. ```yaml permissions: chatcontrol.spy: default: op chatcontrol.spy.* default: op chatcontrol.mute.* default: op chatcontrol.channel.admin.* default: op chatcontrol.admin: default: op ``` -------------------------------- ### ChatControl API Usage Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/chatcontrol-api.md Demonstrates common ChatControl API operations including checking if chat is muted, retrieving player cache, checking messages against rules, applying specific rule types, and sending messages to installed channels. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.mineacademy.chatcontrol.model.RuleType; // Check if chat is muted if (ChatControlAPI.isChatMuted()) { player.sendMessage("Chat is currently muted"); return; } // Get player cache PlayerCache cache = ChatControlAPI.getCache(player); // Check message against rules Checker checker = ChatControlAPI.checkMessage(player, message); if (checker.hasFailed()) { player.sendMessage("Your message violates a rule"); return; } // Apply specific rule type RuleCheck ruleCheck = ChatControlAPI.checkRules(RuleType.COMMAND, player, message); if (ruleCheck.isMatched()) { // Rule matched and was applied } // Send message through channel if (ChatControlAPI.isChannelInstalled("staff")) { ChatControlAPI.sendMessage(player, "staff", "Staff message"); } ``` -------------------------------- ### Party Lookup Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/types.md Demonstrates how to look up a party by its key and check if two players are in the same party. ```java Party party = Party.fromKey("towny-town"); if (party.isInParty(receiver, sender)) { // They are in the same town } ``` -------------------------------- ### Channel Operations: Joining and Listing Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Provides examples for joining a specific channel and listing available channels, including permission checks for joining. ```java import org.mineacademy.chatcontrol.model.Channel; import org.mineacademy.chatcontrol.model.ChannelMode; public class ChannelOperations { public void joinChannel(Player player, String channelName) { Channel channel = Channel.findChannel(channelName); if (channel == null) { player.sendMessage("Channel not found!"); return; } if (channel.joinPlayer(player, ChannelMode.WRITE, true)) { player.sendMessage("Joined " + channelName); } else { player.sendMessage("Could not join (event cancelled)"); } } public void listChannels(Player player) { for (Channel ch : Channel.getChannels()) { boolean canJoin = Channel.hasPermission(player, ch, ChannelMode.WRITE); String status = canJoin ? "available" : "locked"; player.sendMessage(ch.getName() + " [" + status + "]"); } } } ``` -------------------------------- ### Channel Write Permission Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows a player to write messages to the specified channel. Use `*` to grant write access to all channels. ```text chatcontrol.channel.write. ``` ```text chatcontrol.channel.write.global chatcontrol.channel.write.local chatcontrol.channel.write.* # Write to all channels ``` -------------------------------- ### Channel Read Permission Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows a player to read messages in the specified channel. Use `*` to grant read access to all channels. ```text chatcontrol.channel.read. ``` ```text chatcontrol.channel.read.staff chatcontrol.channel.read.global chatcontrol.channel.read.* # Read all channels ``` -------------------------------- ### Basic ChatControl API Usage Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Demonstrates how to check if a channel is installed and send a message to it. Ensure the ChatControlAPI and model classes are imported. ```java // Import the main API import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.mineacademy.chatcontrol.model.*; // Basic usage if (ChatControlAPI.isChannelInstalled("staff")) { ChatControlAPI.sendMessage(player, "staff", "Message"); } ``` -------------------------------- ### Event Registration Example Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/events.md Demonstrates how to register a listener for ChatControl events in a Bukkit plugin. Ensure you register your listener in the plugin's onEnable() method. ```java import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.mineacademy.chatcontrol.api.ChannelPreChatEvent; public class MyListener implements Listener { @EventHandler public void onChannelChat(ChannelPreChatEvent event) { // Handle event } } // In your plugin's onEnable(): getServer().getPluginManager().registerEvents(new MyListener(), this); ``` -------------------------------- ### PlayerCache.getAllChannels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Gets all channels the player is in with their respective modes. ```APIDOC ## PlayerCache.getAllChannels ### Description Gets all channels the player is in with their respective modes. ### Method ```java public Map getAllChannels() ``` ### Response #### Success Response - **Returns** (Map) - channels mapped to modes ### Example ```java Map channels = cache.getAllChannels(); for (Map.Entry entry : channels.entrySet()) { player.sendMessage(entry.getKey().getName() + " (" + entry.getValue() + ")"); } ``` ``` -------------------------------- ### Get Joinable Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves a list of all channels that a player is permitted to join. ```java public static List getChannelsWithJoinPermission(final Player player) ``` -------------------------------- ### ChatControl Event Handling Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Provides an example of how to listen for and handle the ChannelPreChatEvent in ChatControl. This allows for custom logic before a message is processed. ```java // Listen to events @EventHandler public void onChat(ChannelPreChatEvent event) { // Handle chat event } ``` -------------------------------- ### Check if Channel is Installed Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/chatcontrol-api.md Verifies if a specified channel exists and is loaded within ChatControl's configuration. Use this before attempting to send messages to a channel. ```java public static boolean isChannelInstalled(final String channelName) ``` -------------------------------- ### Get All Channel Names Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves a list containing the names of all loaded channels. ```java public static List getChannelNames() ``` -------------------------------- ### Get Server Settings Instance Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Access server settings like mute status and mute duration by obtaining the ServerSettings instance. ```java ServerSettings settings = ServerSettings.getInstance(); boolean muted = settings.isMuted(); SimpleTime muteDuration = settings.getMuteDuration(); ``` -------------------------------- ### Best Practices for API Usage Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Illustrates best practices for using the ChatControl API, including validating before calls, getting player cache for online players, and handling potential event cancellations. ```java // Always validate before API calls if (ChatControlAPI.isChannelInstalled("target")) { ChatControlAPI.sendMessage(sender, "target", message); } // Get cache only for online players if (player.isOnline()) { PlayerCache cache = ChatControlAPI.getCache(player); } // Handle events appropriately try { channel.sendMessage(player, message); } catch (EventHandledException e) { // Event was cancelled by listeners } ``` -------------------------------- ### Handle Newcomers Using ChatControlAPI Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Detect newcomers using ChatControlAPI.isNewcomer and apply special handling, such as showing a welcome guide or restricting channel access. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; public class NewcomerHandler { public void onPlayerJoin(Player player) { if (ChatControlAPI.isNewcomer(player)) { // Show newcomer guide showWelcomeGuide(player); // Restrict to certain channels Channel globalChannel = Channel.findChannel("global"); if (globalChannel != null && !globalChannel.isInChannel(player)) { globalChannel.joinPlayer(player, ChannelMode.READ, true); } } } private void showWelcomeGuide(Player player) { player.sendMessage("&aWelcome! You're a new player on this server."); player.sendMessage("&aType /help for commands."); } } ``` -------------------------------- ### Handling MuteEvent Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/events.md An example of how to handle the MuteEvent in a Bukkit plugin, checking the type of mute that occurred. ```java @EventHandler public void onMute(MuteEvent event) { if (event.getTargetChannel() != null) { // Channel was muted } else if (event.getTargetPlayerName() != null) { // Player was muted } else { // Server was muted } } ``` -------------------------------- ### Get Player's Joinable and Leavable Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieve lists of channels a player can join or leave based on their permissions. Useful for displaying available channels to the player. ```java // Get all channels player can join List joinable = Channel.getChannelsWithJoinPermission(player); for (Channel ch : joinable) { player.sendMessage("You can join: " + ch.getName()); } // Get all channels player can leave List leavable = Channel.getChannelsWithLeavePermission(player); ``` -------------------------------- ### Get All Channels and Modes Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Retrieves a map of all channels the player is currently in, along with their respective modes (WRITE or READ). ```Java public Map getAllChannels() ``` ```Java Map channels = cache.getAllChannels(); for (Map.Entry entry : channels.entrySet()) { player.sendMessage(entry.getKey().getName() + " (" + entry.getValue() + ")"); } ``` -------------------------------- ### Direct Player Permission Checks Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Examples of checking specific ChatControl permissions directly on a player object, including wildcard and admin checks. ```java // Check permission directly if (player.hasPermission("chatcontrol.channel.write.staff")) { // Player can write to staff channel } // Check wildcard if (player.hasPermission("chatcontrol.channel.write.*")) { // Player can write to all channels } // Check admin if (player.hasPermission("chatcontrol.admin")) { // Player is admin } ``` -------------------------------- ### Getting Player's Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves lists of channels that a player can join or leave based on their permissions. ```APIDOC ## Getting Player's Channels ### Description Retrieves lists of channels that a player can join or leave based on their permissions. ### Methods - **getChannelsWithJoinPermission(Player player)**: Returns a list of channels the player can join. - **getChannelsWithLeavePermission(Player player)**: Returns a list of channels the player can leave. ### Example Usage ```java // Get all channels player can join List joinable = Channel.getChannelsWithJoinPermission(player); for (Channel ch : joinable) { // Process joinable channel } // Get all channels player can leave List leavable = Channel.getChannelsWithLeavePermission(player); ``` ``` -------------------------------- ### Testing ChatControl Integration with Mockito Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Shows how to write unit tests for your ChatControl integration using Mockito to mock `Player` objects and verify interactions. This example tests message filtering and channel existence checks. ```java import org.junit.Test; import org.bukkit.entity.Player; import static org.mockito.Mockito.*; public class ChatControlIntegrationTest { @Test public void testMessageFiltering() { Player player = mock(Player.class); when(player.isOnline()).thenReturn(true); // Test message filtering MessageFilter filter = new MessageFilter(); boolean result = filter.filterMessage(player, "Hello"); assertTrue(result); } @Test public void testChannelExists() { // Test channel detection boolean exists = ChatControlAPI.isChannelInstalled("global"); assertTrue("Global channel should exist", exists); } } ``` -------------------------------- ### Get Channel by Name (with Exception) Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves a channel by its name, throwing an IllegalArgumentException if the channel is not found. ```java public static Channel fromString(final String name) ``` -------------------------------- ### Get All Players and Their Modes in Channel Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves a map of all players currently in the channel, along with their respective modes. ```java public Map getOnlinePlayers() ``` -------------------------------- ### Optimized Message Checking Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Illustrates the efficient way to check messages by performing the check once and caching the result. Avoid repeatedly checking the same message, as shown in the 'AVOID' example. ```java // GOOD - Check once and cache result Checker checker = ChatControlAPI.checkMessage(player, message); if (checker.hasFailed()) { // Handle failure } // AVOID - Checking the same message multiple times for (int i = 0; i < 100; i++) { ChatControlAPI.checkMessage(player, message); // Wasteful! } ``` -------------------------------- ### Get Players in Channel by Mode Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Fetches a list of players within a channel, optionally filtered by their mode (WRITE or READ). ```java public List getOnlinePlayers(final ChannelMode mode) ``` -------------------------------- ### Get Player Cache Safely Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Ensure a player is online before attempting to retrieve their cache to avoid errors. Use `player.isOnline()` for this check. ```java if (player.isOnline()) { PlayerCache cache = ChatControlAPI.getCache(player); } ``` -------------------------------- ### Get Player Cache and Check Channel Modes Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Retrieves a player's cache to check their current channel mode. Use this to determine if a player is in a specific channel and their read/write permissions. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.mineacademy.chatcontrol.model.Channel; import org.mineacademy.chatcontrol.model.ChannelMode; import org.mineacademy.chatcontrol.model.db.PlayerCache; public class MyPlugin extends JavaPlugin { public void checkPlayerChannels(Player player) { // Get player cache PlayerCache cache = ChatControlAPI.getCache(player); // Check if in specific channel ChannelMode mode = cache.getChannelMode(staffChannel); if (mode == null) { player.sendMessage("You are not in staff channel"); return; } // Check read/write mode if (mode == ChannelMode.WRITE) { player.sendMessage("You can write to staff channel"); } else { player.sendMessage("You can only read staff channel"); } } public void listPlayerChannels(Player player) { PlayerCache cache = ChatControlAPI.getCache(player); Map channels = cache.getAllChannels(); player.sendMessage("You are in " + channels.size() + " channels:"); for (Map.Entry entry : channels.entrySet()) { String mode = entry.getValue() == ChannelMode.WRITE ? "write" : "read"; player.sendMessage(" - " + entry.getKey().getName() + " (" + mode + ")"); } } public void removePlayerFromAllChannels(Player player) { PlayerCache cache = ChatControlAPI.getCache(player); cache.leaveAllChannels(true); // Save changes player.sendMessage("You have been removed from all channels"); } } ``` -------------------------------- ### Get Player's Channel Mode Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Gets the player's current mode (WRITE or READ) in a specific channel. Returns null if the player is not in the channel. ```Java public ChannelMode getChannelMode(final Channel channel) ``` ```Java PlayerCache cache = ChatControlAPI.getCache(player); ChannelMode mode = cache.getChannelMode(staffChannel); if (mode == ChannelMode.WRITE) { // Player can write to this channel } ``` -------------------------------- ### PlayerCache.getPlayerUid Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Gets the player's UUID. ```APIDOC ## PlayerCache.getPlayerUid ### Description Gets the player's UUID. ### Method ```java public UUID getPlayerUid() ``` ### Response #### Success Response - **Returns** (UUID) - the unique identifier ``` -------------------------------- ### Newcomer Detection Configuration Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Configures the criteria for identifying new players based on join time, playtime, and level. ```yaml Newcomer: # Criteria for classifying new players Check_First_Join: true Check_Playtime: true Minimum_Playtime_Minutes: 60 Check_Level: true Minimum_Level: 5 ``` -------------------------------- ### Get All Loaded Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves an unmodifiable collection of all loaded channels. ```java public static Collection getChannels() ``` -------------------------------- ### PlayerCache.getPlayerName Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Gets the player's name (cached at load time). ```APIDOC ## PlayerCache.getPlayerName ### Description Gets the player's name (cached at load time). ### Method ```java public String getPlayerName() ``` ### Response #### Success Response - **Returns** (String) - the player's username ``` -------------------------------- ### PlayerCache.getChannelMode Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Gets the player's current mode in a specific channel. ```APIDOC ## PlayerCache.getChannelMode ### Description Gets the player's current mode in a specific channel. ### Method ```java public ChannelMode getChannelMode(final Channel channel) ``` ### Parameters #### Path Parameters - **channel** (Channel) - Required - The target channel ### Response #### Success Response - **Returns** (ChannelMode) - WRITE, READ, or null if not in channel ### Example ```java PlayerCache cache = ChatControlAPI.getCache(player); ChannelMode mode = cache.getChannelMode(staffChannel); if (mode == ChannelMode.WRITE) { // Player can write to this channel } ``` ``` -------------------------------- ### loadChannels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Loads all channels from the configuration file. This method is called automatically on startup. ```APIDOC ## loadChannels ### Description Loads all channels from the configuration file (Channels.List in settings.yml). Called automatically on startup. ### Method `static void` ### Parameters None ### Returns None ``` -------------------------------- ### Get Player UUID Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Retrieves the unique identifier (UUID) for the player. ```Java public UUID getPlayerUid() ``` -------------------------------- ### Load Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Loads all channels from the configuration file. This method is called automatically on startup. ```java public static void loadChannels() ``` -------------------------------- ### List Command Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Permissions for listing channels and seeing other players within channels. ```text chatcontrol.list # List channels chatcontrol.list.other # See other players in channels ``` -------------------------------- ### Get Leavable Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves a list of all channels that a player is permitted to leave. ```java public static List getChannelsWithLeavePermission(final Player player) ``` -------------------------------- ### Channel Instance Methods Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Methods for interacting with a specific channel instance. ```APIDOC ## Channel Instance Methods ### Description Methods for interacting with a specific channel instance. ### Methods - `joinPlayer(Player/Cache, ChannelMode, boolean)`: Returns `boolean`. Joins a player to the channel with the specified mode and join type. - `isInChannel(Player/Cache)`: Returns `boolean`. Checks if a player is currently in this channel. - `getChannelMode(Player)`: Returns `ChannelMode`. Gets the player's current mode in this channel. - `getOnlinePlayers(ChannelMode)`: Returns `List`. Gets a list of players in the channel with the specified mode. - `getOnlinePlayers()`: Returns `Map`. Gets a map of all players in the channel and their modes. - `sendMessage(CommandSender, String)`: Returns `State`. Sends a message from a sender into this channel. - `isMuted()`: Returns `boolean`. Checks if the channel is currently muted. - `getUnmuteTimeRemaining()`: Returns `long`. Gets the remaining time in milliseconds until the channel is unmuted. - `setMuted(SimpleTime)`: Returns `void`. Mutes or unmutes the channel for the specified duration. ``` -------------------------------- ### Basic Channel Operations Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Demonstrates common channel interactions like finding, joining, sending messages, listing channels, and managing mute status. Ensure the channel exists before performing operations. ```java import org.mineacademy.chatcontrol.model.Channel; import org.mineacademy.chatcontrol.model.ChannelMode; // Get a channel Channel global = Channel.findChannel("global"); if (global == null) { player.sendMessage("Channel does not exist"); return; } // Check if player is in channel if (global.isInChannel(player)) { player.sendMessage("You are in the global channel"); } // Join a channel if (global.joinPlayer(player, ChannelMode.WRITE, true)) { player.sendMessage("Successfully joined global channel!"); } else { player.sendMessage("Could not join (event was cancelled)"); } // Send a message try { global.sendMessage(player, "Hello everyone!"); } catch (EventHandledException e) { player.sendMessage("Message was cancelled by an event"); } // List all channels for (Channel channel : Channel.getChannels()) { player.sendMessage("Channel: " + channel.getName()); } // Get players in a channel Map players = global.getOnlinePlayers(); for (Map.Entry entry : players.entrySet()) { player.sendMessage(entry.getKey().getName() + " (" + entry.getValue() + ")"); } // Mute a channel global.setMuted(SimpleTime.fromString("10 minutes")); if (global.isMuted()) { player.sendMessage("Global channel is muted"); } ``` -------------------------------- ### Lean Event Handlers for Performance Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Demonstrates how to keep Bukkit event handlers lean by performing quick checks and deferring heavy operations to asynchronous tasks. This prevents blocking the main server thread. ```java @EventHandler public void onChat(ChannelPostChatEvent event) { // GOOD - Quick checks only if (event.getChannel().getName().equals("spam")) { return; } // AVOID - Heavy operations in event handler // Don't do database lookups, network calls, etc. // Instead queue for async processing Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { doHeavyWork(event); }); } ``` -------------------------------- ### BungeeCord API Import Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Import the main class for interacting with ChatControl on BungeeCord proxies. ```java import org.mineacademy.chatcontrol.bungee.BungeeControl; ``` -------------------------------- ### Get Player Name Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/player-cache.md Retrieves the player's username. This name is cached at the time the PlayerCache object is loaded. ```Java public String getPlayerName() ``` -------------------------------- ### Event Handling with Priorities Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Demonstrates how to use Bukkit's EventPriority to control the order of execution for ChatControl events. Choose priorities based on whether you need to modify messages early, cancel them, or just monitor the final state. ```java import org.bukkit.event.EventPriority; @EventHandler(priority = EventPriority.HIGHEST) public void earlyProcessing(ChannelPreChatEvent event) { // First to process - modify message early event.setMessage(event.getMessage().toUpperCase()); } @EventHandler(priority = EventPriority.NORMAL) public void normalProcessing(ChannelPreChatEvent event) { // Middle of the line if (event.getMessage().contains("spam")) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.LOW) public void lateProcessing(ChannelPostChatEvent event) { // After ChatControl processing - log the final message logMessage(event.getSender(), event.getMessage()); } @EventHandler(priority = EventPriority.MONITOR) public void monitoring(ChannelPostChatEvent event) { // Last - read-only monitoring incrementMessageCounter(); } ``` -------------------------------- ### Project Structure Overview Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md This snippet outlines the directory structure of the ChatControl project, indicating the location of various documentation files and API reference modules. ```text output/ ├── INDEX.md (This file) ├── api-reference/ │ ├── overview.md Project structure & architecture │ ├── chatcontrol-api.md Main API class reference │ ├── events.md All event classes │ ├── channels.md Channel API reference │ └── player-cache.md Player cache API reference ├── types.md All types & enums ├── configuration.md Config options ├── permissions.md Permission nodes └── integration-guide.md Integration patterns & best practices ``` -------------------------------- ### Get Remaining Mute Time Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves the remaining mute duration in milliseconds. Returns 0 if the channel is not currently muted. ```java public long getUnmuteTimeRemaining() ``` -------------------------------- ### Say Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to send /say messages. ```text chatcontrol.say # Send /say messages ``` -------------------------------- ### Me Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to send /me messages. ```text chatcontrol.me # Send /me messages ``` -------------------------------- ### isChannelInstalled Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/chatcontrol-api.md Checks if a specified channel exists and is loaded in ChatControl's configuration. It's recommended to use this before attempting to send messages to a channel. ```APIDOC ## isChannelInstalled ### Description Checks if the specified channel exists and is loaded in ChatControl's configuration. ### Method ```java public static boolean isChannelInstalled(final String channelName) ``` ### Parameters #### Path Parameters - **channelName** (String) - Yes - The name of the channel ### Returns `boolean` - true if channel exists and is loaded ### Throws None ### Example ```java if (ChatControlAPI.isChannelInstalled("global")) { ChatControlAPI.sendMessage(sender, "global", "Message"); } ``` ``` -------------------------------- ### Basic Chat Control Integration Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Demonstrates how to check if chat is muted, retrieve player cache, validate messages against filters, and send messages through specific channels using the ChatControlAPI. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.bukkit.entity.Player; public class MyPlugin extends JavaPlugin { public void someMethod(Player player, String message) { // Check if chat is muted if (ChatControlAPI.isChatMuted()) { player.sendMessage("Chat is muted!"); return; } // Get player cache var cache = ChatControlAPI.getCache(player); // Check message against all filters var checker = ChatControlAPI.checkMessage(player, message); if (checker.hasFailed()) { player.sendMessage("Message violates a rule: " + checker.getFailReason()); return; } // Send message through specific channel if (ChatControlAPI.isChannelInstalled("staff")) { ChatControlAPI.sendMessage(player, "staff", message); } } } ``` -------------------------------- ### Enable DiscordSRV Integration Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Enable DiscordSRV integration by setting Enabled and Use_SRV to true in the Discord section of your configuration. ```yaml Discord: # DiscordSRV integration Enabled: true Use_SRV: true ``` -------------------------------- ### Get Player Channel Mode Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Retrieves the current channel mode for a given player. Use this to check if a player can write or read in a channel. ```java public ChannelMode getChannelMode(final Player player) ``` -------------------------------- ### joinPlayer Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Joins a player into this channel with the specified mode and save option. Fires ChannelJoinEvent. ```APIDOC ## joinPlayer ### Description Joins a player into this channel with the specified mode (WRITE or READ). ### Method ```java public boolean joinPlayer(final Player player, final ChannelMode mode, final boolean save) public boolean joinPlayer(final PlayerCache cache, final ChannelMode mode, final boolean save) ``` ### Parameters #### Path Parameters - **player / cache** (Player / PlayerCache) - Yes - The player to join - **mode** (ChannelMode) - Yes - WRITE (can send messages) or READ (receive only) - **save** (boolean) - Yes - Whether to save to database ### Returns `boolean` - false if ChannelJoinEvent was cancelled ### Throws `RuntimeException` - if player already in channel ### Example ```java if (!channel.joinPlayer(player, ChannelMode.WRITE, true)) { /* event was cancelled */ } ``` **Fires:** `ChannelJoinEvent` ``` -------------------------------- ### Check Channel Write Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Ensure that a player has the necessary permissions to write into a target channel before attempting to send a message. ```java if (Channel.canWriteInto(player, targetChannel)) { // Safe to send message } ``` -------------------------------- ### Retrieve Player Cache Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/chatcontrol-api.md Get the PlayerCache object for an online player to access their specific settings and channel modes. An exception is thrown if the player is offline. ```java public static PlayerCache getCache(final Player player) // Example: PlayerCache cache = ChatControlAPI.getCache(player); ``` -------------------------------- ### Maven Dependency for ChatControl Bukkit Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/README.md Add this Maven dependency to your project to use the ChatControl Bukkit API. Ensure the version matches your server setup. ```xml org.mineacademy chatcontrol-bukkit 1.0.0 provided ``` -------------------------------- ### Check Player Join Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Determines if a player has the permission to join at least one available channel. ```java public static boolean canJoinAnyChannel(final Player player) ``` -------------------------------- ### ChatControl Player Cache and Channel Mode Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Shows how to retrieve player cache information and check the channel mode for a specific channel. Requires importing ChatControlAPI and model classes. ```java // Check player cache PlayerCache cache = ChatControlAPI.getCache(player); ChannelMode mode = cache.getChannelMode(channel); ``` -------------------------------- ### Configuration Options Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Overview of configuration options available for ChatControl, categorized by their function. ```APIDOC ## Configuration Options Reference ### Format Options - **`Format`** (String): Default message format. - **`Format_Console`** (String): Message format for the console. - **`Format_To_Discord`** (String): Message format when sending to Discord. - **`Format_From_Discord`** (String): Message format when receiving from Discord. - **`Format_Spy`** (String): Message format for spy mode. ### Range Options - **`Range`** (String/Number): Defines the range for certain features. - **`Range_Worlds`** (List): List of worlds included in the range. - **`Min_Players_For_Range`** (Integer): Minimum players required for range features. ### Party Options - **`Party`** (String): Configuration related to parties. ### Timing Options - **`Message_Delay`** (Duration): Delay between messages. ### Proxy Options - **`Proxy`** (Boolean): Enables or disables proxy features. ### Discord Options - **`Discord_Channel_Id`** (Long): The ID of the Discord channel for integration. ``` -------------------------------- ### Nick Command Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Permissions for changing nicknames and using colors in nicknames. ```text chatcontrol.nick # Change nickname chatcontrol.nick.colors # Use colors in nicknames ``` -------------------------------- ### ChatControl Synced Cache Class Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/types.md A thread-safe cache designed for synchronized data across proxy servers. Provides methods for getting, setting, and removing cached values. ```java public class SyncedCache ``` -------------------------------- ### Newcomer Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/types.md Utility class for checking and setting newcomer status for players. It provides static methods to determine if a player is considered a newcomer and to update their status. ```APIDOC ## Newcomer Utility class for checking if a player is classified as a newcomer. ### Methods: - `static boolean isNewcomer(Player player)` - Check newcomer status - `static void setNewcomer(Player player, boolean newcomer)` - Set status ``` -------------------------------- ### Wildcard Permission: All Commands Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Grants access to all commands provided by ChatControl. ```plaintext chatcontrol.command.* # All ChatControl commands ``` -------------------------------- ### Send Message to Channel Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/chatcontrol-api.md Sends a message to a specific channel, simulating the sender's origin. This method triggers all associated channel events and filters. It is recommended to check channel installation first. ```java public static void sendMessage(final CommandSender sender, final String channelName, final String message) ``` -------------------------------- ### Wildcard Permission: Admin Access Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Grants access to all subcommands under the admin category. ```plaintext chatcontrol.admin.* # All admin subcommands ``` -------------------------------- ### Channel Static Methods Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/INDEX.md Utilities for managing and querying channels within the ChatControl system. ```APIDOC ## Channel Static Methods ### Description Utilities for managing and querying channels within the ChatControl system. ### Methods - `loadChannels()`: Returns `void`. Loads all channels from configuration. - `isChannelLoaded(String)`: Returns `boolean`. Checks if a channel is loaded by its name. - `findChannel(String)`: Returns `Channel`. Retrieves a channel by name, returning null if not found. - `fromString(String)`: Returns `Channel`. Retrieves a channel by name, throwing an exception if not found. - `fromDiscordId(long)`: Returns `Channel`. Finds a channel by its Discord ID. - `getChannels()`: Returns `Collection`. Retrieves all loaded channels. - `getChannelNames()`: Returns `List`. Retrieves the names of all loaded channels. - `canRead(CommandSender, Channel)`: Returns `boolean`. Checks if a sender has permission to read from a channel. - `canWriteInto(CommandSender, Channel)`: Returns `boolean`. Checks if a sender has permission to write into a channel. - `hasPermission(CommandSender, Channel, ChannelMode)`: Returns `boolean`. Checks if a sender has permission for a specific channel mode. - `canJoinAnyChannel(Player)`: Returns `boolean`. Checks if a player can join any channel. - `getChannelsWithJoinPermission(Player)`: Returns `List`. Retrieves a list of channels the player can join. - `getChannelsWithLeavePermission(Player)`: Returns `List`. Retrieves a list of channels the player can leave. - `filterChannelsPlayerCanLeave(Collection, Player)`: Returns `List`. Filters a collection of channels to include only those the player can leave. ``` -------------------------------- ### Join Player to Channel Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Joins a player into the current channel with specified mode and save option. Use this to programmatically add players to channels. ```java public boolean joinPlayer(final Player player, final ChannelMode mode, final boolean save) public boolean joinPlayer(final PlayerCache cache, final ChannelMode mode, final boolean save) ``` ```java if (!channel.joinPlayer(player, ChannelMode.WRITE, true)) { /* event was cancelled */ } ``` -------------------------------- ### Proxy Configuration Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/configuration.md Enables cross-server messaging and configures Redis connection details for proxy integration. ```yaml Proxy: # Enable cross-server messaging Enabled: true # Redis configuration for BungeeCord/Velocity Redis: Host: "localhost" Port: 6379 Username: "" Password: "" Database: 0 ``` -------------------------------- ### Realname Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to see real names behind nicknames. ```text chatcontrol.realname # See real names behind nicknames ``` -------------------------------- ### Bukkit API Imports Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Import necessary classes for interacting with the ChatControl API within Bukkit server plugins. ```java // Main API import org.mineacademy.chatcontrol.api.ChatControlAPI; // Events import org.mineacademy.chatcontrol.api.*; // Models import org.mineacademy.chatcontrol.model.*; import org.mineacademy.chatcontrol.model.db.*; ``` -------------------------------- ### Reply Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to reply to private messages. ```text chatcontrol.reply # Reply to private messages ``` -------------------------------- ### Toggle Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to toggle message types such as join/quit/death messages. ```text chatcontrol.toggle # Toggle message types (join/quit/death) ``` -------------------------------- ### Basic Channel Operations Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Provides methods for finding, joining, sending messages to, listing, and muting channels. It also allows retrieval of players within a channel. ```APIDOC ## Channel Operations ### Description Provides methods for finding, joining, sending messages to, listing, and muting channels. It also allows retrieval of players within a channel. ### Methods - **findChannel(String name)**: Retrieves a channel by its name. - **getChannels()**: Returns a list of all available channels. - **joinPlayer(Player player, ChannelMode mode, boolean force)**: Joins a player to a channel with a specified mode. - **sendMessage(Player sender, String message)**: Sends a message to a channel. - **setMuted(SimpleTime duration)**: Mutes the channel for a specified duration. - **isMuted()**: Checks if the channel is currently muted. - **isInChannel(Player player)**: Checks if a player is in the channel. - **getOnlinePlayers()**: Retrieves a map of players currently in the channel and their modes. ### Example Usage ```java // Get a channel Channel global = Channel.findChannel("global"); if (global == null) { // Handle channel not found return; } // Join a channel global.joinPlayer(player, ChannelMode.WRITE, true); // Send a message try { global.sendMessage(player, "Hello everyone!"); } catch (EventHandledException e) { // Handle cancelled message } // List all channels for (Channel channel : Channel.getChannels()) { // Process each channel } // Get players in a channel Map players = global.getOnlinePlayers(); ``` ``` -------------------------------- ### MOTD Command Permission Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Allows players to view MOTD messages. ```text chatcontrol.motd # View MOTD messages ``` -------------------------------- ### Velocity API Import Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/overview.md Import the main class for interacting with ChatControl on Velocity proxies. ```java import org.mineacademy.chatcontrol.velocity.VelocityControl; ``` -------------------------------- ### Admin Tooling for Channels Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Provides methods to mute, unmute, and list players within specific chat channels. Use this to build administrative interfaces for managing channels. ```java import org.mineacademy.chatcontrol.api.ChatControlAPI; import org.mineacademy.chatcontrol.api.MuteEvent; import org.mineacademy.chatcontrol.model.Channel; public class AdminTools { public void muteChannel(CommandSender sender, String channelName, long durationSeconds) { Channel channel = Channel.findChannel(channelName); if (channel == null) { sender.sendMessage("Channel not found!"); return; } SimpleTime duration = SimpleTime.fromSeconds(durationSeconds); channel.setMuted(duration); sender.sendMessage("Channel " + channelName + " muted for " + durationSeconds + " seconds"); } public void unmuteChannel(CommandSender sender, String channelName) { Channel channel = Channel.findChannel(channelName); if (channel == null) { sender.sendMessage("Channel not found!"); return; } channel.setMuted(null); // null = unmute sender.sendMessage("Channel " + channelName + " unmuted"); } public void listChannelPlayers(CommandSender sender, String channelName) { Channel channel = Channel.findChannel(channelName); if (channel == null) { sender.sendMessage("Channel not found!"); return; } Map players = channel.getOnlinePlayers(); sender.sendMessage("Players in " + channelName + ": " + players.size()); for (Map.Entry entry : players.entrySet()) { String mode = entry.getValue() == ChannelMode.WRITE ? "(RW)" : "(RO)"; sender.sendMessage(" - " + entry.getKey().getName() + " " + mode); } } } ``` -------------------------------- ### Check Channel Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/channels.md Verify if a player has read, write, or specific mode permissions for a given channel. This is crucial for controlling access to channel functionalities. ```java // Check read permission if (Channel.canRead(player, staffChannel)) { // Player can read staff channel } // Check write permission if (Channel.canWriteInto(player, staffChannel)) { // Player can write to staff channel } // Check by mode if (Channel.hasPermission(player, "staff", ChannelMode.WRITE)) { staffChannel.sendMessage(player, "Staff message"); } ``` -------------------------------- ### Event Handling Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/README.md Documentation for 13 event classes that allow developers to hook into various chat-related occurrences, all of which are cancellable. ```APIDOC ## Events ### Description ChatControl emits 13 distinct event classes that developers can listen to and interact with. All events are cancellable, following Bukkit standards. ### Event Types - Channel chat events (pre & post) - Channel membership events (join/leave) - Player message events (automated messages) - Mention events (player mentions) - Private message events - Mute events - Spy events - Rule events ### Further Details Detailed signatures and usage for all 13 event classes can be found in the [api-reference/events.md](api-reference/events.md) file. ``` -------------------------------- ### Default Player Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Permissions automatically granted to all players by default. ```plaintext chatcontrol.channel.read.global chatcontrol.channel.write.global chatcontrol.tell chatcontrol.mail chatcontrol.me chatcontrol.say chatcontrol.tag chatcontrol.motd chatcontrol.list chatcontrol.toggle ``` -------------------------------- ### Ignore Command Permissions Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/permissions.md Permissions for ignoring other players and for administrators to override ignore lists. ```text chatcontrol.ignore # Ignore other players chatcontrol.ignore.admin # Override ignore lists ``` -------------------------------- ### Add Maven Dependency for ChatControl and Foundation Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/integration-guide.md Include these dependencies in your project's pom.xml to use the ChatControl API. The scope is set to 'provided' as these are expected to be available on the server. ```xml org.mineacademy chatcontrol-bukkit 1.0.0 provided org.mineacademy foundation 7 provided ``` -------------------------------- ### PreRuleMatchEvent Source: https://github.com/kangarko/chatcontrol/blob/master/_autodocs/api-reference/events.md Fired before a rule is matched and applied. ```APIDOC ## PreRuleMatchEvent ### Description Fired before a rule is matched and applied. ### Constructor `public PreRuleMatchEvent(Rule rule, RuleType type, Player player, String message)` ### Properties #### Rule - **rule** (`Rule`) - No - The rule being matched #### Type - **type** (`RuleType`) - No - Rule type (CHAT, COMMAND, etc.) #### Player - **player** (`Player`) - No - Player triggering the rule #### Message - **message** (`String`) - No - Message matching the rule #### Cancelled - **cancelled** (`boolean`) - Yes - Set to prevent rule application ```