I made a request plugin but when any user logsout the cooldown disapears how do i make it so it keeps there? Code: package Commands; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.dylanswavonski.testplugin.Main; import net.md_5.bungee.api.ChatColor; public class RequestCommand implements CommandExecutor { private Main main; public RequestCommand (Main main) { this.main = main; } public String bold = ChatColor.BOLD + ""; public String italic = ChatColor.ITALIC + ""; public String strikethrough = ChatColor.STRIKETHROUGH + ""; @SuppressWarnings("deprecation") @Override public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) { Player p = (Player) sender; if (main.cooldown.containsKey(p) && main.cooldown.get(p) > System.currentTimeMillis()) { long longRemaining = main.cooldown.get(p) - System.currentTimeMillis(); int intRemaining = (int) (longRemaining/1000); p.sendMessage(ChatColor.DARK_RED + bold + "(!) " + ChatColor.RED + "There is " + ChatColor.GREEN + intRemaining + ChatColor.GREEN + "s" + ChatColor.RED + " left before you can use this command again.."); } else { if(!(sender instanceof Player)) { sender.sendMessage("Players only command"); return true; } if(args.length >= 1) { Player t = sender.getServer().getPlayer(args[0]); if(t == null) { sender.sendMessage(ChatColor.RED + "Player ''" + ChatColor.WHITE + args[0] + ChatColor.RED + "'' is not online!"); } else { String reason = ""; int x = 0; for (String a : args) { if (x == 1) { x++; continue; } reason = reason + " " + a; } reason = reason.trim(); sender.sendMessage(ChatColor.DARK_GREEN + bold + "(!) " + ChatColor.GREEN + "We have submitted your report and Staff has been notified globally, Thank you."); main.cooldown.put(p, System.currentTimeMillis() + (60 * 1000)); for (Player staff : Bukkit.getServer().getOnlinePlayers()) { if(staff.hasPermission("report.see")) { staff.sendMessage(ChatColor.GRAY + strikethrough + "-------------------------"); staff.sendMessage(ChatColor.DARK_RED + "* " + ChatColor.RED + "Reported: " + ChatColor.GRAY + t.getName()); staff.sendMessage(ChatColor.DARK_RED + "* " + ChatColor.RED + "Reporter: " + ChatColor.GRAY + p.getName() ); staff.sendMessage(ChatColor.DARK_RED + "* " + ChatColor.RED + "Reason: " + ChatColor.GRAY + reason); staff.sendMessage(ChatColor.GRAY + strikethrough + "-------------------------"); } } } } else { sender.sendMessage(ChatColor.RED + "Usage: /report <user> <reason>"); } } return false; } { } { } { } }
@nowhere Don't cast to Player before you know that it is a player. Use UUID's in the main.cooldown instead of Player objects.
as @timtower already said, first check if the sender is a player and then cast it to a player. and also don't save the player object, save his UUID. I made something similar in a plugin of mine: https://dev.bukkit.org/projects/daytime It should be all in there, if you wan't you can decompile it and get an idea how to do it
You think i could get the a part of getting the UUID so i can play around with it and try to implement it?. I'm not quite sure how to use UUID thats why i cast it to a player.
It's quite simple, instead of creating an ArrayList you create a HashMap<UUID, somethingelse> when getting the values you use arraylist.get(player.getUUID()); //was coded out of mind so something could be wrong