Cleanup
This commit is contained in:
@@ -10,7 +10,6 @@ package me.finn.unlegitlibrary.addon.events;
|
||||
|
||||
import me.finn.unlegitlibrary.addon.impl.Addon;
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
public class AddonDisabledEvent extends Event {
|
||||
|
||||
|
@@ -13,7 +13,6 @@ import me.finn.unlegitlibrary.addon.events.AddonEnabledEvent;
|
||||
import me.finn.unlegitlibrary.event.EventListener;
|
||||
import me.finn.unlegitlibrary.event.EventManager;
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
@@ -8,8 +8,6 @@
|
||||
|
||||
package me.finn.unlegitlibrary.addon.impl;
|
||||
|
||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
public class AddonInfo {
|
||||
|
||||
private final String name;
|
||||
@@ -41,9 +39,8 @@ public class AddonInfo {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,5 @@
|
||||
|
||||
package me.finn.unlegitlibrary.event;
|
||||
|
||||
import me.finn.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
public abstract class EventListener {
|
||||
}
|
||||
|
@@ -51,27 +51,27 @@ public class FileUtils extends DefaultMethodsOverrider {
|
||||
|
||||
public static void unzip(File source, String outputDirectory) throws IOException {
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(source));
|
||||
ZipEntry entry = zis.getNextEntry();
|
||||
ZipEntry entry = zis.getNextEntry();
|
||||
|
||||
while (entry != null) {
|
||||
File file = new File(outputDirectory, entry.getName());
|
||||
while (entry != null) {
|
||||
File file = new File(outputDirectory, entry.getName());
|
||||
|
||||
if (entry.isDirectory()) file.mkdirs();
|
||||
else {
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.exists()) parent.mkdirs();
|
||||
if (entry.isDirectory()) file.mkdirs();
|
||||
else {
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.exists()) parent.mkdirs();
|
||||
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
int bufferSize = Math.toIntExact(entry.getSize());
|
||||
byte[] buffer = new byte[bufferSize > 0 ? bufferSize : 1];
|
||||
int location;
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
int bufferSize = Math.toIntExact(entry.getSize());
|
||||
byte[] buffer = new byte[bufferSize > 0 ? bufferSize : 1];
|
||||
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);
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,8 @@ import java.util.Arrays;
|
||||
public class ReflectUtils extends DefaultMethodsOverrider {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -43,9 +43,9 @@ public class NetworkClient extends DefaultMethodsOverrider {
|
||||
private ObjectOutputStream objectOutputStream;
|
||||
private ObjectInputStream objectInputStream;
|
||||
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) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@@ -30,10 +30,7 @@ public class ClientHandler {
|
||||
private Socket socket;
|
||||
private ObjectOutputStream objectOutputStream;
|
||||
private ObjectInputStream objectInputStream;
|
||||
|
||||
private final Thread receiveThread = new Thread(this::receive);
|
||||
|
||||
private int clientID;
|
||||
private int clientID; private final Thread receiveThread = new Thread(this::receive);
|
||||
|
||||
public ClientHandler(NetworkServer networkServer, Socket socket, int clientID) throws IOException {
|
||||
this.networkServer = networkServer;
|
||||
@@ -140,7 +137,7 @@ public class ClientHandler {
|
||||
objectOutputStream.flush();
|
||||
|
||||
networkServer.getEventManager().executeEvent(new S_ClientConnectedEvent(this));
|
||||
continue;
|
||||
continue;
|
||||
} else if (command.equalsIgnoreCase("c2s_disconnect")) {
|
||||
if (clientID != id) continue;
|
||||
networkServer.getEventManager().executeEvent(new S_ClientDisconnectedEvent(this));
|
||||
@@ -154,7 +151,8 @@ public class ClientHandler {
|
||||
|
||||
if (networkServer.getPacketHandler().handlePacket(id, packet, objectInputStream))
|
||||
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;
|
||||
}
|
||||
@@ -177,4 +175,6 @@ public class ClientHandler {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -34,8 +34,6 @@ public class NetworkServer {
|
||||
|
||||
private ServerSocket serverSocket;
|
||||
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) {
|
||||
this.port = port;
|
||||
|
||||
@@ -47,7 +45,7 @@ public class NetworkServer {
|
||||
|
||||
this.maxAttempts = maxAttempts;
|
||||
this.attemptDelayInSec = attemptDelayInSec;
|
||||
}
|
||||
} private final Thread incomingConnectionThread = new Thread(this::incomingConnection);
|
||||
|
||||
public final int getPort() {
|
||||
return port;
|
||||
@@ -210,4 +208,6 @@ public class NetworkServer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@
|
||||
package me.finn.unlegitlibrary.network.system.server.events.client.packets.received;
|
||||
|
||||
import me.finn.unlegitlibrary.event.impl.Event;
|
||||
import me.finn.unlegitlibrary.network.system.packets.Packet;
|
||||
import me.finn.unlegitlibrary.network.system.server.ClientHandler;
|
||||
|
||||
public class S_UnknownObjectReceivedEvent extends Event {
|
||||
|
@@ -15,7 +15,6 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class WebUtils extends DefaultMethodsOverrider {
|
||||
|
@@ -207,34 +207,6 @@ public class MathHelper extends DefaultMethodsOverrider {
|
||||
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
|
||||
*/
|
||||
@@ -277,4 +249,32 @@ public class MathHelper extends DefaultMethodsOverrider {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,29 +19,6 @@ public class Matrix4x4 extends DefaultMethodsOverrider {
|
||||
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) {
|
||||
Matrix4x4 matrix4x4 = new Matrix4x4();
|
||||
|
||||
@@ -59,4 +36,39 @@ public class Matrix4x4 extends DefaultMethodsOverrider {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user