Skip to content

Commit

Permalink
Prevent ignoring yourself (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git authored May 20, 2024
2 parents 39c62d5 + 356288c commit 153d7fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ public PluginConfig(final @NotNull FileConfiguration config) {
);
}

/**
* You are trying to ignore yourself
*/
public @NotNull Component ignoreYourself() {
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.ignore-yourself")));
}

/**
* Target player has never joined the server
* <p>Placeholders:</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
if (!(sender instanceof final @NotNull Player player)) return new NotPlayerError().send(sender);
if (args.length == 0) return sendMessage(player, CloudnodeMSG.getInstance().config().usage(label, usage));
final @NotNull OfflinePlayer target = CloudnodeMSG.getInstance().getServer().getOfflinePlayer(args[0]);
if (target.getUniqueId().equals(player.getUniqueId())) return sendMessage(player, CloudnodeMSG.getInstance().config().ignoreYourself());
if (Message.isIgnored(player, target)) return unignore(player, target);
return ignore(player, target);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pro.cloudnode.smp.cloudnodemsg.error;

import pro.cloudnode.smp.cloudnodemsg.CloudnodeMSG;

public final class IgnoreYourselfError extends Error {
public IgnoreYourselfError() {
super(CloudnodeMSG.getInstance().config().ignoreYourself());
}
}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ errors:
# <player> - the player's username
cannot-ignore: "<red>(!) You cannot ignore <gray><player></gray>.</red>"

# You are trying to ignore yourself
ignore-yourself: "<red>(!) You cannot ignore yourself.</red>"

# Target player has never joined the server
# Placeholders:
# <player> - the player's username
Expand Down

0 comments on commit 153d7fa

Please sign in to comment.