Skip to content

Commit

Permalink
Merge pull request #112 from mc-server/ConsoleRegen
Browse files Browse the repository at this point in the history
Added console "regen" command.
  • Loading branch information
madmaxoft committed Dec 12, 2014
2 parents 037bbb8 + 92e9aca commit 39d980e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 11 deletions.
18 changes: 18 additions & 0 deletions Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,24 @@ g_PluginInfo =
Handler = HandleConsoleRank,
HelpString = "Set or view a player's rank",
},

["regen"] =
{
Handler = HandleConsoleRegen,
Alias = "regeneratechunk",
HelpString = "Regenerates a chunk",
ParameterCombinations =
{
{
Params = "ChunkX ChunkZ",
Help = "Regenerates the specified chunk in the default world",
},
{
Params = "ChunkX ChunkZ WorldName",
Help = "Regenerates the specified chunk in the specified world",
}
},
}, -- regen

["save-all"] =
{
Expand Down
81 changes: 70 additions & 11 deletions regen.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,79 @@
function HandleRegenCommand(Split, Player)

if #Split == 2 or #Split > 3 then
SendMessage( Player, "Usage: '/regeneratechunk' or '/regeneratechunk [X] [Z]'" )
-- regen.lua

-- Implements the in-game and console commands for chunk regeneration





function HandleRegenCommand(a_Split, a_Player)
-- Check the params:
local numParams = #a_Split
if (numParams == 2) or (numParams > 3) then
SendMessage(a_Player, "Usage: '" .. a_Split[1] .. "' or '" .. a_Split[1] .. " <ChunkX> <ChunkZ>'" )
return true
end

local X = Player:GetChunkX()
local Z = Player:GetChunkZ()

if #Split == 3 then
X = Split[2]
Z = Split[3]
-- Get the coords of the chunk to regen:
local chunkX = a_Player:GetChunkX()
local chunkZ = a_Player:GetChunkZ()
if (numParams == 3) then
chunkX = tonumber(a_Split[2])
chunkZ = tonumber(a_Split[3])
if (chunkX == nil) then
SendMessageFailure(a_Player, "Not a number: '" .. a_Split[2] .. "'")
return true
end
if (chunkZ == nil) then
SendMessageFailure(a_Player, "Not a number: '" .. a_Split[3] .. "'")
return true
end
end

SendMessageSuccess( Player, "Regenerating chunk ["..X..", "..Z.."]")
Player:GetWorld():RegenerateChunk(X, Z)
-- Regenerate the chunk:
SendMessageSuccess(a_Player, "Regenerating chunk [" .. chunkX .. ", " .. chunkZ .. "]...")
a_Player:GetWorld():RegenerateChunk(chunkX, chunkZ)
return true
end





function HandleConsoleRegen(a_Split)
-- Check the params:
local numParams = #a_Split
if ((numParams ~= 3) and (numParams ~= 4)) then
return true, "Usage: " .. a_Split[1] .. " <ChunkX> <ChunkZ> [<WorldName>]"
end

-- Get the coords of the chunk to regen:
local chunkX = tonumber(a_Split[2])
if (chunkX == nil) then
return true, "Not a number: '" .. a_Split[2] .. "'"
end
local chunkZ = tonumber(a_Split[3])
if (chunkZ == nil) then
return true, "Not a number: '" .. a_Split[3] .. "'"
end

-- Get the world to regen:
local world
if (a_Split[4] == nil) then
world = cRoot:Get():GetDefaultWorld()
else
world = cRoot:Get():GetWorld(a_Split[4])
if (world == nil) then
return true, "There's no world named '" .. a_Split[4] .. "'."
end
end

-- Regenerate the chunk:
world:RegenerateChunk(chunkX, chunkZ)
return true, "Regenerating chunk [" .. chunkX .. ", " .. chunkZ .. "] in world " .. world:GetName()
end




0 comments on commit 39d980e

Please sign in to comment.