mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-06-24 13:24:45 +02:00
This changes events to store the database Account instead of an OfflinePlayer and deprecates any event method that uses/returns OfflinePlayer. This is necessary as Bukkit#getOfflinePlayer(String) queries Mojang for the UUID when the user was not found in the local cache. As we already store this information (name to UUID mapping) in our database we should not have no need to rely on querying Mojang. (This might make transactions fail for shop owners that haven't played before but that shouldn't really be an issue in most cases)
76 lines
2.2 KiB
Java
76 lines
2.2 KiB
Java
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.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;
|
|
|
|
/**
|
|
* @author KingFaris10
|
|
*/
|
|
public class Toggle implements CommandExecutor {
|
|
private static final List<String> toggledPlayers = new ArrayList<String>();
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (!(sender instanceof Player)) {
|
|
return false;
|
|
}
|
|
|
|
if (!Permission.has(sender, Permission.NOTIFY_TOGGLE)) {
|
|
sender.sendMessage(Messages.ACCESS_DENIED);
|
|
return true;
|
|
}
|
|
|
|
Player player = (Player) sender;
|
|
|
|
if (args.length != 0) {
|
|
return false;
|
|
}
|
|
|
|
if (setIgnoring(player, !toggledPlayers.contains(player.getName()))) {
|
|
player.sendMessage(Messages.prefix(Messages.TOGGLE_MESSAGES_OFF));
|
|
} else {
|
|
player.sendMessage(Messages.prefix(Messages.TOGGLE_MESSAGES_ON));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void clearToggledPlayers() {
|
|
toggledPlayers.clear();
|
|
}
|
|
|
|
public static boolean isIgnoring(OfflinePlayer player) {
|
|
return player != null && isIgnoring(player.getName());
|
|
}
|
|
|
|
public static boolean isIgnoring(String playerName) {
|
|
return toggledPlayers.contains(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());
|
|
}
|
|
} else {
|
|
if (toggledPlayers.contains(player.getName())) {
|
|
toggledPlayers.remove(player.getName());
|
|
}
|
|
}
|
|
|
|
return ignoring;
|
|
}
|
|
|
|
}
|