Skip to content

Commit 66898ff

Browse files
authored
Merge pull request #136 from Andre601/feature/improve-component-parser
Improve component parser
2 parents 2910b13 + a5613db commit 66898ff

File tree

10 files changed

+34
-26
lines changed

10 files changed

+34
-26
lines changed

bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.andre601.oneversionremake.core.files.ConfigHandler;
3131
import com.andre601.oneversionremake.core.interfaces.PluginCore;
3232
import com.andre601.oneversionremake.core.interfaces.ProxyLogger;
33-
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
3433
import net.md_5.bungee.api.ServerPing;
3534
import net.md_5.bungee.api.plugin.Plugin;
3635
import org.bstats.bungeecord.Metrics;
@@ -48,7 +47,6 @@ public class BungeeCore extends Plugin implements PluginCore{
4847

4948
@Override
5049
public void onEnable(){
51-
BungeeAudiences.create(this);
5250
this.core = new OneVersionRemake(this);
5351
}
5452

@@ -142,4 +140,8 @@ public ServerPing.PlayerInfo[] getPlayers(List<String> lines, List<Integer> serv
142140
return core.getPlayers(ServerPing.PlayerInfo.class, lines, serverProtocols, userProtocol, majorOnly)
143141
.toArray(new ServerPing.PlayerInfo[0]);
144142
}
143+
144+
public OneVersionRemake getCore(){
145+
return core;
146+
}
145147
}

bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/BungeeSender.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@
1919
package com.andre601.oneversionremake.bungeecord.commands;
2020

2121
import com.andre601.oneversionremake.core.CommandPermissions;
22+
import com.andre601.oneversionremake.core.OneVersionRemake;
2223
import com.andre601.oneversionremake.core.interfaces.CmdSender;
23-
import net.kyori.adventure.text.Component;
24+
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
2425
import net.kyori.adventure.text.format.NamedTextColor;
25-
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
2626
import net.md_5.bungee.api.CommandSender;
2727

2828
public class BungeeSender implements CmdSender{
2929

30+
private final OneVersionRemake core;
3031
private final CommandSender sender;
32+
private final BungeeAudiences bungeeAudiences;
3133

32-
public BungeeSender(CommandSender sender){
34+
public BungeeSender(OneVersionRemake core, CommandSender sender, BungeeAudiences bungeeAudiences){
35+
this.core = core;
3336
this.sender = sender;
37+
this.bungeeAudiences = bungeeAudiences;
3438
}
3539

3640
@Override
@@ -50,8 +54,8 @@ public void sendMsg(String msg, Object... args){
5054

5155
@Override
5256
public void sendMsg(NamedTextColor color, String msg, Object... args){
53-
sender.sendMessage(BungeeComponentSerializer.get().serialize(
54-
Component.text(String.format(msg, args)).color(color)
55-
));
57+
bungeeAudiences.sender(sender).sendMessage(
58+
core.getComponentParser().toComponent(String.format(msg, args)).color(color)
59+
);
5660
}
5761
}

bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/commands/CmdOneVersionRemake.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@
2020

2121
import com.andre601.oneversionremake.bungeecord.BungeeCore;
2222
import com.andre601.oneversionremake.core.CommandPermissions;
23+
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
2324
import net.md_5.bungee.api.CommandSender;
2425
import net.md_5.bungee.api.plugin.Command;
2526

2627
public class CmdOneVersionRemake extends Command{
2728

2829
private final BungeeCore plugin;
30+
private final BungeeAudiences bungeeAudiences;
2931

3032
public CmdOneVersionRemake(BungeeCore plugin){
3133
super("oneversionremake", CommandPermissions.ADMIN, "ovr");
3234
this.plugin = plugin;
35+
this.bungeeAudiences = BungeeAudiences.create(plugin);
3336
}
3437

3538
@Override
3639
public void execute(CommandSender commandSender, String[] args){
37-
BungeeSender sender = new BungeeSender(commandSender);
40+
BungeeSender sender = new BungeeSender(plugin.getCore(), commandSender, bungeeAudiences);
3841

3942
plugin.getCommandHandler().handle(sender, args);
4043
}

bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeeLoginListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void onLogin(PreLoginEvent event){
5252
kickMessage = Collections.singletonList("<red>This Server is running MC {version}! Please change your client version.");
5353

5454
event.setCancelReason(BungeeComponentSerializer.get().serialize(
55-
plugin.getComponentParser().toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly)
55+
plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly)
5656
));
5757
event.setCancelled(true);
5858

bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/listener/BungeePingListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void onProxyPing(ProxyPingEvent event){
7676
motd = motd.subList(0, 1);
7777

7878
TextComponent component = new TextComponent(BungeeComponentSerializer.get().serialize(
79-
plugin.getComponentParser().toTextComponent(motd, serverProtocols, userProtocol, majorOnly)
79+
plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly)
8080
));
8181

8282
ping.setDescriptionComponent(component);

core/src/main/java/com/andre601/oneversionremake/core/Parser.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ public Parser(OneVersionRemake core){
3232
this.core = core;
3333
}
3434

35-
public Component toTextComponent(List<String> lines, List<Integer> serverProtocols, int userProtocol, boolean majorOnly){
36-
return MiniMessage.get().parse(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly));
35+
public Component toComponent(List<String> lines, List<Integer> serverProtocols, int userProtocol, boolean majorOnly){
36+
return toComponent(parse(String.join("\n", lines), serverProtocols, userProtocol, majorOnly));
37+
}
38+
39+
public Component toComponent(String text){
40+
return MiniMessage.miniMessage().deserialize(text);
3741
}
3842

3943
public String toString(String text, List<Integer> serverProtocols, int userProtocol, boolean majorOnly){
40-
Component component = MiniMessage.get().parse(parse(text, serverProtocols, userProtocol, majorOnly));
44+
Component component = MiniMessage.miniMessage()
45+
.deserialize(parse(text, serverProtocols, userProtocol, majorOnly));
4146
return LegacyComponentSerializer.legacySection().serialize(component);
4247
}
4348

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414

15-
<plugin.version>3.9.0</plugin.version>
15+
<plugin.version>3.10.0</plugin.version>
1616
<plugin.description>Only allow specific client versions on your Network.</plugin.description>
1717

1818
<maven.compiler.target>11</maven.compiler.target>

velocity/pom.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
<repositories>
3737
<repository>
3838
<id>velocity</id>
39-
<url>https://nexus.velocitypowered.com/repository/maven-public</url>
39+
<url>https://papermc.io/repo/repository/maven-public/</url>
4040
</repository>
4141
<repository>
4242
<id>sonatype</id>
43-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
43+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
4444
</repository>
4545
</repositories>
4646

@@ -54,15 +54,9 @@
5454
<dependency>
5555
<groupId>com.velocitypowered</groupId>
5656
<artifactId>velocity-api</artifactId>
57-
<version>3.1.0</version>
57+
<version>3.1.2-SNAPSHOT</version>
5858
<scope>provided</scope>
5959
</dependency>
60-
<dependency>
61-
<groupId>net.kyori</groupId>
62-
<artifactId>adventure-text-minimessage</artifactId>
63-
<version>4.10.0</version>
64-
<scope>compile</scope>
65-
</dependency>
6660
<dependency>
6761
<groupId>org.bstats</groupId>
6862
<artifactId>bstats-velocity</artifactId>

velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityLoginListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void onPreLogin(PreLoginEvent event){
5050
kickMessage = Collections.singletonList("&cThis Server is running MC {version}! Please change your client version.");
5151

5252
PreLoginEvent.PreLoginComponentResult result = PreLoginEvent.PreLoginComponentResult
53-
.denied(plugin.getComponentParser().toTextComponent(kickMessage, serverProtocols, userProtocol, majorOnly));
53+
.denied(plugin.getComponentParser().toComponent(kickMessage, serverProtocols, userProtocol, majorOnly));
5454

5555
event.setResult(result);
5656

velocity/src/main/java/com/andre601/oneversionremake/velocity/listener/VelocityPingListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void onProxyPing(ProxyPingEvent event){
7777
if(motd.size() > 2)
7878
motd = motd.subList(0, 1);
7979

80-
builder.description(plugin.getComponentParser().toTextComponent(motd, serverProtocols, userProtocol, majorOnly));
80+
builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly));
8181
}
8282

8383
event.setPing(builder.build());

0 commit comments

Comments
 (0)