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:

MethodReturnDescription
getMessage()StringGet the message
setMessage(String msg)voidSet the message
getFormat()StringGet the channel format (config.yml)
setFormat(String format)voidSet the format
getSender()PlayerGet the sender
setSender(Player p)voidSet the sender
getRecipients()Set<Player>Get the recipients list
getChannel()ChannelGet the channel
getBukkitFormat()StringGet the Bukkit format
getBaseFormat()StringGet the channel base format (<channel>.yml)
getTags()List<String>Get all the tags in format
getTagValue(String tag)StringGet a value from a tag
setTagValue(String tag,String value)voidSet a value to a tag
addTag(String tag,String value)voidAdd a new tag
isCancelled()booleanIs the event cancelled?
setCancelled(boolean c)voidCancel the event


PrivateMessageEvent

Event called when a private message is sent.
List of methods available:

MethodReturnDescription
getSender()PlayerGet who sent
setSender(Player p)voidSet who sent
getReceiver()PlayerGet who will receive
setReceiver(Player p)voidSet who will receive
getMessage()StringGet the message
setMessage(String msg)voidSet the message
isCancelled()booleanIs the event cancelled?
setCancelled(boolean b)voidCancel 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):

MethodReturnDescription
getChannelManager()ChannelManagerGet the ChannelManager
getPlayerManager()PlayerManagerGet the PlayerManager
getMessageManager()MessageManagerGet the MessageManager
getIgnoreManager()IgnoreManagerGet the IgnoreManager
getPrivateMessageManager()PrivateMessageManagerGet the PrivateMessageManager
getDelayManager()DelayManagerGet the DelayManager
getMuteManager()MuteManagerGet the MuteManager
getCensorManager()CensorManagerGet the CensorManager
getLogManager()LogManagerGet the LogManager
getConfigManager()ConfigManagerGet the ConfigManager
getTemporaryChannelManager()TemporaryChannelManagerGet the TemporaryChannelManager
getAfkManager()AfkManagerGet the AfkManager
getDefaultChannel()ChannelGet the default channel
getBungeecordChannel()ChannelGet the bungeecord channel
getLanguage()StringGet plugin language (like: en)
blockRepeatedTags()booleanConfig.yml
showNoOneHearsYou()booleanConfig.yml
forceRemoveDoubleSpacesFromBukkit()booleanConfig.yml
sendFakeMessageToChat()booleanConfig.yml
logToFile()booleanConfig.yml
getLogToFileTime()intConfig.yml
textToTag()HashMap<String,String>Config.yml
blockShortcutsWhenCancelled()booleanConfig.yml
useAsyncChat()booleanConfig.yml
maintainSpyMode()booleanConfig.yml
isBungeecordActive()booleanConfig.yml
getPlugin()PluginGet Legendchat plugin
getFormat(String base_format)StringGet the format (ex.: default)
format(String msg)StringReplace base_format to format
getPrivateMessageFormat(String format)StringGet a private message format
load()voidReload 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();
}