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

Adding Commands with tasks

Comments in 'Plugin Development' started by Skullex, Nov 28, 2015.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    How would I code this, I need an example :)
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    What do you mean?
    Are you trying to run a command using a task?
    Please explain some more.
  3. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Yes, I am. How would I code this for example "teleporting every player to a set given point in the game and back to spawn on the two different commands that have been used" also how would I Create a configuration using php. I'm new to this and PHP Academy is not supported on mobile platform's such as mine..
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You could just use the teleport() function within the task.

    To actually use commands:
    Use $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);

    And there are a few ways you can create configurations, I'll show you my method.
    PHP:
    // How to create the config:
        
    public function onEnable() {
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML, array(
            
    "message" => "This is a test",
            
    "message2" => "This is a second test"
            
    ));
        }

        
    // How to get information from the config:
        
    $this->config->get("message");

        
    // Getting information from the config in an event:
        
    public function onJoin(PlayerJoinEvent $event) {
            
    $event->getPlayer()->sendMessage($this->config->get("message")); // Will sendMessage "This is a test" to player
            
    $event->getPlayer()->sendMessage($this->config->get("message2")); // Will sendMessage "This is a second test" to player
        
    }

        
    // How to change information in the config:
        
    $this->config->set("message""This message is changed"); // Changes what was once "This is a test" to "This message is changed"
        
    $this->config->save(); // Saves the config

        // Using it in an event:
        
    public function onChat(PlayerChatEvent $event) {
            
    $message $event->getMessage();
        
            
    $this->config->set("message"$message); // Changes "This is a test" to whatever the player says
            
    $this->config->save(); // saves config
        
    }
    }
    Please keep in mind that these are only examples, and configs can be used for many other things.
    Skullex likes this.
  5. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    TY

Share This Page

Advertisement