From 7fe7faf17878d2e37faef1b5d83fa1444c220a50 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:39:58 +0100 Subject: [PATCH 1/3] Improve component parser --- .../oneversionremake/bungeecord/BungeeCore.java | 6 ++++-- .../bungeecord/commands/BungeeSender.java | 16 ++++++++++------ .../bungeecord/commands/CmdOneVersionRemake.java | 5 ++++- .../bungeecord/listener/BungeeLoginListener.java | 2 +- .../bungeecord/listener/BungeePingListener.java | 2 +- .../andre601/oneversionremake/core/Parser.java | 11 ++++++++--- .../velocity/listener/VelocityLoginListener.java | 2 +- .../velocity/listener/VelocityPingListener.java | 2 +- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java index 99f5809..e9b98e5 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java @@ -30,7 +30,6 @@ import com.andre601.oneversionremake.core.files.ConfigHandler; import com.andre601.oneversionremake.core.interfaces.PluginCore; import com.andre601.oneversionremake.core.interfaces.ProxyLogger; -import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.plugin.Plugin; import org.bstats.bungeecord.Metrics; @@ -48,7 +47,6 @@ public class BungeeCore extends Plugin implements PluginCore{ @Override public void onEnable(){ - BungeeAudiences.create(this); this.core = new OneVersionRemake(this); } @@ -142,4 +140,8 @@ public ServerPing.PlayerInfo[] getPlayers(List lines, List serv return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly) .toArray(new ServerPing.PlayerInfo[0]); } + + public OneVersionRemake getCore(){ + return core; + } } diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/BungeeSender.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/BungeeSender.java index f7a28d9..9854382 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/BungeeSender.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/BungeeSender.java @@ -19,18 +19,22 @@ package com.andre601.oneversionremake.bungeecord.commands; import com.andre601.oneversionremake.core.CommandPermissions; +import com.andre601.oneversionremake.core.OneVersionRemake; import com.andre601.oneversionremake.core.interfaces.CmdSender; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.CommandSender; public class BungeeSender implements CmdSender{ + private final OneVersionRemake core; private final CommandSender sender; + private final BungeeAudiences bungeeAudiences; - public BungeeSender(CommandSender sender){ + public BungeeSender(OneVersionRemake core, CommandSender sender, BungeeAudiences bungeeAudiences){ + this.core = core; this.sender = sender; + this.bungeeAudiences = bungeeAudiences; } @Override @@ -50,8 +54,8 @@ public void sendMsg(String msg, Object... args){ @Override public void sendMsg(NamedTextColor color, String msg, Object... args){ - sender.sendMessage(BungeeComponentSerializer.get().serialize( - Component.text(String.format(msg, args)).color(color) - )); + bungeeAudiences.sender(sender).sendMessage( + core.getComponentParser().toComponent(String.format(msg, args)).color(color) + ); } } diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/CmdOneVersionRemake.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/CmdOneVersionRemake.java index 285dfc7..dce2355 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/CmdOneVersionRemake.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/CmdOneVersionRemake.java @@ -20,21 +20,24 @@ import com.andre601.oneversionremake.bungeecord.BungeeCore; import com.andre601.oneversionremake.core.CommandPermissions; +import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Command; public class CmdOneVersionRemake extends Command{ private final BungeeCore plugin; + private final BungeeAudiences bungeeAudiences; public CmdOneVersionRemake(BungeeCore plugin){ super("oneversionremake", CommandPermissions.ADMIN, "ovr"); this.plugin = plugin; + this.bungeeAudiences = BungeeAudiences.create(plugin); } @Override public void execute(CommandSender commandSender, String[] args){ - BungeeSender sender = new BungeeSender(commandSender); + BungeeSender sender = new BungeeSender(plugin.getCore(), commandSender, bungeeAudiences); plugin.getCommandHandler().handle(sender, args); } diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java index c3ba6ee..aa71994 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java @@ -52,7 +52,7 @@ public void onLogin(PreLoginEvent event){ kickMessage = Collections.singletonList("This Server is running MC {version}! Please change your client version."); event.setCancelReason(BungeeComponentSerializer.get().serialize( - plugin.getComponentParser().toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly) + plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly) )); event.setCancelled(true); diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java index e576d97..6e9d7a7 100644 --- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java +++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java @@ -76,7 +76,7 @@ public void onProxyPing(ProxyPingEvent event){ motd = motd.subList(0, 1); TextComponent component = new TextComponent(BungeeComponentSerializer.get().serialize( - plugin.getComponentParser().toTextComponent(motd, serverProtocols, userProtocol, majorOnly) + plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly) )); ping.setDescriptionComponent(component); diff --git a/core/src/main/java/com/andre601/oneversionremake/core/Parser.java b/core/src/main/java/com/andre601/oneversionremake/core/Parser.java index 49b4631..04e8c83 100644 --- a/core/src/main/java/com/andre601/oneversionremake/core/Parser.java +++ b/core/src/main/java/com/andre601/oneversionremake/core/Parser.java @@ -32,12 +32,17 @@ public Parser(OneVersionRemake core){ this.core = core; } - public Component toTextComponent(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ - return MiniMessage.get().parse(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly)); + public Component toComponent(List lines, List serverProtocols, int userProtocol, boolean majorOnly){ + return toComponent(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly)); + } + + public Component toComponent(String text){ + return MiniMessage.miniMessage().deserialize(text); } public String toString(String text, List serverProtocols, int userProtocol, boolean majorOnly){ - Component component = MiniMessage.get().parse(parse(text, serverProtocols, userProtocol, majorOnly)); + Component component = MiniMessage.miniMessage() + .deserialize(parse(text, serverProtocols, userProtocol, majorOnly)); return LegacyComponentSerializer.legacySection().serialize(component); } diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java index d3a4dcf..173366b 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java @@ -50,7 +50,7 @@ public void onPreLogin(PreLoginEvent event){ kickMessage = Collections.singletonList("&cThis Server is running MC {version}! Please change your client version."); PreLoginEvent.PreLoginComponentResult result = PreLoginEvent.PreLoginComponentResult - .denied(plugin.getComponentParser().toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly)); + .denied(plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly)); event.setResult(result); diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java index 76a6f94..d3986e3 100644 --- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java +++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java @@ -77,7 +77,7 @@ public void onProxyPing(ProxyPingEvent event){ if(motd.size() > 2) motd = motd.subList(0, 1); - builder.description(plugin.getComponentParser().toTextComponent(motd, serverProtocols, userProtocol, majorOnly)); + builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly)); } event.setPing(builder.build()); From 5e7765715b7013b9a5e8236db0947356465f79ca Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:03:28 +0100 Subject: [PATCH 2/3] Bump version to 3.10.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 267e383..c330242 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 - 3.9.0 + 3.10.0 Only allow specific client versions on your Network. 11 From a5613db2b6f360a4c9fa7c08460e231da08cf33c Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Fri, 4 Mar 2022 00:09:33 +0100 Subject: [PATCH 3/3] Update to PaperMC velocity nexus --- velocity/pom.xml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 53a88f5..eae2062 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -36,11 +36,11 @@ velocity - https://nexus.velocitypowered.com/repository/maven-public + https://papermc.io/repo/repository/maven-public/ sonatype - https://oss.sonatype.org/content/repositories/snapshots + https://oss.sonatype.org/content/repositories/snapshots/ @@ -54,15 +54,9 @@ com.velocitypowered velocity-api - 3.1.0 + 3.1.2-SNAPSHOT provided - - net.kyori - adventure-text-minimessage - 4.10.0 - compile - org.bstats bstats-velocity