mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Add null value formatting for MapContentProvider
This commit is contained in:
parent
41f9989eef
commit
61e3ffb7e5
@ -2,9 +2,9 @@ package org.mvplugins.multiverse.core.display.parsers;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import co.aikar.commands.BukkitCommandIssuer;
|
import co.aikar.commands.BukkitCommandIssuer;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -45,8 +45,15 @@ public class MapContentProvider<K, V> implements ContentProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<String> parse(@NotNull BukkitCommandIssuer issuer) {
|
public Collection<String> parse(@NotNull BukkitCommandIssuer issuer) {
|
||||||
return map.entrySet().stream()
|
return map.entrySet().stream()
|
||||||
.map(e -> String.format(format, keyColor, e.getKey(), separator, valueColor, e.getValue()))
|
.map(e -> String.format(format, keyColor, e.getKey(), separator, valueColor, formatValue(e.getValue())))
|
||||||
.collect(Collectors.toList());
|
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user