Skip to content

Commit a0c0b60

Browse files
committed
Version 2.1.5.1 that fixes NPE when replacing the alias placeholder
1 parent 69b543f commit a0c0b60

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

Main Plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<name>PlayerBalancer Plugin</name>
1313
<artifactId>playerbalancer-plugin</artifactId>
14-
<version>2.1.5</version>
14+
<version>2.1.5.1</version>
1515

1616
<build>
1717
<finalName>PlayerBalancer</finalName>

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,25 @@ public void execute(CommandSender sender, String[] args) {
109109
.create());
110110
}
111111

112-
sender.sendMessage(new ComponentBuilder("Alias: ")
113-
.color(ChatColor.GRAY)
114-
.append(String.valueOf(section.getProps().getAlias()))
115-
.color(ChatColor.AQUA)
116-
.create()
117-
);
112+
if (section.getProps().getAlias() != null) {
113+
sender.sendMessage(new ComponentBuilder("Alias: ")
114+
.color(ChatColor.GRAY)
115+
.append("\"")
116+
.color(ChatColor.AQUA)
117+
.append(section.getProps().getAlias())
118+
.color(ChatColor.RED)
119+
.append("\"")
120+
.color(ChatColor.AQUA)
121+
.create()
122+
);
123+
} else {
124+
sender.sendMessage(new ComponentBuilder("Alias: ")
125+
.color(ChatColor.GRAY)
126+
.append("None")
127+
.color(ChatColor.AQUA)
128+
.create()
129+
);
130+
}
118131

119132
sender.sendMessage(new ComponentBuilder("Position: ")
120133
.color(ChatColor.GRAY)

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.List;
1414
import java.util.concurrent.TimeUnit;
1515

16+
import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull;
17+
1618
//TODO I don't like this, improve it
1719
public abstract class ConnectionIntent {
1820
protected final PlayerBalancer plugin;
@@ -26,7 +28,7 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
2628

2729
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
2830
(str) -> str.replace("{section}", section.getName())
29-
.replace("{alias}", section.getProps().getAlias())
31+
.replace("{alias}", safeNull(section.getProps().getAlias()))
3032
);
3133

3234
//Prevents removing servers from the section
@@ -48,7 +50,7 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
4850
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(),
4951
(str) -> str.replace("{server}", target.getName())
5052
.replace("{section}", section.getName())
51-
.replace("{alias}", section.getProps().getAlias())
53+
.replace("{alias}", safeNull(section.getProps().getAlias()))
5254
);
5355
}
5456
});

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public static String revertColor(String string) {
2626
return string.replace(ChatColor.COLOR_CHAR, '&');
2727
}
2828

29-
public static String safePrint(String string) {
30-
return string.replace(ChatColor.COLOR_CHAR, '\u00A7');
29+
public static String safeNull(String string) {
30+
if (string == null) {
31+
return "Undefined";
32+
}
33+
return string;
3134
}
3235

3336
private MessageUtils() {}

Main Plugin/src/main/resources/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ features {
229229

230230
rules {
231231
general-lobbies {
232-
special.permission=other-lobby-section,
232+
special.permission=other-lobby-section
233233
}
234234
}
235235
}

0 commit comments

Comments
 (0)