API zh-CN

API

想要改进下 Legendchat 吗? 或者让一个玩家接受或拒绝消息? 或者撤回一条已发送的消息? 没错! 这些API可以让你完成这些!
PS: 建议看看 "设置值到标签" 它非常有用.



事件

聊天事件

有关于聊天的事件 Event (非BungeeCord聊天).
可以调用的列表:

MethodReturnDescription
getMessage()String获取消息
setMessage(String msg)void设置消息
getFormat()String获取频道格式 (config.yml)
setFormat(String format)void设置格式
getSender()Player获取发消息的玩家
setSender(Player p)void设置发消息的玩家
getRecipients()Set<Player>获取接受消息的列表
getChannel()Channel获取聊天频道
getBukkitFormat()String获取Bukkit格式
getBaseFormat()String获取聊天频道基础格式 (<channel>.yml)
getTags()List<String>获取全部标签格式
getTagValue(String tag)String获取标签的值
setTagValue(String tag,String value)void设置值到标签
addTag(String tag,String value)void添加新标签
isCancelled()booleanIs the event cancelled?
setCancelled(boolean c)void取消事件


私聊事件

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


Bungeecord聊天事件

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.




例子

一些事件例子

阻止有关something的消息

@EventHandler
private void onChat(ChatMessageEvent e) {
    if(e.getMessage().contains("something"))
        e.setCancelled(true);
}


阻止player接收消息

@EventHandler
private void onChat(ChatMessageEvent e) {
    if(e.getRecipients().contains(player))
        e.getRecipients().remove(player);
}


设置值到标签

//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] ");
}


一些LegendChat例子

取消玩家禁言

public void myMethod(Player p) {
    MuteManager mm = Legendchat.getMuteManager();
    if(mm.isPlayerMuted(p.getName()))
        mm.unmutePlayer(p.getName());
}


改变玩家聊天频道

public void myMethod(Player p, String ch_name) {
    Channel c = Legendchat.getChannelManager().getChannelByName(ch_name);
    Legendchat.getPlayerManager().setPlayerChannel(p,c,/*send message?*/ true);
}


取消服务器禁言

public void myMethod() {
    Legendchat.getMuteManager().unmuteServer();
}