Search in sources :

Example 6 with UserChatEvent

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();
}
Also used : AutoUser(com.easterlyn.user.AutoUser) User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) Channel(com.easterlyn.chat.channel.Channel) EventHandler(org.bukkit.event.EventHandler)

Aggregations

UserChatEvent (com.easterlyn.chat.event.UserChatEvent)6 CommandAlias (co.aikar.commands.annotation.CommandAlias)3 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)3 CommandPermission (co.aikar.commands.annotation.CommandPermission)3 Description (co.aikar.commands.annotation.Description)3 Syntax (co.aikar.commands.annotation.Syntax)3 EasterlynCore (com.easterlyn.EasterlynCore)3 Channel (com.easterlyn.chat.channel.Channel)3 AutoUser (com.easterlyn.user.AutoUser)3 HashMap (java.util.HashMap)3 User (com.easterlyn.user.User)2 UUID (java.util.UUID)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 EasterlynChat (com.easterlyn.EasterlynChat)1 EasterlynDiscord (com.easterlyn.EasterlynDiscord)1 Event (com.github.jikoo.planarwrappers.event.Event)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Snowflake (discord4j.common.util.Snowflake)1