Skip to content

Commit

Permalink
updated to Skript 2.9 and plugin version to 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Pesekjak committed Jul 22, 2024
1 parent c6a8fae commit 4082633
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 34 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Group and version
group = me.pesekjak.hippo
version = 1.1.1
version = 1.2

# Dependency versions
jetbrainsKotlinGradle = 1.9.23
jetbrainsAnnotations = 24.1.0
junit = 5.10.1
spigotApi = 1.20.4-R0.1-SNAPSHOT
skript = 2.9.0-pre1
skript = 2.9.0
asm = 9.7

# Plugins
Expand Down
Binary file modified libs/skript-reflect.jar
Binary file not shown.
16 changes: 16 additions & 0 deletions plugin/src/main/java/me/pesekjak/hippo/bukkit/MethodCallEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ public class MethodCallEvent extends InstanceEvent {

private static final HandlerList HANDLERS = new HandlerList();

private @Nullable Object returned;

public MethodCallEvent(AbstractClass source, @Nullable Object instance) {
super(source, instance);
}

/**
* @return returned object
*/
public @Nullable Object getReturned() {
return returned;
}

/**
* @param returned new returned object
*/
public void setReturned(@Nullable Object returned) {
this.returned = returned;
}

@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.objectweb.asm.Type;

import java.util.List;
import java.util.function.Supplier;

import static org.objectweb.asm.Opcodes.*;

Expand All @@ -19,14 +18,10 @@
* @param method wrapped method
* @param arguments named parameters of the method
* @param trigger trigger of the method
* @param returnSupplier supplier of returned values
*/
// Named parameters are used because Method object does not store info about parameters names, and
// they are later used to set variables for the method code execution.
public record MethodWrapper(Method method,
List<NamedParameter> arguments,
@Nullable Trigger trigger,
@Nullable Supplier<?> returnSupplier) implements ClassContentSkriptWrapper {
public record MethodWrapper(Method method, List<NamedParameter> arguments, @Nullable Trigger trigger) implements ClassContentSkriptWrapper {

@Override
public ClassContent content() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ public Table<String, String, ClassContentSkriptWrapper> getTable() {
if (event.getThrowable() != null)
ExceptionThrower.throwException(event.getThrowable());

if (methodWrapper.returnSupplier() == null) return null; // abstract method

return methodWrapper.returnSupplier().get();
return event.getReturned();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean init(Expression<?> @NotNull [] expressions,
throw new IllegalModifiersException("Method effects need to be abstract");

source.addMethod(method);
methodWrapper = new MethodWrapper(method, List.of(namedParameters), null, null);
methodWrapper = new MethodWrapper(method, List.of(namedParameters), null);

storage.getTable().put(method.getName(), method.getDescriptor(), methodWrapper);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public class SecMethod extends Section implements ReturnHandler<Object> {
private Type returnType;
private MethodWrapper methodWrapper;

// TODO
// this is temporary solution until Skript introduces
// different API for providing return values
private final ThreadLocal<Object> returnedObject = new ThreadLocal<>();

static {
Skript.registerSection(
SecMethod.class,
Expand Down Expand Up @@ -105,11 +100,7 @@ public boolean init(Expression<?> @NotNull [] expressions,
Trigger trigger = loadReturnableSectionCode(sectionNode, "method", new Class[] {MethodCallEvent.class});

source.addMethod(method);
methodWrapper = new MethodWrapper(method, List.of(namedParameters), trigger, () -> {
Object returned = getReturnValue();
resetReturnValue();
return returned;
});
methodWrapper = new MethodWrapper(method, List.of(namedParameters), trigger);

storage.getTable().put(method.getName(), method.getDescriptor(), methodWrapper);

Expand Down Expand Up @@ -141,9 +132,9 @@ public Type getReturnType() {
}

@Override
public void returnValues(Object @Nullable [] values) {
Object value = values != null && values.length > 0 ? values[0] : null;
returnedObject.set(value);
public void returnValues(@NotNull Event event, @NotNull Expression<?> expression) {
if (!(event instanceof MethodCallEvent methodCall)) return;
methodCall.setReturned(expression.getSingle(event));
}

@Override
Expand All @@ -156,12 +147,4 @@ public boolean isSingleReturnValue() {
return Object.class;
}

public @Nullable Object getReturnValue() {
return returnedObject.get();
}

public void resetReturnValue() {
returnedObject.remove();
}

}
2 changes: 1 addition & 1 deletion plugin/src/main/resources/lang/english.lang
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.1.1
version: 1.2
types:
modifier: modifier¦s @a
annotation: annotation¦s @an
Expand Down

0 comments on commit 4082633

Please sign in to comment.