Skip to content

Commit

Permalink
Remove CommonPlaceholders#displayName methods
Browse files Browse the repository at this point in the history
I18n argument mutation already converts legacy color codes
to parsed MiniMessage. This was redundant and was creating
issues with other parts of the codebase.
  • Loading branch information
JRoy committed Feb 10, 2024
1 parent 3d9d3a3 commit 8a57856
Show file tree
Hide file tree
Showing 51 changed files with 100 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void run() {
user.getBase().setAllowFlight(true);
user.getBase().setFlying(true);
if (ess.getSettings().isSendFlyEnableOnJoin()) {
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), true), CommonPlaceholders.displayName(user));
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), true), user.getDisplayName());
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.FormatUtil;
Expand All @@ -16,7 +15,6 @@
import com.earth2me.essentials.utils.VersionUtil;
import com.google.common.collect.Lists;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.api.MaxMoneyException;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.JailStatusChangeEvent;
Expand Down Expand Up @@ -250,7 +248,7 @@ public void giveMoney(final BigDecimal value, final CommandSource initiator, fin
setMoney(getMoney().add(value), cause);
sendTl("addedToAccount", NumberUtil.displayCurrency(value, ess));
if (initiator != null) {
initiator.sendTl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), CommonPlaceholders.displayName((IUser) this), NumberUtil.displayCurrency(getMoney(), ess));
initiator.sendTl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess));
}
}

Expand All @@ -267,8 +265,8 @@ public void payUser(final User reciever, final BigDecimal value, final UserBalan
if (canAfford(value)) {
setMoney(getMoney().subtract(value), cause);
reciever.setMoney(reciever.getMoney().add(value), cause);
sendTl("moneySentTo", NumberUtil.displayCurrency(value, ess), CommonPlaceholders.displayName((IUser) reciever));
reciever.sendTl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), CommonPlaceholders.displayName((IUser) this));
sendTl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName());
reciever.sendTl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName());
final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value);
ess.getServer().getPluginManager().callEvent(transactionEvent);
} else {
Expand Down Expand Up @@ -297,7 +295,7 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator, fin
}
sendTl("takenFromAccount", NumberUtil.displayCurrency(value, ess));
if (initiator != null) {
initiator.sendTl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), CommonPlaceholders.displayName((IUser) this), NumberUtil.displayCurrency(getMoney(), ess));
initiator.sendTl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess));
}
}

