use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.
the class ChannelManagementListener method onPlayerChat.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
RegisteredServiceProvider<EasterlynCore> easterlynRSP = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (easterlynRSP == null) {
event.getPlayer().sendMessage("Easterlyn core plugin is not enabled! " + "Please report this to @Staff on Discord immediately!");
return;
}
event.setCancelled(true);
EasterlynCore core = easterlynRSP.getProvider();
User user = core.getUserManager().getUser(event.getPlayer().getUniqueId());
event.getPlayer().setDisplayName(user.getDisplayName());
Channel channel = null;
// #channel message parsing
if (event.getMessage().length() > 0 && event.getMessage().charAt(0) == '#') {
int space = event.getMessage().indexOf(' ');
if (space == -1) {
space = event.getMessage().length();
}
String channelName = event.getMessage().substring(1, space);
if (space == event.getMessage().length()) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.no_content", "{value}", '#' + channelName);
return;
}
channel = chat.getChannels().get(channelName);
if (channel == null) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.no_matching_channel", "{value}", '#' + channelName);
return;
}
if (!user.getStorage().getStringList(EasterlynChat.USER_CHANNELS).contains(channel.getName())) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.not_listening_to_channel", "{value}", channel.getDisplayName());
return;
}
event.setMessage(event.getMessage().substring(space + 1));
}
// User's channel
if (channel == null) {
String currentChannelName = user.getStorage().getString(EasterlynChat.USER_CURRENT);
if (currentChannelName != null) {
channel = chat.getChannels().get(currentChannelName);
}
if (channel == null) {
core.getLocaleManager().sendMessage(event.getPlayer(), "chat.common.not_listening_to_channel");
return;
}
}
new UserChatEvent(user, channel, event.getMessage()).send();
}
Aggregations