Move to event loop, prettify warps, add delay to warp with damage counter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
local event = require('event')
|
||||
local commands = require('commands')
|
||||
timers = require('timers')
|
||||
minecraft = require('minecraft')
|
||||
config = require('config')
|
||||
|
||||
@ -11,12 +12,22 @@ warps = {}
|
||||
lastHomeTime = {}
|
||||
lastWarpTime = {}
|
||||
|
||||
objectiveName = "damageTaken"
|
||||
|
||||
event.on('init', function()
|
||||
local loadedHomes, err = config.load('homes')
|
||||
|
||||
if loadedHomes and not err then
|
||||
homes = loadedHomes
|
||||
end
|
||||
|
||||
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')
|
||||
end)
|
||||
|
||||
commands.register('sethome', function(user)
|
||||
@ -36,7 +47,7 @@ commands.register('sethome', function(user)
|
||||
print('Unable to save homes')
|
||||
end
|
||||
|
||||
rcon:SendMessage(user, string.format("Home location set to %d, %d, %d", c[1], c[2], c[3]))
|
||||
rcon:SendColorfulMessage(user, 'green', string.format("Home location set to %d, %d, %d", c[1], c[2], c[3]))
|
||||
end)
|
||||
|
||||
commands.register('resethome', function(user)
|
||||
@ -48,7 +59,7 @@ commands.register('resethome', function(user)
|
||||
print('Unable to save homes')
|
||||
end
|
||||
|
||||
rcon:SendMessage(user, 'Home location reset')
|
||||
rcon:SendColorfulMessage(user, 'green', 'Home location reset')
|
||||
end)
|
||||
|
||||
commands.register('home', function(user)
|
||||
@ -59,7 +70,7 @@ commands.register('home', function(user)
|
||||
end
|
||||
|
||||
if loc == nil then
|
||||
rcon:SendMessage(user, "You haven't set your spawn or home yet.")
|
||||
rcon:SendColorfulMessage(user, 'red', "You haven't set your spawn or home yet.")
|
||||
return
|
||||
end
|
||||
|
||||
@ -68,13 +79,35 @@ commands.register('home', function(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.")
|
||||
rcon:SendColorfulMessage(user, 'red', "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]))
|
||||
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)
|
||||
end)
|
||||
|
||||
commands.register('setwarp <place>', function(user, place)
|
||||
@ -82,7 +115,6 @@ commands.register('setwarp <place>', function(user, place)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local loc = rcon:GetLocation(user)
|
||||
|
||||
local c = {}
|
||||
@ -99,12 +131,12 @@ commands.register('setwarp <place>', function(user, place)
|
||||
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]))
|
||||
rcon:SendColorfulMessage(user, 'green', 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")
|
||||
rcon:SendColorfulMessage(user, 'red', "This warp point doesn't exist")
|
||||
return
|
||||
end
|
||||
|
||||
@ -115,23 +147,11 @@ commands.register('warp <place>', function(user, place)
|
||||
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.")
|
||||
rcon:SendColorfulMessage(user, 'red', "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]))
|
||||
rcon:SendCommand('execute in minecraft:overworld run tp ' .. 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)
|
Reference in New Issue
Block a user