Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

1.4 Command Alias

Comments in 'Plugin Development' started by blocksandgold, Jun 28, 2014.

  1. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    Is it still possible with the 1.4 API to do alias like this "/spawn" alias of "/warp spawn" ?
  2. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    yep
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think it is not as easy.
  4. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    How do you write it in the plugin.yml ? (API 1.4)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can't. That is why I said not as easy.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Better use PlayerCommandPreprocessEvent and ServerCommandEvent, which in fact are not doing the alias job exactly but the result is the same.
  7. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    Ok, i've done it like this then...
    Into the OnCommand method :
    PHP:
           case "spawn":
           case 
    "bank":
           case 
    "arena":
             if (
    $sender instanceof Player) {
               
    Server::getInstance()->dispatchCommand($sender"warp ".$command);
               return 
    true;
             }    

  8. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    you have to cancel the spawn event or the console well get confused and crash
  9. blocksandgold
    Offline

    blocksandgold Active Member

    Joined:
    May 7, 2014
    Posts:
    68
    Minecraft User:
    bifag
    Why ? i won't spawn after that command ? It's just a tp.
  10. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    ( I THINK ) { when you do spawn it well send a request to tp you to spawn but when you are putting another function/tp the console well get confused between tping you to spawn or to the warp something. } this is what i THINK
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes.
    PHP:
    public function onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
    public function 
    onPlayerPreCommand(PlayerCommandPreprocessEvent $event){
      if(
    substr($event->getMessage(), 01) !== "/") return;
      if(
    $this->onCommand($event->getPlayer(), substr($event->getMessage(), 1)) === false$event->setCancelled();
    }
    // same for ServerCommandEvent
    public function onCommand(CommandSender $sender$commandLine){
      if(
    in_array($commandLine, array("spawn""bank""arena"))){
        
    $this->getServer()->dispatchCommand($sender"warp $commandLine");
        return 
    false;
      }
    }
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You mean the event should be cancelled right? He wil remember it.
  13. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    yep

    edit : no . i mean cancel the function of spawn and make it the function of warp
    Last edited: Jun 28, 2014

Share This Page

Advertisement