small fixes

This commit is contained in:
GameHerobrine 2023-01-15 00:00:37 +03:00
parent 8b9cdc6307
commit 0e3f78fbf7
5 changed files with 29 additions and 40 deletions

View file

@ -306,7 +306,10 @@ class BlockAPI{
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username; $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username;
break; break;
}else{ }else{
$item = self::fromString($args[0]); $item = self::fromString($args[0]);
if(!($issuer instanceof Player)){
return "You cant give an item to a non-player.";
}
if(($issuer->gamemode & 0x01) === 0x01){ if(($issuer->gamemode & 0x01) === 0x01){
$output .= "You are in creative mode."; $output .= "You are in creative mode.";
break; break;

View file

@ -143,7 +143,7 @@ class EntityAPI{
return $output; return $output;
} }
public function summon(Position $pos, $class, $type, Array $data = []){ public function summon(Position $pos, $class, $type, array $data = []){
$entity = $this->add($pos->level, $class, $type, [ $entity = $this->add($pos->level, $class, $type, [
"x" => $pos->x, "x" => $pos->x,
"y" => $pos->y, "y" => $pos->y,

View file

@ -115,8 +115,7 @@ class PlayerAPI{
switch($cmd){ switch($cmd){
case "spawnpoint": case "spawnpoint":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
$output .= "Please run this command in-game."; return "Please run this command in-game.";
break;
} }
if(count($args) === 1 or count($args) === 4){ if(count($args) === 1 or count($args) === 4){
@ -126,8 +125,7 @@ class PlayerAPI{
} }
if(!($target instanceof Player)){ if(!($target instanceof Player)){
$output .= "That player cannot be found."; return "That player cannot be found.";
break;
} }
if(count($args) === 3){ if(count($args) === 3){
@ -137,23 +135,18 @@ class PlayerAPI{
} }
$target->setSpawn($spawn); $target->setSpawn($spawn);
$output .= "Spawnpoint set correctly!\n"; return "Spawnpoint set correctly!\n";
break;
case "spawn": case "spawn":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
$output .= "Please run this command in-game."; return "Please run this command in-game.";
break;
} }
$issuer->teleport($this->server->spawn); $issuer->teleport($this->server->spawn);
$output .= "You teleported to the world spawn, " . $issuer->username . " . "; return "You were teleported to the spawn.";
break;
case "ping": case "ping":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
$output .= "Please run this command in-game."; return "Please run this command in-game.";
break;
} }
$output .= "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n"; return "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n";
break;
case "gamemode": case "gamemode":
$player = false; $player = false;
$setgm = false; $setgm = false;
@ -186,16 +179,14 @@ class PlayerAPI{
$player = $this->server->api->player->get($args[0]); $player = $this->server->api->player->get($args[0]);
$setgm = $args[1]; $setgm = $args[1];
}else{ }else{
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n"; return "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break;
} }
} }
if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){ if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n"; return "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break;
} }
if($player->setGamemode($gms[strtolower($setgm)])){ if($player->setGamemode($gms[strtolower($setgm)])){
$output .= "Gamemode of " . $player->username . " changed to " . $player->getGamemode() . "\n"; return "Gamemode of " . $player->username . " changed to " . $player->getGamemode() . "\n";
} }
break; break;
case "tp": case "tp":
@ -207,13 +198,12 @@ class PlayerAPI{
$name = array_shift($args); $name = array_shift($args);
$target = implode(" ", $args); $target = implode(" ", $args);
}else{ }else{
$output .= "Usage: /$cmd [target player] <destination player>\n"; return "Usage: /$cmd [target player] <destination player>\n";
break;
} }
if($this->teleport($name, $target) !== false){ if($this->teleport($name, $target) !== false){
$output .= "\"$name\" teleported to \"$target\"\n"; return "\"$name\" teleported to \"$target\"\n";
}else{ }else{
$output .= "Couldn't teleport.\n"; return "Couldn't teleport.\n";
} }
}else{ }else{
if(!isset($args[3]) and isset($args[2]) and isset($args[1]) and isset($args[0]) and ($issuer instanceof Player)){ if(!isset($args[3]) and isset($args[2]) and isset($args[1]) and isset($args[0]) and ($issuer instanceof Player)){
@ -227,16 +217,14 @@ class PlayerAPI{
$y = $args[2]; $y = $args[2];
$z = $args[3]; $z = $args[3];
}else{ }else{
$output .= "Usage: /$cmd [player] <x> <y> <z>\n"; return "Usage: /$cmd [player] <x> <y> <z>\n";
break;
} }
if($this->tppos($name, $x, $y, $z)){ if($this->tppos($name, $x, $y, $z)){
$output .= "\"$name\" teleported to ($x, $y, $z)\n"; return "\"$name\" teleported to ($x, $y, $z)\n";
}else{ }else{
$output .= "Couldn't teleport.\n"; return "Couldn't teleport.\n";
} }
} }
break;
case "kill": case "kill":
case "suicide": case "suicide":
if(!isset($args[0]) and ($issuer instanceof Player)){ if(!isset($args[0]) and ($issuer instanceof Player)){
@ -246,9 +234,9 @@ class PlayerAPI{
} }
if($player instanceof Player){ if($player instanceof Player){
$player->entity->harm(PHP_INT_MAX, "console", true); $player->entity->harm(PHP_INT_MAX, "console", true);
$player->sendChat("Ouch. That looks like it hurt.\n"); return "Ouch. That looks like it hurt.\n";
}else{ }else{
$output .= "Usage: /$cmd [player]\n"; return "Usage: /$cmd [player]\n";
} }
break; break;
case "list": case "list":
@ -259,7 +247,7 @@ class PlayerAPI{
foreach($this->server->clients as $c){ foreach($this->server->clients as $c){
$output .= $c->username . ", "; $output .= $c->username . ", ";
} }
$output = substr($output, 0, -2) . "\n"; return substr($output, 0, -2) . "\n";
break; break;
case "loc": case "loc":
if(!($issuer instanceof Player)) return "Please run this command in-game."; if(!($issuer instanceof Player)) return "Please run this command in-game.";
@ -269,9 +257,7 @@ class PlayerAPI{
$level = $issuer->entity->level->getName(); $level = $issuer->entity->level->getName();
$compass = [0 => "X+", 1 => "Z+", 2 => "X-", 3 => "Z-", null => "null"]; $compass = [0 => "X+", 1 => "Z+", 2 => "X-", 3 => "Z-", null => "null"];
$direction = $compass[$issuer->entity->getDirection()]; $direction = $compass[$issuer->entity->getDirection()];
$output .= "Your coordinates: X: $x, Y: $y, Z: $z, world: $level.\n"; return "Your coordinates: X: $x, Y: $y, Z: $z, world: $level.\nDirection: $direction";
$output .= "Direction: $direction";
break;
} }
return $output; return $output;
} }
@ -281,7 +267,7 @@ class PlayerAPI{
if($name === ""){ if($name === ""){
return false; return false;
} }
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name " . ($alike === true ? "LIKE '%" . $name . "%'" : "= '" . $name . "'") . ";"); $query = $this->server->query("SELECT ip,port,name FROM players WHERE name " . ($alike === true ? "LIKE '" . $name . "%'" : "= '" . $name . "'") . ";");
$players = []; $players = [];
if($query !== false and $query !== true){ if($query !== false and $query !== true){
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){ while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){

View file

@ -9,7 +9,7 @@ class NetherReactorBlock extends SolidBlock{
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
//if(($item->getID() === IRON_SWORD || $item->getID() === WOODEN_SWORD || $item->getID() === STONE_SWORD || $item->getID() === DIAMOND_SWORD || $item->getID() === GOLD_SWORD) /*&& $player->gamemode === 0*/){ //if(($item->getID() === IRON_SWORD || $item->getID() === WOODEN_SWORD || $item->getID() === STONE_SWORD || $item->getID() === DIAMOND_SWORD || $item->getID() === GOLD_SWORD) /*&& $player->gamemode === 0*/){
if($this->isCorrect($this->getX(),$this->getY(),$this->getZ()) && $this->getY() < 101 && NetherReactorBlock::$enableReactor){ if($this->getMetadata() === 0 && $this->isCorrect($this->getX(),$this->getY(),$this->getZ()) && $this->getY() < 101 && NetherReactorBlock::$enableReactor){
NetherReactorStructure::buildReactor($this->level, $this->getX(),$this->getY(),$this->getZ()); NetherReactorStructure::buildReactor($this->level, $this->getX(),$this->getY(),$this->getZ());
$this->meta = 1; $this->meta = 1;
$this->level->setBlock($this,$this); $this->level->setBlock($this,$this);

View file

@ -336,7 +336,7 @@ class PMFLevel extends PMF{
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4); $aY = $y - ($Y << 4);
if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
$b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]); $b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]);
}else{ //php8 fix }else{ //php8 fix
$b = 0; $b = 0;
@ -381,7 +381,7 @@ class PMFLevel extends PMF{
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4); $aY = $y - ($Y << 4);
if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
}else{ //php8 fix }else{ //php8 fix
$m = 0; $m = 0;