mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Add support for DSRV
This commit is contained in:
1 parent
4b09232e57
commit
f13e7732db
12 files changed
+396
-3
No files matched your search
@@ -20,6 +20,7 @@ dependencies {
|
||||
// Plugins
|
||||
compileOnly("me.clip:placeholderapi:2.10.9") // TODO: move this to libs.versions.yml
|
||||
compileOnly(libs.essentialsXDiscord)
|
||||
compileOnly(libs.discordsrv)
|
||||
}
|
||||
|
||||
carbonShadowPlatform {
|
||||
@@ -44,7 +45,7 @@ bukkit {
|
||||
apiVersion = "1.18"
|
||||
author = "Draycia"
|
||||
depend = listOf("LuckPerms")
|
||||
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord")
|
||||
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord", "DiscordSRV")
|
||||
website = GITHUB_REPO_URL
|
||||
permissions {
|
||||
register("carbon.clearchat") {
|
||||
|
||||
@@ -37,6 +37,7 @@ import net.draycia.carbon.api.util.RenderedMessage;
|
||||
import net.draycia.carbon.bukkit.listeners.BukkitChatListener;
|
||||
import net.draycia.carbon.bukkit.listeners.BukkitPlayerJoinListener;
|
||||
import net.draycia.carbon.bukkit.listeners.DiscordMessageListener;
|
||||
import net.draycia.carbon.bukkit.listeners.DiscordSRVListener;
|
||||
import net.draycia.carbon.bukkit.util.BukkitMessageRenderer;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
@@ -135,6 +136,10 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
Bukkit.getPluginManager().registerEvents(discordMessageListener, this);
|
||||
discordMessageListener.init();
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
|
||||
this.injector.getInstance(DiscordSRVListener.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,6 +123,7 @@ public final class BukkitChatListener implements Listener {
|
||||
|
||||
try {
|
||||
event.viewers().clear();
|
||||
event.setCancelled(true);
|
||||
} catch (final UnsupportedOperationException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
+7
-2
@@ -29,6 +29,7 @@ import net.essentialsx.api.v2.events.discord.DiscordRelayEvent;
|
||||
import net.essentialsx.api.v2.services.discord.DiscordService;
|
||||
import net.essentialsx.api.v2.services.discord.MessageType;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -37,11 +38,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class DiscordMessageListener implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private Map<Key, MessageType> channelMessageTypes = new HashMap<>();
|
||||
private final Map<Key, MessageType> channelMessageTypes = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public DiscordMessageListener(final CarbonChat carbonChat) {
|
||||
public DiscordMessageListener(
|
||||
final CarbonChat carbonChat,
|
||||
final Logger logger
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
logger.info("EssentialsXDiscord found! Enabling hook.");
|
||||
}
|
||||
|
||||
// Minecraft -> Discord
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.bukkit.listeners;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import github.scarsz.discordsrv.api.Subscribe;
|
||||
import github.scarsz.discordsrv.api.events.DiscordReadyEvent;
|
||||
import github.scarsz.discordsrv.api.events.GameChatMessagePostProcessEvent;
|
||||
import net.draycia.carbon.bukkit.util.CarbonChatHook;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Singleton
|
||||
public final class DiscordSRVListener {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
public DiscordSRVListener(final Logger logger) {
|
||||
this.logger = logger;
|
||||
|
||||
this.logger.info("DiscordSRV found! Enabling hook.");
|
||||
DiscordSRV.api.subscribe(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDiscordReady(final DiscordReadyEvent event) {
|
||||
DiscordSRV.getPlugin().getPluginHooks().add(new CarbonChatHook());
|
||||
this.logger.info("Successfully enabled DiscordSRV hook!");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameChat(final GameChatMessagePostProcessEvent event) {
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -158,4 +158,8 @@ public final class CarbonPlayerBukkit extends WrappedCarbonPlayer implements For
|
||||
.anyMatch(MetadataValue::asBoolean);
|
||||
}
|
||||
|
||||
public @Nullable Player bukkitPlayer() {
|
||||
return Bukkit.getPlayer(this.uuid());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.bukkit.util;
|
||||
|
||||
import github.scarsz.discordsrv.Debug;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import github.scarsz.discordsrv.dependencies.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import github.scarsz.discordsrv.hooks.chat.ChatHook;
|
||||
import github.scarsz.discordsrv.util.PluginUtil;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.bukkit.users.CarbonPlayerBukkit;
|
||||
import net.draycia.carbon.common.util.ChannelUtils;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class CarbonChatHook implements ChatHook {
|
||||
|
||||
public CarbonChatHook() {
|
||||
CarbonChatProvider.carbonChat().eventHandler().subscribe(CarbonChatEvent.class, event -> {
|
||||
final ChatChannel chatChannel = event.chatChannel();
|
||||
final CarbonPlayer carbonPlayer = event.sender();
|
||||
|
||||
DiscordSRV.debug(Debug.MINECRAFT_TO_DISCORD, "Received a CarbonChatEvent (player: " + carbonPlayer.username() + ")");
|
||||
|
||||
final @Nullable Player player = ((CarbonPlayerBukkit) carbonPlayer).bukkitPlayer();
|
||||
final String message = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||
|
||||
if (player != null) {
|
||||
DiscordSRV.getPlugin().processChatMessage(player, message, chatChannel.commandName(), event.result().cancelled());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
||||
final String mmFormattedMessage = MiniMessage.get().serialize(message);
|
||||
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, ChannelUtils.locateChannel(channel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin() {
|
||||
return PluginUtil.getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user