Skip to content

Commit

Permalink
Added display role names (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Apr 30, 2022
1 parent 4bbd574 commit 9303944
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
Expand Up @@ -14,6 +14,12 @@ public interface PlayerRole {
*/
String getName();

/**
* Get the display-name of the role.
* This is shown in chat, placeholders, etc.
*/
String getDisplayName();

/**
* Get the weight of the role in the ladder.
*/
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.bgsoftware.superiorskyblock.island.permissions.RolePermissionNode;
import com.google.common.base.Preconditions;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand All @@ -15,12 +16,15 @@ public final class SPlayerRole implements PlayerRole {
private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();

private final String name;
private final String displayName;
private final int id;
private final int weight;
private final RolePermissionNode defaultPermissions;

public SPlayerRole(String name, int id, int weight, List<String> defaultPermissions, SPlayerRole previousRole) {
public SPlayerRole(String name, @Nullable String displayName, int id, int weight, List<String> defaultPermissions,
SPlayerRole previousRole) {
this.name = name;
this.displayName = displayName == null ? name : displayName;
this.id = id;
this.weight = weight;

Expand Down Expand Up @@ -76,6 +80,11 @@ public String getName() {
return name;
}

@Override
public String getDisplayName() {
return displayName;
}

@Override
public int getWeight() {
return weight;
Expand Down
Expand Up @@ -365,12 +365,12 @@ public void onPlayerAsyncChat(AsyncPlayerChatEvent e) {
IslandUtils.sendMessage(island, Message.TEAM_CHAT_FORMAT, new ArrayList<>(),
superiorPlayer.getPlayerRole(), superiorPlayer.getName(), eventResult.getResult());

Message.SPY_TEAM_CHAT_FORMAT.send(Bukkit.getConsoleSender(), superiorPlayer.getPlayerRole(),
Message.SPY_TEAM_CHAT_FORMAT.send(Bukkit.getConsoleSender(), superiorPlayer.getPlayerRole().getDisplayName(),
superiorPlayer.getName(), eventResult.getResult());
for (Player _onlinePlayer : Bukkit.getOnlinePlayers()) {
SuperiorPlayer onlinePlayer = plugin.getPlayers().getSuperiorPlayer(_onlinePlayer);
if (onlinePlayer.hasAdminSpyEnabled())
Message.SPY_TEAM_CHAT_FORMAT.send(onlinePlayer, superiorPlayer.getPlayerRole(),
Message.SPY_TEAM_CHAT_FORMAT.send(onlinePlayer, superiorPlayer.getPlayerRole().getDisplayName(),
superiorPlayer.getName(), eventResult.getResult());
}
} else {
Expand All @@ -386,6 +386,7 @@ public void onPlayerAsyncChat(AsyncPlayerChatEvent e) {
.replace("{island-worth-format}", String.valueOf(island == null ? 0 :
Formatters.FANCY_NUMBER_FORMATTER.format(island.getWorth(), superiorPlayer.getUserLocale())))
.replace("{island-name}", islandNameFormat == null ? "" : islandNameFormat)
.replace("{island-role}", superiorPlayer.getPlayerRole().getDisplayName())
.replace("{island-position-worth}", island == null ? "" : (plugin.getGrid().getIslandPosition(island, SortingTypes.BY_WORTH) + 1) + "")
.replace("{island-position-level}", island == null ? "" : (plugin.getGrid().getIslandPosition(island, SortingTypes.BY_LEVEL) + 1) + "")
.replace("{island-position-rating}", island == null ? "" : (plugin.getGrid().getIslandPosition(island, SortingTypes.BY_RATING) + 1) + "")
Expand Down
Expand Up @@ -108,7 +108,8 @@ public ItemStack modifyButtonItem(ItemStack buttonItem, MenuTopIslands superiorM
lore.add(placeholdersService.parsePlaceholders(member.asOfflinePlayer(), memberFormat
.replace("{}", member.getName())
.replace("{0}", member.getName())
.replace("{1}", onlineMessage == null ? "" : onlineMessage))
.replace("{1}", onlineMessage == null ? "" : onlineMessage)
.replace("{2}", member.getPlayerRole().getDisplayName()))
);
});
}
Expand Down
Expand Up @@ -81,8 +81,9 @@ private int loadRole(ConfigurationSection section, int type, SPlayerRole previou
int weight = section.getInt("weight", type);
int id = section.getInt("id", weight);
String name = section.getString("name");
String displayName = section.getString("display-name");

PlayerRole playerRole = new SPlayerRole(name, id, weight, section.getStringList("permissions"), previousRole);
PlayerRole playerRole = new SPlayerRole(name, displayName, id, weight, section.getStringList("permissions"), previousRole);

this.rolesContainer.addPlayerRole(playerRole);

Expand Down
Expand Up @@ -64,6 +64,7 @@ public final class PlaceholdersServiceImpl implements PlaceholdersService {
new ImmutableMap.Builder<String, PlayerPlaceholderParser>()
.put("texture", SuperiorPlayer::getTextureValue)
.put("role", superiorPlayer -> superiorPlayer.getPlayerRole().toString())
.put("role_display", superiorPlayer -> superiorPlayer.getPlayerRole().getDisplayName())
.put("locale", superiorPlayer -> Formatters.LOCALE_FORMATTER.format(superiorPlayer.getUserLocale()))
.put("world_border", superiorPlayer -> Formatters.BOOLEAN_FORMATTER.format(superiorPlayer.hasWorldBorderEnabled(), superiorPlayer.getUserLocale()))
.put("blocks_stacker", superiorPlayer -> Formatters.BOOLEAN_FORMATTER.format(superiorPlayer.hasBlocksStackerEnabled(), superiorPlayer.getUserLocale()))
Expand Down

0 comments on commit 9303944

Please sign in to comment.