Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 78446e0

Browse files
committed
Add npc system
1 parent 0746b7e commit 78446e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+5789
-10
lines changed

plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Arkania-Ange
2-
version: 0.2.0-beta
2+
version: 0.2.1-beta
33
main: arkania\Engine
44
src-namespace-prefix: arkania
55
api: 5.0.0

src/Engine.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use arkania\commands\CommandCache;
2626
use arkania\commands\default\LanguageCommand;
2727
use arkania\commands\default\MaintenanceCommand;
28+
use arkania\commands\default\NpcCommand;
2829
use arkania\commands\default\PluginCommand;
2930
use arkania\commands\default\ReplyCommand;
3031
use arkania\commands\default\TellCommand;
@@ -52,6 +53,7 @@
5253
use arkania\rank\RankManager;
5354
use arkania\utils\AlreadyInstantiatedException;
5455
use arkania\utils\BadExtensionException;
56+
use arkania\utils\Loader;
5557
use arkania\webhook\AlreadyRegisteredException;
5658
use arkania\webhook\WebhookManager;
5759
use arkania\webhook\WebhookNamesKeys;
@@ -108,6 +110,7 @@ protected function onLoad() : void {
108110
$this->itemManager = new ItemManager();
109111
$this->resourcePackManager = new ResourcePackManager($this);
110112
$this->rankManager = new RankManager($this);
113+
new Loader();
111114

112115
$this->getServerManager()->addServer(
113116
new EngineServer(
@@ -137,6 +140,7 @@ protected function onEnable() : void {
137140

138141
$this->getCommandCache()->registerCommands(
139142
new LanguageCommand(),
143+
new NpcCommand(),
140144
new MaintenanceCommand($this),
141145
new PluginCommand(),
142146
new ReplyCommand(),
@@ -148,7 +152,8 @@ protected function onEnable() : void {
148152
new PlayerJoinListener(),
149153
new PlayerReceiveFormListener(),
150154
new DataPacketSendListener(),
151-
new PlayerChangeLanguageListener()
155+
new PlayerChangeLanguageListener(),
156+
new DataPacketSendListener(),
152157
);
153158

154159
$this->serverLoader->enableEnginePlugins();

src/commands/default/NpcCommand.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* _ ____ _ __ _ _ _ ___ _ _____ _ _ ____ ___ _ _ _____
5+
* / \ | _ \ | |/ / / \ | \ | | |_ _| / \ | ____| | \ | | / ___| |_ _| | \ | | | ____|
6+
* / _ \ | |_) | | ' / / _ \ | \| | | | / _ \ _____ | _| | \| | | | _ | | | \| | | _|
7+
* / ___ \ | _ < | . \ / ___ \ | |\ | | | / ___ \ |_____| | |___ | |\ | | |_| | | | | |\ | | |___
8+
* /_/ \_\ |_| \_\ |_|\_\ /_/ \_\ |_| \_| |___| /_/ \_\ |_____| |_| \_| \____| |___| |_| \_| |_____|
9+
*
10+
* ArkaniaStudios-ANGE, une API conçue pour simplifier le développement.
11+
* Fournissant des outils et des fonctionnalités aux développeurs.
12+
* Cet outil est en constante évolution et est régulièrement mis à jour,
13+
* afin de répondre aux besoins changeants de la communauté.
14+
*
15+
* @author Julien
16+
* @link https://arkaniastudios.com
17+
* @version 0.2.0-beta
18+
*
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace arkania\commands\default;
24+
25+
use arkania\commands\CommandBase;
26+
use arkania\commands\parameters\SubParameter;
27+
use arkania\npc\FormManager;
28+
use arkania\player\permissions\MissingPermissionException;
29+
use arkania\player\permissions\PermissionsBase;
30+
use pocketmine\command\CommandSender;
31+
use pocketmine\player\Player;
32+
use function strtolower;
33+
34+
class NpcCommand extends CommandBase {
35+
public static array $npc = [];
36+
37+
/**
38+
* @throws MissingPermissionException
39+
*/
40+
public function __construct() {
41+
parent::__construct(
42+
'npc',
43+
'Manage the NPCs',
44+
'/npc'
45+
);
46+
$this->setPermission(PermissionsBase::getPermission('npc'));
47+
}
48+
49+
public function getCommandParameter() : array {
50+
return [
51+
new SubParameter('create', 'create', true),
52+
new SubParameter('disband', 'disband', true),
53+
new SubParameter('rotate', 'rotate', true),
54+
new SubParameter('edit', 'edit', true)
55+
];
56+
}
57+
58+
public function onRun(CommandSender $sender, array $parameters) : void {
59+
if(!$sender instanceof Player) {
60+
return;
61+
}
62+
63+
if($parameters === []) {
64+
FormManager::getInstance()->sendNpcCreationForm($sender);
65+
return;
66+
}
67+
$argument = strtolower($parameters['create']);
68+
if($argument === 'create') {
69+
FormManager::getInstance()->sendNpcCreationForm($sender);
70+
} elseif($argument === 'disband') {
71+
self::$npc[$sender->getName()] = 'disband';
72+
$sender->sendMessage('§cTap on the NPC to disband it');
73+
} elseif($argument === 'rotate') {
74+
self::$npc[$sender->getName()] = 'rotate';
75+
$sender->sendMessage('§cTap on the NPC to rotate it');
76+
} elseif($argument === 'edit') {
77+
self::$npc[$sender->getName()] = 'edit';
78+
$sender->sendMessage('§cTap on the NPC to edit it');
79+
}
80+
}
81+
82+
}

src/commands/parameters/SubParameter.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
2828
use pocketmine\network\mcpe\protocol\types\command\CommandEnum;
2929
use pocketmine\network\mcpe\protocol\types\command\CommandParameter;
30-
use RuntimeException;
3130
use function strtolower;
3231

3332
class SubParameter extends Parameter {
@@ -38,7 +37,7 @@ public function __construct(
3837
) {
3938
parent::__construct($name, $isOptional);
4039
$this->getCommandParameter()->paramType = AvailableCommandsPacket::ARG_FLAG_VALID | AvailableCommandsPacket::ARG_FLAG_ENUM;
41-
EnumStore::addEnum($this->getCommandParameter()->enum = new CommandEnum(strtolower($name), [strtolower($subCommandType)]));
40+
EnumStore::addEnum($this->getCommandParameter()->enum = new CommandEnum(strtolower($name), [strtolower($name)]));
4241
}
4342

4443
public function getNetworkType() : int {
@@ -49,8 +48,8 @@ public function canParse(string $argument, CommandSender $sender) : bool {
4948
return true;
5049
}
5150

52-
public function parse(string $argument, CommandSender $sender) : mixed {
53-
throw new RuntimeException("SubParameter cannot be parsed");
51+
public function parse(string $argument, CommandSender $sender) : string {
52+
return $argument;
5453
}
5554

5655
}

src/form/class/CustomForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function handleResponse(Player $player, $data) : void {
6868
$data[$elementName . '-' . $count[$elementName]] = $element->handle($value);
6969
} else {
7070
$count[$elementName] = 1;
71-
$data[$elementName] = $element->handle($value);
71+
$data[$elementName] = $element->handler($value);
7272
}
7373
unset($data[$key]);
7474
}

src/form/element/elements/Input.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
class Input extends Element {
2626
private string $text;
27-
private string $placeholder;
28-
private string $default;
27+
private ?string $placeholder;
28+
private ?string $default;
2929

3030
public function __construct(
3131
string $name,

src/libs/muqsit/simplepackethandler/utils/Utils.php

+14
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222

2323
namespace arkania\libs\muqsit\simplepackethandler\utils;
2424

25+
use arkania\npc\base\CustomEntity;
26+
use arkania\npc\base\SimpleEntity;
27+
use arkania\utils\Loader;
2528
use Closure;
2629
use InvalidArgumentException;
30+
use pocketmine\entity\Location;
2731
use ReflectionFunction;
2832
use ReflectionNamedType;
2933
use function count;
3034
use function implode;
3135
use function is_a;
36+
use function strtolower;
3237

3338
final class Utils {
3439
/**
@@ -64,4 +69,13 @@ public static function parseClosureSignature(Closure $closure, array $params, st
6469

6570
throw new InvalidArgumentException("Closure must satisfy signature (" . implode(", ", $params) . ") : {$return_type}");
6671
}
72+
73+
public static function getEntityById(Location $location, int|string $id) : null|CustomEntity|SimpleEntity {
74+
if(!isset(Loader::$entities[strtolower($id)])) {
75+
return null;
76+
}
77+
return new Loader::$entities[strtolower($id)]($location);
78+
79+
}
80+
6781
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* _ ____ _ __ _ _ _ ___ _ _____ _ _ ____ ___ _ _ _____
5+
* / \ | _ \ | |/ / / \ | \ | | |_ _| / \ | ____| | \ | | / ___| |_ _| | \ | | | ____|
6+
* / _ \ | |_) | | ' / / _ \ | \| | | | / _ \ _____ | _| | \| | | | _ | | | \| | | _|
7+
* / ___ \ | _ < | . \ / ___ \ | |\ | | | / ___ \ |_____| | |___ | |\ | | |_| | | | | |\ | | |___
8+
* /_/ \_\ |_| \_\ |_|\_\ /_/ \_\ |_| \_| |___| /_/ \_\ |_____| |_| \_| \____| |___| |_| \_| |_____|
9+
*
10+
* ArkaniaStudios-ANGE, une API conçue pour simplifier le développement.
11+
* Fournissant des outils et des fonctionnalités aux développeurs.
12+
* Cet outil est en constante évolution et est régulièrement mis à jour,
13+
* afin de répondre aux besoins changeants de la communauté.
14+
*
15+
* @author Julien
16+
* @link https://arkaniastudios.com
17+
* @version 0.2.0-beta
18+
*
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace arkania\listener;
24+
25+
use arkania\events\EngineListener;
26+
use arkania\utils\Loader;
27+
use pocketmine\nbt\tag\CompoundTag;
28+
use pocketmine\network\mcpe\protocol\AvailableActorIdentifiersPacket;
29+
use pocketmine\utils\AssumptionFailedError;
30+
31+
class DataPacketSendListener implements EngineListener {
32+
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) : void {
33+
foreach ($event->getPackets() as $packet) {
34+
if($packet instanceof AvailableActorIdentifiersPacket) {
35+
$customNamespaces = Loader::getCustomNamespaces();
36+
$base = $packet->identifiers->getRoot();
37+
$nbt = $base->getListTag("idlist");
38+
foreach ($customNamespaces as $index => $namespace) {
39+
$components = CompoundTag::create()
40+
->setString("bid", "")
41+
->setByte("hasspawnegg", 0)
42+
->setString("id", $namespace)
43+
->setInt("rid", 200 + $index)
44+
->setByte("summonable", 1);
45+
if($nbt === null) {
46+
throw new AssumptionFailedError("\$nbt === null");
47+
}
48+
$nbt->push($components);
49+
}
50+
}
51+
}
52+
}
53+
54+
}

src/entity/EntityManager.php src/npc/EntityManager.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@
2020

2121
declare(strict_types=1);
2222

23-
namespace arkania\entity;
23+
namespace arkania\npc;
24+
25+
use arkania\npc\utils\EntityRegistry;
2426

2527
class EntityManager {
28+
private static ?EntityRegistry $registry = null;
29+
30+
private static ?string $fallbackEntity = null;
31+
32+
public static function getEntityRegistry() : EntityRegistry {
33+
return self::$registry ??= new EntityRegistry();
34+
}
35+
36+
public static function getFallbackEntity() : ?string {
37+
return self::$fallbackEntity;
38+
}
39+
2640
}

0 commit comments

Comments
 (0)