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();
}
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);
}
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);
}
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());
}
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();
}
Aggregations