1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Help with BlockParticles, need to find an AutoSpawn Plugin

Discussion in 'Plugin Help' started by WinterBuild7074, Apr 27, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Yes. Maybe you want to see the whole code, here. Maybe there's something wrong in the rest of the code, that makes the problem.

    PHP:
    <?php

    namespace AlwaysSpawn;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\Vector3;

    class 
    Main extends PluginBase implements ListenerCommandExecutor{

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        
    $this->saveDefaultConfig();
        
    $this->getResource("config.yml");
            
    $this->getLogger()->info("AlwaysSpawn Loaded!");
        }
        
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            switch(
    $cmd->getName()){
                case 
    "alwaysspawn":
                    if(
    $args[0] == "set"){
                if(!
    $sender Instanceof Player){
                
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                return 
    true;
                }else{
                
    $X $sender->getFloorX();
                
    $Y $sender->getFloorY();
                
    $Z $sender->getFloorZ();
                
    $Level $sender->getLevel()->getName();
                
    $this->getConfig()->set("X"$X);
                
    $this->getConfig()->set("Y"$y);
                
    $this->getConfig()->set("Z"$Z);
                
    $this->getConfig()->set("Level"$Level);
                
    $this->getConfig()->set("enableConf"true);
                
    $this->getConfig()->save();
                
    $sender->sendMessage("[AlwaysSpawn] Set login spawn location to you current position!");
                return 
    true;
                }
                    }elseif(
    $args[0] == "location"){
                if(!
    $sender Instanceof Player){
                
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                return 
    true;
                }else{
                
    $X $sender->getFloorX();
                
    $Y $sender->getFloorY();
                
    $Z $sender->getFloorZ();
                
    $Level $sender->getLevel()->getName();
                
    $sender->sendMessage("[AlwaysSpawn] Your location is:\nX: " $X "\nY: " $Y "\nZ: " $Z "\nLevel: " $Level);
                return 
    true;
                }
                    }else{
                        
    $sender->sendMessage("Usage: /alwaysspawn <set|location>");
                return 
    true;
                    }
                break;
        }
         }
        
        
    /**
         * @param PlayerJoinEvent $event
         *
         * @priority       NORMAL
         * @ignoreCanceled false
         */
        
    public function onRespawn(PlayerRespawnEvent $event){

            
    $enableConf $this->getConfig()->get("enableConf");
            
    $X $this->getConfig()->get("X");
            
    $Y $this->getConfig()->get("Y");
            
    $Z $this->getConfig()->get("Z");
            
    $Level $this->getConfig()->get("Level");
            
    $lvl $this->getServer()->getLevelByName($Level);

            if(
    $enableConf === false){
                
    $event->setRespawnPosition($this->getServer()->getDefaultLevel()->getSpawn());
            } else {
                
    $event->setRespawnPosition(new Position($X$Y+4$Z$lvl));
            }

        }
        
        public function 
    onDisable(){
            
    $this->getConfig()->save();
            
    $this->getLogger()->info("AlwaysSpawn Unloaded!");
        }
    }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    <?php
    namespace AlwaysSpawn;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener
    {

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig(); // creates the config
            
    $this->getLogger()->info("AlwaysSpawn Loaded!");
        }
      
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    $cmd->getName()) {
                case 
    "alwaysspawn":
                    if(
    $args[0] == "set") {
                        if(!
    $sender Instanceof Player) {
                            
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                            return 
    true;
                        } else {

                            
    $X $sender->getFloorX();
                            
    $Y $sender->getFloorY();
                            
    $Z $sender->getFloorZ();
                            
    $Level $sender->getLevel()->getName();

                            
    $this->getConfig()->set("X"$X);
                            
    $this->getConfig()->set("Y"$y);
                            
    $this->getConfig()->set("Z"$Z);
                            
    $this->getConfig()->set("Level"$Level);
                            
    $this->getConfig()->set("enableConf"true);
                            
    $this->getConfig()->save();
                            
    $sender->sendMessage("[AlwaysSpawn] Set login spawn location to you current position!");
                            return 
    true;
                        }
                    }elseif(
    $args[0] == "location") {
                        if(!
    $sender Instanceof Player) {
                            
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                            return 
    true;
                        } else {
                            
    $X $sender->getFloorX();
                            
    $Y $sender->getFloorY();
                            
    $Z $sender->getFloorZ();
                           
    $Level $sender->getLevel()->getName();

                           
    $sender->sendMessage("[AlwaysSpawn] Your location is:\nX: " $X "\nY: " $Y "\nZ: " $Z "\nLevel: " $Level);
                           return 
    true;
                        }
                    } else {
                        
    $sender->sendMessage("Usage: /alwaysspawn <set|location>");
                        return 
    true;
                    }
                break;
            }
        }
      
        
    /**
         * @param PlayerJoinEvent $event
         *
         * @priority       NORMAL
         * @ignoreCanceled false
         */
        
    public function onRespawn(PlayerRespawnEvent $event) {

            
    $enableConf = (bool)$this->getConfig()->get("enableConf",false);
            
    $X = (float)$this->getConfig()->get("X",0);
            
    $Y = (float)$this->getConfig()->get("Y",0);
            
    $Z = (float)$this->getConfig()->get("Z",0);
            
    $Level = (string)$this->getConfig()->get("Level","world");

            
    $lvl $this->getServer()->getLevelByName($Level);
            if(
    $lvl instanceof Level) { // make sure $lvl is actually a Level object
                
    $this->getLogger()->error("Level doesn't exist");
            }

            if(!
    $enableConf) {
                
    $event->setRespawnPosition($this->getServer()->getDefaultLevel()->getSpawn());
            } else {
                
    $event->setRespawnPosition(new Position($X$Y+4$Z$lvl));
            }

        }
      
        public function 
    onDisable() {
            
    $this->getLogger()->info("AlwaysSpawn Disabled!");
        }
    }
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    It always teleport me to the position of my spawn (X: 519.5 and Z: 151), but I always appear at Y: 4 and not at level world Spawn.
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I tried fixing it myself and it now works. But sometimes I get a blank/glitching screen (when this happens my console says that it didn't teleport me to spawn that time), can I fix this? I tried joining the 2nd time and it works perfectly, I appear at spawn.
    Any small things to fix here?
    PHP:
    <?php
    namespace AlwaysSpawn;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements Listener
    {

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig(); // creates the config
            
    $this->getLogger()->info("AlwaysSpawn Loaded!");
        }
     
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    $cmd->getName()) {
                case 
    "alwaysspawn":
                    if(
    $args[0] == "set") {
                        if(!
    $sender Instanceof Player) {
                            
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                            return 
    true;
                        } else {

                            
    $X $sender->getFloorX();
                            
    $Y $sender->getFloorY();
                            
    $Z $sender->getFloorZ();
                            
    $Level $sender->getLevel()->getName();

                            
    $this->getConfig()->set("X"$X);
                            
    $this->getConfig()->set("Y"$y);
                            
    $this->getConfig()->set("Z"$Z);
                            
    $this->getConfig()->set("Level"$Level);
                            
    $this->getConfig()->set("enableConf"true);
                            
    $this->getConfig()->save();
                            
    $sender->sendMessage("[AlwaysSpawn] Set login spawn location to you current position!");
                            return 
    true;
                        }
                    }elseif(
    $args[0] == "location") {
                        if(!
    $sender Instanceof Player) {
                            
    $sender->sendMessage("[AlwaysSpawn] You can only use AlwaysSpawn while in-game!");
                            return 
    true;
                        } else {
                            
    $X $sender->getFloorX();
                            
    $Y $sender->getFloorY();
                            
    $Z $sender->getFloorZ();
                           
    $Level $sender->getLevel()->getName();

                           
    $sender->sendMessage("[AlwaysSpawn] Your location is:\nX: " $X "\nY: " $Y "\nZ: " $Z "\nLevel: " $Level);
                           return 
    true;
                        }
                    } else {
                        
    $sender->sendMessage("Usage: /alwaysspawn <set|location>");
                        return 
    true;
                    }
                break;
            }
        }
     
        
    /**
         * @param PlayerJoinEvent $event
         *
         * @priority       NORMAL
         * @ignoreCanceled false
         */
        
    public function onRespawn(PlayerRespawnEvent $event) {

            
    $enableConf = (bool)$this->getConfig()->get("enableConf",false);
            
    $X = (float)$this->getConfig()->get("X");
            
    $Y = (float)$this->getConfig()->get("1");
            
    $Z = (float)$this->getConfig()->get("Z");
            
    $Level = (string)$this->getConfig()->get("Level");
            
    $lvl $this->getServer()->getLevel($Level);
            
    $tpLevel $this->getServer()->getLevelByName($Level);
            if(
    $lvl instanceof Level) { // make sure $lvl is actually a Level object
                
    $this->getLogger()->error("Level doesn't exist");
            }

            if(!
    $enableConf) {
                
    $event->setRespawnPosition($this->getServer()->getDefaultLevel()->getSpawn());
            } else {
                
    $event->setRespawnPosition(new Position($X$Y$Z$tpLevel));
            }

        }
     
        public function 
    onDisable() {
            
    $this->getLogger()->info("AlwaysSpawn Disabled!");
        }
    }
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Looks that my AlwaysSpawn plugin already works good enough.

    Now I need an answer to my BlockParticles Plugin question. How to change the radius?
     
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Can anyone help me with the BlockParticles plugin? I want to change the radius of the particle-spiral, here is the code:
    PHP:
     public function onRun($tick){
        
    $level $this->plugin->getServer()->getDefaultLevel();
        
    $spawn $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
        
    $r rand(1,300);
        
    $g rand(1,300);
        
    $b rand(1,300);
        
    $x 498.5;
        
    $y 75;
        
    $z 171.5;
        
    $center = new Vector3($x$y$z);
        
    $radius 2;
        
    $count 100;
        
    $particle = new DustParticle($center$r$g$b$radius);
                    for(
    $yaw 0$y $center->y$y $center->7$yaw += (M_PI 2) / 10$y += 10){
                      
    $x = -sin($yaw) + $center->x;
                      
    $z cos($yaw) + $center->z;
                      
    $particle->setComponents($x$y$z);
                      
    $level->addParticle($particle);
          }
      }
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Simply multiply -sin($yaw) and cos($yaw) by the radius.
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    To which variable(s) shall I save this?
    PHP:
    -sin($yaw) * $radius
    cos
    ($yaw) * $radius
     
  9. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
     public function onRun($tick){
        
    $level $this->plugin->getServer()->getDefaultLevel();
        
    $spawn $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
        
    $r rand(1,300);
        
    $g rand(1,300);
        
    $b rand(1,300);
        
    $x 498.5;
        
    $y 75;
        
    $z 171.5;
        
    $center = new Vector3($x$y$z);
        
    $radius 2;
        
    $count 100;
        
    $particle = new DustParticle($center$r$g$b$radius);
                    for(
    $yaw 0$y $center->y$y $center->7$yaw += (M_PI 2) / 10$y += 10){
                      
    $x = -sin($yaw) * $radius $center->x;
                      
    $z cos($yaw) * $radius $center->z;
                      
    $particle->setComponents($x$y$z);
                      
    $level->addParticle($particle);
          }
      }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.