Phpcraft
Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Phpcraft\Phpcraft Class Reference

Static Public Member Functions

static getProfiles (bool $bypass_cache=false)
 
static getProfilesFile ()
 
static getMinecraftFolder ()
 
static isWindows ()
 
static saveProfiles (array $profiles)
 
static getCachableJson (string $url)
 
static maintainCache ()
 
static httpPOST (string $url, array $data)
 
static resolve (string $server)
 
static binaryStringToBin (string $str)
 
static binaryStringToHex (string $str)
 
static sha1 (string $str)
 
static chatToText ($chat, int $format=ChatComponent::FORMAT_NONE, ?array $translations=null)
 
static getServerStatus (string $hostname, int $port=25565, float $timeout=3.000, int $method=ServerConnection::METHOD_ALL)
 
static textToChat (string $text, bool $allow_amp=false)
 
static colorDiff (array $rgb1, array $rgb2)
 
static rgbToHex (array $rgb)
 
static rgbToInt (array $rgb)
 
static recursivelyDelete (string $path)
 

Public Attributes

const SRC_DIR = __DIR__
 
const INSTALL_DIR = self::SRC_DIR.'/..'
 
const BIN_DIR = self::INSTALL_DIR.'/bin'
 
const DATA_DIR = self::INSTALL_DIR.'/data'
 
const FORMAT_NONE = 0
 
const FORMAT_ANSI = 1
 
const FORMAT_SILCROW = 2
 
const FORMAT_AMPERSAND = 3
 
const FORMAT_HTML = 4
 
const METHOD_ALL = 0
 
const METHOD_MODERN = 1
 
const METHOD_LEGACY = 2
 

Static Public Attributes

static $json_cache
 
static $user_cache
 

Member Function Documentation

◆ binaryStringToBin()

static Phpcraft\Phpcraft::binaryStringToBin ( string  $str)
static

◆ binaryStringToHex()

static Phpcraft\Phpcraft::binaryStringToHex ( string  $str)
static

◆ chatToText()

static Phpcraft\Phpcraft::chatToText (   $chat,
int  $format = ChatComponent::FORMAT_NONE,
?array  $translations = null 
)
static
Parameters
array | string | null | ChatComponent$chat
int$format
array<string,string>|null$translations
Returns
string
Deprecated:
Use ChatComponent::cast($chat)->toString($format), instead.

◆ colorDiff()

static Phpcraft\Phpcraft::colorDiff ( array  $rgb1,
array  $rgb2 
)
static

Calculates the "distance" between two RGB arrays (each 3 integers).

Parameters
array{int,int,int}$rgb1
array{int,int,int}$rgb2
Returns
int

◆ getCachableJson()

static Phpcraft\Phpcraft::getCachableJson ( string  $url)
static

Returns the contents of a JSON file as associative array with additional memory and disk caching levels.

Parameters
string$urlThe URL of the resource.
Returns
array
Exceptions
IOException
See also
Phpcraft::maintainCache

◆ getMinecraftFolder()

static Phpcraft\Phpcraft::getMinecraftFolder ( )
static

Returns the path of the .minecraft folder without a folder seperator at the end.

Returns
string

◆ getProfiles()

static Phpcraft\Phpcraft::getProfiles ( bool  $bypass_cache = false)
static

Returns the contents of Minecraft's launcher_profiles.json with some values being set if they are unset.

Parameters
bool$bypass_cacheSet this to true if you anticipate external changes to the file.
Returns
array
See also
Phpcraft::getProfilesFile()
Phpcraft::saveProfiles()

◆ getProfilesFile()

static Phpcraft\Phpcraft::getProfilesFile ( )
static

Returns the path of Minecraft's launcher_profiles.json.

Returns
string

◆ getServerStatus()

static Phpcraft\Phpcraft::getServerStatus ( string  $hostname,
int  $port = 25565,
float  $timeout = 3.000,
int  $method = ServerConnection::METHOD_ALL 
)
static
Parameters
string$hostname
int$port
float$timeout
int$method
Returns
array
Exceptions
IOException
Deprecated:
Use ServerConnection::getStatus, instead.

