Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Any X

Open Moderocky opened this issue 1 year ago • 0 comments

Description

This change is mainly aimed at addons (with a little bit of internal clean-up).

This adds 'Any-X' types, which allow Skript and addons to register lots of different types that have a single common property (e.g. name), which can use the same property expression. See here for details.

With this, addons can support their own (common) properties (e.g. name of <discord channel>, name of <file>) without conflicting with Skript. This also means that Skript doesn't need 18 different possibilities in the pattern input.

These Any-X types have a bit of special behaviour: they have their own kind of class info (they could probably do with a special note in docs because the use patterns look a bit odd) and their input patterns start any-.... This is to help emphasise that they are general acceptors rather than specific things.

Extra Fix!

This also fixes #6727: an unsafe cast is no longer permitted at the start of a no-left-chain, or at the end of a no-right-chain. If you want the old behaviour (I know some of us secretly love unsafe casts) then you can re-enable that behaviour with an extra bit flag ALLOW_UNSAFE_CASTS.

Using This

Addons that want to use an Any-X type can just implement the interface with their type (e.g. MyThing implements AnyNamed) or, if this isn't possible, register a converter from their type (e.g. registerConverter(MyThing.class, AnyNamed.class, thing -> thing::getName) with no right chaining!!!11!1 <- (this is important because otherwise Skript thinks it can convert between your type and every other type in the galaxy)


Target Minecraft Versions: any Requirements: none Related Issues: fixes #6710, fixes #6727

Moderocky avatar May 26 '24 19:05 Moderocky