From 0dd50e71414e780c6553cee481176e11b2ad8350 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sat, 29 Jun 2019 14:57:55 -0500 Subject: [PATCH] Remove: optional_depends --- chatcommands.lua | 17 +-- databases.lua | 30 +--- mod.conf | 3 +- nodes.lua | 349 ++++++++++++++++++++++++----------------------- 4 files changed, 187 insertions(+), 212 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 8470ac4..6958efe 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -123,14 +123,6 @@ factions.register_command = function(cmd_name, cmd, ignore_param_count, or_perm, end end -factions.register_commands = function(cmd_names, cmd, ignore_param_count, or_perm) - local hide = false - for k, v in pairs(cmd_names) do - factions.register_command(k, cmd, ignore_param_count, or_perm, hide) - hide = true - end -end - local init_commands init_commands = function() @@ -1670,9 +1662,9 @@ local premade_help = "" local premade_help_admin = "" -local a_z = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} +local a_z = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} -minetest.register_on_mods_loaded(function() +function factions.create_help_text() for l, j in pairs(a_z) do for k, v in pairs(factions.commands) do if k:sub(1, 1) == j then @@ -1685,7 +1677,10 @@ minetest.register_on_mods_loaded(function() end end end - a_z = nil +end + +minetest.register_on_mods_loaded(function() + factions.create_help_text() end) ------------------------------------------------------------------------------- diff --git a/databases.lua b/databases.lua index 56e9ee9..032ef04 100644 --- a/databases.lua +++ b/databases.lua @@ -12,28 +12,6 @@ factions.player_ips = factions.root.sub_database("ips") -- Memory only storage. factions.onlineplayers = {} --- Table hook functions. - --- Hook function to add or delete from the faction table. -function factions.on_create_faction_table(table) - return table -end - --- Hook function to add or delete from the ip table. -function factions.on_create_ip_table(table) - return table -end - --- Hook function to add or delete from the player table. -function factions.on_create_player_table(table) - return table -end - --- Hook function to add or delete from the claim table. -function factions.on_create_parcel_table(table) - return table -end - -- Table creation. -- Create a empty faction. @@ -87,7 +65,7 @@ function factions.create_faction_table() --! @brief access table access = {players = {}, factions = {}}, } - return factions.on_create_faction_table(table) + return table end -- Create a empty ip table. @@ -95,7 +73,7 @@ function factions.create_ip_table() local table = { ip = "" } - return factions.on_create_ip_table(table) + return table end -- Create a empty player table. @@ -103,7 +81,7 @@ function factions.create_player_table() local table = { faction = "" } - return factions.on_create_player_table(table) + return table end -- Create a empty claim table. @@ -111,7 +89,7 @@ function factions.create_parcel_table() local table = { faction = "" } - return factions.on_create_parcel_table(table) + return table end -- helper functions diff --git a/mod.conf b/mod.conf index 28d1621..2a4f577 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,3 @@ name = factions -description = Mod for handling in game factions and reputation. +description = Mc style faction system. depends = colddb -optional_depends = default, doors, xdecor, ts_doors diff --git a/nodes.lua b/nodes.lua index de3dd50..f0ed8f9 100644 --- a/nodes.lua +++ b/nodes.lua @@ -12,195 +12,198 @@ function factions.can_use_node(pos, player, permission) end end --- Make default chest the faction chest. -if minetest.registered_nodes["default:chest"] then - local dc = minetest.registered_nodes["default:chest"] - local def_on_rightclick = dc.on_rightclick +minetest.register_on_mods_loaded(function() + -- Make default chest the faction chest. + if minetest.registered_nodes["default:chest"] then + local dc = minetest.registered_nodes["default:chest"] + local def_on_rightclick = dc.on_rightclick - local after_place_node = function(pos, placer) - local parcel_faction = factions.get_faction_at(pos) - if parcel_faction then + 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) + local name = parcel_faction.name + meta:set_string("faction", name) + meta:set_string("infotext", "Faction Container (owned by faction " .. + name .. ")") + end + end + + local can_dig = function(pos, player) local meta = minetest.get_meta(pos) - local name = parcel_faction.name - meta:set_string("faction", name) - meta:set_string("infotext", "Faction Container (owned by faction " .. - name .. ")") - end - end - - 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") - end - - local allow_metadata_inventory_move - local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move - if def_allow_metadata_inventory_move then - 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") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return def_allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) - end - else - 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") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return count - end - end - - local allow_metadata_inventory_put - local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put - if def_allow_metadata_inventory_put then - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return def_allow_metadata_inventory_put(pos, listname, index, stack, player) - end - else - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return stack:get_count() - end - end - - local allow_metadata_inventory_take - local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take - if def_allow_metadata_inventory_take then - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return def_allow_metadata_inventory_take(pos, listname, index, stack, player) - end - else - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then - return 0 - end - return stack:get_count() - end - end - - local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - if not factions.can_use_node(pos, clicker:get_player_name(), "container") and not minetest.check_player_privs(clicker, "protection_bypass") then - return itemstack - end - return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) - end - - 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 - -local door_items = {"doors:door_wood", "doors:door_steel", "doors:door_glass", "doors:door_obsidian_glass", "doors:woodglass_door", "doors:slide_door", - "doors:screen_door", "doors:rusty_prison_door", "doors:prison_door", "doors:japanese_door", "ts_doors:door_default_aspen_wood", "ts_doors:door_full_default_aspen_wood", - "ts_doors:door_default_pine_wood", "ts_doors:door_full_default_pine_wood", "ts_doors:door_default_acacia_wood", "ts_doors:door_full_default_acacia_wood", - "ts_doors:door_default_wood", "ts_doors:door_full_default_wood", "ts_doors:door_default_junglewood", "ts_doors:door_full_default_junglewood", - "ts_doors:door_default_bronzeblock", "ts_doors:door_full_default_bronzeblock", "ts_doors:door_default_copperblock", "ts_doors:door_full_default_copperblock", - "ts_doors:door_default_diamondblock", "ts_doors:door_full_default_diamondblock", "ts_doors:door_full_default_goldblock", "ts_doors:door_default_steelblock", "ts_doors:door_full_default_steelblock"} - -local trapdoor_items = {"doors:trapdoor", "doors:trapdoor_steel", "ts_doors:trapdoor_default_aspen_wood", "ts_doors:trapdoor_full_default_aspen_wood", - "ts_doors:trapdoor_default_wood", "ts_doors:trapdoor_full_default_wood", "ts_doors:trapdoor_default_acacia_wood", "ts_doors:trapdoor_full_default_acacia_wood", - "ts_doors:trapdoor_default_bronzeblock", "ts_doors:trapdoor_full_default_bronzeblock", "ts_doors:trapdoor_default_copperblock", "ts_doors:trapdoor_full_default_copperblock", "ts_doors:trapdoor_full_default_diamondblock", - "ts_doors:door_default_goldblock", "ts_doors:trapdoor_default_steelblock", "ts_doors:trapdoor_full_default_steelblock", "ts_doors:trapdoor_default_pine_wood", "ts_doors:trapdoor_full_default_pine_wood", - "ts_doors:trapdoor_full_default_goldblock", "ts_doors:trapdoor_default_junglewood", "ts_doors:trapdoor_full_default_junglewood", - "ts_doors:trapdoor_default_diamondblock", "ts_doors:trapdoor_default_goldblock"} - --- Edit default doors and trapdoors to make them require the door permission. -local doors = {} - -local all_items = {} - -local item_count = 1 - -local old_i = 0 - -for i, l in ipairs(door_items) do - doors[item_count] = l .. "_a" - doors[item_count + 1] = l .. "_b" - all_items[i] = l - item_count = item_count + 2 - old_i = old_i + 1 -end - -for i, l in ipairs(trapdoor_items) do - doors[item_count] = l - doors[item_count + 1] = l .. "_open" - all_items[old_i + i] = l - item_count = item_count + 2 -end - -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 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - if factions.can_use_node(pos, clicker:get_player_name(), "door") or minetest.check_player_privs(clicker, "protection_bypass") then - def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) - end - return itemstack + local inv = meta:get_inventory() + return inv:is_empty("main") and + factions.can_use_node(pos, player:get_player_name(), "container") end - 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) + local allow_metadata_inventory_move + local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move + if def_allow_metadata_inventory_move then + 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") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 end - return false + return def_allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) end else - can_dig = function(pos, digger) - if factions.can_use_node(pos, digger:get_player_name(), "door") then - return true + 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") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 end - return false + return count end end - minetest.override_item(l, {on_rightclick = on_rightclick, - can_dig = can_dig}) + + local allow_metadata_inventory_put + local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put + if def_allow_metadata_inventory_put then + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 + end + return def_allow_metadata_inventory_put(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 + end + return stack:get_count() + end + end + + local allow_metadata_inventory_take + local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take + if def_allow_metadata_inventory_take then + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 + end + return def_allow_metadata_inventory_take(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") and not minetest.check_player_privs(player, "protection_bypass") then + return 0 + end + return stack:get_count() + end + end + + local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if not factions.can_use_node(pos, clicker:get_player_name(), "container") and not minetest.check_player_privs(clicker, "protection_bypass") then + return itemstack + end + return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) + end + + 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 -end -for i, l in ipairs(all_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 .. ")") + local door_items = {"doors:door_wood", "doors:door_steel", "doors:door_glass", "doors:door_obsidian_glass", "doors:woodglass_door", "doors:slide_door", + "doors:screen_door", "doors:rusty_prison_door", "doors:prison_door", "doors:japanese_door", "ts_doors:door_default_aspen_wood", "ts_doors:door_full_default_aspen_wood", + "ts_doors:door_default_pine_wood", "ts_doors:door_full_default_pine_wood", "ts_doors:door_default_acacia_wood", "ts_doors:door_full_default_acacia_wood", + "ts_doors:door_default_wood", "ts_doors:door_full_default_wood", "ts_doors:door_default_junglewood", "ts_doors:door_full_default_junglewood", + "ts_doors:door_default_bronzeblock", "ts_doors:door_full_default_bronzeblock", "ts_doors:door_default_copperblock", "ts_doors:door_full_default_copperblock", + "ts_doors:door_default_diamondblock", "ts_doors:door_full_default_diamondblock", "ts_doors:door_full_default_goldblock", "ts_doors:door_default_steelblock", "ts_doors:door_full_default_steelblock"} + + local trapdoor_items = {"doors:trapdoor", "doors:trapdoor_steel", "ts_doors:trapdoor_default_aspen_wood", "ts_doors:trapdoor_full_default_aspen_wood", + "ts_doors:trapdoor_default_wood", "ts_doors:trapdoor_full_default_wood", "ts_doors:trapdoor_default_acacia_wood", "ts_doors:trapdoor_full_default_acacia_wood", + "ts_doors:trapdoor_default_bronzeblock", "ts_doors:trapdoor_full_default_bronzeblock", "ts_doors:trapdoor_default_copperblock", "ts_doors:trapdoor_full_default_copperblock", "ts_doors:trapdoor_full_default_diamondblock", + "ts_doors:door_default_goldblock", "ts_doors:trapdoor_default_steelblock", "ts_doors:trapdoor_full_default_steelblock", "ts_doors:trapdoor_default_pine_wood", "ts_doors:trapdoor_full_default_pine_wood", + "ts_doors:trapdoor_full_default_goldblock", "ts_doors:trapdoor_default_junglewood", "ts_doors:trapdoor_full_default_junglewood", + "ts_doors:trapdoor_default_diamondblock", "ts_doors:trapdoor_default_goldblock"} + + -- Edit default doors and trapdoors to make them require the door permission. + local doors = {} + + local all_items = {} + + local item_count = 1 + + local old_i = 0 + + for i, l in ipairs(door_items) do + doors[item_count] = l .. "_a" + doors[item_count + 1] = l .. "_b" + all_items[i] = l + item_count = item_count + 2 + old_i = old_i + 1 + end + + for i, l in ipairs(trapdoor_items) do + doors[item_count] = l + doors[item_count + 1] = l .. "_open" + all_items[old_i + i] = l + item_count = item_count + 2 + end + + 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 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if factions.can_use_node(pos, clicker:get_player_name(), "door") or minetest.check_player_privs(clicker, "protection_bypass") then + def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) end - return r + return itemstack end - minetest.override_item(l, {on_place = on_place}) + + 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 -end + + for i, l in ipairs(all_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 + minetest.override_item(l, {on_place = on_place}) + end + end + end + +end) -- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit. local x = math.floor(factions_config.parcel_size / 2.1)