From a0fdd6d9977e75b0262a89499212a818586b33fc Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel Date: Sun, 10 Sep 2023 18:15:01 +0400 Subject: [PATCH] welcome adventure api MiniMessage is now used for Messages.yml fix bug when from is null when server change --- RedisBungee-API/build.gradle.kts | 7 +++++ .../redisbungee/AbstractRedisBungeeAPI.java | 31 ++++++++++++++++++- .../redisbungee/api/PlayerDataManager.java | 13 +++++--- .../redisbungee/api/RedisBungeePlugin.java | 3 +- .../api/config/RedisBungeeConfiguration.java | 4 +-- .../src/main/resources/messages.yml | 8 ++--- RedisBungee-Bungee/build.gradle.kts | 4 +++ .../redisbungee/BungeePlayerDataManager.java | 9 ++++-- .../minecraft/redisbungee/RedisBungee.java | 6 ++-- RedisBungee-Velocity/build.gradle.kts | 8 +++++ .../RedisBungeeVelocityPlugin.java | 6 ++-- .../VelocityPlayerDataManager.java | 8 ++--- 12 files changed, 84 insertions(+), 23 deletions(-) diff --git a/RedisBungee-API/build.gradle.kts b/RedisBungee-API/build.gradle.kts index 933d566..98eb1ff 100644 --- a/RedisBungee-API/build.gradle.kts +++ b/RedisBungee-API/build.gradle.kts @@ -23,6 +23,13 @@ dependencies { api("com.squareup.okhttp:okhttp:2.7.5") api("org.spongepowered:configurate-yaml:$configurateVersion") api("com.github.ben-manes.caffeine:caffeine:3.1.8") + + api("net.kyori:adventure-api:4.14.0") + api("net.kyori:adventure-text-serializer-gson:4.14.0") + api("net.kyori:adventure-text-serializer-legacy:4.14.0") + api("net.kyori:adventure-text-serializer-plain:4.14.0") + api("net.kyori:adventure-text-minimessage:4.14.0") + // tests testImplementation("junit:junit:4.13.2") } diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java index 70e3e7e..1514918 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java @@ -17,6 +17,7 @@ import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisClusterSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisPooledSummoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; +import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import redis.clients.jedis.Jedis; @@ -347,8 +348,9 @@ public abstract class AbstractRedisBungeeAPI { * calls {@link #getUuidFromName(String)} to get uuid * * @param playerName player name - * @param message kick message that player will see on kick + * @param message kick message that player will see on kick * @since 0.8.0 + * @deprecated */ public void kickPlayer(String playerName, String message) { @@ -361,11 +363,38 @@ public abstract class AbstractRedisBungeeAPI { * @param playerUUID player name * @param message kick message that player will see on kick * @since 0.8.0 + * @deprecated */ + @Deprecated public void kickPlayer(UUID playerUUID, String message) { + kickPlayer(playerUUID, Component.text(message)); + } + + /** + * Kicks a player from the network + * calls {@link #getUuidFromName(String)} to get uuid + * + * @param playerName player name + * @param message kick message that player will see on kick + * @since 0.12.0 + */ + + public void kickPlayer(String playerName, Component message) { + kickPlayer(getUuidFromName(playerName), message); + } + + /** + * Kicks a player from the network + * + * @param playerUUID player name + * @param message kick message that player will see on kick + * @since 0.12.0 + */ + public void kickPlayer(UUID playerUUID, Component message) { this.plugin.playerDataManager().kickPlayer(playerUUID, message); } + /** * This gives you instance of Jedis * diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java index c6ccbb6..7d544df 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PlayerDataManager.java @@ -19,6 +19,8 @@ import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNe import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent; import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisPipelineTask; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.json.JSONComponentSerializer; import org.json.JSONObject; import redis.clients.jedis.ClusterPipeline; import redis.clients.jedis.Pipeline; @@ -85,7 +87,7 @@ public abstract class PlayerDataManager extends EventsPlatform { public String getPlayerName(UUID player); - boolean handlePlatformKick(UUID uuid, String message); + boolean handlePlatformKick(UUID uuid, Component message); public String getPlayerServerName(P player); diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java index aeedb08..ec61bae 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java @@ -67,8 +67,8 @@ public class RedisBungeeConfiguration { return overrideBungeeCommands; } - public ImmutableMap getMessages() { - return messages; + public String getMessage(MessageType messageType) { + return this.messages.get(messageType); } public boolean kickWhenOnline() { diff --git a/RedisBungee-API/src/main/resources/messages.yml b/RedisBungee-API/src/main/resources/messages.yml index 200cb4a..a92689b 100644 --- a/RedisBungee-API/src/main/resources/messages.yml +++ b/RedisBungee-API/src/main/resources/messages.yml @@ -1,5 +1,5 @@ # this config file is for messages for players and command messages -# Note this uses legacy formating which § for color codes -# this might get replaced soon with mini message for both, velocity and bungeecord -logged-in-other-location: "§cYou logged in from another location!" -already-logged-in: "§cYou are already logged in!" \ No newline at end of file +# Note this uses MiniMessage format https://docs.advntr.dev/minimessage/format.html + +logged-in-other-location: "You logged in from another location!" +already-logged-in: "You are already logged in!" \ No newline at end of file diff --git a/RedisBungee-Bungee/build.gradle.kts b/RedisBungee-Bungee/build.gradle.kts index 07e1cdb..5ddd158 100644 --- a/RedisBungee-Bungee/build.gradle.kts +++ b/RedisBungee-Bungee/build.gradle.kts @@ -16,7 +16,10 @@ dependencies { compileOnly("net.md-5:bungeecord-api:$bungeecordApiVersion") { exclude("com.google.guava", "guava") exclude("com.google.code.gson", "gson") + exclude("net.kyori","adventure-api") } + implementation("net.kyori:adventure-platform-bungeecord:4.3.0") + implementation("net.kyori:adventure-text-serializer-gson:4.14.0") } description = "RedisBungee Bungeecord implementation" @@ -35,6 +38,7 @@ tasks { options.isDocFilesSubDirs = true options.links( "https://ci.md-5.net/job/BungeeCord/ws/api/target/apidocs/", // bungeecord api + "https://jd.advntr.dev/api/4.14.0" ) val apiDocs = File(rootProject.projectDir, "RedisBungee-API/build/docs/javadoc") options.linksOffline("https://ci.limework.net/RedisBungee/RedisBungee-API/build/docs/javadoc", apiDocs.path) diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java index 360d642..f21d703 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java @@ -16,6 +16,8 @@ import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfigurati import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -32,6 +34,9 @@ import java.util.concurrent.TimeUnit; public class BungeePlayerDataManager extends PlayerDataManager implements Listener { + + private final BungeeComponentSerializer BUNGEECORD_SERIALIZER = BungeeComponentSerializer.get(); + public BungeePlayerDataManager(RedisBungeePlugin plugin) { super(plugin); } @@ -68,12 +73,12 @@ public class BungeePlayerDataManager extends PlayerDataManager event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3); } else { event.setCancelled(true); - event.setCancelReason(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.configuration().getMessages().get(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN))))); + event.setCancelReason(BungeeComponentSerializer.get().serialize(MiniMessage.miniMessage().deserialize( plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN)))); event.completeIntent((Plugin) plugin); } } else { diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index 81988c4..74f5d9b 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -32,6 +32,8 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; import com.squareup.okhttp.Dispatcher; import com.squareup.okhttp.OkHttpClient; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -156,11 +158,11 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin, Con return this.getProxy().getPlayer(player).map(Player::getUsername).orElse(null); } - private final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection(); @Override - public boolean handlePlatformKick(UUID uuid, String message) { + public boolean handlePlatformKick(UUID uuid, Component message) { Player player = getPlayer(uuid); if (player == null) return false; - player.disconnect(serializer.deserialize(message)); + player.disconnect(message); return true; } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java index ebd2511..109cdff 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java @@ -24,6 +24,7 @@ import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Objects; @@ -65,18 +66,17 @@ public class VelocityPlayerDataManager extends PlayerDataManager