Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiworld support #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions R/getCurrentWorld.R
Original file line number Diff line number Diff line change
@@ -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

}
34 changes: 34 additions & 0 deletions R/getPlayerWorld.R
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions R/getWorlds.R
Original file line number Diff line number Diff line change
@@ -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]]

}
37 changes: 37 additions & 0 deletions R/setWorld.R
Original file line number Diff line number Diff line change
@@ -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

}




}