<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
josantonius / minecraft-server-player-stat example snippets
/**
* @param string $version Server version.
* @param string $language Server language.
* @param string $logsPath Server logs directory path.
* @param string $statsPath Server stats directory path.
* @param string $storagePath Directory path where available terms and players will be stored.
*
* @throws MinecraftServerException if the Minecraft version or language is not valid.
* @throws UnreadableDirectoryException if the logs or stats path is not valid.
* @throws UnwriteableDirectoryException if the storage path is not valid.
*
* @see https://mcasset.cloud/1.19.2/assets/minecraft/lang to see available languages.
*/
public function __construct(
private string $version,
private string $language,
private string $logsPath,
private string $statsPath,
private string $storagePath,
);
/**
* @param string $username Username in case insensitive.
* @param string $term Literal Minecraft term in case insensitive.
* In Spanish, a term with accents can be written without them.
* For another languages accents are Stat;
public function getAvailableStats(): array;
public function getPlayerList(): array;
public readonly int|null $broken;
public readonly int|null $crafted;
public readonly int|null $dropped;
public readonly int|null $killed;
public readonly int|null $killedBy;
public readonly int|null $mined;
public readonly int|null $pickedUp;
public readonly int|null $used;
/**
* If the unit type is distance, this value is given in centimeters.
* If the unit type is time, this value is given in ticks.
*
* @see https://minecraft.fandom.com/wiki/Tutorials/Units_of_measure to see the unit conversions.
*/
public readonly int|null $custom;
public readonly string $key;
public readonly string $prettyTerm;
public readonly string $term;
/**
* Available types: block, entity, item, stat.
*/
public readonly string $type;
/**
* Available types: amount, distance, time.
*/
public readonly string $unitType;
public readonly string $username;
public readonly string $uuid;
use Josantonius\MinecraftServerPlayerStat\Exceptions\WrongTermException;
use Josantonius\MinecraftServerPlayerStat\Exceptions\StatsNotFoundException;
use Josantonius\MinecraftServerPlayerStat\Exceptions\UnknownUsernameException;
use Josantonius\MinecraftServerPlayerStat\Exceptions\MinecraftServerException;
use Josantonius\MinecraftServerPlayerStat\Exceptions\UnreadableDirectoryException;
use Josantonius\MinecraftServerPlayerStat\Exceptions\UnwriteableDirectoryException;
use Josantonius\MinecraftServerPlayerStat\MinecraftServer;
$minecraftServer = new MinecraftServer(
version: '1.17.1',
language: 'it_it',
logsPath: '/minecraft/logs',
statsPath: '/minecraft/saves/world/stats',
storagePath: '/data/storage',
);
$stat = $minecraftServer->getPlayerStat('Aguilar11235813', 'Blocco Di Diamante');
echo "{$stat->username} ha raccolto {$stat->pickedUp} blocchi di diamante.";
// Aguilar11235813 ha raccolto 8 blocchi di diamanti.
use Josantonius\MinecraftServerPlayerStat\MinecraftServer;
$minecraftServer = new MinecraftServer(
version: '1.17',
language: 'en_us',
logsPath: '/minecraft/logs',
statsPath: '/minecraft/saves/world/stats',
storagePath: '/data/storage',
);
$stat = $minecraftServer->getPlayerStat('KrakenBite', 'zombie');
echo "{$stat->username} was killed {$stat->killedBy} times by a {$stat->term}.";
// KrakenBite was killed 2 times by a zombie.
use Josantonius\MinecraftServerPlayerStat\MinecraftServer;
$minecraftServer = new MinecraftServer(
version: '1.18.1',
language: 'fr_fr',
logsPath: '/minecraft/logs',
statsPath: '/minecraft/saves/world/stats',
storagePath: '/data/storage',
);
$stat = $minecraftServer->getPlayerStat('Tweedlex', 'HACHE ON BOIS');
echo "{$stat->username} a utilisé une " . strtolower($stat->term) . " {$stat->used} fois.";
// Tweedlex a utilisé une hache en bois 111 fois.
use Josantonius\MinecraftServerPlayerStat\MinecraftServer;
$minecraftServer = new MinecraftServer(
version: '1.19.2',
language: 'pt_br',
logsPath: '/minecraft/logs',
statsPath: '/minecraft/saves/world/stats',
storagePath: '/data/storage',
);
$stat = $minecraftServer->getPlayerStat('SpOok', 'tempo desde a última morte');
echo 'SpOok morreu pela última vez há ' . ticksToHour($stat->custom) . ' horas.';
// SpOok morreu pela última vez há 10 horas.