Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 47 additions & 49 deletions src/CameraAPI/CameraHandler.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
<?php

namespace CameraAPI;

use muqsit\simplepackethandler\SimplePacketHandler;
use pocketmine\event\EventPriority;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\CameraPresetsPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\plugin\Plugin;
use pocketmine\utils\SingletonTrait;

class CameraHandler
{
use SingletonTrait;

protected ?Plugin $plugin = null;

public function __construct()
{
self::setInstance($this);
}

public static function register(Plugin $plugin): void
{
if(!is_null(($pl = self::getInstance()->plugin)))
{
throw new \Error("Already registered with {$pl->getName()}");
}

self::getInstance()->plugin = $plugin;
$interceptor = SimplePacketHandler::createInterceptor($plugin, EventPriority::HIGHEST, false);
$interceptor->interceptIncoming(function (SetLocalPlayerAsInitializedPacket $pk, NetworkSession $target): bool
{
$target->sendDataPacket(CameraPresetsPacket::create(CameraPresets::getAll()));
return true;
});
}

public static function isRegistered(): bool
{
return !is_null(self::getInstance()->plugin);
}

public function getPlugin(): Plugin
{
return $this->plugin;
}
}
<?php

namespace CameraAPI;

use muqsit\simplepackethandler\SimplePacketHandler;
use pocketmine\event\EventPriority;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\CameraPresetsPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\plugin\Plugin;
use pocketmine\utils\SingletonTrait;

