From 780c1d0759f974ce12652dbc75309dde2dde9ecb Mon Sep 17 00:00:00 2001 From: Vankka Date: Mon, 12 Aug 2024 14:30:38 +0300 Subject: [PATCH] Rename some things, prepare for providing chat suggestions --- bukkit/build.gradle | 2 +- .../listener/chat/IBukkitChatForwarder.java | 2 +- .../listener/chat/PaperChatListener.java | 2 +- .../bukkit/player/SpigotPlayer.java | 29 ++++++++++++++++--- .../listener/chat/BukkitChatForwarder.java | 2 +- .../listener/chat/BukkitChatListener.java | 2 +- .../bukkit/player/BukkitPlayer.java | 11 +++++++ .../bungee/player/BungeePlayer.java | 11 +++++++ .../common/abstraction/player/IPlayer.java | 9 ++++-- .../MinecraftToDiscordChatConfig.java | 2 +- .../feature/mention/MentionCachingModule.java | 2 +- .../mention/MentionGameRenderingModule.java | 4 +-- .../game/MinecraftToDiscordChatModule.java | 13 ++++----- .../common/util/GamePermissionUtil.java | 25 ++++++++-------- settings.gradle | 6 ++-- velocity/build.gradle | 10 +++++-- .../velocity/player/VelocityPlayer.java | 11 +++++++ 17 files changed, 104 insertions(+), 39 deletions(-) diff --git a/bukkit/build.gradle b/bukkit/build.gradle index f95e5694..abff6eea 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -28,7 +28,7 @@ tasks.register('generateResourceForCommodore', GenerateDependencyDownloadResourc allprojects { repositories { - maven { url 'https://papermc.io/repo/repository/maven-public/' } + maven { url 'https://repo.papermc.io/repository/maven-public/' } maven { url 'https://nexus.scarsz.me/content/groups/public/' } maven { url 'https://repo.essentialsx.net/releases/' } } diff --git a/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/IBukkitChatForwarder.java b/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/IBukkitChatForwarder.java index 790b719e..b10a5c16 100644 --- a/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/IBukkitChatForwarder.java +++ b/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/IBukkitChatForwarder.java @@ -24,6 +24,6 @@ import org.bukkit.event.Event; public interface IBukkitChatForwarder { - MinecraftComponent annotateChatMessage(Event event, Player player, MinecraftComponent component); + MinecraftComponent renderChatMessage(Event event, Player player, MinecraftComponent component); void forwardMessage(Event event, Player player, MinecraftComponent component, boolean cancelled); } diff --git a/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/PaperChatListener.java b/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/PaperChatListener.java index abcd9a4a..3f2b1de6 100644 --- a/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/PaperChatListener.java +++ b/bukkit/paper/src/main/java/com/discordsrv/bukkit/listener/chat/PaperChatListener.java @@ -70,7 +70,7 @@ public class PaperChatListener implements Listener { } MinecraftComponent component = GET_MESSAGE_HANDLE.getComponent(event); - MinecraftComponent annotated = listener.annotateChatMessage(event, event.getPlayer(), component); + MinecraftComponent annotated = listener.renderChatMessage(event, event.getPlayer(), component); if (annotated != null) { try { SET_MESSAGE_HANDLE.invoke(event, annotated.asAdventure()); diff --git a/bukkit/spigot/src/main/java/com/discordsrv/bukkit/player/SpigotPlayer.java b/bukkit/spigot/src/main/java/com/discordsrv/bukkit/player/SpigotPlayer.java index b613b50f..dfc770c2 100644 --- a/bukkit/spigot/src/main/java/com/discordsrv/bukkit/player/SpigotPlayer.java +++ b/bukkit/spigot/src/main/java/com/discordsrv/bukkit/player/SpigotPlayer.java @@ -23,27 +23,34 @@ import org.bukkit.entity.Player; import org.bukkit.profile.PlayerTextures; import java.net.URL; +import java.util.Collection; import java.util.Locale; public final class SpigotPlayer { private SpigotPlayer() {} - private static final boolean playerProfileExists; + private static final boolean PLAYER_PROFILE_EXISTS; + private static final boolean CHATSUGGESTIONS_METHODS_AVAILABLE; static { Class playerClass = Player.class; - boolean playerProfile = false; + boolean playerProfile = false, chatSuggestions = false; try { playerClass.getMethod("getPlayerProfile"); playerProfile = true; } catch (ReflectiveOperationException ignored) {} - playerProfileExists = playerProfile; + try { + playerClass.getMethod("addCustomChatCompletions", Collection.class); + chatSuggestions = true; + } catch (ReflectiveOperationException ignored) {} + PLAYER_PROFILE_EXISTS = playerProfile; + CHATSUGGESTIONS_METHODS_AVAILABLE = chatSuggestions; } public static SkinInfo getSkinInfo(Player player) { - if (!playerProfileExists) { + if (!PLAYER_PROFILE_EXISTS) { return null; } @@ -60,4 +67,18 @@ public final class SpigotPlayer { textures.getSkinModel().toString().toLowerCase(Locale.ROOT) ); } + + public static void addChatSuggestions(Player player, Collection suggestions) { + if (!CHATSUGGESTIONS_METHODS_AVAILABLE) { + return; + } + player.addCustomChatCompletions(suggestions); + } + + public static void removeChatSuggestions(Player player, Collection suggestions) { + if (!CHATSUGGESTIONS_METHODS_AVAILABLE) { + return; + } + player.removeCustomChatCompletions(suggestions); + } } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatForwarder.java b/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatForwarder.java index d252a50b..888c7034 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatForwarder.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatForwarder.java @@ -49,7 +49,7 @@ public class BukkitChatForwarder implements IBukkitChatForwarder { } @Override - public MinecraftComponent annotateChatMessage(Event event, Player player, MinecraftComponent component) { + public MinecraftComponent renderChatMessage(Event event, Player player, MinecraftComponent component) { IPlayer srvPlayer = discordSRV.playerProvider().player(player); GameChatRenderEvent annotateEvent = new GameChatRenderEvent( event, diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatListener.java b/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatListener.java index 34aca905..be2e547a 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatListener.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/listener/chat/BukkitChatListener.java @@ -39,7 +39,7 @@ public class BukkitChatListener implements Listener { MinecraftComponent component = ComponentUtil.toAPI( BukkitComponentSerializer.legacy().deserialize(event.getMessage())); - MinecraftComponent annotated = forwarder.annotateChatMessage(event, event.getPlayer(), component); + MinecraftComponent annotated = forwarder.renderChatMessage(event, event.getPlayer(), component); if (annotated != null) { event.setMessage(BukkitComponentSerializer.legacy().serialize(ComponentUtil.fromAPI(annotated))); } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java index 77a9d3ee..5279bd8f 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import java.util.Collection; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -94,6 +95,16 @@ public class BukkitPlayer extends BukkitCommandSender implements IPlayer { }); } + @Override + public void addChatSuggestions(Collection suggestions) { + SpigotPlayer.addChatSuggestions(player, suggestions); + } + + @Override + public void removeChatSuggestions(Collection suggestions) { + SpigotPlayer.removeChatSuggestions(player, suggestions); + } + @Override public @Nullable SkinInfo skinInfo() { return SpigotPlayer.getSkinInfo(player); diff --git a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java index a87fda13..7e1fea7f 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java +++ b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java @@ -31,6 +31,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -61,6 +62,16 @@ public class BungeePlayer extends BungeeCommandSender implements IPlayer { return CompletableFuture.completedFuture(null); } + @Override + public void addChatSuggestions(Collection suggestions) { + // API missing + } + + @Override + public void removeChatSuggestions(Collection suggestions) { + // API missing + } + @Override public @Nullable SkinInfo skinInfo() { return null; diff --git a/common/src/main/java/com/discordsrv/common/abstraction/player/IPlayer.java b/common/src/main/java/com/discordsrv/common/abstraction/player/IPlayer.java index f769d5f5..af21825a 100644 --- a/common/src/main/java/com/discordsrv/common/abstraction/player/IPlayer.java +++ b/common/src/main/java/com/discordsrv/common/abstraction/player/IPlayer.java @@ -21,6 +21,7 @@ package com.discordsrv.common.abstraction.player; import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.placeholder.annotation.Placeholder; import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix; +import com.discordsrv.api.placeholder.format.FormattedText; import com.discordsrv.api.player.DiscordSRVPlayer; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.command.game.sender.ICommandSender; @@ -34,6 +35,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -68,6 +70,9 @@ public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSende CompletableFuture kick(Component component); + void addChatSuggestions(Collection suggestions); + void removeChatSuggestions(Collection suggestions); + @NotNull @Placeholder("display_name") Component displayName(); @@ -96,14 +101,14 @@ public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSende @Nullable @ApiStatus.NonExtendable @Placeholder("meta_prefix") - default Component getMetaPrefix() { + default FormattedText getMetaPrefix() { return GamePermissionUtil.getMetaPrefix(discordSRV(), uniqueId()); } @Nullable @ApiStatus.NonExtendable @Placeholder("meta_suffix") - default Component getMetaSuffix() { + default FormattedText getMetaSuffix() { return GamePermissionUtil.getMetaSuffix(discordSRV(), uniqueId()); } diff --git a/common/src/main/java/com/discordsrv/common/config/main/channels/MinecraftToDiscordChatConfig.java b/common/src/main/java/com/discordsrv/common/config/main/channels/MinecraftToDiscordChatConfig.java index 679fb946..cf971ea2 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/channels/MinecraftToDiscordChatConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/channels/MinecraftToDiscordChatConfig.java @@ -91,7 +91,7 @@ public class MinecraftToDiscordChatConfig implements IMessageConfig { + "The player needs the discordsrv.mention.everyone permission to render the mention and trigger a notification") public boolean everyone = false; - public boolean anyCaching() { + public boolean any() { return roles || channels || users; } } diff --git a/common/src/main/java/com/discordsrv/common/feature/mention/MentionCachingModule.java b/common/src/main/java/com/discordsrv/common/feature/mention/MentionCachingModule.java index 68d6f811..342d8d69 100644 --- a/common/src/main/java/com/discordsrv/common/feature/mention/MentionCachingModule.java +++ b/common/src/main/java/com/discordsrv/common/feature/mention/MentionCachingModule.java @@ -100,7 +100,7 @@ public class MentionCachingModule extends AbstractModule { continue; } - if (config.mentions.anyCaching()) { + if (config.mentions.any()) { return true; } } diff --git a/common/src/main/java/com/discordsrv/common/feature/mention/MentionGameRenderingModule.java b/common/src/main/java/com/discordsrv/common/feature/mention/MentionGameRenderingModule.java index b613e15d..bd7f45a5 100644 --- a/common/src/main/java/com/discordsrv/common/feature/mention/MentionGameRenderingModule.java +++ b/common/src/main/java/com/discordsrv/common/feature/mention/MentionGameRenderingModule.java @@ -54,7 +54,7 @@ public class MentionGameRenderingModule extends AbstractModule { } MinecraftToDiscordChatConfig.Mentions mentions = config.mentions; - if (mentions.renderMentionsInGame && mentions.anyCaching()) { + if (mentions.renderMentionsInGame && mentions.any()) { return true; } @@ -63,7 +63,7 @@ public class MentionGameRenderingModule extends AbstractModule { } @Subscribe - public void onGameChatAnnotate(GameChatRenderEvent event) { + public void onGameChatRender(GameChatRenderEvent event) { if (checkCancellation(event) || checkProcessor(event)) { return; } diff --git a/common/src/main/java/com/discordsrv/common/feature/messageforwarding/game/MinecraftToDiscordChatModule.java b/common/src/main/java/com/discordsrv/common/feature/messageforwarding/game/MinecraftToDiscordChatModule.java index ba126f1f..3c476d58 100644 --- a/common/src/main/java/com/discordsrv/common/feature/messageforwarding/game/MinecraftToDiscordChatModule.java +++ b/common/src/main/java/com/discordsrv/common/feature/messageforwarding/game/MinecraftToDiscordChatModule.java @@ -145,20 +145,19 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule perm.getPrefix(uuid)); } @@ -50,16 +61,6 @@ public final class GamePermissionUtil { return getLegacy(discordSRV, "suffix", perm -> perm.getSuffix(uuid)); } - private static Component getMeta(DiscordSRV discordSRV, UUID uuid, String metaKey) { - PermissionModule.Meta meta = discordSRV.getModule(PermissionModule.Meta.class); - if (meta == null) { - return null; - } - - String data = meta.getMeta(uuid, metaKey).join(); - return translate(discordSRV, data); - } - private static Component getLegacy( DiscordSRV discordSRV, String what, diff --git a/settings.gradle b/settings.gradle index 13f866c1..e572b59f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,7 +20,7 @@ dependencyResolutionManagement { // Bukkit version('bukkit_minimum', '1.8.8-R0.1-SNAPSHOT') version('bukkit1_12', '1.12.2-R0.1-SNAPSHOT') - version('bukkit_latest', '1.20.1-R0.1-SNAPSHOT') + version('bukkit_latest', '1.21.1-R0.1-SNAPSHOT') version('folia', '1.20.1-R0.1-SNAPSHOT') library('paperapi', 'io.papermc.paper', 'paper-api').versionRef('bukkit_latest') library('spigotapi', 'org.spigotmc', 'spigot-api').versionRef('bukkit_latest') @@ -29,10 +29,10 @@ dependencyResolutionManagement { library('folia', 'dev.folia', 'folia-api').versionRef('folia') // Bungee - library('bungee', 'net.md-5', 'bungeecord-api').version('1.17-R0.1-SNAPSHOT') + library('bungee', 'net.md-5', 'bungeecord-api').version('1.21-R0.1-SNAPSHOT') // Velocity - library('velocity', 'com.velocitypowered', 'velocity-api').version('3.0.0') + library('velocity', 'com.velocitypowered', 'velocity-api').version('3.3.0-SNAPSHOT') // DependencyDownload version('dependencydownload', '1.3.1') diff --git a/velocity/build.gradle b/velocity/build.gradle index febea034..650bcd7a 100644 --- a/velocity/build.gradle +++ b/velocity/build.gradle @@ -2,6 +2,10 @@ apply from: rootProject.file('buildscript/standalone.gradle') apply plugin: 'net.kyori.blossom' apply plugin: 'org.jetbrains.gradle.plugin.idea-ext' +java { + disableAutoTargetJvm() // Requires Java 17, we target 8 +} + sourceSets { main { blossom { @@ -21,7 +25,7 @@ shadowJar { repositories { exclusiveContent { forRepository { - maven { url 'https://nexus.velocitypowered.com/repository/maven-public/' } + maven { url 'https://repo.papermc.io/repository/maven-public/' } } filter { includeGroup 'com.velocitypowered' @@ -39,7 +43,9 @@ dependencies { // Platform annotationProcessor(libs.velocity) - compileOnly(libs.velocity) + compileOnly(libs.velocity) { + exclude module: 'caffeine' + } // DependencyDownload implementation(libs.mcdependencydownload.velocity) diff --git a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java index 92680763..7b6c1787 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java +++ b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java @@ -31,6 +31,7 @@ import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -59,6 +60,16 @@ public class VelocityPlayer extends VelocityCommandSender implements IPlayer { return CompletableFuture.completedFuture(null); } + @Override + public void addChatSuggestions(Collection suggestions) { + player.addCustomChatCompletions(suggestions); + } + + @Override + public void removeChatSuggestions(Collection suggestions) { + player.removeCustomChatCompletions(suggestions); + } + @Override public @Nullable SkinInfo skinInfo() { for (GameProfile.Property property : player.getGameProfile().getProperties()) {