mcMMO integration

This commit is contained in:
Vankka 2023-05-18 12:33:48 +03:00
parent 9ff2683a78
commit 1fa290402a
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 137 additions and 26 deletions

View File

@ -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)
}

View File

@ -249,6 +249,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap
// Chat Integrations
registerIntegration("com.discordsrv.bukkit.integration.chat.ChattyChatIntegration");
registerIntegration("com.discordsrv.bukkit.integration.chat.LunaChatIntegration");
registerIntegration("com.discordsrv.bukkit.integration.chat.McMMOChatIntegration");
registerIntegration("com.discordsrv.bukkit.integration.chat.TownyChatIntegration");
registerIntegration("com.discordsrv.bukkit.integration.chat.VentureChatIntegration");

View File

@ -0,0 +1,132 @@
package com.discordsrv.bukkit.integration.chat;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.EventPriority;
import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration;
import com.gmail.nossr50.api.ChatAPI;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.chat.author.PlayerAuthor;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcmmo.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class McMMOChatIntegration extends PluginIntegration<BukkitDiscordSRV> 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);
}
}
}

View File

@ -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')