From 1748bc0461822fbe133453dbb776d27b951b207e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 19 Nov 2016 23:45:35 +0100 Subject: [PATCH] Small fixes and formatting --- .../buttondevteam/lib/DebugPotatoAPI.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/buttondevteam/lib/DebugPotatoAPI.java b/src/main/java/buttondevteam/lib/DebugPotatoAPI.java index 6e6851c..867b7fe 100644 --- a/src/main/java/buttondevteam/lib/DebugPotatoAPI.java +++ b/src/main/java/buttondevteam/lib/DebugPotatoAPI.java @@ -12,7 +12,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class DebugPotatoAPI { - public static ItemStack CreateDebugPotato(List message){ + public static ItemStack CreateDebugPotato(List message) { ItemStack potato = new ItemStack(Material.BAKED_POTATO); ItemMeta meta = potato.getItemMeta(); meta.setDisplayName("Spicy Debug Potato"); @@ -21,34 +21,38 @@ public class DebugPotatoAPI { potato.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 10); return potato; } - public static ItemStack CreateDebugPotato(String message){ - return CreateDebugPotato(Arrays.asList(message)); + + public static ItemStack CreateDebugPotato(String message) { + return CreateDebugPotato(WordWrap(message)); } - public static void SendDebugPotato(Player player, List message){ + + public static void SendDebugPotato(Player player, List message) { player.getInventory().addItem(CreateDebugPotato(message)); player.getWorld().playSound(player.getLocation(), Sound.ENTITY_SLIME_SQUISH, 0, 0); return; } - public static void SendDebugPotato(Player player, String[] message){ + + public static void SendDebugPotato(Player player, String[] message) { SendDebugPotato(player, Arrays.asList(message)); } - public static void SendDebugPotato(Player player, String message){ - - SendDebugPotato(player, StringToMessage(message)); + + public static void SendDebugPotato(Player player, String message) { + SendDebugPotato(player, WordWrap(message)); } - public static List StringToMessage(String message){ + + public static List WordWrap(String message) { String[] splitString = message.split("\\s+"); List newMessage = new ArrayList(); String currentLine = ""; int currentLineLength = 0; int wordlength; int maxLineLength = 40; - for (String word : splitString){ + for (String word : splitString) { wordlength = word.length(); - if (currentLineLength == 0 || (currentLineLength + wordlength) < maxLineLength){ + if (currentLineLength == 0 || (currentLineLength + wordlength) < maxLineLength) { currentLine += word + " "; - currentLineLength += wordlength +1; - }else{ + currentLineLength += wordlength + 1; + } else { newMessage.add(currentLine); currentLine = word + " "; currentLineLength = word.length();