Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.
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
2 changes: 2 additions & 0 deletions src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use NeiroNetwork\AlternativeCoreWars\core\PlayerBlockTracker;
use NeiroNetwork\AlternativeCoreWars\core\GameArenaProtector;
use NeiroNetwork\AlternativeCoreWars\core\PlayerKillAssistsEventMaker;
use NeiroNetwork\AlternativeCoreWars\core\CommandFactory;
use NeiroNetwork\AlternativeCoreWars\core\PrivateCraftingForBrewingAndSmelting;
use NeiroNetwork\AlternativeCoreWars\core\RewardGiver;
use NeiroNetwork\AlternativeCoreWars\core\ServerSpecificationNormalizer;
Expand Down Expand Up @@ -70,6 +71,7 @@ protected function onLoad() : void{
ShopCreator::class,
DropItemReplacer::class,
KitEventBroker::class,
CommandFactory::class,
]);
}

Expand Down
34 changes: 34 additions & 0 deletions src/command/PlayerStatsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace NeiroNetwork\AlternativeCoreWars\core\command;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\permission\DefaultPermissions;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use SOFe\InfoAPI\InfoAPI;
use SOFe\InfoAPI\PlayerInfo;

class PlayerStatsCommand extends Command{

public function __construct(){
parent::__construct("stats", "プレイヤーの統計を確認します", null, ["stat", "statistics", "statistic"]);
}

public function execute(CommandSender $sender, string $commandLabel, array $args){
$target = $sender->hasPermission(DefaultPermissions::ROOT_OPERATOR) ? implode(" ", $args) : "";
$target = $sender->getServer()->getPlayerByPrefix($target) ?? $sender;
if($target instanceof Player){
$sender->sendMessage(InfoAPI::resolve(
TextFormat::GOLD . "========== " . TextFormat::WHITE . "{$sender->getName()} さんのステータス " . TextFormat::GOLD . "==========" . TextFormat::RESET . PHP_EOL .
"所持金: {money} Money" . PHP_EOL .
"経験値: {exp} EXP" . PHP_EOL .
"音色ポイント: {np} NP",
new PlayerInfo($target)
));
}
}
}
17 changes: 17 additions & 0 deletions src/core/CommandFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace NeiroNetwork\AlternativeCoreWars\core;

use NeiroNetwork\AlternativeCoreWars\core\command\PlayerStatsCommand;
use NeiroNetwork\AlternativeCoreWars\SubPluginBase;

class CommandFactory extends SubPluginBase{

protected function onEnable() : void{
$this->getServer()->getCommandMap()->registerAll($this->getName(), [
new PlayerStatsCommand(),
]);
}
}
46 changes: 46 additions & 0 deletions src/core/PlayerActivityTracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace NeiroNetwork\AlternativeCoreWars\core;

use NeiroNetwork\AlternativeCoreWars\event\PlayerDeathWithoutDeathScreenEvent;
use NeiroNetwork\AlternativeCoreWars\SubPluginBase;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\player\Player;
use SOFe\Capital\Capital;
use SOFe\Capital\LabelSet;
use SOFe\Capital\Schema\Complete;

class PlayerActivityTracker extends SubPluginBase{

private Complete $kills, $assists, $deaths, $breaks, $victories, $defeats, $playtime;

protected function onEnable() : void{
Capital::api("0.1.0", function(Capital $api){
$this->kills = $api->completeConfig(["currency" => "kills"]);
$this->assists = $api->completeConfig(["currency" => "assists"]);
$this->deaths = $api->completeConfig(["currency" => "deaths"]);
$this->breaks = $api->completeConfig(["currency" => "breaks"]);
$this->victories = $api->completeConfig(["currency" => "victories"]);
$this->defeats = $api->completeConfig(["currency" => "defeats"]);
$this->playtime = $api->completeConfig(["currency" => "playtime"]);
});
}

private function increase(Player $player, Complete $schema, LabelSet $label = null) : void{
Capital::api("0.1.0", function(Capital $api) use ($player, $schema, $label){
yield from $api->addMoney($this->getName(), $player, $schema, 1, $label ?? new LabelSet([]));
});
}

public function onDeath(PlayerDeathWithoutDeathScreenEvent $event) : void{
$player = $event->getPlayer();
$last = $player->getLastDamageCause();

$this->increase($player, $this->deaths, new LabelSet(["cause" => $last->getCause()]));
if($last instanceof EntityDamageByEntityEvent && ($damager = $last->getEntity()) instanceof Player){
$this->increase($damager, $this->kills, new LabelSet(["cause" => $last->getCause()]));
}
}
}