diff --git a/src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java b/src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java index d29245a..2742d11 100644 --- a/src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java +++ b/src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java @@ -1,22 +1,23 @@ package com.Acrobot.ChestShop.Commands; import com.Acrobot.ChestShop.Configuration.Messages; -import com.Acrobot.ChestShop.Permission; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; /** * @author KingFaris10 */ public class Toggle implements CommandExecutor { - private static final List toggledPlayers = new ArrayList(); + private static final Set toggledPlayers = new HashSet<>(); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -30,7 +31,7 @@ public class Toggle implements CommandExecutor { return false; } - if (setIgnoring(player, !toggledPlayers.contains(player.getName()))) { + if (setIgnoring(player, !isIgnoring(player))) { player.sendMessage(Messages.prefix(Messages.TOGGLE_MESSAGES_OFF)); } else { player.sendMessage(Messages.prefix(Messages.TOGGLE_MESSAGES_ON)); @@ -44,24 +45,28 @@ public class Toggle implements CommandExecutor { } public static boolean isIgnoring(OfflinePlayer player) { - return player != null && isIgnoring(player.getName()); + return player != null && isIgnoring(player.getUniqueId()); } + public static boolean isIgnoring(UUID playerId) { + return toggledPlayers.contains(playerId); + } + + /** + * @deprecated Use {@link #isIgnoring(UUID)} + */ + @Deprecated public static boolean isIgnoring(String playerName) { - return toggledPlayers.contains(playerName); + return isIgnoring(Bukkit.getOfflinePlayer(playerName)); } public static boolean setIgnoring(Player player, boolean ignoring) { Validate.notNull(player); // Make sure the player instance is not null, in case there are any errors in the code if (ignoring) { - if (!toggledPlayers.contains(player.getName())) { - toggledPlayers.add(player.getName()); - } + toggledPlayers.add(player.getUniqueId()); } else { - if (toggledPlayers.contains(player.getName())) { - toggledPlayers.remove(player.getName()); - } + toggledPlayers.remove(player.getUniqueId()); } return ignoring; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java index bbd5c15..61155e5 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java @@ -27,15 +27,13 @@ public class TransactionMessageSender implements Listener { } protected static void sendBuyMessage(TransactionEvent event) { - String ownerName = event.getOwnerAccount().getName(); - Player player = event.getClient(); if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) { - sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", ownerName); + sendMessage(player, Messages.YOU_BOUGHT_FROM_SHOP, event, "owner", event.getOwnerAccount().getName()); } - if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getName())) { + if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) { Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid()); if (owner != null) { sendMessage(owner, Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, event, "buyer", player.getName()); @@ -44,15 +42,13 @@ public class TransactionMessageSender implements Listener { } protected static void sendSellMessage(TransactionEvent event) { - String ownerName = event.getOwnerAccount().getName(); - Player player = event.getClient(); if (Properties.SHOW_TRANSACTION_INFORMATION_CLIENT) { - sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", ownerName); + sendMessage(player, Messages.YOU_SOLD_TO_SHOP, event, "buyer", event.getOwnerAccount().getName()); } - if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(ownerName)) { + if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) { Player owner = Bukkit.getPlayer(event.getOwnerAccount().getUuid()); if (owner != null) { sendMessage(owner, Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, event, "seller", player.getName()); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java index af7f27f..4d03e7e 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java @@ -63,7 +63,7 @@ public class ErrorMessageSender implements Listener { message = Messages.NOT_ENOUGH_MONEY_SHOP; break; case NOT_ENOUGH_SPACE_IN_CHEST: - if (Properties.SHOW_MESSAGE_FULL_SHOP && !Properties.CSTOGGLE_TOGGLES_FULL_SHOP || !Toggle.isIgnoring(event.getOwnerAccount().getName())) { + if (Properties.SHOW_MESSAGE_FULL_SHOP && !Properties.CSTOGGLE_TOGGLES_FULL_SHOP || !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) { Location loc = event.getSign().getLocation(); String messageNotEnoughSpace = Messages.prefix(NOT_ENOUGH_SPACE_IN_YOUR_SHOP) .replace("%price", Economy.formatBalance(event.getExactPrice())) @@ -83,7 +83,7 @@ public class ErrorMessageSender implements Listener { message = Messages.NOT_ENOUGH_ITEMS_TO_SELL; break; case NOT_ENOUGH_STOCK_IN_CHEST: - if (Properties.SHOW_MESSAGE_OUT_OF_STOCK && !Properties.CSTOGGLE_TOGGLES_OUT_OF_STOCK || !Toggle.isIgnoring(event.getOwnerAccount().getName())) { + if (Properties.SHOW_MESSAGE_OUT_OF_STOCK && !Properties.CSTOGGLE_TOGGLES_OUT_OF_STOCK || !Toggle.isIgnoring(event.getOwnerAccount().getUuid())) { Location loc = event.getSign().getLocation(); String messageOutOfStock = Messages.prefix(NOT_ENOUGH_STOCK_IN_YOUR_SHOP) .replace("%price", Economy.formatBalance(event.getExactPrice()))