diff --git a/pom.xml b/pom.xml
index a7cdf302..acac7d5b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,12 +65,6 @@
jitpack.iohttps://jitpack.io
-
-
- dv8tion
- m2-dv8tion
- https://m2.dv8tion.net/releases
-
@@ -146,5 +140,11 @@
xsalsa20poly1305v0.10.1
+
+ org.projectlombok
+ lombok
+ 1.18.32
+ provided
+
diff --git a/src/main/java/com/seailz/discordjar/DiscordJar.java b/src/main/java/com/seailz/discordjar/DiscordJar.java
index 10ff9979..1cf56120 100644
--- a/src/main/java/com/seailz/discordjar/DiscordJar.java
+++ b/src/main/java/com/seailz/discordjar/DiscordJar.java
@@ -18,6 +18,7 @@
import com.seailz.discordjar.command.listeners.slash.SlashCommandListener;
import com.seailz.discordjar.command.listeners.slash.SlashSubCommand;
import com.seailz.discordjar.command.listeners.slash.SubCommandListener;
+import com.seailz.discordjar.decoding.DiscordObjectParser;
import com.seailz.discordjar.events.DiscordListener;
import com.seailz.discordjar.events.EventDispatcher;
import com.seailz.discordjar.gateway.Gateway;
@@ -90,6 +91,7 @@ public class DiscordJar {
* Stores the logger
*/
private final Logger logger;
+ private final DiscordObjectParser parser;
/**
* Intents the bot will use when connecting to the gateway
*/
@@ -224,6 +226,7 @@ public DiscordJar(String token, EnumSet intents, APIVersion version, boo
new URLS(release, version);
logger = Logger.getLogger("DISCORD.JAR");
this.commandDispatcher = new CommandDispatcher();
+ this.parser = new DiscordObjectParser(this);
this.queuedRequests = new ArrayList<>();
this.buckets = new ArrayList<>();
this.voiceStates = new HashMap<>();
@@ -1571,4 +1574,8 @@ public Long getAverageGatewayPing() {
public APIVersion getApiVersion() {
return apiVersion;
}
+
+ public DiscordObjectParser getParser() {
+ return parser;
+ }
}
diff --git a/src/main/java/com/seailz/discordjar/decoding/DiscordObject.java b/src/main/java/com/seailz/discordjar/decoding/DiscordObject.java
new file mode 100644
index 00000000..85830a25
--- /dev/null
+++ b/src/main/java/com/seailz/discordjar/decoding/DiscordObject.java
@@ -0,0 +1,17 @@
+package com.seailz.discordjar.decoding;
+
+import com.seailz.discordjar.decoding.annotations.DiscordJarParameter;
+import com.seailz.discordjar.decoding.annotations.DiscordObjectConstructor;
+import com.seailz.discordjar.decoding.annotations.DiscordObjectParameter;
+
+/**
+ * Marks an object that can be decoded by {@link DiscordObjectParser}.
+ *
Each one of your fields must be marked with {@link DiscordObjectParameter DiscordObjectParameter},
+ * and can be marked with {@link DiscordJarParameter DiscordJarParameter} in order to have
+ * its value set default to the existing DiscordJar instance.
+ *
+ * You must have a constructor that matches your fields, even down to the order. That constructor
+ * must be marked with {@link DiscordObjectConstructor DiscordObjectConstructor}.
+ */
+public interface DiscordObject {
+}
diff --git a/src/main/java/com/seailz/discordjar/decoding/DiscordObjectParser.java b/src/main/java/com/seailz/discordjar/decoding/DiscordObjectParser.java
new file mode 100644
index 00000000..fabc9141
--- /dev/null
+++ b/src/main/java/com/seailz/discordjar/decoding/DiscordObjectParser.java
@@ -0,0 +1,193 @@
+package com.seailz.discordjar.decoding;
+
+import com.seailz.discordjar.DiscordJar;
+import com.seailz.discordjar.decoding.annotations.DiscordJarParameter;
+import com.seailz.discordjar.decoding.annotations.DiscordObjectConstructor;
+import com.seailz.discordjar.decoding.annotations.DiscordObjectCustomAssignationsMethod;
+import com.seailz.discordjar.decoding.annotations.DiscordObjectParameter;
+import com.seailz.discordjar.decoding.data.DiscordObjectInformation;
+import com.seailz.discordjar.decoding.data.DiscordObjectParameterInformation;
+import lombok.Getter;
+import org.jetbrains.annotations.Nullable;
+import org.json.JSONObject;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Parses objects from JSON into Java Objects ({@link DiscordObject}). Designed using reflection
+ * to improve the developer experience of working on discord.jar and decrease
+ * the amount of repeated code.
+ *
+ * Each DiscordJar instance uses its own parser as if a parameter is marked as {@link DiscordObjectParameter},
+ * the parser needs to provide a DiscordJar instance.
+ */
+public class DiscordObjectParser {
+
+ @Getter
+ private DiscordJar discordJar;
+
+ public DiscordObjectParser(DiscordJar discordJar) {
+ this.discordJar = discordJar;
+ }
+
+ /**
+ * Since reflection isn't instant, there's a cache to prevent un-needed delays.
+ */
+ private HashMap, DiscordObjectInformation> objectInformationCache = new HashMap<>();
+
+ public T decompileObject(JSONObject data, Class type) {
+ long start = System.currentTimeMillis();
+ DiscordObjectInformation objInfo = objectInformationCache.get(type);
+
+ if (objInfo == null) {
+ objInfo = discoverObject(type);
+ }
+ System.out.println("Took " + (System.currentTimeMillis() - start) + "ms to discover object info");
+
+ List