PandaLib/pandalib-players/src/main/java/fr/pandacube/lib/players/standalone/AbstractOnlinePlayer.java

298 lines
9.2 KiB
Java
Raw Normal View History

package fr.pandacube.lib.players.standalone;
2021-03-21 20:17:31 +01:00
import fr.pandacube.lib.chat.ChatStatic;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
2021-03-21 20:17:31 +01:00
import java.util.Locale;
import java.util.UUID;
/**
* Represents any online player.
*/
public interface AbstractOnlinePlayer extends AbstractOffPlayer {
2021-03-21 20:17:31 +01:00
/*
* General data and state
*/
2021-03-21 20:17:31 +01:00
/**
* Returns the name of the current server the player is in.
* The returned value is used by the 'pandalib-permissions' system.
* @return the name of the current server the player is in.
2021-03-21 20:17:31 +01:00
*/
String getServerName();
/**
* Returns the name of the current world the player is in.
* The returned value is used by the 'pandalib-permissions' system.
* @return the name of the current world the player is in.
*/
String getWorldName();
2021-03-21 20:17:31 +01:00
/*
* Permissions and groups
*/
/**
* Tells if this online player has the specified permission.
* @param permission the permission to test on that player.
* @return weither this player has the specified permission or not.
* @implSpec Implementation of this method should call the permission system of their environment (paper/bungee),
* so this method will work independently of the usage of the 'pandalib-permissions' module.
*/
boolean hasPermission(String permission);
2021-03-21 20:17:31 +01:00
2021-03-21 20:17:31 +01:00
2021-03-21 20:17:31 +01:00
2021-03-21 20:17:31 +01:00
/*
* Sending packet and stuff to player
*/
/**
* Display the provided message in the players chat, if the chat is activated.
* @param message the message to display.
*/
void sendMessage(Component message);
/**
* Display the provided message in the players chat, if the chat is activated.
* @param message the message to display.
*/
default void sendMessage(ComponentLike message) {
sendMessage(message.asComponent());
}
2021-03-21 20:17:31 +01:00
/**
* Display the provided message in the players chat, if they allows to display CHAT messages.
* @param message the message to display.
* @param sender the player causing the send of this message. Client side filtering may occur.
* May be null if we dont want client filtering, but still consider the message as CHAT message.
* @implNote implementation of this method should not filter the send of the message, based on
* the sender. This parameter is only there to be transmitted to the client, so client side filtering can
* be processed.
*/
void sendMessage(Component message, Identified sender);
/**
* Display the provided message in the players chat, if they allows to display CHAT messages.
* @param message the message to display
* @param sender the player causing the send of this message. Client side filtering may occur.
* May be null if we dont want client filtering, but still consider the message as CHAT message.
* @implNote implementation of this method should not filter the send of the message, based on
* the sender. This parameter is only there to be transmitted to the client, so client side filtering can
* be processed.
*/
default void sendMessage(ComponentLike message, UUID sender) {
sendMessage(message.asComponent(), () -> sender == null ? Identity.nil() : Identity.identity(sender));
}
2021-03-21 20:17:31 +01:00
/**
* Display the provided message in the players chat, if the chat is activated, prepended with the server prefix.
2021-03-21 20:17:31 +01:00
* @param message the message to display
*/
default void sendPrefixedMessage(ComponentLike message) {
sendMessage(ChatStatic.prefixedAndColored(message));
2021-03-21 20:17:31 +01:00
}
/**
* Display a title in the middle of the screen.
* @param title The big text
* @param subtitle The less big text
* @param fadeIn Fade in time in tick
* @param stay Stay time in tick
* @param fadeOut Fade out time in tick
*/
void sendTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut);
2021-03-21 20:17:31 +01:00
/**
* Display a title in the middle of the screen.
* @param title The big text
* @param subtitle The less big text
* @param fadeIn Fade in time in tick
* @param stay Stay time in tick
* @param fadeOut Fade out time in tick
*/
default void sendTitle(ComponentLike title, ComponentLike subtitle, int fadeIn, int stay, int fadeOut) {
sendTitle(title.asComponent(), subtitle.asComponent(), fadeIn, stay, fadeOut);
2021-03-21 20:17:31 +01:00
}
/**
* Update the server brand field in the debug menu (F3) of the player (third line in 1.15 debug screen).
* Supports legacy section format but no line break.
2021-03-21 20:17:31 +01:00
* @param brand the server brand to send to the client.
*/
void sendServerBrand(String brand);
2021-03-21 20:17:31 +01:00
/*
* Client options
*/
/**
* Gets the current client options of this player.
* @return the current client options of this player.
*/
ClientOptions getClientOptions();
/**
* Interface providing various configuration values of the Minecraft client.
*/
interface ClientOptions {
/**
* The language of the client interface.
* @return language of the client interface.
*/
Locale getLocale();
/**
* The client view distance, in chunks.
* @return client view distance, in chunks.
*/
int getViewDistance();
/**
* If the chat displays the text colors.
* @return true if the chat displays the text colors, false otherwise.
*/
boolean hasChatColorEnabled();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client is configured to completely hide the chat to the player. When this is the case, nothing
* is displayed in the chat box, and the player cant send any message or command.
* @return true if the chat is fully hidden, false otherwise.
2021-03-21 20:17:31 +01:00
*/
boolean isChatHidden();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client is configured to display the chat normally. When this is the case, chat messages and
* system messages are displayed in the chat box, and the player can send messages and commands.
* @return true if the chat is fully visible, false otherwise.
2021-03-21 20:17:31 +01:00
*/
boolean isChatFullyVisible();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client is configured to only display system messages in the chat.
* When this is the case, chat messages are hidden but system messages are visible in the chat box, and the
* player can only send commands.
* @return true if the chat is visible but only shows system messages, false otherwise.
2021-03-21 20:17:31 +01:00
*/
boolean isChatOnlyDisplayingSystemMessages();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client has configured the main hand on the left.
* @return true if the players character is left handed, false otherwise.
2021-03-21 20:17:31 +01:00
*/
boolean isLeftHanded();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client has configured the main hand on the right.
* @return true if the players character is right handed, false otherwise.
2021-03-21 20:17:31 +01:00
*/
boolean isRightHanded();
2021-03-21 20:17:31 +01:00
/**
* Tells if the client has enabled the filtering of texts on sign and book titles.
* @return true if the client filters swearing in texts, false otherwise.
*/
boolean isTextFilteringEnabled();
/**
* Tells if the client allows the server to list their player name in the multiplayer menu.
* <b>To respect the player privacys configuration, this configuration value must be verified when generating
* custom ping response packet (MOTD in multiplayer servers menu) that includes player names.</b>
* @return true if the client allows the server to list their player name in the multiplayer menu, false
* otherwise.
*/
boolean allowsServerListing();
/**
* Tells if the cape is enabled on the players skin.
* @return true if the cape is enabled on the players skin, false otherwise.
*/
boolean hasSkinCapeEnabled();
/**
* Tells if the jacket is enabled on the players skin.
* @return true if the jacket is enabled on the players skin, false otherwise.
*/
boolean hasSkinJacketEnabled();
/**
* Tells if the left sleeve is enabled on the players skin.
* @return true if the left sleeve is enabled on the players skin, false otherwise.
*/
boolean hasSkinLeftSleeveEnabled();
/**
* Tells if the right sleeve is enabled on the players skin.
* @return true if the right sleeve is enabled on the players skin, false otherwise.
*/
boolean hasSkinRightSleeveEnabled();
/**
* Tells if the left pants is enabled on the players skin.
* @return true if the left pants is enabled on the players skin, false otherwise.
*/
boolean hasSkinLeftPantsEnabled();
/**
* Tells if the right pants is enabled on the players skin.
* @return true if the right pants is enabled on the players skin, false otherwise.
*/
boolean hasSkinRightPantsEnabled();
/**
* Tells if the hat is enabled on the players skin.
* @return true if the hat is enabled on the players skin, false otherwise.
*/
boolean hasSkinHatsEnabled();
2021-03-21 20:17:31 +01:00
}
/**
* Tells if the player can send chat messages or receive chat messages from other players, according to their client
* configuration.
* <p>
* Chat messages represent public communication between players. By default, it only include actual chat message.
* This method may be used in commands like /me, /afk or the login/logout broadcasted messages.
* @return true if the player can send chat messages or receive chat messages from other players, false otherwise.
2021-03-21 20:17:31 +01:00
*/
default boolean canChat() {
2021-03-21 20:17:31 +01:00
return getClientOptions().isChatFullyVisible();
}
}