This commit is contained in:
2024-07-07 23:17:33 +02:00
parent 8ef9a95b67
commit a17b32f95f
14 changed files with 102 additions and 89 deletions

View File

@@ -13,4 +13,12 @@
<maven.compiler.target>21</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<distributionManagement>
<repository>
<id>github</id>
<name>UnlegitLibrary</name>
<url>https://maven.pkg.github.com/unlegitdqrk/unlegitlibrary</url>
</repository>
</distributionManagement>
</project> </project>

View File

@@ -10,7 +10,6 @@ package me.finn.unlegitlibrary.addon.events;
import me.finn.unlegitlibrary.addon.impl.Addon; import me.finn.unlegitlibrary.addon.impl.Addon;
import me.finn.unlegitlibrary.event.impl.Event; import me.finn.unlegitlibrary.event.impl.Event;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
public class AddonDisabledEvent extends Event { public class AddonDisabledEvent extends Event {

View File

@@ -13,7 +13,6 @@ import me.finn.unlegitlibrary.addon.events.AddonEnabledEvent;
import me.finn.unlegitlibrary.event.EventListener; import me.finn.unlegitlibrary.event.EventListener;
import me.finn.unlegitlibrary.event.EventManager; import me.finn.unlegitlibrary.event.EventManager;
import me.finn.unlegitlibrary.event.impl.Event; import me.finn.unlegitlibrary.event.impl.Event;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

View File

@@ -8,8 +8,6 @@
package me.finn.unlegitlibrary.addon.impl; package me.finn.unlegitlibrary.addon.impl;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
public class AddonInfo { public class AddonInfo {
private final String name; private final String name;
@@ -41,9 +39,8 @@ public class AddonInfo {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof AddonInfo)) return false; if (!(obj instanceof AddonInfo other)) return false;
AddonInfo other = (AddonInfo) obj;
return other.name.equalsIgnoreCase(name) && other.version.equalsIgnoreCase(version) && other.author.equalsIgnoreCase(author); return other.name.equalsIgnoreCase(name) && other.version.equalsIgnoreCase(version) && other.author.equalsIgnoreCase(author);
} }

View File

@@ -8,7 +8,5 @@
package me.finn.unlegitlibrary.event; package me.finn.unlegitlibrary.event;
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
public abstract class EventListener { public abstract class EventListener {
} }

View File

@@ -51,27 +51,27 @@ public class FileUtils extends DefaultMethodsOverrider {
public static void unzip(File source, String outputDirectory) throws IOException { public static void unzip(File source, String outputDirectory) throws IOException {
ZipInputStream zis = new ZipInputStream(new FileInputStream(source)); ZipInputStream zis = new ZipInputStream(new FileInputStream(source));
ZipEntry entry = zis.getNextEntry(); ZipEntry entry = zis.getNextEntry();
while (entry != null) { while (entry != null) {
File file = new File(outputDirectory, entry.getName()); File file = new File(outputDirectory, entry.getName());
if (entry.isDirectory()) file.mkdirs(); if (entry.isDirectory()) file.mkdirs();
else { else {
File parent = file.getParentFile(); File parent = file.getParentFile();
if (!parent.exists()) parent.mkdirs(); if (!parent.exists()) parent.mkdirs();
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) { try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
int bufferSize = Math.toIntExact(entry.getSize()); int bufferSize = Math.toIntExact(entry.getSize());
byte[] buffer = new byte[bufferSize > 0 ? bufferSize : 1]; byte[] buffer = new byte[bufferSize > 0 ? bufferSize : 1];
int location; int location;
while ((location = zis.read(buffer)) != -1) bos.write(buffer, 0, location); while ((location = zis.read(buffer)) != -1) bos.write(buffer, 0, location);
}
} }
entry = zis.getNextEntry();
} }
entry = zis.getNextEntry();
}
} }
@@ -122,7 +122,8 @@ public class FileUtils extends DefaultMethodsOverrider {
File destinationFile = new File(toFolder, fileName); File destinationFile = new File(toFolder, fileName);
if (replaceExisting) Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING); if (replaceExisting)
Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
else Files.copy(sourceFile.toPath(), destinationFile.toPath()); else Files.copy(sourceFile.toPath(), destinationFile.toPath());
} }

View File

