From d794703206a5c3f251b6468ebebc63546211668f Mon Sep 17 00:00:00 2001 From: nicerman1 Date: Sat, 4 Jul 2020 17:51:05 +0200 Subject: [PATCH 1/4] Added world commands Added getPlayerWorld, getWorlds and setWorld --- R/getPlayerWorld.R | 34 ++++++++++++++++++++++++++++++++++ R/getWorlds.R | 23 +++++++++++++++++++++++ R/setWorld.R | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 R/getPlayerWorld.R create mode 100644 R/getWorlds.R create mode 100644 R/setWorld.R diff --git a/R/getPlayerWorld.R b/R/getPlayerWorld.R new file mode 100644 index 0000000..83e88ff --- /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 world a player is in. +#' +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' getPlayerWorld() +#' +#' example_entity <- getPlayerIds()[1] +#' getPlayerWorld(example_entity) +#' } +#' +#' @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..028a4db --- /dev/null +++ b/R/getWorlds.R @@ -0,0 +1,23 @@ +#' 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()] and [setWorld()] +#' +#' @export +getWorlds <- function() +{ + result <- mc_sendreceive("getWorlds()") + result <- gsub("\\[", "", result) + result <- gsub("\\]", "", result) + out <- strsplit(result, split = ', ') + out[[1]] + +} diff --git a/R/setWorld.R b/R/setWorld.R new file mode 100644 index 0000000..1dff4d9 --- /dev/null +++ b/R/setWorld.R @@ -0,0 +1,37 @@ +#' Set world +#' +#' Get the world miner uses for its locations. The default is the "normal" overworld, +#' but by using this command with a world as parameter, the world that's used for locations changes +#' +#' @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()] and [player.getWorld()] +#' +#' @export +setWorld <- function(world) +{ + if (is.null(world) || is.na(world)){ + + "[error]: no input given!" + + } else { + + mc_send(merge_data("setWorld()", world)) + cat("set world to", world , "\n") + + } + + + + +} From 467e1c3a446ff76d02e9b48beec5820fe81b8956 Mon Sep 17 00:00:00 2001 From: nicerman1 Date: Sun, 5 Jul 2020 14:44:41 +0200 Subject: [PATCH 2/4] Update setWorld.R Fixed output aswell as a weird formatting bug (had to remove parenthesis when using the merge_data function) --- R/setWorld.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/setWorld.R b/R/setWorld.R index 1dff4d9..4afd4f8 100644 --- a/R/setWorld.R +++ b/R/setWorld.R @@ -26,9 +26,9 @@ setWorld <- function(world) } else { - mc_send(merge_data("setWorld()", world)) - cat("set world to", world , "\n") - + out <- mc_sendreceive(merge_data("setWorld", world)) + out + } From 45f8970a0d7b6792173b3a66ba42e6095155c772 Mon Sep 17 00:00:00 2001 From: nicerman1 Date: Sun, 5 Jul 2020 23:08:23 +0200 Subject: [PATCH 3/4] Update getWorlds.R --- R/getWorlds.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/getWorlds.R b/R/getWorlds.R index 028a4db..43be4cc 100644 --- a/R/getWorlds.R +++ b/R/getWorlds.R @@ -15,9 +15,7 @@ getWorlds <- function() { result <- mc_sendreceive("getWorlds()") - result <- gsub("\\[", "", result) - result <- gsub("\\]", "", result) - out <- strsplit(result, split = ', ') + out <- strsplit(result, split = ',') out[[1]] } From 3360caaa20e546262c54fbcf8e9fed3146e8099c Mon Sep 17 00:00:00 2001 From: nicerman1 Date: Mon, 6 Jul 2020 11:16:15 +0200 Subject: [PATCH 4/4] Added getCurrentWorld() command Added getCurrentWorld() command as well as polishing the documentation a bit --- R/getCurrentWorld.R | 24 ++++++++++++++++++++++++ R/getPlayerWorld.R | 6 +++--- R/getWorlds.R | 3 +-- R/setWorld.R | 6 +++--- 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 R/getCurrentWorld.R 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 index 83e88ff..6d4ecac 100644 --- a/R/getPlayerWorld.R +++ b/R/getPlayerWorld.R @@ -7,7 +7,7 @@ #' @param player_id Integer giving the ID of a player. You can find IDs of all #' current players using [getPlayerIds()]. #' -#' @return The world a player is in. +#' @return The worldname a player is in. #' #' #' @examples @@ -15,8 +15,8 @@ #' mc_connect() #' getPlayerWorld() #' -#' example_entity <- getPlayerIds()[1] -#' getPlayerWorld(example_entity) +#' player <- getPlayerIds()[1] +#' getPlayerWorld(player) #' } #' #' @seealso [getWorlds()] and [setWorld()] diff --git a/R/getWorlds.R b/R/getWorlds.R index 43be4cc..4190d07 100644 --- a/R/getWorlds.R +++ b/R/getWorlds.R @@ -2,14 +2,13 @@ #' #' @return A vector containing all worlds recognized by Spigot. #' -#' #' @examples #' \dontrun{ #' mc_connect() #' worlds <- getWorlds() #' setWorld(worlds[1]) #' } -#' @seealso [getPlayerWorld()] and [setWorld()] +#' @seealso [getPlayerWorld()], [getCurrentWorld()] and [setWorld()] #' #' @export getWorlds <- function() diff --git a/R/setWorld.R b/R/setWorld.R index 4afd4f8..62a7bb2 100644 --- a/R/setWorld.R +++ b/R/setWorld.R @@ -1,7 +1,7 @@ #' Set world #' -#' Get the world miner uses for its locations. The default is the "normal" overworld, -#' but by using this command with a world as parameter, the world that's used for locations changes +#' 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()]. @@ -15,7 +15,7 @@ #' #' } #' -#' @seealso [getWorlds()] and [player.getWorld()] +#' @seealso [getWorlds()], [getCurrentWorld()] and [player.getWorld()] #' #' @export setWorld <- function(world)