mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +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)
|
implementation(libs.bstatsBukkit)
|
||||||
|
|
||||||
// Plugins
|
// 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 {
|
carbonShadowPlatform {
|
||||||
@@ -43,8 +44,7 @@ bukkit {
|
|||||||
apiVersion = "1.16"
|
apiVersion = "1.16"
|
||||||
author = "Draycia"
|
author = "Draycia"
|
||||||
depend = listOf("LuckPerms")
|
depend = listOf("LuckPerms")
|
||||||
softDepend = listOf("PlaceholderAPI")
|
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord")
|
||||||
loadBefore = listOf("Essentials")
|
|
||||||
website = GITHUB_REPO_URL
|
website = GITHUB_REPO_URL
|
||||||
permissions {
|
permissions {
|
||||||
register("carbon.clearchat") {
|
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.api.util.RenderedMessage;
|
||||||
import net.draycia.carbon.bukkit.listeners.BukkitChatListener;
|
import net.draycia.carbon.bukkit.listeners.BukkitChatListener;
|
||||||
import net.draycia.carbon.bukkit.listeners.BukkitPlayerJoinListener;
|
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.bukkit.util.BukkitMessageRenderer;
|
||||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||||
@@ -124,6 +125,16 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
|
|
||||||
// Load channels
|
// Load channels
|
||||||
((CarbonChannelRegistry) this.channelRegistry()).loadConfigChannels();
|
((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
|
@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
|
fabricLoader: 0.12.12
|
||||||
adventurePlatformFabric: 5.0.0
|
adventurePlatformFabric: 5.0.0
|
||||||
luckPermsApi: 5.3
|
luckPermsApi: 5.3
|
||||||
|
essentialsx: 2.19.1-SNAPSHOT
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
adventureBom:
|
adventureBom:
|
||||||
@@ -212,4 +213,9 @@ dependencies:
|
|||||||
name: api
|
name: api
|
||||||
version: { ref: luckPermsApi }
|
version: { ref: luckPermsApi }
|
||||||
|
|
||||||
|
essentialsXDiscord:
|
||||||
|
group: net.essentialsx
|
||||||
|
name: EssentialsXDiscord
|
||||||
|
version: { ref: essentialsx }
|
||||||
|
|
||||||
bundles:
|
bundles:
|
||||||
@@ -33,6 +33,9 @@ dependencyResolutionManagement {
|
|||||||
maven("https://jitpack.io") {
|
maven("https://jitpack.io") {
|
||||||
content { includeGroupByRegex("com\\.github\\..*") }
|
content { includeGroupByRegex("com\\.github\\..*") }
|
||||||
}
|
}
|
||||||
|
// EssentialsDiscord
|
||||||
|
//maven("https://repo.essentialsx.net/releases/")
|
||||||
|
maven("https://repo.essentialsx.net/snapshots/")
|
||||||
}
|
}
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user