Command /plugins override

Discussion in 'Plugin Development' started by GalaxyBeatzz, Mar 8, 2014.

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

    GalaxyBeatzz

    Hi I made my own custom coded plugin for /pl and /plugins to say a custom message, but only /pl reacts. /plugins does what it always does, counts your plugins and show them. Only /pl is giving me a custom message.
    Please help!
    http://pastebin.com/5BFQ4wMh (Link expires in 2 weeks)
     
  2. Offline

    TomYaMee

  3. Offline

    Necrodoom

    Moved to correct section.
     
  4. Offline

    StealerSlain

    Where's returns?
     
  5. Offline

    GalaxyBeatzz

    What you mean?
     
  6. Offline

    Krymonota

    In your code is missing:
    Code:
    return true;
     
  7. Offline

    GalaxyBeatzz

    I have return false;... Should be working right?
    EDIT: What I was trying to say is that /pl works, but /plugins doesn't.
     
  8. Offline

    TemphisEquinox

    Check it with the Event. This is a ready source for you.
    Code:java
    1. @EventHandler
    2. public void onPlayerCommand(PlayerCommandPreprocessEvent e){
    3. if(e.equals("plugins") || e.equals("pl") || e.equals("/plugins") || e.equals("/pl")){
    4. e.setCancelled(true);
    5. Player sender = e.getPlayer();
    6. sender.sendMessage("Do your message here.");
    7. }
    8. }
    9.  
     
  9. Offline

    StealerSlain

    Ah... I see. Delete
    in
    Also, return true should be here:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("plugins")) {
    2. player.sendMessage(ChatColor.GREEN + "CruelKits uses their own custom coded plugins, thats why we shouldn't have any reason to show these plugins. If you want to buy any of these custom coded plugins you can contact GalaxyBeatzz. Because we have more coders I'll maybe send you to another person.");
    3. return true;
    4. }
    5. if(cmd.getName().equalsIgnoreCase("pl")){
    6. player.sendMessage("blabla");
    7. return true;
    8. }
     
  10. Offline

    GalaxyBeatzz

    Oh thanks so much! I'll see if this worked :)

    Sorry man /plugins still gives the default message...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    viper_monster

    GalaxyBeatzz you will have to use PlayerCommandPreprocesEvent for /plugins
     
  12. Offline

    Arcoz

    Instead you could check if the permission made is /plugins with an eventhandler:

    PHP:
        public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
            
    Player p event.getPlayer();
            
    //if the command is /plugins
            
    if (event.getMessage().toLowerCase().startsWith("/plugins")){
            
    //Send custom message
            
    p.sendMessage("Overrides command");
      }
    }
    Here you could ofcourse add a perm:

    PHP:
        public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
            
    Player p event.getPlayer();
            
    //If command is /plugins
            
    if (event.getMessage().toLowerCase().startsWith("/plugins")){
            
    //If player has this perm
            
    if(p.hasPermission("This permission"){
            
    //Do nothing (Make the command like it would default)
            
    return;
            } else {
            
    //Do custom command
            
    p.sendMessage("own custom plugins");
            }
        }
    }
     
  13. Offline

    GalaxyBeatzz

    I'm not the plugin expert... Please explain.
     
  14. Offline

    Arcoz

  15. Offline

    EnderTroll68

    Hey! I know the problem. Change it to ONLY /plugins. Remove /pl completely.

    Then go into your plugin.yml, and make sure that in the commands you have something that looks something like this:
    Code:
    name: blah
    main: blah.blah.blah.blah
    version: blah
    commands:
      plugins:
        usage: /<command>
        description: blah blah blah
        aliases: [pl]
    This will make is so when someone does /plugins OR /pl it will run your command
     
  16. Offline

    GalaxyBeatzz

    Thanks! It's testing time!

    Now both of them stopped working... :confused:

    Updated source: http://pastebin.com/D0ZAZbpn

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  17. Offline

    TemphisEquinox

    Just use this, like we said before.
    Code:java
    1. public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    2. Player p = event.getPlayer();
    3. //if the command is /plugins
    4. if (event.getMessage().toLowerCase().startsWith("/plugins")){
    5. //Send custom message
    6. p.sendMessage("Overrides command");
    7. }
    8. }
     
  18. Offline

    GalaxyBeatzz

  19. Offline

    Borlea

    GalaxyBeatzz
    /plugins is handled by bukkit, only way to override it is if you use PlayerCommandPreprocessEvent

    How you would do it is add this to your main class and make your main class implement Listener

    public class Main extends JavaPlugin implement Listener{
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
    4. Player p = e.getPlayer();
    5. if (e.getMessage().toLowerCase().startsWith("/plugins")){
    6. e.setCancelled(true);
    7. p.sendMessage("Your Message");
    8. }
    9. }
    10.  


    Then to register the event, go into onEnable and do getServer().getPluginManager().registerEvents(this, this);
     
  20. Offline

    GalaxyBeatzz

    I'm not very good at this shit. Where do I need to paste this code? Under wich line of code...
     
  21. Offline

    Arcoz

    Learn some java, watch some tutorials on youtube on how to use eventhandlers...
     
Thread Status:
Not open for further replies.

Share This Page