Skip to content

Commit

Permalink
Fix wrong List.subList range
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Jun 28, 2022
1 parent 3cf5f3f commit 3a3a813
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onProxyPing(ProxyPingEvent event){
int userProtocol = protocol.getProtocol();

List<Integer> serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
List<String> hoverMessage = plugin.getConfigHandler().getStringList("Messages", "Hover");
List<String> hoverMessage = plugin.getConfigHandler().getStringList(false, "Messages", "Hover");

if(serverProtocols.isEmpty())
return;
Expand All @@ -59,7 +59,7 @@ public void onProxyPing(ProxyPingEvent event){
boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");

String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount");
List<String> motd = plugin.getConfigHandler().getStringList("Messages", "Motd");
List<String> motd = plugin.getConfigHandler().getStringList(true, "Messages", "Motd");

if(!serverProtocols.contains(userProtocol)){
if(!hoverMessage.isEmpty()){
Expand All @@ -72,9 +72,6 @@ public void onProxyPing(ProxyPingEvent event){
protocol.setName(plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly));

if(!motd.isEmpty()){
if(motd.size() > 2)
motd = motd.subList(0, 1);

TextComponent component = new TextComponent(BungeeComponentSerializer.get().serialize(
plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ConfigHandler{
Expand Down Expand Up @@ -114,12 +115,18 @@ public List<Integer> getIntList(Object... path){
}
}

public List<String> getStringList(Object... path){
public List<String> getStringList(boolean trim, Object... path){
List<String> list;
try{
return fromPath(path).getList(String.class);
list = fromPath(path).getList(String.class);
}catch(SerializationException ex){
return new ArrayList<>();
return Collections.emptyList();
}

if(list == null)
return Collections.emptyList();

return (trim && list.size() > 2) ? list.subList(0, 2) : list;
}

private ConfigurationNode fromPath(Object... path){
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<plugin.version>3.11.0</plugin.version>
<plugin.version>3.11.1</plugin.version>
<plugin.description>Only allow specific client versions on your Network.</plugin.description>

<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void onProxyPing(ProxyPingEvent event){
boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");

String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount");
List<String> motd = plugin.getConfigHandler().getStringList("Messages", "Motd");
List<String> hoverMessage = plugin.getConfigHandler().getStringList("Messages", "Hover");
List<String> motd = plugin.getConfigHandler().getStringList(true, "Messages", "Motd");
List<String> hoverMessage = plugin.getConfigHandler().getStringList(false, "Messages", "Hover");

if(!serverProtocols.contains(userProtocol)){
ServerPing.Builder builder = ping.asBuilder();
Expand All @@ -74,9 +74,6 @@ public void onProxyPing(ProxyPingEvent event){
}

if(!motd.isEmpty()){
if(motd.size() > 2)
motd = motd.subList(0, 1);

builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly));
}

Expand Down

0 comments on commit 3a3a813

Please sign in to comment.