/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/Mute.java
ViewVC logotype

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/Mute.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1969 - (hide annotations) (download)
Thu Apr 11 14:23:32 2013 UTC (11 years, 2 months ago) by torben
File size: 2011 byte(s)
Make sure to exit command function if requirements aren't met
1 torben 1968 package dk.thoerup.bukkit.hoeruputils;
2    
3     import java.util.Collections;
4     import java.util.Set;
5     import java.util.TreeSet;
6    
7     import org.bukkit.ChatColor;
8     import org.bukkit.Server;
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 CommandExecutor, Listener{
18    
19     Set<String> muted = Collections.synchronizedSet( new TreeSet<String>() );
20    
21     Server server;
22     HoerupUtilsPlugin plugin;
23    
24    
25     public Mute(HoerupUtilsPlugin plugin) {
26     this.plugin = plugin;
27     this.server = plugin.getServer();
28     }
29    
30     @Override
31     public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
32    
33     if (sender instanceof Player) {
34     Player p = (Player) sender;
35     if (p.isOp() == false && p.hasPermission("hoeruputils.mute")==false) {
36     sender.sendMessage(ChatColor.YELLOW + "You don't have permission to use this");
37     return true;
38     }
39     }
40    
41     if ( args.length != 1) {
42     sender.sendMessage(ChatColor.YELLOW + "Usage: mute|unmute <player>");
43 torben 1969 return true;
44 torben 1968 }
45    
46     Player target = server.getPlayer( args[0] );
47     if (target == null) {
48     sender.sendMessage(ChatColor.YELLOW + "Mute: Player " + args[0] + " not found");
49 torben 1969 return true;
50 torben 1968 }
51    
52     if (command.getName().equals("mute")) {
53     muted.add( target.getName() );
54     sender.sendMessage( ChatColor.YELLOW + "Mute ok" );
55     } else {//unmute
56     muted.remove( target.getName() );
57     sender.sendMessage( ChatColor.YELLOW + "Unmute ok" );
58     }
59     return true;
60     }
61    
62     @EventHandler
63     public void onPlayerChat(AsyncPlayerChatEvent event) {
64     if (muted.contains( event.getPlayer().getName() )) {
65     event.setCancelled(true);
66     event.getPlayer().sendMessage(ChatColor.YELLOW + "You cannot chat while you are muted !");
67     }
68     }
69    
70    
71     }

  ViewVC Help
Powered by ViewVC 1.1.20