Skip to content

Commit

Permalink
Merge branch 'master' into equip-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EquipableMC committed Jan 18, 2025
2 parents 6dc6922 + b049b08 commit f2ef51f
Show file tree
Hide file tree
Showing 567 changed files with 1,631 additions and 1,611 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
id "com.gradleup.shadow" version "9.0.0-beta4"
}

group = 'info.itsthesky'
group = 'net.itsthesky'

// Semantic Versioning
def major = '4'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package info.itsthesky.disky;
package net.itsthesky.disky;

import info.itsthesky.disky.core.Bot;
import net.itsthesky.disky.core.Bot;

/**
* Class that will store and handle information about a bot's application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package info.itsthesky.disky;
package net.itsthesky.disky;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.util.Version;
import info.itsthesky.disky.api.emojis.EmojiStore;
import info.itsthesky.disky.api.generator.DocBuilder;
import info.itsthesky.disky.api.modules.DiSkyModule;
import info.itsthesky.disky.api.modules.ModuleManager;
import info.itsthesky.disky.api.skript.ErrorHandler;
import info.itsthesky.disky.core.DiSkyCommand;
import info.itsthesky.disky.core.DiSkyMetrics;
import info.itsthesky.disky.core.Utils;
import info.itsthesky.disky.elements.properties.DynamicElements;
import info.itsthesky.disky.elements.structures.context.ContextCommandManager;
import info.itsthesky.disky.elements.structures.slash.SlashManager;
import info.itsthesky.disky.managers.BotManager;
import info.itsthesky.disky.managers.ConfigManager;
import info.itsthesky.disky.managers.WebhooksManager;
import net.itsthesky.disky.api.emojis.EmojiStore;
import net.itsthesky.disky.api.generator.DocBuilder;
import net.itsthesky.disky.api.modules.DiSkyModule;
import net.itsthesky.disky.api.modules.ModuleManager;
import net.itsthesky.disky.api.skript.ErrorHandler;
import net.itsthesky.disky.core.DiSkyCommand;
import net.itsthesky.disky.core.DiSkyMetrics;
import net.itsthesky.disky.core.Utils;
import net.itsthesky.disky.elements.properties.DynamicElements;
import net.itsthesky.disky.elements.structures.context.ContextCommandManager;
import net.itsthesky.disky.elements.structures.slash.SlashManager;
import net.itsthesky.disky.managers.BotManager;
import net.itsthesky.disky.managers.ConfigManager;
import net.itsthesky.disky.managers.WebhooksManager;
import net.dv8tion.jda.api.requests.RestAction;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -131,7 +131,7 @@ public void onEnable() {
DynamicElements.registerThreadProperties();
DynamicElements.registerAutoMod();

addonInstance.loadClasses("info.itsthesky.disky.elements");
addonInstance.loadClasses("net.itsthesky.disky.elements");
moduleManager.loadModules();
} catch (IOException e) {
errorHandler.exception(null, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package info.itsthesky.disky.api;
package net.itsthesky.disky.api;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.*;
import info.itsthesky.disky.DiSky;
import net.itsthesky.disky.DiSky;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxOrigin;
import org.skriptlang.skript.registration.SyntaxRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api;
package net.itsthesky.disky.api;

import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api;
package net.itsthesky.disky.api;

import net.dv8tion.jda.api.EmbedBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api;
package net.itsthesky.disky.api;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Effect;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.expressions.base.PropertyExpression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.util.SimpleExpression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import info.itsthesky.disky.core.Bot;
import info.itsthesky.disky.elements.changers.Change;
import net.itsthesky.disky.core.Bot;
import net.itsthesky.disky.elements.changers.Change;
import org.jetbrains.annotations.NotNull;

public abstract class DiSkyChanger<T> implements Changer<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.core.Bot;
import net.itsthesky.disky.DiSky;
import net.itsthesky.disky.core.Bot;
import org.bukkit.event.Event;

public interface DiSkyChangerElement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.itsthesky.disky.api.changers;
package net.itsthesky.disky.api.changers;

import ch.njol.skript.classes.Changer;
import info.itsthesky.disky.api.skript.MultiplyPropertyExpression;
import net.itsthesky.disky.api.skript.MultiplyPropertyExpression;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import ch.njol.skript.Skript;
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.expressions.base.SectionExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.datastruct.base.DataStruct;
import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import net.itsthesky.disky.api.datastruct.base.DataStruct;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryContainer;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class BaseDataStructElement<T, D extends DataStruct<T>> extends SectionExpression<T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
Expand All @@ -7,18 +7,14 @@
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.api.datastruct.base.DataStruct;
import info.itsthesky.disky.elements.changers.IAsyncGettableExpression;
import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import net.itsthesky.disky.api.datastruct.base.DataStruct;
import net.itsthesky.disky.elements.changers.IAsyncGettableExpression;
import net.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryContainer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class ChainDataStructElement<F, T, D extends DataStruct<T>>
extends SectionExpression<F> implements IAsyncGettableExpression<F> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import net.itsthesky.disky.elements.datastructs.structures.EmbedFieldStructure;
import net.itsthesky.disky.elements.datastructs.structures.EmbedStructure;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -13,8 +16,8 @@
Class<?> clazz();

/**
* Whether this structure can be made from a {@link info.itsthesky.disky.elements.sections.CreateStructSection create structure section}.
* A data structure may only serve as "sub-data structure" for other structures (like {@link info.itsthesky.disky.elements.datastructs.structures.EmbedFieldStructure} for {@link info.itsthesky.disky.elements.datastructs.structures.EmbedStructure}).
* Whether this structure can be made from a {@link net.itsthesky.disky.elements.sections.CreateStructSection create structure section}.
* A data structure may only serve as "sub-data structure" for other structures (like {@link EmbedFieldStructure} for {@link EmbedStructure}).
*/
boolean canBeCreated() default true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import info.itsthesky.disky.api.datastruct.base.DataStruct;
import net.itsthesky.disky.api.datastruct.base.DataStruct;

