ChromaCore/src/main/java/buttondevteam/lib/DebugPotatoAPI.java

64 lines
1.9 KiB
Java
Raw Normal View History

2016-11-19 22:40:57 +00:00
package buttondevteam.lib;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class DebugPotatoAPI {
2016-11-19 22:45:35 +00:00
public static ItemStack CreateDebugPotato(List<String> message) {
2016-11-19 22:40:57 +00:00
ItemStack potato = new ItemStack(Material.BAKED_POTATO);
ItemMeta meta = potato.getItemMeta();
meta.setDisplayName("Spicy Debug Potato");
meta.setLore(message);
potato.setItemMeta(meta);
potato.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 10);
return potato;
}
2016-11-19 22:45:35 +00:00
public static ItemStack CreateDebugPotato(String message) {
return CreateDebugPotato(WordWrap(message));
2016-11-19 22:40:57 +00:00
}
2016-11-19 22:45:35 +00:00
public static void SendDebugPotato(Player player, List<String> message) {
2016-11-19 22:40:57 +00:00
player.getInventory().addItem(CreateDebugPotato(message));
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_SLIME_SQUISH, 0, 0);
return;
}
2016-11-19 22:45:35 +00:00
public static void SendDebugPotato(Player player, String[] message) {
2016-11-19 22:40:57 +00:00
SendDebugPotato(player, Arrays.asList(message));
}
2016-11-19 22:45:35 +00:00
public static void SendDebugPotato(Player player, String message) {
SendDebugPotato(player, WordWrap(message));
2016-11-19 22:40:57 +00:00
}
2016-11-19 22:45:35 +00:00
public static List<String> WordWrap(String message) {
2016-11-19 22:40:57 +00:00
String[] splitString = message.split("\\s+");
List<String> newMessage = new ArrayList<String>();
String currentLine = "";
int currentLineLength = 0;
int wordlength;
int maxLineLength = 40;
2016-11-19 22:45:35 +00:00
for (String word : splitString) {
2016-11-19 22:40:57 +00:00
wordlength = word.length();
2016-11-19 22:45:35 +00:00
if (currentLineLength == 0 || (currentLineLength + wordlength) < maxLineLength) {
2016-11-19 22:40:57 +00:00
currentLine += word + " ";
2016-11-19 22:45:35 +00:00
currentLineLength += wordlength + 1;
} else {
2016-11-19 22:40:57 +00:00
newMessage.add(currentLine);
currentLine = word + " ";
currentLineLength = word.length();
}
}
return newMessage;
}
}