diff --git a/README.md b/README.md
index 33ccbea7..c3dedd88 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,13 @@
-SeverUtilities
+ServerUtilities
===============
-ServerUtilities for server owners. Fork and Rebrand of FTBUtilities, FTBLibrary, and LatCore 1.7.10.
+ServerUtilities for server owners. Backport and Rebrand of the 1.12.2 version of FTBUtilities, FTBLibrary, and Aurora for 1.7.10.
+Fully backwards compatible with homes, chunks and warps. These will be loaded from FTBU on first load.
+
+Utilizes a permission system to handle whether a player can use certain commands and do certain things.
+A full list of permissions along with their description can be dumped using the command /dump_permissions,
+the file will be placed at .minecraft/serverutilities/server/.
+They can also be viewed using the Aurora webapi.
### License
@@ -18,7 +24,10 @@ Original code Copyright (c) 2016 LatvianModder and licensed MIT (Based on LatMod
![Lat MIT License](lat-mit-license.png)
![Lat FTBU License](lat-ftbu-license-discord.png)
-* [FTB Utilities wayback machine license](https://web.archive.org/web/20190418033327/https://minecraft.curseforge.com/projects/ftb-utilities)
+* [FTB Utilities wayback machine license](https://web.archive.org/web/20190624234434/https://minecraft.curseforge.com/projects/ftb-utilities)
![FTB Utilities License CF Wayback](ftbu-license-wayback.png)
* [FTB Library wayback machine license](https://web.archive.org/web/20190418011645/https://minecraft.curseforge.com/projects/ftblib)
![FTB Library License CF Wayback](ftbl-license-wayback.png)
+
+* Aurora License
+![image](https://github.com/GTNewHorizons/ServerUtilities/assets/3237986/eecd36d3-6b77-4286-9767-3f4aa2dd008f)
diff --git a/build.gradle b/build.gradle
index b894d647..e59189c8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,4 +1,4 @@
-//version: 1692122114
+//version: 1697697256
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
@@ -89,6 +89,23 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
def projectJavaVersion = JavaLanguageVersion.of(8)
boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false
+boolean disableCheckstyle = project.hasProperty("disableCheckstyle") ? project.disableCheckstyle.toBoolean() : false
+
+final String CHECKSTYLE_CONFIG = """
+
+
+
+
+
+
+
+
+
+
+
+"""
checkPropertyExists("modName")
checkPropertyExists("modId")
@@ -140,6 +157,17 @@ if (!disableSpotless) {
apply from: Blowdryer.file('spotless.gradle')
}
+if (!disableCheckstyle) {
+ apply plugin: 'checkstyle'
+ tasks.named("checkstylePatchedMc") { enabled = false }
+ tasks.named("checkstyleMcLauncher") { enabled = false }
+ tasks.named("checkstyleIdeVirtualMain") { enabled = false }
+ tasks.named("checkstyleInjectedTags") { enabled = false }
+ checkstyle {
+ config = resources.text.fromString(CHECKSTYLE_CONFIG)
+ }
+}
+
String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
String kotlinSourceDir = "src/main/kotlin/"
@@ -600,15 +628,10 @@ repositories {
}
maven {
name = "ic2"
- url = "https://maven.ic2.player.to/"
- metadataSources {
- mavenPom()
- artifact()
+ url = getURL("https://maven.ic2.player.to/", "https://maven2.ic2.player.to/")
+ content {
+ includeGroup "net.industrial-craft"
}
- }
- maven {
- name = "ic2-mirror"
- url = "https://maven2.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
@@ -770,23 +793,14 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies"
}
dependencies {
- def lwjgl3ifyVersion = '1.4.0'
- def asmVersion = '9.4'
+ def lwjgl3ifyVersion = '1.5.1'
if (modId != 'lwjgl3ify') {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
- java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.26')
+ java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.17')
}
- java17PatchDependencies('net.minecraft:launchwrapper:1.17.2') {transitive = false}
- java17PatchDependencies("org.ow2.asm:asm:${asmVersion}")
- java17PatchDependencies("org.ow2.asm:asm-commons:${asmVersion}")
- java17PatchDependencies("org.ow2.asm:asm-tree:${asmVersion}")
- java17PatchDependencies("org.ow2.asm:asm-analysis:${asmVersion}")
- java17PatchDependencies("org.ow2.asm:asm-util:${asmVersion}")
- java17PatchDependencies('org.ow2.asm:asm-deprecated:7.1')
- java17PatchDependencies("org.apache.commons:commons-lang3:3.12.0")
java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false}
}
@@ -1576,6 +1590,25 @@ def getSecondaryArtifacts() {
return secondaryArtifacts
}
+def getURL(String main, String fallback) {
+ return pingURL(main, 10000) ? main : fallback
+}
+
+// credit: https://stackoverflow.com/a/3584332
+def pingURL(String url, int timeout) {
+ url = url.replaceFirst("^https", "http") // Otherwise an exception may be thrown on invalid SSL certificates.
+ try {
+ HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection()
+ connection.setConnectTimeout(timeout)
+ connection.setReadTimeout(timeout)
+ connection.setRequestMethod("HEAD")
+ int responseCode = connection.getResponseCode()
+ return 200 <= responseCode && responseCode <= 399
+ } catch (IOException ignored) {
+ return false
+ }
+}
+
// For easier scripting of things that require variables defined earlier in the buildscript
if (file('addon.late.gradle.kts').exists()) {
apply from: 'addon.late.gradle.kts'
diff --git a/dependencies.gradle b/dependencies.gradle
index bb71379a..d6192fc7 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -1,5 +1,10 @@
// Add your dependencies here
dependencies {
- api("com.github.GTNewHorizons:waila:1.6.0:dev")
+
+ compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.3.81-GTNH:dev")
+
+ runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.6.2:dev")
+
+ shadowCompile("it.unimi.dsi:fastutil:8.5.12")
}
diff --git a/gradle.properties b/gradle.properties
index 021ef6d4..7f0fb492 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,9 +1,9 @@
modName = ServerUtilities
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
-modId = ServerUtilities
+modId = serverutilities
-modGroup = serverutils.utils
+modGroup = serverutils
# WHY is there no version field?
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
@@ -21,12 +21,16 @@ forgeVersion = 10.13.4.1614
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
developmentEnvironmentUserName = Developer
+# Enables using modern java syntax (up to version 17) via Jabel, while still targetting JVM 8.
+# See https://github.com/bsideup/jabel for details on how this works.
+enableModernJavaSyntax = true
+
# Define a source file of your project with:
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...])
# Leave these properties empty to skip individual token replacements
-replaceGradleTokenInFile = ServerUtilitiesFinals.java
+replaceGradleTokenInFile = ServerUtilities.java
gradleTokenModId =
gradleTokenModName =
gradleTokenVersion = GRADLETOKEN_VERSION
@@ -39,7 +43,7 @@ apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
-accessTransformersFile =
+accessTransformersFile = serverutil_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
@@ -57,7 +61,7 @@ containsMixinsAndOrCoreModOnly = false
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
# responsibility check the licence and request permission for distribution, if required.
-usesShadowedDependencies = false
+usesShadowedDependencies = true
# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
# projects. New projects should not use this parameter.
diff --git a/src/main/java/latmod/lib/Bits.java b/src/main/java/latmod/lib/Bits.java
deleted file mode 100644
index f60b210a..00000000
--- a/src/main/java/latmod/lib/Bits.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package latmod.lib;
-
-import java.util.UUID;
-
-/**
- * Made by LatvianModder
- */
-public class Bits {
-
- private static final int MAX_BYTE = 0xFF;
- private static final int MAX_SHORT = 0xFFFF;
- private static final long MAX_INT = 0xFFFFFFFFL;
-
- public static int toInt(boolean[] b) {
- int d = 0;
- for (int i = 0; i < b.length; i++) d |= (b[i] ? 1 : 0) << i;
- return d;
- }
-
- public static void toBool(boolean[] b, int d) {
- for (int j = 0; j < b.length; j++) b[j] = ((d >> j) & 1) == 1;
- }
-
- public static boolean getBit(byte bits, byte i) {
- return ((bits >> i) & 1) == 1;
- }
-
- public static int toBit(boolean b, byte i) {
- return (b ? 1 : 0) << i;
- }
-
- public static byte setBit(byte bits, byte i, boolean v) {
- if (v) return (byte) ((bits & 0xFF) | (1 << i));
- else return (byte) ((bits & 0xFF) & (not(1 << i) & 0xFF));
- }
-
- public static int not(int bits) {
- return (~bits) & 0xFF;
- }
-
- //
-
- // Int
- public static long intsToLong(int a, int b) {
- return (((long) a) << 32) | (b & MAX_INT);
- }
-
- public static int intFromLongA(long l) {
- return (int) (l >> 32);
- }
-
- public static int intFromLongB(long l) {
- return (int) l;
- }
-
- // Short
- public static int shortsToInt(int a, int b) {
- return ((short) a << 16) | ((short) b & MAX_SHORT);
- }
-
- public static short shortFromIntA(int i) {
- return (short) (i >> 16);
- }
-
- public static short shortFromIntB(int i) {
- return (short) (i & MAX_SHORT);
- }
-
- // Byte
- public static short bytesToShort(int a, int b) {
- return (short) (((a & MAX_BYTE) << 8) | (b & MAX_BYTE));
- }
-
- public static byte byteFromShortA(short s) {
- return (byte) ((s >> 8) & MAX_BYTE);
- }
-
- public static byte byteFromShortB(short s) {
- return (byte) (s & MAX_BYTE);
- }
-
- // - //
-
- public static int toUShort(byte[] b, int off) {
- int ch1 = b[off] & MAX_BYTE;
- int ch2 = b[off + 1] & MAX_BYTE;
- return (ch1 << 8) + ch2;
- }
-
- public static int toInt(byte[] b, int off) {
- int ch1 = b[off] & MAX_BYTE;
- int ch2 = b[off + 1] & MAX_BYTE;
- int ch3 = b[off + 2] & MAX_BYTE;
- int ch4 = b[off + 3] & MAX_BYTE;
- return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + ch4;
- }
-
- public static long toLong(byte[] b, int off) {
- return (((long) b[off] << 56) + ((long) (b[off + 1] & MAX_BYTE) << 48)
- + ((long) (b[off + 2] & MAX_BYTE) << 40)
- + ((long) (b[off + 3] & MAX_BYTE) << 32)
- + ((long) (b[off + 4] & MAX_BYTE) << 24)
- + ((b[off + 5] & MAX_BYTE) << 16)
- + ((b[off + 6] & MAX_BYTE) << 8)
- + ((b[off + 7] & MAX_BYTE)));
- }
-
- public static UUID toUUID(byte[] b, int off) {
- long msb = toLong(b, off);
- long lsb = toLong(b, off + 8);
- return new UUID(msb, lsb);
- }
-
- // - //
-
- public static void fromUShort(byte[] b, int off, int v) {
- b[off] = (byte) (v >>> 8);
- b[off + 1] = (byte) v;
- }
-
- public static void fromInt(byte[] b, int off, int v) {
- b[off] = (byte) (v >>> 24);
- b[off + 1] = (byte) (v >>> 16);
- b[off + 2] = (byte) (v >>> 8);
- b[off + 3] = (byte) v;
- }
-
- public static void fromLong(byte[] b, int off, long v) {
- b[off] = (byte) (v >>> 56);
- b[off + 1] = (byte) (v >>> 48);
- b[off + 2] = (byte) (v >>> 40);
- b[off + 3] = (byte) (v >>> 32);
- b[off + 4] = (byte) (v >>> 24);
- b[off + 5] = (byte) (v >>> 16);
- b[off + 6] = (byte) (v >>> 8);
- b[off + 7] = (byte) v;
- }
-
- public static void fromUUID(byte[] b, int off, UUID uuid) {
- fromLong(b, off, uuid.getMostSignificantBits());
- fromLong(b, off + 8, uuid.getLeastSignificantBits());
- }
-}
diff --git a/src/main/java/latmod/lib/ByteCompressor.java b/src/main/java/latmod/lib/ByteCompressor.java
deleted file mode 100644
index aa0e7e83..00000000
--- a/src/main/java/latmod/lib/ByteCompressor.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package latmod.lib;
-
-import java.io.ByteArrayOutputStream;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-public class ByteCompressor {
-
- public static byte[] compress(byte[] data, int off, int len) throws Exception {
- Deflater d = new Deflater();
- d.setInput(data, off, len);
- ByteArrayOutputStream os = new ByteArrayOutputStream(len);
- d.finish();
-
- byte[] buffer = new byte[1024];
- while (!d.finished()) {
- int count = d.deflate(buffer);
- os.write(buffer, 0, count);
- }
-
- os.close();
- byte[] output = os.toByteArray();
- d.end();
- return output;
- }
-
- public static byte[] decompress(byte[] data, int off, int len) throws Exception {
- Inflater i = new Inflater();
- i.setInput(data, off, len);
-
- ByteArrayOutputStream os = new ByteArrayOutputStream(len);
- byte[] buffer = new byte[1024];
- while (!i.finished()) {
- int count = i.inflate(buffer);
- os.write(buffer, 0, count);
- }
-
- os.close();
- byte[] output = os.toByteArray();
- i.end();
- return output;
- }
-}
diff --git a/src/main/java/latmod/lib/ByteCount.java b/src/main/java/latmod/lib/ByteCount.java
deleted file mode 100644
index b35db212..00000000
--- a/src/main/java/latmod/lib/ByteCount.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package latmod.lib;
-
-public enum ByteCount {
-
- BYTE(1),
- SHORT(2),
- INT(4);
-
- public final int bytes;
-
- ByteCount(int i) {
- bytes = i;
- }
-
- public void write(ByteIOStream io, int num) {
- if (this == BYTE) io.writeByte(num);
- else if (this == SHORT) io.writeShort(num);
- else io.writeInt(num);
- }
-
- public int read(ByteIOStream io) {
- if (this == BYTE) {
- byte b = io.readByte();
- if (b == -1) return -1;
- return b & 0xFF;
- } else if (this == SHORT) {
- short s = io.readShort();
- if (s == -1) return -1;
- return s & 0xFFFF;
- }
- return io.readInt();
- }
-}
diff --git a/src/main/java/latmod/lib/ByteIOStream.java b/src/main/java/latmod/lib/ByteIOStream.java
deleted file mode 100644
index be9a4de6..00000000
--- a/src/main/java/latmod/lib/ByteIOStream.java
+++ /dev/null
@@ -1,427 +0,0 @@
-package latmod.lib;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UTFDataFormatException;
-import java.util.UUID;
-
-/**
- * Made by LatvianModder
- */
-public final class ByteIOStream implements DataInput, DataOutput {
-
- protected byte[] bytes;
- protected int pos;
-
- private static void throwUTFException(String s) {
- try {
- throw new UTFDataFormatException(s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public ByteIOStream(int size) {
- bytes = new byte[size];
- }
-
- public ByteIOStream() {
- this(0);
- }
-
- public int getDataPos() {
- return pos;
- }
-
- public int available() {
- return bytes.length - pos;
- }
-
- public byte[] toByteArray() {
- if (pos == bytes.length) return bytes;
- byte[] b = new byte[pos];
- System.arraycopy(bytes, 0, b, 0, pos);
- return b;
- }
-
- public byte[] toCompressedByteArray() {
- try {
- return ByteCompressor.compress(bytes, 0, pos);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public void expand(int c) {
- if (pos + c >= bytes.length) {
- byte[] b = new byte[bytes.length + Math.max(c, 16)];
- System.arraycopy(bytes, 0, b, 0, pos);
- bytes = b;
- }
- }
-
- public void flip() {
- pos = 0;
- }
-
- public void setData(byte[] b) {
- bytes = b;
- flip();
- }
-
- public void setCompressedData(byte[] b) {
- try {
- setData(ByteCompressor.decompress(b, 0, b.length));
- } catch (Exception e) {
- e.printStackTrace();
- setData(null);
- }
- }
-
- public String toString() {
- return toString(false);
- }
-
- public String toString(boolean compressed) {
- byte[] b = compressed ? toCompressedByteArray() : toByteArray();
- return "[ (" + b.length + ") " + LMStringUtils.stripB(b) + " ]";
- }
-
- public OutputStream createOutputStream() {
- return new OutputStream() {
-
- public void write(int b) throws IOException {
- ByteIOStream.this.write(b);
- }
-
- public void write(byte b[], int off, int len) throws IOException {
- ByteIOStream.this.write(b, off, len);
- }
- };
- }
-
- public InputStream createInputStream() {
- return new InputStream() {
-
- public int read() throws IOException {
- return (available() <= 0) ? -1 : ByteIOStream.this.readUnsignedByte();
- }
-
- public int read(byte b[], int off, int len) throws IOException {
- ByteIOStream.this.readFully(b, off, len);
- return len;
- }
-
- public int available() {
- return ByteIOStream.this.available();
- }
- };
- }
-
- // Read functions //
-
- public byte readByte() {
- byte b = bytes[pos];
- pos++;
- return b;
- }
-
- public void readFully(byte[] b, int off, int len) {
- if (b == null || len == 0) return;
- System.arraycopy(bytes, pos, b, off, len);
- pos += len;
- }
-
- public int readUnsignedByte() {
- return readByte() & 0xFF;
- }
-
- public void readFully(byte[] b) {
- readFully(b, 0, b.length);
- }
-
- public byte[] readByteArray(ByteCount c) {
- int s = c.read(this);
- if (s == -1) return null;
- byte[] b = new byte[s];
- readFully(b);
- return b;
- }
-
- public boolean readBoolean() {
- return readUnsignedByte() == 1;
- }
-
- public char readChar() {
- return (char) readUnsignedShort();
- }
-
- public String readUTF() {
- int l = readUnsignedShort();
- if (l == 65535) return null;
- else if (l == 0) return "";
-
- char[] utf_chars = new char[l];
-
- int c, c2, c3, c1 = 0, cac = 0, pos0 = pos;
-
- pos += l;
-
- while (c1 < l) {
- c = (int) bytes[c1 + pos0] & 0xFF;
- if (c > 127) break;
- c1++;
- utf_chars[cac++] = (char) c;
- }
-
- while (c1 < l) {
- c = (int) bytes[c1 + pos0] & 0xFF;
-
- switch (c >> 4) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- c1++;
- utf_chars[cac++] = (char) c;
- break;
- case 12:
- case 13:
- c1 += 2;
- if (c1 > l) throwUTFException("malformed input: partial character at end");
- c2 = (int) bytes[c1 + pos0 - 1];
- if ((c2 & 0xC0) != 0x80) throwUTFException("malformed input around byte " + c1);
- utf_chars[cac++] = (char) (((c & 0x1F) << 6) | (c2 & 0x3F));
- break;
- case 14:
- c1 += 3;
- if (c1 > l) throwUTFException("malformed input: partial character at end");
- c2 = (int) bytes[c1 + pos0 - 2];
- c3 = (int) bytes[c1 + pos0 - 1];
- if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80))
- throwUTFException("malformed input around byte " + (c1 - 1));
- utf_chars[cac++] = (char) (((c & 0x0F) << 12) | ((c2 & 0x3F) << 6) | ((c3 & 0x3F)));
- break;
- default:
- throwUTFException("malformed input around byte " + c1);
- }
- }
-
- String s = new String(utf_chars, 0, cac);
- utf_chars = null;
- return s;
- }
-
- @Deprecated
- public String readLine() {
- return null;
- }
-
- public int readUnsignedShort() {
- int v = Bits.toUShort(bytes, pos);
- pos += 2;
- return v;
- }
-
- public short readShort() {
- return (short) readUnsignedShort();
- }
-
- public int readInt() {
- int v = Bits.toInt(bytes, pos);
- pos += 4;
- return v;
- }
-
- public long readLong() {
- long v = Bits.toLong(bytes, pos);
- pos += 8;
- return v;
- }
-
- public float readFloat() {
- return Float.intBitsToFloat(readInt());
- }
-
- public double readDouble() {
- return Double.longBitsToDouble(readLong());
- }
-
- public UUID readUUID() {
- UUID v = Bits.toUUID(bytes, pos);
- pos += 16;
- return v;
- }
-
- public int[] readIntArray(ByteCount c) {
- int len = c.read(this);
- if (len == -1) return null;
- int[] ai = new int[len];
- for (int i = 0; i < len; i++) ai[i] = readInt();
- return ai;
- }
-
- // Write functions //
-
- public void writeByte(int i) {
- expand(1);
- bytes[pos] = (byte) i;
- pos++;
- }
-
- public void write(int b) {
- writeByte(b);
- }
-
- public void write(byte[] b, int off, int len) {
- if (b == null || len == 0) return;
- expand(len);
- System.arraycopy(b, off, bytes, pos, len);
- pos += len;
- }
-
- public void write(byte[] b) {
- write(b, 0, b.length);
- }
-
- public void writeByteArray(byte[] b, ByteCount c) {
- if (b == null) {
- c.write(this, -1);
- return;
- }
- c.write(this, b.length);
- write(b);
- }
-
- public void writeBoolean(boolean b) {
- writeByte(b ? 1 : 0);
- }
-
- public void writeChar(int c) {
- writeShort(c);
- }
-
- public void writeUTF(String s) {
- if (s == null) {
- writeShort(-1);
- return;
- }
- int sl = s.length();
- if (sl == 0) {
- writeShort(0);
- return;
- }
- int l = 0;
- int c;
-
- for (int i = 0; i < sl; i++) {
- c = s.charAt(i);
- if ((c >= 0x0001) && (c <= 0x007F)) l++;
- else if (c > 0x07FF) l += 3;
- else l += 2;
- }
-
- if (l >= 65535) throwUTFException("encoded string too long: " + l + " bytes");
-
- writeShort(l);
- expand(l);
-
- int i = 0;
- for (i = 0; i < sl; i++) {
- c = s.charAt(i);
- if (!(c >= 0x0001 && c <= 0x007F)) break;
- writeByte(c);
- }
-
- for (; i < sl; i++) {
- c = s.charAt(i);
- if (c >= 0x0001 && c <= 0x007F) writeByte(c);
- else if (c > 0x07FF) {
- writeByte(0xE0 | ((c >> 12) & 0x0F));
- writeByte(0x80 | ((c >> 6) & 0x3F));
- writeByte(0x80 | ((c) & 0x3F));
- } else {
- writeByte(0xC0 | ((c >> 6) & 0x1F));
- writeByte(0x80 | ((c) & 0x3F));
- }
- }
- }
-
- public void writeBytes(String s) {
- if (s == null || s.isEmpty()) return;
- for (int i = 0; i < s.length(); i++) writeByte((byte) s.charAt(i));
- }
-
- public void writeChars(String s) {
- if (s == null || s.isEmpty()) return;
- for (int i = 0; i < s.length(); i++) writeChar(s.charAt(i));
- }
-
- public void writeShort(int s) {
- expand(2);
- Bits.fromUShort(bytes, pos, s);
- pos += 2;
- }
-
- public void writeInt(int i) {
- expand(4);
- Bits.fromInt(bytes, pos, i);
- pos += 4;
- }
-
- public void writeLong(long l) {
- expand(8);
- Bits.fromLong(bytes, pos, l);
- pos += 8;
- }
-
- public void writeFloat(float f) {
- writeInt(Float.floatToIntBits(f));
- }
-
- public void writeDouble(double d) {
- writeLong(Double.doubleToLongBits(d));
- }
-
- public void writeUUID(UUID uuid) {
- expand(16);
- Bits.fromUUID(bytes, pos, uuid);
- pos += 16;
- }
-
- public void writeIntArray(int[] ai, ByteCount c) {
- int asize = (ai == null) ? -1 : ai.length;
- c.write(this, asize);
- for (int i = 0; i < asize; i++) writeInt(ai[i]);
- }
-
- public int skipBytes(int n) {
- return 0;
- }
-
- public static int getUTFLength(String data) {
- if (data == null) return -1;
- else if (data.isEmpty()) return 0;
- else {
- int len = 0;
- char c;
-
- for (int i = 0; i < data.length(); i++) {
- c = data.charAt(i);
- if ((c >= 0x0001) && (c <= 0x007F)) len++;
- else if (c > 0x07FF) len += 3;
- else len += 2;
- }
-
- return len;
- }
- }
-}
diff --git a/src/main/java/latmod/lib/Converter.java b/src/main/java/latmod/lib/Converter.java
deleted file mode 100644
index 7c3b8f69..00000000
--- a/src/main/java/latmod/lib/Converter.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package latmod.lib;
-
-import java.util.Arrays;
-
-/**
- * Made by LatvianModder
- */
-public class Converter {
-
- public static int[] toInts(byte[] b) {
- if (b == null) return null;
- int ai[] = new int[b.length];
- for (int i = 0; i < ai.length; i++) ai[i] = b[i] & 0xFF;
- return ai;
- }
-
- public static int[] toInts(short[] b) {
- if (b == null) return null;
- int ai[] = new int[b.length];
- for (int i = 0; i < ai.length; i++) ai[i] = b[i];
- return ai;
- }
-
- public static byte[] toBytes(int[] b) {
- if (b == null) return null;
- byte ai[] = new byte[b.length];
- for (int i = 0; i < ai.length; i++) ai[i] = (byte) b[i];
- return ai;
- }
-
- public static Integer[] fromInts(int[] i) {
- if (i == null) return null;
- Integer ai[] = new Integer[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static int[] toInts(Integer[] i) {
- if (i == null) return null;
- int ai[] = new int[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static Float[] fromFloats(float[] i) {
- if (i == null) return null;
- Float ai[] = new Float[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static float[] toFloats(Float[] i) {
- if (i == null) return null;
- float ai[] = new float[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static Double[] fromDoubles(double[] i) {
- if (i == null) return null;
- Double ai[] = new Double[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static double[] toDoubles(Double[] i) {
- if (i == null) return null;
- double ai[] = new double[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static Byte[] fromBytes(byte[] i) {
- if (i == null) return null;
- Byte ai[] = new Byte[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static byte[] toBytes(Byte[] i) {
- if (i == null) return null;
- byte ai[] = new byte[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static float[] toFloats(double[] i) {
- if (i == null) return null;
- float ai[] = new float[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = (float) i[j];
- return ai;
- }
-
- public static double[] toDoubles(float[] i) {
- if (i == null) return null;
- double ai[] = new double[i.length];
- for (int j = 0; j < ai.length; j++) ai[j] = i[j];
- return ai;
- }
-
- public static void toBools(boolean[] bools, IntList idx, boolean isTrue) {
- Arrays.fill(bools, !isTrue);
- for (int i = 0; i < idx.size(); i++) bools[idx.get(i)] = isTrue;
- }
-
- public static void fromBools(boolean[] bools, IntList il, boolean isTrue) {
- il.clear();
- for (int i = 0; i < bools.length; i++) if (bools[i] == isTrue) il.add(i);
- }
-
- public static boolean canParseInt(String s) {
- try {
- Integer.parseInt(s);
- return true;
- } catch (Exception e) {}
- return false;
- }
-
- public static boolean canParseDouble(String s) {
- try {
- Double.parseDouble(s);
- return true;
- } catch (Exception e) {}
- return false;
- }
-
- public static int toInt(String text, int def) {
- try {
- return Integer.parseInt(text);
- } catch (Exception e) {}
- return def;
- }
-
- public static int nonNull(Integer i) {
- return (i == null) ? 0 : i;
- }
-
- public static double nonNull(Double d) {
- return (d == null) ? 0D : d;
- }
-}
diff --git a/src/main/java/latmod/lib/IIDObject.java b/src/main/java/latmod/lib/IIDObject.java
deleted file mode 100644
index 8c48e9b1..00000000
--- a/src/main/java/latmod/lib/IIDObject.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package latmod.lib;
-
-/**
- * Created by LatvianModder on 05.03.2016.
- */
-public interface IIDObject {
-
- String getID();
-}
diff --git a/src/main/java/latmod/lib/IntList.java b/src/main/java/latmod/lib/IntList.java
deleted file mode 100644
index 0f051aec..00000000
--- a/src/main/java/latmod/lib/IntList.java
+++ /dev/null
@@ -1,264 +0,0 @@
-package latmod.lib;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.google.gson.JsonElement;
-
-public class IntList implements Iterable {
-
- private int defVal = -1;
- private int array[];
- private int size;
-
- public IntList(int i) {
- array = new int[i];
- }
-
- public IntList() {
- this(0);
- }
-
- public IntList(int[] ai) {
- if (ai != null && ai.length > 0) {
- size = ai.length;
- array = new int[size];
- System.arraycopy(ai, 0, array, 0, size);
- } else {
- size = 0;
- array = new int[0];
- }
- }
-
- public int size() {
- return size;
- }
-
- public void clear() {
- if (size > 0) {
- size = 0;
- array = new int[0];
- }
- }
-
- public IntList setDefVal(int value) {
- defVal = value;
- return this;
- }
-
- public void expand(int s) {
- if (size + s > array.length) {
- int ai[] = new int[size + Math.max(s, 10)];
- System.arraycopy(array, 0, ai, 0, size);
- array = ai;
- }
- }
-
- public void add(int value) {
- expand(1);
- array[size] = value;
- size++;
- }
-
- public void addAll(int... values) {
- if (values != null && values.length > 0) {
- expand(values.length);
- System.arraycopy(values, 0, array, size, values.length);
- size += values.length;
- }
- }
-
- public void addAll(IntList l) {
- if (l != null && l.size > 0) {
- expand(l.size);
- System.arraycopy(l.array, 0, array, size, l.size);
- size += l.size;
- }
- }
-
- public int get(int index) {
- return (index >= 0 && index < size) ? array[index] : defVal;
- }
-
- public int indexOf(int value) {
- if (size == 0) return -1;
- for (int i = 0; i < size; i++) if (array[i] == value) return i;
- return -1;
- }
-
- public boolean contains(int value) {
- return indexOf(value) != -1;
- }
-
- public int removeKey(int key) {
- if (key < 0 || key >= size) return defVal;
- int rem = get(key);
- size--;
- System.arraycopy(array, key + 1, array, key, size - key);
- return rem;
- }
-
- public int removeValue(int value) {
- return removeKey(indexOf(value));
- }
-
- public void set(int i, int value) {
- array[i] = value;
- }
-
- public boolean isEmpty() {
- return size <= 0;
- }
-
- public int[] toArray() {
- return toArray(null);
- }
-
- public int[] toArray(int[] a) {
- if (a == null || a.length != size) a = new int[size];
- if (size > 0) System.arraycopy(array, 0, a, 0, size);
- return a;
- }
-
- public List toList() {
- ArrayList l = new ArrayList<>();
- if (size == 0) return l;
- for (int i = 0; i < size; i++) l.add(array[i]);
- return l;
- }
-
- public void sort() {
- if (size < 2) return;
- Arrays.sort(array, 0, size);
- }
-
- public int[] toSortedArray() {
- if (size == 0) return new int[0];
- int[] a = toArray();
- Arrays.sort(a);
- return a;
- }
-
- public int hashCode() {
- int h = 0;
- for (int i = 0; i < size; i++) h = h * 31 + array[i];
- return h;
- }
-
- public boolean equals(Object o) {
- if (o == null) return false;
- else if (o == this) return true;
- else {
- IntList l = (IntList) o;
- if (size != l.size) return false;
- for (int i = 0; i < size; i++) {
- if (array[i] != l.array[i]) return false;
- }
- return true;
- }
- }
-
- public boolean equalsIgnoreOrder(IntList l) {
- if (l == null) return false;
- else if (l == this) return true;
- else {
- if (size != l.size) return false;
-
- IntList l1 = l.copy();
-
- for (int i = 0; i < size; i++) l1.removeValue(array[i]);
-
- return l1.isEmpty();
- }
- }
-
- public String toString() {
- if (size == 0) return "[ ]";
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- sb.append(' ');
-
- for (int i = 0; i < size; i++) {
- sb.append(array[i]);
-
- if (i != size - 1) {
- sb.append(',');
- sb.append(' ');
- }
- }
-
- sb.append(' ');
- sb.append(']');
- return sb.toString();
- }
-
- public Iterator iterator() {
- return new IntIterator(array);
- }
-
- public IntList copy() {
- IntList l = new IntList(size);
- System.arraycopy(array, 0, l.array, 0, size);
- l.size = size;
- l.defVal = defVal;
- return l;
- }
-
- // Value, IsInNewList
- public Map getDifferenceMap(IntList newList) {
- HashMap map = new HashMap<>();
-
- if (isEmpty() && newList.isEmpty()) return map;
-
- for (int i = 0; i < size; i++) {
- if (!newList.contains(array[i])) map.put(array[i], false);
- }
-
- for (int i = 0; i < newList.size; i++) {
- if (!contains(newList.array[i])) map.put(array[i], true);
- }
-
- return map;
- }
-
- public static IntList asList(int... values) {
- IntList l = new IntList(values.length);
- l.addAll(values);
- return l;
- }
-
- public void setJson(JsonElement e) {
- clear();
- addAll(LMJsonUtils.fromIntArray(e));
- }
-
- public JsonElement getJson() {
- return LMJsonUtils.toIntArray(array);
- }
-
- public static class IntIterator implements Iterator {
-
- public final int[] values;
- public int pos = -1;
-
- public IntIterator(int[] v) {
- values = v;
- }
-
- public boolean hasNext() {
- return pos < values.length;
- }
-
- public Integer next() {
- return values[++pos];
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-}
diff --git a/src/main/java/latmod/lib/IntMap.java b/src/main/java/latmod/lib/IntMap.java
deleted file mode 100644
index 1a30819f..00000000
--- a/src/main/java/latmod/lib/IntMap.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package latmod.lib;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by LatvianModder on 06.03.2016.
- */
-public class IntMap {
-
- public final IntList list;
-
- public IntMap(int s) {
- list = new IntList(s * 2);
- }
-
- public IntMap() {
- this(0);
- }
-
- public int size() {
- return list.size() / 2;
- }
-
- public String toString() {
- if (list.isEmpty()) return "{ }";
- StringBuilder sb = new StringBuilder();
- sb.append('{');
- sb.append(' ');
-
- for (int i = 0; i < list.size(); i += 2) {
- sb.append(list.get(i));
- sb.append('=');
- sb.append(list.get(i + 1));
-
- if (i != list.size() - 2) {
- sb.append(',');
- sb.append(' ');
- }
- }
-
- sb.append(' ');
- sb.append('}');
- return sb.toString();
- }
-
- public int[] toArray() {
- return list.toArray();
- }
-
- public void fromArray(int[] ai) {
- list.clear();
- list.addAll(ai);
- }
-
- private int keyIndex(int key) {
- for (int i = 0; i < list.size(); i += 2) {
- if (list.get(i) == key) return i;
- }
-
- return -1;
- }
-
- public void put(int key, int value) {
- int index = keyIndex(key);
- if (index != -1) {
- list.set(index + 1, value);
- } else {
- list.add(key);
- list.add(value);
- }
- }
-
- public int get(int key) {
- return list.get(keyIndex(key) + 1);
- }
-
- public Map toMap() {
- HashMap map = new HashMap<>();
- for (int i = 0; i < list.size(); i += 2) {
- map.put(list.get(i), list.get(i + 1));
- }
- return map;
- }
-
- public static IntMap fromMap(Map map) {
- if (map == null) return null;
- else if (map.isEmpty()) return new IntMap();
- else {
- IntMap m = new IntMap(map.size());
- for (Map.Entry e : map.entrySet()) {
- m.put(e.getKey(), e.getValue());
- }
- return m;
- }
- }
-
- public boolean containsKey(int key) {
- return keyIndex(key) != -1;
- }
-
- public void clear() {
- list.clear();
- }
-
- public IntList getKeys() {
- IntList list1 = new IntList(list.size() / 2);
- if (list.isEmpty()) return list1;
-
- for (int i = 0; i < list.size(); i += 2) {
- list1.add(list.get(i));
- }
-
- return list1;
- }
-
- public IntList getValues() {
- IntList list1 = new IntList(list.size() / 2);
- if (list.isEmpty()) return list1;
-
- for (int i = 0; i < list.size(); i += 2) {
- list1.add(list.get(i + 1));
- }
-
- return list1;
- }
-}
diff --git a/src/main/java/latmod/lib/LMColor.java b/src/main/java/latmod/lib/LMColor.java
deleted file mode 100644
index 9ca41e4d..00000000
--- a/src/main/java/latmod/lib/LMColor.java
+++ /dev/null
@@ -1,262 +0,0 @@
-package latmod.lib;
-
-/**
- * Created by LatvianModder on 08.01.2016.
- */
-public abstract class LMColor {
-
- public static final LMColor WHITE = new ImmutableColor(0xFFFFFFFF);
- public static final LMColor BLACK = new ImmutableColor(0xFF000000);
- public static final LMColor TRANSPARENT = new ImmutableColor(0x00000000);
-
- public static class RGB extends LMColor {
-
- private int red = 255, green = 255, blue = 255;
-
- public RGB() {}
-
- public RGB(int r, int g, int b) {
- setRGBA(r, g, b, 255);
- }
-
- public void set(LMColor col) {
- red = col.red();
- green = col.green();
- blue = col.blue();
- }
-
- public void setRGBA(int r, int g, int b, int a) {
- red = r;
- green = g;
- blue = b;
- }
-
- public void setHSB(float h, float s, float b) {
- setRGBA(0xFF000000 | java.awt.Color.HSBtoRGB(h, s, b));
- }
-
- public void setRGBA(int col) {
- red = LMColorUtils.getRed(col);
- green = LMColorUtils.getGreen(col);
- blue = LMColorUtils.getBlue(col);
- }
-
- public void setRGBAF(float r, float g, float b, float a) {
- setRGBA((int) (r * 255F), (int) (g * 255F), (int) (b * 255F), (int) (a * 255F));
- }
-
- public int color() {
- return LMColorUtils.getRGBA(red(), green(), blue(), alpha());
- }
-
- public int red() {
- return red;
- }
-
- public int green() {
- return green;
- }
-
- public int blue() {
- return blue;
- }
-
- public int alpha() {
- return 255;
- }
-
- public float hue() {
- float[] hsb = new float[3];
- java.awt.Color.RGBtoHSB(red, green, blue, hsb);
- return hsb[0];
- }
-
- public float saturation() {
- float[] hsb = new float[3];
- java.awt.Color.RGBtoHSB(red, green, blue, hsb);
- return hsb[1];
- }
-
- public float brightness() {
- float[] hsb = new float[3];
- java.awt.Color.RGBtoHSB(red, green, blue, hsb);
- return hsb[2];
- }
-
- public RGB copy() {
- RGB col = new RGB();
- col.set(this);
- return col;
- }
- }
-
- public static class RGBA extends RGB {
-
- private int alpha = 255;
-
- public RGBA() {}
-
- public RGBA(int r, int g, int b, int a) {
- setRGBA(r, g, b, a);
- }
-
- public void setRGBA(int col) {
- super.setRGBA(col);
- alpha = LMColorUtils.getAlpha(col);
- }
-
- public void setRGBA(int r, int g, int b, int a) {
- super.setRGBA(r, g, b, a);
- alpha = a;
- }
-
- public int alpha() {
- return alpha;
- }
- }
-
- public static class HSB extends LMColor {
-
- private int color;
- private final float[] hsb;
-
- public HSB(float h, float s, float b) {
- hsb = new float[3];
- setHSB(h, s, b);
- }
-
- public HSB() {
- this(0F, 1F, 1F);
- }
-
- public void set(LMColor col) {
- color = 0xFF000000 | col.color();
- hsb[0] = col.hue();
- hsb[1] = col.saturation();
- hsb[2] = col.brightness();
- }
-
- public void setRGBA(int rgba) {
- setRGBA(LMColorUtils.getRed(rgba), LMColorUtils.getGreen(rgba), LMColorUtils.getBlue(rgba), 255);
- }
-
- public void setRGBA(int r, int g, int b, int a) {
- color = LMColorUtils.getRGBA(r, g, b, 255);
- java.awt.Color.RGBtoHSB(r, g, b, hsb);
- }
-
- public void setHSB(float h, float s, float b) {
- hsb[0] = h % 1F;
- hsb[1] = MathHelperLM.clampFloat(s, 0F, 1F);
- hsb[2] = MathHelperLM.clampFloat(b, 0F, 1F);
- color = 0xFF000000 | java.awt.Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
- }
-
- public void addHue(float hue) {
- setHSB(hsb[0] + hue, hsb[1], hsb[2]);
- }
-
- public int color() {
- return color;
- }
-
- public int red() {
- return LMColorUtils.getRed(color);
- }
-
- public int green() {
- return LMColorUtils.getGreen(color);
- }
-
- public int blue() {
- return LMColorUtils.getBlue(color);
- }
-
- public int alpha() {
- return 255;
- }
-
- public float hue() {
- return hsb[0];
- }
-
- public float saturation() {
- return hsb[1];
- }
-
- public float brightness() {
- return hsb[2];
- }
-
- public HSB copy() {
- HSB col = new HSB();
- col.set(this);
- return col;
- }
- }
-
- public abstract void set(LMColor col);
-
- public abstract void setRGBA(int rgba);
-
- public abstract void setRGBA(int r, int g, int b, int a);
-
- public abstract void setHSB(float h, float s, float b);
-
- public abstract int color();
-
- public abstract int red();
-
- public abstract int green();
-
- public abstract int blue();
-
- public abstract int alpha();
-
- public abstract float hue();
-
- public abstract float saturation();
-
- public abstract float brightness();
-
- public abstract LMColor copy();
-
- public final String toString() {
- return LMColorUtils.getHex(color());
- }
-
- public final int hashCode() {
- return color();
- }
-
- public final boolean equals(Object o) {
- return hashCode() == o.hashCode();
- }
-
- public final LMColor immutable() {
- return new ImmutableColor(this);
- }
-
- public static class ImmutableColor extends RGBA {
-
- public ImmutableColor(LMColor col) {
- super.set(col);
- }
-
- public ImmutableColor(int col) {
- super.setRGBA(col);
- }
-
- public void set(LMColor col) {}
-
- public void setRGBA(int rgba) {}
-
- public void setRGBA(int r, int g, int b, int a) {}
-
- public void setHSB(float h, float s, float b) {}
-
- public ImmutableColor copy() {
- return new ImmutableColor(this);
- }
- }
-}
diff --git a/src/main/java/latmod/lib/LMColorUtils.java b/src/main/java/latmod/lib/LMColorUtils.java
deleted file mode 100644
index 4a20eccc..00000000
--- a/src/main/java/latmod/lib/LMColorUtils.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package latmod.lib;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
-public class LMColorUtils {
-
- public static final int[] chatFormattingColors = new int[16];
-
- public static final int BLACK = 0xFF000000;
- public static final int WHITE = 0xFFFFFFFF;
- public static final int LIGHT_GRAY = 0xFFAAAAAA;
- public static final int DARK_GRAY = 0xFF333333;
- public static final int WIDGETS = 0xFF000000;
-
- static {
- for (int i = 0; i < 16; i++) {
- int j = (i >> 3 & 1) * 85;
- int r = (i >> 2 & 1) * 170 + j;
- int g = (i >> 1 & 1) * 170 + j;
- int b = (i & 1) * 170 + j;
- if (i == 6) r += 85;
- chatFormattingColors[i] = getRGBA(r, g, b, 255);
- }
- }
-
- public static JsonElement serialize(int col) {
- return new JsonPrimitive('#' + Integer.toHexString(col).toUpperCase());
- }
-
- public static int deserialize(JsonElement e) {
- if (e == null || !e.isJsonPrimitive()) return 0xFF000000;
- return (int) Long.parseLong(e.getAsString().substring(1), 16);
- }
-
- public static int getRGBA(int r, int g, int b, int a) {
- return ((a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | ((b & 255));
- }
-
- public static int getRGBAF(float r, float g, float b, float a) {
- return getRGBA((int) (r * 255F), (int) (g * 255F), (int) (b * 255F), (int) (a * 255F));
- }
-
- public static int getRed(int c) {
- return (c >> 16) & 255;
- }
-
- public static int getGreen(int c) {
- return (c >> 8) & 255;
- }
-
- public static int getBlue(int c) {
- return (c) & 255;
- }
-
- public static int getAlpha(int c) {
- return (c >> 24) & 255;
- }
-
- public static float getRedF(int c) {
- return getRed(c) / 255F;
- }
-
- public static float getGreenF(int c) {
- return getGreen(c) / 255F;
- }
-
- public static float getBlueF(int c) {
- return getBlue(c) / 255F;
- }
-
- public static float getAlphaF(int c) {
- return getAlpha(c) / 255F;
- }
-
- public static String getHex(int c) {
- return '#' + Integer.toHexString(getRGBA(c, 255)).substring(2).toUpperCase();
- }
-
- public static int getRGBA(int c, int a) {
- return getRGBA(getRed(c), getGreen(c), getBlue(c), a);
- }
-
- public static int addBrightness(int c, int b) {
- int red = MathHelperLM.clampInt(getRed(c) + b, 0, 255);
- int green = MathHelperLM.clampInt(getGreen(c) + b, 0, 255);
- int blue = MathHelperLM.clampInt(getBlue(c) + b, 0, 255);
- return getRGBA(red, green, blue, getAlpha(c));
- }
-
- public static void addHSB(int pixels[], float h, float s, float b) {
- if (pixels == null || pixels.length == 0) return;
- float[] hsb = new float[3];
-
- for (int i = 0; i < pixels.length; i++) {
- java.awt.Color.RGBtoHSB(getRed(pixels[i]), getGreen(pixels[i]), getBlue(pixels[i]), hsb);
- hsb[0] += h;
- hsb[1] = MathHelperLM.clampFloat(hsb[1] + s, 0F, 1F);
- hsb[2] = MathHelperLM.clampFloat(hsb[2] + b, 0F, 1F);
- pixels[i] = getRGBA(java.awt.Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]), 255);
- }
- }
-
- public static int lerp(int col1, int col2, double m, int alpha) {
- m = MathHelperLM.clamp(m, 0F, 1F);
- int r = MathHelperLM.lerpInt(getRed(col1), getRed(col2), m);
- int g = MathHelperLM.lerpInt(getGreen(col1), getGreen(col2), m);
- int b = MathHelperLM.lerpInt(getBlue(col1), getBlue(col2), m);
- return getRGBA(r, g, b, alpha);
- }
-
- public static int lerp(int col1, int col2, double m) {
- return lerp(col1, col2, m, getAlpha(col1));
- }
-
- public static int multiply(int col1, int col2, int a) {
- float r = MathHelperLM.clampFloat(getRedF(col1) * getRedF(col2), 0F, 1F);
- float g = MathHelperLM.clampFloat(getGreenF(col1) * getGreenF(col2), 0F, 1F);
- float b = MathHelperLM.clampFloat(getBlueF(col1) * getBlueF(col2), 0F, 1F);
- return getRGBA((int) (r * 255F), (int) (g * 255F), (int) (b * 255F), a);
- }
-}
diff --git a/src/main/java/latmod/lib/LMFileUtils.java b/src/main/java/latmod/lib/LMFileUtils.java
deleted file mode 100644
index 8f032cf9..00000000
--- a/src/main/java/latmod/lib/LMFileUtils.java
+++ /dev/null
@@ -1,199 +0,0 @@
-package latmod.lib;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.net.URL;
-import java.nio.channels.Channels;
-import java.nio.channels.FileChannel;
-import java.nio.channels.ReadableByteChannel;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-
-public class LMFileUtils {
-
- public static final File latmodHomeFolder = getFolder();
-
- public static final int KB = 1024;
- public static final int MB = KB * 1024;
- public static final int GB = MB * 1024;
-
- public static final double KB_D = 1024D;
- public static final double MB_D = KB_D * 1024D;
- public static final double GB_D = MB_D * 1024D;
-
- public static final Comparator fileComparator = new Comparator() {
-
- public int compare(File o1, File o2) {
- return o1.getName().compareToIgnoreCase(o2.getName());
- }
- };
-
- public static final Comparator deepFileComparator = new Comparator() {
-
- public int compare(File o1, File o2) {
- return o1.getAbsolutePath().compareToIgnoreCase(o2.getAbsolutePath());
- }
- };
-
- private static File getFolder() {
- // if(!f.exists()) f.mkdirs();
- return new File(System.getProperty("user.home"), "/LatMod/");
- }
-
- public static File newFile(File f) {
- if (f == null || f.exists()) return f;
-
- try {
- File pf = f.getParentFile();
- if (!pf.exists()) pf.mkdirs();
- f.createNewFile();
- return f;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return f;
- }
-
- public static void save(File f, List al) throws Exception {
- save(f, LMStringUtils.fromStringList(al));
- }
-
- public static void save(File f, String s) throws Exception {
- FileWriter fw = new FileWriter(newFile(f));
- BufferedWriter br = new BufferedWriter(fw);
- br.write(s);
- br.close();
- fw.close();
- }
-
- public static List load(File f) throws Exception {
- return LMStringUtils.readStringList(new FileInputStream(f));
- }
-
- public static String loadAsText(File f) throws Exception {
- return LMStringUtils.readString(new FileInputStream(f));
- }
-
- public static boolean downloadFile(String url, File out) {
- try {
- URL website = new URL(url);
- ReadableByteChannel rbc = Channels.newChannel(website.openStream());
- FileOutputStream fos = new FileOutputStream(out);
- fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
- fos.close();
- return true;
- } catch (Exception e) {}
- return false;
- }
-
- public static List listAll(File f) {
- ArrayList l = new ArrayList<>();
- addAllFiles(l, f);
- return l;
- }
-
- private static void addAllFiles(ArrayList l, File f) {
- if (f.isDirectory()) {
- File[] fl = f.listFiles();
-
- if (fl != null && fl.length > 0) {
- for (File aFl : fl) addAllFiles(l, aFl);
- }
- } else if (f.isFile()) l.add(f);
- }
-
- public static long getSize(File f) {
- if (f == null || !f.exists()) return 0L;
- else if (f.isFile()) return f.length();
- else if (f.isDirectory()) {
- long length = 0L;
- File[] f1 = f.listFiles();
- if (f1 != null && f1.length > 0) for (File aF1 : f1) length += getSize(aF1);
- return length;
- }
- return 0L;
- }
-
- public static String getSizeS(double b) {
- if (b >= GB_D) {
- b /= GB_D;
- b = (long) (b * 10D) / 10D;
- return b + "GB";
- } else if (b >= MB_D) {
- b /= MB_D;
- b = (long) (b * 10D) / 10D;
- return b + "MB";
- } else if (b >= KB_D) {
- b /= KB_D;
- b = (long) (b * 10D) / 10D;
- return b + "KB";
- }
-
- return b + "B";
- }
-
- public static String getSizeS(File f) {
- return getSizeS(getSize(f));
- }
-
- @SuppressWarnings("resource")
- public static Exception copyFile(File src, File dst) {
- if (src != null && dst != null && src.exists() && !src.equals(dst)) {
- if (src.isDirectory() && dst.isDirectory()) {
- for (File f : listAll(src)) {
- File dst1 = new File(
- dst.getAbsolutePath() + File.separatorChar
- + (f.getAbsolutePath().replace(src.getAbsolutePath(), "")));
- Exception e = copyFile(f, dst1);
- if (e != null) return e;
- }
-
- return null;
- }
-
- dst = newFile(dst);
-
- FileChannel srcC, dstC;
-
- try {
- srcC = new FileInputStream(src).getChannel();
- dstC = new FileOutputStream(dst).getChannel();
- dstC.transferFrom(srcC, 0L, srcC.size());
- srcC.close();
- dstC.close();
- return null;
- } catch (Exception e) {
- return e;
- }
- }
-
- return null;
- }
-
- public static boolean delete(File f) {
- if (f == null || !f.exists()) return false;
- if (f.isFile()) return f.delete();
- String[] files = f.list();
- for (String file : files) delete(new File(f, file));
- return f.delete();
- }
-
- public static File getSourceDirectory(Class> c) {
- return new File(c.getProtectionDomain().getCodeSource().getLocation().getFile());
- }
-
- public static String getRawFileName(File f) {
- if (f == null || !f.exists()) return null;
- else if (f.isDirectory()) return f.getName();
- else if (f.isFile()) {
- String s = f.getName();
- return s.substring(0, s.lastIndexOf('.'));
- }
- return null;
- }
-}
diff --git a/src/main/java/latmod/lib/LMJsonUtils.java b/src/main/java/latmod/lib/LMJsonUtils.java
deleted file mode 100644
index e8a6075e..00000000
--- a/src/main/java/latmod/lib/LMJsonUtils.java
+++ /dev/null
@@ -1,247 +0,0 @@
-package latmod.lib;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.Reader;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonNull;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-
-/**
- * Type for Lists: new TypeToken>() {}.getType()
- */
-public class LMJsonUtils {
-
- private static Gson gson = null;
- private static Gson gson_pretty = null;
- public static JsonDeserializationContext deserializationContext;
- public static JsonSerializationContext serializationContext, prettySerializationContext;
-
- public static Gson getGson(boolean pretty) {
- if (gson == null || gson_pretty == null) {
- GsonBuilder gb = new GsonBuilder();
- gson = gb.create();
- gb.setPrettyPrinting();
- gson_pretty = gb.create();
-
- deserializationContext = new JsonDeserializationContext() {
-
- @SuppressWarnings("unchecked")
- public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
- return (T) gson.fromJson(json, typeOfT);
- }
- };
-
- serializationContext = new JsonSerializationContext() {
-
- public JsonElement serialize(Object src) {
- return gson.toJsonTree(src);
- }
-
- public JsonElement serialize(Object src, Type typeOfSrc) {
- return gson.toJsonTree(src, typeOfSrc);
- }
- };
-
- prettySerializationContext = new JsonSerializationContext() {
-
- public JsonElement serialize(Object src) {
- return gson_pretty.toJsonTree(src);
- }
-
- public JsonElement serialize(Object src, Type typeOfSrc) {
- return gson_pretty.toJsonTree(src, typeOfSrc);
- }
- };
- }
-
- return pretty ? gson_pretty : gson;
- }
-
- public static String toJson(Gson gson, JsonElement e) {
- if (e == null) return null;
- return gson.toJson(e);
- }
-
- public static boolean toJson(Gson gson, File f, JsonElement o) {
- if (o == null) return false;
-
- try {
- String s = toJson(gson, o);
- LMFileUtils.save(f, s);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return false;
- }
-
- public static String toJson(JsonElement o) {
- return toJson(getGson(false), o);
- }
-
- public static boolean toJson(File f, JsonElement o) {
- return toJson(getGson(true), f, o);
- }
-
- public static JsonElement fromJson(String json) {
- return (json == null || json.isEmpty()) ? JsonNull.INSTANCE : new JsonParser().parse(json);
- }
-
- public static JsonElement fromJson(Reader json) {
- return (json == null) ? JsonNull.INSTANCE : new JsonParser().parse(json);
- }
-
- public static JsonElement fromJson(File json) {
- try {
- if (json == null || !json.exists()) return JsonNull.INSTANCE;
- BufferedReader reader = new BufferedReader(new FileReader(json));
- JsonElement e = fromJson(reader);
- reader.close();
- return e;
- } catch (Exception ex) {}
- return JsonNull.INSTANCE;
- }
-
- public static JsonArray join(JsonArray... a) {
- JsonArray a1 = new JsonArray();
-
- for (JsonArray anA : a) {
- if (anA != null) {
- for (int j = 0; j < anA.size(); j++) a1.add(anA.get(j));
- }
- }
-
- return a1;
- }
-
- // -- //
-
- public static JsonArray toIntArray(int[] ai) {
- if (ai == null) return null;
- JsonArray a = new JsonArray();
- if (ai.length == 0) return a;
- for (int anAi : ai) a.add(new JsonPrimitive(anAi));
- return a;
- }
-
- public static int[] fromIntArray(JsonElement e) {
- if (e == null || e.isJsonNull()) return null;
-
- if (e.isJsonArray()) {
- JsonArray a = e.getAsJsonArray();
- int[] ai = new int[a.size()];
- if (ai.length == 0) return ai;
- for (int i = 0; i < ai.length; i++) ai[i] = a.get(i).getAsInt();
- return ai;
- }
-
- return new int[] { e.getAsInt() };
- }
-
- public static JsonArray toNumberArray(Number[] ai) {
- if (ai == null) return null;
- JsonArray a = new JsonArray();
- if (ai.length == 0) return a;
- for (Number anAi : ai) a.add(new JsonPrimitive(anAi));
- return a;
- }
-
- public static Number[] fromNumberArray(JsonElement e) {
- if (e == null || e.isJsonNull()) return null;
-
- if (e.isJsonArray()) {
- JsonArray a = e.getAsJsonArray();
- Number[] ai = new Number[a.size()];
- if (ai.length == 0) return ai;
- for (int i = 0; i < ai.length; i++) ai[i] = a.get(i).getAsNumber();
- return ai;
- }
-
- return new Number[] { e.getAsNumber() };
- }
-
- public static JsonArray toStringArray(String[] ai) {
- if (ai == null) return null;
- JsonArray a = new JsonArray();
- if (ai.length == 0) return a;
- for (String anAi : ai) a.add(new JsonPrimitive(anAi));
- return a;
- }
-
- public static String[] fromStringArray(JsonElement e) {
- if (e == null || e.isJsonNull() || !e.isJsonArray()) return null;
- JsonArray a = e.getAsJsonArray();
- String[] ai = new String[a.size()];
- if (ai.length == 0) return ai;
- for (int i = 0; i < ai.length; i++) ai[i] = a.get(i).getAsString();
- return ai;
- }
-
- public static JsonObject join(JsonObject... o) {
- JsonObject o1 = new JsonObject();
-
- for (JsonObject anO : o) {
- if (anO != null) {
- for (Map.Entry e : anO.entrySet()) o1.add(e.getKey(), e.getValue());
- }
- }
-
- return o1;
- }
-
- public static void printPretty(JsonElement e) {
- System.out.println(toJson(getGson(true), e));
- }
-
- public static List deserializeText(List text) {
- List elements = new ArrayList<>();
-
- StringBuilder sb = new StringBuilder();
- int inc = 0;
-
- for (String s : text) {
- s = LMStringUtils.trimAllWhitespace(s);
-
- System.out.println(s);
-
- if (s.isEmpty()) {
- elements.add(JsonNull.INSTANCE);
- } else {
- if (inc > 0 || s.startsWith("{")) {
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c == '{') inc++;
- else if (c == '}') inc--;
- sb.append(c);
-
- if (inc == 0) {
- System.out.println(":: " + sb.toString());
- elements.add(fromJson(sb.toString()));
- sb.setLength(0);
- }
- }
- } else {
- elements.add(new JsonPrimitive(s));
- }
- }
- }
-
- return elements;
- }
-}
diff --git a/src/main/java/latmod/lib/LMListUtils.java b/src/main/java/latmod/lib/LMListUtils.java
deleted file mode 100644
index 7e449cb7..00000000
--- a/src/main/java/latmod/lib/LMListUtils.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package latmod.lib;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * Created by LatvianModder on 06.01.2016.
- */
-public class LMListUtils {
-
- public static String toString(Collection> c) {
- String[] s = toStringArray(c);
- if (s == null) return null;
- if (s.length == 0) return "[ ]";
- StringBuilder sb = new StringBuilder();
- sb.append('[');
- sb.append(' ');
-
- for (int i = 0; i < s.length; i++) {
- sb.append(s[i]);
-
- if (i != s.length - 1) {
- sb.append(',');
- sb.append(' ');
- }
- }
-
- sb.append(' ');
- sb.append(']');
- return sb.toString();
- }
-
- public static String[] toStringArray(Collection> c) {
- if (c == null) return null;
- String[] s = new String[c.size()];
- if (s.length == 0) return s;
- int i = -1;
- for (Object o : c) s[++i] = String.valueOf(o);
- return s;
- }
-
- public static List toStringList(Collection> c) {
- if (c == null) return null;
- List list = new ArrayList<>(c.size());
- if (c.isEmpty()) return list;
- for (Object o : c) list.add(String.valueOf(o));
- return list;
- }
-
- public static int[] toHashCodeArray(Collection> c) {
- if (c == null) return null;
- int[] s = new int[c.size()];
- int i = -1;
- for (Object o : c) s[++i] = LMUtils.hashCodeOf(o);
- return s;
- }
-
- public List flip(List list) {
- if (list == null || list.isEmpty()) return list;
- int s = list.size();
- ArrayList al1 = new ArrayList<>(s);
- for (int i = 0; i < s; i++) al1.add(list.get(s - i - 1));
- return al1;
- }
-
- public static void removeNullValues(List> list) {
- if (list == null) return;
- for (int i = list.size() - 1; i >= 0; i--) if (list.get(i) == null) list.remove(i);
- }
-
- public static void removeAll(List> list, IntList l) {
- if (list == null) return;
- for (int i = 0; i < l.size(); i++) list.remove(l.get(i));
- }
-
- public static void removeAll(List list, RemoveFilter f) {
- if (list == null) return;
- if (f == null) list.clear();
- else {
- for (int i = list.size() - 1; i >= 0; i--) {
- if (f.remove(list.get(i))) list.remove(i);
- }
- }
- }
-
- public static List sortToNew(Collection c, Comparator super E> comparator) {
- if (c == null) return null;
- else if (c.isEmpty()) return new ArrayList<>();
- ArrayList list = new ArrayList<>(c.size());
- list.addAll(c);
- Collections.sort(list, comparator);
- return list;
- }
-
- public static boolean trim(List> list, int t) {
- if (list != null && list.size() > t) {
- while (list.size() > t) {
- list.remove(t);
- t--;
- }
- return true;
- }
-
- return false;
- }
-
- public static List clone(Collection c) {
- if (c == null) return null;
- if (c.isEmpty()) return new ArrayList<>();
- ArrayList list1 = new ArrayList<>(c.size());
- list1.addAll(c);
- return list1;
- }
-
- // TODO: Remove me
- public static void addAll(Collection c, E[] e) {
- if (c != null && e != null && e.length > 0) {
- Collections.addAll(c, e);
- }
- }
-
- public static boolean containsAny(Collection> c, Collection> c1) {
- for (Object o : c1) {
- if (c.contains(o)) return true;
- }
-
- return false;
- }
-}
diff --git a/src/main/java/latmod/lib/LMMapUtils.java b/src/main/java/latmod/lib/LMMapUtils.java
deleted file mode 100644
index 1ab7c40e..00000000
--- a/src/main/java/latmod/lib/LMMapUtils.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package latmod.lib;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by LatvianModder on 06.01.2016.
- */
-public class LMMapUtils {
-
- public static String toString(Map, ?> map) {
- if (map == null) return null;
- StringBuilder sb = new StringBuilder();
- sb.append('{');
- sb.append(' ');
-
- int s = map.size();
-
- if (s > 0) {
- int i = 0;
- for (Map.Entry, ?> e : map.entrySet()) {
- sb.append(e.getKey());
- sb.append(':');
- sb.append(' ');
- sb.append(e.getValue());
-
- if (i != s - 1) {
- sb.append(',');
- sb.append(' ');
- }
- i++;
- }
-
- sb.append(' ');
- }
-
- sb.append('}');
- return sb.toString();
- }
-
- public static Map toStringMap(Map, ?> map) {
- if (map == null) return null;
- HashMap map1 = new HashMap<>();
- for (Map.Entry, ?> e : map.entrySet()) map1.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
- return map1;
- }
-
- public static Map inverse(Map map) {
- if (map == null) return null;
- HashMap map1 = new HashMap<>();
- for (Map.Entry e : map.entrySet()) map1.put(e.getValue(), e.getKey());
- return map1;
- }
-
- public static List> sortedEntryList(Map map, Comparator> c) {
- if (map == null) return null;
- ArrayList> list = new ArrayList<>();
-
- if (c == null) c = new Comparator>() {
-
- public int compare(Map.Entry o1, Map.Entry o2) {
- return ((Comparable) o1.getKey()).compareTo(o2.getKey());
- }
- };
-
- list.addAll(map.entrySet());
- Collections.sort(list, c);
- return list;
- }
-
- public static List values(Map map, Comparator> c) {
- if (map == null) return null;
- ArrayList list = new ArrayList<>();
- for (Map.Entry, V> entry : sortedEntryList(map, c)) list.add(entry.getValue());
- return list;
- }
-
- public static Comparator> byKeyNames(final boolean ignoreCase) {
- return new Comparator>() {
-
- public int compare(Map.Entry o1, Map.Entry o2) {
- if (ignoreCase) return String.valueOf(o1.getKey()).compareToIgnoreCase(String.valueOf(o2.getKey()));
- else return String.valueOf(o1.getKey()).compareTo(String.valueOf(o2.getKey()));
- }
- };
- }
-
- public static Comparator> byKeyNumbers() {
- return new Comparator>() {
-
- public int compare(Map.Entry o1, Map.Entry o2) {
- Number n1 = ((Number) o1.getKey());
- Number n2 = ((Number) o1.getKey());
- return Long.compare((n1 == null) ? 0L : n1.longValue(), (n2 == null) ? 0L : n2.longValue());
- }
- };
- }
-
- public static void removeAll(Map map, RemoveFilter> f) {
- if (map == null) return;
- if (f == null) map.clear();
- else {
- List> set = new ArrayList<>(map.entrySet());
- map.clear();
-
- for (Map.Entry e : set) {
- if (!f.remove(e)) map.put(e.getKey(), e.getValue());
- }
- }
- }
-
- public static void sortMap(LinkedHashMap map, Comparator> comparator) {
- if (map == null || map.isEmpty()) return;
- List> list = new ArrayList<>();
- list.addAll(map.entrySet());
- Collections.sort(list, comparator);
- map.clear();
-
- for (Map.Entry e : list) {
- map.put(e.getKey(), e.getValue());
- }
- }
-}
diff --git a/src/main/java/latmod/lib/LMStringUtils.java b/src/main/java/latmod/lib/LMStringUtils.java
deleted file mode 100644
index cd6e553a..00000000
--- a/src/main/java/latmod/lib/LMStringUtils.java
+++ /dev/null
@@ -1,383 +0,0 @@
-package latmod.lib;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-
-public class LMStringUtils {
-
- public static final int DAY24 = 24 * 60 * 60;
- public static final Charset UTF_8 = Charset.forName("UTF-8");
-
- public static final String STRIP_SEP = ", ";
- public static final String ALLOWED_TEXT_CHARS = " -_!@#$%^&*()+=\\/,.<>?\'\"[]{}|;:`~";
-
- public static final Comparator