Need Help With MUTE - Certain Time

Discussion in 'Plugin Development' started by 123ang, Aug 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    123ang

    Hey there, I've got a fully functioning mute command here. However, it can only mute for permanent. Here's my code:

    The ArrayList:

    Code:java
    1. public ArrayList<String> mute = new ArrayList<String>();


    The Command:

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("mute")){
    2. if (player.hasPermission("mute.player")){
    3.  
    4. if (args.length == 0){
    5. player.sendMessage(ChatColor.GOLD + "Punishment> " + ChatColor.RED + "Please specify the player's name & the duration.");
    6. return false;
    7. } else if (args.length == 1){
    8.  
    9. Player target = Bukkit.getServer().getPlayer(args[0]);
    10. if (target == null) {
    11. player.sendMessage(ChatColor.GOLD + "Punishment> " + ChatColor.GRAY + "0 matches for " + ChatColor.RED + args[0] + ChatColor.GRAY + ".");
    12. return false;
    13. } else{
    14. mute.add(target.getName());
    15. player.sendMessage(ChatColor.GOLD + "Punishment> " + ChatColor.GREEN + target.getName() + ChatColor.GRAY + " was muted.");
    16. target.sendMessage(ChatColor.GOLD + "Punishment> " + ChatColor.GRAY + "You were muted by " + ChatColor.GREEN + player.getName() + ChatColor.GRAY + ".");
    17. Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Punishment> " + ChatColor.YELLOW + player.getName() + ChatColor.GRAY + " muted " + ChatColor.YELLOW + target.getName() +
    18. ChatColor.GRAY + " for " + ChatColor.GREEN + "Permanent" + ChatColor.GRAY + ".");
    19. return true;
    20. }
    21. }
    22. } else{
    23. player.sendMessage(ChatColor.GRAY + "This requires the permission rank " + ChatColor.GRAY + "[" + ChatColor.RED + "ADMIN" + ChatColor.GRAY + "]");
    24. }
    25.  
    26. }


    The Event:

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerChat(AsyncPlayerChatEvent event){
    3. if (mute.contains(event.getPlayer().getName())){
    4. event.getPlayer().sendMessage(ChatColor.GOLD + "Punishment> " + ChatColor.GRAY + "Shhhh! Your muted!");
    5. event.setCancelled(true);
    6. } else{
    7. event.setCancelled(false);
    8. }
    9. }


    Both of the code segments above are in the same class.

    As you can see in my command I have mute.add(target.getName()); I would like it to be something like: mute.add(target.getName(), 20); The 20 is for 1 second of mute.

    Thanks in advance! :)
     
  2. Offline

    NonameSL

    Capture the date of the mute, and then in the chat event compare dates and check if the time has passed. If it has - let him speak, and remove him from the list. If it has not - don't let him speak. Also, I suggest using a list in the config or any YML file, so if the server reloads the mutes won't reset. For the capturing, you could create a class containing the player, the time to be muted, and the date of the mute, and then have a list of all of these classes.
     
    Datdenkikniet likes this.
Thread Status:
Not open for further replies.

Share This Page