diff --git a/src/main/java/com/github/ucchyocean/lc3/channel/BukkitChannel.java b/src/main/java/com/github/ucchyocean/lc3/channel/BukkitChannel.java index 24b0468..376fa0a 100644 --- a/src/main/java/com/github/ucchyocean/lc3/channel/BukkitChannel.java +++ b/src/main/java/com/github/ucchyocean/lc3/channel/BukkitChannel.java @@ -65,64 +65,60 @@ protected void sendMessage( if ( isBroadcastChannel() ) { // ブロードキャストチャンネル - if ( isWorldRange() && player.isOnline() && player.getWorldName() != null ) { - - if ( player instanceof ChannelMemberBukkit ) { - // ↑常にtrueだと思うが、念のため。 - - World w = ((ChannelMemberBukkit)player).getWorld(); - - if ( getChatRange() > 0 ) { - // 範囲チャット - - Location origin = ((ChannelMemberBukkit)player).getLocation(); - for ( Player p : Bukkit.getOnlinePlayers() ) { - ChannelMember cp = ChannelMember.getChannelMember(p); - if ( p.getWorld().equals(w) && - origin.distance(p.getLocation()) <= getChatRange() && - !getHided().contains(cp) ) { - recipients.add(ChannelMember.getChannelMember(p)); - } - } - - } else { - // ワールドチャット - - for ( Player p : Bukkit.getOnlinePlayers() ) { - ChannelMember cp = ChannelMember.getChannelMember(p); - if ( p.getWorld().equals(w) && !getHided().contains(cp) ) { - recipients.add(ChannelMember.getChannelMember(p)); - } - } - } + for ( Player p : Bukkit.getOnlinePlayers() ) { + ChannelMember cp = ChannelMember.getChannelMember(p); + if ( !getHided().contains(cp) ) { + recipients.add(cp); + } + } + } else { + // 通常チャンネル + + for ( ChannelMember mem : getMembers() ) { + if ( mem != null && mem.isOnline() && !getHided().contains(mem) ) { + recipients.add(mem); + } + } + } + + if ( isWorldRange() && player.isOnline() && player.getWorldName() != null ) { + // ワールドチャットや範囲チャットの場合は、範囲外のプレイヤーをrecipientsから抜く + + List recipientsNew = new ArrayList<>(); + + if ( getChatRange() > 0 ) { + // 範囲チャット - // 受信者が自分以外いない場合は、メッセージを表示する - if ( Messages.noRecipientMessage("", "").length > 0 && ( - recipients.size() == 0 || - (recipients.size() == 1 && - recipients.get(0).getName().equals(player.getName()) ) ) ) { - sendNoRecipientMessage = true; + @Nullable Location origin = ((ChannelMemberBukkit)player).getLocation(); + for ( ChannelMember recipient : recipients ) { + @Nullable Location target = ((ChannelMemberBukkit)recipient).getLocation(); + if ( origin != null && target != null && + origin.getWorld().equals(target.getWorld()) && + origin.distance(target) <= getChatRange() ) { + recipientsNew.add(recipient); } } } else { - // 通常ブロードキャスト(全員へ送信) + // ワールドチャット - for ( Player p : Bukkit.getOnlinePlayers() ) { - ChannelMember cp = ChannelMember.getChannelMember(p); - if ( !getHided().contains(cp) ) { - recipients.add(cp); + @Nullable World w = ((ChannelMemberBukkit)player).getWorld(); + for ( ChannelMember recipient : recipients ) { + @Nullable World target = ((ChannelMemberBukkit)recipient).getWorld(); + if ( w != null && target != null && w.equals(target) ) { + recipientsNew.add(recipient); } } } - } else { - // 通常チャンネル + recipients = recipientsNew; - for ( ChannelMember mem : getMembers() ) { - if ( mem != null && mem.isOnline() && !getHided().contains(mem) ) { - recipients.add(mem); - } + // 受信者が自分以外いない場合は、メッセージを表示する + if ( Messages.noRecipientMessage("", "").length > 0 && ( + recipients.size() == 0 || + (recipients.size() == 1 && + recipients.get(0).getName().equals(player.getName()) ) ) ) { + sendNoRecipientMessage = true; } }