Clear chat / chat toggle

Discussion in 'Plugin Development' started by iamcion, Oct 23, 2015.

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

    iamcion

    Hey there! I have the command /chat clear working, but not /chat pclear working. I want it to clear a players personal chat. I also want a /chat toggle command, but I don't know how to go about that, can someone please help me?

    My class file:

    Code:
    package me.iamcion.vcommands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public class Chat
    implements Listener, CommandExecutor
    {
    
          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
          {
            String Prefix = ChatColor.BLUE + "" + ChatColor.BOLD + "Chat" + ChatColor.GREEN + ChatColor.BOLD + ">" + ChatColor.RED + ChatColor.BOLD + "> ";
            Player player = (Player)sender;
            if (commandLabel.equalsIgnoreCase("chat"))
            {
              if ((!player.hasPermission("vortex.chat")) &&
                (!player.isOp()))
              {
                  player.sendMessage(ChatColor.BLUE + "VortexCommands> " + ChatColor.RED + "This is a staff-only command!");
                return false;
              }
              if (args.length == 0)
              {
                player.sendMessage(Prefix + ChatColor.DARK_RED + "Incorrect usage!");
                player.sendMessage(Prefix + ChatColor.DARK_RED + "Correct usage: /chat [toggle/clear/pclear]");
              }
              else if (args.length == 1)
              {
                if (args[0].equalsIgnoreCase("clear"))
                      if ((player.hasPermission("vortex.gclear")) || (player.isOp()))
                      {
                        for (int x = 0; x < 120; x++)
                        {
                          Bukkit.broadcastMessage("");
                          if (x == 119)
                          {
                    Bukkit.broadcastMessage(Prefix + ChatColor.GREEN + player.getName() + ChatColor.YELLOW + " has cleared the chat!" );
                          }
                        }
                        if (args[0].equalsIgnoreCase("pclear"))
                            if ((player.hasPermission("vortex.pclear")) || (player.isOp()))
                          {
                            for (int x = 0; x < 120; x++)
                            {
                              sender.sendMessage("");
                              if (x == 119)
                              {
                        Bukkit.broadcastMessage(Prefix + ChatColor.YELLOW + " you have cleared your chat!" );
                              }
                            }
                          }
                      }
              }
            }
            return false;
          }
    }
     
  2. Offline

    teej107

    @iamcion Can you explain what those commands are supposed to do so we are on the same page?
     
  3. Offline

    Scimiguy

    @teej107
    I believe clear is meant to clear everyone's chat, and pclear is meant to clear a specific person

    The reason it's not working is because you have your "pclear" check inside your "clear" check. A string can't be two things at once.

    Fix up your spacing and braces to see where things are aligned
     
  4. Offline

    boomboompower

    @iamcion
    Offtopic, use the [code ] brackets with java, not javascript :p
     
  5. Offline

    Zombie_Striker

    If you're using multiple classes to separate things, don't add listeners and CommandExecutors to the same class. Also, you don't have any event sin that class.
    Don't cast without checking.

    Your oncommand is very messy. It does not really seem oganized, well thought through, Please clean up your code a little bit.

    Also, JAVASCIPT! AWAY WITH THEE!
     
  6. Offline

    iamcion

    nevermind guys, I have it all done ;) thanks anyway!
     
  7. Offline

    VortexGmer

    Holy cow your server it's called vortex too? Stealer
     
Thread Status:
Not open for further replies.

Share This Page