parent
f3a8438904
commit
8d0b1f5acf
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
||||||
<groupId>xyz.etztech</groupId>
|
<groupId>xyz.etztech</groupId>
|
||||||
<artifactId>DeluxeGroups</artifactId>
|
<artifactId>DeluxeGroups</artifactId>
|
||||||
<!-- Version is used in plugin.yml -->
|
<!-- Version is used in plugin.yml -->
|
||||||
<version>2.0</version>
|
<version>2.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<!-- Plugin Information -->
|
<!-- Plugin Information -->
|
||||||
|
|
|
@ -1,26 +1,14 @@
|
||||||
package xyz.etztech.deluxegroups.listeners;
|
package xyz.etztech.deluxegroups.listeners;
|
||||||
|
|
||||||
import github.scarsz.discordsrv.DiscordSRV;
|
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.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.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import xyz.etztech.deluxegroups.DeluxeGroups;
|
import xyz.etztech.deluxegroups.DeluxeGroups;
|
||||||
import xyz.etztech.deluxegroups.events.GlobalChatEvent;
|
import xyz.etztech.deluxegroups.events.GlobalChatEvent;
|
||||||
import xyz.etztech.deluxegroups.events.GroupChatEvent;
|
import xyz.etztech.deluxegroups.events.GroupChatEvent;
|
||||||
|
|
||||||
import static org.bukkit.Bukkit.getServer;
|
|
||||||
|
|
||||||
public class DGListener implements Listener {
|
public class DGListener implements Listener {
|
||||||
|
|
||||||
private DeluxeGroups plugin;
|
private DeluxeGroups plugin;
|
||||||
|
@ -32,42 +20,12 @@ public class DGListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onGlobalChat(GlobalChatEvent event) {
|
public void onGlobalChat(GlobalChatEvent event) {
|
||||||
TextChannel mainChannel = DiscordSRV.getPlugin().getMainTextChannel();
|
TextChannel mainChannel = DiscordSRV.getPlugin().getMainTextChannel();
|
||||||
|
if (mainChannel != null) {
|
||||||
// FIXME Do we really need to copy/paste DiscordSRV code??
|
String message = DiscordSRV.config().getString("MinecraftChatToDiscordMessageFormatNoPrimaryGroup").
|
||||||
String channel = mainChannel.getName();
|
replace("%displayname%", event.getAuthor().getName()).
|
||||||
String message = event.getMessage();
|
replace("%message%", event.getMessage());
|
||||||
Player player = event.getAuthor();
|
mainChannel.sendMessage(message).queue();
|
||||||
String userPrimaryGroup = VaultHook.getPrimaryGroup(player);
|
|
||||||
boolean hasGoodGroup = StringUtils.isNotBlank(userPrimaryGroup);
|
|
||||||
if (hasGoodGroup) {
|
|
||||||
userPrimaryGroup = userPrimaryGroup.substring(0, 1).toUpperCase() + userPrimaryGroup.substring(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@EventHandler
|
||||||
|
|
|
@ -7,7 +7,7 @@ prefix:
|
||||||
# So, we have a few options to make players aware of group chat vs global chat
|
# 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
|
# If you don't want anything, leave these as-is
|
||||||
format:
|
format:
|
||||||
color: ''
|
color: '&b'
|
||||||
# Custom format. The variables <group> and <message> are available and will be
|
# Custom format. The variables <group> and <message> are available and will be
|
||||||
# replaced by the group name and chat message respectively
|
# replaced by the group name and chat message respectively
|
||||||
custom: ''
|
custom: ''
|
||||||
|
@ -16,6 +16,6 @@ format:
|
||||||
discord:
|
discord:
|
||||||
# These have the same variables available as custom, but also <author> for the name of the speaker
|
# These have the same variables available as custom, but also <author> for the name of the speaker
|
||||||
# Discord to Minecraft. Can include color codes
|
# 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
|
# Minecraft to Discord
|
||||||
mtd: '<author> > <message>'
|
mtd: '<author> > <message>'
|
|
@ -5,6 +5,7 @@ author: ${author}
|
||||||
website: ${url}
|
website: ${url}
|
||||||
main: ${mainClass}
|
main: ${mainClass}
|
||||||
softdepend: [dynmap, MinecraftManager, DiscordSRV]
|
softdepend: [dynmap, MinecraftManager, DiscordSRV]
|
||||||
|
api-version: 1.15
|
||||||
commands:
|
commands:
|
||||||
deluxegroups:
|
deluxegroups:
|
||||||
description: Base DeluxeGroups command
|
description: Base DeluxeGroups command
|
||||||
|
|
Loading…
Reference in New Issue