You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dependencies.md
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,38 @@ order: 97
4
4
---
5
5
6
6
# Dependencies
7
-
TO-DO
7
+
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.
8
+
9
+
!!! warning EXPERIMENTAL
10
+
Current implementation, despite being relatively simple and fully functional, is still marked as experimental.
11
+
We may introuduce breaking changes to the way dependencies are declared and exposed to scripts.
12
+
!!!
13
+
14
+
<br />
15
+
16
+
<!--
17
+
## Declaring Dependencies
18
+
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/)**.
**Why is that important?** Declaring dependency will ensure that script will not be loaded if **PlaceholderAPI** plugin is missing.
27
+
-->
28
+
29
+
## Using Dependencies
30
+
Importing any class that belongs to an installed plugin should work out of the box. In this example we will use **[PlaceholderAPI](https://www.spigotmc.org/resources/placeholderapi.19978/)**, a plugin you should be already familiar with.
31
+
32
+
Assuming the plugin is **installed** and **enabled** on the server, we should be able to call its API like any other function.
local self = setmetatable({}, {__index = Counter})
22
22
self.count = 0
23
23
return self
24
24
end
@@ -37,8 +37,6 @@ end
37
37
function Counter:get()
38
38
return self.count
39
39
end
40
-
41
-
returnCounter
42
40
```
43
41
==-
44
42
@@ -51,7 +49,7 @@ local Counter = require("example_library")
51
49
52
50
script:onLoad(function()
53
51
-- Creating a new instance of the Counter class.
54
-
localcounter=Counter()
52
+
local counter = Counter:new()
55
53
-- Incrementing the counter three times.
56
54
counter:increment()
57
55
counter:increment()
@@ -63,6 +61,8 @@ end)
63
61
64
62
<br />
65
63
64
+
-->
65
+
66
66
## Java Libraries
67
67
External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink/libraries.json` file. Dependencies will be downloaded and exposed to the scripting runtime after server restart.
68
68
@@ -72,7 +72,7 @@ External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink
72
72
// Repositories to be used for dependency resolution.
In this example, we are adding stefvanschie's [IF](https://github.com/stefvanschie/IF) library of version `0.10.11` from [Maven Central](https://repo.maven.apache.org/maven2/) repository. You can also see how and authenticate with a private repository using credentials, which might be essential when working with closed-source projects or [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry).
91
+
In this example, we are adding **[PaperLib](https://github.com/PaperMC/PaperLub)** library of version **1.0.7** from **[PaperMC](https://repo.papermc.io/repository/maven-public/)** repository. You can also see how and authenticate with a private repository using credentials, which might be essential when working with closed-source projects or **[GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry)**.
92
92
93
93
After restarting the server, we should be able to import and access any class that belongs to specified library(-ies).
script.logger:info("Is the server running Paper? " .. (PaperLib:isPaper() and"YES" or"NO") .."!")
99
+
```
100
+
```log Console Output
101
+
[00:00:00 INFO]: [LuaLink/example_script] Is the server running Paper? YES!
102
+
```
103
+
While this example may not be the best use of **PaperLib** - especially because **LuaLink** requires you to run the plugin on **Paper** - it is still a good example of how to use external libraries in your scripts.
0 commit comments