new party member list format/style

This commit is contained in:
nossr50 2020-10-29 13:54:12 -07:00
parent 449407439a
commit c6ecf30d1f
4 changed files with 36 additions and 146 deletions

View File

@ -3,8 +3,10 @@ Version 2.1.151
Added new config 'chat.yml' Added new config 'chat.yml'
Added 'Chat.Channels.Party.Spies.Automatically_Enable_Spying' to chat.yml which when enabled will start users who have the chat spy permission in chat spying mode Added 'Chat.Channels.Party.Spies.Automatically_Enable_Spying' to chat.yml which when enabled will start users who have the chat spy permission in chat spying mode
All chat settings that used to be in 'config.yml' are now in 'chat.yml' All chat settings that used to be in 'config.yml' are now in 'chat.yml'
The list of party members shown when using the party command has been simplified, this will change again in the T&C update
NOTES: NOTES:
I greatly disliked the old party member list but was avoiding rewriting it until later, someone pointed out how ugly it was and my OCD triggered and now it is rewritten. I will rewrite it again in T&C.
The new config file lets you disable the chat system (you can disable all of it, or just party chat, and or just admin chat) without permission nodes. The new config file lets you disable the chat system (you can disable all of it, or just party chat, and or just admin chat) without permission nodes.
If you disable the party/admin chat, then the party/admin chat command never gets registered and attempting to use the command will result in a whole lot of nothing. If you disable the party/admin chat, then the party/admin chat command never gets registered and attempting to use the command will result in a whole lot of nothing.
I hate adding more config files using the old .yml system, but the config update is a ways out and this works for now. I hate adding more config files using the old .yml system, but the config update is a ways out and this works for now.

View File

