I have no idea why my code is not keeping players muted after they relog even though I added them to the config.
This is there the muted players get saved:
private static ArrayList <Player> mutedPlayers = new ArrayList<Player>();
This is the event that handles the muted player and that should check if the player is muted or not:
@EventHandler
public void handlePlayerChat(AsyncPlayerChatEvent e){
Player p = e.getPlayer();
if (mutedPlayers.contains(p)) {
p.sendMessage(ChatColor.DARK_RED + "You've been muted!");
e.setCancelled(true);
}
}
This is the command:
if(command.getName().equals("mute")) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (p.hasPermission("shxr.mute")) {
if (args.length == 1) {
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (!mutedPlayers.contains(target)) {
mutedPlayers.add(target);
p.sendMessage(ChatColor.GREEN + "You have successfully muted " + target.getName() + ChatColor.GREEN + "!");
target.sendMessage(ChatColor.DARK_RED + "You are muted!");
getConfig().set("mutedPlayers.Players", mutedPlayers);
saveConfig();
} else {
mutedPlayers.remove(target);
p.sendMessage(ChatColor.GREEN + target.getName() + ChatColor.GREEN + " has been unmuted!");
target.sendMessage(ChatColor.DARK_RED + "You have been unmuted!");
saveConfig();
}
} else {
p.sendMessage(ChatColor.DARK_RED + "Cannot find the player.");
}
} else {
p.sendMessage(ChatColor.DARK_RED + "Proper usage of this command is: /mute <player>");
}
} else {
p.sendMessage(ChatColor.DARK_RED + "You do not have the permissions to mute players!");
}
}
}