diff --git a/R/getCurrentWorld.R b/R/getCurrentWorld.R new file mode 100644 index 0000000..d554c6c --- /dev/null +++ b/R/getCurrentWorld.R @@ -0,0 +1,24 @@ +#' Get the name of the current world. +#' +#' @return the current world miner uses is working in. +#' +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' currentWorld <- getCurrentWorld() +#' playerWorld <- getPlayerWorld() +#' if(currentWorld != playerWorld){ +#' setWorld(playerWorld) +#' } +#' +#' } +#' @seealso [getPlayerWorld()], [getWorlds()] and [setWorld()] +#' +#' @export +getCurrentWorld <- function() +{ + out <- mc_sendreceive("getCurrentWorld()") + out + +} diff --git a/R/getPlayerWorld.R b/R/getPlayerWorld.R new file mode 100644 index 0000000..6d4ecac --- /dev/null +++ b/R/getPlayerWorld.R @@ -0,0 +1,34 @@ +#' Get player world +#' +#' Get player world. The default is to get the world of the first player spawned +#' in the game, but the world of other players can be gotten using the +#' `player_id` argument. +#' +#' @param player_id Integer giving the ID of a player. You can find IDs of all +#' current players using [getPlayerIds()]. +#' +#' @return The worldname a player is in. +#' +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' getPlayerWorld() +#' +#' player <- getPlayerIds()[1] +#' getPlayerWorld(player) +#' } +#' +#' @seealso [getWorlds()] and [setWorld()] +#' +#' @export +getPlayerWorld <- function(player_id = NULL) +{ + + if(is.null(player_id)){ + out <- mc_sendreceive("player.getWorld()") + } else { + out <- mc_sendreceive(merge_data("player.getWorld", player_id)) + } + out +} diff --git a/R/getWorlds.R b/R/getWorlds.R new file mode 100644 index 0000000..4190d07 --- /dev/null +++ b/R/getWorlds.R @@ -0,0 +1,20 @@ +#' Get a vector of all worlds recognized by Spigot. +#' +#' @return A vector containing all worlds recognized by Spigot. +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' worlds <- getWorlds() +#' setWorld(worlds[1]) +#' } +#' @seealso [getPlayerWorld()], [getCurrentWorld()] and [setWorld()] +#' +#' @export +getWorlds <- function() +{ + result <- mc_sendreceive("getWorlds()") + out <- strsplit(result, split = ',') + out[[1]] + +} diff --git a/R/setWorld.R b/R/setWorld.R new file mode 100644 index 0000000..62a7bb2 --- /dev/null +++ b/R/setWorld.R @@ -0,0 +1,37 @@ +#' Set world +#' +#' Get the world that miner uses for its locations. The default is the "normal" overworld, +#' but by using this command with a worldname as parameter, the world that is used for locations gets changed +#' +#' @param world The world you want to change to. You can find IDs of all +#' worlds using [getWorlds()], or the world a player is in by using [player.getWorld()]. +#' +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' world <- getPlayerWorld() +#' setWorld(world) +#' +#' } +#' +#' @seealso [getWorlds()], [getCurrentWorld()] and [player.getWorld()] +#' +#' @export +setWorld <- function(world) +{ + if (is.null(world) || is.na(world)){ + + "[error]: no input given!" + + } else { + + out <- mc_sendreceive(merge_data("setWorld", world)) + out + + } + + + + +}