Browse Source

Merge branch 'master' into nalc

master
sys4-fr 1 year ago
parent
commit
aa03ef9ddb
10 changed files with 1210 additions and 1196 deletions
  1. +340
    -229
      chatcommands.lua
  2. +45
    -0
      convert.lua
  3. +3
    -1
      depends.txt
  4. +701
    -839
      factions.lua
  5. +28
    -13
      hud.lua
  6. +3
    -7
      init.lua
  7. +0
    -28
      ip.lua
  8. +0
    -38
      misc_mod_data.lua
  9. +1
    -1
      mod.conf
  10. +89
    -40
      nodes.lua

+ 340
- 229
chatcommands.lua
File diff suppressed because it is too large
View File


+ 45
- 0
convert.lua View File

@@ -0,0 +1,45 @@
function ip_convert()
local path = minetest.get_worldpath() .. "/factions_iplist.txt"
local file, error = io.open(path, "r")

if file ~= nil then
local raw_data = file:read("*a")
local ips = minetest.deserialize(raw_data)
file:close()
for i, k in pairs(ips) do
factions.player_ips.set(i, k)
end
os.rename(path, minetest.get_worldpath() .. "/factions_iplist_old.txt")
end
end

function faction_convert()
local path = minetest.get_worldpath() .. "/factions.conf"
local file, error = io.open(path, "r")

if file ~= nil then
local raw_data = file:read("*a")
local tabledata = minetest.deserialize(raw_data)
file:close()
if tabledata then
for facname, faction in pairs(tabledata) do
factions.factions.set(facname, faction)
for player, rank in pairs(faction.players) do
factions.players.set(player, facname)
end
for parcelpos, val in pairs(faction.land) do
factions.parcels.set(parcelpos, facname)
end
end
os.rename(path, minetest.get_worldpath() .. "/factions_old.conf")
end
end
end

ip_convert()
faction_convert()

+ 3
- 1
depends.txt View File

@@ -1,2 +1,4 @@
default?
doors?
doors?
xdecor?
colddb

+ 701
- 839
factions.lua
File diff suppressed because it is too large
View File


+ 28
- 13
hud.lua View File

@@ -4,13 +4,14 @@ function createHudfactionLand(player)
if player then
local name = player:get_player_name()
local id_name = name .. "factionLand"
if not hud_ids[id_name] then
hud_ids[id_name] = player:hud_add({
hud_elem_type = "text",
name = "factionLand",
number = 0xFFFFFF,
position = {x=0.1, y = .98},
text = "Wilderness",
text = "Parcel:",
scale = {x=1, y=1},
alignment = {x=0, y=0},
})
@@ -18,17 +19,18 @@ function createHudfactionLand(player)
end
end

