From ffb50e8391bb89831af051968a4ab02c03304204 Mon Sep 17 00:00:00 2001 From: aro Date: Mon, 23 Jan 2023 10:05:02 +0100 Subject: [PATCH] refactor: return values if profile is null --- .../nicko/placeholder/NickoExpansion.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/nicko-core/src/main/java/net/artelnatif/nicko/placeholder/NickoExpansion.java b/nicko-core/src/main/java/net/artelnatif/nicko/placeholder/NickoExpansion.java index 1d611a0..cf50376 100644 --- a/nicko-core/src/main/java/net/artelnatif/nicko/placeholder/NickoExpansion.java +++ b/nicko-core/src/main/java/net/artelnatif/nicko/placeholder/NickoExpansion.java @@ -39,20 +39,30 @@ public class NickoExpansion extends PlaceholderExpansion { @Override public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) { - if(player == null) return null; - Optional optionalProfile = instance.getDataStore().getData(player.getUniqueId()); + if (player == null) return null; + + String name, skin, locale; + boolean bungeecord; + + final Optional optionalProfile = instance.getDataStore().getData(player.getUniqueId()); if (optionalProfile.isPresent()) { final NickoProfile profile = optionalProfile.get(); - return switch (params) { - case "name" -> profile.getName(); - case "skin" -> profile.getSkin(); - case "locale" -> profile.getLocale().getName(); - case "bungeecord" -> String.valueOf(profile.isBungeecordTransfer()); - default -> null; - }; + name = profile.getName(); + skin = profile.getSkin(); + locale = profile.getLocale().getName(); + bungeecord = profile.isBungeecordTransfer(); } else { - instance.getLogger().severe("Couldn't satisfy request for placeholder " + params + ". This is a bug!"); - return null; + name = skin = player.getName(); + locale = "N/A"; + bungeecord = true; } + + return switch (params) { + case "name" -> name; + case "skin" -> skin; + case "locale" -> locale; + case "bungeecord" -> String.valueOf(bungeecord); + default -> null; + }; } }