Search in sources :

Example 1 with UserChatEvent

use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.

the class MinecraftBridge method handleDiscordChat.

private void handleDiscordChat(DiscordUser user, Message message) {
    String content = message.getContent();
    if (content.isBlank() && message.getAttachments().isEmpty() || message.getAuthor().isEmpty()) {
        return;
    }
    for (Attachment attachment : message.getAttachments()) {
        if (!content.isEmpty()) {
            content = content.concat(" ");
        }
        content = content.concat(attachment.getProxyUrl());
    }
    String finalContent = content;
    if (!user.hasPermission("easterlyn.discord.unfiltered")) {
        message.getChannel().doOnSuccess(messageChannel -> {
            Mono<Message> replyMono;
            if (finalContent.indexOf('\n') > 0) {
                replyMono = messageChannel.createMessage("Newlines are not allowed in messages to Minecraft, " + message.getAuthor().get().getMention());
            } else if (finalContent.length() > 255) {
                replyMono = messageChannel.createMessage("Messages from Discord may not be over 255 characters, " + message.getAuthor().get().getMention());
            } else {
                return;
            }
            replyMono.doOnSuccess(replyMessage -> replyMessage.addReaction(ReactionEmoji.unicode(":no_entry_sign:"))).subscribe();
        }).subscribe();
    }
    new UserChatEvent(user, EasterlynChat.DEFAULT, sanitizeForMinecraft(content)).send();
}
Also used : MessageChannel(discord4j.core.object.entity.channel.MessageChannel) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) Snowflake(discord4j.common.util.Snowflake) Attachment(discord4j.core.object.entity.Attachment) GuildChannel(discord4j.core.object.entity.channel.GuildChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Matcher(java.util.regex.Matcher) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) EasterlynDiscord(com.easterlyn.EasterlynDiscord) ChatColor(net.md_5.bungee.api.ChatColor) User(discord4j.core.object.entity.User) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) EasterlynCore(com.easterlyn.EasterlynCore) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) ReactionEmoji(discord4j.core.object.reaction.ReactionEmoji) TimeUnit(java.util.concurrent.TimeUnit) Event(com.github.jikoo.planarwrappers.event.Event) Message(discord4j.core.object.entity.Message) EventPriority(org.bukkit.event.EventPriority) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Channel(discord4j.core.object.entity.channel.Channel) Command(org.bukkit.command.Command) CacheBuilder(com.google.common.cache.CacheBuilder) GatewayDiscordClient(discord4j.core.GatewayDiscordClient) Pattern(java.util.regex.Pattern) Cache(com.google.common.cache.Cache) NotNull(org.jetbrains.annotations.NotNull) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) EasterlynChat(com.easterlyn.EasterlynChat) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) Mono(reactor.core.publisher.Mono) Attachment(discord4j.core.object.entity.Attachment)

Example 2 with UserChatEvent

use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.

the class MessageCommand method sendMessage.

@CommandAlias("message|msg|m|whisper|w|pm|tell|t")
@Description("{@@chat.commands.message.description}")
@CommandPermission("easterlyn.command.message")
@Syntax("<recipient> <message>")
@CommandCompletion("@player")
public void sendMessage(BukkitCommandIssuer sender, @Flags(CoreContexts.ONLINE) User target, String message) {
    User issuer;
    if (sender.isPlayer()) {
        issuer = core.getUserManager().getUser(sender.getUniqueId());
    } else {
        Map<String, String> userData = new HashMap<>();
        userData.put("name", sender.getIssuer().getName());
        issuer = new AutoUser(core, userData);
        // For the purpose of allowing replies to console, set target's reply target.
        replies.put(target.getUniqueId(), issuer);
    }
    replies.put(issuer.getUniqueId(), target);
    Channel channel = chat.getChannels().get("pm");
    if (channel == null) {
        ReportableEvent.call("Channel #pm not set up when executing /message!");
        core.getLocaleManager().sendMessage(sender.getIssuer(), "chat.commands.message.error.pm_channel");
        return;
    }
    List<UUID> recipients = new ArrayList<>();
    if (!(issuer instanceof AutoUser)) {
        recipients.add(issuer.getUniqueId());
    }
    if (!(target instanceof AutoUser)) {
        recipients.add(target.getUniqueId());
    }
    new UserChatEvent(issuer, channel, target.getDisplayName() + ": " + message).send(recipients);
}
Also used : User(com.easterlyn.user.User) AutoUser(com.easterlyn.user.AutoUser) HashMap(java.util.HashMap) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) AutoUser(com.easterlyn.user.AutoUser) Channel(com.easterlyn.chat.channel.Channel) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 3 with UserChatEvent

