mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
Update TimeAPI.php
Multiworld /time
This commit is contained in:
parent
5a240c7e0f
commit
e93e81222a
1 changed files with 78 additions and 7 deletions
|
|
@ -35,7 +35,7 @@ class TimeAPI{
|
||||||
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
|
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||||
$output = "";
|
$output = "";
|
||||||
switch($cmd){
|
switch($cmd){
|
||||||
case "time":
|
case "time":
|
||||||
|
|
@ -43,25 +43,96 @@ class TimeAPI{
|
||||||
if($issuer instanceof Player){
|
if($issuer instanceof Player){
|
||||||
$level = $issuer->level;
|
$level = $issuer->level;
|
||||||
}
|
}
|
||||||
$p = strtolower(array_shift($params));
|
else{
|
||||||
|
$level = $this->server->api->level->getDefault();
|
||||||
|
}
|
||||||
|
$p = strtolower(array_shift($args));
|
||||||
switch($p){
|
switch($p){
|
||||||
case "check":
|
case "check":
|
||||||
$output .= "Time: ".$this->getDate($level).", ".$this->getPhase($level)." (".$this->get(true, $level).")\n";
|
if(substr($args[0], 0, 2) === "w:"){
|
||||||
|
$levelName = preg_replace("/w:/", "", $args[0]);
|
||||||
|
$level = $this->server->api->level->get($levelName);
|
||||||
|
if($level instanceof Level){
|
||||||
|
$world = " in world \"$levelName\"";
|
||||||
|
}
|
||||||
|
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";
|
||||||
break;
|
break;
|
||||||
case "add":
|
case "add":
|
||||||
$output .= "Set the time to ".$this->add(array_shift($params), $level)."\n";
|
if(substr($args[1], 0, 2) === "w:"){
|
||||||
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
|
$level = $this->server->api->level->get($levelName);
|
||||||
|
if($level instanceof Level){
|
||||||
|
$world = " to the time of world \"$levelName\"";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
$this->add($addTime, $level);
|
||||||
|
$output .= "Added $addTime ticks".$world."\n";
|
||||||
break;
|
break;
|
||||||
case "set":
|
case "set":
|
||||||
$output .= "Set the time to ".$this->set(array_shift($params), $level)."\n";
|
if(substr($args[1], 0, 2) === "w:"){
|
||||||
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
|
$level = $this->server->api->level->get($levelName);
|
||||||
|
if($level instanceof Level){
|
||||||
|
$world = " in world \"$levelName\"";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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');
|
||||||
|
else{
|
||||||
|
$output .= "Wrong time!";
|
||||||
|
}
|
||||||
|
$this->set($setTime, $level);
|
||||||
|
$output .= "Set the time to ".$setTime.$world."\n";
|
||||||
break;
|
break;
|
||||||
case "sunrise":
|
case "sunrise":
|
||||||
case "day":
|
case "day":
|
||||||
case "sunset":
|
case "sunset":
|
||||||
case "night":
|
case "night":
|
||||||
$output .= "Set the time to ".$this->set($p, $level)."\n";
|
if(substr($args[1], 0, 2) === "w:"){
|
||||||
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
|
$level = $this->server->api->level->get($levelName);
|
||||||
|
if($level instanceof Level){
|
||||||
|
$world = " in world \"$levelName\"";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$output .= "World \"$levelName\" doesn't exist or loaded!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else $world = " in world \"".$level->getName()."\"";
|
||||||
|
|
||||||
|
$this->set($p, $level);
|
||||||
|
$output .= "Set the time to ".$p.$world."\n";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$output .= "Usage: /time <check|set|add> [time]\n";
|
$output .= "Usage: /time <check|set|add> [time] [w:world]\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue