Package net.citizensnpcs.api.scripting
Interface Script
- All Known Implementing Classes:
SimpleScript
public interface Script
Represents a script written in a scripting language such as Lua, Ruby, Python or JavaScript, or any others that
implements the JSR-233 scripting interfaces, including
Invocable
and Compilable
.-
Method Summary
Modifier and TypeMethodDescription<T> T
convertToInterface
(Object obj, Class<T> expected) Converts an object returned by a script to the given Java interface.getAttribute
(String name) Fetches the attribute with the specified name, or null if not found.Invokes a method on the given object, which should be a return value or scripting object.Invokes a root-level method using the method name and args and returns the result.void
setAttribute
(String name, Object value) Sets the attribute with the given name and value.
-
Method Details
-
convertToInterface
Converts an object returned by a script to the given Java interface. The class should be an interface, as although abstract classes are accepted by the Rhino engine, this is not standard behaviour.- Parameters:
obj
- The object to convertexpected
- The expected interface- Returns:
- The converted class
-
getAttribute
Fetches the attribute with the specified name, or null if not found. The returned attribute can be user-stored or a script variable, such as a function. Script objects should be accessed throughinvoke(String, Object...)
- Parameters:
name
- The key of the attribute- Returns:
- The attribute
-
invoke
Invokes a method on the given object, which should be a return value or scripting object.- Parameters:
instance
- The object instance to invoke the method onname
- The name of the methodargs
- The method arguments- Returns:
- The result of the method, if any
- Throws:
NoSuchMethodException
- If no such method was found on the object
-
invoke
Invokes a root-level method using the method name and args and returns the result.- Parameters:
name
- The method nameargs
- The method arguments- Returns:
- The result of the method call, or null if there was none
-
setAttribute
Sets the attribute with the given name and value.
-