12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package me.hammerle.code;
- import java.awt.Color;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Random;
- import java.util.stream.Collectors;
- import me.hammerle.console.ConsoleUtils;
- import me.hammerle.exceptions.IllegalColorException;
- public class ScriptUtils
- {
- public static Color getColor(Object o) throws IllegalColorException
- {
- try
- {
- String[] parts = o.toString().split(":");
- return new Color(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
- }
- catch(NumberFormatException | ArrayIndexOutOfBoundsException ex)
- {
- throw new IllegalColorException(o.toString());
- }
- }
-
- public static void printError(Object message)
- {
- ConsoleUtils.sendMessage(String.valueOf(message), Color.RED);
- }
-
- public static void printErrorList(Object message, Object message2)
- {
- ConsoleUtils.sendMessage(" - " + message + " " + message2, Color.RED);
- }
-
- public static void printDebug(Object message)
- {
- ConsoleUtils.sendMessage(String.valueOf(message), null);
- }
-
- public static int randomInt(int min, int max)
- {
- Random rand = new Random();
- int randomNum = rand.nextInt((max - min) + 1) + min;
- return randomNum;
- }
-
- public static String connect(Object[] o, int skip)
- {
- return Arrays.stream(o, skip, o.length).map(ob -> String.valueOf(ob)).collect(Collectors.joining());
- }
-
- public static List<String> readCode(String filename)
- {
- File script = new File(filename + ".snuvi");
- if(script.exists())
- {
- try
- {
- return Files.readAllLines(script.toPath());
- }
- catch (IOException ex)
- {
- ScriptUtils.printError("File '" + filename + "' cannot be read.");
- }
- }
- else
- {
- ScriptUtils.printError("File '" + filename + "' does not exist.");
- }
- return null;
- }
- }
|