Mute plugin

Discussion in 'Plugin Development' started by DMDO1599, May 2, 2014.

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

    DMDO1599

    ok so i coded this plugin earlier in the morning and it uses a array list and i cant remove the player from the array list

    here is the code:

    Code:java
    1. package me.DMDO1599.Listener;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import me.DMDO1599.main;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.AsyncPlayerChatEvent;
    16.  
    17. public class Mute implements Listener, CommandExecutor{
    18.  
    19. public ArrayList<String> mute = new ArrayList<String>();
    20.  
    21.  
    22. private main plugin;
    23.  
    24. public Mute(main instance){
    25. this.plugin =instance;
    26. this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
    27.  
    28. }
    29. @EventHandler
    30. public void onChat(AsyncPlayerChatEvent e){
    31. Player p = e.getPlayer();
    32. if(mute.contains(p.getName())){
    33. e.setCancelled(true);
    34. p.sendMessage(ChatColor.DARK_RED + "You are still muted!");
    35. }
    36. }
    37.  
    38.  
    39. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    40.  
    41. Player p = (Player) sender;
    42.  
    43. if(commandLabel.equalsIgnoreCase("mute")){
    44. if(args.length == 0){
    45. p.sendMessage(ChatColor.RED + "Incorrect usage /mute <username>");
    46. return true;
    47. }
    48. if(args.length == 1){
    49.  
    50. Player online = Bukkit.getPlayer(args[0]);
    51. if(online == null || !online.isOnline()){
    52. p.sendMessage(ChatColor.RED + "Player: " + args[0] + " is not online");
    53. }else{
    54. mute.add(online.getName());
    55. p.sendMessage(ChatColor.GREEN + "You have succesfully muted: " + online.getName());
    56. online.sendMessage(ChatColor.RED + "You have been muted by: " + p.getName());
    57. }
    58. }
    59. }
    60. if(commandLabel.equalsIgnoreCase("unmute")){
    61. if(args.length == 0){
    62. p.sendMessage(ChatColor.RED + "Incorrect usage /unmute <username>");
    63. return true;
    64. }
    65. if(args.length == 1){
    66.  
    67. Player online = Bukkit.getPlayer(args[0]);
    68. if(online == null || !online.isOnline()){
    69. p.sendMessage(ChatColor.RED + "Player: " + args[0] + " is not online");
    70. }else{
    71. mute.remove(online.getName());
    72. mute.remove(online.getName());
    73. mute.remove(online.getName());
    74. p.sendMessage(ChatColor.GREEN + "You have succesfully unmuted: " + online.getName());
    75. online.sendMessage(ChatColor.GREEN + "You have been unmuted by: " + p.getName());
    76. }
    77. }
    78. }
    79. return false;
    80. }
    81. }
    82.  
     
  2. Offline

    Superckl1

    DMDO1599

    First of all, use Collections.synchronizedList(new ArrayList<String>()); for your mute list. Chat us handled in an asynchronous thread.

    What happens you try the unmute command?
     
  3. Offline

    unforgiven5232

    DMDO1599 so why did u make 2 forum posts for this?
     
  4. Offline

    DMDO1599

    when i do the unmute it sends the message but it doesnt removes you from the array list
    i need to fix this fast plz :S
     
Thread Status:
Not open for further replies.

Share This Page