mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,38 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class TimeAPI{
|
||||
public static $phases = array(
|
||||
|
||||
public static $phases = [
|
||||
"day" => 0,
|
||||
"sunset" => 9500,
|
||||
"night" => 10900,
|
||||
"sunrise" => 17800,
|
||||
);
|
||||
];
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("time", "<check|set|add> [time]", [$this, "commandHandler"]);
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||
|
|
@ -42,8 +25,7 @@ class TimeAPI{
|
|||
$level = false;
|
||||
if($issuer instanceof Player){
|
||||
$level = $issuer->level;
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
$p = strtolower(array_shift($args));
|
||||
|
|
@ -54,14 +36,12 @@ class TimeAPI{
|
|||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
$world = " in world \"$levelName\"";
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else $world = " in world \"".$level->getName()."\"";
|
||||
$output .= "Time".$world.": ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level)." ticks)\n";
|
||||
}else $world = " in world \"" . $level->getName() . "\"";
|
||||
$output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
|
||||
break;
|
||||
case "add":
|
||||
if(substr($args[1], 0, 2) === "w:"){
|
||||
|
|
@ -69,22 +49,20 @@ class TimeAPI{
|
|||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
$world = " to the time of world \"$levelName\"";
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else $world = " to the time of world \"".$level->getName()."\"";
|
||||
|
||||
}else $world = " to the time of world \"" . $level->getName() . "\"";
|
||||
|
||||
$addTime = array_shift($args);
|
||||
if(!is_numeric($addTime)){
|
||||
$output .= "Time must be an integer!";
|
||||
break;
|
||||
}
|
||||
$addTime = (int)$addTime;
|
||||
$addTime = (int) $addTime;
|
||||
$this->add($addTime, $level);
|
||||
$output .= "Added $addTime ticks".$world."\n";
|
||||
$output .= "Added $addTime ticks" . $world . "\n";
|
||||
break;
|
||||
case "set":
|
||||
if(substr($args[1], 0, 2) === "w:"){
|
||||
|
|
@ -92,24 +70,22 @@ class TimeAPI{
|
|||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
$world = " in world \"$levelName\"";
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else $world = " in world \"".$level->getName()."\"";
|
||||
|
||||
}else $world = " in world \"" . $level->getName() . "\"";
|
||||
|
||||
$setTime = array_shift($args);
|
||||
if(is_numeric($setTime)){
|
||||
$setTime = (int)$setTime;
|
||||
}
|
||||
elseif($setTime == 'sunrise' or $setTime == 'day' or $setTime == 'sunset' or $setTime == 'night');
|
||||
$setTime = (int) $setTime;
|
||||
}elseif($setTime == 'sunrise' or $setTime == 'day' or $setTime == 'sunset' or $setTime == 'night')
|
||||
;
|
||||
else{
|
||||
$output .= "Wrong time!";
|
||||
}
|
||||
$this->set($setTime, $level);
|
||||
$output .= "Set the time to ".$setTime.$world."\n";
|
||||
$output .= "Set the time to " . $setTime . $world . "\n";
|
||||
break;
|
||||
case "sunrise":
|
||||
case "day":
|
||||
|
|
@ -120,16 +96,14 @@ class TimeAPI{
|
|||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
$world = " in world \"$levelName\"";
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else $world = " in world \"".$level->getName()."\"";
|
||||
|
||||
}else $world = " in world \"" . $level->getName() . "\"";
|
||||
|
||||
$this->set($p, $level);
|
||||
$output .= "Set the time to ".$p.$world."\n";
|
||||
$output .= "Set the time to " . $p . $world . "\n";
|
||||
break;
|
||||
default:
|
||||
$output .= "Usage: /time <check|set|add> [time] [w:world]\n";
|
||||
|
|
@ -140,40 +114,20 @@ class TimeAPI{
|
|||
return $output;
|
||||
}
|
||||
|
||||
public function night(){
|
||||
return $this->set("night");
|
||||
}
|
||||
public function day(){
|
||||
return $this->set("day");
|
||||
}
|
||||
public function sunrise(){
|
||||
return $this->set("sunrise");
|
||||
}
|
||||
public function sunset(){
|
||||
return $this->set("sunset");
|
||||
public function getDate($time = false){
|
||||
$time = !is_integer($time) ? $this->get(false, $time) : $time;
|
||||
return str_pad(strval((floor($time / 800) + 6) % 24), 2, "0", STR_PAD_LEFT) . ":" . str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function get($raw = false, $level = false){
|
||||
if(!($level instanceof Level)){
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
return $raw === true ? $level->getTime():abs($level->getTime()) % 19200;
|
||||
}
|
||||
|
||||
public function add($time, $level = false){
|
||||
if(!($level instanceof Level)){
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
$level->setTime($level->getTime() + (int) $time);
|
||||
}
|
||||
|
||||
public function getDate($time = false){
|
||||
$time = !is_integer($time) ? $this->get(false, $time):$time;
|
||||
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
|
||||
}
|
||||
|
||||
public function getPhase($time = false){
|
||||
$time = !is_integer($time) ? $this->get(false, $time):$time;
|
||||
$time = !is_integer($time) ? $this->get(false, $time) : $time;
|
||||
if($time < TimeAPI::$phases["sunset"]){
|
||||
$time = "day";
|
||||
}elseif($time < TimeAPI::$phases["night"]){
|
||||
|
|
@ -186,6 +140,13 @@ class TimeAPI{
|
|||
return $time;
|
||||
}
|
||||
|
||||
public function add($time, $level = false){
|
||||
if(!($level instanceof Level)){
|
||||
$level = $this->server->api->level->getDefault();
|
||||
}
|
||||
$level->setTime($level->getTime() + (int) $time);
|
||||
}
|
||||
|
||||
public function set($time, $level = false){
|
||||
if(!($level instanceof Level)){
|
||||
$level = $this->server->api->level->getDefault();
|
||||
|
|
@ -198,5 +159,21 @@ class TimeAPI{
|
|||
return $level->getTime();
|
||||
}
|
||||
|
||||
public function night(){
|
||||
return $this->set("night");
|
||||
}
|
||||
|
||||
public function day(){
|
||||
return $this->set("day");
|
||||
}
|
||||
|
||||
public function sunrise(){
|
||||
return $this->set("sunrise");
|
||||
}
|
||||
|
||||
public function sunset(){
|
||||
return $this->set("sunset");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue