Skip to content

ohitszenqi/VoidJump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Information

  • Author: Zenqi
  • API: 5.0.0
  • Version: 1.0.0
  • Time spent: 2 hours

How does it work?

  • on PlayerLogin the player would be added in jump array
public function onLogin(PlayerLoginEvent $event) {
        $player = $event->getPlayer();
        $this->jump[$player->getName()] = 0;
    }
  • on PlayerQuit the player would be removed from the jump array
  public function onQuit(PlayerQuitEvent $event) {
        $player = $event->getPlayer();
        if (isset($this->jump[$player->getName()])) {
            unset($this->jump[$player->getName()]);
        }
    }
  • on PlayerJump the jump array will temporary enable the player permission to fly, and keep track of number of jumps that has maximum of 2 so if player stops jumping it would go back to 0, by temporary enabling the permission to fly, the player now can trigger the PlayerToggleFlightEvent which can make the player jump mid-air without actually toggling the fly function
public function onJump(PlayerJumpEvent $event) {
        $player = $event->getPlayer();
        $this->jump[$player->getName()]++;  
        if ($this->jump[$player->getName()] == 1)  {
            $player->setAllowFlight(true);
        }
        if ($this->jump[$player->getName()] == 1) $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function () use ($player) : void {
            $this->jump[$player->getName()] = 0;
        }), 30);
    }
  • on PlayerToggleFlightEvent the direction where the player is will be the direction where the player will jump mid-air, this is a necessary function due to other plugins jumping to random sides, using cosine and sine to get the direction of player.
 public function onToggle(PlayerToggleFlightEvent $event) {
        $player = $event->getPlayer();
        # Configurable, recommended: 0.4 - 0.6
        $jumpHeight = 0.4;
        $jumpDistance = 0.4; 
        $motionX = -sin(deg2rad($player->getLocation()->getYaw())) * $jumpDistance;
        $motionY = $jumpHeight;
        $motionZ = cos(deg2rad($player->getLocation()->getYaw())) * $jumpDistance;
        $player->setMotion(new Vector3($motionX, $motionY, $motionZ));
        $this->jump[$player->getName()] = 0;
        $event->cancel();
        $player->setAllowFlight(false);
    }

About

Double Jump feature for Pocketmine-MP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages