mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Moved Player-related classes to pocketmine\player namespace
This commit is contained in:
151
src/pocketmine/player/Achievement.php
Normal file
151
src/pocketmine/player/Achievement.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\player;
|
||||
|
||||
use pocketmine\lang\TranslationContainer;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
/**
|
||||
* Handles the achievement list and a bit more
|
||||
*/
|
||||
abstract class Achievement{
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
public static $list = [
|
||||
/*"openInventory" => array(
|
||||
"name" => "Taking Inventory",
|
||||
"requires" => [],
|
||||
),*/
|
||||
"mineWood" => [
|
||||
"name" => "Getting Wood",
|
||||
"requires" => [ //"openInventory",
|
||||
]
|
||||
],
|
||||
"buildWorkBench" => [
|
||||
"name" => "Benchmarking",
|
||||
"requires" => [
|
||||
"mineWood"
|
||||
]
|
||||
],
|
||||
"buildPickaxe" => [
|
||||
"name" => "Time to Mine!",
|
||||
"requires" => [
|
||||
"buildWorkBench"
|
||||
]
|
||||
],
|
||||
"buildFurnace" => [
|
||||
"name" => "Hot Topic",
|
||||
"requires" => [
|
||||
"buildPickaxe"
|
||||
]
|
||||
],
|
||||
"acquireIron" => [
|
||||
"name" => "Acquire hardware",
|
||||
"requires" => [
|
||||
"buildFurnace"
|
||||
]
|
||||
],
|
||||
"buildHoe" => [
|
||||
"name" => "Time to Farm!",
|
||||
"requires" => [
|
||||
"buildWorkBench"
|
||||
]
|
||||
],
|
||||
"makeBread" => [
|
||||
"name" => "Bake Bread",
|
||||
"requires" => [
|
||||
"buildHoe"
|
||||
]
|
||||
],
|
||||
"bakeCake" => [
|
||||
"name" => "The Lie",
|
||||
"requires" => [
|
||||
"buildHoe"
|
||||
]
|
||||
],
|
||||
"buildBetterPickaxe" => [
|
||||
"name" => "Getting an Upgrade",
|
||||
"requires" => [
|
||||
"buildPickaxe"
|
||||
]
|
||||
],
|
||||
"buildSword" => [
|
||||
"name" => "Time to Strike!",
|
||||
"requires" => [
|
||||
"buildWorkBench"
|
||||
]
|
||||
],
|
||||
"diamonds" => [
|
||||
"name" => "DIAMONDS!",
|
||||
"requires" => [
|
||||
"acquireIron"
|
||||
]
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @param string $achievementId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function broadcast(Player $player, string $achievementId) : bool{
|
||||
if(isset(Achievement::$list[$achievementId])){
|
||||
$translation = new TranslationContainer("chat.type.achievement", [$player->getDisplayName(), TextFormat::GREEN . Achievement::$list[$achievementId]["name"] . TextFormat::RESET]);
|
||||
if(Server::getInstance()->getConfigBool("announce-player-achievements", true)){
|
||||
Server::getInstance()->broadcastMessage($translation);
|
||||
}else{
|
||||
$player->sendMessage($translation);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $achievementId
|
||||
* @param string $achievementName
|
||||
* @param array $requires
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function add(string $achievementId, string $achievementName, array $requires = []) : bool{
|
||||
if(!isset(Achievement::$list[$achievementId])){
|
||||
Achievement::$list[$achievementId] = [
|
||||
"name" => $achievementName,
|
||||
"requires" => $requires
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
132
src/pocketmine/player/GameMode.php
Normal file
132
src/pocketmine/player/GameMode.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\player;
|
||||
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
* This must be regenerated whenever enum members are added, removed or changed.
|
||||
* @see EnumTrait::_generateMethodAnnotations()
|
||||
*
|
||||
* @method static self SURVIVAL()
|
||||
* @method static self CREATIVE()
|
||||
* @method static self ADVENTURE()
|
||||
* @method static self SPECTATOR()
|
||||
*/
|
||||
final class GameMode{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
register as Enum_register;
|
||||
fromString as Enum_fromString;
|
||||
}
|
||||
|
||||
/** @var self[] */
|
||||
protected static $aliasMap = [];
|
||||
/** @var self[] */
|
||||
protected static $magicNumberMap = [];
|
||||
|
||||
protected static function setup() : array{
|
||||
return [
|
||||
new self("survival", 0, "Survival", "gameMode.survival", ["s", "0"]),
|
||||
new self("creative", 1, "Creative", "gameMode.creative", ["c", "1"]),
|
||||
new self("adventure", 2, "Adventure", "gameMode.adventure", ["a", "2"]),
|
||||
new self("spectator", 3, "Spectator", "gameMode.spectator", ["v", "view", "3"])
|
||||
];
|
||||
}
|
||||
|
||||
protected static function register(self $member) : void{
|
||||
self::Enum_register($member);
|
||||
self::$magicNumberMap[$member->getMagicNumber()] = $member;
|
||||
foreach($member->getAliases() as $alias){
|
||||
self::$aliasMap[$alias] = $member;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromString(string $str) : self{
|
||||
self::checkInit();
|
||||
return self::$aliasMap[$str] ?? self::Enum_fromString($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $n
|
||||
*
|
||||
* @return GameMode
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromMagicNumber(int $n) : self{
|
||||
self::checkInit();
|
||||
if(!isset(self::$magicNumberMap[$n])){
|
||||
throw new \InvalidArgumentException("No " . self::class . " enum member matches magic number $n");
|
||||
}
|
||||
return self::$magicNumberMap[$n];
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
private $magicNumber;
|
||||
/** @var string */
|
||||
private $englishName;
|
||||
/** @var string */
|
||||
private $translationKey;
|
||||
/** @var string[] */
|
||||
private $aliases;
|
||||
|
||||
private function __construct(string $enumName, int $magicNumber, string $englishName, string $translationKey, array $aliases = []){
|
||||
$this->Enum___construct($enumName);
|
||||
$this->magicNumber = $magicNumber;
|
||||
$this->englishName = $englishName;
|
||||
$this->translationKey = $translationKey;
|
||||
$this->aliases = $aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMagicNumber() : int{
|
||||
return $this->magicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEnglishName() : string{
|
||||
return $this->englishName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTranslationKey() : string{
|
||||
return "%" . $this->translationKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAliases() : array{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
//TODO: ability sets per gamemode
|
||||
}
|
80
src/pocketmine/player/IPlayer.php
Normal file
80
src/pocketmine/player/IPlayer.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\player;
|
||||
|
||||
use pocketmine\permission\ServerOperator;
|
||||
|
||||
interface IPlayer extends ServerOperator{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isOnline() : bool;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isBanned() : bool;
|
||||
|
||||
/**
|
||||
* @param bool $banned
|
||||
*/
|
||||
public function setBanned(bool $banned) : void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isWhitelisted() : bool;
|
||||
|
||||
/**
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setWhitelisted(bool $value) : void;
|
||||
|
||||
/**
|
||||
* @return Player|null
|
||||
*/
|
||||
public function getPlayer() : ?Player;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getFirstPlayed() : ?int;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getLastPlayed() : ?int;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlayedBefore() : bool;
|
||||
|
||||
}
|
135
src/pocketmine/player/OfflinePlayer.php
Normal file
135
src/pocketmine/player/OfflinePlayer.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\player;
|
||||
|
||||
use pocketmine\metadata\Metadatable;
|
||||
use pocketmine\metadata\MetadataValue;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\Server;
|
||||
|
||||
class OfflinePlayer implements IPlayer, Metadatable{
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var Server */
|
||||
private $server;
|
||||
/** @var CompoundTag|null */
|
||||
private $namedtag = null;
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Server $server, string $name){
|
||||
$this->server = $server;
|
||||
$this->name = $name;
|
||||
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
|
||||
}
|
||||
|
||||
public function isOnline() : bool{
|
||||
return $this->getPlayer() !== null;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getServer(){
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
public function isOp() : bool{
|
||||
return $this->server->isOp($this->name);
|
||||
}
|
||||
|
||||
public function setOp(bool $value) : void{
|
||||
if($value === $this->isOp()){
|
||||
return;
|
||||
}
|
||||
|
||||
if($value){
|
||||
$this->server->addOp($this->name);
|
||||
}else{
|
||||
$this->server->removeOp($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
public function isBanned() : bool{
|
||||
return $this->server->getNameBans()->isBanned($this->name);
|
||||
}
|
||||
|
||||
public function setBanned(bool $banned) : void{
|
||||
if($banned){
|
||||
$this->server->getNameBans()->addBan($this->name, null, null, null);
|
||||
}else{
|
||||
$this->server->getNameBans()->remove($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
public function isWhitelisted() : bool{
|
||||
return $this->server->isWhitelisted($this->name);
|
||||
}
|
||||
|
||||
public function setWhitelisted(bool $value) : void{
|
||||
if($value){
|
||||
$this->server->addWhitelist($this->name);
|
||||
}else{
|
||||
$this->server->removeWhitelist($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPlayer() : ?Player{
|
||||
return $this->server->getPlayerExact($this->name);
|
||||
}
|
||||
|
||||
public function getFirstPlayed() : ?int{
|
||||
return ($this->namedtag !== null and $this->namedtag->hasTag("firstPlayed", LongTag::class)) ? $this->namedtag->getInt("firstPlayed") : null;
|
||||
}
|
||||
|
||||
public function getLastPlayed() : ?int{
|
||||
return ($this->namedtag !== null and $this->namedtag->hasTag("lastPlayed", LongTag::class)) ? $this->namedtag->getLong("lastPlayed") : null;
|
||||
}
|
||||
|
||||
public function hasPlayedBefore() : bool{
|
||||
return $this->namedtag !== null;
|
||||
}
|
||||
|
||||
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{
|
||||
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||
}
|
||||
|
||||
public function getMetadata(string $metadataKey){
|
||||
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
||||
}
|
||||
|
||||
public function hasMetadata(string $metadataKey) : bool{
|
||||
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
||||
}
|
||||
|
||||
public function removeMetadata(string $metadataKey, Plugin $owningPlugin) : void{
|
||||
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||
}
|
||||
}
|
2840
src/pocketmine/player/Player.php
Normal file
2840
src/pocketmine/player/Player.php
Normal file
File diff suppressed because it is too large
Load Diff
98
src/pocketmine/player/PlayerInfo.php
Normal file
98
src/pocketmine/player/PlayerInfo.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\player;
|
||||
|
||||
use pocketmine\entity\Skin;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
/**
|
||||
* Encapsulates data needed to create a player.
|
||||
*/
|
||||
class PlayerInfo{
|
||||
|
||||
/** @var string */
|
||||
private $username;
|
||||
/** @var UUID */
|
||||
private $uuid;
|
||||
/** @var Skin */
|
||||
private $skin;
|
||||
/** @var string */
|
||||
private $locale;
|
||||
/** @var string */
|
||||
private $xuid;
|
||||
/** @var int */
|
||||
private $clientId;
|
||||
|
||||
public function __construct(string $username, UUID $uuid, Skin $skin, string $locale, string $xuid, int $clientId){
|
||||
$this->username = TextFormat::clean($username);
|
||||
$this->uuid = $uuid;
|
||||
$this->skin = $skin;
|
||||
$this->locale = $locale;
|
||||
$this->xuid = $xuid;
|
||||
$this->clientId = $clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername() : string{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID
|
||||
*/
|
||||
public function getUuid() : UUID{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Skin
|
||||
*/
|
||||
public function getSkin() : Skin{
|
||||
return $this->skin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale() : string{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getXuid() : string{
|
||||
return $this->xuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getClientId() : int{
|
||||
return $this->clientId;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user