Skip to content

Commit

Permalink
Support Object When Setting Placeholder Result (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotSoDelayed authored Feb 9, 2024
1 parent b730ffa commit 583ac4c
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.registrations.Classes;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import io.github.apickledwalrus.skriptplaceholders.skript.PlaceholderEvent;
Expand All @@ -27,7 +28,7 @@
"\t# Placeholder is \"{skriptplaceholders_author}\"",
"\tset the result to \"APickledWalrus\""
})
@Since("1.0, 1.3 (MVdWPlaceholderAPI support)")
@Since("1.0, 1.3 (MVdWPlaceholderAPI support), INSERT VERSION (object support)")
@Events("Placeholder Request")
public class ExprPlaceholderResult extends SimpleExpression<String> {

Expand Down Expand Up @@ -58,21 +59,26 @@ public Class<?>[] acceptChange(ChangeMode mode) {
case SET:
case DELETE:
case RESET:
return CollectionUtils.array(String.class);
return CollectionUtils.array(Object.class);
default:
return null;
}
}

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
PlaceholderEvent placeholderEvent = ((PlaceholderEvent) event);
switch (mode) {
case SET:
((PlaceholderEvent) event).setResult((String) delta[0]);
if (delta[0] instanceof String) {
placeholderEvent.setResult((String) delta[0]);
} else {
placeholderEvent.setResult(Classes.toString(delta[0]));
}
break;
case RESET:
case DELETE:
((PlaceholderEvent) event).setResult(null);
placeholderEvent.setResult(null);
break;
default:
assert false;
Expand Down

0 comments on commit 583ac4c

Please sign in to comment.