2020-07-10 01:01:29 +00:00
|
|
|
local event = require('event')
|
|
|
|
local commands = require('commands')
|
2021-06-12 05:28:34 +00:00
|
|
|
timers = require('timers')
|
2020-07-10 01:01:29 +00:00
|
|
|
minecraft = require('minecraft')
|
|
|
|
config = require('config')
|
|
|
|
|
|
|
|
warpDelay = 60 * 5
|
|
|
|
|
|
|
|
homes = {}
|
|
|
|
warps = {}
|
|
|
|
|
|
|
|
lastHomeTime = {}
|
|
|
|
lastWarpTime = {}
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
objectiveName = "damageTaken"
|
|
|
|
|
2020-07-10 01:01:29 +00:00
|
|
|
event.on('init', function()
|
|
|
|
local loadedHomes, err = config.load('homes')
|
|
|
|
|
|
|
|
if loadedHomes and not err then
|
|
|
|
homes = loadedHomes
|
|
|
|
end
|
2021-06-12 05:28:34 +00:00
|
|
|
|
|
|
|
local loadedWarps, err = config.load('warps')
|
|
|
|
|
|
|
|
if loadedWarps and not err then
|
|
|
|
warps = loadedWarps
|
|
|
|
end
|
|
|
|
|
|
|
|
rcon:SendCommand('scoreboard objectives add ' .. objectiveName .. ' minecraft.custom:minecraft.damage_taken')
|
2020-07-10 01:01:29 +00:00
|
|
|
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
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'green', string.format("Home location set to %d, %d, %d", c[1], c[2], c[3]))
|
2020-07-10 01:01:29 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
commands.register('resethome', function(user)
|
|
|
|
homes[user] = nil
|
|
|
|
|
|
|
|
err = config.save('homes', homes)
|
|
|
|
|
|
|
|
if err ~= nil then
|
|
|
|
print('Unable to save homes')
|
|
|
|
end
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'green', 'Home location reset')
|
2020-07-10 01:01:29 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
commands.register('home', function(user)
|
|
|
|
local loc = nil
|
|
|
|
|
|
|
|
if homes[user] ~= nil then
|
|
|
|
loc = homes[user]
|
|
|
|
end
|
|
|
|
|
|
|
|
if loc == nil then
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'red', "You haven't set your spawn or home yet.")
|
2020-07-10 01:01:29 +00:00
|
|
|
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)
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'red', "You need to wait " .. delay .. " seconds before warping again.")
|
2020-07-10 01:01:29 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
lastHomeTime[user] = os.time()
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
local delayLeft = 5
|
|
|
|
|
|
|
|
local originalDamage, err = rcon:SendCommand("scoreboard players get " .. user .. " " .. objectiveName)
|
|
|
|
|
|
|
|
local interval = nil
|
|
|
|
|
|
|
|
interval = timers.setInterval(function()
|
|
|
|
if delayLeft == 0 then
|
|
|
|
local newDamage, err = rcon:SendCommand("scoreboard players get " .. user .. " " .. objectiveName)
|
|
|
|
|
|
|
|
timers.clearInterval(interval)
|
|
|
|
|
|
|
|
if newDamage ~= originalDamage then
|
|
|
|
rcon:SendColorfulMessage(user, 'red', "Teleport was interrupted by combat.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
rcon:SendCommand('execute in minecraft:overworld run tp ' .. user .. ' ' .. string.format("%f %d %f", loc[1], loc[2], loc[3]))
|
|
|
|
else
|
|
|
|
rcon:SendColorfulMessage(user, 'gray', "Teleporting in " .. delayLeft .. " seconds")
|
|
|
|
delayLeft = delayLeft - 1
|
|
|
|
end
|
|
|
|
end, 1000)
|
2020-07-10 01:01:29 +00:00
|
|
|
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
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'green', string.format("Warp %s set to %d, %d, %d", place, c[1], c[2], c[3]))
|
2020-07-10 01:01:29 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
commands.register('warp <place>', function(user, place)
|
|
|
|
if warps[place] == nil then
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'red', "This warp point doesn't exist")
|
2020-07-10 01:01:29 +00:00
|
|
|
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)
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendColorfulMessage(user, 'red', "You need to wait " .. delay .. " seconds before warping again.")
|
2020-07-10 01:01:29 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
lastWarpTime[user] = os.time()
|
|
|
|
|
2021-06-12 05:28:34 +00:00
|
|
|
rcon:SendCommand('execute in minecraft:overworld run tp ' .. user .. ' ' .. string.format("%f %d %f", loc[1], loc[2], loc[3]))
|
2020-07-10 01:01:29 +00:00
|
|
|
end)
|