API zh-CN
API
想要改进下 Legendchat 吗? 或者让一个玩家接受或拒绝消息? 或者撤回一条已发送的消息? 没错! 这些API可以让你完成这些!
PS: 建议看看 "设置值到标签" 它非常有用.
事件
聊天事件
有关于聊天的事件 Event (非BungeeCord聊天).
可以调用的列表:
Method | Return | Description |
---|---|---|
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() | boolean | Is the event cancelled? |
setCancelled(boolean c) | void | 取消事件 |
私聊事件
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 |
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):
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.
例子
一些事件例子
阻止有关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(); }