Deprecation, deprecated, ...

This commit is contained in:
2023-06-16 19:14:22 +02:00
parent e6fc31e5ca
commit d59ae22970
7 changed files with 44 additions and 87 deletions

View File

@@ -1,13 +1,10 @@
package fr.pandacube.lib.players.standalone;
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;
import java.util.Locale;
import java.util.UUID;
/**
* Represents any online player.
@@ -87,30 +84,6 @@ public interface AbstractOnlinePlayer extends AbstractOffPlayer {
default void sendMessage(ComponentLike message) {
sendMessage(message.asComponent());
}
/**
* 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));
}
/**
* Display the provided message in the players chat, if the chat is activated, prepended with the server prefix.

View File

@@ -184,37 +184,49 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
/**
* Broadcast a message to some or all players, and eventually to the console.
* Broadcast a SYSTEM message to some or all players, and eventually to the console.
*
* @param message the message to send.
* @param prefix if the server prefix will be prepended to the message.
* @param console if the message must be displayed in the console.
* @param permission if not null, the message is only sent to player with this permission.
* @param sourcePlayer specifiy the eventual player that is the source of the message.
* If null, the message will be sent as a SYSTEM chat message.
* If not null, the message will be sent as a CHAT message, and will not be sent
* to players ignoring the provided player (if implemented).
* @throws IllegalArgumentException if message is null.
* @implSpec subclasses may override this method, for instance to restrict the players being able to see the message
* (like /ignored players).
*/
public void broadcastMessage(ComponentLike message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
public void broadcastMessage(ComponentLike message, boolean prefix, boolean console, String permission) {
Objects.requireNonNull(message, "message cannot be null");
if (prefix)
message = ChatStatic.prefixedAndColored(message.asComponent());
for (OP op : getAll()) {
if (permission != null && !(op.hasPermission(permission))) continue;
if (sourcePlayer != null)
op.sendMessage(message, sourcePlayer); // CHAT message with UUID
else
op.sendMessage(message); // SYSTEM message
if (permission != null && !(op.hasPermission(permission)))
continue;
op.sendMessage(message);
}
if (console)
sendMessageToConsole(message.asComponent());
}
/**
* Broadcast a message to some or all players, and eventually to the console.
*
* @param message the message to send.
* @param prefix if the server prefix will be prepended to the message.
* @param console if the message must be displayed in the console.
* @param permission if not null, the message is only sent to player with this permission.
* @param sourcePlayer specify the eventual player that is the source of the message. Default implementation of this
* method does not use this parameter due to the Minecraft client not handling unsigned CHAT
* messages.
* @throws IllegalArgumentException if message is null.
* @implSpec subclasses may override this method, for instance to restrict the players being able to see the message
* (like /ignored players).
*/
public void broadcastMessage(ComponentLike message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
broadcastMessage(message, prefix, console, permission);
}