Skip to content

Utils ​

final class · pocketmine\utils\Utils · source

Big collection of functions

Constants ​

OS_ANDROID ​

php
public const OS_ANDROID = "android"

OS_BSD ​

php
public const OS_BSD = "bsd"

OS_IOS ​

php
public const OS_IOS = "ios"

OS_LINUX ​

php
public const OS_LINUX = "linux"

OS_MACOS ​

php
public const OS_MACOS = "mac"

OS_UNKNOWN ​

php
public const OS_UNKNOWN = "other"

OS_WINDOWS ​

php
public const OS_WINDOWS = "win"

Methods ​

assumeNotFalse() ​

php
public static function assumeNotFalse(mixed $value, \Closure|string $context = "This should never be false") : mixed

checkFloatNotInfOrNaN() ​

php
public static function checkFloatNotInfOrNaN(string $name, float $float) : void

checkLocationNotInfOrNaN() ​

php
public static function checkLocationNotInfOrNaN(\pocketmine\entity\Location $location) : void

checkUTF8() ​

php
public static function checkUTF8(string $string) : void

checkVector3NotInfOrNaN() ​

php
public static function checkVector3NotInfOrNaN(\pocketmine\math\Vector3 $vector3) : void

cloneCallback() ​

php
public static function cloneCallback() : \Closure

Deprecated

Deprecated.

cloneObjectArray() ​

php
public static function cloneObjectArray(array $array) : array

currentTrace() ​

php
public static function currentTrace(int $skipFrames = 0) : array

getCoreCount() ​

php
public static function getCoreCount(bool $recalculate = false) : int

getMachineUniqueId() ​

php
public static function getMachineUniqueId(string $extra = "") : \Ramsey\Uuid\UuidInterface

Gets this machine / server instance unique ID Returns a hash, the first 32 characters (or 16 if raw) will be an identifier that won't change frequently. The rest of the hash will change depending on other factors.

getNiceClassName() ​

php
public static function getNiceClassName(object $obj) : string

Returns a readable identifier for the class of the given object. Sanitizes class names for anonymous classes.

getNiceClosureName() ​

php
public static function getNiceClosureName(\Closure $closure) : string

Returns a readable identifier for the given Closure, including file and line.

getOS() ​

php
public static function getOS(bool $recalculate = false) : string

getOpcacheJitMode() ​

php
public static function getOpcacheJitMode() : ?int

Returns an integer describing the current OPcache JIT setting.

getRandomFloat() ​

php
public static function getRandomFloat() : float

Returns a random float between 0.0 and 1.0 Drop-in replacement for lcg_value()

getReferenceCount() ​

php
public static function getReferenceCount(object $value, bool $includeCurrent = true) : int

hexdump() ​

php
public static function hexdump(string $bin) : string

Returns a prettified hexdump

javaStringHash() ​

php
public static function javaStringHash(string $string) : int

parseDocComment() ​

php
public static function parseDocComment(string $docComment) : array

Extracts one-line tags from the doc-comment

printable() ​

php
public static function printable(mixed $str) : string

Returns a string that can be printed, replaces non-printable characters

printableCurrentTrace() ​

php
public static function printableCurrentTrace(int $skipFrames = 0) : array

printableExceptionInfo() ​

php
public static function printableExceptionInfo(\Throwable $e, $trace = null) : array

printableTrace() ​

php
public static function printableTrace(array $trace, int $maxStringLength = 80) : array

printableTraceWithMetadata() ​

php
public static function printableTraceWithMetadata(array $rawTrace, int $maxStringLength = 80) : array

Similar to Utils::printableTrace(), but associates metadata such as file and line number with each frame. This is used to transmit thread-safe information about crash traces to the main thread when a thread crashes.

promoteKeys() ​

php
public static function promoteKeys(array $array) : array

Gets rid of PHPStan BenevolentUnionType on array keys, so that wrong type errors get reported properly Use this if you don't care what the key type is and just want proper PHPStan error reporting

stringifyKeys() ​

php
public static function stringifyKeys(array $array) : \Generator

Generator which forces array keys to string during iteration. This is necessary because PHP has an anti-feature where it casts numeric string keys to integers, leading to various crashes.

testValidInstance() ​

php
public static function testValidInstance(string $className, string $baseName) : void

validateArrayValueType() ​

php
public static function validateArrayValueType(array $array, \Closure $validator) : void

validateCallableSignature() ​

php
public static function validateCallableSignature(callable|\DaveRandom\CallbackValidator\CallbackType $signature, callable $subject) : void

Verifies that the given callable is compatible with the desired signature. Throws a TypeError if they are incompatible.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.