### Skript Proxy Example (Function Reference)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies
Demonstrates how to create a proxy instance for the Runnable interface and link its 'run' method to a Skript function named 'do_something'. The example shows calling the proxy directly and via Bukkit's scheduler.
```skript
import:
org.bukkit.Bukkit
ch.njol.skript.Skript
java.lang.Runnable
function do_something():
broadcast "It does something!"
command /proxy:
trigger:
# As you can see on https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html
# the Runnable interface has one method: run
set {_functions::run} to function reference "do_something"
set {_proxy} to new proxy instance of Runnable using {_functions::*}
{_proxy}.run() # will broadcast 'It does something!'
Bukkit.getScheduler().runTask(Skript.getInstance(), {_proxy}) # also broadcasts 'It does something!'
```
--------------------------------
### Skript Proxy Example (Section)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies
Provides an example of creating a proxy instance for the Runnable interface, this time using a Skript section to implement the 'run' method. The section's code is executed when the proxy's 'run' method is invoked.
```skript
import:
org.bukkit.Bukkit
ch.njol.skript.Skript
java.lang.Runnable
command /proxy:
trigger:
# As you can see on https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html
# the Runnable interface has one method: run
create section with {_proxy} stored in {_functions::run}:
broadcast "It does something!"
set {_proxy} to new proxy instance of Runnable using {_functions::*}
{_proxy}.run() # will broadcast 'It does something!'
Bukkit.getScheduler().runTask(Skript.getInstance(), {_proxy}) # also broadcasts 'It does something!'
```
--------------------------------
### Skript Parse Section Example
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/conditions
An example demonstrating the 'parse' section in a Skript condition. It shows how local variables set in 'parse' are available in the 'check' section, illustrating state persistence between sections.
```skript
condition example:
parse:
set {_test} to 1
continue
check:
# {_test} always starts at 1 here
add 1 to {_test}
# 2 is always broadcast
broadcast "%{_test}%"
```
--------------------------------
### Section Creation and Execution Example - Skript Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/sections
An example demonstrating the creation and execution of a section in Skript Reflect. It shows how to define a section with an argument, use a local variable within the section, and then run the section asynchronously, storing and displaying its result.
```skript
set {_i} to 2
create new section with {_x} stored in {_section}:
return {_x} * {_i}
run section {_section} async with 3 and store result in {_result} and wait
broadcast "Result: %{_result}%"
```
--------------------------------
### Skript Reflect: Parse Section Example
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Shows an example of the 'parse' section in Skript Reflect expressions. This section is executed during parsing and can be used for validation. It demonstrates the use of 'continue' upon successful parsing and how local variables are copied by value to other sections.
```skript
expression example:
parse:
set {_test} to 1
continue
get:
# {_test} always starts at 1 here
add 1 to {_test}
# 2 is always returned
return {_test}
```
--------------------------------
### Parse Section Example (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
An example demonstrating the use of the 'parse' section in a custom event. Code within 'parse' is executed when the event is parsed. Local variables created here are copied by-value to other sections. A 'continue' statement is required if the event is parsed successfully.
```skript
event "example":
pattern: example
parse:
set {_test} to 1
continue
check:
# {_test} always starts at 1 here
add 1 to {_test}
# broadcasts 2
broadcast "%{"_test"}%"
continue
```
--------------------------------
### Get Plugin Instance
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns the instance of a specified plugin. The plugin can be identified either by its Java class name or by its name as a string.
```Skript
[(an|the)] instance of [the] plugin %javatype/string%
```
--------------------------------
### Skript Reflect: Return Syntax
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Provides the syntax for the 'return' statement within the 'get' section of Skript Reflect expressions. This is used to specify the value that the expression will provide when its value is read.
```skript
return [%objects%]
```
--------------------------------
### Get Object Member Names
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns a list containing only the names of fields or methods of an object, without details about modifiers or parameters. This is a simpler way to get member identifiers.
```Skript
[the] (field|method) names of %objects%
%objects%'[s] (field|method) names
```
--------------------------------
### Skript Effect Parse Section Example
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/effects
Demonstrates the use of the 'parse' section in a Skript effect to initialize a local variable and ensure it is passed correctly to the 'trigger' section. The 'continue' statement is necessary after successful parsing. This example shows that local variables in 'parse' are copied by value.
```skript
effect example:
parse:
set {_test} to 1
continue
trigger:
# {_test} always starts at 1 here
add 1 to {_test}
# 2 is always broadcast
broadcast "%{_test}%"
```
--------------------------------
### Define a Computed Option in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/computed-options
Defines a computed option in Skript. The 'get' section contains code that is executed upon parsing, and must return a value. Computed options are accessed using the syntax {@}.
```skript
option :
get:
# code, required
```
--------------------------------
### Skript Reflect: Dynamic Type Modifier Example
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Demonstrates the use of the '$' type modifier in Skript Reflect expressions to create dynamic return types. This allows an expression to return a single value or multiple values based on the input provided, enhancing flexibility.
```skript
expression uppercase %$strings%:
# ... (rest of the expression definition)
```
--------------------------------
### Skript Reflect: Loop Alias Example
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Illustrates how to define a 'loop of' alias for non-single Skript Reflect expressions. This alias provides a more specific name for the looped item within the 'loop' block, improving code readability.
```skript
plural expression test points:
loop of: point
on script load:
loop test points:
# You may use "loop-point" instead of "loop-value" here
```
--------------------------------
### Get Java Class Reference
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns a reference to the `java.lang.Class` object for a given Java type. This expression also works with primitive types without needing an explicit import.
```Skript
%javatype%.class
```
--------------------------------
### Skript Reflect: Define Single Pattern Expression
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Defines a custom Skript expression with a single pattern. This allows for specific syntax matching and provides optional sections for return type, loop alias, parsing, getting, adding, setting, removing, deleting, and resetting the expression's value.
```skript
[local] [(plural|non(-|[ ])single))] expression :
return type: # optional
loop of: # optional
usable in:
# events, optional
parse:
# code, optional
get:
# code, optional
add:
# code, optional
set:
# code, optional
remove:
# code, optional
remove all:
# code, optional
delete:
# code, optional
reset:
# code, optional
```
--------------------------------
### Get Raw Object Value
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns the underlying object of an expression. This can be used to access the raw Java object representation. It can also be used to set the value, potentially modifying the input value from the calling trigger.
```Skript
[the] raw %objects%
```
```Skript
import:
ch.njol.skript.lang.Variable
effect put %objects% in %objects%:
parse:
expr-2 is an instance of Variable # to check if the second argument is a variable
continue
trigger:
set raw expr-2 to expr-1
```
--------------------------------
### Skript Reflect: Define Multiple Patterns Expression
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Defines a custom Skript expression that can match multiple patterns. This provides flexibility in how the expression is called and includes optional sections for return type, usable in events, parsing, getting, adding, setting, removing, deleting, and resetting the expression's value.
```skript
[local] [(plural|non(-|[ ])single))] expression:
patterns:
# patterns, one per line
return type: # optional
usable in:
# events, optional
parse:
# code, optional
get:
# code, optional
add:
# code, optional
set:
# code, optional
remove:
# code, optional
remove all:
# code, optional
delete:
# code, optional
reset:
# code, optional
```
--------------------------------
### Skript Reflect: Define Property Expression
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/expressions
Defines a custom Skript property expression, which allows accessing properties of objects. It supports two distinct patterns for accessing properties and includes optional sections for return type, usable in events, parsing, getting, adding, setting, removing, deleting, and resetting the property's value.
```skript
[local] property :
return type: # optional
usable in:
# events, optional
parse:
# code, optional
get:
# code, optional
add:
# code, optional
set:
# code, optional
remove:
# code, optional
remove all:
# code, optional
delete:
# code, optional
reset:
# code, optional
```
--------------------------------
### Create Section Syntax - Skript Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/sections
This snippet shows the syntax for creating a new section in Skript Reflect. Sections can optionally take arguments and are stored in a specified object. The `return` keyword is used to specify the output of the section.
```skript
create [new] section [with [arguments variables] %-objects%] (and store it|stored) in %objects%
```
--------------------------------
### Skript Function Reference Syntax
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies
Illustrates the syntax for creating a function reference in Skript, which can optionally include arguments. This reference can then be used to map a Java method to a Skript function or section. The arguments are passed in a specific order: function reference arguments, the proxy instance, and then method call arguments.
```skript
[the] function(s| [reference[s]]) %strings% [called with [[the] [arg[ument][s]]] %-objects%]
```
--------------------------------
### Calling a Custom Event (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
Shows the syntax for retrieving and calling a custom event instance. You can provide event-values and extra data when calling the event. The 'call' effect is used to execute the event.
```skript
[a] [new] custom event %string% [(with|using) [[event-]values] %-objects%] [[and] [(with|using)] data %-objects%]
call [event] %events%
```
--------------------------------
### Run Section Syntax - Skript Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/sections
This snippet details the syntax for executing a section in Skript Reflect. It supports both synchronous and asynchronous execution, allows passing arguments, and provides a way to store the section's result. Asynchronous sections can optionally wait for completion.
```skript
run section %section% [(1¦sync|2¦async)] [with [arguments] %-objects%] [and store [the] result in %-objects%] [(2¦and wait)]
```
--------------------------------
### Safe Parse Sections for Preloadable Syntax in Skript-Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/experiments
Illustrates the use of 'safe parse' sections in Skript-Reflect, designed for custom syntax that needs to be preloadable. These sections allow code execution during parsing but have limitations, such as disallowing functions, computed options, and certain imports.
```skript
# Example of a safe parse section
syntax "my custom syntax" parsed as "my syntax":
safe parse:
# Code that can be run during parsing but with limitations
```
--------------------------------
### Listen to Multiple Bukkit Events with Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/handling-events
Shows how to use a single handler for multiple Bukkit events, like ProjectileLaunchEvent and ProjectileHitEvent. Ensure careful handling when accessing methods that might not be present in all listed events.
```skript
import:
org.bukkit.event.entity.ProjectileLaunchEvent
org.bukkit.event.entity.ProjectileHitEvent
on ProjectileLaunchEvent and ProjectileHitEvent:
# your code
```
--------------------------------
### Listen to Single Bukkit Event with Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/handling-events
Demonstrates how to import and listen for a specific Bukkit event, such as EnderDragonChangePhaseEvent. This requires the event to extend org.bukkit.event.Event and be processed by Bukkit's event executor.
```skript
import:
org.bukkit.event.entity.EnderDragonChangePhaseEvent
on EnderDragonChangePhaseEvent:
# your code
```
--------------------------------
### Enable Experimental Features in Skript-Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/experiments
This code block enables experimental features in Skript-Reflect. It requires explicit consent and understanding of potential future changes. Add this section to your Skript configuration.
```skript
skript-reflect, I know what I'm doing:
I understand that the following features are experimental and may change in the future.
I have read about this at https://tpgamesnl.gitbook.io/skript-reflect/advanced/experiments
```
--------------------------------
### Skript Proxy Syntax
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies
Defines the syntax for creating a new proxy instance of a Java interface in Skript. It requires a list of imported interfaces and an indexed list variable mapping method names to Skript functions or sections. The arguments passed to the proxy method are handled according to specific rules.
```skript
[a] [new] proxy [instance] of %javatypes% (using|from) %objects%
```
--------------------------------
### Deferred Parsing Syntax in Skript-Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/experiments
Demonstrates the deferred parsing syntax '(parse[d] later)' for Skript-Reflect. This feature defers the parsing of a line until its first execution, useful for circumventing issues with custom syntax order. It is recommended only for mutually referencing custom syntaxes.
```skript
# Example usage of deferred parsing
(parse later) send "This will be parsed on execution."
```
--------------------------------
### Create Java Objects (Constructors) in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Allows creating new Java objects using their constructors within Skript. The syntax involves `new javatype(arguments)`. Requires Skript and Skript-Reflect.
```skript
[a] new %javatype%(%objects%)
```
```skript
new Location(player's world, 0, 0, 0)
```
--------------------------------
### Dynamic NMS Imports with Computed Options in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/computed-options
Demonstrates using computed options to dynamically generate NMS package paths for cross-version compatibility. The 'nms' option calculates the server version and returns the correct package path, which is then used for importing NMS classes.
```skript
import:
org.bukkit.Bukkit
option nms:
get:
set {_nms version} to Bukkit.getServer().getClass().getPackage().getName().split(".")[3]
return "net.minecraft.server.%{_nms version}%"
import:
{@nms}.MinecraftServer
{@nms}.Item
```
--------------------------------
### Skript Custom Syntax: Expression Utility
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
A Skript utility for creating custom expressions, allowing for dynamic retrieval and manipulation of data. It supports setting values when used with raw expressions, enabling data storage in calling triggers. Requires Skript 2.6.1+ for advanced features.
```skript
[the] expr[ession][s](-| )%number%
```
```skript
import:
ch.njol.skript.lang.Variable
effect put %objects% in %objects%:
parse:
expr-2 is an instance of Variable # to check if the second argument is a variable
continue
trigger:
set raw expr-2 to expr-1
```
--------------------------------
### Skript Custom Syntax: Event Classes
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
Represents a utility for defining custom event classes within Skript using skript-reflect. No specific inputs or outputs are detailed, but it's a fundamental building block for custom event handling.
```skript
event-classes
```
--------------------------------
### Skript Custom Syntax: Parse Tags
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
Enables the use of sets of strings as parse tags within Skript syntax, providing a more advanced way to handle tagged data compared to single integers. Requires Skript 2.6.1 or later.
```skript
[the] parse[r] tags
```
--------------------------------
### Skript Custom Syntax: Parser Mark
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
A utility for marking specific points or elements within the Skript parser. This aids in more complex syntax analysis and manipulation.
```skript
[the] [parse[r]] mark
```
--------------------------------
### Skript Custom Syntax: Matched Pattern
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
Utility for defining and referencing matched patterns within Skript syntax. This allows for flexible pattern recognition in custom syntax definitions.
```skript
[the] [matched] pattern
```
--------------------------------
### Call Java Methods in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Allows invoking Java methods on objects within Skript. Methods can be used as effects, expressions, or conditions. Conditions pass if the return value is not false, null, or 0. Dependencies include Skript and Skript-Reflect.
```skript
%object%.(%objects%)
```
```skript
event-block.breakNaturally()
(last spawned creeper).setPowered(true)
player.giveExpLevels({_levels})
```
--------------------------------
### Skript Condition with Multiple Patterns
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/conditions
Defines a custom Skript condition that supports multiple patterns. It includes 'usable in' for context, 'patterns' for defining multiple patterns, 'parse' for optional initialization code, and 'check' for the core condition logic.
```skript
[local] condition:
usable in:
# events, optional
patterns:
# patterns, one per line
parse:
# code, optional
check:
# code, required
```
--------------------------------
### Create Java Array
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Creates a new array of a specified Java type and size. Primitive types can be used directly without requiring an import. The syntax uses literal brackets for array size.
```Skript
new %javatype%[%integer%]
```
--------------------------------
### Parse-time Class Import (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Imports a Java class at parse-time using skript-reflect's import block. This makes the class accessible by its simple name within the script. Place import blocks at the root of the script before the class is referenced.
```skript
import:
java.lang.System
command /example:
trigger:
message "%System%" # java.lang.System
System.out.println("test")
```
--------------------------------
### Skript Custom Syntax: Continue Keyword
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
The 'continue' keyword in Skript is used to proceed with the execution flow, often within loops or conditional blocks. Its specific usage in custom syntax is context-dependent.
```skript
continue
```
--------------------------------
### Runtime Class Import from Object (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Imports the Java class of a given object at runtime. This expression retrieves the class of an object, such as a player, and can be stored in a variable. It's useful for dynamic class referencing.
```skript
command /example:
executable by: players
trigger:
set {Player} to player's class
message "%{Player}%" # org.bukkit.entity.Player
```
--------------------------------
### Skript Property Condition
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/conditions
Defines a custom Skript condition for properties, specifying the skript type and pattern. It includes 'usable in' to define valid contexts, 'parse' for optional pre-execution code, and 'check' for the condition's success criteria.
```skript
[local] property condition :
usable in:
# events, optional
parse:
# code, optional
check:
# code, required
```
--------------------------------
### Set Event Priority Level in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/handling-events
Illustrates how to set a priority level for an event handler using keywords like 'highest'. This controls the execution order relative to other handlers. Available priorities include lowest, low, normal, high, highest, and monitor.
```skript
import:
org.bukkit.event.entity.EnderDragonChangePhaseEvent
on EnderDragonChangePhaseEvent with priority highest:
# your code
```
--------------------------------
### Handle Cancelled Events in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/handling-events
Demonstrates how to ensure an event handler is called even if the event has been cancelled by a lower priority handler, by using the 'all' keyword. The 'uncancel event' command can be used within the handler.
```skript
import:
org.bukkit.event.block.BlockBreakEvent
on all BlockBreakEvent:
uncancel event
```
--------------------------------
### Define Custom Event with One Pattern (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
Defines a custom event with a single pattern. The 'pattern' is required, while 'event-values', 'parse', and 'check' are optional. The 'parse' section runs during event parsing, and 'check' runs before the event is called. Local events are only usable within their defining script.
```skript
[local] [custom] event %string%:
pattern: # pattern, required
event-values: # list of types, optional
parse:
# code, optional
check:
# code, optional
```
--------------------------------
### Introspect Object Members (Fields, Methods, Constructors)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns a list of fields, methods, or constructors of an object, including their modifiers and parameters. This is useful for examining the structure of Java objects.
```Skript
[the] (fields|methods|constructors) of %objects%
%objects%'[s] (fields|methods|constructors)
```
--------------------------------
### Call Overloaded Java Methods in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Provides a way to explicitly call a specific overloaded Java method by appending the argument types in brackets after the method name. Skript-Reflect usually infers the correct method, but this allows for manual selection. Requires Skript and Skript-Reflect.
```skript
System.out.println[Object]({_something})
Math.max[int, int](0, {_value})
```
--------------------------------
### Access Java Fields in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Allows reading the value of Java fields on objects within Skript. The syntax is `object.field_descriptor`. Requires Skript and Skript-Reflect.
```skript
%object%.
```
--------------------------------
### Import Effect for Effect Commands (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Allows importing Java classes within effect commands, where standard import blocks are not permitted. This import is temporary and only lasts until the server stops.
```skript
effect /my_effect:
trigger:
import org.bukkit.entity.Player as PlayerAlias
message PlayerAlias.getOnlinePlayers()
```
--------------------------------
### Define Custom Event with Multiple Patterns (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
Defines a custom event that can be triggered by multiple patterns. The 'patterns' field requires one pattern per line. Optional fields include 'event-values', 'parse', and 'check', similar to single-pattern events.
```skript
[local] [custom] event %string%:
patterns:
# patterns, one per line, required
event-values: # list of types, optional
parse:
# code, optional
check:
# code, optional
```
--------------------------------
### Access Event Data with 'event' Expression in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/handling-events
Explains how to use the skript-reflect 'event' expression to access and modify event data using reflection. This allows interaction with event methods like getNewPhase() and setNewPhase().
```skript
import:
org.bukkit.event.entity.EnderDragonChangePhaseEvent
org.bukkit.entity.EnderDragon$Phase as EnderDragonPhase
on EnderDragonChangePhaseEvent:
if event.getNewPhase() is EnderDragonPhase.CIRCLING:
event.setNewPhase(EnderDragonPhase.CHARGE_PLAYER)
```
--------------------------------
### Runtime Class Import from Fully Qualified Name (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Imports a Java class at runtime using its fully qualified name. This method is used when the class cannot be determined at parse-time. The imported class is stored in a variable for later use.
```skript
on script load:
set {Player} to the class "org.bukkit.entity.Player"
message "%{Player}%" # org.bukkit.entity.Player
```
--------------------------------
### Group skript-Reflect Call Targets
Source: https://tpgamesnl.gitbook.io/skript-reflect/code-conventions
When calling a method or accessing a field using skript-reflect, keep the target expression grouped to enhance clarity. Avoid unnecessary spaces unless the expression itself requires them, in which case, use parentheses. Complex expressions should be extracted into variables.
```skript
event.getPlayer()
```
```skript
(spawned creeper).isPowered()
```
```skript
{my script::%player%::pet}.isDead()
```
--------------------------------
### Skript Custom Syntax: Parser Regular Expression
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax
A utility for incorporating regular expressions into Skript syntax parsing, identified by a number. This allows for powerful pattern matching in custom syntax.
```skript
[the] [parse[r]] (regex|regular expression)(-| )%number%
```
--------------------------------
### Call Non-Public Java Methods in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Enables calling non-public Java methods by specifying the declaring class in brackets before the method name. This is necessary when a method exists in multiple superclasses. Requires Skript and Skript-Reflect.
```skript
{_arraylist}.[ArrayList]fastRemove(1)
```
--------------------------------
### Manipulate Bits of a Number
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Represents a subset of bits from a number, allowing for reading and writing specific bit ranges or individual bits. This syntax supports various ways to specify the bit range.
```Skript
[the] (bit %number%|bit(s| range) [from] %number%( to |[ ]-[ ])%number%) of %numbers%
%numbers%'[s] (bit %number%|1¦bit(s| range) [from] %number%( to |[ ]-[ ])%number%)
```
--------------------------------
### Represent Null Value
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Represents the `null` value in Java. It's important to note that this is distinct from Skript's ``.
```Skript
null
```
--------------------------------
### Collect Objects into Array
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Creates a new array containing the specified objects. An optional Java type can be provided to determine the component type of the resulting array. The syntax uses literal brackets.
```Skript
[%objects%]
[%objects% as %javatype%]
```
--------------------------------
### Skript Condition with One Pattern
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/conditions
Defines a custom Skript condition that utilizes a single pattern. The 'usable in' section specifies where the condition can be used, 'parse' is for optional parsing code, and 'check' is required for the condition's logic.
```skript
[local] condition :
usable in:
# events, optional
parse:
# code, optional
check:
# code, required
```
--------------------------------
### Import Nested Class with Alias (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Imports a nested Java class using an alias to handle potentially common or ambiguous simple names. Nested classes are denoted with a '$' instead of a '.' in their fully qualified name.
```skript
import:
org.bukkit.entity.EnderDragon$Phase as EnderDragonPhase
command /test:
trigger:
message "Imported EnderDragonPhase: %EnderDragonPhase%"
```
--------------------------------
### Access Nested Class via Enclosing Class (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Accesses a nested Java class member by first importing its enclosing class. This approach avoids aliasing the nested class directly and uses dot notation to access nested static members.
```skript
import:
org.bukkit.entity.EnderDragon
on load:
set {phase} to EnderDragon.Phase.LEAVE_PORTAL
message "EnderDragon Phase: %{phase}%"
```
--------------------------------
### Spread Array Contents
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Returns the contents of a single array, iterable, iterator, or stream. This is useful for expanding collections into individual elements.
```Skript
...%object%
```
--------------------------------
### Define Skript Effect with Multiple Patterns
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/effects
Defines a Skript effect that can handle multiple distinct patterns. Each pattern is listed under the 'patterns' key. The 'usable in' and 'parse' sections are optional, with 'trigger' being mandatory for the effect's core logic. The 'parse' section allows for initial validation.
```skript
[local] effect:
usable in:
# events, optional
patterns:
# patterns, one per line
parse:
# code, optional
trigger:
# code, required
```
--------------------------------
### Define Skript Effect with One Pattern
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/effects
Defines a Skript effect that accepts a single pattern. The 'usable in' and 'parse' sections are optional, while the 'trigger' section is required for the effect's execution logic. The 'parse' section can be used for pre-execution checks.
```skript
[local] effect :
usable in:
# events, optional
parse:
# code, optional
trigger:
# code, required
```
--------------------------------
### Access Non-Public Java Fields in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/running-java-code
Enables accessing non-public Java fields by specifying the declaring class in brackets before the field name. This is useful when a field with the same name exists in different superclasses. Requires Skript and Skript-Reflect.
```skript
{_hashmap}.[HashMap]modCount
```
--------------------------------
### Parse-time Class Import with Alias (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/importing-classes
Imports a Java class at parse-time using an alias to resolve naming conflicts. This is useful when a class's simple name clashes with existing Skript expressions or other imported classes. Aliases must be valid Java identifiers.
```skript
import:
java.lang.String as JavaString
command /example:
trigger:
message JavaString.format("Hello %%s", sender)
```
--------------------------------
### Access Array Element by Index
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Represents the value at a specific index within an array. This expression allows both reading from and writing to the array element.
```Skript
%array%[%integer%]
```
--------------------------------
### Accessing Extra Data in Custom Event (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
Demonstrates how to access 'extra data' provided when calling a custom event. The 'data' expression is used within the event to retrieve values based on their string index.
```skript
[extra] [event(-| )]data %string%
```
--------------------------------
### Separate Complex Skript Expressions from skript-Reflect Calls
Source: https://tpgamesnl.gitbook.io/skript-reflect/code-conventions
To improve code readability, separate complex Skript expressions from skript-reflect calls by using intermediate variables. This prevents clutter and makes the code easier to understand. The input is a Skript expression, and the output is a more organized Skript code block.
```skript
set {_target} to the player's targeted block
{_target}.breakNaturally()
```
--------------------------------
### Check Event Cancellation Status (Skript)
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/custom-syntax/events
Provides the conditions to check if a custom event has been cancelled after being called. This allows for conditional logic based on whether the event was allowed to proceed.
```skript
%events% (is|are) cancelled
%events% (isn't|is not|aren't|are not) cancelled
```
--------------------------------
### Suppress Java Call Errors in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/error-handling
Use the 'try' keyword before a Java call to prevent errors from being logged to the console. The error object is still accessible programmatically if needed. This is useful for gracefully handling potential issues in Java method invocations within Skript.
```skript
set {_second item in list} to try {_list}.get(1)
try {_connection}.setUseCaches(true)
```
--------------------------------
### Avoid Unnecessary Java Reflection in skript-Reflect
Source: https://tpgamesnl.gitbook.io/skript-reflect/code-conventions
skript-reflect provides direct access to private members by default, making explicit Java reflection for accessing private methods, fields, or constructors generally unnecessary. This simplifies the code and leverages skript-reflect's built-in capabilities.
```skript
set {_mod count} to {_map}.modCount
```
--------------------------------
### Avoid Aesthetic Class Aliasing in Imports
Source: https://tpgamesnl.gitbook.io/skript-reflect/code-conventions
Import aliases in skript-reflect should primarily be used to resolve naming conflicts, not for aesthetic purposes to mimic Skript events. This ensures clarity and adheres to standard import practices.
```skript
import:
org.bukkit.event.player.PlayerMoveEvent
on PlayerMoveEvent:
# code
```
--------------------------------
### Check if Object is Instance of Java Type
Source: https://tpgamesnl.gitbook.io/skript-reflect/basics/utilities
Checks whether one or more objects are instances of the specified Java types. This supports both positive and negative checks (is/is not).
```Skript
%objects% (is|are) [a[n]] instance[s] of %javatypes%
%objects% (is not|isn't|are not|aren't) [a[n]] instance[s] of %javatypes%
```
--------------------------------
### Access Last Java Call Error Object in Skript
Source: https://tpgamesnl.gitbook.io/skript-reflect/advanced/error-handling
Retrieve the last error object thrown by a Java call using the '[last] [java] (throwable|exception|error)' syntax. This allows for custom error handling, such as logging or alternative task execution. The error might be a 'com.btk5h.skriptmirror.JavaCallException' if method resolution or output conversion failed.
```skript
[the] [last] [java] (throwable|exception|error)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.