use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.

the class ChannelManagementListener method onUserCreate.

@EventHandler
public void onUserCreate(UserCreationEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider != null) {
        ConfigurationSection userSection = chat.getConfig().getConfigurationSection("auto_user");
        Map<String, String> userData = new HashMap<>();
        if (userSection != null) {
            userSection.getKeys(false).forEach(key -> userData.put(key, userSection.getString(key)));
        }
        Player player = event.getUser().getPlayer();
        if (player != null && !player.hasPlayedBefore()) {
            // TODO lang?
            new UserChatEvent(new AutoUser(easterlynProvider.getProvider(), userData), EasterlynChat.DEFAULT, event.getUser().getDisplayName() + " is new! Please welcome them.");
        }
    }
    addMainChannel(event.getUser(), null);
}
Also used : Player(org.bukkit.entity.Player) EasterlynCore(com.easterlyn.EasterlynCore) HashMap(java.util.HashMap) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) AutoUser(com.easterlyn.user.AutoUser) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) EventHandler(org.bukkit.event.EventHandler)

Example 4 with UserChatEvent

use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.

the class AetherCommand method aether.

@CommandAlias("aether")
@Description("{@@chat.commands.aether.description}")
@CommandPermission("easterlyn.command.aether")
@Syntax("<name> <message content>")
@CommandCompletion("")
public void aether(BukkitCommandIssuer issuer, @Single String name, String text) {
    Map<String, String> userData = new HashMap<>();
    userData.put("name", name);
    userData.put("color", issuer.isPlayer() ? core.getUserManager().getUser(issuer.getUniqueId()).getColor().getName() : Colors.RANK_HEAD_ADMIN.getName());
    Channel channel = chat.getChannels().get("aether");
    if (channel == null) {
        ReportableEvent.call("Channel #aether not set up when executing /aether!");
        return;
    }
    // TODO async
    new UserChatEvent(new AetherUser(userData), channel, text).send(EasterlynChat.DEFAULT.getMembers());
}
Also used : HashMap(java.util.HashMap) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) Channel(com.easterlyn.chat.channel.Channel) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 5 with UserChatEvent

use of com.easterlyn.chat.event.UserChatEvent in project Easterlyn by Easterlyn.

the class ShowItemCommand method showItem.

@CommandAlias("show|me show")
@Description("{@@chat.commands.me.show.description}")
@CommandPermission("easterlyn.command.show")
@Syntax("[#channel]")
@CommandCompletion("@channelsListening")
public void showItem(@Flags(CoreContexts.SELF) User sender, @Flags(ChannelFlag.LISTENING_OR_CURRENT) Channel channel) {
    Player player = sender.getPlayer();
    if (player == null) {
        core.getLocaleManager().sendMessage(getCurrentCommandIssuer().getIssuer(), "chat.commands.me.show.error.no_player");
        return;
    }
    ItemStack hand = player.getInventory().getItemInMainHand();
    if (hand.getItemMeta() == null || (!hand.getItemMeta().hasDisplayName() && hand.getEnchantments().isEmpty())) {
        core.getLocaleManager().sendMessage(player, "chat.commands.me.show.error.not_special");
        return;
    }
    new UserChatEvent(sender, channel, "shows off {ITEM:" + player.getInventory().getHeldItemSlot() + "}", true).send();
}
Also used : Player(org.bukkit.entity.Player) UserChatEvent(com.easterlyn.chat.event.UserChatEvent) ItemStack(org.bukkit.inventory.ItemStack) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

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