UltimateModeration/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java
2019-03-03 16:33:44 -05:00

93 lines
3.2 KiB
Java

package com.songoda.ultimatemoderation.utils;
import com.songoda.ultimatemoderation.UltimateModeration;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.concurrent.TimeUnit;
public class Methods {
public static ItemStack getGlass() {
UltimateModeration instance = UltimateModeration.getInstance();
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
}
public static ItemStack getBackgroundGlass(boolean type) {
UltimateModeration instance = UltimateModeration.getInstance();
if (type)
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
else
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
}
private static ItemStack getGlass(Boolean rainbow, int type) {
int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass;
if (rainbow) {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
} else {
glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
}
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l");
glass.setItemMeta(glassmeta);
return glass;
}
public static String formatText(String text) {
if (text == null || text.equals(""))
return "";
return formatText(text, false);
}
public static String formatText(String text, boolean cap) {
if (text == null || text.equals(""))
return "";
if (cap)
text = text.substring(0, 1).toUpperCase() + text.substring(1);
return ChatColor.translateAlternateColorCodes('&', text);
}
public static String makeReadable(Long time) {
if (time == null)
return "";
return String.format("%dd %dh %dm",
TimeUnit.MILLISECONDS.toDays(time),
TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time)),
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)));
}
public static long parseTime(String input) {
long result = 0;
String number = "";
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (Character.isDigit(c)) {
number += c;
} else if (Character.isLetter(c) && !number.isEmpty()) {
result += convert(Integer.parseInt(number), c);
number = "";
}
}
return result;
}
private static long convert(int value, char unit) {
switch (unit) {
case 'd':
return value * 1000 * 60 * 60 * 24;
case 'h':
return value * 1000 * 60 * 60;
case 'm':
return value * 1000 * 60;
case 's':
return value * 1000;
}
return 0;
}
}