Skip to content

Commit f055ca5

Browse files
committed
fix commandsender thing
1 parent aba1e27 commit f055ca5

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

packages/php/src/Commands/CommandSender.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22

33
namespace Dragonfly\PluginLib\Commands;
44

5-
use Df\Plugin\WorldRef;
6-
use Dragonfly\PluginLib\Actions\Actions;
7-
use Dragonfly\PluginLib\Entity\Player;
8-
9-
class CommandSender extends Player {
10-
public function __construct(
11-
public string $uuid,
12-
public string $name,
13-
Actions $actions,
14-
?WorldRef $world = null,
15-
) {
16-
parent::__construct($uuid, $name, $actions, $world);
17-
}
5+
/**
6+
* Interface for anything that can execute commands (players, console, etc.)
7+
*/
8+
interface CommandSender {
9+
public function sendMessage(string $message): void;
10+
public function getName(): string;
1811
}

packages/php/src/Entity/Player.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use Df\Plugin\Vec3;
77
use Df\Plugin\WorldRef;
88
use Dragonfly\PluginLib\Actions\Actions;
9+
use Dragonfly\PluginLib\Commands\CommandSender;
910

10-
final class Player {
11+
final class Player implements CommandSender {
1112
public function __construct(
1213
private string $uuid,
1314
private string $name,

packages/php/src/Events/EventContext.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Df\Plugin\EventResult;
66
use Dragonfly\PluginLib\Actions\Actions;
77
use Dragonfly\PluginLib\Actions\ActionsTrait;
8-
use Dragonfly\PluginLib\Commands\CommandSender;
98
use Dragonfly\PluginLib\Entity\Player;
109
use Dragonfly\PluginLib\Server\Server;
1110
use Dragonfly\PluginLib\StreamSender;
@@ -93,9 +92,8 @@ public function player(string $uuid, string $name = ''): Player {
9392
return new Player($uuid, $name, $this->getActions());
9493
}
9594

96-
public function commandSender(string $uuid, string $name): CommandSender {
97-
$world = $this->server->getPlayerWorld($uuid);
98-
return new CommandSender($uuid, $name, $this->getActions(), $world);
95+
public function commandSender(string $uuid): ?Player {
96+
return $this->server->getPlayer($uuid);
9997
}
10098

10199
/**

packages/php/src/PluginBase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ private function ensureCommandHandler(): void {
478478
$cmd = clone $template;
479479

480480
$senderUuid = $cmdEvt->getPlayerUuid();
481-
$senderName = $cmdEvt->getName();
482481
$ctx = new EventContext($this->pluginId, $eventId, $this->sender, $this->server, $event->getExpectsResponse());
483-
$sender = $ctx->commandSender($senderUuid, $senderName);
482+
$sender = $ctx->commandSender($senderUuid);
483+
if ($sender === null) {
484+
return;
485+
}
484486

485487
try {
486488
$argsField = $cmdEvt->getArgs();

0 commit comments

Comments
 (0)