Skip to content

Commit

Permalink
🚀 (for real this time) Updated to Skript 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Jan 3, 2025
1 parent a5d06a2 commit 3afcd26
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 31 deletions.
47 changes: 40 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'java'
id 'idea'
Expand All @@ -19,7 +21,7 @@ version = major + '.' + minor + '.' + patch + (channel ? '-' + channel + channel
repositories {
mavenCentral()
mavenLocal()
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
maven { url = 'https://oss.sonatype.org/content/groups/public/' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://maven.enginehub.org/repo/' }
Expand All @@ -28,7 +30,7 @@ repositories {
}

dependencies {
shadow 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
shadow 'io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT'
shadow 'com.github.SkriptLang:Skript:2.10.0-pre1'
// Jetbrains Annotations
shadow 'org.jetbrains:annotations:23.0.0'
Expand All @@ -44,10 +46,45 @@ dependencies {
shadowJar {
minimize()

// archiveName = 'DiSky ' + version + '.jar'
setArchiveFileName('DiSky ' + version + '.jar')
}

task removeClassPath {
doLast {
def jarFile = file("${buildDir}/libs/DiSky ${version}.jar")

// Créer un jar temporaire
def tempJar = new File(temporaryDir, "temp.jar")
def manifestFile = new File(temporaryDir, "MANIFEST.MF")
manifestFile.parentFile.mkdirs()

// Lire le manifest existant
def origManifest = new java.util.jar.JarFile(jarFile).manifest

// Créer un nouveau manifest sans Class-Path
def newManifest = new StringBuilder()
origManifest.mainAttributes.entrySet().each { entry ->
if (entry.key.toString() != "Class-Path") {
newManifest.append("${entry.key}: ${entry.value}\n")
}
}
manifestFile.text = newManifest.toString()

// Créer le nouveau jar avec le manifest modifié
ant.jar(destfile: tempJar.path, manifest: manifestFile) {
zipfileset(src: jarFile) {
exclude(name: 'META-INF/MANIFEST.MF')
}
}

// Remplacer le jar original
jarFile.delete()
tempJar.renameTo(jarFile)
}
}

shadowJar.finalizedBy removeClassPath

def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
Expand All @@ -73,10 +110,6 @@ processResources {
}
}

configurations.all {
resolutionStrategy.cacheChangingModulesFor 1, 'minutes'
}

idea {
module {
downloadJavadoc = true
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/info/itsthesky/disky/api/DiSkyRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package info.itsthesky.disky.api;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import info.itsthesky.disky.DiSky;
import org.bukkit.plugin.java.JavaPlugin;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxOrigin;
import org.skriptlang.skript.registration.SyntaxRegistry;

public final class DiSkyRegistry {

public static <E extends Expression<T>, T> void registerExpression(
Class<E> expressionType, Class<T> returnType, ExpressionType type, String... patterns
) throws IllegalArgumentException {
var addon = DiSky.getAddonInstance();
addon.syntaxRegistry().register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(expressionType, returnType)
.priority(type.priority())
.origin(SyntaxOrigin.of(addon))
.addPatterns(patterns)
.build()
);
}

public static <E extends Condition> void registerCondition(Class<E> conditionClass, Condition.ConditionType type, String... patterns) throws IllegalArgumentException {
var addon = DiSky.getAddonInstance();
addon.syntaxRegistry().register(SyntaxRegistry.CONDITION, SyntaxInfo.builder(conditionClass)
.priority(type.priority())
.origin(SyntaxOrigin.of(addon))
.addPatterns(patterns)
.build()
);
}

public static boolean unregisterElement(SyntaxRegistry.Key syntaxKey, Class<?> element) {
try {
var reg = DiSky.getAddonInstance().syntaxRegistry();

for (var entry : reg.elements()) {
if (entry.type().equals(element)) {
reg.unregister(syntaxKey, entry);
return true;
}
}

DiSky.debug("The element " + element.getSimpleName() + " is not registered in the Skript registry.");
return false;
} catch (Exception e) {
DiSky.debug("An error occurred while trying to unregister the element " + element.getSimpleName() + " from the Skript registry:");
e.printStackTrace();
return false;
}
}

public static <T> void registerProperty(Class<? extends Expression<T>> expressionClass, Class<T> type, String property, String fromType) {
registerExpression(expressionClass, type, ExpressionType.PROPERTY, PropertyExpression.getPatterns(property, fromType));
}

public static void registerPropertyCondition(Class<? extends Condition> condition, String property, String type) {
registerCondition(condition, Condition.ConditionType.PROPERTY,
PropertyCondition.getPatterns(PropertyCondition.PropertyType.BE, property, type));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public EmbedBuilder build() {
if (thumbnail != null) builder.setThumbnail(thumbnail);
if (image != null) builder.setImage(image);

if (timestamp != null) builder.setTimestamp(Instant.ofEpochMilli(timestamp.getTime()));
if (timestamp != null) builder.setTimestamp(Instant.ofEpochMilli(timestamp.getTimestamp()));

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.DiSkyRegistry;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.implementation.MethodDelegation;
Expand Down Expand Up @@ -114,7 +115,7 @@ public static <F, T> void register(String fromTypeName,
.load(ReflectProperty.class.getClassLoader())
.getLoaded();

SimplePropertyExpression.register((Class<? extends Expression<T>>) elementClass,
DiSkyRegistry.registerProperty((Class<? extends Expression<T>>) elementClass,
toType, property, fromTypeName);
DiSky.debug("Registered property expression: " + elementClass.getName() + " (" + fromTypeName + " -> " + toType.getSimpleName() + ")");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.DiSkyRegistry;
import info.itsthesky.disky.api.skript.SimpleGetterExpression;
import info.itsthesky.disky.elements.events.interactions.MessageCommandEvent;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.MethodDelegation;
import net.dv8tion.jda.api.entities.Message;
import org.bukkit.event.Event;
import org.bukkit.plugin.java.JavaPlugin;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxOrigin;
import org.skriptlang.skript.registration.SyntaxRegistry;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand All @@ -28,6 +33,9 @@ public static <T, E extends Event> void registerEventExpression(
Class<T> expressionClass,
Function<E, T> converter
) {
if (true)
return;

COUNT.incrementAndGet();
try {

Expand All @@ -45,7 +53,7 @@ public static <T, E extends Event> void registerEventExpression(
.load(ReflectGetterExpression.class.getClassLoader())
.getLoaded();

Skript.registerExpression(
DiSkyRegistry.registerExpression(
(Class) elementClass,
expressionClass,
ExpressionType.SIMPLE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package info.itsthesky.disky.api.skript.reflects;

import ch.njol.skript.expressions.base.SimplePropertyExpression;
import io.papermc.paper.plugin.provider.classloader.ConfiguredPluginClassLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ch.njol.skript.classes.Changer;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.ExpressionType;
import info.itsthesky.disky.api.DiSkyRegistry;
import info.itsthesky.disky.api.skript.INodeHolder;
import ch.njol.skript.conditions.base.PropertyCondition;
import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
Expand Down Expand Up @@ -54,7 +56,7 @@ public static <T> void register(
.make()
.load(typeClass.getClassLoader())
.getLoaded();
PropertyCondition.register((Class<? extends Condition>) conditionClass, stateName, typeName);
DiSkyRegistry.registerPropertyCondition((Class<? extends Condition>) conditionClass, stateName, typeName);

// Property
final Class<?> propertyClass = new ByteBuddy()
Expand All @@ -69,7 +71,7 @@ public static <T> void register(
.load(typeClass.getClassLoader())
.getLoaded();

SimplePropertyExpression.register(
DiSkyRegistry.registerProperty(
(Class<? extends SimplePropertyExpression<Object, Boolean>>) propertyClass,
Boolean.class,
stateName + " state",
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/info/itsthesky/disky/core/SkriptUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public static <B extends Event, T> void registerValue(Class<B> bukkitClass,
int time) {
if (entityClass.isArray())
Logger.getLogger("DiSky").severe("Class "+ ReflectionUtils.getCurrentClass().getName() + " still use the single value registration while providing an array value.");
EventValues.registerEventValue(bukkitClass, entityClass, new Converter<B, T>() {
EventValues.registerEventValue(bukkitClass, entityClass, new Getter<T, B>() {
@Override
public @Nullable T convert(B arg) {
public @Nullable T get(B arg) {
try {
return function.apply(arg);
} catch (Exception ex) {
Expand Down Expand Up @@ -255,7 +255,7 @@ public static List<TriggerItem> loadCode(SectionNode sectionNode, Class<? extend
}

public static OffsetDateTime convertDate(Date date) {
final long ms = date.getTime();
final long ms = date.getTimestamp();
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(ms), ZoneId.systemDefault());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
bot = (Expression<Bot>) exprs[1];
changed = exprs[0];
}
this.bot = SkriptUtils.defaultToEventValue(bot, Bot.class);
//this.bot = SkriptUtils.defaultToEventValue(bot, Bot.class);
if (bot == null) {
parsing = false;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public class CommandRegistry extends SelfRegisteringSkriptEvent {
SkriptUtils.registerValue(CommandEvent.class, GuildChannel.class, CommandEvent::getTxtChannel);
SkriptUtils.registerValue(CommandEvent.class, String.class, CommandEvent::getPrefix);

EventValues.registerEventValue(CommandEvent.class, Bot.class, new Converter<CommandEvent, Bot>() {
EventValues.registerEventValue(CommandEvent.class, Bot.class, new Getter<Bot, CommandEvent>() {
@Override
public Bot convert(@NotNull CommandEvent event) {
public Bot get(@NotNull CommandEvent event) {
return DiSky.getManager().fromJDA(event.getBot());
}
}, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.ExprPermissions;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.DiSkyRegistry;
import info.itsthesky.disky.api.ReflectionUtils;
import info.itsthesky.disky.api.skript.EasyElement;
import info.itsthesky.disky.elements.changers.IAsyncChangeableExpression;
Expand All @@ -25,6 +27,7 @@
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxRegistry;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -41,13 +44,10 @@
public class PermissionsOf extends SimpleExpression<Object> implements IAsyncChangeableExpression {

static {
try {
ReflectionUtils.removeElement("ch.njol.skript.expressions.ExprPermissions",
"expressions");
DiSky.debug("Removed original 'permissions' expression, to replace it with a new one.");
} catch (Exception e) {
Skript.error("DiSky were unable to remove the original 'permissions' expression, please report this error to the developer, with the following error.");
e.printStackTrace();
if (DiSkyRegistry.unregisterElement(SyntaxRegistry.EXPRESSION, ExprPermissions.class)) {
DiSky.debug("Unregistered the original 'permissions' expression, to replace it with a new one.");
} else {
Skript.error("DiSky were unable to unregister the original 'permissions' expression, please report this error to the developer.");
}

Skript.registerExpression(PermissionsOf.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.effects.Delay;
import ch.njol.skript.effects.EffReturn;
import ch.njol.skript.expressions.ExprPermissions;
import ch.njol.skript.lang.*;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.function.FunctionEvent;
Expand All @@ -16,13 +18,15 @@
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.DiSkyRegistry;
import info.itsthesky.disky.api.ReflectionUtils;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxRegistry;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -35,12 +39,10 @@ public class FindMemberSection extends Section {
"find [the] [discord] member[s] (in|from) [guild] %guild% and store (them|the members) in %~objects% with filter var[iable] %~objects%"
);

try {
ReflectionUtils.removeElement("ch.njol.skript.effects.EffReturn",
"expressions");
} catch (Exception e) {
Skript.error("DiSky were unable to remove the original 'return' effect, please report this error to the developer, with the following error.");
e.printStackTrace();
if (DiSkyRegistry.unregisterElement(SyntaxRegistry.EXPRESSION, ch.njol.skript.effects.EffReturn.class)) {
DiSky.debug("Unregistered the original 'permissions' expression, to replace it with a new one.");
} else {
Skript.error("DiSky were unable to unregister the original 'permissions' expression, please report this error to the developer.");
}

Skript.registerEffect(
Expand Down

0 comments on commit 3afcd26

Please sign in to comment.