Overriding /plugins?

Discussion in 'Plugin Development' started by Evangon, Nov 6, 2011.

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

    Evangon

    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args0){
      if(command.getName().equalsIgnoreCase("help")){
       sender.sendMessage("test");
      } else if(command.getName().equalsIgnoreCase("plugins")){
       sender.sendMessage("test");
      }
      return true;
    
     }
    
    Tips or fixes anyone?
    Offtopic: Bukkit, stop screwing up the edit post box.
     
  2. Offline

    h4344

    So wait whats your issue exactly?
     
  3. Offline

    Evangon

    When I use /plugins, it doesn't return "test" to me, it returns the list of plugins.
     
  4. Offline

    h4344

    Can i see your plugin.yml? i think i know what your problem is.
     
  5. Offline

    Evangon

    Code:
    name: HelpMePatchy
    version: HaxSignEdition
    main: book.page
    
    commands:
     help:
      description: Request basic help.
      usage: /help
     plugins:
      description: Gets plugin listings.
      usage: /plugins
    Everything works, except /plugins

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  6. Offline

    h4344

    The problem was /plugins is already a command so you cant replace it that easy i believe. I changed the command to /pluginsl and it prints out test2 just fine. Also i edited the package name and all that so dont forget to change it back. If you have anymore questions just let me know :)

    Heres your Main Class:

    package me.h4.Basic;

    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Basic extends JavaPlugin {
    public void onEnable() {

    Logger.getLogger("Minecraft").info(this + " is now Enabled!");
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    if(cmd.getName().equalsIgnoreCase("help")){
    sender.sendMessage("Test1");
    return true;
    }
    else if (cmd.getName().equalsIgnoreCase("pluginsl")){
    sender.sendMessage("Test2");
    return false;
    }
    return false;
    }
    public void onDisable() {
    Logger.getLogger("Minecraft").info(this + " is now Disabled!");
    }
    }

    And heres your plugin.yml:

    name: HelpMePatchy
    version: HaxSignEdition
    main: me.h4.Basic.Basic
    commands:
    help:
    description: Request basic help.
    usage: /help
    pluginsl:
    description: Gets plugin listings.
    usage: /pluginsl
     
  7. Offline

    Evangon

    Nonono, I was trying to replace the /plugins command, not create another >_>
    You could replace /help, so why not /plugins?
     
  8. Offline

    knoxcorner

    I'm not sure this will work, but try adding a chat listener and whenever the message is /plugins or /pl, cancel it use a player.sendMessage(String) or something like that with what you want to have.




    Heh, just kidding... Doesn't work.
     
  9. Offline

    h4344

    ooooooooo ok lemme look around lol. Now the title makes sense to me.

    I think this would be your best bet too. I read that putting commands in the plugin.yml should replace them but since its clearly not, that option that he suggested would be best.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  10. Offline

    Evangon

    I'll try it.
    I'm not familer with Listener's, so expect some questions from me.
     
  11. Offline

    knoxcorner

    @Evangon Sorry, doesn't work, just tried it...
     
  12. Use onCommandPreprocess if you want to override stuff (not advised to do so at all, though).
     
  13. Offline

    Evangon

    Code:
    package book;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class ear extends PlayerListener {
        public page plugin;
    
        public ear(page ear) {
            plugin = ear;
        }
        @Override
        public void onPlayerChat(PlayerChatEvent event){
            String temp = event.getPlayer().getDisplayName();
            String tstr = event.getMessage();
            if (tstr.equalsIgnoreCase("/plugins")){
                event.setCancelled(true);
                Player tplyr = Bukkit.getServer().getPlayer(temp);
                tplyr.sendMessage("test");
             };
    }
    
    Still returns the list of plugins in the server.

    Oh, I didn't reload the page. Stupid me. K, lemmie try Pan's suggestion.
    1 secound just to post.
    Wow.
    Reag. No work for Pan's suggestion.
    Code:
    package book;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
    public class ear extends PlayerListener {
     public page plugin;
     public ear(page ear) {
      plugin = ear;
     }
        public void onCommandPreprocess(PlayerChatEvent event){
         String temp = event.getPlayer().getDisplayName();
         String tstr = event.getMessage();
         if (tstr.equalsIgnoreCase("/plugins")){
          event.setCancelled(true);
          Player tplyr = Bukkit.getServer().getPlayer(temp);
       tplyr.sendMessage("test")
         }
        };
    }
    
    EDIT: I tried putting it in my main class, it failed.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  14. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {}
     
  15. Offline

    Evangon

    Code:
    package book;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class ear extends PlayerListener {
        public page plugin;
    
        public ear(page ear) {
            plugin = ear;
        }
        public void onCommandPreprocess(PlayerCommandPreprocessEvent event){
            String temp = event.getPlayer().getDisplayName();
            String tstr = event.getMessage();
            if (tstr.equalsIgnoreCase("plugins")){
                event.setCancelled(true);
                Player tplyr = Bukkit.getServer().getPlayer(temp);
                tplyr.sendMessage("test");
            }
        }
    };
    
    Doesn't work either, @tips48
     
  16. Offline

    coldandtired

    It has to be in the main class, not a Listener.
     
  17. Offline

    Acrobot

    Did you register the event?
    Also - are you sure it's event.getMessage() and it returns just "plugins", not "/plugins"?

    @coldandtired
    You're wrong. It's a listener, therefore it must be in a different class.
     
  18. Offline

    coldandtired

    Hmm, you're right. Thought it was related to CommandSender but I see it extends PlayerChatEvent.

    That's what I get for skimming a thread! :)
     
  19. equalsIgnoreCase("/plugins") maybe?
     
  20. Offline

    Baba43

    PlayerListener
    Code:
    	public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    		dttm.getCommand(event);
    	}
    
    ddtm
    Code:
    	public void getCommand(PlayerCommandPreprocessEvent event) {
    		String[] args = event.getMessage().substring(1).split(" ");
    
    		if(args[0].equalsIgnoreCase("plugins") || args[0].equalsIgnoreCase("pl")) {
    event.setCancelled(true);
    		}
    
    	}
    
    Also make sure you registered the event
    Code:
    pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS,new ChatListener(this),Priority.Lowest,this);
    
     
  21. Offline

    stelar7

Thread Status:
Not open for further replies.

Share This Page