@ -206,7 +206,6 @@ public class ChatManager {
return false; return false;
} else { } else {
switch(chatChannel) { switch(chatChannel) {
case ADMIN: case ADMIN:
case PARTY: case PARTY:
case PARTY_OFFICER: case PARTY_OFFICER:

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.datatypes.party; package com.gmail.nossr50.datatypes.party;
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.SamePartyPredicate; import com.gmail.nossr50.chat.SamePartyPredicate;
import com.gmail.nossr50.config.ChatConfig; import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -17,17 +18,14 @@ import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
public class Party { public class Party {
private final @NotNull Predicate<CommandSender> samePartyPredicate; private final @NotNull Predicate<CommandSender> samePartyPredicate;
@ -353,146 +351,34 @@ public class Party {
*/ */
public String createMembersList(Player player) { public String createMembersList(Player player) {
StringBuilder memberList = new StringBuilder(); StringBuilder memberList = new StringBuilder();
List<String> coloredNames = new ArrayList<>();
List<UUID> onlineMembers = members.keySet().stream() for(UUID playerUUID : members.keySet()) {
.filter(x -> Bukkit.getOfflinePlayer(x).isOnline()) OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerUUID);
.collect(Collectors.toList()); if(offlinePlayer.isOnline() && player.canSee((Player) offlinePlayer)) {
coloredNames.add(ChatColor.GREEN + offlinePlayer.getName());
List<UUID> offlineMembers = members.keySet().stream()
.filter(x -> !Bukkit.getOfflinePlayer(x).isOnline())
.collect(Collectors.toList());
ArrayList<UUID> visiblePartyList = new ArrayList<>();
boolean isPartyLeaderOfflineOrHidden = false;
ArrayList<UUID> offlineOrHiddenPartyList = new ArrayList<>();
for(UUID onlineMember : onlineMembers)
{
Player onlinePlayer = Bukkit.getPlayer(onlineMember);
if(!isNotSamePerson(player.getUniqueId(), onlineMember)
|| onlinePlayer != null && player.canSee(onlinePlayer))
{
visiblePartyList.add(onlineMember);
} else { } else {
//Party leader and cannot be seen by this player coloredNames.add(ChatColor.DARK_GRAY + offlinePlayer.getName());
if(isNotSamePerson(leader.getUniqueId(), player.getUniqueId()) && onlineMember == leader.getUniqueId())
isPartyLeaderOfflineOrHidden = true;
offlineOrHiddenPartyList.add(onlineMember);
} }
} }
if(offlineMembers.contains(leader.getUniqueId())) buildChatMessage(memberList, coloredNames.toArray(new String[0]));
isPartyLeaderOfflineOrHidden = true;
//Add all the actually offline members
offlineOrHiddenPartyList.addAll(offlineMembers);
/* BUILD THE PARTY LIST WITH FORMATTING */
String partyLeaderPrefix =
/*ChatColor.WHITE
+ "["
+*/ ChatColor.GOLD
+ ""
/*+ ChatColor.WHITE
+ "]"*/
+ ChatColor.RESET;
//First add the party leader
memberList.append(partyLeaderPrefix);
List<Player> nearbyPlayerList = getNearMembers(UserManager.getPlayer(player));
boolean useDisplayNames = ChatConfig.getInstance().useDisplayNames(ChatChannel.PARTY);
if(isPartyLeaderOfflineOrHidden)
{
if(isNotSamePerson(player.getUniqueId(), leader.getUniqueId()))
applyOnlineAndRangeFormatting(memberList, false, false);
memberList.append(ChatColor.GRAY)
.append(leader.getPlayerName());
}
else {
if(isNotSamePerson(leader.getUniqueId(), player.getUniqueId()))
applyOnlineAndRangeFormatting(memberList, true, nearbyPlayerList.contains(Bukkit.getPlayer(leader.getUniqueId())));
if(useDisplayNames) {
memberList.append(leader.getPlayerName());
} else {
memberList.append(ChatColor.GOLD)
.append(Bukkit.getOfflinePlayer(leader.getUniqueId()));
}
}
//Space
memberList.append(" ");
//Now do online members
for(UUID onlinePlayerUUID : visiblePartyList)
{
if(onlinePlayerUUID == leader.getUniqueId())
continue;
if(isNotSamePerson(onlinePlayerUUID, player.getUniqueId()))
applyOnlineAndRangeFormatting(memberList, true, nearbyPlayerList.contains(Bukkit.getPlayer(onlinePlayerUUID)));
if(useDisplayNames)
{
memberList.append(Bukkit.getPlayer(onlinePlayerUUID).getDisplayName());
}
else
{
//Color allies green, players dark aqua
memberList.append(ChatColor.GREEN)
.append(Bukkit.getPlayer(onlinePlayerUUID).getName());
}
memberList.append(" ").append(ChatColor.RESET);
}
for(UUID offlineOrHiddenPlayer : offlineOrHiddenPartyList)
{
if(offlineOrHiddenPlayer == leader.getUniqueId())
continue;
applyOnlineAndRangeFormatting(memberList, false, false);
memberList.append(ChatColor.GRAY)
.append(Bukkit.getOfflinePlayer(offlineOrHiddenPlayer).getName())
.append(" ").append(ChatColor.RESET);
}
// for (Player otherPlayer : this.getVisibleMembers(player)) {
// String memberName = otherPlayer.getName();
//
// if (this.getLeader().getUniqueId().equals(otherPlayer.getUniqueId())) {
// memberList.append(ChatColor.GOLD);
//
// if (otherPlayer == null) {
// memberName = memberName.substring(0, 1) + ChatColor.GRAY + ChatColor.ITALIC + "" + memberName.substring(1);
// }
// }
// else if (otherPlayer != null) {
// memberList.append(ChatColor.WHITE);
// }
// else {
// memberList.append(ChatColor.GRAY);
// }
//
// if (player.getName().equalsIgnoreCase(otherPlayer.getName())) {
// memberList.append(ChatColor.ITALIC);
// }
//
// memberList.append(memberName).append(ChatColor.RESET).append(" ");
// }
return memberList.toString(); return memberList.toString();
} }
private void buildChatMessage(@NotNull StringBuilder stringBuilder, String @NotNull [] names) {
for(int i = 0; i < names.length; i++) {
if(i + 1 >= names.length) {
stringBuilder
.append(names[i]);
} else {
stringBuilder
.append(names[i])
.append(" ");
}
}
}
private boolean isNotSamePerson(UUID onlinePlayerUUID, UUID uniqueId) { private boolean isNotSamePerson(UUID onlinePlayerUUID, UUID uniqueId) {
return onlinePlayerUUID != uniqueId; return onlinePlayerUUID != uniqueId;
} }

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
@ -892,14 +893,16 @@ public class PlayerListener implements Listener {
return; return;
} }
if(mcMMOPlayer.getChatChannel() != ChatChannel.NONE) { if(plugin.getChatManager().isChatChannelEnabled(mcMMOPlayer.getChatChannel())) {
if(plugin.getChatManager().isMessageAllowed(mcMMOPlayer)) { if(mcMMOPlayer.getChatChannel() != ChatChannel.NONE) {
//If the message is allowed we cancel this event to avoid double sending messages if(plugin.getChatManager().isMessageAllowed(mcMMOPlayer)) {
plugin.getChatManager().processPlayerMessage(mcMMOPlayer, event.getMessage(), event.isAsynchronous()); //If the message is allowed we cancel this event to avoid double sending messages
event.setCancelled(true); plugin.getChatManager().processPlayerMessage(mcMMOPlayer, event.getMessage(), event.isAsynchronous());
} else { event.setCancelled(true);
//Message wasn't allowed, remove the player from their channel } else {
plugin.getChatManager().setOrToggleChatChannel(mcMMOPlayer, mcMMOPlayer.getChatChannel()); //Message wasn't allowed, remove the player from their channel
plugin.getChatManager().setOrToggleChatChannel(mcMMOPlayer, mcMMOPlayer.getChatChannel());
}
} }
} }
} }