Expand Down Expand Up @@ -409,7 +407,7 @@ public boolean hasOutstandingTpaRequest(String playerUsername, boolean here) {
}
teleportRequestQueue.remove(playerUsername);
if (inform) {
sendTl("requestTimedOutFrom", CommonPlaceholders.displayName((IUser) ess.getUser(request.getRequesterUuid())));
sendTl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName());
}
return null;
}
Expand Down Expand Up @@ -443,7 +441,7 @@ public TpaRequest getNextTpaRequest(boolean inform, boolean ignoreExpirations, b
}
} else {
if (inform) {
sendTl("requestTimedOutFrom", CommonPlaceholders.displayName((IUser) ess.getUser(request.getRequesterUuid())));
sendTl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName());
}
teleportRequestQueue.remove(key);
}
Expand Down Expand Up @@ -806,9 +804,9 @@ public void updateActivity(final boolean broadcast, final AfkStatusChangeEvent.C
if (broadcast && !isHidden() && !isAfk()) {
setDisplayNick();
if (ess.getSettings().broadcastAfkMessage()) {
ess.broadcastTl(this, u -> u == this, "userIsNotAway", CommonPlaceholders.displayName((IUser) this));
ess.broadcastTl(this, u -> u == this, "userIsNotAway", getDisplayName());
}
sendTl("userIsNotAwaySelf", CommonPlaceholders.displayName((IUser) this));
sendTl("userIsNotAwaySelf", getDisplayName());
}
}
lastActivity = System.currentTimeMillis();
Expand Down Expand Up @@ -861,9 +859,9 @@ public void checkActivity() {
if (isAfk() && !isHidden()) {
setDisplayNick();
if (ess.getSettings().broadcastAfkMessage()) {
ess.broadcastTl(this, u -> u == this, "userIsAway", CommonPlaceholders.displayName((IUser) this));
ess.broadcastTl(this, u -> u == this, "userIsAway", getDisplayName());
}
sendTl("userIsAwaySelf", CommonPlaceholders.displayName((IUser) this));
sendTl("userIsAwaySelf", getDisplayName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException;
import net.ess3.api.events.AfkStatusChangeEvent;
import org.bukkit.Server;
Expand Down Expand Up @@ -97,10 +95,10 @@ private void toggleAfk(final User sender, final User user, final String message)
}
if (!tlKey.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
// exclude user from receiving general AFK announcement in favor of personal message
ess.broadcastTl(user, u -> u == user, tlKey, CommonPlaceholders.displayName((IUser) user), message);
ess.broadcastTl(user, u -> u == user, tlKey, user.getDisplayName(), message);
}
if (!selfTlKey.isEmpty()) {
user.sendTl(selfTlKey, CommonPlaceholders.displayName((IUser) user), message);
user.sendTl(selfTlKey, user.getDisplayName(), message);
}
user.setDisplayNick(); // Set this again after toggling
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IUser;
import org.bukkit.Server;

import java.util.Collections;
Expand All @@ -22,14 +20,14 @@ protected void run(final Server server, final CommandSource sender, final String
}

final User target = getPlayer(server, args, 0, false, true);
sender.sendTl("balanceOther", target.isHidden() ? target.getName() : CommonPlaceholders.displayName((IUser) target), NumberUtil.displayCurrency(target.getMoney(), ess));
sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess));
}

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length == 1 && user.isAuthorized("essentials.balance.others")) {
final User target = getPlayer(server, args, 0, true, true);
user.sendTl("balanceOther", target.isHidden() ? target.getName() : CommonPlaceholders.displayName((IUser) target), NumberUtil.displayCurrency(target.getMoney(), ess));
user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess));
} else if (args.length < 2) {
user.sendTl("balance", NumberUtil.displayCurrency(user.getMoney(), ess));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.IUser;
import org.bukkit.Server;

import java.util.Collections;
Expand All @@ -22,7 +20,7 @@ protected void run(final Server server, final CommandSource sender, final String

final User user = getPlayer(server, sender, args, 0);
user.getBase().setFireTicks(Integer.parseInt(args[1]) * 20);
sender.sendTl("burnMsg", CommonPlaceholders.displayName((IUser) user), Integer.parseInt(args[1]));
sender.sendTl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1]));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import net.ess3.api.IUser;
import net.ess3.api.MaxMoneyException;
import net.ess3.api.TranslatableException;
import net.ess3.api.events.UserBalanceUpdateEvent;
Expand Down Expand Up @@ -67,7 +65,7 @@ public void run(final Server server, final CommandSource sender, final String co
final boolean aboveMax = userAmount.compareTo(maxBal) > 0;
player.setMoney(underMin ? minBal : aboveMax ? maxBal : userAmount, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
player.sendTl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess));
sender.sendTl("setBalOthers", CommonPlaceholders.displayName((IUser) player), NumberUtil.displayCurrency(player.getMoney(), ess));
sender.sendTl("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.earth2me.essentials.userstorage.ModernUserMap;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommandMapUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.FloatUtil;
Expand All @@ -22,7 +21,6 @@
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -485,7 +483,7 @@ private void runReset(final Server server, final CommandSource sender, final Str
}
final User user = getPlayer(server, args, 1, true, true);
user.reset();
sender.sendMessage("Reset Essentials userdata for player: " + CommonPlaceholders.displayName((IUser) user));
sender.sendMessage("Reset Essentials userdata for player: " + user.getDisplayName());
}

// Toggles debug mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.earth2me.essentials.IUser;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.SetExpFix;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
Expand Down Expand Up @@ -99,7 +97,7 @@ public void run(final Server server, final CommandSource sender, final String co
}

private void showExp(final CommandSource sender, final IUser target) {
sender.sendTl("exp", CommonPlaceholders.displayNameRecipient((IMessageRecipient) target), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase()));
sender.sendTl("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase()));
}

