# Proxies

{% tabs %}
{% tab title="Syntax" %}

```
[a] [new] proxy [instance] of %javatypes% (using|from) %objects%
```

{% endtab %}
{% endtabs %}

The first argument (`%javatypes%`) is a list of imported interfaces (whether a class is an interface can be found on the javadoc).

The second argument is an indexed list variable, with each element in the form `{list::%method name%} = %function/section%`. `%method name%` is the name of one of the methods from one of the interfaces. `%function/section%` is either a function reference or a [section](https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/sections).

Function wrappers can be created with the following syntax.

{% tabs %}
{% tab title="Function reference syntax" %}

```
[the] function(s| [reference[s]]) %strings% [called with [[the] [arg[ument][s]]] %-objects%]
```

{% endtab %}
{% endtabs %}

The first argument (`%strings%`) is the name of the function you want to reference. This is enough for the function reference to be completed, but you can also add some argument values.

When a method from the proxy is ran, it is passed on to the function/section corresponding to the method name. The arguments are defined in the following way: 1. The argument values specified in the function reference (if there are any) (only if this method doesn't redirect to a section) 2. The proxy instance object itself. 3. The argument values from the method call.

Here's an example to help you understand it:

{% tabs %}
{% tab title="Function reference example" %}

```
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!'
```

{% endtab %}

{% tab title="Section example" %}

```
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!'
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Class proxies are most useful for more interaction with Java code, for example when methods require some implementation of an interface.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
