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

[New API] Question about plugin

Comments in 'Plugin Development' started by Hiddenfootball, Jul 21, 2014.

  1. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Hello,
    I was thinking, and quickly made up a plugin. I'm asking would this work? This is spossed to (in my thoughts) teleport players to specific coordinates when they enter a world. Like a HungerGames spawn pads.
    Code:
    PHP:
    <?php

    namespace MulipleSpawns;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;
    //do not change
    private $p 1;
    //coords
    private $coord1 $c1
    private $coord2 $c2;
    private 
    $coord3 $c3;
    private 
    $coord4 $c4;
    private 
    $coord5 $c5;
    private 
    $coord6 $c6;
    private 
    $coord7 $c7;
    private 
    $coord8 $c8;
    private 
    $world $aworld
    private $valve;
    private 
    $messege;

    class 
    MulipleSpawns extends PluginBase implements Listener{

        public function 
    onLoad(){
        }

        public function 
    onEnable(){
            
    $this->getLogger()->info(TextFormat::DARK_GREEN "Muliple Spawns is enabled!");
            
    $this->getLogger()->info(TextFormat::DARK_BLUE "[MulipleSpawns] Made by iFootball");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::DARK_RED "Advanced World Spawns is disabled!");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
        {
            if (
    strtolower($sender->getName()) !== "console") return $this->onCommandByUser($sender$command$label$args);
            switch (
    $command->getName()) {
                case 
    "ms":
                    
    $subCommand strtolower(array_shift($args));
                    switch (
    $subCommand) {
                        case 
    "":
                        case 
    "help":
                            
    $sender->sendMessage("/ms help");
                            
    $sender->sendMessage("/ms world (The world that teleports the players to the positions)");
                            
    $sender->sendMessage("/ms cord1");
                            
    $sender->sendMessage("/ms cord2");
                            
    $sender->sendMessage("/ms cord3");
                            
    $sender->sendMessage("/ms cord4");
                            
    $sender->sendMessage("/ms cord5");
                            
    $sender->sendMessage("/ms cord6");
                            
    $sender->sendMessage("/ms cord7");
                            
    $sender->sendMessage("/ms cord8");
                            break;

                    case 
    "world":
                    
    $sender->getLevel() = $this->aworld;
                    
    $sender->sendMessage("[MulipleSpawns] World set.");
                    case 
    "cord1":
                    
    $c1 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 1 at "$c1 ."created");
                    case 
    "cord2":
                    
    $c2 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 2 at "$c2 ."created");
                    case 
    "cord3":
                    
    $c3 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 3 at "$c3 ."created");
                    case 
    "cord4":
                    
    $c4 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 4 at "$c4 ."created");
                    case 
    "cord5":
                    
    $c5 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 5 at "$c5 ."created");
                    case 
    "cord6":
                    
    $c6 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 6 at "$c6 ."created");
                    case 
    "cord7":
                    
    $c7 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 7 at "$c7 ."created");
                    case 
    "cord8":
                    
    $c8 $sender->getX(), $sender->getY(), $sender->getZ();
                    
    $sender->sendMessage("[MulipleSpawns] Position 8 at "$c8 ."created");
                    case 
    "messege":
                    
    $this->valve array_shift($args);
                    
    $this->messege array_shift($args);
                        if (
    is_null($this->valve) or is_null($this->messege)) {
                            
    $sender->sendMessage("Usage: /ms on/off <messege>");
                                break;
                            }
                        if (
    $this->valve === "on") {
                        
    $sender->sendMessage("[MulipleSpawns] Messege set!");
                        }
                        else {
                            
    $sender->sendMessage("[MulipleSpawns] No messege!");
                        }
                    case 
    "bypass":
                    
    $rawnames array_shift($args);
                    
    $this->bypass = array($rawnames)
                            if (
    is_null($this->bypass)) {
                                
    $sender->sendMessage("Usage: /ms bypass <names>");
                                break;
                                }
                    }
                    }
                    return 
    true;

                default:
                    return 
    false;
            }
        }

        public function 
    onSwitchLevel(EntityLevelChangeEvent $event){
            if (
    $event->getTarget() === $this->world) {
                
    $player $event->getEntity();
                if (
    $player $this->bypass) {
                    
    $sender->sendMessage("[MulipleSpawns] You have bypassed the Muliple spawns");
                    break;
                }
                if (
    $this->valve === "on") {
                
    $sender->sendMessage($this->messege);
                }
                if(
    $player instanceof Player){
                if (
    $this->=== 1) {
                
    $player->teleport(new Vector3($this->coord1));
                
    $this->+= 1;
                }
                if (
    $this->=== 2) {
                
    $player->teleport(new Vector3($this->coord2));
                
    $this->+= 1;
                }
                if (
    $this->=== 3) {
                
    $player->teleport(new Vector3($this->coord3));
                
    $this->+= 1;
                }
                if (
    $this->=== 4) {
                
    $player->teleport(new Vector3($this->coord4));
                
    $this->+= 1;
                }
                if (
    $this->=== 5) {
                
    $player->teleport(new Vector3($this->coord5));
                
    $this->+= 1;
                }
                if (
    $this->=== 6) {
                
    $player->teleport(new Vector3($this->coord6));
                
    $this->+= 1;
                }
                if (
    $this->=== 7) {
                
    $player->teleport(new Vector3($this->coord7));
                
    $this->+= 1;
                }
                if (
    $this->=== 8) {
                
    $player->teleport(new Vector3($this->coord8));
                
    $this->-= 7;
            }
            }
        }
    }






    }






    }
    Last edited: Jul 22, 2014
    18wyj2 and LDX like this.
  2. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    what is $this-p for ? i well also do some corrections
  3. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Changed,
    It's a private variable (as seen on top)
  4. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    then you don't need the quotes use if ($this->p === 1){ , you forgot to put which level they are going to , to do that you should use $event->getTraget() and if you want get the level they are from use $event->getOrigin()
  5. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    And would I have to add a data storing system (storing the coords if I were going to have a command that sets the coords)?
  6. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Code updates at the top
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I don't recommend using aws as a command. :p (Amazon Web Services)
  8. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Ok :D, I'll change. Everything else looks good?
  9. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Would we be good? Or would it be to close to SimpleWorlds. Any good name ideas?
  10. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Well, this wouldn't be a very good standalone plugin...
  11. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    I added some fetures to make it more suitable. I mainly made this plugin for,
    http://forums.pocketmine.net/thread...eperate-position-when-they-join-a-world.4425/
    But this could be used for HungerGames, Factions (Teleporting players far away from each other to get resources), and minigames. If someone could confirm that I did the bypass right, (and the other features).
    I edited the original code ^.
    LDX likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use arrays and separate 1-8 out to decrease code size greatly.
  13. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    Started working in this and got a bit confused, a example would be greatly appriciated.
  14. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Thank you so much
  15. Hiddenfootball
    Offline

    Hiddenfootball New Member

    Joined:
    Jul 21, 2014
    Posts:
    15
    Minecraft User:
    Hiddenfootball
    I'll try to get a stable version out, but it may be slower or more laggy untill I figure out the arrays.:p
  16. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    WAT??? Do you know about "foreach" or "while" or "for" ???
    Yes, I like green :D
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I see. ":D"
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Ya, they know but they don't care. They think it is easier for them to put the numbers in the variable names then putting them in arrays.
    Like @Lambo's spleef plugin :D
  19. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    Ok, if they don't use foreach or other function, I'm think use array more comfortable, then just variable.
  20. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    OK I wanna ask you if I could merge your plugin into mine:);):cool::D:rolleyes:plz

Share This Page

Advertisement