Skip to content

Commit 7b9f770

Browse files
committed
don't run expensive offline player check if player is not in a channel
1 parent fbec10a commit 7b9f770

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ public static boolean hasChannel(final @NotNull Player player, final @NotNull Of
263263
return channel.isPresent() && channel.get().getUniqueId().equals(recipient.getUniqueId());
264264
}
265265

266+
/**
267+
* Check whether player has DM channel
268+
*
269+
* @param player The player
270+
*/
271+
public static boolean hasChannel(final @NotNull Player player) {
272+
return getChannel(player).isPresent();
273+
}
274+
266275
/**
267276
* Team message channel
268277
*

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
3838
return new MessageYourselfError().send(sender);
3939
if (args.length == 1) {
4040
final @NotNull Player player = (Player) sender;
41-
final @NotNull OfflinePlayer recipientOffline = CloudnodeMSG.getInstance().getServer().getOfflinePlayer(args[0]);
42-
if (Message.getChannel(player).map(r -> r.getUniqueId().equals(recipientOffline.getUniqueId())).orElse(false)) {
43-
Message.exitChannel(player);
44-
return sendMessage(player, CloudnodeMSG.getInstance().config().channelClosed(player.getName(), Optional.ofNullable(recipientOffline.getName()).orElse("Unknown Player"), label));
41+
if (Message.hasChannel(player)) {
42+
final @NotNull OfflinePlayer recipientOffline = CloudnodeMSG.getInstance().getServer().getOfflinePlayer(args[0]);
43+
if (Message.getChannel(player).map(r -> r.getUniqueId().equals(recipientOffline.getUniqueId())).orElse(false)) {
44+
Message.exitChannel(player);
45+
return sendMessage(player, CloudnodeMSG.getInstance().config().channelClosed(player.getName(), Optional.ofNullable(recipientOffline.getName()).orElse("Unknown Player"), label));
46+
}
4547
}
4648
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get()) && !player.hasPermission(Permission.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player);
4749
if (!Message.isIncomingEnabled(recipient.get())) return new PlayerHasIncomingDisabledError(recipient.get().getName()).send(player);

0 commit comments

Comments
 (0)