Initial commit

This commit is contained in:
2024-07-07 23:13:20 +02:00
commit 8ef9a95b67
73 changed files with 4575 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package me.finn.unlegitlibrary.string;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
public class RandomString extends DefaultMethodsOverrider {
public static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String lower = upper.toLowerCase(Locale.ROOT);
public static final String digits = "0123456789";
public static final String alphanum = upper + lower + digits;
private final Random random;
private final char[] symbols;
private final char[] buf;
public RandomString(int length, Random random, String symbols) {
if (length < 1) throw new IllegalArgumentException();
if (symbols.length() < 2) throw new IllegalArgumentException();
this.random = Objects.requireNonNull(random);
this.symbols = symbols.toCharArray();
this.buf = new char[length];
}
/**
* Create an alphanumeric string generator.
*/
public RandomString(int length, Random random) {
this(length, random, alphanum);
}
/**
* Create an alphanumeric strings from a secure generator.
*/
public RandomString(int length) {
this(length, new SecureRandom());
}
/**
* Create session identifiers.
*/
public RandomString() {
this(21);
}
/**
* Generate a random string.
*/
public final String nextString() {
for (int idx = 0; idx < buf.length; ++idx) buf[idx] = symbols[random.nextInt(symbols.length)];
return new String(buf);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package me.finn.unlegitlibrary.string;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
public class SimpleEncoderDecoder extends DefaultMethodsOverrider {
private static SecretKeySpec secretKey;
private static byte[] keyByte;
private static void setKey(final EncoderDecoderKeys key) throws NoSuchAlgorithmException {
keyByte = key.getKey().getBytes(StandardCharsets.UTF_8);
MessageDigest sha = MessageDigest.getInstance("SHA-1");
keyByte = sha.digest(keyByte);
keyByte = Arrays.copyOf(keyByte, 16);
secretKey = new SecretKeySpec(keyByte, "AES");
}
public static String encrypt(final Object toEncrypt, final EncoderDecoderKeys key) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
setKey(key);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return Base64.getEncoder().encodeToString(cipher.doFinal(toEncrypt.toString().getBytes(StandardCharsets.UTF_8)));
}
public static String decrypt(final Object toDecrypt, final EncoderDecoderKeys key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
setKey(key);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return new String(cipher.doFinal(Base64.getDecoder().decode(toDecrypt.toString())));
}
public static class EncoderDecoderKeys {
public static final EncoderDecoderKeys BIT_KEY_128 = new EncoderDecoderKeys("Bar12345Bar12345");
public static final EncoderDecoderKeys DEC1632DDCL542 = new EncoderDecoderKeys("Dec1632DDCL542");
public static final EncoderDecoderKeys SSSHHHHHHHHHHH = new EncoderDecoderKeys("ssshhhhhhhhhhh!!!!");
private final String key;
public EncoderDecoderKeys(String key) {
this.key = key;
}
public final String getKey() {
return key;
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package me.finn.unlegitlibrary.string;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
import java.util.ArrayList;
import java.util.List;
public class StringUtils extends DefaultMethodsOverrider {
public static String removeLastChar(String string) {
return string.substring(0, string.length() - 1);
}
public static String removeCharAtIndex(String string, int index) {
return string.substring(0, index) + string.substring(index + 1);
}
public static String reverseString(String string) {
return new StringBuilder(string).reverse().toString();
}
public static String[] removeEmptyStrings(String[] strings) {
List<String> result = new ArrayList<>();
for (int i = 0; i < strings.length; i++) if (!isEmptyString(strings[i])) result.add(strings[i]);
String[] res = new String[result.size()];
result.toArray(res);
return res;
}
public static boolean isEmptyString(String string) {
return string == null || string.isEmpty() || string.isBlank() || string.equalsIgnoreCase(" ");
}
public static String[] removeEmptyStringsExceptWhitespace(String[] strings) {
List<String> result = new ArrayList<>();
for (int i = 0; i < strings.length; i++) if (!isEmptyStringExceptWhitespace(strings[i])) result.add(strings[i]);
String[] res = new String[result.size()];
result.toArray(res);
return res;
}
public static boolean isEmptyStringExceptWhitespace(String string) {
if (string == null) return true;
return (string.isEmpty() || string.isBlank()) && !string.equalsIgnoreCase(" ");
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package me.finn.unlegitlibrary.string.color;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
public class ConsoleColor extends DefaultMethodsOverrider {
// Reset
public static final String RESET = "\033[0m"; // Text Reset
// Regular Colors
public static final String BLACK = "\033[0;30m"; // BLACK
public static final String RED = "\033[0;31m"; // RED
public static final String GREEN = "\033[0;32m"; // GREEN
public static final String YELLOW = "\033[0;33m"; // YELLOW
public static final String BLUE = "\033[0;34m"; // BLUE
public static final String PURPLE = "\033[0;35m"; // PURPLE
public static final String CYAN = "\033[0;36m"; // CYAN
public static final String WHITE = "\033[0;37m"; // WHITE
// Bold
public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
public static final String RED_BOLD = "\033[1;31m"; // RED
public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
public static final String YELLOW_BOLD = "\033[1;33m"; // YELLOW
public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
public static final String PURPLE_BOLD = "\033[1;35m"; // PURPLE
public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
public static final String WHITE_BOLD = "\033[1;37m"; // WHITE
// Underline
public static final String BLACK_UNDERLINED = "\033[4;30m"; // BLACK
public static final String RED_UNDERLINED = "\033[4;31m"; // RED
public static final String GREEN_UNDERLINED = "\033[4;32m"; // GREEN
public static final String YELLOW_UNDERLINED = "\033[4;33m"; // YELLOW
public static final String BLUE_UNDERLINED = "\033[4;34m"; // BLUE
public static final String PURPLE_UNDERLINED = "\033[4;35m"; // PURPLE
public static final String CYAN_UNDERLINED = "\033[4;36m"; // CYAN
public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
// Background
public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
public static final String RED_BACKGROUND = "\033[41m"; // RED
public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
// High Intensity
public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
public static final String RED_BRIGHT = "\033[0;91m"; // RED
public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
// Bold High Intensity
public static final String BLACK_BOLD_BRIGHT = "\033[1;90m"; // BLACK
public static final String RED_BOLD_BRIGHT = "\033[1;91m"; // RED
public static final String GREEN_BOLD_BRIGHT = "\033[1;92m"; // GREEN
public static final String YELLOW_BOLD_BRIGHT = "\033[1;93m";// YELLOW
public static final String BLUE_BOLD_BRIGHT = "\033[1;94m"; // BLUE
public static final String PURPLE_BOLD_BRIGHT = "\033[1;95m";// PURPLE
public static final String CYAN_BOLD_BRIGHT = "\033[1;96m"; // CYAN
public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
// High Intensity backgrounds
public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package me.finn.unlegitlibrary.string.color;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
import java.awt.*;
import java.util.ArrayList;
import java.util.Scanner;
public class MinecraftColorUtils extends DefaultMethodsOverrider {
public static int clamp_int(int num, int min, int max) {
return num < min ? min : (Math.min(num, max));
}
public static int toRGB(int red, int green, int blue, int alpha) {
return (alpha & 0xFF) << 24 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF;
}
public static String toColor(String colorChar) {
return '§' + colorChar;
}
public static String booleanToColor(boolean value) {
return value ? Color.GREEN.toString() : Color.RED.toString();
}
public static int getAstolfo(int delay, float offset, float hueSetting) {
float speed = 500;
float hue = (float) (System.currentTimeMillis() % delay) + offset;
while (hue > speed) hue -= speed;
hue /= speed;
if (hue > 0.5D) hue = 0.5F - hue - 0.5F;
hue += hueSetting;
return Color.HSBtoRGB(hue, 0.5F, 1.0F);
}
public static String removeColorCodes(String message) {
String colorCodes = "0123456789abcdefklmnor";
ArrayList<String> colors = new ArrayList<String>();
for (char c : colorCodes.toCharArray()) colors.add("" + c);
Object object = colors.iterator();
while (((Scanner) object).hasNext()) {
String s = ((Scanner) object).next();
message = message.replaceAll("\u00a7" + s, "");
}
return message;
}
public static Color rainbowEffect(final long offset, final float fade) {
final float hue = (System.nanoTime() + offset) / 1.0E10f % 1.0f;
final long color = Long.parseLong(Integer.toHexString(Color.HSBtoRGB(hue, 1.0f, 1.0f)), 16);
final Color c = new Color((int) color);
return new Color(c.getRed() / 255.0f * fade, c.getGreen() / 255.0f * fade, c.getBlue() / 255.0f * fade, c.getAlpha() / 255.0f);
}
public static int rainbowEffect() {
return Color.HSBtoRGB((float) (System.currentTimeMillis() % 3000L) / 3000.0F, 0.8F, 1.0F);
}
public static int chroma(float delay) {
double rainbowState = Math.ceil((System.currentTimeMillis() + delay) / 20.0);
rainbowState %= 360;
return Color.HSBtoRGB((float) (rainbowState / 360.0F), 0.75F, 1.0F);
}
public static int rgbColor(int red, int green, int blue) {
return new Color(red, green, blue).getRGB();
}
public static int rainbow(float seconds, float saturation, float brightness) {
return Color.HSBtoRGB((System.currentTimeMillis() % (int) (seconds * 1000)) / (seconds * 1000), saturation, brightness);
}
public static int getColor(int offset) {
return getAstolfo(10000000, offset, 0.5F);
}
public static int getColor(Color color) {
return getColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
public static int getColor(int brightness, int alpha) {
return getColor(brightness, brightness, brightness, alpha);
}
public static int getColor(int red, int green, int blue) {
return getColor(red, green, blue, 255);
}
public static int getColor(int red, int green, int blue, int alpha) {
int color = clamp_int(alpha, 0, 255) << 24;
color |= clamp_int(red, 0, 255) << 16;
color |= clamp_int(green, 0, 255) << 8;
color |= clamp_int(blue, 0, 255);
return color;
}
public static Color getAstolfoColor(int delay, float offset) {
float speed = 500;
float hue = (float) (System.currentTimeMillis() % delay) + offset;
while (hue > speed) hue -= speed;
hue /= speed;
if (hue > 0.5D) hue = 0.5F - hue - 0.5F;
hue += 0.5F;
return Color.getHSBColor(hue, 0.5F, 1.0F);
}
public static Color getColorWave(Color color, float offset) {
float speed = 500;
float hue = (float) (System.currentTimeMillis() % 10000000L) + offset;
while (hue > speed) hue -= speed;
hue /= speed;
if (hue > 0.5D) hue = 0.5F - hue - 0.5F;
hue += 0.5F;
float[] colors = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
return Color.getHSBColor(colors[0], 1.0F, hue);
}
}