Interface DocumentViewBuilder
When creating a document view, if more than 1 player is specified, then it's required that
setSpawnLocation(Location)
also be set explicitly.
This is because the system for automatically determining for where to spawn a page only works
if there's exactly 1 player in the getPlayers()
player set.
If it's empty, then it doesn't know where to spawn, if there's more than 1, then it's not
possible to know which player it should be spawned in front of, as the players may be in
different locations and different worlds on the server.
-
Method Summary
Modifier and TypeMethodDescriptionaddPlayer
(@NotNull org.bukkit.entity.Player player) Add a player to the resulting view.addPlayers
(@NotNull Collection<org.bukkit.entity.Player> players) Add players that resulting view will be visible and interactable to.Make the resulting view visible to all online players.@Nullable String
Get the currently set instance name.@Nullable ResourcePath
getPath()
Get the path the request will be sent toGet the player the opened document will be linked to.@Nullable org.bukkit.Location
Get the set spawn location for the opened document.open()
Attempts to open the document specified bygetPath()
and show it to thegetPlayers()
.Invokesopen()
and if an erroneous result is returned, it is logged and an empty optional returned.Invokesopen()
and if an erroneous result is returned, the exception is thrown.setInstanceName
(@Nullable String instanceName) Set the instance name of the view.setPath
(@NotNull ResourcePath path) Set the resource path the document will be fetched from.Set the resource path the document will be fetched from.setPlayer
(@NotNull org.bukkit.entity.Player player) Set the player the opened document will be linked to.setPlayers
(@NotNull Collection<org.bukkit.entity.Player> players) Set the players that resulting view will be visible and interactable to.setSpawnLocation
(@Nullable org.bukkit.Location location) Set the spawn location of the opened document.
-
Method Details
-
getPath
Get the path the request will be sent to- Returns:
- Request path
-
setPath
Set the resource path the document will be fetched from.- Parameters:
path
- Document resource path- Returns:
this
- Throws:
NullPointerException
- Ifpath
isnull
-
setPath
Set the resource path the document will be fetched from.Shorthand for calling
setPath(ResourcePath)
andDelphi.parsePath(String)
- Parameters:
path
- Document resource path- Returns:
this
- Throws:
NullPointerException
- Ifpath
isnull
.DelphiException
- (With Error codeDelphiException.ERR_INVALID_PATH
) If thepath
cannot be parsed.
-
getInstanceName
Get the currently set instance name.Instance names are unique names given to each page used to differentiate them from other open pages of the same module or same resource path.
- Returns:
- Instance name
-
setInstanceName
Set the instance name of the view.Instance names are unique names given to each page used to differentiate them from other open pages of the same module or same resource path.
- Parameters:
instanceName
- New instance name- Returns:
this
-
getPlayers
PlayerSet getPlayers()Get the player the opened document will be linked to.Unless any of the player set methods have been called, this will return a set of all online players.
- Returns:
- Request player.
-
setPlayer
Set the player the opened document will be linked to.If there are any other players in the
getPlayers()
set, then they will be removed and only the specified player will be in that set.- Parameters:
player
- player- Returns:
this
- Throws:
NullPointerException
- Ifplayer
isnull
-
setPlayers
Set the players that resulting view will be visible and interactable to.- Parameters:
players
- Player collection- Returns:
this
- Throws:
NullPointerException
- Ifplayers
, or any element inplayers
isnull
-
addPlayers
Add players that resulting view will be visible and interactable to.If
allPlayers()
has been called before this, then this acts identically tosetPlayers(Collection)
.- Parameters:
players
- Player collection- Returns:
this
- Throws:
NullPointerException
- Ifplayers
, or any element inplayers
isnull
-
addPlayer
Add a player to the resulting view.Adding a player to the view means the player can see and use the document page.
If
allPlayers()
has been called, this method acts identically tosetPlayer(Player)
.- Parameters:
player
- Player- Returns:
this
- Throws:
NullPointerException
- Ifplayer
isnull
- See Also:
-
allPlayers
DocumentViewBuilder allPlayers()Make the resulting view visible to all online players.This means the resulting view will be shown to all players and can be used by all players.
- Returns:
this
-
getSpawnLocation
@Nullable @Nullable org.bukkit.Location getSpawnLocation()Get the set spawn location for the opened document.If this is not set, the document will be spawned in front of the player, facing the player.
- Returns:
- Document spawn location
-
setSpawnLocation
Set the spawn location of the opened document.If set to null, then the document will be spawned in front of the player, facing the player.
- Parameters:
location
- Spawn location- Returns:
this
-
open
Attempts to open the document specified bygetPath()
and show it to thegetPlayers()
.Uses
DelphiResources.findModule(String)
to find the module of thegetPath()
, then creates aViewResources
object with the module and attempts to callViewResources.loadDocument(String)
with the path given to this method.If the document is successfully loaded and initialized, it is spawned and then shown to the players, and the created document view is returned.
Any erroneous result returned by this method will have an error code dictated by either the
DelphiResources.findModule(String)
orViewResources.loadDocument(String)
methods.Special error codes Error code Description ERR_INSTANCE_NAME_USED
The specified getInstanceName()
is already in useERR_ILLEGAL_INSTANCE_NAME
The specified getInstanceName()
is not allowed
Most likely because its usage would interfere with a command.- Returns:
- The opened view, or an error result explaining why the document couldn't be opened.
- Throws:
NullPointerException
- IfgetPath()
is unsetIllegalStateException
- IfgetPlayers()
does not contain exactly 1 player, and nogetSpawnLocation()
has been set.
This means if the player set is empty, or contains more than 1 player, the system cannot figure out where to spawn the page by itself, and requires a spawn location to be set.
-
openOrThrow
Invokesopen()
and if an erroneous result is returned, the exception is thrown.- Returns:
- Opened document view.
- Throws:
DelphiException
- If the document failed to be opened for any reasonNullPointerException
- IfgetPath()
is unsetIllegalStateException
- IfgetPlayers()
does not contain exactly 1 player, and nogetSpawnLocation()
has been set.
This means if the player set is empty, or contains more than 1 player, the system cannot figure out where to spawn the page by itself, and requires a spawn location to be set.
-
openOrLog
Invokesopen()
and if an erroneous result is returned, it is logged and an empty optional returned. If theopen()
invocation succeeds, an optional containing the opened view is returned.- Returns:
- View optional
- Throws:
NullPointerException
- IfgetPath()
is unsetIllegalStateException
- IfgetPlayers()
does not contain exactly 1 player, and nogetSpawnLocation()
has been set.
This means if the player set is empty, or contains more than 1 player, the system cannot figure out where to spawn the page by itself, and requires a spawn location to be set.
-