mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Add basic support for EssentialsDiscord
This commit is contained in:
5 files changed
+108
-3
No files matched your search
@@ -18,7 +18,8 @@ dependencies {
|
||||
implementation(libs.bstatsBukkit)
|
||||
|
||||
// Plugins
|
||||
compileOnly("me.clip:placeholderapi:2.10.9")
|
||||
compileOnly("me.clip:placeholderapi:2.10.9") // TODO: move this to libs.versions.yml
|
||||
compileOnly(libs.essentialsXDiscord)
|
||||
}
|
||||
|
||||
carbonShadowPlatform {
|
||||
@@ -43,8 +44,7 @@ bukkit {
|
||||
apiVersion = "1.16"
|
||||
author = "Draycia"
|
||||
depend = listOf("LuckPerms")
|
||||
softDepend = listOf("PlaceholderAPI")
|
||||
loadBefore = listOf("Essentials")
|
||||
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord")
|
||||
website = GITHUB_REPO_URL
|
||||
permissions {
|
||||
register("carbon.clearchat") {
|
||||
|
||||
@@ -36,6 +36,7 @@ import net.draycia.carbon.api.users.UserManager;
|
||||
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.util.BukkitMessageRenderer;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
@@ -124,6 +125,16 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
// Load channels
|
||||
((CarbonChannelRegistry) this.channelRegistry()).loadConfigChannels();
|
||||
|
||||
this.discoverDiscordHooks();
|
||||
}
|
||||
|
||||
private void discoverDiscordHooks() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord")) {
|
||||
final DiscordMessageListener discordMessageListener = this.injector.getInstance(DiscordMessageListener.class);
|
||||
Bukkit.getPluginManager().registerEvents(discordMessageListener, this);
|
||||
discordMessageListener.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
||||
import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
||||
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.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class DiscordMessageListener implements Listener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private Map<Key, MessageType> channelMessageTypes = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public DiscordMessageListener(final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
// Minecraft -> Discord
|
||||
@EventHandler
|
||||
public void onDiscordMessage(final DiscordMessageEvent event) {
|
||||
if (!event.getType().equals(MessageType.DefaultTypes.CHAT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var result = this.carbonChat.server().player(event.getUUID()).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
var channel = result.player().selectedChannel();
|
||||
|
||||
if (channel == null) {
|
||||
channel = this.carbonChat.channelRegistry().defaultValue();
|
||||
}
|
||||
|
||||
final var messageType = this.channelMessageTypes.get(channel.key());
|
||||
|
||||
event.setType(messageType);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDiscordMessage(final DiscordRelayEvent event) {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
final @Nullable DiscordService discord = Bukkit.getServicesManager().load(DiscordService.class);
|
||||
|
||||
if (discord != null) {
|
||||
this.carbonChat.channelRegistry().forEach(channel -> {
|
||||
final MessageType channelMessageType = new MessageType(channel.key().value());
|
||||
discord.registerMessageType((CarbonChatBukkit) this.carbonChat, channelMessageType);
|
||||
this.channelMessageTypes.put(channel.key(), channelMessageType);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,7 @@ versions:
|
||||
fabricLoader: 0.12.12
|
||||
adventurePlatformFabric: 5.0.0
|
||||
luckPermsApi: 5.3
|
||||
essentialsx: 2.19.1-SNAPSHOT
|
||||
|
||||
dependencies:
|
||||
adventureBom:
|
||||
@@ -212,4 +213,9 @@ dependencies:
|
||||
name: api
|
||||
version: { ref: luckPermsApi }
|
||||
|
||||
essentialsXDiscord:
|
||||
group: net.essentialsx
|
||||
name: EssentialsXDiscord
|
||||
version: { ref: essentialsx }
|
||||
|
||||
bundles:
|
||||
@@ -33,6 +33,9 @@ dependencyResolutionManagement {
|
||||
maven("https://jitpack.io") {
|
||||
content { includeGroupByRegex("com\\.github\\..*") }
|
||||
}
|
||||
// EssentialsDiscord
|
||||
//maven("https://repo.essentialsx.net/releases/")
|
||||
maven("https://repo.essentialsx.net/snapshots/")
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user