Class Utils

java.lang.Object
cn.nukkit.utils.Utils

public class Utils extends Object
Author:
MagicDroidX (Nukkit Project)
  • Field Details

  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • safeWrite

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static void safeWrite(File currentFile, Consumer<File> operation) throws IOException
      Throws:
      IOException
    • writeFile

      public static void writeFile(String fileName, String content) throws IOException
      Throws:
      IOException
    • writeFile

      public static void writeFile(String fileName, InputStream content) throws IOException
      Throws:
      IOException
    • writeFile

      public static void writeFile(File file, String content) throws IOException
      Throws:
      IOException
    • writeFile

      public static void writeFile(File file, InputStream content) throws IOException
      Throws:
      IOException
    • readFile

      public static String readFile(File file) throws IOException
      Throws:
      IOException
    • readFile

      public static String readFile(String filename) throws IOException
      Throws:
      IOException
    • readFile

      public static String readFile(InputStream inputStream) throws IOException
      Throws:
      IOException
    • copyFile

      public static void copyFile(File from, File to) throws IOException
      Throws:
      IOException
    • getAllThreadDumps

      public static String getAllThreadDumps()
    • getExceptionMessage

      public static String getExceptionMessage(Throwable e)
    • dataToUUID

      public static UUID dataToUUID(String... params)
    • dataToUUID

      public static UUID dataToUUID(byte[]... params)
    • rtrim

      public static String rtrim(String s, char character)
    • isByteArrayEmpty

      public static boolean isByteArrayEmpty(byte[] array)
    • toRGB

      public static long toRGB(byte r, byte g, byte b, byte a)
    • toABGR

      public static long toABGR(int argb)
    • splitArray

      public static Object[][] splitArray(Object[] arrayToSplit, int chunkSize)
    • reverseArray

      public static <T> void reverseArray(T[] data)
    • reverseArray

      public static <T> T[] reverseArray(T[] array, boolean copy)
    • clone2dArray

      public static <T> T[][] clone2dArray(T[][] array)
    • getOrCreate

      public static <T, U, V> Map<U,V> getOrCreate(Map<T,Map<U,V>> map, T key)
    • getOrCreate

      public static <T, U, V extends U> U getOrCreate(Map<T,U> map, Class<V> clazz, T key)
    • toInt

      public static int toInt(Object number)
    • parseHexBinary

      public static byte[] parseHexBinary(String s)
    • rand

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static int rand(int min, int max)
      返回介于最小值(包含)和最大值(包含)之间的伪随机数

      Return a random number between the minimum (inclusive) and maximum (inclusive).

      Parameters:
      min - the min
      max - the max
      Returns:
      the int
    • rand

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static double rand(double min, double max)
    • rand

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static boolean rand()
    • dynamic

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static int dynamic(int value)
      A way to tell the java compiler to do not replace the users of a public static final int constant with the value defined in it, forcing the JVM to get the value directly from the class, preventing binary incompatible changes.
      Parameters:
      value - The value to be assigned to the field.
      Returns:
      The same value that was passed as parameter
    • dynamic

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static <T> T dynamic(T value)
      A way to tell the java compiler to do not replace the users of a public static final constant with the value defined in it, forcing the JVM to get the value directly from the class, preventing binary incompatible changes.
      Parameters:
      value - The value to be assigned to the field.
      Returns:
      The same value that was passed as parameter
    • zipFolder

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static void zipFolder(Path sourceFolderPath, Path zipPath) throws IOException
      Throws:
      IOException
    • isInteger

      @PowerNukkitOnly @Since("1.5.1.0-PN") public static boolean isInteger(String str)
    • getLevelBlocks

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static Block[] getLevelBlocks(Level level, AxisAlignedBB bb)
    • calLinearFunction

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static double calLinearFunction(Vector3 pos1, Vector3 pos2, double element, int type)
    • hasCollisionBlocks

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static boolean hasCollisionBlocks(Level level, AxisAlignedBB bb)
    • hasCollisionTickCachedBlocks

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static boolean hasCollisionTickCachedBlocks(Level level, AxisAlignedBB bb)