版本更新至:3.76
调整:开发框架改为 Gradle 新增:Language2 工具新增 [book] 类型
This commit is contained in:
88
src/main/java/me/skymc/taboolib/other/DateUtils.java
Normal file
88
src/main/java/me/skymc/taboolib/other/DateUtils.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package me.skymc.taboolib.other;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
/**
|
||||
* 最后一次更新:2018年1月16日21:07:27
|
||||
*
|
||||
* @author sky
|
||||
*/
|
||||
|
||||
public static SimpleDateFormat CH_ALL = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
|
||||
public static SimpleDateFormat EN_ALL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
public static SimpleDateFormat YEAR = new SimpleDateFormat("yyyy");
|
||||
|
||||
public static SimpleDateFormat MONTH = new SimpleDateFormat("MM");
|
||||
|
||||
public static SimpleDateFormat DAY_OF_MONTH = new SimpleDateFormat("dd");
|
||||
public static SimpleDateFormat DAY_OF_YEAR = new SimpleDateFormat("DD");
|
||||
|
||||
public static SimpleDateFormat HOUR_OF_DAY = new SimpleDateFormat("HH");
|
||||
public static SimpleDateFormat HOUR = new SimpleDateFormat("hh");
|
||||
|
||||
public static SimpleDateFormat MINUTE = new SimpleDateFormat("mm");
|
||||
public static SimpleDateFormat SECONDS = new SimpleDateFormat("ss");
|
||||
|
||||
public static SimpleDateFormat MILLISECOND = new SimpleDateFormat("SSS");
|
||||
|
||||
public static SimpleDateFormat WEEK = new SimpleDateFormat("E");
|
||||
|
||||
private static SimpleDateFormat Hour = new SimpleDateFormat("HH:mm");
|
||||
|
||||
public static Calendar getCalendar() {
|
||||
return Calendar.getInstance();
|
||||
}
|
||||
|
||||
public static Date getTime() {
|
||||
return Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
public static Integer getTime(SimpleDateFormat date) {
|
||||
return Integer.valueOf(date.format(getTime()));
|
||||
}
|
||||
|
||||
public static boolean timeInDifference(String m1, String m2) {
|
||||
try {
|
||||
Date now = Hour.parse(Hour.format(System.currentTimeMillis()));
|
||||
Date min = Hour.parse(m1);
|
||||
Date max = Hour.parse(m2);
|
||||
return (now.after(min) && now.before(max)) || now.equals(min) || now.equals(max);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static long formatDate(String time) {
|
||||
long date = 0;
|
||||
try {
|
||||
for (String value : time.toLowerCase().split(";")) {
|
||||
Integer num = Integer.valueOf(value.substring(0, value.length() - 1));
|
||||
if (value.endsWith("d")) {
|
||||
date += num * 1000L * 60 * 60 * 24;
|
||||
}
|
||||
else if (value.endsWith("h")) {
|
||||
date += num * 1000L * 60 * 60;
|
||||
}
|
||||
else if (value.endsWith("m")) {
|
||||
date += num * 1000L * 60;
|
||||
}
|
||||
else if (value.endsWith("s")) {
|
||||
date += num * 1000L;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
||||
64
src/main/java/me/skymc/taboolib/other/MathUtils.java
Normal file
64
src/main/java/me/skymc/taboolib/other/MathUtils.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package me.skymc.taboolib.other;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import me.skymc.taboolib.particle.EffLib;
|
||||
|
||||
public class MathUtils {
|
||||
|
||||
public static double tronc(double paramDouble, int paramInt)
|
||||
{
|
||||
double d = Math.pow(10.0D, paramInt);
|
||||
return Math.floor(paramDouble * d) / d;
|
||||
}
|
||||
|
||||
public static void drawVec(Vector paramVector, Location paramLocation, Color paramColor)
|
||||
{
|
||||
for (double d = 0.0D; d < 1.0D; d += 0.1D) {
|
||||
EffLib.REDSTONE.display(new EffLib.OrdinaryColor(paramColor), paramLocation.clone().add(paramVector.clone().multiply(d)), 100.0D);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCoords(Player paramPlayer, Vector paramVector, String paramString)
|
||||
{
|
||||
paramPlayer.sendMessage(paramString + tronc(paramVector.getX(), 2) + " " + tronc(paramVector.getY(), 2) + " " + tronc(paramVector.getZ(), 2));
|
||||
}
|
||||
|
||||
public static void sendCoords(Player paramPlayer, Location paramLocation, String paramString)
|
||||
{
|
||||
paramPlayer.sendMessage(paramString + tronc(paramLocation.getX(), 2) + " " + tronc(paramLocation.getY(), 2) + " " + tronc(paramLocation.getZ(), 2));
|
||||
}
|
||||
|
||||
public static Vector rotAxisX(Vector paramVector, double paramDouble)
|
||||
{
|
||||
double d1 = paramVector.getY() * Math.cos(paramDouble) - paramVector.getZ() * Math.sin(paramDouble);
|
||||
double d2 = paramVector.getY() * Math.sin(paramDouble) + paramVector.getZ() * Math.cos(paramDouble);
|
||||
return paramVector.setY(d1).setZ(d2);
|
||||
}
|
||||
|
||||
public static Vector rotAxisY(Vector paramVector, double paramDouble)
|
||||
{
|
||||
double d1 = paramVector.getX() * Math.cos(paramDouble) + paramVector.getZ() * Math.sin(paramDouble);
|
||||
double d2 = paramVector.getX() * -Math.sin(paramDouble) + paramVector.getZ() * Math.cos(paramDouble);
|
||||
return paramVector.setX(d1).setZ(d2);
|
||||
}
|
||||
|
||||
public static Vector rotAxisZ(Vector paramVector, double paramDouble)
|
||||
{
|
||||
double d1 = paramVector.getX() * Math.cos(paramDouble) - paramVector.getY() * Math.sin(paramDouble);
|
||||
double d2 = paramVector.getX() * Math.sin(paramDouble) + paramVector.getY() * Math.cos(paramDouble);
|
||||
return paramVector.setX(d1).setY(d2);
|
||||
}
|
||||
|
||||
public static Vector rotateFunc(Vector paramVector, Location paramLocation)
|
||||
{
|
||||
double d1 = paramLocation.getYaw() / 180.0F * 3.141592653589793D;
|
||||
double d2 = paramLocation.getPitch() / 180.0F * 3.141592653589793D;
|
||||
paramVector = rotAxisX(paramVector, d2);
|
||||
paramVector = rotAxisY(paramVector, -d1);
|
||||
return paramVector;
|
||||
}
|
||||
}
|
||||
70
src/main/java/me/skymc/taboolib/other/NumberUtils.java
Normal file
70
src/main/java/me/skymc/taboolib/other/NumberUtils.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package me.skymc.taboolib.other;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
import me.skymc.taboolib.methods.MethodsUtils;
|
||||
|
||||
public class NumberUtils {
|
||||
|
||||
private static Random rand = new Random();
|
||||
private static DecimalFormat doubleFormat = new DecimalFormat("#.##");
|
||||
|
||||
public static Random getRand() {
|
||||
return rand;
|
||||
}
|
||||
|
||||
public static Double format(Double num) {
|
||||
return Double.valueOf(doubleFormat.format(num));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int getRandom() {
|
||||
return rand.nextInt(100);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean getChance(int a) {
|
||||
return getRandom() <= a ? true : false;
|
||||
}
|
||||
|
||||
public static int getRandomInteger(Number l, Number u) {
|
||||
Integer ll = Math.min(l.intValue(), u.intValue());
|
||||
Integer uu = Math.max(l.intValue(), u.intValue());
|
||||
return rand.nextInt(uu) % (uu - ll + 1) + ll;
|
||||
}
|
||||
|
||||
public static double getRandomDouble(Number l, Number u) {
|
||||
double ll = Math.min(l.doubleValue(), u.doubleValue());
|
||||
double uu = Math.max(l.doubleValue(), u.doubleValue());
|
||||
double d = ll + rand.nextDouble() * (uu - ll);
|
||||
return Double.valueOf(doubleFormat.format(d));
|
||||
}
|
||||
|
||||
public static int getInteger(String s) {
|
||||
try {
|
||||
return Integer.valueOf(s);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(String s) {
|
||||
try {
|
||||
return Double.valueOf(s);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean getBoolean(String s) {
|
||||
try {
|
||||
return Boolean.valueOf(s);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/main/java/me/skymc/taboolib/other/WeightUtils.java
Normal file
34
src/main/java/me/skymc/taboolib/other/WeightUtils.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package me.skymc.taboolib.other;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.object.WeightCategory;
|
||||
|
||||
public class WeightUtils {
|
||||
|
||||
public static String getStringByWeight(List<WeightCategory> categorys) {
|
||||
|
||||
int weightSum = 0;
|
||||
for (WeightCategory wc : categorys) {
|
||||
weightSum += wc.getWeight();
|
||||
}
|
||||
|
||||
if (weightSum <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Integer n = NumberUtils.getRand().nextInt(weightSum);
|
||||
Integer m = 0;
|
||||
|
||||
for (WeightCategory wc : categorys) {
|
||||
if (m <= n && n < m + wc.getWeight()) {
|
||||
return wc.getCategory();
|
||||
}
|
||||
m += wc.getWeight();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user