import javax.annotation.Nullable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import ch.njol.skript.Skript;
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.registrations.Classes;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.ReflectionUtils;
import info.itsthesky.disky.api.datastruct.base.BasicDS;
import info.itsthesky.disky.api.datastruct.base.ChainDS;
import info.itsthesky.disky.api.datastruct.base.DataStruct;
import info.itsthesky.disky.api.skript.BetterExpressionEntryData;
import info.itsthesky.disky.core.SkriptUtils;
import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import net.itsthesky.disky.DiSky;
import net.itsthesky.disky.api.ReflectionUtils;
import net.itsthesky.disky.api.datastruct.base.BasicDS;
import net.itsthesky.disky.api.datastruct.base.ChainDS;
import net.itsthesky.disky.api.datastruct.base.DataStruct;
import net.itsthesky.disky.api.skript.BetterExpressionEntryData;
import net.itsthesky.disky.core.SkriptUtils;
import net.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryContainer;
import org.skriptlang.skript.lang.entry.EntryValidator;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

/**
Expand All @@ -44,6 +44,7 @@ public final class DataStructureFactory {
* containing all necessary information to create instances.
*/
public static record DataStructureParseResult(
@NotNull SectionNode relatedNode,
@NotNull EntryValidator validator,
@NotNull EntryContainer container,
@NotNull Map<String, List<Expression<?>>> expressions,
Expand Down Expand Up @@ -79,7 +80,7 @@ public static DataStructureParseResult initDataStructure(
return null;
}

return new DataStructureParseResult(validator, container, expressions, subStructures);
return new DataStructureParseResult(node, validator, container, expressions, subStructures);
}

/**
Expand All @@ -92,15 +93,22 @@ public static EntryValidator createValidator(@NotNull Class<?> structClass) {
final var validator = EntryValidator.builder();
DiSky.debug("=========== Starting validation of data structure " + structClass.getName() + " ===========");

final var plannedKeys = new HashSet<String>();
for (final var field : structClass.getDeclaredFields()) {
final var entry = field.getAnnotation(DataStructureEntry.class);
if (entry == null) continue;
if (entry == null)
continue;

processFieldValidator(validator, field, entry, structClass);
plannedKeys.add(entry.value());
}

validator.unexpectedNodeTester(node -> {
DiSky.debug("UNEXPECTED NODE: " + node.getKey());
final var key = node.getKey().split(":")[0];
if (plannedKeys.contains(key))
return false; // all good, it's a sub-structure or entry

Skript.error("Unexpected node with key '" + key + "' in data structure " + structClass.getSimpleName());
return false;
});

Expand Down Expand Up @@ -130,11 +138,38 @@ public static Object createDataStructure(

final var unhandledNodes = groupUnhandledNodes(container);
processFields(structClass, instance, parseResult, event, unhandledNodes);
if (!validateFields(parseResult.relatedNode(), structClass, instance))
return null;

DiSky.debug("################## End of creation of data structure " + structClass.getName() + " ##################");
return finalizeInstance(instance, chainInstance);
}

/**
* Validates the fields of a data structure instance.
* This will check the instance's field value for optional and type constraints.
* @param structClass The class of the data structure
* @param instance The instance to validate
*/
private static boolean validateFields(@NotNull Node node, @NotNull Class<?> structClass, @NotNull Object instance) {
for (final var field : structClass.getDeclaredFields()) {
final var entry = field.getAnnotation(DataStructureEntry.class);
if (entry == null) continue;

final var key = entry.value();
final var value = ReflectionUtils.getFieldValue(field, instance);

if (value == null && !entry.optional()) {
DiSkyRuntimeHandler.error(new IllegalStateException(
"Field '" + key + "' in data structure " + structClass.getSimpleName() + " is null/none/empty, but is required!"
), node, false);
return false;
}
}

return true;
}

/**
* Maps field keys to their corresponding field names.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package info.itsthesky.disky.api.datastruct;
package net.itsthesky.disky.api.datastruct;

import ch.njol.skript.lang.ExpressionType;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.DiSkyRegistry;
import info.itsthesky.disky.api.datastruct.base.DataStruct;
import info.itsthesky.disky.elements.datastructs.structures.EmbedStructure;
import net.itsthesky.disky.DiSky;
import net.itsthesky.disky.api.DiSkyRegistry;
import net.itsthesky.disky.api.datastruct.base.DataStruct;
import net.itsthesky.disky.elements.datastructs.structures.EmbedStructure;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.bind.annotation.AllArguments;
Expand Down Expand Up @@ -32,7 +32,7 @@ public static <T, D extends DataStruct<T>> void registerBasicDataStructure(Class

final Class<?> elementClass = new ByteBuddy()
.redefine(ReflectBasicDataStructure.class)
.name("info.itsthesky.disky.elements.reflects.ReflectDataStructureElement_" + COUNT.incrementAndGet())
.name("net.itsthesky.disky.elements.reflects.ReflectDataStructureElement_" + COUNT.incrementAndGet())

.method(named("getReturnType")).intercept(MethodDelegation.to(new ReturnClassMethodInterceptor(returnType)))
.method(named("getDataStructClass")).intercept(MethodDelegation.to(new ReturnClassMethodInterceptor(clazz)))
Expand Down
Loading

0 comments on commit f2ef51f

Please sign in to comment.