mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
Added multiple Player events using the new system
This commit is contained in:
parent
279472b01a
commit
68abafef7a
@ -99,7 +99,7 @@ abstract class Achievement{
|
||||
public static function broadcast(Player $player, $achievementId){
|
||||
if(isset(Achievement::$list[$achievementId])){
|
||||
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
|
||||
ServerAPI::request()->api->chat->broadcast($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
|
||||
Player::broadcastChat($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]);
|
||||
}else{
|
||||
$player->sendChat("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]);
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ class BanAPI{
|
||||
$this->ops->set(strtolower($player->getUsername()));
|
||||
$this->ops->save();
|
||||
$output .= $player->getUsername() . " is now op\n";
|
||||
$this->server->api->chat->sendTo(false, "You are now op.", $player->getUsername());
|
||||
$player->sendChat("You are now op.");
|
||||
break;
|
||||
case "deop":
|
||||
$user = strtolower($params[0]);
|
||||
@ -180,7 +180,7 @@ class BanAPI{
|
||||
$this->ops->remove(strtolower($player->getUsername()));
|
||||
$this->ops->save();
|
||||
$output .= $player->getUsername() . " is no longer op\n";
|
||||
$this->server->api->chat->sendTo(false, "You are no longer op.", $player->getUsername());
|
||||
$player->sendChat("You are no longer op.");
|
||||
break;
|
||||
case "kick":
|
||||
if(!isset($params[0])){
|
||||
@ -197,9 +197,9 @@ class BanAPI{
|
||||
$this->server->schedule(60, array($player, "close"), "You have been kicked: " . $reason); //Forces a kick
|
||||
$player->blocked = true;
|
||||
if($issuer instanceof Player){
|
||||
$this->server->api->chat->broadcast($player->getUsername() . " has been kicked by " . $issuer->getUsername() . ": $reason\n");
|
||||
Player::broadcastChat($player->getUsername() . " has been kicked by " . $issuer->getUsername() . ": $reason\n");
|
||||
} else{
|
||||
$this->server->api->chat->broadcast($player->getUsername() . " has been kicked: $reason\n");
|
||||
Player::broadcastChat($player->getUsername() . " has been kicked: $reason\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -258,7 +258,7 @@ class BanAPI{
|
||||
$player = Player::get($ip);
|
||||
if($player instanceof Player){
|
||||
$ip = $player->getIP();
|
||||
$player->close("banned");
|
||||
$player->kick("You are banned");
|
||||
}
|
||||
$this->bannedIPs->set($ip);
|
||||
$this->bannedIPs->save();
|
||||
@ -292,12 +292,12 @@ class BanAPI{
|
||||
$this->banned->save();
|
||||
$player = Player::get($user);
|
||||
if($player !== false){
|
||||
$player->close("You have been banned");
|
||||
$player->kick("You are banned");
|
||||
}
|
||||
if($issuer instanceof Player){
|
||||
$this->server->api->chat->broadcast($user . " has been banned by " . $issuer->getUsername() . "\n");
|
||||
Player::broadcastChat($user . " has been banned by " . $issuer->getUsername() . "\n");
|
||||
} else{
|
||||
$this->server->api->chat->broadcast($user . " has been banned\n");
|
||||
Player::broadcastChat($user . " has been banned\n");
|
||||
}
|
||||
$this->kick($user, "Banned");
|
||||
$output .= "Player \"$user\" added to ban list\n";
|
||||
|
@ -55,7 +55,7 @@ class ChatAPI{
|
||||
break;
|
||||
}
|
||||
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
|
||||
$this->server->api->chat->broadcast("[$sender] " . $s);
|
||||
Player::broadcastChat("[$sender] " . $s);
|
||||
break;
|
||||
case "me":
|
||||
if(!($issuer instanceof Player)){
|
||||
@ -67,7 +67,7 @@ class ChatAPI{
|
||||
} else{
|
||||
$sender = $issuer->getUsername();
|
||||
}
|
||||
$this->broadcast("* $sender " . implode(" ", $params));
|
||||
Player::broadcastChat("* $sender " . implode(" ", $params));
|
||||
break;
|
||||
case "tell":
|
||||
if(!isset($params[0]) or !isset($params[1])){
|
||||
@ -77,25 +77,23 @@ class ChatAPI{
|
||||
if(!($issuer instanceof Player)){
|
||||
$sender = ucfirst($issuer);
|
||||
} else{
|
||||
$sender = $issuer->getUsername();
|
||||
$sender = $issuer;
|
||||
}
|
||||
$n = array_shift($params);
|
||||
$target = Player::get($n);
|
||||
if($target instanceof Player){
|
||||
$target = $target->getUsername();
|
||||
} else{
|
||||
if(!($target instanceof Player)){
|
||||
$target = strtolower($n);
|
||||
if($target === "server" or $target === "console" or $target === "rcon"){
|
||||
$target = "Console";
|
||||
}
|
||||
}
|
||||
$mes = implode(" ", $params);
|
||||
$output .= "[me -> " . $target . "] " . $mes . "\n";
|
||||
if($target !== "Console" and $target !== "Rcon"){
|
||||
$this->sendTo(false, "[" . $sender . " -> me] " . $mes, $target);
|
||||
$output .= "[me -> " . ($target instanceof Player ? $target->getUsername() : $target) . "] " . $mes . "\n";
|
||||
if($target instanceof Player){
|
||||
$target->sendChat("[" . ($sender instanceof Player ? $sender->getUsername() : $sender) . " -> me] " . $mes);
|
||||
}
|
||||
if($target === "Console" or $sender === "Console"){
|
||||
console("[INFO] [" . $sender . " -> " . $target . "] " . $mes);
|
||||
console("[INFO] [" . ($sender instanceof Player ? $sender->getUsername() : $sender) . " -> " . ($target instanceof Player ? $target->getUsername() : $target) . "] " . $mes);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -103,51 +101,4 @@ class ChatAPI{
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function broadcast($message){
|
||||
$this->send(false, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $owner
|
||||
* @param string $text
|
||||
* @param mixed $player Can be either Player object or string username. Boolean false for broadcast.
|
||||
*/
|
||||
public function sendTo($owner, $text, $player){
|
||||
$this->send($owner, $text, array($player));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $owner Can be either Player object or string username. Boolean false for broadcast.
|
||||
* @param string $text
|
||||
* @param $whitelist
|
||||
* @param $blacklist
|
||||
*/
|
||||
public function send($owner, $text, $whitelist = false, $blacklist = false){
|
||||
$message = array(
|
||||
"player" => $owner,
|
||||
"message" => $text,
|
||||
);
|
||||
if($owner !== false){
|
||||
if($owner instanceof Player){
|
||||
if($whitelist === false){
|
||||
console("[INFO] <" . $owner->getUsername() . "> " . $text);
|
||||
}
|
||||
} else{
|
||||
if($whitelist === false){
|
||||
console("[INFO] <" . $owner . "> " . $text);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
if($whitelist === false){
|
||||
console("[INFO] $text");
|
||||
}
|
||||
$message["player"] = "";
|
||||
}
|
||||
|
||||
//TODO: Remove Container
|
||||
$this->server->handle("server.chat", new Container($message, $whitelist, $blacklist));
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine;
|
||||
|
||||
use PocketMine;
|
||||
|
||||
class Container{
|
||||
private $payload = "", $whitelist = false, $blacklist = false;
|
||||
|
||||
public function __construct($payload = "", $whitelist = false, $blacklist = false){
|
||||
$this->payload = $payload;
|
||||
if(is_array($whitelist)){
|
||||
$this->whitelist = $whitelist;
|
||||
}
|
||||
if(is_array($blacklist)){
|
||||
$this->blacklist = $blacklist;
|
||||
}
|
||||
}
|
||||
|
||||
public function get(){
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
public function check($target){
|
||||
$w = true;
|
||||
$b = false;
|
||||
if($this->whitelist !== false){
|
||||
$w = false;
|
||||
if(in_array($target, $this->whitelist, true)){
|
||||
$w = true;
|
||||
}
|
||||
} else{
|
||||
$w = true;
|
||||
}
|
||||
if($this->blacklist !== false){
|
||||
$b = false;
|
||||
if(in_array($target, $this->blacklist, true)){
|
||||
$b = true;
|
||||
}
|
||||
} else{
|
||||
$b = false;
|
||||
}
|
||||
if($w === false or $b === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function __toString(){
|
||||
return $this->payload;
|
||||
}
|
||||
}
|
@ -168,6 +168,9 @@ class Player extends RealHuman{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public static function getAll(){
|
||||
return Player::$list;
|
||||
}
|
||||
@ -271,13 +274,10 @@ class Player extends RealHuman{
|
||||
$nbt->readCompressed(file_get_contents(\PocketMine\DATA . "players/" . $iname . ".dat"));
|
||||
$nbt = $nbt->getData();
|
||||
}
|
||||
|
||||
$server->handle("player.offline.get", $nbt);
|
||||
return $nbt;
|
||||
}
|
||||
|
||||
public static function saveOffline($name, Compound $nbtTag){
|
||||
ServerAPI::request()->handle("player.offline.save", $nbtTag);
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setData($nbtTag);
|
||||
file_put_contents(\PocketMine\DATA . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
||||
@ -580,20 +580,35 @@ class Player extends RealHuman{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reason Reason for closing connection
|
||||
* @param boolean $msg Set to false to silently disconnect player. No broadcast.
|
||||
* Kicks a player from the server
|
||||
*
|
||||
* @param string $reason
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function close($reason = "", $msg = true){
|
||||
public function kick($reason = ""){
|
||||
if(EventHandler::callEvent($ev = new Event\Player\PlayerKickEvent($this, $reason, "Kicked player " . $this->username . "." . ($reason !== "" ? " With reason: $reason" : ""))) !== Event\Event::DENY){
|
||||
$this->sendChat("You have been kicked. " . ($reason !== "" ? " Reason: $reason" : "") . "\n");
|
||||
$this->close($ev->getQuitMessage(), $reason);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $message Message to be broadcasted
|
||||
* @param string $reason Reason showed in console
|
||||
*/
|
||||
public function close($message = "", $reason = "generic reason"){
|
||||
if($this->connected === true){
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev);
|
||||
}
|
||||
if($this->username != ""){
|
||||
$this->server->api->handle("player.quit", $this);
|
||||
EventHandler::callEvent($ev = new Event\Player\PlayerQuitEvent($this, $message));
|
||||
$this->save();
|
||||
}
|
||||
$reason = $reason == "" ? "server stop" : $reason;
|
||||
$this->sendChat("You have been kicked. Reason: " . $reason . "\n");
|
||||
|
||||
$this->sendBuffer();
|
||||
$this->directDataPacket(new DisconnectPacket);
|
||||
unset(Player::$list[$this->CID]);
|
||||
@ -607,8 +622,8 @@ class Player extends RealHuman{
|
||||
if($this->username != "" and ($this->namedtag instanceof Compound)){
|
||||
Player::saveOffline($this->username, $this->namedtag);
|
||||
}
|
||||
if($msg === true and $this->username != "" and $this->spawned !== false){
|
||||
$this->server->api->chat->broadcast($this->username . " left the game");
|
||||
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
|
||||
Player::broadcastChat($ev->getQuitMessage());
|
||||
}
|
||||
$this->spawned = false;
|
||||
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason);
|
||||
@ -796,26 +811,33 @@ class Player extends RealHuman{
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
break;
|
||||
case "server.chat":
|
||||
if(($data instanceof Container) === true){
|
||||
if(!$data->check($this->username) and !$data->check($this->iusername)){
|
||||
return;
|
||||
} else{
|
||||
$message = $data->get();
|
||||
$this->sendChat($message["message"], $message["player"]);
|
||||
}
|
||||
} else{
|
||||
$this->sendChat((string) $data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function broadcastChat($message){
|
||||
foreach(self::getAll() as $p){
|
||||
$p->sendChat($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $author
|
||||
* Sends a message to a group of players
|
||||
*
|
||||
* @param string $message
|
||||
* @param Player[] $players
|
||||
*/
|
||||
public function sendChat($message, $author = ""){
|
||||
public static function groupChat($message, array $players){
|
||||
foreach($players as $p){
|
||||
$p->sendChat($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a direct chat message to a player
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function sendChat($message){
|
||||
$mes = explode("\n", $message);
|
||||
foreach($mes as $m){
|
||||
if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0){
|
||||
@ -838,7 +860,7 @@ class Player extends RealHuman{
|
||||
|
||||
if($m !== ""){
|
||||
$pk = new MessagePacket;
|
||||
$pk->source = ($author instanceof Player) ? $author->username : $author;
|
||||
$pk->author = ""; //Do not use this ;)
|
||||
$pk->message = TextFormat::clean($m); //Colors not implemented :(
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
@ -1021,7 +1043,7 @@ class Player extends RealHuman{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->server->api->dhandle("player.gamemode.change", array("player" => $this, "gamemode" => $gm)) === false){
|
||||
if(EventHandler::callEvent(new Event\Player\PlayerGameModeChangeEvent((int) $gm)) === Event\Event::DENY){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1092,7 +1114,7 @@ class Player extends RealHuman{
|
||||
}
|
||||
$time = microtime(true);
|
||||
if($time > $this->timeout){
|
||||
$this->close("timeout");
|
||||
$this->close($this->username . " has left the game", "timeout");
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1246,7 +1268,7 @@ class Player extends RealHuman{
|
||||
$this->directDataPacket($pk);
|
||||
break;
|
||||
case ProtocolInfo::DISCONNECT_PACKET:
|
||||
$this->close("client disconnect");
|
||||
$this->close($this->username . " has left the game", "client disconnect");
|
||||
break;
|
||||
case ProtocolInfo::CLIENT_CONNECT_PACKET:
|
||||
if($this->loggedIn === true){
|
||||
@ -1271,7 +1293,7 @@ class Player extends RealHuman{
|
||||
$this->iusername = strtolower($this->username);
|
||||
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
|
||||
if(count(Player::$list) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
|
||||
$this->close("server is full!", false);
|
||||
$this->kick("server full");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1285,27 +1307,28 @@ class Player extends RealHuman{
|
||||
$pk->status = 2;
|
||||
$this->directDataPacket($pk);
|
||||
}
|
||||
$this->close("Incorrect protocol #" . $packet->protocol1, false);
|
||||
$this->close("", "Incorrect protocol #" . $packet->protocol1, false);
|
||||
|
||||
return;
|
||||
}
|
||||
if(preg_match('#^[a-zA-Z0-9_]{3,16}$#', $this->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){
|
||||
$this->close("Bad username", false);
|
||||
$this->close("", "Bad username");
|
||||
|
||||
return;
|
||||
}
|
||||
if($this->server->api->handle("player.connect", $this) === false){
|
||||
$this->close("Unknown reason", false);
|
||||
|
||||
if(EventHandler::callEvent($ev = new Event\Player\PlayerPreLoginEvent($this, "Plugin reason")) === Event\Event::DENY){
|
||||
$this->close($ev->getKickMessage(), "Plugin reason");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){
|
||||
$this->close("Server is white-listed", false);
|
||||
$this->close($this->username . " has left the game", "Server is white-listed");
|
||||
|
||||
return;
|
||||
} elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){
|
||||
$this->close("You are banned!", false);
|
||||
$this->close($this->username . " has left the game", "You are banned");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1315,7 +1338,7 @@ class Player extends RealHuman{
|
||||
if(count($u) > 0){
|
||||
foreach($u as $p){
|
||||
if($p !== $this){
|
||||
$p->close("logged in from another location");
|
||||
$p->close($p->getUsername() . " has left the game", "logged in from another location");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1335,14 +1358,8 @@ class Player extends RealHuman{
|
||||
$nbt["Pos"][2] = $this->level->getSpawn()->z;
|
||||
}
|
||||
|
||||
if($this->server->api->handle("player.join", $this) === false){
|
||||
$this->close("join cancelled", false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!($nbt instanceof Compound)){
|
||||
$this->close("no config created", false);
|
||||
$this->close($this->username . " has left the game", "invalid data");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1355,10 +1372,6 @@ class Player extends RealHuman{
|
||||
Player::saveOffline($this->username, $nbt);
|
||||
$this->auth = true;
|
||||
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 0;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
parent::__construct($this->level, $nbt);
|
||||
|
||||
if(($this->gamemode & 0x01) === 0x01){
|
||||
@ -1368,6 +1381,16 @@ class Player extends RealHuman{
|
||||
$this->slot = $this->hotbar[0];
|
||||
}
|
||||
|
||||
if(EventHandler::callEvent($ev = new Event\Player\PlayerLoginEvent($this, "Plugin reason")) === Event\Event::DENY){
|
||||
$this->close($ev->getKickMessage(), "Plugin reason");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 0;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new StartGamePacket;
|
||||
$pk->seed = $this->level->getSeed();
|
||||
$pk->x = $this->x;
|
||||
@ -1389,7 +1412,6 @@ class Player extends RealHuman{
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
|
||||
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.event", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.metadata", array($this, "eventHandler"));
|
||||
@ -1399,6 +1421,9 @@ class Player extends RealHuman{
|
||||
$this->lastMeasure = microtime(true);
|
||||
$this->server->schedule(50, array($this, "measureLag"), array(), true);
|
||||
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
|
||||
|
||||
EventHandler::callEvent(new Event\Player\PlayerJoinEvent($this, $this->username . " joined the game"));
|
||||
|
||||
break;
|
||||
case ProtocolInfo::READY_PACKET:
|
||||
if($this->loggedIn === false){
|
||||
@ -1950,13 +1975,9 @@ class Player extends RealHuman{
|
||||
if($message{0} === "/"){ //Command
|
||||
$this->server->api->console->run(substr($message, 1), $this);
|
||||
} else{
|
||||
$data = array("player" => $this, "message" => $message);
|
||||
if($this->server->api->handle("player.chat", $data) !== false){
|
||||
if(isset($data["message"])){
|
||||
$this->server->api->chat->send($this, $data["message"]);
|
||||
} else{
|
||||
$this->server->api->chat->send($this, $message);
|
||||
}
|
||||
$ev = new Event\Player\PlayerChatEvent($this, $message);
|
||||
if(EventHandler::callEvent($ev) !== Event\Event::DENY){
|
||||
Player::groupChat(sprintf($ev->getFormat(), $ev->getPlayer()->getUsername(), $ev->getMessage()), $ev->getRecipients());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class PlayerAPI{
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->server->api->chat->broadcast($data["player"]->getUsername() . $message);
|
||||
Player::broadcastChat($data["player"]->getUsername() . $message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class Server{
|
||||
}
|
||||
if(($this->api instanceof ServerAPI) === true){
|
||||
if(($this->api->chat instanceof ChatAPI) === true){
|
||||
$this->api->chat->broadcast("Stopping server...");
|
||||
Player::broadcastChat("Stopping server...");
|
||||
}
|
||||
}
|
||||
$this->stop = true;
|
||||
|
95
src/PocketMine/event/player/PlayerChatEvent.php
Normal file
95
src/PocketMine/event/player/PlayerChatEvent.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player chats something
|
||||
*/
|
||||
class PlayerChatEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
/**
|
||||
* @var Player[]
|
||||
*/
|
||||
protected $recipients = array();
|
||||
|
||||
public function __construct(Player $player, $message, $format = "<%s> %s", array $recipients = null){
|
||||
$this->player = $player;
|
||||
$this->message = $message;
|
||||
$this->format = $format;
|
||||
if($recipients === null){
|
||||
$this->recipients = Player::getAll();
|
||||
}else{
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
}
|
||||
|
||||
public function getMessage(){
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMessage($message){
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the player that is sending the message
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function setPlayer(Player $player){
|
||||
if($player instanceof Player){
|
||||
$this->player = $player;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormat(){
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
public function setFormat($format){
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
public function getRecipients(){
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
public function setRecipients(array $recipients){
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
}
|
49
src/PocketMine/event/player/PlayerGameModeChangeEvent.php
Normal file
49
src/PocketMine/event/player/PlayerGameModeChangeEvent.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player has its gamemode changed
|
||||
*/
|
||||
class PlayerGameModeChangeEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $gamemode;
|
||||
|
||||
public function __construct(Player $player, $newGamemode){
|
||||
$this->player = $player;
|
||||
$this->gamemode = (int) $gamemode;
|
||||
}
|
||||
|
||||
public function getNewGamemode(){
|
||||
return $this->gamemode;
|
||||
}
|
||||
|
||||
}
|
58
src/PocketMine/event/player/PlayerJoinEvent.php
Normal file
58
src/PocketMine/event/player/PlayerJoinEvent.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player joins the server, after sending all the spawn packets
|
||||
*/
|
||||
class PlayerJoinEvent extends PlayerEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $joinMessage;
|
||||
|
||||
public function __construct(Player $player, $joinMessage){
|
||||
$this->player = $player;
|
||||
$this->joinMessage = $joinMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the join message. This won't work on Minecraft: PE <= 0.8.1, since the join message is client-side
|
||||
* We'll see if Mojang adds this in Minecraft: PE 0.9.0 ^.^
|
||||
*
|
||||
* @param string $joinMessage
|
||||
*/
|
||||
public function setJoinMessage($joinMessage){
|
||||
$this->joinMessage = $joinMessage;
|
||||
}
|
||||
|
||||
public function getJoinMessage(){
|
||||
return $this->joinMessage;
|
||||
}
|
||||
|
||||
}
|
63
src/PocketMine/event/player/PlayerKickEvent.php
Normal file
63
src/PocketMine/event/player/PlayerKickEvent.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player leaves the server
|
||||
*/
|
||||
class PlayerKickEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $quitMessage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $reason;
|
||||
|
||||
public function __construct(Player $player, $reason, $quitMessage){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
public function getReason(){
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
public function setQuitMessage($quitMessage){
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
public function getQuitMessage(){
|
||||
return $this->quitMessage;
|
||||
}
|
||||
|
||||
}
|
53
src/PocketMine/event/player/PlayerLoginEvent.php
Normal file
53
src/PocketMine/event/player/PlayerLoginEvent.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player joins, after things have been correctly set up (you can change anything now)
|
||||
*/
|
||||
class PlayerLoginEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $kickMessage;
|
||||
|
||||
public function __construct(Player $player, $kickMessage){
|
||||
$this->player = $player;
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function setKickMessage($kickMessage){
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function getKickMessage(){
|
||||
return $this->kickMessage;
|
||||
}
|
||||
|
||||
}
|
53
src/PocketMine/event/player/PlayerPreLoginEvent.php
Normal file
53
src/PocketMine/event/player/PlayerPreLoginEvent.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine\Event\CancellableEvent;
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when the player logs in, before things have been set up
|
||||
*/
|
||||
class PlayerPreLoginEvent extends PlayerEvent implements CancellableEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $kickMessage;
|
||||
|
||||
public function __construct(Player $player, $kickMessage){
|
||||
$this->player = $player;
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function setKickMessage($kickMessage){
|
||||
$this->kickMessage = $kickMessage;
|
||||
}
|
||||
|
||||
public function getKickMessage(){
|
||||
return $this->kickMessage;
|
||||
}
|
||||
|
||||
}
|
52
src/PocketMine/event/player/PlayerQuitEvent.php
Normal file
52
src/PocketMine/event/player/PlayerQuitEvent.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Event\Player;
|
||||
|
||||
use PocketMine;
|
||||
use PocketMine\Player;
|
||||
|
||||
/**
|
||||
* Called when a player leaves the server
|
||||
*/
|
||||
class PlayerQuitEvent extends PlayerEvent{
|
||||
public static $handlers;
|
||||
public static $handlerPriority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $quitMessage;
|
||||
|
||||
public function __construct(Player $player, $quitMessage){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
public function setQuitMessage($quitMessage){
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
public function getQuitMessage(){
|
||||
return $this->quitMessage;
|
||||
}
|
||||
|
||||
}
|
@ -151,7 +151,7 @@ class Level{
|
||||
public static function loadLevel($name){
|
||||
if(self::get($name) !== false){
|
||||
return true;
|
||||
} elseif(self::levelExists($name) === false){
|
||||
}elseif(self::levelExists($name) === false){
|
||||
console("[NOTICE] Level \"" . $name . "\" not found");
|
||||
|
||||
return false;
|
||||
@ -291,10 +291,10 @@ class Level{
|
||||
|
||||
if($generator !== false and class_exists($generator)){
|
||||
$generator = new $generator($options);
|
||||
} else{
|
||||
}else{
|
||||
if(strtoupper(ServerAPI::request()->api->getProperty("level-type")) == "FLAT"){
|
||||
$generator = new Flat($options);
|
||||
} else{
|
||||
}else{
|
||||
$generator = new Normal($options);
|
||||
}
|
||||
}
|
||||
@ -323,7 +323,7 @@ class Level{
|
||||
if($level->import() === false){
|
||||
return false;
|
||||
}
|
||||
} else{
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -372,8 +372,8 @@ class Level{
|
||||
$this->save();
|
||||
foreach($this->getPlayers() as $player){
|
||||
if($this === self::getDefault()){
|
||||
$player->close("forced level unload");
|
||||
} else{
|
||||
$player->close($player->getUsername() . " has left the game", "forced level unload");
|
||||
}else{
|
||||
$player->teleport(Level::getDefault()->getSafeSpawn());
|
||||
}
|
||||
}
|
||||
@ -418,7 +418,7 @@ class Level{
|
||||
$now = microtime(true);
|
||||
if($this->stopTime == true){
|
||||
return;
|
||||
} else{
|
||||
}else{
|
||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||
}
|
||||
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
|
||||
@ -446,7 +446,7 @@ class Level{
|
||||
}
|
||||
if(count($this->changedBlocks[$index][$Y]) < 582){ //Optimal value, calculated using the relation between minichunks and single packets
|
||||
continue;
|
||||
} else{
|
||||
}else{
|
||||
foreach($this->players as $p){
|
||||
$p->setChunkIndex($index, $mini);
|
||||
}
|
||||
@ -608,7 +608,7 @@ class Level{
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getMetadata();
|
||||
Player::broadcastPacket($this->players, $pk);
|
||||
} elseif($direct === false){
|
||||
}elseif($direct === false){
|
||||
if(!($pos instanceof Position)){
|
||||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||
}
|
||||
@ -653,7 +653,7 @@ class Level{
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getMetadata();
|
||||
Player::broadcastPacket($this->players, $pk);
|
||||
} else{
|
||||
}else{
|
||||
$index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
@ -890,7 +890,7 @@ class Level{
|
||||
$index = LevelFormat::getIndex($X, $Z);
|
||||
if(isset($this->usedChunks[$index])){
|
||||
return true;
|
||||
} elseif($this->level->loadChunk($X, $Z) !== false){
|
||||
}elseif($this->level->loadChunk($X, $Z) !== false){
|
||||
$this->usedChunks[$index] = array();
|
||||
$this->chunkTiles[$index] = array();
|
||||
$this->chunkEntities[$index] = array();
|
||||
@ -1021,7 +1021,7 @@ class Level{
|
||||
$b = $this->getBlock($v->getSide(0));
|
||||
if($b === false){
|
||||
return $spawn;
|
||||
} elseif(!($b instanceof Air)){
|
||||
}elseif(!($b instanceof Air)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1031,7 +1031,7 @@ class Level{
|
||||
if($this->getBlock($v) instanceof Air){
|
||||
return new Position($x, $y, $z, $this);
|
||||
}
|
||||
} else{
|
||||
}else{
|
||||
++$y;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user