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
|[3. Importing and Requiring](#importing-and-requiring)|
25
25
|[4. Constructors and Instances](#constructors-and-instances)|
26
26
|[5. Commands](#commands)|
27
27
|[6. Events](#events)|
@@ -31,12 +31,12 @@ Basic **Lua** knowledge is an obvious prerequisite, but it should be relatively
31
31
32
32
### Creating Scripts
33
33
There are a couple of things to keep in mind when using LuaLink.
34
-
- Each script is stored in a separate folder inside the `plugins/LuaLink/scripts` directory, and libraries are stored in the `plugins/LuaLink/libs` directory.
35
-
<sup>More about libraries can be found on the **[Libraries](libraries.md)** page.</sup>
36
-
- Entry point of the script (or library) is a file named `main.lua` or `init.lua`.
37
-
<sup>It doesn't matter which file you choose as the entry point, but you should be consistent with your naming convention.</sup>
38
34
- Script life-cycle can be managed using `/lualink load`, `/lualink unload` and `/lualink reload` commands.
39
35
<sup>More on this can be found on the **[Commands](commands.md)** page.</sup>
36
+
- Each script is stored in a separate folder inside the `plugins/LuaLink/scripts` directory, and libraries are stored in the `plugins/LuaLink/libs` directory.
37
+
<sup>More about libraries can be found on the **[Libraries](libraries.md)** page.</sup>
38
+
- Entry point of the script (or library) is a file named `main.lua`.
39
+
<sup>More files can be created and loaded using the `require` keyword.</sup>
40
40
41
41
<br />
42
42
@@ -45,12 +45,12 @@ Scripts are automatically loaded after server has been fully started. They can a
45
45
```lua
46
46
-- Called after the script has been successfully loaded.
47
47
script:onLoad(function()
48
-
script:logger:info("Script has been loaded.")
48
+
script.logger:info("Script has been loaded.")
49
49
end)
50
50
51
51
-- Called before the script is attempted to be unloaded.
52
52
script:onUnload(function()
53
-
script:logger:info("Script is about to be unloaded.")
53
+
script.logger:info("Script is about to be unloaded.")
54
54
end)
55
55
```
56
56
@@ -81,17 +81,18 @@ script:onLoad(function()
81
81
counter:increment()
82
82
counter:increment()
83
83
-- Printing current value of the counter to the console.
84
-
script.logger.info(counter:get() ..
84
+
script.logger:info(counter:get() .." is the current value of the counter.")
85
+
end)
85
86
```
86
87
87
88
<br />
88
89
89
90
### Constructors and Instances
90
91
New instances of Java classes can be created as follows.
Copy file name to clipboardExpand all lines: index.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,9 @@ This documentation page is still a work in progress and may contain outdated inf
8
8
!!!
9
9
10
10
# LuaLink v2
11
-
LuaLink is an experimental plugin that provides a basic Lua scripting runtime for Paper-based Minecraft servers. It is designed for small and simple tasks and serves as an alternative to Skript and other scripting plugins.
11
+
**LuaLink** is an experimental plugin that provides a basic Lua scripting runtime for **Paper-based** Minecraft servers. It is designed for small and simple tasks and serves as a much more powerful alternative to **Skript** and other scripting plugins.
12
12
13
-
Scripting runtime is based on [LuaJava](https://github.com/gudzpoz/luajava) with [LuaJIT](https://github.com/LuaJIT/LuaJIT). For more details on implementation specifics or differences, please refer to their respective documentation.
13
+
Scripting runtime is based on **[LuaJava](https://github.com/gudzpoz/luajava)** with **[LuaJIT](https://github.com/LuaJIT/LuaJIT)**. For more details on implementation specifics or differences, please refer to their respective documentation.
14
14
15
15
<br />
16
16
@@ -41,26 +41,26 @@ Plugin can be downloaded from following sources:
41
41
## Quick Start
42
42
After you have installed the plugin, you can start writing your first script.
43
43
44
-
- Each script is stored in a separate folder inside the `plugins/LuaLink/scripts` directory.
45
-
- Entry point of the script is a file named `main.lua` or `init.lua`.
46
44
- Script life-cycle can be managed using `/lualink load`, `/lualink unload` and `/lualink reload` commands.
45
+
- Each script is stored in a separate folder inside the `plugins/LuaLink/scripts` directory.
46
+
- Entry point of the script is a file named `main.lua`.
47
47
48
-
```lua plugins/LuaLink/scripts/my_script/init.lua
49
-
localBukkit=import"org.bukkit.Bukkit"
48
+
```lua plugins/LuaLink/scripts/my_script/main.lua
49
+
localBukkit=import("org.bukkit.Bukkit")
50
50
51
51
-- Called after the script has been successfully loaded.
52
52
script:onLoad(function()
53
53
-- Logging message to the console.
54
-
script:logger:info("Hello, World!")
54
+
script.logger:info("Hello, World!")
55
55
end)
56
56
57
57
```
58
58
It's quite simple, isn't it? For this particular case, we can simplify it even further by extracting the logic away from the `onLoad` block.
59
59
60
-
```lua plugins/LuaLink/scripts/my_script/init.lua
61
-
localBukkit=import"org.bukkit.Bukkit"
60
+
```lua plugins/LuaLink/scripts/my_script/main.lua
61
+
localBukkit=import("org.bukkit.Bukkit")
62
62
63
63
-- Logging message to the console.
64
-
script:logger:info("Hello, World!")
64
+
script.logger:info("Hello, World!")
65
65
```
66
66
Want to do something more complex? More information on how to write scripts can be found on the **[Getting Started](getting-started.md)** page.
-- Printing current value of the counter to the console.
60
-
script.logger.info(counter:get() .." is the current value of the counter.")
60
+
script.logger:info(counter:get() .." is the current value of the counter.")
61
61
end)
62
62
```
63
63
@@ -88,7 +88,7 @@ External Java/Kotlin libraries can be added by configuring the `/plugins/LuaLink
88
88
}
89
89
```
90
90
91
-
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 to add 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 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).
92
92
93
93
After restarting the server, we should be able to import and access any class that belongs to specified library(-ies).
0 commit comments