From 42992de312dece7ddd4e65742a7bd4dacdefa5a5 Mon Sep 17 00:00:00 2001 From: Sxtanna Date: Mon, 20 Jul 2020 18:22:08 -0400 Subject: [PATCH] updated with null contracts, immutability, and early returns. --- .../java/me/clip/placeholderapi/util/Msg.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/util/Msg.java b/src/main/java/me/clip/placeholderapi/util/Msg.java index 3d526e4..022ef5a 100644 --- a/src/main/java/me/clip/placeholderapi/util/Msg.java +++ b/src/main/java/me/clip/placeholderapi/util/Msg.java @@ -23,21 +23,37 @@ package me.clip.placeholderapi.util; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; -import java.util.Objects; import java.util.stream.Collectors; -public final class Msg { - public static void msg(CommandSender s, String... msg) { - s.sendMessage(Arrays.stream(msg).filter(Objects::nonNull).map(Msg::color).collect(Collectors.joining("\n"))); - } +public final class Msg +{ - public static void broadcast(String... msg) { - Arrays.stream(msg).filter(Objects::nonNull).map(Msg::color).forEach(Bukkit::broadcastMessage); - } + public static void msg(@NotNull final CommandSender sender, @NotNull final String... messages) + { + if (messages.length == 0) + { + return; + } + + sender.sendMessage(Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n"))); + } + + public static void broadcast(@NotNull final String... messages) + { + if (messages.length == 0) + { + return; + } + + Bukkit.broadcastMessage(Arrays.stream(messages).map(Msg::color).collect(Collectors.joining("\n"))); + } + + public static String color(@NotNull final String text) + { + return ChatColor.translateAlternateColorCodes('&', text); + } - public static String color(String text) { - return ChatColor.translateAlternateColorCodes('&', text); - } }