Alright so understand the use of Hashmaps to add a player to a mute which i have done and implemented, however i do not understand how one would add hours, minutes, seconds to the mute if someone could give me a quick crash course that would be awesome atm the i just have the feature that permanantly adds the player to the hashmap, mutes them and then typing the command again unmuted them and removes them from the hashmap.
@x_Jake_s It depends on how you manage your map, but I would suggest using Code: Map<UUID, Date> mutedPlayers So you can have the date of when their mute expires, and if they are not in the map then they are not muted.
@x_Jake_s Hashmap: generally, map implementations like hashmaps, weakhashmaps ect, have different properties. The most common in bukkit plugin dev, is hashmap. So a map is like a table that stores a key and a value. to get the value you input the key and it returns the value. So lets say i have map: HashMap<String, String> map = new HashMap<>(); map.put("Hi","Hello"); map.put("Bye","cya"); map.put(""," to you!"); So the map will be like: So if i do: Bukkit.broadcastMessage(map.get("Hi")); it will broadcast "Hello" since thats the assigned value. In your case: Take a map <UUID,Long> in uuid purt player's uuid and in Long put system.curentTimeMils()+(timeinseconds/1000); when thwy try to chat check if they are in the map (map.containsKey(playersuuid)) and if they are cancel the event! Otherwise, let them chat. Careful!: when they chat, first check if they belong in the map, and once they do, check if the long assigned to them is <= to system.curenttimemills(); if it is, remove them from the map, it means their time is over Phew, hope that helps!
Okay i loved the picture btw but heres what i have coded and im not sure how to implement the timing in it : (im only including the actual code for the single command to protect my plugin rights) Code: public ArrayList<String> mute = new ArrayList<String>(); if (command.getName().equalsIgnoreCase("mute")) { if (args.length < 1) { sender.sendMessage(prafix + ChatColor.WHITE + "Usage: /mute <player> [time]"); return false; } else { String message = ""; if (args.length > 1) { for (int i = 1; i < args.length; i++) { message = message + args[i] + " "; } } Player p = Bukkit.getPlayer(args[0]); if ((p == null) || p.hasPermission("chatadmin.mute.bypass")) { sender.sendMessage(prafix + ChatColor.GREEN + p.getName() + ChatColor.RED + " is not online or you cannot mute that player."); } else { if (mute.contains(p.getName())) { mute.remove(p.getName()); p.sendMessage(prafix + ChatColor.GREEN + "You have been unmuted!"); Bukkit.broadcastMessage(ChatColor.AQUA + sender.getName() + ChatColor.GREEN + " has Unmuted " + ChatColor.AQUA + p.getName() + "."); } else { mute.add(p.getName()); p.sendMessage(prafix + ChatColor.GREEN + "You have been Muted by " + sender.getName()); Bukkit.broadcastMessage(prafix + ChatColor.AQUA + sender.getName() + ChatColor.GREEN + " has muted " + ChatColor.AQUA + p.getName() + ChatColor.GREEN + " for " + ChatColor.RED + message); } } } } now after reading what you have put i kind of understand a little bit more but im still not there at where to insert the items im guessing its the basic : public HashMap<UUID, Long) mute = new HashMap<UUID, Long>(); and then to add the player to it: muted.put(p.getName() + System.curentTimeMils()+(interval/1000); but it doenst work? ** and yes the command i showed doesnt have a permission link but i add that in usually when i finish the command.
so would i add a third variable to the hashmap? like UUID, String, Long? im still doing trial and error in my plugin so i might figure it out eventually but i do need help when i cant get it. Edit #1: okay so i think i finally got the code to be happy with: Code: public HashMap<String, Long> mute1 = new HashMap<String, Long>(); if (mute1.containsKey(p.getName())) { mute1.put(p.getName(), System.currentTimeMillis()+(interval/1000)); is this right? Edit #2: i think i finally got it to work: Code: if (mute1.containsKey(p.getName())) { mute1.remove(p.getName()); p.sendMessage(prafix + ChatColor.GREEN + "You have been unmuted!"); Bukkit.broadcastMessage(prafix + ChatColor.AQUA + sender.getName() + ChatColor.GREEN + " has Unmuted " + ChatColor.AQUA + p.getName() + "."); } else { if (mute1.containsKey(p.getName())) { mute1.remove(p.getName()); p.sendMessage(prafix + ChatColor.GREEN + "You have been Muted!"); Bukkit.broadcastMessage(prafix + ChatColor.AQUA + sender.getName() + ChatColor.GREEN + " has Muted " + ChatColor.AQUA + p.getName() + "."); } } } [code]
You were declaring a hashmap with a UUID, then you were assigning values with the player's name, which is a string, not a UUID.