Sandboxed (untrusted) script:
Code (Text):
--[[
Example script that can run untrusted.
The following variables are available to lua scripts. All of these variables are exact copies of their Java classes from Spigot:
- player - The player that broke the luckyblock. Documentation: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Player.html
- loc - The location of the broken luckyblock. Documentation: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Location.html
- world - The world the luckyblock was broken in. Documentation: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/World.html
- scheduler - The bukkit scheduler which can be used to, for example, delay tasks: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/scheduler/BukkitRunnable.html
- All material enum values are available as global variables, prefixed with MATERIAL_. (For example, you can use MATERIAL_IRON_BOOTS to use the IRON_BOOTS Material). Materials: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
- All effect enum values are available as global variables, prefixed with EFFECT_. Usage is the same as the material values. Effects: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Effect.html
- All sound enum values are available as global variables, prefixed with SOUND_. Usage is the same as the material values. Sounds: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
- All enchantment values are available as global variables, prefixed with ENCHANTMENT_. Usage is the same as the material values. Enchantments: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/enchantments/Enchantment.html
SuperLuckyBlock also provides a utils class, which allows you to do the following things:
- utils:createItemStack(material, amount) - Allows you to create a new ItemStack. Docs: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/ItemStack.html
- utils:colorText(text) - Converts values like &3 to their respective colors.
- utils:createEnchantment(name) - Creates an Enchantment object with the specified enchantment. Enchantments: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/enchantments/Enchantment.html
Methods on these variables can be called in 2 ways:
- player:setFireTicks(100)
- player.setFireTicks(player, 100)
As you can see, calling a method with a dot requires you to pass the variable(in this case player) alongside the other arguments. You don't have to do that when using the semicolon.
If you are missing access to any classes/methods, feel free to contact me and I will look into adding support for it.
]]
local name = player:getName()
if string.find(name, "i") ~= nil then
local itemStack = utils:createItemStack(MATERIAL_DIAMOND_SWORD, 1)
local itemMeta = itemStack:getItemMeta()
itemMeta:setDisplayName(utils:colorText("&2&lSome &3&lRandom &4&lSword"))
itemMeta:addEnchant(utils:createEnchantment("KNOCKBACK"), math.random(1, 10), true)
itemStack:setItemMeta(itemMeta)
world:dropItemNaturally(loc, itemStack)
else
local fireTicks = math.random(100, 500)
player:setFireTicks(fireTicks)
player:chat("I'm on fire for " .. fireTicks .. " ticks!")
end
Unsandboxed (trusted) script:
Code (Text):
--[[
Example script that can only be ran in trusted mode.
The same methods as specified in example.lua are available in trusted mode. In addition to that, scripts that run in trusted mode have access to the following features:
- All Java and Spigot classes (Luajava library)
- Any file reading or writing
- The IO library
- The OS library
- Loading other scripts
- Creating coroutines
Luajava provides two important functions that make trusted mode so powerful, but also dangerous:
- luajava.bindClass("fully.qualified.class.name") - Example: luajava.bindClass("org.bukkit.Bukkit"). Allows you to call static methods, access static fields and enum values
- luajava.newInstance("fully.qualified.class.name") - Example luajava.newInstance("org.bukkit.inventory.ItemStack"). Creates a new instance of the specified class. Allows the methods of that class to be used.
]]
local bukkit = luajava.bindClass("org.bukkit.Bukkit")
local server = bukkit:getServer()
local itemstack = luajava.newInstance("org.bukkit.inventory.ItemStack", MATERIAL_DIAMOND_BLOCK, 4)
player:chat("Hello! Welcome to " .. server:getName())
world:dropItemNaturally(player:getLocation(), itemstack)