How to Mute a player from chat.

Discussion in 'Resources' started by DocRedstone, Jul 7, 2012.

  1. Offline

    DocRedstone

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    First create a String List.
    PHP:
    List<StringbannedFromChat = new ArrayList<String>();
    Then you want to register the chat event
    PHP:
    //Class Declaration
    public class Main extends JavaPlugin implements Listener {
     
    //On enable
    getServer().getPluginManager().registerEvents(thisthis);
    And finally your chat listener
    PHP:
    public void onPlayerChat(PlayerChatEvent event) {
            
    Player p event.getPlayer();
            for (
    String s bannedFromChat) {
                if (
    s.equals(p.getName())) {
                    
    event.setCancelled(true);
                    
    p.sendMessage(ChatColor.RED "[BanVote] You have been muted. You can not chat.");
                }
            }
        }
    to ban someone just add the following code after the onCommand(...) Method.

    PHP:
    bannedFromChat.add(args[0]);
    to unban someone just add the following code after the onCommand(...) Method.
    PHP:
    bannedFromChat.remove(args[0]);

    This post has been edited 3 times. It was last edited by DocRedstone Jul 7, 2012.
  2. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:
    [...]
    if (s.equalsIgnoreCase(p.getDisplayName())) {
    [...]
    You're gonna have some problems with that.
  3. Offline

    DocRedstone

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeh quick fingers. I fixed it to just include equals.
  4. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I was actually talking about the .getDisplayName(), since it can change AND contain colors so there's a way to bypass this mute.
    DocRedstone likes this.
  5. Offline

    DocRedstone

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    you can make it use getName() instead and it will work just fine.
  6. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I know, that's my point. Hence, it would be nice if you could edit your post so other people, who might use this, won't run into the issue.
    McLuke500 likes this.
  7. Offline

    DocRedstone

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Done and Done.
  8. Offline

    desht

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    bannedFromChat really needs to be a HashSet, not an ArrayList.
  9. Offline

    Blackside921

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I would do something like: if(bannedFromChat.contains(p.getName())
    instead of looping through the whole List.
  10. Offline

    md_5

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeah, you will cause pretty bad chat lag if a large server ever tries to use something based on this.

Share This Page