|
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
6 | | - <meta name="turbo-cache-control" content="no-cache" data-turbo-track="reload" data-track-token="3.7.0.797870837668"> |
| 6 | + <meta name="turbo-cache-control" content="no-cache" data-turbo-track="reload" data-track-token="3.7.0.797879387426"> |
7 | 7 |
|
8 | 8 | <!-- See retype.com --> |
9 | 9 | <meta name="generator" content="Retype 3.7.0"> |
|
31 | 31 | <script data-cfasync="false">(function () { var el = document.documentElement, m = localStorage.getItem("doc_theme"), wm = window.matchMedia; if (m === "dark" || (!m && wm && wm("(prefers-color-scheme: dark)").matches)) { el.classList.add("dark") } else { el.classList.remove("dark") } })();</script> |
32 | 32 |
|
33 | 33 | <link href="../assets/favicon.png" rel="icon"> |
34 | | - <link href="../resources/css/retype.css?v=3.7.0.797870837668" rel="stylesheet"> |
| 34 | + <link href="../resources/css/retype.css?v=3.7.0.797879387426" rel="stylesheet"> |
35 | 35 |
|
36 | | - <script data-cfasync="false" src="../resources/js/config.js?v=3.7.0.797870837668" data-turbo-eval="false" defer></script> |
| 36 | + <script data-cfasync="false" src="../resources/js/config.js?v=3.7.0.797879387426" data-turbo-eval="false" defer></script> |
37 | 37 | <script data-cfasync="false" src="../resources/js/retype.js?v=3.7.0" data-turbo-eval="false" defer></script> |
38 | | - <script id="lunr-js" data-cfasync="false" src="../resources/js/lunr.js?v=3.7.0.797870837668" data-turbo-eval="false" defer></script> |
39 | | - <script id="prism-js" data-cfasync="false" src="../resources/js/prism.js?v=3.7.0.797870837668" defer></script> |
| 38 | + <script id="lunr-js" data-cfasync="false" src="../resources/js/lunr.js?v=3.7.0.797879387426" data-turbo-eval="false" defer></script> |
| 39 | + <script id="prism-js" data-cfasync="false" src="../resources/js/prism.js?v=3.7.0.797879387426" defer></script> |
40 | 40 |
|
41 | 41 | <style> |
42 | 42 |
|
@@ -250,56 +250,42 @@ <h1> |
250 | 250 | </h1> |
251 | 251 | </doc-anchor-target> |
252 | 252 | <p>LuaLink provides a way to access and use plugins' APIs in your scripts. This feature is very powerful and makes it easy to integrate scripts with other plugins. It must be noted this has not been thoroughly tested yet and some issues may arise. Please be cautious when using this feature.</p> |
253 | | -<div class="flex mb-6"> |
254 | | - <div class="shrink-0 w-1 rounded-tl rounded-bl bg-yellow-500"></div> |
255 | | - <div class="flex w-full py-4 border border-l-0 border-gray-300 rounded-tr rounded-br doc-alert bg-white dark:bg-dark-700 dark:border-dark-700" role="alert"> |
256 | | - <div class="flex items-center ml-4 h-7"> |
257 | | - <svg xmlns="http://www.w3.org/2000/svg" class="mb-px text-yellow-500" width="22" height="22" viewBox="0 0 24 24" role="presentation"> |
258 | | - <g fill="currentColor"><g> |
259 | | - <path d="M22.48 15.59L14.01 1.45A2.968 2.968 0 0012.16.09c-.78-.19-1.58-.07-2.27.35-.41.25-.76.6-1.01 1.01v.01L.4 15.6c-.83 1.43-.33 3.27 1.1 4.1.45.26.95.4 1.48.4h16.95c.8-.01 1.55-.33 2.11-.9.56-.57.87-1.33.86-2.13a3.04 3.04 0 00-.42-1.48zm-1.87 2.21c-.19.19-.44.3-.69.3H2.99c-.17 0-.34-.05-.49-.13a.992.992 0 01-.37-1.35L10.6 2.48c.08-.14.2-.25.34-.33a.992.992 0 011.37.33l8.46 14.13c.09.15.13.32.13.49 0 .26-.1.51-.29.7z"></path> |
260 | | - <path d="M11.45 12.1c.55 0 1-.45 1-1v-4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .56.45 1 1 1zM11.46 14.1c-.56 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1z"></path> |
261 | | - </g></g> |
262 | | - </svg> |
263 | | - </div> |
264 | | - <div class="pr-5 ml-3 w-full"> |
265 | | - <h5>EXPERIMENTAL</h5> |
266 | | -<p>Current implementation, despite being relatively simple and fully functional, is still marked as experimental. |
267 | | -We may introuduce breaking changes to the way dependencies are declared and exposed to scripts.</p> |
268 | | - </div> |
269 | | - </div> |
270 | | -</div> |
271 | 253 | <br /> |
272 | | -<!-- |
273 | | -## Declaring Dependencies |
274 | | -To declare a dependency, you must create an `init.lua` file in your script's folder. In this example we will use **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.19978/)**. |
275 | | -
|
276 | | -```lua /plugins/LuaLink/scripts/example_script/init.lua |
277 | | -depends { |
278 | | - "PlaceholderAPI" |
279 | | -} |
280 | | -``` |
281 | | -
|
282 | | -**Why is that important?** Declaring dependency will ensure that script will not be loaded if **PlaceholderAPI** plugin is missing. |
283 | | ---> |
284 | | -<doc-anchor-target id="using-dependencies"> |
285 | | - <h2> |
286 | | - <doc-anchor-trigger class="header-anchor-trigger" to="#using-dependencies">#</doc-anchor-trigger> |
287 | | - <span>Using Dependencies</span> |
288 | | - </h2> |
| 254 | +<doc-anchor-target id="declaring-dependencies"> |
| 255 | + <h3> |
| 256 | + <doc-anchor-trigger class="header-anchor-trigger" to="#declaring-dependencies">#</doc-anchor-trigger> |
| 257 | + <span>Declaring Dependencies</span> |
| 258 | + </h3> |
| 259 | +</doc-anchor-target> |
| 260 | +<p>Before we can start using any external API, we must declare a dependency. This ensures that script will <strong>not be loaded</strong> if dependency plugin is missing. To declare dependencies, you must create <code v-pre>init.lua</code> file in your script's folder.</p> |
| 261 | +<div class="codeblock-wrapper"><doc-codeblock> |
| 262 | +<div class="codeblock-title">/plugins/LuaLink/scripts/example_script/init.lua</div> |
| 263 | +<pre class="language-lua"><code v-pre class="language-lua">return { |
| 264 | + dependencies = { |
| 265 | + "PlaceholderAPI" |
| 266 | + } |
| 267 | +}</code></pre> |
| 268 | +</doc-codeblock></div> |
| 269 | +<p>In this example we will use <strong><a href="https://www.spigotmc.org/resources/placeholderapi.19978/">PlaceholderAPI</a></strong> - a plugin you should already be familiar with.</p> |
| 270 | +<br /> |
| 271 | +<doc-anchor-target id="accessing-dependencies"> |
| 272 | + <h3> |
| 273 | + <doc-anchor-trigger class="header-anchor-trigger" to="#accessing-dependencies">#</doc-anchor-trigger> |
| 274 | + <span>Accessing Dependencies</span> |
| 275 | + </h3> |
289 | 276 | </doc-anchor-target> |
290 | | -<p>Importing any class that belongs to an installed plugin should work out of the box. In this example we will use <strong><a href="https://www.spigotmc.org/resources/placeholderapi.19978/">PlaceholderAPI</a></strong>, a plugin you should be already familiar with.</p> |
291 | | -<p>Assuming the plugin is <strong>installed</strong> and <strong>enabled</strong> on the server, we should be able to call its API like any other function.</p> |
| 277 | +<p>Next, assuming the plugin is <strong>installed</strong> and <strong>enabled</strong> on the server, any import and call to its API should work as expected.</p> |
292 | 278 | <div class="codeblock-wrapper"><doc-codeblock> |
293 | 279 | <div class="codeblock-title">/plugins/LuaLink/scripts/example_script/main.lua</div> |
294 | 280 | <pre class="language-lua"><code v-pre class="language-lua">local PlaceholderAPI = import("me.clip.placeholderapi.PlaceholderAPI") |
295 | 281 |
|
| 282 | +-- NOTE: Placeholders in this example come from the Server expansion which is not installed by default. |
296 | 283 | script.logger:info(PlaceholderAPI:setPlaceholders(nil, "Server is running %server_variant% %server_version_full%"))</code></pre> |
297 | 284 | </doc-codeblock></div> |
298 | 285 | <div class="codeblock-wrapper"><doc-codeblock> |
299 | 286 | <div class="codeblock-title">Console Output</div> |
300 | 287 | <pre class="language-log"><code v-pre class="language-log">[00:00:00 INFO]: [LuaLink/example_script] Server is running Paper 1.21.4-224</code></pre> |
301 | 288 | </doc-codeblock></div> |
302 | | -<p>That's it. As mentioned earlier, current implementation is really simple and should just work.</p> |
303 | 289 |
|
304 | 290 |
|
305 | 291 | <!-- Required only on API pages --> |
|
0 commit comments