SkriptLang / skript-reflect

Powerful reflection utilities for Skript.
MIT License
65 stars 20 forks source link

Implement ExprPlugin #49

Closed Pikachu920 closed 2 years ago

Pikachu920 commented 2 years ago

Adds ExprPlugin which allows direct access to javaplugin instances either by name or from a javatype. This makes it easier to get an instance of a plugin without having to import org.bukkit.Bukkit and grab it from the PluginManager. Test script:

import:
    ch.njol.skript.Skript as pluginMainClass
    ch.njol.skript.ScriptLoader as otherPluginClass
    java.lang.String as notAPluginClass

on load:
    broadcast "pluginMainClass: %instance of plugin pluginMainClass%"
    broadcast "otherPluginClass: %instance of plugin otherPluginClass%"
    broadcast "notAPluginClass: %instance of plugin notAPluginClass%"
    broadcast "Null: %instance of plugin {_null}%"
    broadcast "Case insensitive (sKrIpT): %instance of plugin "sKrIpT"%"
    broadcast "Case sensitive (Skript): %instance of plugin "Skript"%"
    broadcast "Call instance method of plugin instance: %(instance of plugin "Skript").getUpdater()%"

Output:

[02:20:49 INFO]: [Skript] Reloading test.sk...
[02:20:49 INFO]: pluginMainClass: Skript v2.6.1
[02:20:49 INFO]: otherPluginClass: Skript v2.6.1
[02:20:49 INFO]: notAPluginClass: <none>
[02:20:49 INFO]: Null: <none>
[02:20:49 INFO]: Case insensitive (sKrIpT): Skript v2.6.1
[02:20:49 INFO]: Case sensitive (Skript): Skript v2.6.1
[02:20:49 INFO]: Call instance method of plugin instance: ch.njol.skript.SkriptUpdater@219b27ec
[02:20:49 INFO]: [Skript] Successfully reloaded test.sk. (27ms)
TPGamesNL commented 2 years ago

I've made a few changes, among others disallowing the use of none-main plugin classes (such as ScriptLoader) with this expression. I did this because I often see people struggle with getting the instance of a certain class, and people might think this expression does it for them, plus the benefit of being able to call it on a non-main plugin class is small.