SkriptLang / skript-reflect

Powerful reflection utilities for Skript.
MIT License
56 stars 19 forks source link

Structure API Update #77

Closed UnderscoreTud closed 4 months ago

UnderscoreTud commented 7 months ago

Convert code using SelfRegisteringSkriptEvent to use Structures and start moving classes into the new package (org.skriptlang.skript)

Fixes https://github.com/SkriptLang/skript-reflect/issues/75 Fixes https://github.com/SkriptLang/skript-reflect/issues/72 Fixes https://github.com/SkriptLang/skript-reflect/issues/69

envizar commented 6 months ago

Is there already a stable version with these changes? New version of Hippo depends on skript-reflect with these changes

rudde0 commented 6 months ago

idk is it correct place or not but I want to mention that skript-reflects detects new ArrayList() as skript function and it throws The function 'ArrayList' does not exist. error.

import:
    java.util.ArrayList
    java.util.Collections
    java.util.Map$Entry
    ch.njol.skript.variables.Variables

# Example
#set {_topkillers::*} to the top (size of {Kills::*}) values of {Kills::*} as "&e@place. &a@index &7- &b@value"
expression replace values %strings% with %strings% in %string%:
    get:
        set {_string} to expression-3
        loop expressions-1:
            add 1 to {_index}
            replace all "%loop-value%" with "%{_index}th element of expressions-2%" in {_string}
        return {_string}

plural expression [the ](1¦(highest|top)|2¦(lowest|last)) %integer% values of %objects% [formatted ]as %string%:
    get:
        set {_list} to new ArrayList(Variables.getVariable(raw expressions-2.getName().toString(event), event, raw expressions-2.isLocal()).entrySet())
        ({_list}).sort(Entry.comparingByValue())
        if parse mark = 1:
            Collections.reverse({_list})
        loop ...{_list}:
            add 1 to {_index}
            set {_sorted::%{_index}%} to replace values "@place", "@index" and "@value" with "%{_index}%", "%loop-value.getKey()%" and "%loop-value.getValue()%" in expression-3
            {_index} = expression-1
            stop loop
        return {_sorted::*}