This commit is contained in:
2023-02-22 16:40:08 +01:00
parent 6f310de32e
commit a6bde9e191
5 changed files with 87 additions and 15 deletions

View File

@@ -74,14 +74,46 @@ public interface AbstractOffPlayer {
* Player config
*/
/**
* Gets the value of the provided configuration key of this player.
* @param key the configuration key.
* @return the value of the configuration, or null if the configuration is not set.
* @throws Exception if an error occurs fetching the configuration value.
*/
String getConfig(String key) throws Exception;
/**
* Gets the value of the provided configuration key of this player.
* @param key the configuration key.
* @param deflt the default value if the configuration is not set.
* @return the value of the configuration, or {@code deflt} if the configuration is not set.
* @throws Exception if an error occurs fetching the configuration value.
*/
String getConfig(String key, String deflt) throws Exception;
/**
* Sets the value of the provided configuration key for this player.
* @param key the configuration key to set.
* @param value the new value.
* @throws Exception if an error occurs updating the configuration value.
*/
void setConfig(String key, String value) throws Exception;
/**
* Updates the value of the provided configuration key for this player, using the provided updater.
* @param key the configuration key to update.
* @param deflt the default value to use if the configuration is not already set.
* @param updater the unary operator to use to update th value. The old value is used as the parameter of the updater,
* and it returns the new value of the configuration.
* @throws Exception if an error occurs updating the configuration value.
*/
void updateConfig(String key, String deflt, UnaryOperator<String> updater) throws Exception;
/**
* Unsets the value of the provided configuration key for this player.
* @param key the configuration key to update.
* @throws Exception if an error occurs deleting the configuration value.
*/
void unsetConfig(String key) throws Exception;

View File

@@ -122,6 +122,7 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
* The default implementation returns all the players.
* Concrete subclasses should override this method, especially
* on Paper server, using the {@code Player.canSee(Player)} API.
* @param viewer the player to test visibility on.
* @return the players that the provided player can see.
*/
public List<OP> getOnlyVisibleFor(OF viewer) {
@@ -130,10 +131,10 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
/**
* Get all the players that the provided player can see.
* The default implementation returns all the players.
* Concrete subclasses should override this method, especially
* on Paper server, using the {@code Player.canSee(Player)} API.
* Uses {@link #getOnlyVisibleFor(AbstractOffPlayer)}.
* @param viewer the player to test visibility on.
* @return the players that the provided player can see.
* @see #getOnlyVisibleFor(AbstractOffPlayer)
*/
public List<String> getNamesOnlyVisible(OF viewer) {
return getOnlyVisibleFor(viewer).stream()