mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Added the server give command.
This commit is contained in:
parent
c9ef119692
commit
4689fdcb2c
@ -118,7 +118,7 @@ _msm() {
|
||||
__init_server "${COMP_WORDS[1]}"
|
||||
|
||||
if [[ $COMP_CWORD == 2 ]]; then
|
||||
options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall save cmd cmdlog"
|
||||
options="start stop restart status connected worlds logroll backup jar whitelist blacklist operator gamemode kick say time toggledownfall give xp save cmd cmdlog console"
|
||||
else
|
||||
case "${COMP_WORDS[2]}" in
|
||||
stop|restart)
|
||||
|
73
init/msm
73
init/msm
@ -25,7 +25,7 @@ CONF="${MSM_CONF:-/etc/msm.conf}"
|
||||
|
||||
|
||||
### The Minecraft Server Manager version, use "msm version" to check yours.
|
||||
VERSION="0.3.4 Beta"
|
||||
VERSION="0.3.4"
|
||||
|
||||
|
||||
### Config variables the user should not need/want to change
|
||||
@ -1232,7 +1232,13 @@ command_restart_now() {
|
||||
|
||||
# Displays the MSM version
|
||||
command_version() {
|
||||
echo "Minecraft Server Manager $VERSION"
|
||||
local version="$VERSION"
|
||||
|
||||
if [ "${version:0:1}" -eq 0 ]; then
|
||||
version="$version Beta"
|
||||
fi
|
||||
|
||||
echo "Minecraft Server Manager $version"
|
||||
}
|
||||
|
||||
# Displays a list of servers
|
||||
@ -1338,10 +1344,13 @@ command_help() {
|
||||
echo -e " <server> say <message> Broadcast a (pink) message to all players on a server"
|
||||
echo -e " <server> time set|add <number> Set/increment time on a server (0-24000)"
|
||||
echo -e " <server> toggledownfall Toggles rain and snow on a server"
|
||||
echo -e " <server> give <player> <item> [amount] [data] Gives an entity to a player"
|
||||
# echo -e " <server> xp <player> <amount> Gives XP to, or takes away (when negative) XP from, a player"
|
||||
echo -e " <server> save on|off Enable/disable writing world changes to file"
|
||||
echo -e " <server> save all Force the writing of all non-saved world changes to file"
|
||||
echo -e " <server> cmd <command> Send a command string to the server and return"
|
||||
echo -e " <server> cmdlog <command> Same as 'cmd' but shows log output afterwards (Ctrl+C to exit)"
|
||||
echo -e " <server> console Connects to the interactive console. Access may be limited"
|
||||
echo -e
|
||||
echo -e "--Jar Commands--------------------------------------------------"
|
||||
echo -e " jargroup list List the stored jar files."
|
||||
@ -1857,6 +1866,47 @@ command_server_toggledownfall() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Gives entities to players in game
|
||||
# $1: The server ID
|
||||
# $2: The player name
|
||||
# $3: The entity id/name
|
||||
# $4: The amount to give
|
||||
# $5: The entity damage value
|
||||
command_server_give() {
|
||||
if server_is_running "$1"; then
|
||||
local line regex
|
||||
line="$(server_eval_and_get_line "$1" "give $2 $3 $4 $5" "${SERVER_CONFIRM_GIVE[$1]}" "${SERVER_CONFIRM_GIVE_FAIL_NO_USER[$1]}" "${SERVER_CONFIRM_GIVE_FAIL_NO_ITEM[$1]}")"
|
||||
|
||||
regex="${LOG_REGEX} ${SERVER_CONFIRM_GIVE[$1]}"
|
||||
if [[ "$line" =~ $regex ]]; then
|
||||
echo "${line}"
|
||||
fi
|
||||
regex="${LOG_REGEX} ${SERVER_CONFIRM_GIVE_FAIL_NO_USER[$1]}"
|
||||
if [[ "$line" =~ $regex ]]; then
|
||||
echo "${line}"
|
||||
fi
|
||||
regex="${LOG_REGEX} ${SERVER_CONFIRM_GIVE_FAIL_NO_ITEM[$1]}"
|
||||
if [[ "$line" =~ $regex ]]; then
|
||||
echo "${line}"
|
||||
fi
|
||||
else
|
||||
error_exit SERVER_STOPPED "Server \"${SERVER_NAME[$1]}\" is not running."
|
||||
fi
|
||||
}
|
||||
|
||||
# Gives XP to a player in game
|
||||
# $1: The server ID
|
||||
# $2: The player name
|
||||
# $3: The amount of XP to give (can be negative)
|
||||
# command_server_xp() {
|
||||
# if server_is_running "$1"; then
|
||||
# local line regex
|
||||
# line="$(server_eval_and_get_line "$1" "xp $2 $3" "${SERVER_CONFIRM_XP[$1]}")"
|
||||
# else
|
||||
# error_exit SERVER_STOPPED "Server \"${SERVER_NAME[$1]}\" is not running."
|
||||
# fi
|
||||
# }
|
||||
|
||||
# Turns world saving on for an individual server
|
||||
# $1: The server ID
|
||||
command_server_save_on() {
|
||||
@ -2048,6 +2098,9 @@ server_load_config() {
|
||||
msm-confirm-gamemode) SERVER_CONFIRM_GAMEMODE[$1]="$value";;
|
||||
msm-confirm-gamemode-fail-no-user) SERVER_CONFIRM_GAMEMODE_FAIL_NO_USER[$1]="$value";;
|
||||
msm-confirm-gamemode-fail-no-change) SERVER_CONFIRM_GAMEMODE_FAIL_NO_CHANGE[$1]="$value";;
|
||||
msm-confirm-give) SERVER_CONFIRM_GIVE[$1]="$value";;
|
||||
msm-confirm-give-fail-no-user) SERVER_CONFIRM_GIVE_FAIL_NO_USER[$1]="$value";;
|
||||
msm-confirm-give-fail-no-item) SERVER_CONFIRM_GIVE_FAIL_NO_ITEM[$1]="$value";;
|
||||
esac
|
||||
done < "${SERVER_CONF[$1]}"
|
||||
fi
|
||||
@ -2097,6 +2150,7 @@ server_init() {
|
||||
SERVER_WORLD_BACKUP_FINISHED[$1]="$DEFAULT_WORLD_BACKUP_FINISHED"
|
||||
SERVER_COMPLETE_BACKUP_STARTED[$1]="$DEFAULT_COMPLETE_BACKUP_STARTED"
|
||||
SERVER_COMPLETE_BACKUP_FINISHED[$1]="$DEFAULT_COMPLETE_BACKUP_FINISHED"
|
||||
SERVER_COMPLETE_BACKUP_FOLLOW_SYMLINKS[$1]="$DEFAULT_COMPLETE_BACKUP_FOLLOW_SYMLINKS"
|
||||
SERVER_CONFIRM_SAVE_ON[$1]="$DEFAULT_CONFIRM_SAVE_ON"
|
||||
SERVER_CONFIRM_SAVE_OFF[$1]="$DEFAULT_CONFIRM_SAVE_OFF"
|
||||
SERVER_CONFIRM_SAVE_ALL[$1]="$DEFAULT_CONFIRM_SAVE_ALL"
|
||||
@ -2112,7 +2166,9 @@ server_init() {
|
||||
SERVER_CONFIRM_GAMEMODE[$1]="$DEFAULT_CONFIRM_GAMEMODE"
|
||||
SERVER_CONFIRM_GAMEMODE_FAIL_NO_USER[$1]="$DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_USER"
|
||||
SERVER_CONFIRM_GAMEMODE_FAIL_NO_CHANGE[$1]="$DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_CHANGE"
|
||||
SERVER_COMPLETE_BACKUP_FOLLOW_SYMLINKS[$1]="$DEFAULT_COMPLETE_BACKUP_FOLLOW_SYMLINKS"
|
||||
SERVER_CONFIRM_GIVE[$1]="$DEFAULT_CONFIRM_GIVE"
|
||||
SERVER_CONFIRM_GIVE_FAIL_NO_USER[$1]="$DEFAULT_CONFIRM_GIVE_FAIL_NO_USER"
|
||||
SERVER_CONFIRM_GIVE_FAIL_NO_ITEM[$1]="$DEFAULT_CONFIRM_GIVE_FAIL_NO_ITEM"
|
||||
|
||||
|
||||
# Load config overrides from server config file if present
|
||||
@ -2182,7 +2238,7 @@ server_init() {
|
||||
# $1: The name of the variable to test
|
||||
assert_is_set_in_config() {
|
||||
[[ ! ${!1} && ${!1-_} ]] && {
|
||||
error_exit CONF_ERROR "$1 must be set in $CONF"
|
||||
error_exit CONF_ERROR "Have you recently upgraded? \"$1\" is a new required setting, and must be set in $CONF. See https://raw.github.com/marcuswhybrow/minecraft-server-manager/${VERSION}/msm.conf and look for the line starting with \"$1\". Add this line to your settings. Sorry about this... A better sollution for upgrading is being worked on."
|
||||
}
|
||||
}
|
||||
|
||||
@ -2239,6 +2295,9 @@ init_ensure_settings() {
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GAMEMODE
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_USER
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_CHANGE
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GIVE
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GIVE_FAIL_NO_USER
|
||||
assert_is_set_in_config DEFAULT_CONFIRM_GIVE_FAIL_NO_ITEM
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -2304,7 +2363,7 @@ register_command() {
|
||||
# Variables are denoted by angle brackets (e.g. "<variable>") and can
|
||||
# at this stage be accepted as any non-zero string
|
||||
if [[ "$word" =~ ^\<.*\>$ ]]; then
|
||||
regex="${regex}.+ "
|
||||
regex="${regex}([^ ]+|\".*\"|'.*') "
|
||||
continue
|
||||
fi
|
||||
|
||||
@ -2627,6 +2686,10 @@ main() {
|
||||
register_command "<name:server> time set <string>" "command_server_time_set"
|
||||
register_command "<name:server> time add <string>" "command_server_time_add"
|
||||
register_command "<name:server> toggledownfall|tdf" "command_server_toggledownfall"
|
||||
register_command "<name:server> give <string> <string>" "command_server_give"
|
||||
register_command "<name:server> give <string> <string> <string>" "command_server_give"
|
||||
register_command "<name:server> give <string> <string> <string> <string>" "command_server_give"
|
||||
# register_command "<name:server> xp <string> <string>" "command_server_xp"
|
||||
register_command "<name:server> save on" "command_server_save_on"
|
||||
register_command "<name:server> save off" "command_server_save_off"
|
||||
register_command "<name:server> save all" "command_server_save_all"
|
||||
|
9
msm.conf
9
msm.conf
@ -201,3 +201,12 @@ DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_USER="Can't find user .+"
|
||||
|
||||
# The message logged when a player is already in the specified game mode
|
||||
DEFAULT_CONFIRM_GAMEMODE_FAIL_NO_CHANGE=".+ already has game mode (1|0)"
|
||||
|
||||
# The message logged when a player is successfully given an entity
|
||||
DEFAULT_CONFIRM_GIVE="CONSOLE: Giving .+ some .+ (.+)"
|
||||
|
||||
# The message logged when a player cannot be found when using the give command
|
||||
DEFAULT_CONFIRM_GIVE_FAIL_NO_USER="Can't find user .+"
|
||||
|
||||
# The message logged when an item ID or name is invalid
|
||||
DEFAULT_CONFIRM_GIVE_FAIL_NO_ITEM="There's no item called .+"
|
Loading…
Reference in New Issue
Block a user