Chat Lock plugin help

Discussion in 'Plugin Development' started by Brugz, May 27, 2012.

Thread Status:
Not open for further replies.
  1. Look in the console, there should be a stack trace, copy and paste it here, than we can look at what the problem is.
     
  2. Offline

    Brugz

    Nvm its doesnt working its just says the message then Administrator has blocked the chat.
    can you help me make on and off command like that?
    PHP:
      if(commandLabel.equalsIgnoreCase("blockchat")){
    player.sendMessage(ChatColor.RED "You can only type /blockchat on/off!");
              if(
    args[0].equalsIgnoreCase("on")){
    //make the plugin on
                  
    if(args[0].equalsIgnoreCase("off")){
    //make the plugin off
     
  3. sure, you almost did it already:p I'll rewrite it a bit.

    Here it is, i made this in a texteditor so i don't know if there are any errors, so just tell me if there are.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args) {
                Player player = (Player) sender;
                Plugin plugin = (Plugin) sender;
                if(commandLabel.equalsIgnoreCase("blockchat")){
                if(args.length() == 2)
                {
                        if(player.isOp()) {
                            if(args[1].equalsIgnoreCase("on"))
                        {
                            stopChat = true;
                        }
                        else if(args[1].equalsIgnoreCase("off"))
                        {
                            stopChat = false;
                        }
                       
                        }
                    else
                    {
                        return false;
                          }
                }
                return false;
                  }
            return false
          }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. Offline

    Brugz

    Thank you very much :D.

    Still doesnt working anyways can you try to fix it in your own server i will give you the scripts
    Main:
    PHP:
    package me.cc;
     
    import java.util.logging.Logger;
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    BlockChat extends JavaPlugin{
        private 
    boolean stopChat;
        public 
    boolean isStopChat(){
        return 
    stopChat;
        }
     
        public final 
    MyPlayerListener playerListener = new MyPlayerListener();
        public final 
    Logger logger Logger.getLogger("MineCraft");
     
        @
    Override
        
    public void onDisable() {
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + "Is now disabled!");
        }
     
        @
    Override
        
    public void onEnable() {
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + "Is now enabled!");
            
    PluginManager pm getServer().getPluginManager();
            
    pm.registerEvents(this.playerListenerthis);
            
    stopChat false;
    }
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[]args) {
                
    Player player = (Playersender;
                if(
    commandLabel.equalsIgnoreCase("blockchat")){
                if(
    args.length == 2)
                {
                        if(
    player.isOp()) {
                            if(
    args[1].equalsIgnoreCase("on"))
                        {
                                
    Bukkit.broadcastMessage(ChatColor.GREEN "An Administrator has disabled the chat block!");
                            
    stopChat true;
                        }
                        else if(
    args[1].equalsIgnoreCase("off"))
                        {
                            
    Bukkit.broadcastMessage(ChatColor.RED "An Administrator has blocked the chat!");
                            
    stopChat false;
                        }
                     
                        }
                    else
                    {
                        return 
    false;
                          }
                }
          }
                return 
    false;
        }
    }
    PlayerListener:
    PHP:
    package me.cc;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
     
    public class 
    MyPlayerListener implements Listener{
     
        public 
    BlockChat plugin;
        public 
    Logger log Logger.getLogger("MineCraft");
     
        @
    EventHandler(priority EventPriority.NORMAL)
        public 
    void onPlayerChat(PlayerChatEvent event) {
        
    Player p event.getPlayer();
        if(
     
        
    p.isOp()) {
        
    event.setCancelled(false);
        }else{
        
    p.sendMessage(ChatColor.RED "You are not allowed to type in the chat right now the Chat is blocked!");
        
    event.setCancelled(true);
        }
      }
    }
    BTW dude you have skype for i could chat you? :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  5. yes i have skype, nickname is the same as here, and sure, i can fix it i think.
    greetz blackwolf12333
     
  6. Offline

    Coryf88

    Um...

    Code:
    public boolean isEven(int number)
    {
          return number % 2 == 0;
    }
     
  7. Offline

    Brugz

    can you send me the full script. :p
     
  8. Yeah, lol, just took it of a website, didn't wanna think myself:p
     
  9. newbie error 1 on the forums, using [.php] instead of [.syntax=java]
     
  10. I don't even know how to add syntax to the forum posts:p
     
  11. Offline

    Coryf88

    Code:
    [syntax=java]Java here[/syntax]
     
  12. Offline

    Brugz

  13. Offline

    Kanlaki101

    Also, for your commands, you should be using Command, not CommandLabel.


    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (cmd.getName().equalsIgnoreCase("myCommand") {
    3. //Rest of code here.
    4. }
    5. }
     
  14. Yeah, i told him that already:p twice...:p
     
Thread Status:
Not open for further replies.

Share This Page