Skip to content

Commit 153d7fa

Browse files
authored
Prevent ignoring yourself (#48)
2 parents 39c62d5 + 356288c commit 153d7fa

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/main/java/pro/cloudnode/smp/cloudnodemsg/PluginConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ public PluginConfig(final @NotNull FileConfiguration config) {
386386
);
387387
}
388388

389+
/**
390+
* You are trying to ignore yourself
391+
*/
392+
public @NotNull Component ignoreYourself() {
393+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.ignore-yourself")));
394+
}
395+
389396
/**
390397
* Target player has never joined the server
391398
* <p>Placeholders:</p>

src/main/java/pro/cloudnode/smp/cloudnodemsg/command/IgnoreCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
2727
if (!(sender instanceof final @NotNull Player player)) return new NotPlayerError().send(sender);
2828
if (args.length == 0) return sendMessage(player, CloudnodeMSG.getInstance().config().usage(label, usage));
2929
final @NotNull OfflinePlayer target = CloudnodeMSG.getInstance().getServer().getOfflinePlayer(args[0]);
30+
if (target.getUniqueId().equals(player.getUniqueId())) return sendMessage(player, CloudnodeMSG.getInstance().config().ignoreYourself());
3031
if (Message.isIgnored(player, target)) return unignore(player, target);
3132
return ignore(player, target);
3233
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package pro.cloudnode.smp.cloudnodemsg.error;
2+
3+
import pro.cloudnode.smp.cloudnodemsg.CloudnodeMSG;
4+
5+
public final class IgnoreYourselfError extends Error {
6+
public IgnoreYourselfError() {
7+
super(CloudnodeMSG.getInstance().config().ignoreYourself());
8+
}
9+
}

src/main/resources/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ errors:
123123
# <player> - the player's username
124124
cannot-ignore: "<red>(!) You cannot ignore <gray><player></gray>.</red>"
125125

126+
# You are trying to ignore yourself
127+
ignore-yourself: "<red>(!) You cannot ignore yourself.</red>"
128+
126129
# Target player has never joined the server
127130
# Placeholders:
128131
# <player> - the player's username

0 commit comments

Comments
 (0)