Skip to content

Commit 6716aee

Browse files
committed
feat: add config option to enable or disable self-messaging for players
1 parent d29225e commit 6716aee

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,15 @@ public PluginConfig(final @NotNull FileConfiguration config) {
386386
public @NotNull Component messageYourself() {
387387
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.message-yourself")));
388388
}
389-
389+
/**
390+
* Whether to allow players to message themselves
391+
* Config key: allow-self-message
392+
* Default: false
393+
*/
394+
public boolean allowSelfMessage() {
395+
return config.getBoolean("allow-self-message", false);
396+
}
397+
390398
public @NotNull Component nobodyReply() {
391399
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.nobody-reply")));
392400
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
3333

3434
final @NotNull Optional<@NotNull Player> recipient = Optional.ofNullable(CloudnodeMSG.getInstance().getServer()
3535
.getPlayer(args[0]));
36-
if (sender instanceof final @NotNull Player player && recipient.isPresent() && recipient.get().getUniqueId().equals(player.getUniqueId()))
37-
return new MessageYourselfError().send(sender);
36+
if (sender instanceof final @NotNull Player player && recipient.isPresent() && recipient.get().getUniqueId().equals(player.getUniqueId())) {
37+
if (!CloudnodeMSG.getInstance().config().allowSelfMessage()) {
38+
return new MessageYourselfError().send(sender);
39+
}
40+
}
3841
if (args.length == 1) {
3942
final @NotNull Player player = (Player) sender;
4043
if (Message.hasChannel(player)) {
@@ -67,4 +70,4 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
6770
if (args.length == 1) return null;
6871
return new ArrayList<>();
6972
}
70-
}
73+
}

src/main/resources/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ignored: "<green>(!) You will no longer see messages from <gray><player></gray>.
3434
# Same placeholders as ignored
3535
unignored: "<yellow>(!) You are no longer ignoring <gray><player></gray>.</yellow>"
3636

37+
# Allow players to send private messages to themselves.
38+
# Default: false
39+
allow-self-message: false
40+
3741
channel:
3842
# Message channel created
3943
# Placeholders:
@@ -159,7 +163,7 @@ pm-sound:
159163
enabled: true
160164
# Sound to play on private message (Minecraft sound identifier)
161165
# Examples: ENTITY_ALLAY_AMBIENT_WITH_ITEM, ENTITY_PLAYER_LEVELUP, etc.
162-
sound: BLOCK_NOTE_BLOCK_PLINGt
166+
sound: BLOCK_NOTE_BLOCK_PLING
163167
# Volume of the sound (float). 1.0 is normal volume, increase to be louder.
164168
volume: 1.0
165169
# Pitch of the sound (float). 1.0 is normal pitch, lower for deeper, higher for sharper.

0 commit comments

Comments
 (0)