mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Independient Player gamemode, saved between sessions, set it via /gamemode
This commit is contained in:
parent
49d2723806
commit
3ba56c3e81
@ -92,15 +92,6 @@ class ConsoleAPI{
|
|||||||
$output .= "Stopping the server\n";
|
$output .= "Stopping the server\n";
|
||||||
$this->server->close();
|
$this->server->close();
|
||||||
break;
|
break;
|
||||||
case "gamemode":
|
|
||||||
$s = trim(array_shift($params));
|
|
||||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1 and ((int) $s) !== 2)){
|
|
||||||
$output .= "Usage: /gamemode <0 | 1 | 2>\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$this->server->api->setProperty("gamemode", (int) $s);
|
|
||||||
$output .= "Gamemode changed to ".$this->server->getGamemode()."\n";
|
|
||||||
break;
|
|
||||||
case "difficulty":
|
case "difficulty":
|
||||||
$s = trim(array_shift($params));
|
$s = trim(array_shift($params));
|
||||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
||||||
@ -126,7 +117,6 @@ class ConsoleAPI{
|
|||||||
case "?":
|
case "?":
|
||||||
$output .= "/help: Show available commands\n";
|
$output .= "/help: Show available commands\n";
|
||||||
$output .= "/status: Show server TPS and memory usage\n";
|
$output .= "/status: Show server TPS and memory usage\n";
|
||||||
$output .= "/gamemode: Changes default gamemode\n";
|
|
||||||
$output .= "/difficulty: Changes difficulty\n";
|
$output .= "/difficulty: Changes difficulty\n";
|
||||||
$output .= "/invisible: Manages server visibility\n";
|
$output .= "/invisible: Manages server visibility\n";
|
||||||
$output .= "/say: Broadcasts mesages\n";
|
$output .= "/say: Broadcasts mesages\n";
|
||||||
|
@ -37,6 +37,7 @@ class PlayerAPI{
|
|||||||
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
|
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler"));
|
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("harm", "Harms a player", array($this, "commandHandler"));
|
$this->server->api->console->register("harm", "Harms a player", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("gamemode", "Changes the player gamemode", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
||||||
$this->server->api->console->alias("suicide", "kill");
|
$this->server->api->console->alias("suicide", "kill");
|
||||||
@ -113,6 +114,26 @@ class PlayerAPI{
|
|||||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
$output = "";
|
$output = "";
|
||||||
switch($cmd){
|
switch($cmd){
|
||||||
|
case "gamemode":
|
||||||
|
$gm = -1;
|
||||||
|
$player = false;
|
||||||
|
if(!isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
|
||||||
|
$player = $issuer;
|
||||||
|
$gm = (int) $params[1];
|
||||||
|
}elseif(isset($params[1]) and isset($params[0])){
|
||||||
|
$player = $this->server->api->player->get($params[0]);
|
||||||
|
$gm = (int) $params[1];
|
||||||
|
}
|
||||||
|
if(!($player instanceof Player) or $gm < 0 or $gm > 2){
|
||||||
|
$output .= "Usage: /gamemode [player] <0 | 1 | 2>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($player->setGamemode($gm)){
|
||||||
|
$output .= "Gamemode of ".$player->username." changed to ".$player->getGamemode()."\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "tp":
|
case "tp":
|
||||||
if(!isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
|
if(!isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
|
||||||
$name = $issuer->username;
|
$name = $issuer->username;
|
||||||
@ -248,6 +269,7 @@ class PlayerAPI{
|
|||||||
$player = $this->server->clients[$CID];
|
$player = $this->server->clients[$CID];
|
||||||
console("[INFO] Player \"\x1b[33m".$player->username."\x1b[0m\" connected from \x1b[36m".$player->ip.":".$player->port."\x1b[0m");
|
console("[INFO] Player \"\x1b[33m".$player->username."\x1b[0m\" connected from \x1b[36m".$player->ip.":".$player->port."\x1b[0m");
|
||||||
$player->data = $this->getOffline($player->username);
|
$player->data = $this->getOffline($player->username);
|
||||||
|
$player->gamemode = $player->data->get("gamemode");
|
||||||
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');");
|
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,6 +304,7 @@ class PlayerAPI{
|
|||||||
),
|
),
|
||||||
"inventory" => array_fill(0, 36, array(AIR, 0, 0)),
|
"inventory" => array_fill(0, 36, array(AIR, 0, 0)),
|
||||||
"armor" => array_fill(0, 4, array(AIR, 0, 0)),
|
"armor" => array_fill(0, 4, array(AIR, 0, 0)),
|
||||||
|
"gamemode" => $this->server->gamemode,
|
||||||
"health" => 20,
|
"health" => 20,
|
||||||
"lastIP" => "",
|
"lastIP" => "",
|
||||||
"lastID" => 0,
|
"lastID" => 0,
|
||||||
@ -291,15 +314,15 @@ class PlayerAPI{
|
|||||||
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
|
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
|
||||||
$data->save();
|
$data->save();
|
||||||
}
|
}
|
||||||
if($this->server->gamemode === 1){
|
if($this->server->gamemode === CREATIVE){
|
||||||
$data->set("health", 20);
|
$data->set("health", 20);
|
||||||
}
|
}
|
||||||
$this->server->handle("api.player.offline.get", $data);
|
$this->server->handle("player.offline.get", $data);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveOffline(Config $data){
|
public function saveOffline(Config $data){
|
||||||
$this->server->handle("api.player.offline.save", $data);
|
$this->server->handle("player.offline.save", $data);
|
||||||
$data->save();
|
$data->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,6 +31,8 @@ class Deprecation{
|
|||||||
"world.block.change" => "block.change",
|
"world.block.change" => "block.change",
|
||||||
"block.drop" => "item.drop",
|
"block.drop" => "item.drop",
|
||||||
"api.op.check" => "op.check",
|
"api.op.check" => "op.check",
|
||||||
|
"api.player.offline.get" => "player.offline.get",
|
||||||
|
"api.player.offline.save" => "player.offline.save",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,6 +188,7 @@ class Player{
|
|||||||
));
|
));
|
||||||
$this->data->set("inventory", $this->inventory);
|
$this->data->set("inventory", $this->inventory);
|
||||||
$this->data->set("armor", $this->armor);
|
$this->data->set("armor", $this->armor);
|
||||||
|
$this->data->set("gamemode", $this->gamemode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,6 +492,34 @@ class Player{
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGamemode(){
|
||||||
|
switch($this->gamemode){
|
||||||
|
case SURVIVAL:
|
||||||
|
return "survival";
|
||||||
|
case CREATIVE:
|
||||||
|
return "creative";
|
||||||
|
case ADVENTURE:
|
||||||
|
return "adventure";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGamemode($gm){
|
||||||
|
if($gm < 0 or $gm > 2 or $this->gamemode === $gm){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($this->gamemode === SURVIVAL and $gm === ADVENTURE) or ($this->gamemode === ADVENTURE and $gm === SURVIVAL)){
|
||||||
|
$this->gamemode = $gm;
|
||||||
|
$this->sendSettings();
|
||||||
|
$this->eventHandler("Your gamemode has been changed to ".$this->getGamemode()."..", "server.chat");
|
||||||
|
}else{
|
||||||
|
$this->gamemode = $gm;
|
||||||
|
$this->eventHandler("Your gamemode has been changed to ".$this->getGamemode().", you've to do a forced reconnect.", "server.chat");
|
||||||
|
$this->server->schedule(30, array($this, "close")); //Forces a kick
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function handle($pid, $data){
|
public function handle($pid, $data){
|
||||||
if($this->connected === true){
|
if($this->connected === true){
|
||||||
$this->timeout = microtime(true) + 20;
|
$this->timeout = microtime(true) + 20;
|
||||||
@ -610,7 +639,7 @@ class Player{
|
|||||||
$this->close("bad username", false);
|
$this->close("bad username", false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$o = $this->server->api->player->getOffline($this->username);
|
|
||||||
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
|
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
|
||||||
$this->close("\"\x1b[33m".$this->username."\x1b[0m\" not being on white-list", false);
|
$this->close("\"\x1b[33m".$this->username."\x1b[0m\" not being on white-list", false);
|
||||||
break;
|
break;
|
||||||
@ -622,12 +651,12 @@ class Player{
|
|||||||
$u->close("logged in from another location");
|
$u->close("logged in from another location");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->server->api->player->add($this->CID);
|
||||||
if($this->server->api->handle("player.join", $this) === false){
|
if($this->server->api->handle("player.join", $this) === false){
|
||||||
$this->close();
|
$this->close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->api->player->add($this->CID);
|
|
||||||
$this->auth = true;
|
$this->auth = true;
|
||||||
if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){
|
if(!$this->data->exists("inventory") or $this->gamemode === CREATIVE){
|
||||||
$this->data->set("inventory", $this->inventory);
|
$this->data->set("inventory", $this->inventory);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user