Signed-off-by: Etzelia <etzelia@hotmail.com>
discord
Etzelia 2020-06-23 22:47:47 -05:00
parent f3a8438904
commit 8d0b1f5acf
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
4 changed files with 9 additions and 50 deletions

View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>DeluxeGroups</artifactId>
<!-- Version is used in plugin.yml -->
<version>2.0</version>
<version>2.1</version>
<packaging>jar</packaging>
<!-- Plugin Information -->

View File

@ -1,26 +1,14 @@
package xyz.etztech.deluxegroups.listeners;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.commons.lang3.StringUtils;
import github.scarsz.discordsrv.dependencies.dev.vankka.mcdiscordreserializer.discord.DiscordSerializer;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import github.scarsz.discordsrv.dependencies.net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import github.scarsz.discordsrv.hooks.VaultHook;
import github.scarsz.discordsrv.hooks.world.MultiverseCoreHook;
import github.scarsz.discordsrv.util.DiscordUtil;
import github.scarsz.discordsrv.util.LangUtil;
import github.scarsz.discordsrv.util.PlaceholderUtil;
import github.scarsz.discordsrv.util.TimeUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import xyz.etztech.deluxegroups.DeluxeGroups;
import xyz.etztech.deluxegroups.events.GlobalChatEvent;
import xyz.etztech.deluxegroups.events.GroupChatEvent;
import static org.bukkit.Bukkit.getServer;
public class DGListener implements Listener {
private DeluxeGroups plugin;
@ -32,42 +20,12 @@ public class DGListener implements Listener {
@EventHandler
public void onGlobalChat(GlobalChatEvent event) {
TextChannel mainChannel = DiscordSRV.getPlugin().getMainTextChannel();
// FIXME Do we really need to copy/paste DiscordSRV code??
String channel = mainChannel.getName();
String message = event.getMessage();
Player player = event.getAuthor();
String userPrimaryGroup = VaultHook.getPrimaryGroup(player);
boolean hasGoodGroup = StringUtils.isNotBlank(userPrimaryGroup);
if (hasGoodGroup) {
userPrimaryGroup = userPrimaryGroup.substring(0, 1).toUpperCase() + userPrimaryGroup.substring(1);
if (mainChannel != null) {
String message = DiscordSRV.config().getString("MinecraftChatToDiscordMessageFormatNoPrimaryGroup").
replace("%displayname%", event.getAuthor().getName()).
replace("%message%", event.getMessage());
mainChannel.sendMessage(message).queue();
}
boolean reserializer = DiscordSRV.config().getBoolean("Experiment_MCDiscordReserializer_ToDiscord");
String username = DiscordUtil.strip(player.getName());
if (!reserializer) {
username = DiscordUtil.escapeMarkdown(username);
}
String discordMessage = (hasGoodGroup ? LangUtil.Message.CHAT_TO_DISCORD.toString() : LangUtil.Message.CHAT_TO_DISCORD_NO_PRIMARY_GROUP.toString()).replaceAll("%time%|%date%", TimeUtil.timeStamp()).replace("%channelname%", channel != null ? channel.substring(0, 1).toUpperCase() + channel.substring(1) : "").replace("%primarygroup%", userPrimaryGroup).replace("%username%", username).replace("%world%", player.getWorld().getName()).replace("%worldalias%", DiscordUtil.strip(MultiverseCoreHook.getWorldAlias(player.getWorld().getName())));
discordMessage = PlaceholderUtil.replacePlaceholdersToDiscord(discordMessage, player);
String displayName = DiscordUtil.strip(player.getDisplayName());
if (reserializer) {
message = DiscordSerializer.INSTANCE.serialize(LegacyComponentSerializer.legacy().deserialize(message));
} else {
displayName = DiscordUtil.escapeMarkdown(displayName);
}
discordMessage = discordMessage.replace("%displayname%", displayName).replace("%message%", message);
if (!reserializer) {
discordMessage = DiscordUtil.strip(discordMessage);
}
if (DiscordSRV.config().getBoolean("DiscordChatChannelTranslateMentions")) {
discordMessage = DiscordUtil.convertMentionsFromNames(discordMessage, DiscordSRV.getPlugin().getMainGuild());
} else {
discordMessage = discordMessage.replace("@", "@\u200b");
}
DiscordUtil.sendMessage(mainChannel, discordMessage);
}
@EventHandler

View File

@ -7,7 +7,7 @@ prefix:
# So, we have a few options to make players aware of group chat vs global chat
# If you don't want anything, leave these as-is
format:
color: ''
color: '&b'
# Custom format. The variables <group> and <message> are available and will be
# replaced by the group name and chat message respectively
custom: ''
@ -16,6 +16,6 @@ format:
discord:
# These have the same variables available as custom, but also <author> for the name of the speaker
# Discord to Minecraft. Can include color codes
dtm: '[&bDiscord &f| &b<group>&f] <author> > <message>'
dtm: '[&bDiscord &f| &b<group>&f] <author> > &b<message>'
# Minecraft to Discord
mtd: '<author> > <message>'

View File

@ -5,6 +5,7 @@ author: ${author}
website: ${url}
main: ${mainClass}
softdepend: [dynmap, MinecraftManager, DiscordSRV]
api-version: 1.15
commands:
deluxegroups:
description: Base DeluxeGroups command