function createHudFactionName(player,factionname)
function createHudFactionName(player, factionname)
if player and factionname then
local name = player:get_player_name()
local id_name = name .. "factionName"
if not hud_ids[id_name] then
hud_ids[id_name] = player:hud_add({
hud_elem_type = "text",
name = "factionName",
number = 0xFFFFFF,
position = {x=1, y = 0},
text = "Faction "..factionname,
text = "Faction " .. factionname,
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = -20, y = 20}
@@ -37,17 +39,18 @@ function createHudFactionName(player,factionname)
end
end

function createHudPower(player,faction)
function createHudPower(player, faction)
if player and faction then
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if not hud_ids[id_name] then
hud_ids[id_name] = player:hud_add({
hud_elem_type = "text",
name = "powerWatch",
number = 0xFFFFFF,
position = {x=0.9, y = .98},
text = "Power: "..faction.power.." / ".. faction.maxpower - faction.usedpower,
text = "Power: " .. faction.power .. " / " .. faction.maxpower - faction.usedpower,
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = 0, y = 0}
@@ -56,9 +59,10 @@ function createHudPower(player,faction)
end
end

function removeHud(player,hudname)
function removeHud(player, hudname)
local name = ""
local p = {}
if type(player) ~= "string" then
name = player:get_player_name()
p = player
@@ -66,24 +70,28 @@ function removeHud(player,hudname)
name = player
p = minetest.get_player_by_name(player)
end
local id_name = name .. hudname
if hud_ids[id_name] then
p:hud_remove(hud_ids[id_name])
hud_ids[id_name] = nil
end
end

function updateHudPower(player,faction)
function updateHudPower(player, faction)
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if hud_ids[id_name] then
player:hud_change(hud_ids[id_name],"text","Power: "..faction.power.." / ".. faction.maxpower - faction.usedpower)
player:hud_change(hud_ids[id_name], "text", "Power: " .. faction.power .. " / " .. faction.maxpower - faction.usedpower)
end
end

function updateFactionName(player,factionname)
function updateFactionName(player, factionname)
local name = ""
local p = {}
if type(player) ~= "string" then
name = player:get_player_name()
p = player
@@ -91,9 +99,11 @@ function updateFactionName(player,factionname)
name = player
p = minetest.get_player_by_name(player)
end
local id_name = name .. "factionName"
if hud_ids[id_name] then
p:hud_change(hud_ids[id_name],"text","Faction "..factionname)
p:hud_change(hud_ids[id_name], "text", "Faction " .. factionname)
end
end

@@ -102,11 +112,16 @@ function hudUpdateClaimInfo()
for i in pairs(playerslist) do
local player = playerslist[i]
local name = player:get_player_name()
local faction = factions.get_faction_at(player:getpos())
local faction, facname = factions.get_faction_at(player:getpos())
local id_name = name .. "factionLand"
if hud_ids[id_name] then
player:hud_change(hud_ids[id_name],"text",(faction and faction.name) or "Wilderness")
local display = "Parcel:"
if facname then
display = display .. facname
end
player:hud_change(hud_ids[id_name], "text", display)
end
end
minetest.after(3,hudUpdateClaimInfo)
minetest.after(3, hudUpdateClaimInfo)
end

+ 3
- 7
init.lua View File

@@ -2,17 +2,13 @@
factions_modpath = minetest.get_modpath("factions")

dofile (factions_modpath .. "/config.lua")
dofile (factions_modpath .. "/misc_mod_data.lua")
dofile (factions_modpath .. "/hud.lua")
dofile (factions_modpath .. "/ip.lua")
dofile (factions_modpath .. "/factions.lua")
dofile (factions_modpath .. "/chatcommands.lua")
dofile (factions_modpath .. "/nodes.lua")
dofile (factions_modpath .. "/convert.lua")

factions.load()
misc_mod_data.check_file()

minetest.after(1,hudUpdateClaimInfo)
minetest.after(1,factionUpdate)
minetest.after(1, hudUpdateClaimInfo)
minetest.after(factions_config.tick_time, factionUpdate)

minetest.log("action", "[factions] loaded.")

+ 0
- 28
ip.lua View File

@@ -1,28 +0,0 @@
factions_ip = {}
factions_ip.player_ips = {}

--read some basic information
local factions_worldid = minetest.get_worldpath()

function factions_ip.save()
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.txt","w")

if file ~= nil then
file:write(minetest.serialize(factions_ip.player_ips))
file:close()
else
minetest.log("error","MOD factions: unable to save faction player ips!: " .. error)
end
end

function factions_ip.load()
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.txt","r")

if file ~= nil then
local raw_data = file:read("*a")
factions_ip.player_ips = minetest.deserialize(raw_data)
file:close()
else
factions_ip.save()
end
end

+ 0
- 38
misc_mod_data.lua View File

@@ -1,38 +0,0 @@
misc_mod_data = {}
misc_mod_data.data = {factions_version = "0.8.1",config = factions_config}

--read some basic information
local factions_worldid = minetest.get_worldpath()

function misc_mod_data.save()
local file,error = io.open(factions_worldid .. "/" .. "factions_misc_mod_data.txt","w")

if file ~= nil then
file:write(minetest.serialize(misc_mod_data.data))
file:close()
else
minetest.log("error","MOD factions: unable to save factions misc mod data!: " .. error)
end
end

function misc_mod_data.load()
local file,error = io.open(factions_worldid .. "/" .. "factions_misc_mod_data.txt","r")

if file ~= nil then
local raw_data = file:read("*a")
misc_mod_data.data = minetest.deserialize(raw_data)
file:close()
else
misc_mod_data.save()
end
end

function misc_mod_data.check_file()
local file,error = io.open(factions_worldid .. "/" .. "factions_misc_mod_data.txt","r")

if file ~= nil then
file:close()
else
misc_mod_data.save()
end
end

+ 1
- 1
mod.conf View File

@@ -1 +1 @@
name = factions
name = factions

+ 89
- 40
nodes.lua View File

@@ -1,4 +1,4 @@
function factions.can_use_node(pos, player,permission)
function factions.can_use_node(pos, player, permission)
if not player then
return false
end
@@ -6,11 +6,12 @@ function factions.can_use_node(pos, player,permission)
if not parcel_faction then
return true
end
local player_faction = factions.get_player_faction(player)
if player_faction and (parcel_faction.name == player_faction.name or parcel_faction.allies[player_faction.name]) and player_faction:has_permission(player, permission) then
local player_faction, facname = factions.get_player_faction(player)
if player_faction and (parcel_faction.name == facname or parcel_faction.allies[facname]) and factions.has_permission(facname, player, permission) then
return true
end
end

-- Make default chest the faction chest.
if minetest.registered_nodes["default:chest"] then
minetest.register_lbm({
@@ -18,84 +19,132 @@ if minetest.registered_nodes["default:chest"] then
name = "factions:replace_factions_chest",
nodenames = {"factions:chest"},
action = function(pos, node)
minetest.swap_node(pos, {name="default:chest"})
minetest.swap_node(pos, {name = "default:chest"})
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
meta:set_string("faction", parcel_faction.name or "")
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Chest (owned by faction " ..
meta:get_string("faction") .. ")")
name .. ")")
end
end
})
local dc = minetest.registered_nodes["default:chest"]
local def_on_rightclick = dc.on_rightclick
local clonenode = {}
for k,v in pairs(minetest.registered_nodes["default:chest"]) do clonenode[k] = v end
clonenode.after_place_node = function(pos, placer)

local after_place_node = function(pos, placer)
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
meta:set_string("faction", parcel_faction.name or "")
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Chest (owned by faction " ..
meta:get_string("faction") .. ")")
name .. ")")
end
end
clonenode.can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("main") and
factions.can_use_node(pos, player:get_player_name(),"container")
factions.can_use_node(pos, player:get_player_name(), "container")
end
clonenode.allow_metadata_inventory_move = function(pos, from_list, from_index,
local allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if not factions.can_use_node(pos, player:get_player_name(),"container") then
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return count
end
clonenode.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(),"container") then
local allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return stack:get_count()
end
clonenode.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(),"container") then
local allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not factions.can_use_node(pos, player:get_player_name(), "container") then
return 0
end
return stack:get_count()
end
clonenode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not factions.can_use_node(pos, clicker:get_player_name(),"container") then
local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not factions.can_use_node(pos, clicker:get_player_name(), "container") then
return itemstack
end
def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end
minetest.register_node(":default:chest",clonenode)
minetest.override_item("default:chest", {after_place_node = after_place_node,
can_dig = can_dig,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
on_rightclick = on_rightclick})
end

-- Edit default doors and trapdoors to make them require the door permission.
local doors = {"doors:door_wood_a","doors:door_wood_b","doors:door_steel_a","doors:door_steel_b","doors:door_glass_a","doors:door_glass_b"
,"doors:door_obsidian_glass_a","doors:door_obsidian_glass_b","doors:trapdoor","doors:trapdoor_open","doors:trapdoor_steel","doors:trapdoor_steel_open"}
for i,k in ipairs(doors) do
if minetest.registered_nodes[k] then
local dw = minetest.registered_nodes[k]
local def_after_place_node = dw.on_rightclick
local doors = {"doors:door_wood_a", "doors:door_wood_b", "doors:door_steel_a", "doors:door_steel_b", "doors:door_glass_a", "doors:door_glass_b",
"doors:door_obsidian_glass_a", "doors:door_obsidian_glass_b", "doors:trapdoor", "doors:trapdoor_open", "doors:trapdoor_steel", "doors:trapdoor_steel_open",
"doors:woodglass_door_a", "doors:woodglass_door_b", "doors:slide_door_a", "doors:slide_door_b", "doors:screen_door_a", "doors:screen_door_b", "doors:rusty_prison_door_a",
"doors:rusty_prison_door_b", "doors:prison_door_a", "doors:prison_door_b", "doors:japanese_door_a", "doors:japanese_door_b"}
for i, l in ipairs(doors) do
local dw = minetest.registered_nodes[l]
if dw then
local def_on_rightclick = dw.on_rightclick
local def_can_dig = dw.can_dig
local clonenode = {}
for k,v in pairs(minetest.registered_nodes[k]) do clonenode[k] = v end
clonenode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if factions.can_use_node(pos, clicker:get_player_name(),"door") then
def_after_place_node(pos, node, clicker, itemstack, pointed_thing)
local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if factions.can_use_node(pos, clicker:get_player_name(), "door") then
def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end
return itemstack
end
clonenode.can_dig = function(pos, digger)
if factions.can_use_node(pos, digger:get_player_name(),"door") then
return def_can_dig(pos, digger)
local can_dig = nil
if def_can_dig then
can_dig = function(pos, digger)
if factions.can_use_node(pos, digger:get_player_name(), "door") then
return def_can_dig(pos, digger)
end
return false
end
else
can_dig = function(pos, digger)
if factions.can_use_node(pos, digger:get_player_name(), "door") then
return true
end
return false
end
end
minetest.override_item(l, {on_rightclick = on_rightclick,
can_dig = can_dig})
end
end

local door_items = {"doors:door_wood", "doors:door_steel", "doors:door_glass", "doors:door_obsidian_glass", "doors:trapdoor", "doors:trapdoor_steel", "doors:woodglass_door", "doors:slide_door",
"doors:screen_door", "doors:rusty_prison_door", "doors:prison_door", "doors:japanese_door"}

for i, l in ipairs(door_items) do
local it = minetest.registered_items[l]
if it then
local def_on_place = it.on_place
if def_on_place ~= nil then
local on_place = function(itemstack, placer, pointed_thing)
local r = def_on_place(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local parcel_faction = factions.get_faction_at(pos)
if parcel_faction then
local meta = minetest.get_meta(pos)
local name = parcel_faction.name
meta:set_string("faction", name)
meta:set_string("infotext", "Faction Door (owned by faction " ..
name .. ")")
end
return r
end
return false
minetest.override_item(l, {on_place = on_place})
end
minetest.register_node(":"..k,clonenode)
end
end
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.


Loading…
Cancel
Save