class CameraHandler
{
use SingletonTrait;

protected ?Plugin $plugin = null;

public function __construct()
{
self::setInstance($this);
}

public static function register(Plugin $plugin): void
{
if (!is_null(($pl = self::getInstance()->plugin))) {
throw new \Error("Already registered with {$pl->getName()}");
}

self::getInstance()->plugin = $plugin;
$interceptor = SimplePacketHandler::createInterceptor($plugin, EventPriority::HIGHEST, false);
$interceptor->interceptIncoming(function (SetLocalPlayerAsInitializedPacket $pk, NetworkSession $target): bool {
$target->sendDataPacket(CameraPresetsPacket::create(CameraPresets::getAll()));
return true;
});
}

public static function isRegistered(): bool
{
return !is_null(self::getInstance()->plugin);
}

public function getPlugin(): Plugin
{
return $this->plugin;
}
}
92 changes: 46 additions & 46 deletions src/CameraAPI/CameraPresets.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
<?php
namespace CameraAPI;
use pocketmine\network\mcpe\protocol\types\camera\CameraPreset;
use pocketmine\utils\RegistryTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static CameraPreset FREE()
* @method static CameraPreset FIRST_PERSON()
* @method static CameraPreset THIRD_PERSON()
* @method static CameraPreset THIRD_PERSON_FRONT()
* @method static CameraPreset FOLLOW_ORBIT()
* @method static CameraPreset FIXED_BOOM()
*/
final class CameraPresets
{
use RegistryTrait;
protected static function setup(): void
{
self::register("free", new CameraPreset("minecraft:free", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_CAMERA, null, null, null));
self::register("first_person", new CameraPreset("minecraft:first_person", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register("third_person", new CameraPreset("minecraft:third_person", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0,CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register("third_person_front", new CameraPreset("minecraft:third_person_front", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register("follow_orbit", new CameraPreset("minecraft:follow_orbit", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register("fixed_boom", new CameraPreset("minecraft:fixed_boom", "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
}
protected static function register(string $name, CameraPreset $member): void
{
self::_registryRegister($name, $member);
}
public static function getAll(): array
{
return [self::FREE(), self::FIRST_PERSON(), self::THIRD_PERSON(), self::THIRD_PERSON_FRONT(), self::FOLLOW_ORBIT(), self::FIXED_BOOM(),];
}
}
<?php

namespace CameraAPI;

use pocketmine\network\mcpe\protocol\types\camera\CameraPreset;
use pocketmine\utils\RegistryTrait;

/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static CameraPreset FREE()
* @method static CameraPreset FIRST_PERSON()
* @method static CameraPreset THIRD_PERSON()
* @method static CameraPreset THIRD_PERSON_FRONT()
* @method static CameraPreset FOLLOW_ORBIT()
* @method static CameraPreset FIXED_BOOM()
*/

final class CameraPresets
{
use RegistryTrait;

protected static function setup(): void
{
self::register('free', new CameraPreset('minecraft:free', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_CAMERA, null, null, null));
self::register('first_person', new CameraPreset('minecraft:first_person', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register('third_person', new CameraPreset('minecraft:third_person', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register('third_person_front', new CameraPreset('minecraft:third_person_front', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register('follow_orbit', new CameraPreset('minecraft:follow_orbit', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));
self::register('fixed_boom', new CameraPreset('minecraft:fixed_boom', '', null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0, CameraPreset::AUDIO_LISTENER_TYPE_PLAYER, null, null, null));

}

protected static function register(string $name, CameraPreset $member): void
{
self::_registryRegister($name, $member);
}

public static function getAll(): array
{
return [self::FREE(), self::FIRST_PERSON(), self::THIRD_PERSON(), self::THIRD_PERSON_FRONT(), self::FOLLOW_ORBIT(), self::FIXED_BOOM(),];
}
}
20 changes: 10 additions & 10 deletions src/CameraAPI/Instructions/CameraInstruction.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace CameraAPI\Instructions;
use pocketmine\player\Player;
abstract class CameraInstruction
{
abstract public function send(Player $player): void;
}
<?php

namespace CameraAPI\Instructions;

use pocketmine\player\Player;

abstract class CameraInstruction
{
abstract public function send(Player $player): void;
}
54 changes: 27 additions & 27 deletions src/CameraAPI/Instructions/ClearCameraInstruction.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php
namespace CameraAPI\Instructions;
use pocketmine\network\mcpe\protocol\CameraInstructionPacket;
use pocketmine\player\Player;
final class ClearCameraInstruction extends CameraInstruction
{
private ?bool $clear = true;
private ?bool $removeTarget = true;
public function setClear(bool $clear): void
{
$this->clear = $clear;
}
public function setRemoveTarget(bool $removeTarget): void
{
$this->removeTarget = $removeTarget;
}
public function send(Player $player): void
{
$player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, $this->clear, null, null, $this->removeTarget, null));
}
}
<?php

namespace CameraAPI\Instructions;

use pocketmine\network\mcpe\protocol\CameraInstructionPacket;
use pocketmine\player\Player;

final class ClearCameraInstruction extends CameraInstruction
{
private ?bool $clear = true;
private ?bool $removeTarget = true;

public function setClear(bool $clear): void
{
$this->clear = $clear;
}

public function setRemoveTarget(bool $removeTarget): void
{
$this->removeTarget = $removeTarget;
}

public function send(Player $player): void
{
$player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, $this->clear, null, null, $this->removeTarget, null, null, null, null));
}
}
60 changes: 30 additions & 30 deletions src/CameraAPI/Instructions/FadeCameraInstruction.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?php
namespace CameraAPI\Instructions;
use pocketmine\network\mcpe\protocol\CameraInstructionPacket;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstruction;
use pocketmine\player\Player;
final class FadeCameraInstruction extends CameraInstruction
{
private ?CameraFadeInstructionTime $time = null;
private ?CameraFadeInstructionColor $color = null;
public function setTime(float $fadeInTime, float $stayInTime, float $fadeOutTime): void
{
$this->time = new CameraFadeInstructionTime($fadeInTime, $stayInTime, $fadeOutTime);
}
public function setColor(float $red, float $green, float $blue): void
{
$this->color = new CameraFadeInstructionColor($red, $green, $blue);
}
public function send(Player $player): void
{
$player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, null, new CameraFadeInstruction($this->time, $this->color), null, null, null));
}
}
<?php

namespace CameraAPI\Instructions;

use pocketmine\network\mcpe\protocol\CameraInstructionPacket;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionColor;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstructionTime;
use pocketmine\player\Player;

final class FadeCameraInstruction extends CameraInstruction
{
private ?CameraFadeInstructionTime $time = null;
private ?CameraFadeInstructionColor $color = null;

public function setTime(float $fadeInTime, float $stayInTime, float $fadeOutTime): void
{
$this->time = new CameraFadeInstructionTime($fadeInTime, $stayInTime, $fadeOutTime);
}

public function setColor(float $red, float $green, float $blue): void
{
$this->color = new CameraFadeInstructionColor($red, $green, $blue);
}

public function send(Player $player): void
{
$player->getNetworkSession()->sendDataPacket(CameraInstructionPacket::create(null, null, new CameraFadeInstruction($this->time, $this->color), null, null, null, null, null, null));
}
}
Loading