Proxy
Usage: proxy [<interfaces>|...] [using:<map>] [as:<name>]
proxy [<interfaces>|...] [using:<map>] [as:<name>]
Creates a dynamic proxy object that implements one or more interfaces and delegates method calls to a provided map. If the proxy method produces a result, it will be returned to the corresponding Task or Section.
Example of a proxy using sections
ProxySectionExample:
type: task
debug: false
script:
# As you can see on https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html
# the Runnable interface has one method: run
- section as:functions.run:
- narrate Action
- proxy java.lang.Runnable using:<[functions]> as:proxy
# will broadcast ”Action” to the console
- invoke <[proxy]>.run()
# will also pass ”Action” to the console, but synchronously
- invoke 'org.bukkit.Bukkit.getScheduler().runTask(<plugin[Denizen]>, <[proxy]>)'
Example of using a proxy with tasks
ProxyTaskExample:
type: task
debug: false
script:
# As you can see on https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html
# the Runnable interface has one method: run
- definemap functions:
run: ProxyTask
- proxy java.lang.Runnable using:<[functions]> as:proxy
# will broadcast ”Action” to the console
- invoke <[proxy]>.run()
# will also pass ”Action” to the console, but synchronously
- invoke 'org.bukkit.Bukkit.getScheduler().runTask(<plugin[Denizen]>, <[proxy]>)'
ProxyTask:
type: task
debug: false
script:
- narrate Action
Example of using a proxy with JDA (Task)
JDA_Register:
type: task
debug: false
definitions: JDA
script:
- definemap functions:
onEvent: JDA_EventProxyListener
- proxy net.dv8tion.jda.api.hooks.EventListener using:<[functions]> as:proxy
- invoke <[JDA]>.getEventManager().register(<[proxy]>)
JDA_EventProxyListener:
type: task
debug: false
definitions: event
script:
- if <[event].interpret> == MessageReceivedEvent:
- invoke <[event]>.getMessage().delete().queue()
Example of using a proxy with JDA (Section)
JDA_Register:
type: task
debug: false
definitions: JDA
script:
- section as:section def:functions.onEvent:
- if <[event].interpret> == MessageReceivedEvent:
- invoke <[event]>.getMessage().delete().queue()
- proxy net.dv8tion.jda.api.hooks.EventListener using:<[functions]> as:proxy
- invoke <[JDA]>.getEventManager().register(<[proxy]>)
Last updated