Interface CoordinateOffsetAPI
External plugins may get a singleton instance of this API via CoordinateOffset.api().
-
Method Summary
Modifier and TypeMethodDescriptionadaptLocation(Object platformLocationObject) Adapt a platform-specific location object (such as a BukkitLocation) into anOffsetLocation.adaptPlayer(Object platformPlayerObject) Adapt a platform-specific player object (such as a BukkitPlayer) into anOffsetPlayer.Get running configuration of the CoordinateOffset plugin.getOffset(OffsetPlayer player) Get the currently active coordinateOffsetfor a player.getOffsetData(OffsetPlayer player) Get information about a player's current offset, including the source from where the offset came and the context from which the offset was generated.@Nullable OffsetPlayerGet anOffsetPlayerinstance for a player currently connected to the server by their UUID.Get Offset Providers configured in the CoordinateOffset configuration.regenerateOffset(OffsetPlayer player) Immediately regenerate the player's current offset by selecting a new offset from the applicably configured offset provider.voidregisterOffsetProviderClass(String className, Function<OffsetProviderConfig, OffsetProvider> deserializeFunction) Register a new OffsetProvider class that can be used in the CoordinateOffset configuration.setOffset(OffsetPlayer player, Offset offset) Immediately set the player's current offset.
-
Method Details
-
getOffset
Get the currently active coordinateOffsetfor a player.Offsets are subtracted from a player's real coordinates to determine the coordinates they see. As an example, a player might have a coordinate offset of
Similarly, if the player moves to the world's origin(128, 128). This would mean that the player standing at(128, 128)sees that they are standing at(0, 0)in the "F3" menu.(0, 0), they would see in "F3" that they are standing at(-128, -128).This Offset is subject to change, for example if the Player changes worlds.
This method is safe to call from any thread.
- Parameters:
player- A player currently logged in to the server. UseadaptPlayer(Object)to convert a platform-specific instance (such as a BukkitPlayer) to anOffsetPlayer, orgetPlayer(UUID)to get a player by their UUID.- Returns:
- The coordinate offset this player sees, or
Offset.ZEROif the player has no offset. - See Also:
-
getOffsetData
Get information about a player's current offset, including the source from where the offset came and the context from which the offset was generated.This method is safe to call from any thread.
- Parameters:
player- A player currently logged in to the server. UseadaptPlayer(Object)to convert a platform-specific instance (such as a BukkitPlayer) to anOffsetPlayer, orgetPlayer(UUID)to get a player by their UUID.- Returns:
- A container for all known data about the player's current offset.
-
regenerateOffset
Immediately regenerate the player's current offset by selecting a new offset from the applicably configured offset provider. This forces a teleport effect on the player if their offset is changed, but it does not move them in real coordinate space.This method must only be called on the main server thread.
- Parameters:
player- A player currently logged in to the server. UseadaptPlayer(Object)to convert a platform-specific instance (such as a BukkitPlayer) to anOffsetPlayer, orgetPlayer(UUID)to get a player by their UUID.- Returns:
- A container with the player's previous and new offset, which can be inspected to determine if the offset was changed.
-
setOffset
Immediately set the player's current offset. This forces a teleport effect on the player if their offset is changed, but it does not move them in real coordinate space.Use of this function is discouraged because any applied offset will be lost as soon as the player's offset has a chance to change. This means any teleport, world change, or relog will undo the offset applied here. This is the case even if
regenerateOn*options in the configuration are set to false.To apply an offset that persists, instead register an
OffsetProviderwithregisterOffsetProviderClass(java.lang.String, java.util.function.Function<com.jtprince.coordinateoffset.provider.OffsetProviderConfig, com.jtprince.coordinateoffset.provider.OffsetProvider>), apply the offset provider in the plugin's configuration, and callregenerateOffset(com.jtprince.coordinateoffset.adapter.OffsetPlayer). Return the desired offset in your offset provider, and that offset will continue to be applied every time the player's offset might change.This method must only be called on the main server thread.
- Parameters:
player- A player currently logged in to the server. UseadaptPlayer(Object)to convert a platform-specific instance (such as a BukkitPlayer) to anOffsetPlayer, orgetPlayer(UUID)to get a player by their UUID.offset- The new offset to apply.- Returns:
- A container with the player's previous and new offset, which can be inspected to determine if the offset was changed.
-
getPlayer
Get anOffsetPlayerinstance for a player currently connected to the server by their UUID.- Parameters:
playerUuid- The UUID of a player currently connected to the server.- Returns:
- An OffsetPlayer instance for the player, or null if no matching player is connected.
-
adaptPlayer
Adapt a platform-specific player object (such as a BukkitPlayer) into anOffsetPlayer.This method is safe to call from any thread.
- Parameters:
platformPlayerObject- A platform-specific player object. The exact type depends on the platform adapter in use. For example, on a Paper server, this would be an instance oforg.bukkit.entity.Player.- Returns:
- An OffsetPlayer instance for the player.
- Throws:
ClassCastException- if the provided object is not of the expected type for the running platform.
-
adaptLocation
Adapt a platform-specific location object (such as a BukkitLocation) into anOffsetLocation.This method is safe to call from any thread.
- Parameters:
platformLocationObject- A platform-specific location object. The exact type depends on the platform adapter in use. For example, on a Paper server, this would be an instance oforg.bukkit.Location.- Returns:
- An OffsetLocation instance for the location.
- Throws:
ClassCastException- if the provided object is not of the expected type for the running platform.
-
getConfig
CoordinateOffsetConfig getConfig()Get running configuration of the CoordinateOffset plugin.Configured Offset Providers are not accessible here because they load after the main CoordinateOffset config. See
getProviderConfig()for provider-specific configuration access.- Returns:
- The current configuration.
-
getProviderConfig
CoordinateOffsetProviderConfig getProviderConfig()Get Offset Providers configured in the CoordinateOffset configuration.Offset Providers load after external plugins have a chance to register new OffsetProvider classes, so this function must only be called after the server has finished starting up.
See
getConfig()for general configuration access.- Returns:
- The current configuration.
- Throws:
IllegalStateException- if Offset Provider configuration has not yet been loaded.
-
registerOffsetProviderClass
void registerOffsetProviderClass(String className, Function<OffsetProviderConfig, OffsetProvider> deserializeFunction) Register a new OffsetProvider class that can be used in the CoordinateOffset configuration.- Parameters:
className- A class name to identify the provider in the configuration. Users may activate this provider by creating a provider in the CoordinateOffset config.yml with aclass:parameter matching this name. This should be a simple string matching the class name of the provider, for example"MyOffsetProvider".deserializeFunction- A function that can create instances of the provider from configuration data. For examples, see the built-in providers.
-