API
API
Want to change something inside Legendchat? Or stop a player from receiving a message? Or cancel a message from being sent? Okay! You can do!
PS: I really recommend you to read "Set a value to a tag". It could be useful.
Events
ChatMessageEvent
Event called when someone say something in the chat (but not the bungeecord channel).
List of methods available:
Method | Return | Description |
---|---|---|
getMessage() | String | Get the message |
setMessage(String msg) | void | Set the message |
getFormat() | String | Get the channel format (config.yml) |
setFormat(String format) | void | Set the format |
getSender() | Player | Get the sender |
setSender(Player p) | void | Set the sender |
getRecipients() | Set<Player> | Get the recipients list |
getChannel() | Channel | Get the channel |
getBukkitFormat() | String | Get the Bukkit format |
getBaseFormat() | String | Get the channel base format (<channel>.yml) |
getTags() | List<String> | Get all the tags in format |
getTagValue(String tag) | String | Get a value from a tag |
setTagValue(String tag,String value) | void | Set a value to a tag |
addTag(String tag,String value) | void | Add a new tag |
isCancelled() | boolean | Is the event cancelled? |
setCancelled(boolean c) | void | Cancel the event |
PrivateMessageEvent
Event called when a private message is sent.
List of methods available:
Method | Return | Description |
---|---|---|
getSender() | Player | Get who sent |
setSender(Player p) | void | Set who sent |
getReceiver() | Player | Get who will receive |
setReceiver(Player p) | void | Set who will receive |
getMessage() | String | Get the message |
setMessage(String msg) | void | Set the message |
isCancelled() | boolean | Is the event cancelled? |
setCancelled(boolean b) | void | Cancel the event |
BungeecordChatMessageEvent
Event called when a chat message is sent through the bungeecord channel.
The methods inside this event is the same as ChatMessageEvent, excluding getSender(), setSender() and getBukkitFormat().
You can get the Sender's name inside the tag 'sender' or 'plainsender'.
Observation: Message flow when someone sent a bungeecord message:
Player say in channel => ChatMessageEvent (sender server) => Send message to BungeeCord => BungeeCord send message to other servers => BungeecordChatMessageEvent (others servers) => Other players receive the message
Inside Legendchat
Methods
You can change other things inside Legendchat.
To hook with Legendchat you just need to use Legendchat.
Example:
public void onEnable() { ChannelManager channelManager = Legendchat.getChannelManager(); }
List of methods (I will list what manager do what):
Method | Return | Description |
---|---|---|
getChannelManager() | ChannelManager | Get the ChannelManager |
getPlayerManager() | PlayerManager | Get the PlayerManager |
getMessageManager() | MessageManager | Get the MessageManager |
getIgnoreManager() | IgnoreManager | Get the IgnoreManager |
getPrivateMessageManager() | PrivateMessageManager | Get the PrivateMessageManager |
getDelayManager() | DelayManager | Get the DelayManager |
getMuteManager() | MuteManager | Get the MuteManager |
getCensorManager() | CensorManager | Get the CensorManager |
getLogManager() | LogManager | Get the LogManager |
getConfigManager() | ConfigManager | Get the ConfigManager |
getTemporaryChannelManager() | TemporaryChannelManager | Get the TemporaryChannelManager |
getAfkManager() | AfkManager | Get the AfkManager |
getDefaultChannel() | Channel | Get the default channel |
getBungeecordChannel() | Channel | Get the bungeecord channel |
getLanguage() | String | Get plugin language (like: en) |
blockRepeatedTags() | boolean | Config.yml |
showNoOneHearsYou() | boolean | Config.yml |
forceRemoveDoubleSpacesFromBukkit() | boolean | Config.yml |
sendFakeMessageToChat() | boolean | Config.yml |
logToFile() | boolean | Config.yml |
getLogToFileTime() | int | Config.yml |
textToTag() | HashMap<String,String> | Config.yml |
blockShortcutsWhenCancelled() | boolean | Config.yml |
useAsyncChat() | boolean | Config.yml |
maintainSpyMode() | boolean | Config.yml |
isBungeecordActive() | boolean | Config.yml |
getPlugin() | Plugin | Get Legendchat plugin |
getFormat(String base_format) | String | Get the format (ex.: default) |
format(String msg) | String | Replace base_format to format |
getPrivateMessageFormat(String format) | String | Get a private message format |
load() | void | Reload Legendchat class |
List of managers
ChannelManager
Contains: All channels.
Methods to: Create, delete and get channels.
PlayerManager
Contains: Player's channels, spies and hidden players.
Methods to: Get and change player channel, get and set spies, get and set hidden players.
MessageManager
Contains: All loaded messages.
Methods to: Get a message.
IgnoreManager
Contains: All ignored players and who ignored.
Methods to: Get and set players to ignore others.
PrivateMessageManager
Contains: All methods to send and change the private message system.
Methods to: Send private messages, reply private messages, start and stop chats.
DelayManager
Contains: All methods to change delays.
Methods to: Add, remove and get delays (the delay is per channel).
MuteManager
Contains: All methods to change muted player and muted server.
Methods to: Add, remove and get muted players and change muted server state.
CensorManager
Contains: All methods to censor functions.
Methods to: Add, remove and get censored words.
TemporaryChannelManager
Contains: All methods to temporary channels.
Methods to: Add, remove and get temporary channels.
ConfigManager
Contains: All methods to access others config files.
Methods to: Read config files.
LogManager
Contains: All methods to log messages.
Methods to: Manage the message cache.
AfkManager
Contains: All methods to afk managing.
Methods to: Add, remove and set afk reasons.
Examples
Examples with the events
Block a message containg something
@EventHandler private void onChat(ChatMessageEvent e) { if(e.getMessage().contains("something")) e.setCancelled(true); }
Block someone from receiving messages
@EventHandler private void onChat(ChatMessageEvent e) { if(e.getRecipients().contains(player)) e.getRecipients().remove(player); }
Set a value to a tag
//Observation: the channel format (config.yml) must contains {mytag} //Like others prefixes ({prefix}, {suffix}, ...) @EventHandler private void onChat(ChatMessageEvent e) { if(e.getTags().contains("mytag")) e.setTagValue("mytag","&6[MyTag] "); }
Examples with the Legendchat class
Unmute a player
public void myMethod(Player p) { MuteManager mm = Legendchat.getMuteManager(); if(mm.isPlayerMuted(p.getName())) mm.unmutePlayer(p.getName()); }
Change player channel
public void myMethod(Player p, String ch_name) { Channel c = Legendchat.getChannelManager().getChannelByName(ch_name); Legendchat.getPlayerManager().setPlayerChannel(p,c,/*send message?*/ true); }
Unmute server
public void myMethod() { Legendchat.getMuteManager().unmuteServer(); }