Migrate all commands to new lib

This commit is contained in:
Cooldude2606
2024-11-08 12:59:46 +00:00
parent c9bf85835f
commit 4b6872c14c
103 changed files with 2415 additions and 3694 deletions

View File

@@ -6,8 +6,7 @@
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local config = require("modules.exp_legacy.config.bonus") --- @dep config.bonuses
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Commands = require("modules/exp_commands")
-- Stores the bonus for the player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -47,19 +46,16 @@ PlayerBonus:on_update(function(player_name, player_bonus)
end)
--- Changes the amount of bonus you receive
-- @command bonus
-- @tparam number amount range 0-10 the increase for your bonus
Commands.new_command("bonus", "Changes the amount of bonus you receive")
:add_param("amount", "integer-range", 0, 10)
Commands.new("bonus", { "bonus.description" })
:optional("amount", { "bonus.arg-amount" }, Commands.types.integer_range(0, 10))
:register(function(player, amount)
if not Roles.player_allowed(player, "command/bonus") then
Commands.print{ "expcom-bonus.perm", 1 }
return
--- @cast amount number?
if amount then
PlayerBonus:set(player, amount)
return Commands.status.success{ "bonus.set", amount }
else
return Commands.status.success{ "bonus.get", PlayerBonus:get(player) }
end
PlayerBonus:set(player, amount)
Commands.print{ "expcom-bonus.set", amount }
end)
--- When a player respawns re-apply bonus

View File

@@ -2,8 +2,7 @@
-- @data Greetings
local config = require("modules.exp_legacy.config.join_messages") --- @dep config.join_messages
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Commands = require("modules/exp_commands")
--- Stores the join message that the player have
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -24,20 +23,23 @@ CustomMessages:on_load(function(player_name, player_message)
end)
--- Set your custom join message
-- @command join-message
-- @tparam string message The custom join message that will be used
Commands.new_command("join-message", "Sets your custom join message")
:add_param("message", false, "string-max-length", 255)
:enable_auto_concat()
Commands.new("set-join-message", { "join-message.description-add" })
:optional("message", false, Commands.types.string_max_length(255))
:enable_auto_concatenation()
:add_aliases{ "join-message" }
:register(function(player, message)
if not player then return end
CustomMessages:set(player, message)
return { "join-message.message-set" }
--- @cast message string?
if message then
CustomMessages:set(player, message)
return Commands.status.success{ "join-message.message-set" }
else
return Commands.status.success{ "join-message.message-get", CustomMessages:get(player) }
end
end)
Commands.new_command("join-message-clear", "Clear your join message")
--- Removes your custom join message
Commands.new("remove-join-message", { "join-message.description-remove" })
:register(function(player)
if not player then return end
CustomMessages:remove(player)
return { "join-message.message-cleared" }
return Commands.status.success{ "join-message.message-cleared" }
end)

View File

@@ -1,4 +1,4 @@
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic
local function pl(type, target, amount)
@@ -66,21 +66,20 @@ local function pl(type, target, amount)
end
end
Commands.new_command("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:add_param("amount", "integer-range", -1, 10)
:add_alias("pl")
Commands.new("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:argument("amount", "", Commands.types.integer_range(-1, 10))
:add_aliases{ "pl" }
:register(function(player, amount)
--- @cast amount number
if player.force.technologies["logistic-robotics"].researched then
if player.selected ~= nil then
if player.selected.name == "spidertron" then
pl("s", player.selected, amount / 10)
return Commands.success
end
else
pl("p", player, amount / 10)
return Commands.success
end
else
player.print("Personal Logistic not researched")
return Commands.status.error("Personal Logistic not researched")
end
end)

View File

@@ -3,7 +3,7 @@
@data Quickbar
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @dep config.preset_player_quickbar
--- Stores the quickbar filters for a player
@@ -32,7 +32,7 @@ PlayerFilters:on_load(function(player_name, filters)
end
end)
local ignoredItems = {
local ignored_items = {
["blueprint"] = true,
["blueprint-book"] = true,
["deconstruction-planner"] = true,
@@ -41,9 +41,8 @@ local ignoredItems = {
}
--- Saves your quickbar preset to the script-output folder
-- @command save-quickbar
Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file")
:add_alias("save-toolbar")
Commands.new("save-quickbar", "Saves your Quickbar preset items to file")
:add_aliases{ "save-toolbar" }
:register(function(player)
local filters = {}
@@ -51,7 +50,7 @@ Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file"
local slot = player.get_quick_bar_slot(i)
-- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data
if slot ~= nil then
local ignored = ignoredItems[slot.name]
local ignored = ignored_items[slot.name]
if ignored ~= true then
filters[i] = slot.name
end
@@ -64,5 +63,5 @@ Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file"
PlayerFilters:remove(player)
end
return { "quickbar.saved" }
return Commands.status.success{ "quickbar.saved" }
end)

View File

@@ -3,11 +3,8 @@
@data Tag
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
require("modules.exp_legacy.config.expcore.command_general_parse")
require("modules.exp_legacy.config.expcore.command_role_parse")
require("modules.exp_legacy.config.expcore.command_color_parse")
--- Stores the tag for a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -47,42 +44,39 @@ PlayerTagColors:on_update(function(player_name, player_tag_color)
end)
--- Sets your player tag.
-- @command tag
-- @tparam string tag the tag that will be after the name, there is a max length
Commands.new_command("tag", "Sets your player tag.")
:add_param("tag", false, "string-max-length", 20)
:enable_auto_concat()
Commands.new("tag", "Sets your player tag.")
:argument("tag", "", Commands.types.string_max_length(20))
:enable_auto_concatenation()
:register(function(player, tag)
--- @cast tag string
PlayerTags:set(player, tag)
end)
--- Sets your player tag color.
-- @command tag
-- @tparam string color name.
Commands.new_command("tag-color", "Sets your player tag color.")
:add_param("color", false, "color")
:enable_auto_concat()
Commands.new("tag-color", "Sets your player tag color.")
:argument("color", "", Commands.types.color)
:enable_auto_concatenation()
:register(function(player, color)
--- @cast color Color
PlayerTagColors:set(player, color)
end)
--- Clears your tag. Or another player if you are admin.
-- @command tag-clear
-- @tparam[opt=self] LuaPlayer player the player to remove the tag from, nil will apply to self
Commands.new_command("tag-clear", "Clears your tag. Or another player if you are admin.")
:add_param("player", true, "player-role")
:set_defaults{ player = function(player)
return player -- default is the user using the command
end }
:register(function(player, action_player)
if action_player.index == player.index then
-- no player given so removes your tag
PlayerTags:remove(action_player)
Commands.new("tag-clear", "Clears your tag. Or another player if you are admin.")
:optional("player", "", Commands.types.lower_role_player)
:defaults{
player = function(player) return player end
}
:register(function(player, other_player)
--- @cast other_player LuaPlayer
if other_player == player then
-- No player given so removes your tag
PlayerTags:remove(other_player)
elseif Roles.player_allowed(player, "command/clear-tag/always") then
-- player given and user is admin so clears that player's tag
PlayerTags:remove(action_player)
-- Player given and user is admin so clears that player's tag
PlayerTags:remove(other_player)
else
-- user is not admin and tried to clear another users tag
return Commands.error{ "expcore-commands.unauthorized" }
-- User is not admin and tried to clear another users tag
return Commands.status.unauthorised()
end
end)