Skip to content

Commit 798bc72

Browse files
committed
[sync] Update embedded LibHud from standalone
1 parent d98b545 commit 798bc72

8 files changed

Lines changed: 49 additions & 36 deletions

File tree

src/imperazim/hud/bossbar/AnimatedBossBar.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use pocketmine\plugin\Plugin;
88
use pocketmine\scheduler\ClosureTask;
99
use pocketmine\scheduler\TaskHandler;
10+
use Closure;
1011

1112
/**
1213
* BossBar with automatic animated progress.
@@ -45,7 +46,7 @@ public function startAnimation(
4546
int $duration = 100,
4647
float $from = 0.0,
4748
float $to = 1.0,
48-
?\Closure $onComplete = null
49+
?Closure $onComplete = null
4950
): void {
5051
$this->stopAnimation();
5152

src/imperazim/hud/bossbar/BossBar.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
2222
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
2323
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
24+
use Throwable;
2425

2526
/**
2627
* Class BossBar
@@ -95,7 +96,7 @@ public function addPlayer(Player $player): static {
9596
$this->sendBossPacket([$player]);
9697
$this->players[$player->getId()] = $player;
9798
}
98-
} catch (\Throwable $e) {
99+
} catch (Throwable $e) {
99100
GlobalLogger::get()->logException($e);
100101
}
101102
return $this;
@@ -111,7 +112,7 @@ public function addPlayers(array $players): static {
111112
foreach ($players as $player) {
112113
$this->addPlayer($player);
113114
}
114-
} catch (\Throwable $e) {
115+
} catch (Throwable $e) {
115116
GlobalLogger::get()->logException($e);
116117
}
117118
return $this;
@@ -131,7 +132,7 @@ public function removePlayer(Player $player): static {
131132
} else {
132133
GlobalLogger::get()->debug("Removed player that was not added to the boss bar (" . $this . ")");
133134
}
134-
} catch (\Throwable $e) {
135+
} catch (Throwable $e) {
135136
GlobalLogger::get()->logException($e);
136137
}
137138
return $this;
@@ -147,7 +148,7 @@ public function removePlayers(array $players): static {
147148
foreach ($players as $player) {
148149
$this->removePlayer($player);
149150
}
150-
} catch (\Throwable $e) {
151+
} catch (Throwable $e) {
151152
GlobalLogger::get()->logException($e);
152153
}
153154
return $this;
@@ -162,7 +163,7 @@ public function removeAllPlayers(): static {
162163
foreach ($this->getPlayers() as $player) {
163164
$this->removePlayer($player);
164165
}
165-
} catch (\Throwable $e) {
166+
} catch (Throwable $e) {
166167
GlobalLogger::get()->logException($e);
167168
}
168169
return $this;
@@ -185,7 +186,7 @@ public function setTitle(string $title = ""): static {
185186
try {
186187
$this->title = $title;
187188
$this->sendBossTextPacket($this->getPlayers());
188-
} catch (\Throwable $e) {
189+
} catch (Throwable $e) {
189190
GlobalLogger::get()->logException($e);
190191
}
191192
return $this;
@@ -208,7 +209,7 @@ public function setSubTitle(string $subTitle = ""): static {
208209
try {
209210
$this->subTitle = $subTitle;
210211
$this->sendBossTextPacket($this->getPlayers());
211-
} catch (\Throwable $e) {
212+
} catch (Throwable $e) {
212213
GlobalLogger::get()->logException($e);
213214
}
214215
return $this;
@@ -236,7 +237,7 @@ public function setPercentage(float $percentage): static {
236237
$percentage = min(1.0, max(0.0, $percentage));
237238
$this->getAttributeMap()->get(Attribute::HEALTH)->setValue($percentage * $this->getAttributeMap()->get(Attribute::HEALTH)->getMaxValue(), true, true);
238239
$this->sendBossHealthPacket($this->getPlayers());
239-
} catch (\Throwable $e) {
240+
} catch (Throwable $e) {
240241
GlobalLogger::get()->logException($e);
241242
}
242243
return $this;
@@ -267,7 +268,7 @@ public function setColor(int $color): static {
267268
try {
268269
$this->color = $color;
269270
$this->sendBossPacket($this->getPlayers());
270-
} catch (\Throwable $e) {
271+
} catch (Throwable $e) {
271272
GlobalLogger::get()->logException($e);
272273
}
273274
return $this;
@@ -284,7 +285,7 @@ public function hideFrom(array $players): void {
284285
$player->getNetworkSession()->sendDataPacket(BossEventPacket::hide($this->actorId ?? $player->getId()));
285286
}
286287
}
287-
} catch (\Throwable $e) {
288+
} catch (Throwable $e) {
288289
GlobalLogger::get()->logException($e);
289290
}
290291
}
@@ -351,7 +352,7 @@ public function setEntity(?Entity $entity = null): static {
351352
}
352353

353354
$this->sendBossPacket($this->getPlayers());
354-
} catch (\Throwable $e) {
355+
} catch (Throwable $e) {
355356
GlobalLogger::get()->logException($e);
356357
}
357358
return $this;
@@ -368,7 +369,7 @@ public function resetEntity(bool $removeEntity = false): static {
368369
$this->getEntity()->close();
369370
}
370371
$this->setEntity();
371-
} catch (\Throwable $e) {
372+
} catch (Throwable $e) {
372373
GlobalLogger::get()->logException($e);
373374
}
374375
return $this;
@@ -424,7 +425,7 @@ protected function sendBossPacket(array $players): void {
424425
));
425426
}
426427
}
427-
} catch (\Throwable $e) {
428+
} catch (Throwable $e) {
428429
GlobalLogger::get()->logException($e);
429430
}
430431
}
@@ -440,7 +441,7 @@ protected function sendRemoveBossPacket(array $players): void {
440441
$player->getNetworkSession()->sendDataPacket(BossEventPacket::hide($this->actorId ?? $player->getId()));
441442
}
442443
}
443-
} catch (\Throwable $e) {
444+
} catch (Throwable $e) {
444445
GlobalLogger::get()->logException($e);
445446
}
446447
}
@@ -459,7 +460,7 @@ protected function sendBossTextPacket(array $players): void {
459460
));
460461
}
461462
}
462-
} catch (\Throwable $e) {
463+
} catch (Throwable $e) {
463464
GlobalLogger::get()->logException($e);
464465
}
465466
}
@@ -478,7 +479,7 @@ protected function sendBossHealthPacket(array $players): void {
478479
));
479480
}
480481
}
481-
} catch (\Throwable $e) {
482+
} catch (Throwable $e) {
482483
GlobalLogger::get()->logException($e);
483484
}
484485
}

src/imperazim/hud/composer/HudComposer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace imperazim\hud\composer;
66

77
use pocketmine\player\Player;
8+
use Closure;
89

910
/**
1011
* Composes multiple HUD elements per player in indexed layers.
@@ -21,23 +22,23 @@
2122
*/
2223
final class HudComposer {
2324

24-
/** @var array<int, array<string, array{priority: int, apply: \Closure, remove: \Closure|null}>> */
25+
/** @var array<int, array<string, array{priority: int, apply: Closure, remove: Closure|null}>> */
2526
private array $layers = [];
2627

2728
/**
2829
* Sets a HUD layer for a player.
2930
*
3031
* @param Player $player Target player
3132
* @param string $key Unique layer identifier
32-
* @param \Closure $apply Apply callback: fn(): void
33-
* @param \Closure|null $remove Remove callback: fn(): void
33+
* @param Closure $apply Apply callback: fn(): void
34+
* @param Closure|null $remove Remove callback: fn(): void
3435
* @param int $priority Layer priority (lower = first)
3536
*/
3637
public function setLayer(
3738
Player $player,
3839
string $key,
39-
\Closure $apply,
40-
?\Closure $remove = null,
40+
Closure $apply,
41+
?Closure $remove = null,
4142
int $priority = 0
4243
): void {
4344
$id = $player->getId();

src/imperazim/hud/cooldown/CooldownHUD.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use pocketmine\scheduler\TaskHandler;
1111
use pocketmine\network\mcpe\protocol\types\BossBarColor;
1212
use imperazim\hud\bossbar\BossBar;
13+
use pocketmine\scheduler\TaskScheduler;
14+
use pocketmine\Server;
15+
use RuntimeException;
1316

1417
/**
1518
* Visual cooldown HUD using a temporary BossBar with decreasing progress.
@@ -139,17 +142,17 @@ public static function cleanup(Player $player): void {
139142
}
140143
}
141144

142-
private static function getScheduler(): \pocketmine\scheduler\TaskScheduler {
145+
private static function getScheduler(): TaskScheduler {
143146
if (self::$plugin !== null) {
144147
return self::$plugin->getScheduler();
145148
}
146149
// Fallback: try to find an enabled plugin
147-
$plugins = \pocketmine\Server::getInstance()->getPluginManager()->getPlugins();
150+
$plugins = Server::getInstance()->getPluginManager()->getPlugins();
148151
foreach ($plugins as $plugin) {
149152
if ($plugin->isEnabled()) {
150153
return $plugin->getScheduler();
151154
}
152155
}
153-
throw new \RuntimeException("CooldownHUD: No plugin available. Call CooldownHUD::init(\$plugin) first.");
156+
throw new RuntimeException("CooldownHUD: No plugin available. Call CooldownHUD::init(\$plugin) first.");
154157
}
155158
}

src/imperazim/hud/exception/HudException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace imperazim\hud\exception;
66

7+
use RuntimeException;
8+
79
/**
810
* Class HudException
911
* @package imperazim\hud\exception
1012
*/
11-
final class HudException extends \RuntimeException {}
13+
final class HudException extends RuntimeException {}

src/imperazim/hud/notification/NotificationQueue.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use imperazim\hud\message\ToastManager;
1111
use imperazim\hud\message\TitleManager;
1212
use imperazim\hud\message\ActionBarManager;
13+
use pocketmine\scheduler\TaskScheduler;
14+
use pocketmine\Server;
15+
use RuntimeException;
1316

1417
/**
1518
* Queues notifications (toast, title, actionbar) one at a time without overlap.
@@ -151,16 +154,16 @@ private static function processNext(Player $player): void {
151154
);
152155
}
153156

154-
private static function getScheduler(): \pocketmine\scheduler\TaskScheduler {
157+
private static function getScheduler(): TaskScheduler {
155158
if (self::$plugin !== null) {
156159
return self::$plugin->getScheduler();
157160
}
158-
$plugins = \pocketmine\Server::getInstance()->getPluginManager()->getPlugins();
161+
$plugins = Server::getInstance()->getPluginManager()->getPlugins();
159162
foreach ($plugins as $plugin) {
160163
if ($plugin->isEnabled()) {
161164
return $plugin->getScheduler();
162165
}
163166
}
164-
throw new \RuntimeException("NotificationQueue: No plugin available. Call NotificationQueue::init(\$plugin) first.");
167+
throw new RuntimeException("NotificationQueue: No plugin available. Call NotificationQueue::init(\$plugin) first.");
165168
}
166169
}

src/imperazim/hud/scoreboard/ScoreBoardManager.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use pocketmine\player\Player;
1010
use pocketmine\network\mcpe\protocol\SetScorePacket;
1111
use pocketmine\network\mcpe\protocol\RemoveObjectivePacket;
12+
use Throwable;
1213

1314
/**
1415
* Class ScoreBoardManager
@@ -34,7 +35,7 @@ public static function sendToPlayer(Player $player, ScoreBoard $scoreboard): voi
3435

3536
$lines = $scoreboard->getLines();
3637
$player->getNetworkSession()->sendDataPacket($lines);
37-
} catch (\Throwable $e) {
38+
} catch (Throwable $e) {
3839
GlobalLogger::get()->logException($e);
3940
}
4041
}
@@ -53,7 +54,7 @@ public static function removeFromPlayer(Player $player): void {
5354
$player->getNetworkSession()->sendDataPacket($pk);
5455
unset(self::$scoreboards[$player->getName()]);
5556
}
56-
} catch (\Throwable $e) {
57+
} catch (Throwable $e) {
5758
GlobalLogger::get()->logException($e);
5859
}
5960
}
@@ -75,7 +76,7 @@ public static function clearLine(Player $player, int $score): void {
7576
$pk->entries = [$entry->toEntry()];
7677
$player->getNetworkSession()->sendDataPacket($pk);
7778
}
78-
} catch (\Throwable $e) {
79+
} catch (Throwable $e) {
7980
GlobalLogger::get()->logException($e);
8081
}
8182
}
@@ -99,7 +100,7 @@ public static function clearAllLines(Player $player): void {
99100
$pk->entries = $entries;
100101
$player->getNetworkSession()->sendDataPacket($pk);
101102
}
102-
} catch (\Throwable $e) {
103+
} catch (Throwable $e) {
103104
GlobalLogger::get()->logException($e);
104105
}
105106
}
@@ -114,7 +115,7 @@ public static function updateToPlayer(Player $player): void {
114115
$scoreboard = self::$scoreboards[$player->getName()];
115116
self::sendToPlayer($player, $scoreboard);
116117
}
117-
} catch (\Throwable $e) {
118+
} catch (Throwable $e) {
118119
GlobalLogger::get()->logException($e);
119120
}
120121
}

src/imperazim/hud/scoreboard/ScoreLine.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace imperazim\hud\scoreboard;
66

77
use pocketmine\network\mcpe\protocol\types\ScorePacketEntry;
8+
use InvalidArgumentException;
89

910
/**
1011
* Class ScoreLine
@@ -27,7 +28,7 @@ final class ScoreLine {
2728
*/
2829
public function __construct(int $score = 1, string $message = "") {
2930
if ($score < 1 || $score > 15) {
30-
throw new \InvalidArgumentException("Score must be between 1 and 15. Given: $score");
31+
throw new InvalidArgumentException("Score must be between 1 and 15. Given: $score");
3132
}
3233
$this->score = $score;
3334
$this->scoreboardId = $score;
@@ -63,7 +64,7 @@ public function getMessage(): string {
6364
*/
6465
public function setScore(int $score): void {
6566
if ($score < 1 || $score > 15) {
66-
throw new \InvalidArgumentException("Score must be between 1 and 15. Given: $score");
67+
throw new InvalidArgumentException("Score must be between 1 and 15. Given: $score");
6768
}
6869
$this->score = $score;
6970
}

0 commit comments

Comments
 (0)