@@ -18,7 +18,8 @@ import java.util.Arrays;
public class ReflectUtils extends DefaultMethodsOverrider { public class ReflectUtils extends DefaultMethodsOverrider {
public static Method getMethodByArgs(final Class<?> clazz, final Class<?>... args) { public static Method getMethodByArgs(final Class<?> clazz, final Class<?>... args) {
for (Method method : clazz.getDeclaredMethods()) if (Arrays.equals(method.getParameterTypes(), args)) return method; for (Method method : clazz.getDeclaredMethods())
if (Arrays.equals(method.getParameterTypes(), args)) return method;
return null; return null;
} }

View File

@@ -43,9 +43,9 @@ public class NetworkClient extends DefaultMethodsOverrider {
private ObjectOutputStream objectOutputStream; private ObjectOutputStream objectOutputStream;
private ObjectInputStream objectInputStream; private ObjectInputStream objectInputStream;
private int clientID = -1; private int clientID = -1;
private int attempt = 1; private final Thread receiveThread = new Thread(this::receive); private int attempt = 1;
private boolean needClientID = false; private final Thread receiveThread = new Thread(this::receive);
private boolean needClientID = false;
private NetworkClient(String host, int port, PacketHandler packetHandler, EventManager eventManager, boolean autoReconnect, boolean debugLog, int maxAttempts, int attemptDelayInSec) { private NetworkClient(String host, int port, PacketHandler packetHandler, EventManager eventManager, boolean autoReconnect, boolean debugLog, int maxAttempts, int attemptDelayInSec) {
this.host = host; this.host = host;
this.port = port; this.port = port;

View File

@@ -30,10 +30,7 @@ public class ClientHandler {
private Socket socket; private Socket socket;
private ObjectOutputStream objectOutputStream; private ObjectOutputStream objectOutputStream;
private ObjectInputStream objectInputStream; private ObjectInputStream objectInputStream;
private int clientID; private final Thread receiveThread = new Thread(this::receive);
private final Thread receiveThread = new Thread(this::receive);
private int clientID;
public ClientHandler(NetworkServer networkServer, Socket socket, int clientID) throws IOException { public ClientHandler(NetworkServer networkServer, Socket socket, int clientID) throws IOException {
this.networkServer = networkServer; this.networkServer = networkServer;
@@ -140,7 +137,7 @@ public class ClientHandler {
objectOutputStream.flush(); objectOutputStream.flush();
networkServer.getEventManager().executeEvent(new S_ClientConnectedEvent(this)); networkServer.getEventManager().executeEvent(new S_ClientConnectedEvent(this));
continue; continue;
} else if (command.equalsIgnoreCase("c2s_disconnect")) { } else if (command.equalsIgnoreCase("c2s_disconnect")) {
if (clientID != id) continue; if (clientID != id) continue;
networkServer.getEventManager().executeEvent(new S_ClientDisconnectedEvent(this)); networkServer.getEventManager().executeEvent(new S_ClientDisconnectedEvent(this));
@@ -154,7 +151,8 @@ public class ClientHandler {
if (networkServer.getPacketHandler().handlePacket(id, packet, objectInputStream)) if (networkServer.getPacketHandler().handlePacket(id, packet, objectInputStream))
networkServer.getEventManager().executeEvent(new S_PacketReceivedEvent(this, packet)); networkServer.getEventManager().executeEvent(new S_PacketReceivedEvent(this, packet));
else networkServer.getEventManager().executeEvent(new S_PacketFailedReceivedEvent(this, packet)); else
networkServer.getEventManager().executeEvent(new S_PacketFailedReceivedEvent(this, packet));
continue; continue;
} }
@@ -177,4 +175,6 @@ public class ClientHandler {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }

View File

@@ -34,8 +34,6 @@ public class NetworkServer {
private ServerSocket serverSocket; private ServerSocket serverSocket;
private int attempt = 1; private int attempt = 1;
private final Thread incomingConnectionThread = new Thread(this::incomingConnection);
private NetworkServer(int port, PacketHandler packetHandler, EventManager eventManager, boolean autoRestart, boolean debugLog, int maxAttempts, int attemptDelayInSec) { private NetworkServer(int port, PacketHandler packetHandler, EventManager eventManager, boolean autoRestart, boolean debugLog, int maxAttempts, int attemptDelayInSec) {
this.port = port; this.port = port;
@@ -47,7 +45,7 @@ public class NetworkServer {
this.maxAttempts = maxAttempts; this.maxAttempts = maxAttempts;
this.attemptDelayInSec = attemptDelayInSec; this.attemptDelayInSec = attemptDelayInSec;
} } private final Thread incomingConnectionThread = new Thread(this::incomingConnection);
public final int getPort() { public final int getPort() {
return port; return port;
@@ -210,4 +208,6 @@ public class NetworkServer {
} }
} }

View File

@@ -9,7 +9,6 @@
package me.finn.unlegitlibrary.network.system.server.events.client.packets.received; package me.finn.unlegitlibrary.network.system.server.events.client.packets.received;
import me.finn.unlegitlibrary.event.impl.Event; import me.finn.unlegitlibrary.event.impl.Event;
import me.finn.unlegitlibrary.network.system.packets.Packet;
import me.finn.unlegitlibrary.network.system.server.ClientHandler; import me.finn.unlegitlibrary.network.system.server.ClientHandler;
public class S_UnknownObjectReceivedEvent extends Event { public class S_UnknownObjectReceivedEvent extends Event {

View File

@@ -15,7 +15,6 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
public class WebUtils extends DefaultMethodsOverrider { public class WebUtils extends DefaultMethodsOverrider {

View File

@@ -207,34 +207,6 @@ public class MathHelper extends DefaultMethodsOverrider {
return value; return value;
} }
public final float clamp(float value, float minimum, float maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final int clamp(int value, int minimum, int maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final double clamp(double value, double minimum, double maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final long clamp(long value, long minimum, long maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
/** /**
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check * the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
*/ */
@@ -277,4 +249,32 @@ public class MathHelper extends DefaultMethodsOverrider {
return angle; return angle;
} }
public final float clamp(float value, float minimum, float maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final int clamp(int value, int minimum, int maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final double clamp(double value, double minimum, double maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
public final long clamp(long value, long minimum, long maximum) {
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
} }

View File

@@ -19,29 +19,6 @@ public class Matrix4x4 extends DefaultMethodsOverrider {
setIdentity(); setIdentity();
} }
public final float[][] getMatrix() {
return matrix;
}
public final void setMatrix(float[][] matrix) {
this.matrix = matrix;
}
public final void setIdentity() {
matrix[0][0] = 1; matrix[0][1] = 0; matrix[0][2] = 0; matrix[0][3] = 0;
matrix[1][0] = 0; matrix[1][1] = 1; matrix[1][2] = 0; matrix[1][3] = 0;
matrix[2][0] = 0; matrix[2][1] = 0; matrix[2][2] = 1; matrix[2][3] = 0;
matrix[3][0] = 0; matrix[3][1] = 0; matrix[3][2] = 0; matrix[3][3] = 1;
}
public final void getBuffer(FloatBuffer buffer) {
buffer.put(matrix[0][0]).put(matrix[0][1]).put(matrix[0][2]).put(matrix[0][3]);
buffer.put(matrix[1][0]).put(matrix[1][1]).put(matrix[1][2]).put(matrix[1][3]);
buffer.put(matrix[2][0]).put(matrix[2][1]).put(matrix[2][2]).put(matrix[2][3]);
buffer.put(matrix[3][0]).put(matrix[3][1]).put(matrix[3][2]).put(matrix[3][3]);
buffer.flip();
}
public static Matrix4x4 orthographic(float left, float right, float bottom, float top, float near, float far) { public static Matrix4x4 orthographic(float left, float right, float bottom, float top, float near, float far) {
Matrix4x4 matrix4x4 = new Matrix4x4(); Matrix4x4 matrix4x4 = new Matrix4x4();
@@ -59,4 +36,39 @@ public class Matrix4x4 extends DefaultMethodsOverrider {
return matrix4x4; return matrix4x4;
} }
public final float[][] getMatrix() {
return matrix;
}
public final void setMatrix(float[][] matrix) {
this.matrix = matrix;
}
public final void setIdentity() {
matrix[0][0] = 1;
matrix[0][1] = 0;
matrix[0][2] = 0;
matrix[0][3] = 0;
matrix[1][0] = 0;
matrix[1][1] = 1;
matrix[1][2] = 0;
matrix[1][3] = 0;
matrix[2][0] = 0;
matrix[2][1] = 0;
matrix[2][2] = 1;
matrix[2][3] = 0;
matrix[3][0] = 0;
matrix[3][1] = 0;
matrix[3][2] = 0;
matrix[3][3] = 1;
}
public final void getBuffer(FloatBuffer buffer) {
buffer.put(matrix[0][0]).put(matrix[0][1]).put(matrix[0][2]).put(matrix[0][3]);
buffer.put(matrix[1][0]).put(matrix[1][1]).put(matrix[1][2]).put(matrix[1][3]);
buffer.put(matrix[2][0]).put(matrix[2][1]).put(matrix[2][2]).put(matrix[2][3]);
buffer.put(matrix[3][0]).put(matrix[3][1]).put(matrix[3][2]).put(matrix[3][3]);
buffer.flip();
}
} }