mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
Update to API 12
This commit is contained in:
parent
731ada7b38
commit
c59b4776ae
149 changed files with 6850 additions and 1918 deletions
|
|
@ -21,26 +21,27 @@
|
|||
|
||||
class Cache{
|
||||
public static $cached = array();
|
||||
|
||||
|
||||
public static function add($identifier, $blob, $minTTL = 30){
|
||||
self::$cached[$identifier] = array($blob, microtime(true) + $minTTL);
|
||||
self::$cached[$identifier] = array($blob, microtime(true) + $minTTL, $minTTL);
|
||||
}
|
||||
|
||||
|
||||
public static function get($identifier){
|
||||
if(isset(self::$cached[$identifier])){
|
||||
self::$cached[$identifier][1] = microtime(true) + self::$cached[$identifier][2];
|
||||
return self::$cached[$identifier][0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function exists($identifier){
|
||||
return isset(self::$cached[$identifier]);
|
||||
}
|
||||
|
||||
|
||||
public static function remove($identifier){
|
||||
unset(self::$cached[$identifier]);
|
||||
}
|
||||
|
||||
|
||||
public static function cleanup(){
|
||||
$time = microtime(true);
|
||||
foreach(self::$cached as $index => $data){
|
||||
|
|
@ -50,4 +51,4 @@ class Cache{
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -86,6 +86,10 @@ class Config{
|
|||
$this->load($this->file);
|
||||
$correct = $this->check();
|
||||
}
|
||||
|
||||
public function fixYAMLIndexes($str){
|
||||
return preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
|
|
@ -125,7 +129,8 @@ class Config{
|
|||
$this->config = @json_decode($content, true);
|
||||
break;
|
||||
case CONFIG_YAML:
|
||||
$this->config = Spyc::YAMLLoad($content);
|
||||
$content = $this->fixYAMLIndexes($content);
|
||||
$this->config = yaml_parse($content);
|
||||
break;
|
||||
case CONFIG_SERIALIZED:
|
||||
$this->config = @unserialize($content);
|
||||
|
|
@ -172,7 +177,7 @@ class Config{
|
|||
$content = json_encode($this->config, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING);
|
||||
break;
|
||||
case CONFIG_YAML:
|
||||
$content = Spyc::YAMLDump($this->config);
|
||||
$content = yaml_emit($this->config, YAML_UTF8_ENCODING);
|
||||
break;
|
||||
case CONFIG_SERIALIZED:
|
||||
$content = @serialize($this->config);
|
||||
|
|
|
|||
|
|
@ -63,58 +63,4 @@ class Java_String{
|
|||
}
|
||||
return $h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Java_Random{
|
||||
private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero;
|
||||
|
||||
public function __construct($seed = false){
|
||||
$this->n1 = new Math_BigInteger(0x5DEECE66D);
|
||||
$this->n2 = new Math_BigInteger(1);
|
||||
$this->n2 = $this->n2->bitwise_leftShift(48)->subtract($this->n2);
|
||||
$this->n3 = new Math_BigInteger(0xB);
|
||||
$this->zero = new Math_BigInteger(0);
|
||||
if($seed === false){
|
||||
$seed = microtime(true) * 1000000;
|
||||
}
|
||||
$this->setSeed($seed);
|
||||
}
|
||||
|
||||
public function setSeed($seed){
|
||||
$seed = new Math_BigInteger($seed);
|
||||
$this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2);
|
||||
$this->haveNextNextGaussian = false;
|
||||
}
|
||||
|
||||
protected function next($bits){
|
||||
$bits = (int) $bits;
|
||||
$this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2);
|
||||
return $this->_tripleRightShift($this->seed, (48 - $bits));
|
||||
}
|
||||
|
||||
private function _tripleRightShift($number, $places){
|
||||
if($number->compare($this->zero) >= 0){
|
||||
return $number->bitwise_rightShift($places);
|
||||
}
|
||||
$n1 = new Math_BigInteger(2);
|
||||
return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places));
|
||||
}
|
||||
|
||||
public function nextBytes($bytes){
|
||||
$bytes = (int) $bytes;
|
||||
$b = b"";
|
||||
$max = $bytes & ~0x3;
|
||||
for($i = 0; $i < $max; $i += 4){
|
||||
$b .= $this->next(32)->toBytes();
|
||||
}
|
||||
if($max < $bytes){
|
||||
$random = $this->next(32)->toBytes();
|
||||
for($j = $max; $j < $bytes; ++$j){
|
||||
$b .= $random{$j-$max};
|
||||
}
|
||||
}
|
||||
return $b;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ class NBT{
|
|||
$this->offset += $n;
|
||||
return substr($this->binary, $this->offset - $n, $n);
|
||||
}
|
||||
|
||||
|
||||
private function feof(){
|
||||
return !isset($this->binary{$this->offset});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,15 @@ class Utils{
|
|||
public static $ip = false;
|
||||
|
||||
public static function isOnline(){
|
||||
return ((@fsockopen("google.com", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false);
|
||||
return ((@fsockopen("8.8.8.8", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false);
|
||||
}
|
||||
|
||||
public static function getCallableIdentifier(callable $variable){
|
||||
if(is_array($variable)){
|
||||
return sha1(strtolower(get_class($variable[0]))."::".strtolower($variable[1]));
|
||||
}else{
|
||||
return sha1(strtolower($variable));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUniqueID($raw = false, $extra = ""){
|
||||
|
|
@ -90,13 +98,23 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function getOS(){
|
||||
$uname = trim(strtoupper(php_uname("s")));
|
||||
if(strpos($uname, "DARWIN") !== false){
|
||||
return "mac";
|
||||
}elseif(strpos($uname, "WIN") !== false){
|
||||
$uname = php_uname("s");
|
||||
if(stripos($uname, "Darwin") !== false){
|
||||
if(strpos(php_uname("m"), "iP") === 0){
|
||||
return "ios";
|
||||
}else{
|
||||
return "mac";
|
||||
}
|
||||
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
|
||||
return "win";
|
||||
}elseif(strpos($uname, "LINUX") !== false){
|
||||
return "linux";
|
||||
}elseif(stripos($uname, "Linux") !== false){
|
||||
if(@file_exists("/system/build.prop")){
|
||||
return "android";
|
||||
}else{
|
||||
return "linux";
|
||||
}
|
||||
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
|
||||
return "bsd";
|
||||
}else{
|
||||
return "other";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue