diff --git a/worldeditadditions_core/core/pos.lua b/worldeditadditions_core/core/pos.lua new file mode 100644 index 0000000..5066984 --- /dev/null +++ b/worldeditadditions_core/core/pos.lua @@ -0,0 +1,57 @@ +local wea_c = worldeditadditions_core + +local positions_count_limit = 999 +local positions = {} + +local function ensure_player(player_name) + if not positions[player_name] then + positions[player_name] = {} + end +end + +--- Gets the position with the given index for the given player. +-- @param player_name string The name of the player to fetch the position for. +-- @param +local function get_pos(player_name, i) + ensure_player(player_name) + return positions[player_name][i] +end + +local function get_pos1(player_name) return get_pos(player_name, 1) end +local function get_pos2(player_name) return get_pos(player_name, 2) end + +local function get_pos_all(player_name) + ensure_player(player_name) + return positions[player_name] +end +local function pos_count(player_name) + ensure_player(player_name) + return #pos_count[player_name] +end + +local function set_pos(player_name, i, pos) + if i > positions_count_limit then return false end + ensure_player(player_name) + positions[player_name][i] = pos + return true +end +local function set_pos_all(player_name, i, pos_list) + if #pos_list > positions_count_limit then return false end + positions[player_name] = pos_list +end +local function clear(player_name) + if positions[player_name] then + positions[player_name] = nil + end +end + +return { + get = get_pos, + get1 = get_pos1, + get2 = get_pos2, + get_all = get_pos_all, + set = set_pos, + set_all = set_pos_all, + count = pos_count, + clear = clear +} \ No newline at end of file diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 3ce5a68..7164948 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -26,6 +26,7 @@ local wea_c = worldeditadditions_core wea_c.register_command = dofile(modpath.."/core/register_command.lua") wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") wea_c.register_alias = dofile(modpath.."/core/register_alias.lua") +wea_c.pos = dofile(modpath.."/core/pos.lua") -- Initialise WorldEdit stuff if the WorldEdit mod is not present