Mostly javadoc, and also some fixes there and there
This commit is contained in:
@@ -6,9 +6,12 @@ import java.util.stream.LongStream;
|
||||
import fr.pandacube.lib.chat.ChatColorUtil;
|
||||
import fr.pandacube.lib.permissions.PermPlayer;
|
||||
import fr.pandacube.lib.permissions.Permissions;
|
||||
import fr.pandacube.lib.players.standalone.StandaloneOffPlayer;
|
||||
import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
|
||||
|
||||
public interface PermissibleOffPlayer extends StandaloneOffPlayer {
|
||||
/**
|
||||
* Represents a player, either offline or online, with extra methods related to the {@code pandalib-permissions} system.
|
||||
*/
|
||||
public interface PermissibleOffPlayer extends AbstractOffPlayer {
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +47,7 @@ public interface PermissibleOffPlayer extends StandaloneOffPlayer {
|
||||
* Get an updated display name of the user,
|
||||
* generated using eventual permission’s prefix(es) and suffix(es) of the player,
|
||||
* and with color codes translated to Minecraft’s native {@code §}.
|
||||
* @return the display name of this player, generated by the permission system.
|
||||
*/
|
||||
default String getDisplayNameFromPermissionSystem() {
|
||||
PermPlayer permU = getPermissionUser();
|
||||
@@ -127,6 +131,8 @@ public interface PermissibleOffPlayer extends StandaloneOffPlayer {
|
||||
|
||||
/**
|
||||
* Returns the maximum value returned by {@link PermissibleOffPlayer#getPermissionRangeValues(String)}.
|
||||
* @param permissionPrefix the permission prefix to search for.
|
||||
* @return the maximum value for the provided permission range.
|
||||
*/
|
||||
default OptionalLong getPermissionRangeMax(String permissionPrefix) {
|
||||
PermissibleOnlinePlayer online = getOnlineInstance();
|
||||
@@ -139,8 +145,7 @@ public interface PermissibleOffPlayer extends StandaloneOffPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the this player is part of the specified group
|
||||
*
|
||||
* Tells if the this player is part of the specified group.
|
||||
* @param group the permissions group
|
||||
* @return <i>true</i> if this player is part of the group,
|
||||
* <i>false</i> otherwise
|
||||
|
@@ -4,9 +4,12 @@ import java.util.OptionalLong;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
import fr.pandacube.lib.permissions.PermissionExpressionParser;
|
||||
import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer;
|
||||
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
||||
|
||||
public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, StandaloneOnlinePlayer {
|
||||
/**
|
||||
* Represents an online player, with extra methods related to the {@code pandalib-permissions} system.
|
||||
*/
|
||||
public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, AbstractOnlinePlayer {
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +19,7 @@ public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, Standalon
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return The current name of this player
|
||||
* {@inheritDoc}
|
||||
* @implSpec The implementation is expected to call the environment API
|
||||
* (Bukkit/Bungee) to get the name of the player.
|
||||
*/
|
||||
|
@@ -1,140 +0,0 @@
|
||||
package fr.pandacube.lib.players.permissible;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
|
||||
import fr.pandacube.lib.chat.ChatStatic;
|
||||
import fr.pandacube.lib.players.standalone.StandalonePlayerManager;
|
||||
|
||||
public abstract class PermissiblePlayerManager<OP extends PermissibleOnlinePlayer, OF extends PermissibleOffPlayer> extends StandalonePlayerManager<OP, OF> {
|
||||
private static PermissiblePlayerManager<?, ?> instance;
|
||||
|
||||
public static synchronized PermissiblePlayerManager<?, ?> getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static synchronized void setInstance(PermissiblePlayerManager<?, ?> newInstance) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("cannot have multiple instance of PlayerManager");
|
||||
}
|
||||
instance = newInstance;
|
||||
}
|
||||
|
||||
public PermissiblePlayerManager() {
|
||||
super();
|
||||
setInstance(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastMessage(ComponentLike message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
|
||||
Objects.requireNonNull(message, "message cannot be null");
|
||||
|
||||
if (prefix)
|
||||
message = ChatStatic.prefixedAndColored(message.asComponent());
|
||||
|
||||
for (PermissibleOnlinePlayer 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 (console)
|
||||
sendMessageToConsole(message.asComponent());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Message broadcasting
|
||||
*/
|
||||
|
||||
// ComponentLike message
|
||||
// boolean prefix
|
||||
// boolean console = (permission == null)
|
||||
// String permission = null
|
||||
// UUID sourcePlayer = null
|
||||
|
||||
|
||||
/**
|
||||
* 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 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.
|
||||
*/
|
||||
public static void broadcast(ComponentLike message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
|
||||
getInstance().broadcastMessage(message, prefix, console, permission, sourcePlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a message to some or all players, and eventually to the console.
|
||||
* <p>
|
||||
* This method assumes this message is not caused by a specific player. To specify the source player, use
|
||||
* {@link #broadcast(ComponentLike, boolean, boolean, String, UUID)}.
|
||||
*
|
||||
* @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.
|
||||
* @throws IllegalArgumentException if message is null.
|
||||
*/
|
||||
public static void broadcast(ComponentLike message, boolean prefix, boolean console, String permission) {
|
||||
broadcast(message, prefix, console, permission, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a message to some or all players, and eventually to the console.
|
||||
* <p>
|
||||
* This method assumes this message is not caused by a specific player. To specify the source player, use
|
||||
* {@link #broadcast(ComponentLike, boolean, String, UUID)}.
|
||||
* <p>
|
||||
* This method decides to send the message to the console depending on whether {@code permission}
|
||||
* is null (will send to console) or not (will not send to console). To specify this behaviour, use
|
||||
* {@link #broadcast(ComponentLike, boolean, boolean, String)}.
|
||||
*
|
||||
* @param message the message to send.
|
||||
* @param prefix if the server prefix will be prepended to the message.
|
||||
* @param permission if not null, the message is only sent to player with this permission (but not to console).
|
||||
* If null, the message will be sent to all players and to console.
|
||||
* @throws IllegalArgumentException if message is null.
|
||||
*/
|
||||
public static void broadcast(ComponentLike message, boolean prefix, String permission) {
|
||||
broadcast(message, prefix, (permission == null), permission, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a message to all players, and to the console.
|
||||
* <p>
|
||||
* This method sends the message to the console. To change this behaviour, use
|
||||
* {@link #broadcast(ComponentLike, boolean, boolean, String, UUID)}.
|
||||
*
|
||||
* @param message the message to send.
|
||||
* @param prefix if the server prefix will be prepended to the message.
|
||||
* @param permission if not null, the message is only sent to player with this permission (but not to console).
|
||||
* If null, the message will be sent to all players and to console.
|
||||
* @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.
|
||||
*/
|
||||
public static void broadcast(ComponentLike message, boolean prefix, String permission, UUID sourcePlayer) {
|
||||
broadcast(message, prefix, true, permission, sourcePlayer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user