◆ httpPOST()

static Phpcraft\Phpcraft::httpPOST ( string  $url,
array  $data 
)
static

Sends an HTTP POST request with a JSON payload. The response will always contain a "status" value which will be the HTTP response code, e.g. 200.

Parameters
string$url
array$data
Returns
array

◆ isWindows()

static Phpcraft\Phpcraft::isWindows ( )
static

Returns true if the code is running on a Windows machine.

Returns
boolean

◆ maintainCache()

static Phpcraft\Phpcraft::maintainCache ( )
static

Deletes expired cache entries.

Returns
void
See also
getCachableJson
getCachableResource

◆ recursivelyDelete()

static Phpcraft\Phpcraft::recursivelyDelete ( string  $path)
static

Recursively deletes a folder.

Parameters
string$path
Returns
void

◆ resolve()

static Phpcraft\Phpcraft::resolve ( string  $server)
static

Resolves the given address.

Parameters
string$serverThe server address, e.g. localhost
Returns
string The resolved address, e.g. localhost:25565
Deprecated:
Use ServerConnection::resolveAddress or even ServerConnection::toAddress.

◆ rgbToHex()

static Phpcraft\Phpcraft::rgbToHex ( array  $rgb)
static

Converts an RGB array (3 integers) into a hexadecimal string, e.g. ff00ff.

Parameters
array{int,int,int}$rgb
Returns
string
Since
0.5.18

◆ rgbToInt()

static Phpcraft\Phpcraft::rgbToInt ( array  $rgb)
static

Converts an RGB array (3 integers) into a decimal number for use in NBT tags.

Parameters
array{int,int,int}$rgb
Returns
int
Since
0.5.18

◆ saveProfiles()

static Phpcraft\Phpcraft::saveProfiles ( array  $profiles)
static

Saves the profiles array into Minecraft's launcher_profiles.json.

Parameters
array$profiles
Returns
void

◆ sha1()

static Phpcraft\Phpcraft::sha1 ( string  $str)
static

Generates a Minecraft-style SHA1 hash.

Parameters
string$str
Returns
string

◆ textToChat()

static Phpcraft\Phpcraft::textToChat ( string  $text,
bool  $allow_amp = false 
)
static
Parameters
string$text
boolean$allow_amp
Returns
array
Deprecated:
Use ChatComponent::text($text, $allow_amp)->toArray(), instead.

Member Data Documentation

◆ $json_cache

Configuration Phpcraft\Phpcraft::$json_cache
static

◆ $user_cache

Configuration Phpcraft\Phpcraft::$user_cache
static

◆ BIN_DIR

const Phpcraft\Phpcraft::BIN_DIR = self::INSTALL_DIR.'/bin'

◆ DATA_DIR

const Phpcraft\Phpcraft::DATA_DIR = self::INSTALL_DIR.'/data'

◆ FORMAT_AMPERSAND

const Phpcraft\Phpcraft::FORMAT_AMPERSAND = 3

◆ FORMAT_ANSI

const Phpcraft\Phpcraft::FORMAT_ANSI = 1

◆ FORMAT_HTML

const Phpcraft\Phpcraft::FORMAT_HTML = 4

◆ FORMAT_NONE

const Phpcraft\Phpcraft::FORMAT_NONE = 0

◆ FORMAT_SILCROW

const Phpcraft\Phpcraft::FORMAT_SILCROW = 2

◆ INSTALL_DIR

const Phpcraft\Phpcraft::INSTALL_DIR = self::SRC_DIR.'/..'

◆ METHOD_ALL

const Phpcraft\Phpcraft::METHOD_ALL = 0

◆ METHOD_LEGACY

const Phpcraft\Phpcraft::METHOD_LEGACY = 2

◆ METHOD_MODERN

const Phpcraft\Phpcraft::METHOD_MODERN = 1

◆ SRC_DIR

const Phpcraft\Phpcraft::SRC_DIR = __DIR__