From 61e3ffb7e5518ff7bf35dbff4708e2b4071f4b66 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:20:13 +0800 Subject: [PATCH] Add null value formatting for MapContentProvider --- .../core/display/parsers/MapContentProvider.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/display/parsers/MapContentProvider.java b/src/main/java/org/mvplugins/multiverse/core/display/parsers/MapContentProvider.java index c460405a..28739cd0 100644 --- a/src/main/java/org/mvplugins/multiverse/core/display/parsers/MapContentProvider.java +++ b/src/main/java/org/mvplugins/multiverse/core/display/parsers/MapContentProvider.java @@ -2,9 +2,9 @@ package org.mvplugins.multiverse.core.display.parsers; import java.util.Collection; import java.util.Map; -import java.util.stream.Collectors; import co.aikar.commands.BukkitCommandIssuer; +import com.google.common.base.Strings; import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; @@ -45,8 +45,15 @@ public class MapContentProvider implements ContentProvider { @Override public Collection parse(@NotNull BukkitCommandIssuer issuer) { return map.entrySet().stream() - .map(e -> String.format(format, keyColor, e.getKey(), separator, valueColor, e.getValue())) - .collect(Collectors.toList()); + .map(e -> String.format(format, keyColor, e.getKey(), separator, valueColor, formatValue(e.getValue()))) + .toList(); + } + + private String formatValue(V value) { + if (value instanceof String stringValue) { + return Strings.isNullOrEmpty(stringValue) ? "&7&onull" : stringValue; + } + return value == null ? "&7&onull" : String.valueOf(value); } /**