Overriding Default Commands?

Discussion in 'Plugin Development' started by morshu9001, Jun 19, 2013.

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

    morshu9001

    I know that to override a default Bukkit command, you just put it in plugin.yml and set it up like a normal command. But I want to use Server.dispatchCommand on the command that I just overrode. Is there no way to do the equivalent of a "super.method()" dispatchCommand?

    More specifically, I'm overriding ban-ip <player|address>. I want my command to do something and then dispatch the Bukkit original ban-ip <player|address>, not my modified one.
     
  2. Offline

    the_merciless

  3. Offline

    Alex5657

    Ah, here you would need to use a clever way called "reflection". Try this (not sure if it works):
    Code:java
    1. SimpleCommandMap cmap = null;
    2. try{
    3. if(Bukkit.getServer() instanceof CraftServer){
    4.  
    5. final Field f = CraftServer.class.getDeclaredField("commandMap");
    6. f.setAccessible(true);
    7. cmap = (SimpleCommandMap)f.get(Bukkit.getServer());
    8. vcmds = cmap.getFallbackCommands();
    9. for(VanillaCommand cmd:vcmds){
    10. if(cmd instanceof BanIpCommand){
    11. vcmds.remove(cmd);
    12. vcmds.add(new CustomBanIpCommand());
    13. break;
    14. }
    15. }
    16. }
    17. } catch (Exception e){
    18. e.printStackTrace();
    19. }

    And create the class for the command:
    Code:java
    1. public class CustomBanIpCommand{
    2. @Override
    3. public void execute(CommandSender sender,String currentAlias,String[] args){
    4. //Code goes here
    5. }
    6. }
     
  4. Offline

    OcelotcR

    PreProcessCommandEvent I believe its called, look into that.
     
  5. Offline

    morshu9001

    Thanks, but I don't understand how to use this to call commands. Am I supposed to initialize one and input it to some other method? I also can't figure out how to initialize it because it requires a Player parameter for the sender, and I want to send it as the console.

    I could use an event listener to listen for a PlayerCommandPreprocessEvent and act appropriately if the right command was called, but I want this to work with console commands as well.
     
Thread Status:
Not open for further replies.

Share This Page