Argument 2 passed to Fishing\API::sendBossBarToPlayer() must be of the type int, string given, called in /storage/emulated/0/PocketMine-MP/plugins/moch/src/Fishing/entity/projectile/FishingHook.php on line 97 File: plugins/mochsrc/Fishing/API Line: 47 Type: TypeError Code: PHP: namespace Fishing;use pocketmine\entity\Entity;use pocketmine\network\mcpe\protocol\AddActorPacket;use pocketmine\network\mcpe\protocol\BossEventPacket;use pocketmine\network\mcpe\protocol\RemoveActorPacket;use pocketmine\network\mcpe\protocol\SetActorDataPacket;use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\event\Listener;use pocketmine\Server;use Fishing\Fishing;use Fishing\entity\projectile\FishingHook;class API implements Listener{ const ENTITY = 37; public static function addBossBar($players, string $title, $ticks = null){ if (empty($players)) return null; $eid = Entity::$entityCount++; $packet = new AddActorPacket(); $packet->entityRuntimeId = $eid; $packet->type = self::ENTITY; $packet->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 0 ^ 1 << Entity::DATA_FLAG_SILENT ^ 1 << Entity::DATA_FLAG_INVISIBLE ^ 1 << Entity::DATA_FLAG_NO_AI], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0]]; foreach ($players as $player){ $pk = clone $packet; $pk->position = $player->getPosition()->asVector3()->subtract(0, 28); $player->dataPacket($pk); } $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; Server::getInstance()->broadcastPacket($players, $bpk); return $eid; } public static function sendBossBarToPlayer(Player $player, int $eid, string $title, $ticks = null){ self::removeBossBar([$player], $eid); $packet = new AddActorPacket(); $packet->entityRuntimeId = $eid; $packet->type = self::ENTITY; $packet->position = $player->getPosition()->asVector3()->subtract(0, 28); $packet->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 0 ^ 1 << Entity::DATA_FLAG_SILENT ^ 1 << Entity::DATA_FLAG_INVISIBLE ^ 1 << Entity::DATA_FLAG_NO_AI], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0]]; $player->dataPacket($packet); $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; $player->dataPacket($bpk); } public static function removeBossBar($players, int $eid){ if (empty($players)) return false; $pk = new RemoveActorPacket(); $pk->entityUniqueId = $eid; Server::getInstance()->broadcastPacket($players, $pk); return true; } public static function setPercentage(int $percentage, int $eid, $players = []){ if (empty($players)) $players = Server::getInstance()->getOnlinePlayers(); if (!count($players) > 0) return; $upk = new UpdateAttributesPacket(); $upk->entries[] = new BossBarValues(1, 600, max(1, min([$percentage, 100])) / 100 * 600, 'minecraft:health'); $upk->entityRuntimeId = $eid; Server::getInstance()->broadcastPacket($players, $upk); $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = ""; $bpk->healthPercent = $percentage / 100; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; Server::getInstance()->broadcastPacket($players, $bpk); } public static function setTitle(string $title, int $eid, $players = []){ if (!count(Server::getInstance()->getOnlinePlayers()) > 0) return; $npk = new SetActorDataPacket(); $npk->metadata = [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title]]; $npk->entityRuntimeId = $eid; Server::getInstance()->broadcastPacket($players, $npk); $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; Server::getInstance()->broadcastPacket($players, $bpk); }} PHP: API::sendBossBarToPlayer($oe, "Fish");
Let me fix it for you Argument 2 passed to Fishing\API::sendBossBarToPlayer() must be of the type int, string given
Code API: PHP: use pocketmine\entity\Entity;use pocketmine\network\mcpe\protocol\AddEntityPacket;use pocketmine\network\mcpe\protocol\BossEventPacket;use pocketmine\network\mcpe\protocol\RemoveEntityPacket;use pocketmine\network\mcpe\protocol\SetEntityDataPacket;use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;use pocketmine\Player;use pocketmine\Server;class API{ const ENTITY = 37;//52 - 37 is slime, inspired by MiNET /** * Sends the text to all players * * @param Player[] $players * To who to send * @param string $title * The title of the boss bar * @param null|int $ticks * How long it displays * @return int EntityID NEEDED FOR CHANGING TEXT/PERCENTAGE! | null (No Players) */ public static function addBossBar($players, string $title, $ticks = null) { if (empty($players)) return null; $eid = Entity::$entityCount++; $packet = new AddEntityPacket(); $packet->entityRuntimeId = $eid; $packet->type = self::ENTITY; $packet->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 0 ^ 1 << Entity::DATA_FLAG_SILENT ^ 1 << Entity::DATA_FLAG_INVISIBLE ^ 1 << Entity::DATA_FLAG_NO_AI], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0]]; foreach ($players as $player) { $pk = clone $packet; $pk->position = $player->getPosition()->asVector3()->subtract(0, 28); $player->dataPacket($pk); } $bpk = new BossEventPacket(); // This updates the bar $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->color = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->overlay = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->playerEid = 0;//TODO TEST!!! Server::getInstance()->broadcastPacket($players, $bpk); return $eid; // TODO: return EID from bosseventpacket? } /** * Sends the text to one player * * @param Player $player * @param int $eid * The EID of an existing fake wither * @param string $title * The title of the boss bar * @param null|int $ticks * How long it displays * @internal param Player $players To who to send* To who to send */ public static function sendBossBarToPlayer(Player $player, int $eid, string $title, $ticks = null) { self::removeBossBar([$player], $eid);//remove same bars $packet = new AddEntityPacket(); $packet->entityRuntimeId = $eid; $packet->type = self::ENTITY; $packet->position = $player->getPosition()->asVector3()->subtract(0, 28); $packet->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 0 ^ 1 << Entity::DATA_FLAG_SILENT ^ 1 << Entity::DATA_FLAG_INVISIBLE ^ 1 << Entity::DATA_FLAG_NO_AI], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0]]; $player->dataPacket($packet); $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; $player->dataPacket($bpk); } /** * Sets how many % the bar is full by EID * * @param int $percentage * 0-100 * @param int $eid * @param array $players * If empty this will default to Server::getInstance()->getOnlinePlayers() */ public static function setPercentage(int $percentage, int $eid, $players = []) { if (empty($players)) $players = Server::getInstance()->getOnlinePlayers(); if (!count($players) > 0) return; $upk = new UpdateAttributesPacket(); // Change health of fake wither -> bar progress $upk->entries[] = new BossBarValues(1, 600, max(1, min([$percentage, 100])) / 100 * 600, 'minecraft:health'); // Ensures that the number is between 1 and 100; //Blame mojang, Ender Dragon seems to die on health 1 $upk->entityRuntimeId = $eid; Server::getInstance()->broadcastPacket($players, $upk); $bpk = new BossEventPacket(); // This updates the bar $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = ""; //We can't get this -.- $bpk->healthPercent = $percentage / 100; $bpk->unknownShort = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->color = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->overlay = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->playerEid = 0;//TODO TEST!!! Server::getInstance()->broadcastPacket($players, $bpk); } /** * Sets the BossBar title by EID * * @param string $title * @param int $eid * @param Player[] $players */ public static function setTitle(string $title, int $eid, $players = []) { if (!count(Server::getInstance()->getOnlinePlayers()) > 0) return; $npk = new SetEntityDataPacket(); // change name of fake wither -> bar text $npk->metadata = [Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title]]; $npk->entityRuntimeId = $eid; Server::getInstance()->broadcastPacket($players, $npk); $bpk = new BossEventPacket(); // This updates the bar $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->color = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->overlay = 0;//TODO: remove. Shoghi deleted that unneeded mess that was copy-pasted from MC-JAVA $bpk->playerEid = 0;//TODO TEST!!! Server::getInstance()->broadcastPacket($players, $bpk); } /** * Remove BossBar from players by EID * * @param Player[] $players * @param int $eid * @return boolean removed */ public static function removeBossBar($players, int $eid) { if (empty($players)) return false; $pk = new RemoveEntityPacket(); $pk->entityUniqueId = $eid; Server::getInstance()->broadcastPacket($players, $pk); return true; }} Code BossbarValues: PHP: use pocketmine\entity\Attribute;class BossBarValues extends Attribute{ public $min, $max, $value, $name; public function __construct($min, $max, $value, $name) { $this->min = $min; $this->max = $max; $this->value = $value; $this->name = $name; } public function getMinValue(): float { return $this->min; } public function getMaxValue(): float { return $this->max; } public function getValue(): float { return $this->value; } public function getName(): string { return $this->name; } public function getDefaultValue(): float { return $this->min; }}
FishingHook.php PHP: declare(strict_types = 1);namespace Fishing\entity\projectile;use pocketmine\block\StillWater;use pocketmine\block\Water;use pocketmine\block\Liquid;use pocketmine\entity\Entity;use pocketmine\entity\projectile\Projectile;use pocketmine\event\entity\EntityDamageByChildEntityEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\ProjectileHitEntityEvent;use pocketmine\math\RayTraceResult;use pocketmine\math\AxisAlignedBB;use pocketmine\math\Vector3;use pocketmine\utils\Random;use pocketmine\network\mcpe\protocol\ActorEventPacket;use pocketmine\Player;use pocketmine\level\particle\GenericParticle;use pocketmine\level\particle\Particle;use pocketmine\Server as PMServer;use Fishing\API;class FishingHook extends Projectile { public const NETWORK_ID = self::FISHING_HOOK; public $width = 0.25; public $length = 0.25; public $height = 0.25; public $coughtTimer = 0; public $bubbleTimer = 0; public $bubbleTicks = 0; public $bitesTicks = 0; public $attractTimer = 0; protected $gravity = 0.1; protected $drag = 0.05; protected $touchedWater = false; public function onUpdate(int $currentTick): bool{ if($this->isFlaggedForDespawn() || !$this->isAlive()){ return false; } $this->timings->startTiming(); $hasUpdate = parent::onUpdate($currentTick); if($this->isInsideOfSolid()){ $random = new Random((int) (microtime(true) * 1000) + mt_rand()); $this->motion->x *= $random->nextFloat() * 0.2; $this->motion->y *= $random->nextFloat() * 0.2; $this->motion->z *= $random->nextFloat() * 0.2; } if (!$this->isInsideOfSolid()) { $f6 = 0.92; if($this->onGround or $this->isCollidedHorizontally){ $f6 = 0.5; } $d10 = 0; $bb = $this->getBoundingBox(); for($j = 0; $j < 5; ++$j){ $d1 = $bb->minY + ($bb->maxY - $bb->minY) * $j / 5; $d3 = $bb->minY + ($bb->maxY - $bb->minY) * ($j + 1) / 5; $bb2 = new AxisAlignedBB($bb->minX, $d1, $bb->minZ, $bb->maxX, $d3, $bb->maxZ); if($this->isLiquidInBoundingBox($bb2)){ $d10 += 0.2; } } if ($d10 > 0) { //Wait Wait, we are waiting the fish if($this->attractTimer === 0){ //Set bubble timer, fish is near ! if ($this->bubbleTimer === 0 && $this->coughtTimer === 0) { $this->bubbleTimer = mt_rand(5, 10) * 20; $oe = $this->getOwningEntity(); if($oe instanceof Player){ $oe->sendTip("§a[§6Kail Bergerak!§a]"); API::sendBossBarToPlayer($oe, "Fishing "); } } else if ($this->bubbleTimer > 0) { $this->bubbleTimer--; } //If bubble timer finished, catch it ! if ($this->bubbleTimer <= 0 && $this->coughtTimer === 0) { $this->coughtTimer = mt_rand(3, 5) * 20; $oe = $this->getOwningEntity(); if($oe instanceof Player){ $oe->sendTip("§a[§6Kail Tergigit!§a]\n§a[§6Segera tarik Pancingan§a]"); } $this->fishBites(); $this->bitesTicks = mt_rand(1, 3) * 20; } //Else do animation every X ticks else { if ($this->bubbleTicks === 0) { $this->attractFish(); $this->bubbleTicks = 10; } else { $this->bubbleTicks--; } } } elseif($this->attractTimer > 0){ $this->attractTimer--; } if($this->coughtTimer > 0){ $this->coughtTimer--; if ($this->bitesTicks === 0) { $this->fishBites(); $this->bitesTicks = mt_rand(1, 3) * 20; } else { $this->bitesTicks--; } //Reset the timer if ($this->attractTimer === 0) $this->attractTimer = mt_rand(30, 100) * 20; } } $d11 = $d10 * 2.0 - 1.0; $this->motion->y += 0.04 * $d11; if($d10 > 0.0){ $f6 = $f6 * 0.9; $this->motion->y *= 0.8; } $this->motion->x *= $f6; $this->motion->y *= $f6; $this->motion->z *= $f6; } // var_dump("attractTimer: ".$this->attractTimer." coughtTimer: ".$this->coughtTimer." bubbleTimer: ".$this->bubbleTimer); $this->timings->stopTiming(); return $hasUpdate; } public function attractFish(){ $oe = $this->getOwningEntity(); if($oe instanceof Player){ $pk = new ActorEventPacket(); $pk->entityRuntimeId = $this->getId(); $pk->event = ActorEventPacket::FISH_HOOK_BUBBLE; PMServer::getInstance()->broadcastPacket($this->getViewers(), $pk); } $this->level->addParticle(new GenericParticle(new Vector3($this->x, $this->y - 0.1, $this->z), Particle::TYPE_BUBBLE)); } public function fishBites(){ $oe = $this->getOwningEntity(); if($oe instanceof Player){ $pk = new ActorEventPacket(); $pk->entityRuntimeId = $this->getId(); $pk->event = ActorEventPacket::FISH_HOOK_HOOK; PMServer::getInstance()->broadcastPacket($this->getViewers(), $pk); } } public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void{ $this->server->getPluginManager()->callEvent(new ProjectileHitEntityEvent($this, $hitResult, $entityHit)); $damage = $this->getResultDamage(); if($this->getOwningEntity() === null){ $ev = new EntityDamageByEntityEvent($this, $entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); }else{ $ev = new EntityDamageByChildEntityEvent($this->getOwningEntity(), $this, $entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); } $entityHit->attack($ev); $entityHit->setMotion($this->getOwningEntity()->getDirectionVector()->multiply(-0.3)->add(0, 0.3, 0)); $this->isCollided = true; $this->flagForDespawn(); } public function getResultDamage(): int{ return 1; } /** * @param AxisAlignedBB $bb * @param Liquid $material * * @return bool */ public function isLiquidInBoundingBox(AxisAlignedBB $bb) : bool{ $minX = (int) floor($bb->minX); $minY = (int) floor($bb->minY); $minZ = (int) floor($bb->minZ); $maxX = (int) floor($bb->maxX + 1); $maxY = (int) floor($bb->maxY + 1); $maxZ = (int) floor($bb->maxZ + 1); for($x = $minX; $x < $maxX; ++$x){ for($y = $minY; $y < $maxY; ++$y){ for($z = $minZ; $z < $maxZ; ++$z){ $block = $this->level->getBlockAt($x, $y, $z); if($block instanceof Liquid){ $j2 = $block->getDamage(); $d0 = $y + 1; if($j2 < 8){ $d0 -= $j2 / 8; } if($d0 >= $bb->minY){ return true; } } } } } return false; } protected function tryChangeMovement() : void{ }}
Are you a programmer? The error is telling you you're giving a string instead of an integer. It's not that hard to read.
PHP: public static function sendBossBarToPlayer(Player $player, int $eid, string $title, $ticks = null) { self::removeBossBar([$player], $eid);//remove same bars $packet = new AddEntityPacket(); $packet->entityRuntimeId = $eid; $packet->type = self::ENTITY; $packet->position = $player->getPosition()->asVector3()->subtract(0, 28); $packet->metadata = [Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 0 ^ 1 << Entity::DATA_FLAG_SILENT ^ 1 << Entity::DATA_FLAG_INVISIBLE ^ 1 << Entity::DATA_FLAG_NO_AI], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $title], Entity::DATA_BOUNDING_BOX_WIDTH => [Entity::DATA_TYPE_FLOAT, 0], Entity::DATA_BOUNDING_BOX_HEIGHT => [Entity::DATA_TYPE_FLOAT, 0]]; $player->dataPacket($packet); $bpk = new BossEventPacket(); $bpk->bossEid = $eid; $bpk->eventType = BossEventPacket::TYPE_SHOW; $bpk->title = $title; $bpk->healthPercent = 1; $bpk->unknownShort = 0; $bpk->color = 0; $bpk->overlay = 0; $bpk->playerEid = 0; $player->dataPacket($bpk); } PHP: API::sendBossBarToPlayer($oe, "Fishing "); Like this??