//TODO: Limit who can give negative exp?
Expand Down Expand Up @@ -131,7 +129,7 @@ private void setExp(final CommandSource sender, final IUser target, String strAm
amount = 0L;
}
SetExpFix.setTotalExperience(target.getBase(), (int) amount);
sender.sendTl("expSet", CommonPlaceholders.displayNameRecipient((IMessageRecipient) target), amount);
sender.sendTl("expSet", target.getDisplayName(), amount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.IUser;
import org.bukkit.Server;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -38,7 +36,7 @@ public void run(final Server server, final User user, final String commandLabel,
@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) {
extPlayer(player.getBase());
sender.sendTl("extinguishOthers", CommonPlaceholders.displayName((IUser) player));
sender.sendTl("extinguishOthers", player.getDisplayName());
}

private void extPlayer(final Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.IUser;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent;
Expand Down Expand Up @@ -44,7 +42,7 @@ protected void run(final Server server, final CommandSource sender, final String
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException {
try {
feedPlayer(player.getBase());
sender.sendTl("feedOther", CommonPlaceholders.displayName((IUser) player));
sender.sendTl("feedOther", player.getDisplayName());
} catch (final QuietAbortException e) {
//Handle Quietly
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.IUser;
import net.ess3.api.events.FlyStatusChangeEvent;
import org.bukkit.Server;

Expand Down Expand Up @@ -39,9 +38,9 @@ protected void togglePlayer(final CommandSource sender, final User user, Boolean
user.getBase().setFlying(false);
}

user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), CommonPlaceholders.displayName((IUser) user));
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), user.getDisplayName());
if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) {
sender.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), CommonPlaceholders.displayName((IUser) user));
sender.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), user.getDisplayName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.IUser;
import com.earth2me.essentials.User;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.google.common.collect.ImmutableList;
import org.bukkit.GameMode;
import org.bukkit.Server;
Expand Down Expand Up @@ -62,7 +60,7 @@ protected void run(final Server server, final User user, final String commandLab
}

user.getBase().setGameMode(gameMode);
user.sendTl("gameMode", user.playerTl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), CommonPlaceholders.displayNameRecipient((IMessageRecipient) user));
user.sendTl("gameMode", user.playerTl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName());
}

private void setUserGamemode(final CommandSource sender, final GameMode gameMode, final User user) throws NotEnoughArgumentsException {
Expand All @@ -76,7 +74,7 @@ private void setUserGamemode(final CommandSource sender, final GameMode gameMode
}

user.getBase().setGameMode(gameMode);
sender.sendTl("gameMode", sender.tl(gameMode.toString().toLowerCase(Locale.ENGLISH)), CommonPlaceholders.displayNameRecipient((IMessageRecipient) user));
sender.sendTl("gameMode", sender.tl(gameMode.toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName());
}

// essentials.gamemode will let them change to any but essentials.gamemode.survival would only let them change to survival.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.Inventories;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.NumberUtil;
import com.earth2me.essentials.utils.VersionUtil;
import com.google.common.collect.Lists;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException;
import org.bukkit.Material;
import org.bukkit.Server;
Expand Down Expand Up @@ -81,7 +79,7 @@ public void run(final Server server, final CommandSource sender, final String co
final boolean isDropItemsIfFull = ess.getSettings().isDropItemsIfFull();
final ItemStack finalStack = stack;
loopOnlinePlayersConsumer(server, sender, false, true, args[0], player -> {
sender.sendTl("giveSpawn", finalStack.getAmount(), itemName, CommonPlaceholders.displayName((IUser) player));
sender.sendTl("giveSpawn", finalStack.getAmount(), itemName, player.getDisplayName());

final Map<Integer, ItemStack> leftovers = Inventories.addItem(player.getBase(), player.isAuthorized("essentials.oversizedstacks") ? ess.getSettings().getOversizedStackSize() : 0, finalStack);

Expand All @@ -90,7 +88,7 @@ public void run(final Server server, final CommandSource sender, final String co
final World w = player.getWorld();
w.dropItemNaturally(player.getLocation(), item);
} else {
sender.sendTl("giveSpawnFailure", item.getAmount(), itemName, CommonPlaceholders.displayName((IUser) player));
sender.sendTl("giveSpawnFailure", item.getAmount(), itemName, player.getDisplayName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.IUser;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityRegainHealthEvent;
Expand Down Expand Up @@ -71,7 +69,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin
player.removePotionEffect(effect.getType());
}
}
sender.sendTl("healOther", CommonPlaceholders.displayName((IUser) user));
sender.sendTl("healOther", user.getDisplayName());
} catch (final QuietAbortException e) {
//Handle Quietly
}
Expand Down
Loading

0 comments on commit 8a57856

Please sign in to comment.