diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 3e803d1b..e898d7dd 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -28,32 +28,8 @@ tasks.register('generateResourceForCommodore', GenerateDependencyDownloadResourc allprojects { repositories { - exclusiveContent { - forRepository { - maven { url 'https://papermc.io/repo/repository/maven-public/' } - } - filter { - includeGroup 'com.destroystokyo.paper' - includeGroup 'io.papermc.paper' - includeGroup 'dev.folia' - includeGroup 'org.spigotmc' - includeGroup 'net.md-5' - } - } - - exclusiveContent { - forRepository { - maven { url 'https://nexus.scarsz.me/content/groups/public/' } - } - filter { - includeGroup 'net.milkbowl.vault' - includeGroup 'me.clip' - includeGroup 'com.palmergames.bukkit' - includeGroup 'mineverse.aust1n46' - includeGroup 'ru.mrbrikster' - includeGroup 'com.github.ucchyocean.lc' - } - } + maven { url 'https://papermc.io/repo/repository/maven-public/' } + maven { url 'https://nexus.scarsz.me/content/groups/public/' } } } @@ -95,6 +71,7 @@ dependencies { // Chat Integrations compileOnly(libs.chatty) compileOnly(libs.lunachat) + compileOnly(libs.mcmmo) compileOnly(libs.townychat) compileOnly(libs.venturechat) } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java index 959b2c9d..8c52a7ce 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java @@ -249,6 +249,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV implements Listener { + + private final McMMOAdminChannel adminChannel = new McMMOAdminChannel(); + + public McMMOChatIntegration(BukkitDiscordSRV discordSRV) { + super(discordSRV, new NamedLogger(discordSRV, "MCMMO")); + } + + @Override + public @NotNull String getIntegrationName() { + return "mcMMO"; + } + + @Override + public boolean isEnabled() { + try { + Class.forName("com.gmail.nossr50.mcMMO"); + } catch (ClassNotFoundException ignored) { + return false; + } + + return super.isEnabled(); + } + + @Override + public void enable() { + discordSRV.server().getPluginManager().registerEvents(this, discordSRV.plugin()); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + @Subscribe(priority = EventPriority.EARLY) + public void onGameChatMessageReceive(GameChatMessageReceiveEvent event) { + Player player = discordSRV.server().getPlayer(event.getPlayer().uniqueId()); + if (!player.hasMetadata("mcMMO: Player Data")) { + return; + } + + if (ChatAPI.isUsingPartyChat(player) || ChatAPI.isUsingAdminChat(player)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = org.bukkit.event.EventPriority.MONITOR) + public void onMcMMOAdminChat(McMMOAdminChatEvent event) { + Author author = event.getAuthor(); + if (!author.isPlayer()) return; + + Player player = ((PlayerAuthor) author).getPlayer(); + + String json = GsonComponentSerializer.gson().serialize(event.getChatMessage().getChatMessage()); + MinecraftComponent component = ComponentUtil.toAPI( + BukkitComponentSerializer.gson().deserialize(json) + ); + + discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( + new GameChatMessageReceiveEvent( + event, + discordSRV.playerProvider().player(player), + component, + adminChannel, + event.isCancelled() + ) + )); + } + + @Subscribe + public void onGameChannelLookup(GameChannelLookupEvent event) { + if (checkProcessor(event)) { + return; + } + + if (event.getChannelName().equalsIgnoreCase(adminChannel.getChannelName())) { + event.process(adminChannel); + } + } + + private class McMMOAdminChannel implements GameChannel { + + @Override + public @NotNull String getOwnerName() { + return getIntegrationName(); + } + + @Override + public @NotNull String getChannelName() { + return "admin"; + } + + @Override + public boolean isChat() { + return true; + } + + @Override + public void sendMessage(@NotNull MinecraftComponent component) { + mcMMO mcMMO = (mcMMO) discordSRV.server().getPluginManager().getPlugin("mcMMO"); + if (mcMMO == null) return; + + String message = BukkitComponentSerializer.legacy().serialize(ComponentUtil.fromAPI(component)); + mcMMO.getChatManager().processConsoleMessage(message); + } + } +} diff --git a/settings.gradle b/settings.gradle index 5afe4e65..01f4560c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -109,6 +109,7 @@ dependencyResolutionManagement { library('venturechat', 'mineverse.aust1n46', 'venturechat').version('3.5.0') library('chatty', 'ru.mrbrikster', 'chatty-api').version('2.19.13') library('lunachat', 'com.github.ucchyocean.lc', 'LunaChat').version('3.0.16') + library('mcmmo', 'com.gmail.nossr50', 'mcmmo').version('2.1.220') // Logging library('slf4j-api', 'org.slf4j', 'slf4j-api').version('1.7.36')