From ae59d3da59c4b67e0bffaf77bd552f0449598153 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 2 Jul 2024 07:29:44 +0300 Subject: [PATCH] hotbar is limited to 7 slots by default, changeable with /hotbar --- src/API/PlayerAPI.php | 20 +++++++++++++++++++- src/Player.php | 19 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 3deefafc..8c3272f9 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -18,7 +18,8 @@ class PlayerAPI{ $this->registerCmd("spawn"); $this->registerCmd("ping"); $this->registerCmd("loc"); - + $this->registerCmd("hotbar", ""); + $this->server->api->console->alias("lag", "ping"); $this->server->api->console->alias("gm", "gamemode"); $this->server->api->console->alias("who", "list"); @@ -31,6 +32,7 @@ class PlayerAPI{ $this->server->api->console->cmdWhitelist("ping"); $this->server->api->console->cmdWhitelist("spawn"); $this->server->api->console->cmdWhitelist("loc"); + $this->server->api->console->cmdWhitelist("hotbar"); } public function registerCmd($cmd, $help = ""){ @@ -119,6 +121,21 @@ class PlayerAPI{ $target->setSpawn($spawn); return "Spawnpoint set correctly!\n"; + case "hotbar": + if(!($issuer instanceof Player)) return "Please run this command in-game."; + if(count($args) < 1) return "Slots in hotbar on server: {$issuer->slotCount}"; + + $scrw = $args[0]; + if(is_numeric($scrw)){ + $sc = (int)$scrw; + if($sc < 5 || $sc > 9) return "Slot count must be between 5 and 9."; + + $issuer->slotCount = $sc; + $issuer->sendInventory(); + return "Changed slot count to $sc"; + }else{ + return "Usage: /$cmd "; + } case "spawn": if(!($issuer instanceof Player)){ return "Please run this command in-game."; @@ -375,6 +392,7 @@ class PlayerAPI{ "lastIP" => "", "lastID" => 0, "achievements" => [], + "slot-count" => 7 ]; if(!file_exists(DATA_PATH . "players/" . $iname . ".yml")){ diff --git a/src/Player.php b/src/Player.php index 479e9116..2ec3141c 100755 --- a/src/Player.php +++ b/src/Player.php @@ -69,6 +69,7 @@ class Player{ private $chunkCount = []; private $received = []; + public $slotCount = 7; public $entityMovementQueue; public $entityMovementQueueLength = 0; @@ -1617,6 +1618,13 @@ class Player{ $this->slot = -1;//0 $this->hotbar = [-1, -1, -1, -1, -1, -1, -1, -1, -1]; } + + if($this->data->exists("slot-count")){ + $this->slotCount = $this->data->get("slot-count"); + }else{ + $this->data->set("slot-count", $this->slotCount); + } + $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); $this->eid = $this->entity->eid; $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); @@ -1786,7 +1794,16 @@ class Player{ if($this->server->handle("player.equipment.change", $data) !== false){ $this->slot = $packet->slot; if(($this->gamemode & 0x01) === SURVIVAL){ - if(!in_array($this->slot, $this->hotbar)){ + + $has = false; + for($i = 0; $i < $this->slotCount; ++$i){ + if($this->slot == $this->hotbar[$i]){ + $has = true; + break; + } + } + + if(!$has){ array_pop($this->hotbar); array_unshift($this->hotbar, $this->slot); }