Fix start, join, formatting, and locale issues

This commit is contained in:
Cooldude2606
2024-11-14 23:59:22 +00:00
parent 48f55b0547
commit 9aee1c425f
29 changed files with 168 additions and 135 deletions

View File

@@ -13,11 +13,19 @@ local authorities = {}
--- If a command has the flag "character_only" then the command can only be used outside of remote view
authorities.exp_permission =
add(function(player, command)
if not player_allowed(player, command.flags.exp_permission or ("command/" .. command)) then
if not player_allowed(player, command.flags.exp_permission or ("command/" .. command.name)) then
return deny{ "exp-commands-authorities_role.deny" }
else
return allow()
end
end)
Roles.define_flag_trigger("is_system", function(player, state)
if state then
Commands.unlock_system_commands(player.name)
else
Commands.lock_system_commands(player.name)
end
end)
return authorities

View File

@@ -5,8 +5,9 @@ Adds a command that allows viewing and changing the construction queue limits
local Commands = require("modules/exp_commands")
--- Get / Set the current values for the bot queue
Commands.new("bot-queue", { "exp-commands_bot-queue.description" })
Commands.new("set-bot-queue", { "exp-commands_bot-queue.description" })
:optional("amount", { "exp-commands_bot-queue.arg-amount" }, Commands.types.integer_range(1, 20))
:add_aliases{ "bot-queue" }
:add_flags{ "admin_only" }
:register(function(player, amount)
if amount then

View File

@@ -52,7 +52,7 @@ end
--- Connect to a different server
Commands.new("connect", { "exp-commands_connect.description" })
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean)
:optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_aliases{ "join" }
:register(function(player, server, is_address)
--- @cast server string
@@ -72,7 +72,7 @@ Commands.new("connect", { "exp-commands_connect.description" })
Commands.new("connect-player", { "exp-commands_connect.description-player" })
:argument("player", { "exp-commands_connect.arg-player" }, Commands.types.player_online)
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean)
:optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_flags{ "admin_only" }
:register(function(player, other_player, server, is_address)
--- @cast other_player LuaPlayer
@@ -92,7 +92,7 @@ Commands.new("connect-player", { "exp-commands_connect.description-player" })
--- Connect all players to a different server
Commands.new("connect-all", { "exp-commands_connect.description-all" })
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean)
:optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_flags{ "admin_only" }
:register(function(player, server, is_address)
--- @cast server string

View File

@@ -92,28 +92,28 @@ local function remove_render(player, key)
end
--- Toggles entity protection selection
Commands.new("protect-entity", { "exp-commands_protection.description-entity" })
Commands.new("protect-entity", { "exp-commands_entity-protection.description-entity" })
:add_aliases{ "pe" }
:register(function(player)
if Selection.is_selecting(player, SelectionNameEntity) then
Selection.stop(player)
return Commands.status.success{ "exp-commands_protection.exit-entity" }
return Commands.status.success{ "exp-commands_entity-protection.exit-entity" }
else
Selection.start(player, SelectionNameEntity)
return Commands.status.success{ "exp-commands_protection.enter-entity" }
return Commands.status.success{ "exp-commands_entity-protection.enter-entity" }
end
end)
--- Toggles area protection selection
Commands.new("protect-area", { "exp-commands_protection.description-area" })
Commands.new("protect-area", { "exp-commands_entity-protection.description-area" })
:add_aliases{ "pa" }
:register(function(player)
if Selection.is_selecting(player, SelectionNameEntity) then
Selection.stop(player)
return Commands.status.success{ "exp-commands_protection.exit-area" }
return Commands.status.success{ "exp-commands_entity-protection.exit-area" }
else
Selection.start(player, SelectionNameEntity)
return Commands.status.success{ "exp-commands_protection.enter-area" }
return Commands.status.success{ "exp-commands_entity-protection.enter-area" }
end
end)
@@ -126,7 +126,7 @@ Selection.on_selection(SelectionNameEntity, function(event)
show_protected_entity(player, entity)
end
player.print({ "exp-commands_protection.protected-entities", #event.entities }, Commands.print_settings.default)
player.print({ "exp-commands_entity-protection.protected-entities", #event.entities }, Commands.print_settings.default)
end)
--- When an area is selected to remove protection from entities
@@ -138,7 +138,7 @@ Selection.on_alt_selection(SelectionNameEntity, function(event)
remove_render(player, get_entity_key(entity))
end
player.print({ "exp-commands_protection.unprotected-entities", #event.entities }, Commands.print_settings.default)
player.print({ "exp-commands_entity-protection.unprotected-entities", #event.entities }, Commands.print_settings.default)
end)
--- When an area is selected to add protection to the area
@@ -150,13 +150,13 @@ Selection.on_selection(SelectionNameArea, function(event)
local player = game.players[event.player_index]
for _, next_area in pairs(areas) do
if contains_area(next_area, area) then
return player.print({ "exp-commands_protection.already-protected" }, Commands.print_settings.error)
return player.print({ "exp-commands_entity-protection.already-protected" }, Commands.print_settings.error)
end
end
EntityProtection.add_area(surface, area)
show_protected_area(player, surface, area)
player.print({ "exp-commands_protection.protected-area" }, Commands.print_settings.default)
player.print({ "exp-commands_entity-protection.protected-area" }, Commands.print_settings.default)
end)
--- When an area is selected to remove protection from the area
@@ -169,7 +169,7 @@ Selection.on_alt_selection(SelectionNameArea, function(event)
for _, next_area in pairs(areas) do
if contains_area(area, next_area) then
EntityProtection.remove_area(surface, next_area)
player.print({ "exp-commands_protection.unprotected-area" }, Commands.print_settings.default)
player.print({ "exp-commands_entity-protection.unprotected-area" }, Commands.print_settings.default)
remove_render(player, get_area_key(next_area))
end
end
@@ -222,7 +222,7 @@ end
--- When there is a repeat offence print it in chat
local function on_repeat_violation(event)
Roles.print_to_roles_higher("Regular", {
"exp-commands_protection.repeat-offence",
"exp-commands_entity-protection.repeat-offence",
format_player_name(event.player_index),
event.entity.localised_name,
event.entity.position.x,

View File

@@ -18,17 +18,17 @@ Storage.register({
end)
--- Toggle admin marker mode, can only be applied to yourself
local cmd_protected_tag =
Commands.new("protected-tag", { "exp-commands_protected-tags.description" })
local cmd_protect_tag =
Commands.new("protect-tag", { "exp-commands_tag-protection.description" })
:add_aliases{ "ptag" }
:add_flags{ "admin_only" }
:register(function(player)
if active_players[player.index] then
active_players[player.index] = nil
return Commands.status.success{ "exp-commands_protected-tags.exit" }
return Commands.status.success{ "exp-commands_tag-protection.exit" }
else
active_players[player.index] = true
return Commands.status.success{ "exp-commands_protected-tags.enter" }
return Commands.status.success{ "exp-commands_tag-protection.enter" }
end
end)
@@ -47,7 +47,7 @@ local function on_chart_tag_added(event)
local tag = event.tag
local player = game.players[event.player_index]
map_tags[tag.force.name .. tag.tag_number] = true
player.print{ "exp-commands_protected-tags.create" }
player.print{ "exp-commands_tag-protection.create" }
end
--- Stop a tag from being edited or removed
@@ -60,7 +60,7 @@ local function on_chart_tag_removed_or_modified(event)
-- Check if the player is in protected mode, and inform them that it was protected
if active_players[event.player_index] then
player.print{ "exp-commands_protected-tags.edit" }
player.print{ "exp-commands_tag-protection.edit" }
return
end
@@ -92,12 +92,12 @@ local function on_chart_tag_removed_or_modified(event)
map_tags[new_tag.force.name .. new_tag.tag_number] = true
end
if Commands.player_has_permission(player, cmd_protected_tag) then
if Commands.player_has_permission(player, cmd_protect_tag) then
-- Player is not in protected mode, but has access to the command
player.print({ "exp-commands_protected-tags.revert-has-access", cmd_protected_tag.name }, Commands.print_settings.error)
player.print({ "exp-commands_tag-protection.revert-has-access", cmd_protect_tag.name }, Commands.print_settings.error)
else
--- Player does not have access to protected mode
player.print({ "exp-commands_protected-tags.revert-no-access" }, Commands.print_settings.error)
player.print({ "exp-commands_tag-protection.revert-no-access" }, Commands.print_settings.error)
end
end

View File

@@ -52,7 +52,7 @@ local function next_color(color, step)
end
--- Sends an rainbow message in the chat
Commands.new("rainbow", { "exp-commands_rainbow" })
Commands.new("rainbow", { "exp-commands_rainbow.description" })
:argument("message", { "exp-commands_rainbow.arg-message" }, Commands.types.string)
:enable_auto_concatenation()
:register(function(player, message)

View File

@@ -4,23 +4,23 @@ Adds a command to calculate the number of machines needed to fulfil a desired pr
local Commands = require("modules/exp_commands")
Commands.new("ratio", { "exp-command_ratio.description" })
:optional("items-per-second", { "exp-command_ratio.arg-items-per-second" }, Commands.types.number)
Commands.new("ratio", { "exp-commands_ratio.description" })
:optional("items-per-second", { "exp-commands_ratio.arg-items-per-second" }, Commands.types.number)
:register(function(player, items_per_second)
--- @cast items_per_second number?
local machine = player.selected
if not machine then
return Commands.status.error{ "exp-command_ratio.not-selecting" }
return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end
if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then
return Commands.status.error{ "exp-command_ratio.not-selecting" }
return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end
local recipe = machine.get_recipe()
if not recipe then
return Commands.status.error{ "exp-command_ratio.not-selecting" }
return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end
local products = recipe.products
@@ -34,7 +34,7 @@ Commands.new("ratio", { "exp-command_ratio.description" })
for _, ingredient in ipairs(ingredients) do
Commands.print{
ingredient.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out",
ingredient.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out",
math.round(ingredient.amount * crafts_per_second, 3),
ingredient.name
}
@@ -42,13 +42,13 @@ Commands.new("ratio", { "exp-command_ratio.description" })
for i, product in ipairs(products) do
Commands.print{
product.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out",
product.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out",
math.round(product.amount * crafts_per_second, 3),
product.name
}
end
if amount_of_machines ~= 1 then
Commands.print{ "exp-command_ratio.machine-count", amount_of_machines }
Commands.print{ "exp-commands_ratio.machine-count", amount_of_machines }
end
end)

View File

@@ -125,7 +125,7 @@ end
Commands.new("search", { "exp-commands_search.description-search" })
:argument("item", { "exp-commands_search.arg-item" }, parse_item)
:enable_auto_concatenation()
:add_aliases{ "s" }
:add_aliases{ "si" } -- cant use /s
:register(function(player, item)
--- @cast item LuaItemPrototype
local results = search_players(game.players, item)
@@ -172,7 +172,7 @@ end
Commands.new("search-recent", { "exp-commands_search.description-recent" })
:argument("item", { "exp-commands_search.arg-item" }, parse_item)
:enable_auto_concatenation()
:add_aliases{ "sr" } -- cant use /sc
:add_aliases{ "sr" }
:register(function(player, item)
--- @cast item LuaItemPrototype
local results = search_players(game.players, item)

View File

@@ -17,12 +17,12 @@ Commands.new("spectate", { "exp-commands_spectate.description-spectate" })
--- Enters follow mode for the caller, following the given player.
Commands.new("follow", { "exp-commands_spectate.description-follow" })
:argument("player", { "exp-command_spectate.arg-player" }, Commands.types.player_online)
:argument("player", { "exp-commands_spectate.arg-player" }, Commands.types.player_online)
:add_aliases{ "f" }
:register(function(player, other_player)
--- @cast other_player LuaPlayer
if player == other_player then
return Commands.status.invalid_input{ "exp-command_spectate.follow-self" }
return Commands.status.invalid_input{ "exp-commands_spectate.follow-self" }
else
Spectate.start_follow(player, other_player)
end

View File

@@ -71,7 +71,7 @@ Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints"
--- Clear all blueprints in a radius around you
Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" })
:argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 1000))
:argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 100))
:register(function(player, radius)
--- @cast radius number
local player_name = format_player_name(player)

View File

@@ -59,7 +59,7 @@ Commands.new("goto", { "exp-commands_teleport.description-goto" })
--- Teleport to spawn
Commands.new("spawn", { "exp-commands_teleport.description-spawn" })
:optional("player", { "exp-commands_teleport.arg-player-spawn" }, Commands.types.player_alive)
:optional("player", { "exp-commands_teleport.arg-player-from" }, Commands.types.player_alive)
:defaults{
player = function(player)
if player.character and player.character.health > 0 then