137 lines
2.6 KiB
Lua
137 lines
2.6 KiB
Lua
local event = require('event')
|
|
local commands = require('commands')
|
|
minecraft = require('minecraft')
|
|
config = require('config')
|
|
|
|
warpDelay = 60 * 5
|
|
|
|
homes = {}
|
|
warps = {}
|
|
|
|
lastHomeTime = {}
|
|
lastWarpTime = {}
|
|
|
|
event.on('init', function()
|
|
local loadedHomes, err = config.load('homes')
|
|
|
|
if loadedHomes and not err then
|
|
homes = loadedHomes
|
|
end
|
|
end)
|
|
|
|
commands.register('sethome', function(user)
|
|
local loc = rcon:GetLocation(user)
|
|
|
|
local c = {}
|
|
|
|
for i, v in loc() do
|
|
c[i] = v
|
|
end
|
|
|
|
homes[user] = c
|
|
|
|
err = config.save('homes', homes)
|
|
|
|
if err ~= nil then
|
|
print('Unable to save homes')
|
|
end
|
|
|
|
rcon:SendMessage(user, string.format("Home location set to %d, %d, %d", c[1], c[2], c[3]))
|
|
end)
|
|
|
|
commands.register('resethome', function(user)
|
|
homes[user] = nil
|
|
|
|
err = config.save('homes', homes)
|
|
|
|
if err ~= nil then
|
|
print('Unable to save homes')
|
|
end
|
|
|
|
rcon:SendMessage(user, 'Home location reset')
|
|
end)
|
|
|
|
commands.register('home', function(user)
|
|
local loc = nil
|
|
|
|
if homes[user] ~= nil then
|
|
loc = homes[user]
|
|
end
|
|
|
|
if loc == nil then
|
|
rcon:SendMessage(user, "You haven't set your spawn or home yet.")
|
|
return
|
|
end
|
|
|
|
local lastWarp = lastHomeTime[user]
|
|
|
|
if lastWarp ~= nil and lastWarp + warpDelay > os.time() and not minecraft.isOp(user) then
|
|
local delay = warpDelay - (os.time() - lastWarp)
|
|
|
|
rcon:SendMessage(user, "You need to wait " .. delay .. " seconds before warping again.")
|
|
return
|
|
end
|
|
|
|
lastHomeTime[user] = os.time()
|
|
|
|
rcon:Teleport(user, string.format("%f %d %f", loc[1], loc[2], loc[3]))
|
|
end)
|
|
|
|
commands.register('setwarp <place>', function(user, place)
|
|
if not minecraft.isOp(user) then
|
|
return
|
|
end
|
|
|
|
|
|
local loc = rcon:GetLocation(user)
|
|
|
|
local c = {}
|
|
|
|
for i, v in loc() do
|
|
c[i] = v
|
|
end
|
|
|
|
warps[place] = c
|
|
|
|
err = config.save('warps', warps)
|
|
|
|
if err ~= nil then
|
|
print('Unable to save warps')
|
|
end
|
|
|
|
rcon:SendMessage(user, string.format("Warp %s set to %d, %d, %d", place, c[1], c[2], c[3]))
|
|
end)
|
|
|
|
commands.register('warp <place>', function(user, place)
|
|
if warps[place] == nil then
|
|
rcon:SendMessage(user, "This warp point doesn't exist")
|
|
return
|
|
end
|
|
|
|
local loc = warps[place]
|
|
|
|
local lastWarp = lastWarpTime[user]
|
|
|
|
if lastWarp ~= nil and lastWarp + warpDelay > os.time() and not minecraft.isOp(user) then
|
|
local delay = warpDelay - (os.time() - lastWarp)
|
|
|
|
rcon:SendMessage(user, "You need to wait " .. delay .. " seconds before warping again.")
|
|
return
|
|
end
|
|
|
|
lastWarpTime[user] = os.time()
|
|
|
|
rcon:Teleport(user, string.format("%f %d %f", loc[1], loc[2], loc[3]))
|
|
end)
|
|
|
|
tprequests = {}
|
|
|
|
commands.register('tpa <target>', function(user, target)
|
|
|
|
end)
|
|
|
|
commands.register('tpaccept', function(user)
|
|
end)
|
|
|
|
commands.register('tpdeny', function(user)
|
|
end) |