Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/at/helpch/chatchat/api/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface User extends ForwardingAudience.Single, Identified {

@NotNull UUID uuid();

boolean hasPermission(@NotNull final String node);

boolean canSee(@NotNull final User target);

@NotNull Set<UUID> ignoredUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int radius() {

@Override
public boolean isUseableBy(@NotNull final ChatUser user) {
return user.player().hasPermission(ChannelUtils.USE_CHANNEL_PERMISSION + name());
return user.hasPermission(ChannelUtils.USE_CHANNEL_PERMISSION + name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public String toString() {
@Override
public Set<User> targets(final @NotNull User source) {

final Predicate<User> filterIgnores = user -> !user.ignoredUsers().contains(source.uuid()) ||
(source instanceof ChatUser && ((ChatUser) source).player().hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION));
final Predicate<User> filterIgnores = user -> user instanceof ChatUser &&
(!user.ignoredUsers().contains(source.uuid()) || source.hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION));

if (plugin.configManager().channels().defaultChannel().equals(this.name()))
return plugin.usersHolder().users().stream()
Expand All @@ -62,8 +62,7 @@ public Set<User> targets(final @NotNull User source) {
.collect(Collectors.toSet());

return plugin.usersHolder().users().stream().filter(user ->
!(user instanceof ChatUser) ||
((ChatUser) user).player().hasPermission(ChannelUtils.SEE_CHANNEL_PERMISSION + name()))
user.hasPermission(ChannelUtils.SEE_CHANNEL_PERMISSION + name()))
.filter(user -> ChannelUtils.isTargetWithinRadius(source, user, radius()))
.filter(filterIgnores)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public DumpCommand(@NotNull final ChatChatPlugin plugin) {

@SubCommand("dump")
public void dump(final User user, final @Suggestion("files") @Optional String file) {
// TODO: 8/26/22 Implement a User#hasPermission method
if (user instanceof ChatUser && !((ChatUser )user).player().hasPermission(DUMP_PERMISSION)) {
if (!user.hasPermission(DUMP_PERMISSION)) {
user.sendMessage(plugin.configManager().messages().noPermission());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public void whisperCommand(
return;
}

final var userHasBypassPerm = user.player().hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION);
if (recipient.ignoredUsers().contains(user.uuid()) && !userHasBypassPerm) {
if (recipient.ignoredUsers().contains(user.uuid()) &&
!user.hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION)) {
user.sendMessage(plugin.configManager().messages().cantMessageGeneral());
return;
}

final var recipientHasBypassPerm = recipient.player().hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION);
if (user.ignoredUsers().contains(recipient.uuid()) && !recipientHasBypassPerm) {
if (user.ignoredUsers().contains(recipient.uuid()) &&
!recipient.hasPermission(IgnoreCommand.IGNORE_BYPASS_PERMISSION)) {
user.sendMessage(plugin.configManager().messages().cantMessageIgnoredPlayer());
return;
}
Expand All @@ -81,7 +81,7 @@ public void whisperCommand(
return;
}

if (StringUtils.containsIllegalChars(message) && !user.player().hasPermission(UTF_PERMISSION)) {
if (StringUtils.containsIllegalChars(message) && !user.hasPermission(UTF_PERMISSION)) {
user.sendMessage(plugin.configManager().messages().specialCharactersNoPermission());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public void format(@NotNull final Format format) {
return uuid;
}

@Override
public boolean hasPermission(@NotNull final String node) {
return player().hasPermission(node);
}

@Override
public @NotNull Optional<ChatUser> lastMessagedUser() {
return lastMessagedUser.get();
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/main/java/at/helpch/chatchat/user/ConsoleUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import at.helpch.chatchat.format.ChatFormat;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
Expand Down Expand Up @@ -43,6 +44,11 @@ public void format(@NotNull final Format format) {
return Identity.nil().uuid();
}

@Override
public boolean hasPermission(@NotNull final String node) {
return true;
}

@Override
public boolean canSee(@NotNull User target) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import at.helpch.chatchat.api.User;
import at.helpch.chatchat.channel.ChatChannel;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand Down Expand Up @@ -47,15 +46,13 @@ public static boolean isTargetWithinRadius(
return true;
}

final Player playerTarget = ((ChatUser) target).player();

if (playerTarget.hasPermission(BYPASS_RADIUS_CHANNEL_PERMISSION)) {
if (target.hasPermission(BYPASS_RADIUS_CHANNEL_PERMISSION)) {
return true;
}

if (radius != -1 && source instanceof ChatUser) {
final Location sourceLocation = ((ChatUser) source).player().getLocation();
final Location targetLocation = playerTarget.getLocation();
final Location targetLocation = ((ChatUser) target).player().getLocation();
final int relativeX = targetLocation.getBlockX() - sourceLocation.getBlockX();
final int relativeZ = targetLocation.getBlockZ() - sourceLocation.getBlockZ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public static MentionReplaceResult replaceMention(
@NotNull final User target,
@NotNull final Component message
) {
if (!user.player().hasPermission(MENTION_CHANNEL_PERMISSION)) {
if (!user.hasPermission(MENTION_CHANNEL_PERMISSION)) {
return Map.entry(false, message);
}

if (target instanceof ChatUser) {
final var targetChatUser = (ChatUser) target;

if (!targetChatUser.channelMentions() && !user.player().hasPermission(MENTION_CHANNEL_BLOCK_OVERRIDE_PERMISSION)) {
if (!targetChatUser.channelMentions() && !user.hasPermission(MENTION_CHANNEL_BLOCK_OVERRIDE_PERMISSION)) {
return Map.entry(false, message);
}
}
Expand All @@ -120,8 +120,8 @@ public static MentionReplaceResult replaceMention(
@NotNull final ChatUser target,
@NotNull final Component message
) {
if (!user.player().hasPermission(MENTION_PERSONAL_PERMISSION) ||
(!target.personalMentions() && !user.player().hasPermission(MENTION_PERSONAL_BLOCK_OVERRIDE_PERMISSION))
if (!user.hasPermission(MENTION_PERSONAL_PERMISSION) ||
(!target.personalMentions() && !user.hasPermission(MENTION_PERSONAL_BLOCK_OVERRIDE_PERMISSION))
) {
return Map.entry(false, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static boolean process(
@NotNull final String message,
final boolean async
) {
if (StringUtils.containsIllegalChars(message) && !user.player().hasPermission(UTF_PERMISSION)) {
if (StringUtils.containsIllegalChars(message) && !user.hasPermission(UTF_PERMISSION)) {
user.sendMessage(plugin.configManager().messages().specialCharactersNoPermission());
return false;
}
Expand Down Expand Up @@ -319,22 +319,22 @@ public static boolean process(
final var resolver = TagResolver.builder();

for (final var entry : PERMISSION_TAGS.entrySet()) {
if (!user.player().hasPermission(TAG_BASE_PERMISSION + entry.getKey())) {
if (!user.hasPermission(TAG_BASE_PERMISSION + entry.getKey())) {
continue;
}

resolver.resolver(entry.getValue());
}

for (final var tag : TextDecoration.values()) {
if (!user.player().hasPermission(TAG_BASE_PERMISSION + tag.toString())) {
if (!user.hasPermission(TAG_BASE_PERMISSION + tag.toString())) {
continue;
}

resolver.resolver(StandardTags.decorations(tag));
}

if (user.player().hasPermission(ITEM_TAG_PERMISSION)) {
if (user.hasPermission(ITEM_TAG_PERMISSION)) {
resolver.resolver(
ItemUtils.createItemPlaceholder(
plugin.configManager().settings().itemFormat(),
Expand All @@ -344,7 +344,7 @@ public static boolean process(
);
}

return !user.player().hasPermission(URL_PERMISSION)
return !user.hasPermission(URL_PERMISSION)
? USER_MESSAGE_MINI_MESSAGE.deserialize(message, resolver.build())
: USER_MESSAGE_MINI_MESSAGE.deserialize(message, resolver.build()).replaceText(URL_REPLACER_CONFIG);
}
Expand Down