GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Player Class Reference

Public Member Functions

 linkHookToPlayer (FishingHook $entity)
 
 unlinkHookFromPlayer ()
 
 isFishing ()
 
 getFishingHook ()
 
 setFishingHook (FishingHook $entity=null)
 
 getDeviceModel ()
 
 getDeviceOS ()
 
 getItemInHand ()
 
 getLeaveMessage ()
 
 getClientId ()
 
 getClientSecret ()
 
 isBanned ()
 
 setBanned ($value)
 
 isWhitelisted ()
 
 setWhitelisted ($value)
 
 getPlayer ()
 
 getFirstPlayed ()
 
 getLastPlayed ()
 
 hasPlayedBefore ()
 
 setAllowFlight ($value)
 
 getAllowFlight ()
 
 setFlying (bool $value)
 
 isFlying ()
 
 setAutoJump ($value)
 
 hasAutoJump ()
 
 allowMovementCheats ()
 
 setAllowMovementCheats (bool $value=false)
 
 allowInstaBreak ()
 
 setAllowInstaBreak (bool $value=false)
 
 spawnTo (Player $player)
 
 getServer ()
 
 getRemoveFormat ()
 
 setRemoveFormat ($remove=true)
 
 canSee (Player $player)
 
 hidePlayer (Player $player)
 
 showPlayer (Player $player)
 
 canCollideWith (Entity $entity)
 
 resetFallDistance ()
 
 getViewDistance ()
 
 setViewDistance (int $distance)
 
 isOnline ()
 
 isOp ()
 
 setOp ($value)
 
 isPermissionSet ($name)
 
 hasPermission ($name)
 
 addAttachment (Plugin $plugin, $name=null, $value=null)
 
 removeAttachment (PermissionAttachment $attachment)
 
 recalculatePermissions ()
 
 getEffectivePermissions ()
 
 sendCommandData ()
 
 __construct (SourceInterface $interface, $clientID, $ip, $port)
 
 removeAchievement ($achievementId)
 
 hasAchievement ($achievementId)
 
 isConnected ()
 
 getDisplayName ()
 
 setDisplayName ($name)
 
 setSkin ($str, $skinId)
 
 getAddress ()
 
 getPort ()
 
 getNextPosition ()
 
 isSleeping ()
 
 getInAirTicks ()
 
 getSpawn ()
 
 hasValidSpawnPosition ()
 
 sendChunk ($x, $z, $payload)
 
 batchDataPacket (DataPacket $packet)
 
 dataPacket (DataPacket $packet, $needACK=false)
 
 directDataPacket (DataPacket $packet, $needACK=false)
 
 sleepOn (Vector3 $pos)
 
 setSpawn (Vector3 $pos)
 
 stopSleep ()
 
 awardAchievement ($achievementId)
 
 getGamemode ()
 
 setGamemode (int $gm, bool $client=false)
 
 sendGamemode ()
 
 sendSettings ()
 
 isSurvival ()
 
 isCreative ()
 
 isSpectator ()
 
 isAdventure ()
 
 isFireProof ()
 
 getDrops ()
 
 setDataProperty ($id, $type, $value)
 
 setMotion (Vector3 $mot)
 
 setMoving ($moving)
 
 isMoving ()
 
 sendAttributes (bool $sendAll=false)
 
 onUpdate ($currentTick)
 
 checkNetwork ()
 
 canInteract (Vector3 $pos, $maxDistance, $maxDiff=0.5)
 
 onPlayerPreLogin ()
 
 clearCreativeItems ()
 
 getCreativeItems ()
 
 addCreativeItem (Item $item)
 
 removeCreativeItem (Item $item)
 
 getCreativeItemIndex (Item $item)
 
 getProtocol ()
 
 kick ($reason="", $isAdmin=true)
 
 dropItem (Item $item)
 
 sendActionBar (string $title, string $subtitle="", int $fadeIn=-1, int $stay=-1, int $fadeOut=-1)
 
 addTitle (string $title, string $subtitle="", int $fadeIn=-1, int $stay=-1, int $fadeOut=-1)
 
 addActionBarMessage (string $message)
 
 removeTitles ()
 
 setTitleDuration (int $fadeIn, int $stay, int $fadeOut)
 
 transfer (string $address, $port)
 
 sendMessage ($message)
 
 sendTranslation ($message, array $parameters=[])
 
 sendPopup ($message, $subtitle="")
 
 sendTip ($message)
 
 sendTitle ($title, $subtitle="", $fadein=20, $fadeout=20, $duration=5)
 
 close ($message="", $reason="generic reason", $notify=true)
 
 __debugInfo ()
 
 save ($async=false)
 
 getName ()
 
 kill ()
 
 setHealth ($amount)
 
 attack ($damage, EntityDamageEvent $source)
 
 sendPosition (Vector3 $pos, $yaw=null, $pitch=null, $mode=MovePlayerPacket::MODE_NORMAL, array $targets=null)
 
 teleport (Vector3 $pos, $yaw=null, $pitch=null)
 
 teleportImmediate (Vector3 $pos, $yaw=null, $pitch=null)
 
 getWindowId (Inventory $inventory)
 
 addWindow (Inventory $inventory, $forceId=null)
 
 removeWindow (Inventory $inventory)
 
 setMetadata ($metadataKey, MetadataValue $metadataValue)
 
 getMetadata ($metadataKey)
 
 hasMetadata ($metadataKey)
 
 removeMetadata ($metadataKey, Plugin $plugin)
 
 onChunkChanged (Chunk $chunk)
 
 onChunkLoaded (Chunk $chunk)
 
 onChunkPopulated (Chunk $chunk)
 
 onChunkUnloaded (Chunk $chunk)
 
 onBlockChanged (Vector3 $block)
 
 getLoaderId ()
 
 isLoaderActive ()
 
 addEffect (Effect $effect)
 
- Public Member Functions inherited from Human
 getSkinData ()
 
 getSkinId ()
 
 getUniqueId ()
 
 getRawUniqueId ()
 
 setSkin ($str, $skinId)
 
 getFood ()
 
 setFood (float $new)
 
 getMaxFood ()
 
 addFood (float $amount)
 
 getSaturation ()
 
 setSaturation (float $saturation)
 
 addSaturation (float $amount)
 
 getExhaustion ()
 
 setExhaustion (float $exhaustion)
 
 exhaust (float $amount, int $cause=PlayerExhaustEvent::CAUSE_CUSTOM)
 
 getXpLevel ()
 
 setXpLevel (int $level)
 
 addXpLevel (int $level)
 
 takeXpLevel (int $level)
 
 getXpProgress ()
 
 setXpProgress (float $progress)
 
 getTotalXp ()
 
 setTotalXp (int $xp, bool $syncLevel=false)
 
 addXp (int $xp, bool $syncLevel=false)
 
 takeXp (int $xp, bool $syncLevel=false)
 
 getRemainderXp ()
 
 getFilledXp ()
 
 recalculateXpProgress ()
 
 getXpSeed ()
 
 resetXpCooldown ()
 
 canPickupXp ()
 
 getInventory ()
 
 getEnderChestInventory ()
 
 getFloatingInventory ()
 
 getTransactionQueue ()
 
 getAbsorption ()
 
 setAbsorption (int $absorption)
 
 entityBaseTick ($tickDiff=1, $EnchantL=0)
 
 getName ()
 
 getDrops ()
 
 saveNBT ()
 
 spawnTo (Player $player)
 
 close ()
 
- Public Member Functions inherited from Creature
 onUpdate ($tick)
 
 willMove ($distance=36)
 
 attack ($damage, EntityDamageEvent $source)
 
 ifjump (Level $level, Vector3 $v3, $hate=false, $reason=false)
 
 whatBlock (Level $level, $v3)
 
 getMyYaw ($mx, $mz)
 
 getMyPitch (Vector3 $from, Vector3 $to)
 
- Public Member Functions inherited from Living
 setHealth ($amount)
 
 saveNBT ()
 
 getName ()
 
 hasLineOfSight (Entity $entity)
 
 heal ($amount, EntityRegainHealthEvent $source)
 
 attack ($damage, EntityDamageEvent $source)
 
 knockBack (Entity $attacker, $damage, $x, $z, $base=0.4)
 
 kill ()
 
 entityBaseTick ($tickDiff=1, $EnchantL=0)
 
 getDrops ()
 
 getLineOfSight ($maxDistance, $maxLength=0, array $transparent=[])
 
 getTargetBlock ($maxDistance, array $transparent=[])
 
- Public Member Functions inherited from Entity
 __construct (Level $level, CompoundTag $nbt)
 
 getHeight ()
 
 getWidth ()
 
 getLength ()
 
 setScale ($scale)
 
 getScale ()
 
 getDropExpMin ()
 
 getDropExpMax ()
 
 getNameTag ()
 
 isNameTagVisible ()
 
 isNameTagAlwaysVisible ()
 
 setNameTag ($name)
 
 setNameTagVisible ($value=true)
 
 setNameTagAlwaysVisible ($value=true)
 
 isSneaking ()
 
 setSneaking ($value=true)
 
 isSprinting ()
 
 setSprinting ($value=true)
 
 isGliding ()
 
 setGliding ($value=true)
 
 isImmobile ()
 
 setImmobile ($value=true)
 
 canClimb ()
 
 setCanClimb (bool $value)
 
 canClimbWalls ()
 
 setCanClimbWalls (bool $value=true)
 
 getOwningEntityId ()
 
 getOwningEntity ()
 
 setOwningEntity (Entity $owner)
 
 getEffects ()
 
 removeAllEffects ()
 
 removeEffect ($effectId)
 
 getEffect ($effectId)
 
 hasEffect ($effectId)
 
 addEffect (Effect $effect)
 
 getSaveId ()
 
 saveNBT ()
 
 getViewers ()
 
 spawnTo (Player $player)
 
 sendPotionEffects (Player $player)
 
 sendData ($player, array $data=null)
 
 despawnFrom (Player $player, bool $send=true)
 
 attack ($damage, EntityDamageEvent $source)
 
 heal ($amount, EntityRegainHealthEvent $source)
 
 getHealth ()
 
 isAlive ()
 
 setHealth ($amount)
 
 setLastDamageCause (EntityDamageEvent $type)
 
 getLastDamageCause ()
 
 getAttributeMap ()
 
 getMaxHealth ()
 
 setMaxHealth ($amount)
 
 canCollideWith (Entity $entity)
 
 entityBaseTick ($tickDiff=1)
 
 getDirectionVector ()
 
 getDirectionPlane ()
 
 onUpdate ($currentTick)
 
 scheduleUpdate ()
 
 isOnFire ()
 
 setOnFire ($seconds)
 
 isFireProof ()
 
 getDirection ()
 
 extinguish ()
 
 canTriggerWalking ()
 
 resetFallDistance ()
 
 getBoundingBox ()
 
 fall ($fallDistance)
 
 handleLavaMovement ()
 
 getEyeHeight ()
 
 moveFlying ()
 
 onCollideWithPlayer (Human $entityPlayer)
 
 getPosition ()
 
 getLocation ()
 
 isInsideOfPortal ()
 
 isInsideOfWater ()
 
 isInsideOfSolid ()
 
 isInsideOfFire ()
 
 fastMove ($dx, $dy, $dz)
 
 move ($dx, $dy, $dz)
 
 getBlocksAround ()
 
 setPositionAndRotation (Vector3 $pos, $yaw, $pitch)
 
 setRotation ($yaw, $pitch)
 
 setLocation (Location $pos)
 
 setPosition (Vector3 $pos)
 
 getMotion ()
 
 setMotion (Vector3 $motion)
 
 isOnGround ()
 
 kill ()
 
 teleport (Vector3 $pos, $yaw=null, $pitch=null)
 
 getId ()
 
 respawnToAll ()
 
 spawnToAll ()
 
 despawnFromAll ()
 
 close ()
 
 setDataProperty ($id, $type, $value)
 
 linkEntity (Entity $entity)
 
 sendLinkedData ()
 
 setLinked ($type=0, Entity $entity)
 
 getLinkedEntity ()
 
 getLinkedType ()
 
 getDataProperty ($id)
 
 getDataPropertyType ($id)
 
 setDataFlag ($propertyId, $id, $value=true, $type=self::DATA_TYPE_LONG)
 
 getDataFlag ($propertyId, $id)
 
 __destruct ()
 
 setMetadata ($metadataKey, MetadataValue $metadataValue)
 
 getMetadata ($metadataKey)
 
 hasMetadata ($metadataKey)
 
 removeMetadata ($metadataKey, Plugin $plugin)
 
 __toString ()
 
- Public Member Functions inherited from Location
 __construct ($x=0, $y=0, $z=0, $yaw=0.0, $pitch=0.0, Level $level=null)
 
 asLocation ()
 
 add ($x, $y=0, $z=0, $yaw=0, $pitch=0)
 
 getYaw ()
 
 getPitch ()
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 
- Public Member Functions inherited from Position
 __construct ($x=0, $y=0, $z=0, Level $level=null)
 
 asPosition ()
 
 add ($x, $y=0, $z=0)
 
 getLevel ()
 
 setLevel (Level $level=null)
 
 isValid ()
 
 getSide ($side, $step=1)
 
 __toString ()
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
- Public Member Functions inherited from Vector3
 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 
- Public Member Functions inherited from ChunkLoader
 getPosition ()
 
 getX ()
 
 getZ ()
 
 getLevel ()
 

Static Public Member Functions

static getClientFriendlyGamemode (int $gamemode)
 
- Static Public Member Functions inherited from Human
static getTotalXpRequirement (int $level)
 
static getLevelXpRequirement (int $level)
 
static getLevelFromXp (int $xp)
 
- Static Public Member Functions inherited from Entity
static init ()
 
static createEntity ($type, Level $level, CompoundTag $nbt,... $args)
 
static registerEntity ($className, $force=false)
 
- Static Public Member Functions inherited from Location
static fromObject (Vector3 $pos, Level $level=null, $yaw=0.0, $pitch=0.0)
 
- Static Public Member Functions inherited from Position
static fromObject (Vector3 $pos, Level $level=null)
 
- Static Public Member Functions inherited from Vector3
static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 

Data Fields

const SURVIVAL = 0
 
const CREATIVE = 1
 
const ADVENTURE = 2
 
const SPECTATOR = 3
 
const VIEW = Player::SPECTATOR
 
const CRAFTING_SMALL = 0
 
const CRAFTING_BIG = 1
 
const CRAFTING_ANVIL = 2
 
const CRAFTING_ENCHANT = 3
 
 $playedBefore = false
 
 $spawned = false
 
 $loggedIn = false
 
 $gamemode
 
 $lastBreak
 
 $speed = null
 
 $achievements = []
 
 $craftingType = self::CRAFTING_SMALL
 
 $creationTime = 0
 
 $usedChunks = []
 
 $weatherData = [0, 0, 0]
 
 $fromPos = null
 
 $fishingHook = null
 
 $selectedPos = []
 
 $selectedLev = []
 
 $foodTick = 0
 
 $starvationTick = 0
 
 $foodUsageTime = 0
 
- Data Fields inherited from Human
const DATA_PLAYER_FLAG_SLEEP = 1
 
const DATA_PLAYER_FLAG_DEAD = 2
 
const DATA_PLAYER_FLAGS = 27
 
const DATA_PLAYER_BED_POSITION = 29
 
 $width = 0.6
 
 $length = 0.6
 
 $height = 1.8
 
 $eyeHeight = 1.62
 
- Data Fields inherited from Creature
 $attackingTick = 0
 
- Data Fields inherited from Entity
const NETWORK_ID = -1
 
const DATA_TYPE_BYTE = 0
 
const DATA_TYPE_SHORT = 1
 
const DATA_TYPE_INT = 2
 
const DATA_TYPE_FLOAT = 3
 
const DATA_TYPE_STRING = 4
 
const DATA_TYPE_SLOT = 5
 
const DATA_TYPE_POS = 6
 
const DATA_TYPE_LONG = 7
 
const DATA_TYPE_VECTOR3F = 8
 
const DATA_FLAGS = 0
 
const DATA_HEALTH = 1
 
const DATA_VARIANT = 2
 
const DATA_COLOR = 3
 
const DATA_COLOUR = 3
 
const DATA_NAMETAG = 4
 
const DATA_OWNER_EID = 5
 
const DATA_TARGET_EID = 6
 
const DATA_AIR = 7
 
const DATA_POTION_COLOR = 8
 
const DATA_POTION_AMBIENT = 9
 
const DATA_HURT_TIME = 11
 
const DATA_HURT_DIRECTION = 12
 
const DATA_PADDLE_TIME_LEFT = 13
 
const DATA_PADDLE_TIME_RIGHT = 14
 
const DATA_EXPERIENCE_VALUE = 15
 
const DATA_MINECART_DISPLAY_BLOCK = 16
 
const DATA_MINECART_DISPLAY_OFFSET = 17
 
const DATA_MINECART_HAS_DISPLAY = 18
 
const DATA_ENDERMAN_HELD_ITEM_ID = 23
 
const DATA_ENDERMAN_HELD_ITEM_DAMAGE = 24
 
const DATA_ENTITY_AGE = 25
 
const DATA_FIREBALL_POWER_X = 30
 
const DATA_FIREBALL_POWER_Y = 31
 
const DATA_FIREBALL_POWER_Z = 32
 
const DATA_POTION_AUX_VALUE = 37
 
const DATA_LEAD_HOLDER_EID = 38
 
const DATA_SCALE = 39
 
const DATA_INTERACTIVE_TAG = 40
 
const DATA_NPC_SKIN_ID = 41
 
const DATA_URL_TAG = 42
 
const DATA_MAX_AIR = 43
 
const DATA_MARK_VARIANT = 44
 
const DATA_BLOCK_TARGET = 48
 
const DATA_WITHER_INVULNERABLE_TICKS = 49
 
const DATA_WITHER_TARGET_1 = 50
 
const DATA_WITHER_TARGET_2 = 51
 
const DATA_WITHER_TARGET_3 = 52
 
const DATA_BOUNDING_BOX_WIDTH = 54
 
const DATA_BOUNDING_BOX_HEIGHT = 55
 
const DATA_FUSE_LENGTH = 56
 
const DATA_RIDER_SEAT_POSITION = 57
 
const DATA_RIDER_ROTATION_LOCKED = 58
 
const DATA_RIDER_MAX_ROTATION = 59
 
const DATA_RIDER_MIN_ROTATION = 60
 
const DATA_AREA_EFFECT_CLOUD_RADIUS = 61
 
const DATA_AREA_EFFECT_CLOUD_WAITING = 62
 
const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63
 
const DATA_SHULKER_ATTACH_FACE = 65
 
const DATA_SHULKER_ATTACH_POS = 67
 
const DATA_TRADING_PLAYER_EID = 68
 
const DATA_COMMAND_BLOCK_COMMAND = 71
 
const DATA_COMMAND_BLOCK_LAST_OUTPUT = 72
 
const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73
 
const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74
 
const DATA_STRENGTH = 75
 
const DATA_MAX_STRENGTH = 76
 
const DATA_FLAG_ONFIRE = 0
 
const DATA_FLAG_SNEAKING = 1
 
const DATA_FLAG_RIDING = 2
 
const DATA_FLAG_SPRINTING = 3
 
const DATA_FLAG_ACTION = 4
 
const DATA_FLAG_INVISIBLE = 5
 
const DATA_FLAG_TEMPTED = 6
 
const DATA_FLAG_INLOVE = 7
 
const DATA_FLAG_SADDLED = 8
 
const DATA_FLAG_POWERED = 9
 
const DATA_FLAG_IGNITED = 10
 
const DATA_FLAG_BABY = 11
 
const DATA_FLAG_CONVERTING = 12
 
const DATA_FLAG_CRITICAL = 13
 
const DATA_FLAG_CAN_SHOW_NAMETAG = 14
 
const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15
 
const DATA_FLAG_IMMOBILE = 16
 
const DATA_FLAG_NO_AI = 16
 
const DATA_FLAG_SILENT = 17
 
const DATA_FLAG_WALLCLIMBING = 18
 
const DATA_FLAG_CAN_CLIMB = 19
 
const DATA_FLAG_SWIMMER = 20
 
const DATA_FLAG_CAN_FLY = 21
 
const DATA_FLAG_RESTING = 22
 
const DATA_FLAG_SITTING = 23
 
const DATA_FLAG_ANGRY = 24
 
const DATA_FLAG_INTERESTED = 25
 
const DATA_FLAG_CHARGED = 26
 
const DATA_FLAG_TAMED = 27
 
const DATA_FLAG_LEASHED = 28
 
const DATA_FLAG_SHEARED = 29
 
const DATA_FLAG_GLIDING = 30
 
const DATA_FLAG_ELDER = 31
 
const DATA_FLAG_MOVING = 32
 
const DATA_FLAG_BREATHING = 33
 
const DATA_FLAG_CHESTED = 34
 
const DATA_FLAG_STACKABLE = 35
 
const DATA_FLAG_SHOWBASE = 36
 
const DATA_FLAG_REARING = 37
 
const DATA_FLAG_VIBRATING = 38
 
const DATA_FLAG_IDLING = 39
 
const DATA_FLAG_EVOKER_SPELL = 40
 
const DATA_FLAG_CHARGE_ATTACK = 41
 
const DATA_FLAG_LINGER = 45
 
const SOUTH = 0
 
const WEST = 1
 
const NORTH = 2
 
const EAST = 3
 
 $passenger = null
 
 $vehicle = null
 
 $chunk
 
 $lastX = null
 
 $lastY = null
 
 $lastZ = null
 
 $motionX
 
 $motionY
 
 $motionZ
 
 $temporalVector
 
 $lastMotionX
 
 $lastMotionY
 
 $lastMotionZ
 
 $lastYaw
 
 $lastPitch
 
 $boundingBox
 
 $onGround
 
 $inBlock = false
 
 $positionChanged
 
 $motionChanged
 
 $deadTicks = 0
 
 $height
 
 $eyeHeight = null
 
 $width
 
 $length
 
 $keepMovement = false
 
 $fallDistance = 0
 
 $ticksLived = 0
 
 $lastUpdate
 
 $maxFireTicks
 
 $fireTicks = 0
 
 $namedtag
 
 $canCollide = true
 
 $isCollided = false
 
 $isCollidedHorizontally = false
 
 $isCollidedVertically = false
 
 $noDamageTicks
 
 $closed = false
 
 $dropExp = [0, 0]
 
- Data Fields inherited from Location
 $yaw
 
 $pitch
 
- Data Fields inherited from Position
 $level = null
 
- Data Fields inherited from Vector3
const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 

Protected Member Functions

 switchLevel (Level $targetLevel)
 
 sendNextChunk ()
 
 doFirstSpawn ()
 
 orderChunks ()
 
 checkGroundState ($movX, $movY, $movZ, $dx, $dy, $dz)
 
 checkNearEntities ($tickDiff)
 
 processMovement ($tickDiff)
 
 updateMovement ()
 
 sendTitleText (string $title, int $type)
 
 checkTeleportPosition ()
 
- Protected Member Functions inherited from Human
 initEntity ()
 
 addAttributes ()
 
- Protected Member Functions inherited from Living
 initEntity ()
 
- Protected Member Functions inherited from Entity
 recalculateEffectColor ()
 
 initEntity ()
 
 addAttributes ()
 
 checkObstruction ($x, $y, $z)
 
 updateMovement ()
 
 updateFallState ($distanceThisTick, $onGround)
 
 switchLevel (Level $targetLevel)
 
 checkGroundState ($movX, $movY, $movZ, $dx, $dy, $dz)
 
 checkBlockCollision ()
 
 checkChunks ()
 

Protected Attributes

 $interface
 
 $windowCnt = 2
 
 $windows
 
 $windowIndex = []
 
 $messageCounter = 2
 
 $randomClientId
 
 $protocol
 
 $forceMovement = null
 
 $teleportPosition = null
 
 $connected = true
 
 $ip
 
 $removeFormat = false
 
 $port
 
 $username
 
 $iusername
 
 $displayName
 
 $startAction = -1
 
 $sleeping = null
 
 $clientID = null
 
 $deviceModel
 
 $deviceOS
 
 $stepHeight = 0.6
 
 $chunkLoadCount = 0
 
 $loadQueue = []
 
 $nextChunkOrderRun = 5
 
 $hiddenPlayers = []
 
 $newPosition
 
 $viewDistance = -1
 
 $chunksPerTick
 
 $spawnThreshold
 
 $inAirTicks = 0
 
 $startAirTicks = 5
 
 $autoJump = true
 
 $allowFlight = false
 
 $flying = false
 
 $allowMovementCheats = false
 
 $allowInstaBreak = false
 
 $shouldSendStatus = false
 
 $personalCreativeItems = []
 
 $lastEnderPearlUse = 0
 
 $moving = false
 
- Protected Attributes inherited from Human
 $inventory
 
 $enderChestInventory
 
 $floatingInventory
 
 $transactionQueue = null
 
 $uuid
 
 $rawUUID
 
 $skinId
 
 $skin
 
 $foodTickTimer = 0
 
 $totalXp = 0
 
 $xpSeed
 
 $xpCooldown = 0
 
- Protected Attributes inherited from Living
 $gravity = 0.08
 
 $drag = 0.02
 
 $attackTime = 0
 
 $invisible = false
 
- Protected Attributes inherited from Entity
 $hasSpawned = []
 
 $effects = []
 
 $id
 
 $dataFlags = 0
 
 $dataProperties
 
 $lastDamageCause = null
 
 $age = 0
 
 $ySize = 0
 
 $stepHeight = 0
 
 $isStatic = false
 
 $justCreated
 
 $attributeMap
 
 $gravity
 
 $drag
 
 $server
 
 $timings
 
 $isPlayer = false
 
 $linkedEntity = null
 
 $linkedType = null
 
 $riding = null
 
 $activatedPressurePlates = []
 

Additional Inherited Members

- Static Public Attributes inherited from Entity
static $entityCount = 1
 

Detailed Description

Main class that handles networking, recovery, and packet sending to the server part

Constructor & Destructor Documentation

◆ __construct()

__construct ( SourceInterface  $interface,
  $clientID,
  $ip,
  $port 
)
Parameters
SourceInterface$interface
null$clientID
string$ip
int$port
770  {
771  $this->interface = $interface;
772  $this->windows = new \SplObjectStorage();
773  $this->perm = new PermissibleBase($this);
774  $this->namedtag = new CompoundTag();
775  $this->server = Server::getInstance();
776  $this->lastBreak = PHP_INT_MAX;
777  $this->ip = $ip;
778  $this->port = $port;
779  $this->clientID = $clientID;
780  $this->loaderId = Level::generateChunkLoaderId($this);
781  $this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4);
782  $this->spawnThreshold = (int) (($this->server->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
783  $this->spawnPosition = null;
784  $this->gamemode = $this->server->getGamemode();
785  $this->setLevel($this->server->getDefaultLevel());
786  $this->newPosition = new Vector3(0, 0, 0);
787  $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
788 
789  $this->uuid = null;
790  $this->rawUUID = null;
791 
792  $this->creationTime = microtime(true);
793 
794  $this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false);
795  $this->allowInstaBreak = (bool) $this->server->getProperty("player.anti-cheat.allow-instabreak", false);
796  }

Member Function Documentation

◆ __debugInfo()

__debugInfo ( )
Returns
array
4096  {
4097  return [];
4098  }

◆ addActionBarMessage()

addActionBarMessage ( string  $message)

Adds small text to the user's screen.

Parameters
string$message
3824  {
3826  }

◆ addAttachment()

addAttachment ( Plugin  $plugin,
  $name = null,
  $value = null 
)
Parameters
Plugin$plugin
string$name
bool$value
Returns
permission|null

Implements Permissible.

698  {
699  if($this->perm == null) return null;
700  return $this->perm->addAttachment($plugin, $name, $value);
701  }

◆ addCreativeItem()

addCreativeItem ( Item  $item)
Parameters
Item$item
2150  {
2151  $this->personalCreativeItems[] = Item::get($item->getId(), $item->getDamage());
2152  }

◆ addEffect()

addEffect ( Effect  $effect)
Parameters
Effect$effect
Returns
bool|void
4663  {//Overwrite
4664  if($effect->isBad() && $this->isCreative()){
4665  return;
4666  }
4667 
4668  parent::addEffect($effect);
4669  }

◆ addTitle()

addTitle ( string  $title,
string  $subtitle = "",
int  $fadeIn = -1,
int  $stay = -1,
int  $fadeOut = -1 
)
Parameters
string$title
string$subtitle
int$fadeIn
int$stay
int$fadeOut
3811  {
3812  $this->setTitleDuration($fadeIn, $stay, $fadeOut);
3813  if($subtitle !== ""){
3814  $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SUB_TITLE);
3815  }
3816  $this->sendTitleText($title, SetTitlePacket::TYPE_TITLE);
3817  }

◆ addWindow()

addWindow ( Inventory  $inventory,
  $forceId = null 
)

Returns the created/existing window id

Parameters
Inventory$inventory
int$forceId
Returns
int
4536  : int{
4537  if($this->windows->contains($inventory)){
4538  return $this->windows[$inventory];
4539  }
4540 
4541  if($forceId === null){
4542  $this->windowCnt = $cnt = max(2, ++$this->windowCnt % 99);
4543  }else{
4544  $cnt = (int) $forceId;
4545  }
4546  $this->windowIndex[$cnt] = $inventory;
4547  $this->windows->attach($inventory, $cnt);
4548  if($inventory->open($this)){
4549  return $cnt;
4550  }else{
4551  $this->removeWindow($inventory);
4552 
4553  return -1;
4554  }
4555  }

◆ allowInstaBreak()

allowInstaBreak ( )
Returns
bool
525  : bool{
526  return $this->allowInstaBreak;
527  }

◆ allowMovementCheats()

allowMovementCheats ( )
Returns
bool
511  : bool{
513  }

◆ attack()

attack (   $damage,
EntityDamageEvent  $source 
)
Parameters
float$damage
EntityDamageEvent$source
Returns
bool
4321  {
4322  if(!$this->isAlive()){
4323  return false;
4324  }
4325 
4326  if($this->isCreative()
4327  and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC
4328  and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE
4329  and $source->getCause() !== EntityDamageEvent::CAUSE_VOID
4330  ){
4331  $source->setCancelled();
4332  }elseif($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL){
4333  $source->setCancelled();
4334  }
4335 
4336  parent::attack($damage, $source);
4337 
4338  if($source->isCancelled()){
4339  return false;
4340  }elseif($this->getLastDamageCause() === $source and $this->spawned){
4341  $pk = new EntityEventPacket();
4342  $pk->eid = $this->id;
4343  $pk->event = EntityEventPacket::HURT_ANIMATION;
4344  $this->dataPacket($pk);
4345 
4346  if($this->isSurvival()){
4348  }
4349  }
4350  return true;
4351  }

◆ awardAchievement()

awardAchievement (   $achievementId)
Parameters
string$achievementId
Returns
bool
1399  {
1400  if(isset(Achievement::$list[$achievementId]) and !$this->hasAchievement($achievementId)){
1401  foreach(Achievement::$list[$achievementId]["requires"] as $requirementId){
1402  if(!$this->hasAchievement($requirementId)){
1403  return false;
1404  }
1405  }
1406  $this->server->getPluginManager()->callEvent($ev = new PlayerAchievementAwardedEvent($this, $achievementId));
1407  if(!$ev->isCancelled()){
1408  $this->achievements[$achievementId] = true;
1409  Achievement::broadcast($this, $achievementId);
1410 
1411  return true;
1412  }else{
1413  return false;
1414  }
1415  }
1416 
1417  return false;
1418  }

◆ batchDataPacket()

batchDataPacket ( DataPacket  $packet)

Batch a Data packet into the channel list to send at the end of the tick

Parameters
DataPacket$packet
Returns
bool
1230  {
1231  if($this->connected === false){
1232  return false;
1233  }
1234 
1236  $timings->startTiming();
1237  $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
1238  if($ev->isCancelled()){
1239  $timings->stopTiming();
1240  return false;
1241  }
1242 
1243  if(!isset($this->batchedPackets)){
1244  $this->batchedPackets = [];
1245  }
1246 
1247  $this->batchedPackets[] = clone $packet;
1248  $timings->stopTiming();
1249  return true;
1250  }

◆ canCollideWith()

canCollideWith ( Entity  $entity)
Parameters
Entity$entity
Returns
bool
604  : bool{
605  return false;
606  }

◆ canInteract()

canInteract ( Vector3  $pos,
  $maxDistance,
  $maxDiff = 0.5 
)
Parameters
Vector3$pos
$maxDistance
float$maxDiff
Returns
bool
2116  {
2117  $eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0);
2118  if($eyePos->distanceSquared($pos) > $maxDistance ** 2){
2119  return false;
2120  }
2121 
2122  $dV = $this->getDirectionPlane();
2123  $dot = $dV->dot(new Vector2($eyePos->x, $eyePos->z));
2124  $dot1 = $dV->dot(new Vector2($pos->x, $pos->z));
2125  return ($dot1 - $dot) >= -$maxDiff;
2126  }

◆ canSee()

canSee ( Player  $player)
Parameters
Player$player
Returns
bool
571  : bool{
572  return !isset($this->hiddenPlayers[$player->getRawUniqueId()]);
573  }

◆ checkGroundState()

checkGroundState (   $movX,
  $movY,
  $movZ,
  $dx,
  $dy,
  $dz 
)
protected
Parameters
$movX
$movY
$movZ
$dx
$dy
$dz
1616  {
1617  if(!$this->onGround or $movY != 0){
1618  $bb = clone $this->boundingBox;
1619  $bb->maxY = $bb->minY + 0.5;
1620  $bb->minY -= 1;
1621  if(count($this->level->getCollisionBlocks($bb, true)) > 0){
1622  $this->onGround = true;
1623  }else{
1624  $this->onGround = false;
1625  }
1626  }
1627  $this->isCollided = $this->onGround;
1628  }

◆ checkNearEntities()

checkNearEntities (   $tickDiff)
protected
Parameters
$tickDiff
1651  {
1652  foreach($this->level->getNearbyEntities($this->boundingBox->grow(0.5, 0.5, 0.5), $this) as $entity){
1653  $entity->scheduleUpdate();
1654 
1655  if(!$entity->isAlive()){
1656  continue;
1657  }
1658 
1659  if($entity instanceof Arrow and $entity->hadCollision){
1660  $item = Item::get(Item::ARROW, $entity->getPotionId(), 1);
1661 
1662  $add = false;
1663  if(!$this->server->allowInventoryCheats and !$this->isCreative()){
1664  if(!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)){
1665  //The item is added to the floating inventory to allow client to handle the pickup
1666  //We have to also check if it can be added to the real inventory before sending packets.
1667  continue;
1668  }
1669  $add = true;
1670  }
1671 
1672  $this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
1673  if($ev->isCancelled()){
1674  continue;
1675  }
1676 
1677  $pk = new TakeItemEntityPacket();
1678  $pk->eid = $this->id;
1679  $pk->target = $entity->getId();
1680  $this->server->broadcastPacket($entity->getViewers(), $pk);
1681 
1682  if($add){
1683  $this->getFloatingInventory()->addItem(clone $item);
1684  }
1685  $entity->kill();
1686  }elseif($entity instanceof DroppedItem){
1687  if($entity->getPickupDelay() <= 0){
1688  $item = $entity->getItem();
1689 
1690  if($item instanceof Item){
1691  $add = false;
1692  if(!$this->server->allowInventoryCheats and !$this->isCreative()){
1693  if(!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)){
1694  continue;
1695  }
1696  $add = true;
1697  }
1698 
1699  $this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
1700  if($ev->isCancelled()){
1701  continue;
1702  }
1703 
1704  switch($item->getId()){
1705  case Item::WOOD:
1706  $this->awardAchievement("mineWood");
1707 
1708  break;
1709  case Item::DIAMOND:
1710  $this->awardAchievement("diamond");
1711  break;
1712  }
1713 
1714  $pk = new TakeItemEntityPacket();
1715  $pk->eid = $this->id;
1716  $pk->target = $entity->getId();
1717  $this->server->broadcastPacket($entity->getViewers(), $pk);
1718 
1719  if($add){
1720  $this->getFloatingInventory()->addItem(clone $item);
1721  }
1722  $entity->kill();
1723  }
1724  }
1725  }
1726  }
1727  }

◆ checkNetwork()

checkNetwork ( )
2089  {
2090  if(!$this->isOnline()){
2091  return;
2092  }
2093 
2094  if($this->nextChunkOrderRun-- <= 0 or $this->chunk === null){
2095  $this->orderChunks();
2096  }
2097 
2098  if(count($this->loadQueue) > 0 or !$this->spawned){
2099  $this->sendNextChunk();
2100  }
2101 
2102  if(count($this->batchedPackets) > 0){
2103  $this->server->batchPackets([$this], $this->batchedPackets, false);
2104  $this->batchedPackets = [];
2105  }
2106 
2107  }

◆ checkTeleportPosition()

checkTeleportPosition ( )
protected
Returns
bool
4421  {
4422  if($this->teleportPosition !== null){
4423  $chunkX = $this->teleportPosition->x >> 4;
4424  $chunkZ = $this->teleportPosition->z >> 4;
4425 
4426  for($X = -1; $X <= 1; ++$X){
4427  for($Z = -1; $Z <= 1; ++$Z){
4428  if(!isset($this->usedChunks[$index = Level::chunkHash($chunkX + $X, $chunkZ + $Z)]) or $this->usedChunks[$index] === false){
4429  return false;
4430  }
4431  }
4432  }
4433 
4434  $this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET);
4435  $this->spawnToAll();
4436  $this->forceMovement = $this->teleportPosition;
4437  $this->teleportPosition = null;
4438 
4439  return true;
4440  }
4441 
4442  return true;
4443  }

◆ clearCreativeItems()

clearCreativeItems ( )
2136  {
2137  $this->personalCreativeItems = [];
2138  }

◆ close()

close (   $message = "",
  $reason = "generic reason",
  $notify = true 
)
final

Note for plugin developers: use kick() with the isAdmin flag set to kick without the "Kicked by admin" part instead of this method.

Parameters
string$messageMessage to be broadcasted
string$reasonReason showed in console
bool$notify
3996  {
3997  if($this->connected and !$this->closed){
3998  if($notify and strlen((string) $reason) > 0){
3999  $pk = new DisconnectPacket();
4000  $pk->hideDisconnectionScreen = null;
4001  $pk->message = $reason;
4002  $this->dataPacket($pk);
4003  }
4004 
4005  //$this->setLinked();
4006 
4007  if($this->fishingHook instanceof FishingHook){
4008  $this->fishingHook->close();
4009  $this->fishingHook = null;
4010  }
4011 
4013 
4014  $this->connected = false;
4015  if(strlen($this->getName()) > 0){
4016  $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message, true));
4017  if($this->loggedIn === true and $ev->getAutoSave()){
4018  $this->save();
4019  }
4020  }
4021 
4022  foreach($this->server->getOnlinePlayers() as $player){
4023  if(!$player->canSee($this)){
4024  $player->showPlayer($this);
4025  }
4026  }
4027  $this->hiddenPlayers = [];
4028 
4029  foreach($this->windowIndex as $window){
4030  $this->removeWindow($window);
4031  }
4032 
4033  foreach($this->usedChunks as $index => $d){
4034  Level::getXZ($index, $chunkX, $chunkZ);
4035  $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ);
4036  foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
4037  $entity->despawnFrom($this, false);
4038  }
4039  unset($this->usedChunks[$index]);
4040  }
4041 
4042  parent::close();
4043 
4044  $this->interface->close($this, $notify ? $reason : "");
4045 
4046  if($this->loggedIn){
4047  $this->server->removeOnlinePlayer($this);
4048  }
4049 
4050  $this->loggedIn = false;
4051 
4052  $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
4053  $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
4054 
4055  if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
4056  if($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_MESSAGE) $this->server->broadcastMessage($ev->getQuitMessage());
4057  elseif($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_TIP) $this->server->broadcastTip(str_replace("@player", $this->getName(), $this->server->playerLogoutMsg));
4058  elseif($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_POPUP) $this->server->broadcastPopup(str_replace("@player", $this->getName(), $this->server->playerLogoutMsg));
4059  }
4060 
4061  $this->spawned = false;
4062  $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [
4064  $this->ip,
4065  $this->port,
4066  $this->getServer()->getLanguage()->translateString($reason)
4067  ]));
4068  $this->windows = new \SplObjectStorage();
4069  $this->windowIndex = [];
4070  $this->usedChunks = [];
4071  $this->loadQueue = [];
4072  $this->hasSpawned = [];
4073  $this->spawnPosition = null;
4074 
4075  if($this->server->dserverConfig["enable"] and $this->server->dserverConfig["queryAutoUpdate"]) $this->server->updateQuery();
4076  }
4077 
4078  if($this->perm !== null){
4079  $this->perm->clearPermissions();
4080  $this->perm = null;
4081  }
4082 
4083  $this->inventory = null;
4084  $this->floatingInventory = null;
4085  $this->enderChestInventory = null;
4086  $this->transactionQueue = null;
4087 
4088  $this->chunk = null;
4089 
4090  $this->server->removePlayer($this);
4091  }

◆ dataPacket()

dataPacket ( DataPacket  $packet,
  $needACK = false 
)

Sends an ordered DataPacket to the send buffer

Parameters
DataPacket$packet
bool$needACK
Returns
int|bool
1260  {
1261  if(!$this->connected){
1262  return false;
1263  }
1264 
1266  $timings->startTiming();
1267 
1268  $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
1269  if($ev->isCancelled()){
1270  $timings->stopTiming();
1271  return false;
1272  }
1273 
1274  $identifier = $this->interface->putPacket($this, $packet, $needACK, false);
1275 
1276  if($needACK and $identifier !== null){
1277  $this->needACK[$identifier] = false;
1278 
1279  $timings->stopTiming();
1280  return $identifier;
1281  }
1282 
1283  $timings->stopTiming();
1284  return true;
1285  }

◆ directDataPacket()

directDataPacket ( DataPacket  $packet,
  $needACK = false 
)
Parameters
DataPacket$packet
bool$needACK
Returns
bool|int
1293  {
1294  if($this->connected === false){
1295  return false;
1296  }
1297 
1299  $timings->startTiming();
1300  $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
1301  if($ev->isCancelled()){
1302  $timings->stopTiming();
1303  return false;
1304  }
1305 
1306  $identifier = $this->interface->putPacket($this, $packet, $needACK, true);
1307 
1308  if($needACK and $identifier !== null){
1309  $this->needACK[$identifier] = false;
1310 
1311  $timings->stopTiming();
1312  return $identifier;
1313  }
1314 
1315  $timings->stopTiming();
1316  return true;
1317  }

◆ doFirstSpawn()

doFirstSpawn ( )
protected
1045  {
1046  $this->spawned = true;
1047 
1048  $this->sendPotionEffects($this);
1049  $this->sendData($this);
1050 
1051  $pk = new SetTimePacket();
1052  $pk->time = $this->level->getTime();
1053  $pk->started = $this->level->stopTime == false;
1054  $this->dataPacket($pk);
1055 
1056  $pos = $this->level->getSafeSpawn($this);
1057 
1058  $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
1059 
1060  $pos = $ev->getRespawnPosition();
1061  if($pos->getY() < 127) $pos = $pos->add(0, 0.2, 0);
1062 
1063  /*$pk = new RespawnPacket();
1064  $pk->x = $pos->x;
1065  $pk->y = $pos->y;
1066  $pk->z = $pos->z;
1067  $this->dataPacket($pk);*/
1068 
1069  $pk = new PlayStatusPacket();
1070  $pk->status = PlayStatusPacket::PLAYER_SPAWN;
1071  $this->dataPacket($pk);
1072 
1073  $this->noDamageTicks = 60;
1074 
1075  foreach($this->usedChunks as $index => $c){
1076  Level::getXZ($index, $chunkX, $chunkZ);
1077  foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
1078  if($entity !== $this and !$entity->closed and $entity->isAlive()){
1079  $entity->spawnTo($this);
1080  }
1081  }
1082  }
1083 
1084  $this->teleport($pos);
1085 
1086  $this->allowFlight = (($this->gamemode == 3) or ($this->gamemode == 1));
1087  $this->setHealth($this->getHealth());
1088 
1089  $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.joined", [
1090  $this->getDisplayName()
1091  ])));
1092 
1093  $this->sendSettings();
1094 
1095  if(strlen(trim($msg = $ev->getJoinMessage())) > 0){
1096  if($this->server->playerMsgType === Server:: PLAYER_MSG_TYPE_MESSAGE) $this->server->broadcastMessage($msg);
1097  elseif($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_TIP) $this->server->broadcastTip(str_replace("@player", $this->getName(), $this->server->playerLoginMsg));
1098  elseif($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_POPUP) $this->server->broadcastPopup(str_replace("@player", $this->getName(), $this->server->playerLoginMsg));
1099  }
1100 
1101  $this->server->onPlayerLogin($this);
1102  $this->spawnToAll();
1103 
1104  $this->level->getWeather()->sendWeather($this);
1105 
1106  if($this->server->dserverConfig["enable"] and $this->server->dserverConfig["queryAutoUpdate"]){
1107  $this->server->updateQuery();
1108  }
1109 
1110  /*if($this->server->getUpdater()->hasUpdate() and $this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)){
1111  $this->server->getUpdater()->showPlayerUpdate($this);
1112  }*/
1113 
1114  if($this->getHealth() <= 0){
1115  $pk = new RespawnPacket();
1116  $pos = $this->getSpawn();
1117  $pk->x = $pos->x;
1118  $pk->y = $pos->y;
1119  $pk->z = $pos->z;
1120  $this->dataPacket($pk);
1121  }
1122 
1123  $this->inventory->sendContents($this);
1124  $this->inventory->sendArmorContents($this);
1125 
1126  }

◆ dropItem()

dropItem ( Item  $item)
Parameters
Item$itemDrops the specified item in front of the player.
3756  {
3757  if($this->spawned === false or !$this->isAlive()){
3758  return;
3759  }
3760 
3761  if(($this->isCreative() and $this->server->limitedCreative) or $this->isSpectator()){
3762  //Ignore for limited creative
3763  return;
3764  }
3765 
3766  if($item->getId() === Item::AIR or $item->getCount() < 1){
3767  //Ignore dropping air or items with bad counts
3768  return;
3769  }
3770 
3771  $ev = new PlayerDropItemEvent($this, $item);
3772  $this->server->getPluginManager()->callEvent($ev);
3773  if($ev->isCancelled()){
3774  $this->getFloatingInventory()->removeItem($item);
3775  $this->getInventory()->addItem($item);
3776  return;
3777  }
3778 
3779  $motion = $this->getDirectionVector()->multiply(0.4);
3780 
3781  $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40);
3782 
3783  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
3784  }

◆ getAddress()

getAddress ( )

Gets the player IP address

Returns
string
864  : string{
865  return $this->ip;
866  }

◆ getAllowFlight()

getAllowFlight ( )
Returns
bool
474  : bool{
475  return $this->allowFlight;
476  }

◆ getClientFriendlyGamemode()

static getClientFriendlyGamemode ( int  $gamemode)
static
1439  : int{
1440  $gamemode &= 0x03;
1441  if($gamemode === Player::SPECTATOR){
1442  return Player::CREATIVE;
1443  }
1444 
1445  return $gamemode;
1446  }

◆ getClientId()

getClientId ( )

This might disappear in the future. Please use getUniqueId() instead (IP + clientId + name combo, in the future it'll change to real UUID for online auth)

387  {
388  return $this->randomClientId;
389  }

◆ getClientSecret()

getClientSecret ( )
Returns
mixed
394  {
395  return $this->clientSecret;
396  }

◆ getCreativeItemIndex()

getCreativeItemIndex ( Item  $item)
Parameters
Item$item
Returns
int
2169  : int{
2170  foreach($this->personalCreativeItems as $i => $d){
2171  if($item->equals($d, !$item->isTool())){
2172  return $i;
2173  }
2174  }
2175 
2176  return -1;
2177  }

◆ getCreativeItems()

getCreativeItems ( )
Returns
array
2143  : array{
2145  }

◆ getDeviceModel()

getDeviceModel ( )
Returns
mixed
355  {
356  return $this->deviceModel;
357  }

◆ getDeviceOS()

getDeviceOS ( )
Returns
mixed
362  {
363  return $this->deviceOS;
364  }

◆ getDisplayName()

getDisplayName ( )

Gets the "friendly" name to display of this player to use in the chat.

Returns
string
834  {
835  return $this->displayName;
836  }

◆ getDrops()

getDrops ( )
Returns
array
1584  {
1585  if(!$this->isCreative()){
1586  return parent::getDrops();
1587  }
1588 
1589  return [];
1590  }

◆ getEffectivePermissions()

getEffectivePermissions ( )
Returns
permission[]

Implements Permissible.

740  {
741  return $this->perm->getEffectivePermissions();
742  }

◆ getFirstPlayed()

getFirstPlayed ( )
Returns
null

Implements IPlayer.

445  {
446  return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null;
447  }

◆ getFishingHook()

getFishingHook ( )
Returns
FishingHook
338  {
339  return $this->fishingHook;
340  }

◆ getGamemode()

getGamemode ( )
Returns
int
1423  : int{
1424  return $this->gamemode;
1425  }

◆ getInAirTicks()

getInAirTicks ( )
Returns
int
892  {
893  return $this->inAirTicks;
894  }

◆ getItemInHand()

getItemInHand ( )
Returns
Item
369  {
370  return $this->inventory->getItemInHand();
371  }

◆ getLastPlayed()

getLastPlayed ( )
Returns
null

Implements IPlayer.

452  {
453  return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null;
454  }

◆ getLeaveMessage()

getLeaveMessage ( )
Returns
TranslationContainer
376  {
377  return new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.left", [
378  $this->getDisplayName()
379  ]);
380  }

◆ getLoaderId()

getLoaderId ( )
Returns
int|null

Implements ChunkLoader.

4646  {
4647  return $this->loaderId;
4648  }

◆ getMetadata()

getMetadata (   $metadataKey)
Parameters
string$metadataKey
Returns
MetadataValue[]

Implements Metadatable.

4582  {
4583  return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
4584  }

◆ getName()

getName ( )

Gets the username

Returns
string

Implements CommandSender.

4140  {
4141  return $this->username;
4142  }

◆ getNextPosition()

getNextPosition ( )
Returns
Position
878  {
879  return $this->newPosition !== null ? new Position($this->newPosition->x, $this->newPosition->y, $this->newPosition->z, $this->level) : $this->getPosition();
880  }

◆ getPlayer()

getPlayer ( )
Returns
$this

Implements IPlayer.

438  {
439  return $this;
440  }

◆ getPort()

getPort ( )
Returns
int
871  : int{
872  return $this->port;
873  }

◆ getProtocol()

getProtocol ( )
Returns
mixed
2347  {
2348  return $this->protocol;
2349  }

◆ getRemoveFormat()

getRemoveFormat ( )
Returns
bool
555  {
556  return $this->removeFormat;
557  }

◆ getServer()

getServer ( )
Returns
Server

Implements CommandSender.

548  {
549  return $this->server;
550  }

◆ getSpawn()

getSpawn ( )
Returns
Position
959  {
960  if($this->hasValidSpawnPosition()){
961  return $this->spawnPosition;
962  }else{
963  $level = $this->server->getDefaultLevel();
964 
965  return $level->getSafeSpawn();
966  }
967  }

◆ getViewDistance()

getViewDistance ( )
Returns
int
619  : int{
620  return $this->viewDistance;
621  }

◆ getWindowId()

getWindowId ( Inventory  $inventory)
Parameters
Inventory$inventory
Returns
int
4520  : int{
4521  if($this->windows->contains($inventory)){
4522  return $this->windows[$inventory];
4523  }
4524 
4525  return -1;
4526  }

◆ hasAchievement()

hasAchievement (   $achievementId)
Parameters
string$achievementId
Returns
bool
812  : bool{
813  if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
814  $this->achievements = [];
815 
816  return false;
817  }
818 
819  return isset($this->achievements[$achievementId]) and $this->achievements[$achievementId] != false;
820  }

◆ hasAutoJump()

hasAutoJump ( )
Returns
bool
504  : bool{
505  return $this->autoJump;
506  }

◆ hasMetadata()

hasMetadata (   $metadataKey)
Parameters
string$metadataKey
Returns
bool

Implements Metadatable.

4591  {
4592  return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
4593  }

◆ hasPermission()

hasPermission (   $name)
Parameters
permission\Permission | string$name
Returns
bool
Exceptions

Implements Permissible.

684  {
685  if($this->closed){
686  throw new \InvalidStateException("Trying to get permissions of closed player");
687  }
688  return $this->perm->hasPermission($name);
689  }

◆ hasPlayedBefore()

hasPlayedBefore ( )
Returns
bool

Implements IPlayer.

459  {
460  return $this->playedBefore;
461  }

◆ hasValidSpawnPosition()

hasValidSpawnPosition ( )
Returns
bool
972  : bool{
973  return $this->spawnPosition instanceof WeakPosition and $this->spawnPosition->isValid();
974  }

◆ hidePlayer()

hidePlayer ( Player  $player)
Parameters
Player$player
578  {
579  if($player === $this){
580  return;
581  }
582  $this->hiddenPlayers[$player->getRawUniqueId()] = $player;
583  $player->despawnFrom($this);
584  }

◆ isAdventure()

isAdventure ( )
Returns
bool
1570  : bool{
1571  return ($this->gamemode & 0x02) > 0;
1572  }

◆ isBanned()

isBanned ( )
Returns
bool

Implements IPlayer.

401  {
402  return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
403  }

◆ isConnected()

isConnected ( )
Returns
bool
825  : bool{
826  return $this->connected === true;
827  }

◆ isCreative()

isCreative ( )
Returns
bool
1556  : bool{
1557  return ($this->gamemode & 0x01) > 0;
1558  }

◆ isFireProof()

isFireProof ( )
Returns
bool
1577  : bool{
1578  return $this->isCreative();
1579  }

◆ isFishing()

isFishing ( )
Returns
bool
331  {
332  return ($this->fishingHook instanceof FishingHook);
333  }

◆ isFlying()

isFlying ( )
Returns
bool
489  : bool{
490  return $this->flying;
491  }

◆ isLoaderActive()

isLoaderActive ( )
Returns
bool

Implements ChunkLoader.

4653  {
4654  return $this->isConnected();
4655  }

◆ isMoving()

isMoving ( )
Returns
bool
1922  : bool{
1923  return $this->moving;
1924  }

◆ isOnline()

isOnline ( )
Returns
bool

Implements IPlayer.

639  : bool{
640  return $this->connected === true and $this->loggedIn === true;
641  }

◆ isOp()

isOp ( )
Returns
bool

Implements ServerOperator.

646  : bool{
647  return $this->server->isOp($this->getName());
648  }

◆ isPermissionSet()

isPermissionSet (   $name)
Parameters
permission\Permission | string$name
Returns
bool

Implements Permissible.

673  {
674  return $this->perm->isPermissionSet($name);
675  }

◆ isSleeping()

isSleeping ( )
Returns
bool
885  : bool{
886  return $this->sleeping !== null;
887  }

◆ isSpectator()

isSpectator ( )
Returns
bool
1563  : bool{
1564  return $this->gamemode === 3;
1565  }

◆ isSurvival()

isSurvival ( )
Returns
bool
1549  : bool{
1550  return ($this->gamemode & 0x01) === 0;
1551  }

◆ isWhitelisted()

isWhitelisted ( )
Returns
bool

Implements IPlayer.

420  : bool{
421  return $this->server->isWhitelisted(strtolower($this->getName()));
422  }

◆ kick()

kick (   $reason = "",
  $isAdmin = true 
)

Kicks a player from the server

Parameters
string$reason
bool$isAdmin
Returns
bool
3728  {
3729  $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage()));
3730  if(!$ev->isCancelled()){
3731  if($isAdmin){
3732  $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
3733  }else{
3734  if($reason === ""){
3735  $message = "disconnectionScreen.noReason";
3736  }else{
3737  $message = $reason;
3738  }
3739  }
3740  $this->close($ev->getQuitMessage(), $message);
3741 
3742  return true;
3743  }
3744 
3745  return false;
3746  }

◆ kill()

kill ( )
4144  {
4145  if(!$this->spawned){
4146  return;
4147  }
4148 
4149  $message = "death.attack.generic";
4150 
4151  $params = [
4152  $this->getDisplayName()
4153  ];
4154 
4155  $cause = $this->getLastDamageCause();
4156 
4157  switch($cause === null ? EntityDamageEvent::CAUSE_CUSTOM : $cause->getCause()){
4159  if($cause instanceof EntityDamageByEntityEvent){
4160  $e = $cause->getDamager();
4161  if($e instanceof Player){
4162  $message = "death.attack.player";
4163  $params[] = $e->getDisplayName();
4164  break;
4165  }elseif($e instanceof Living){
4166  $message = "death.attack.mob";
4167  $params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
4168  break;
4169  }else{
4170  $params[] = "Unknown";
4171  }
4172  }
4173  break;
4175  if($cause instanceof EntityDamageByEntityEvent){
4176  $e = $cause->getDamager();
4177  if($e instanceof Player){
4178  $message = "death.attack.arrow";
4179  $params[] = $e->getDisplayName();
4180  }elseif($e instanceof Living){
4181  $message = "death.attack.arrow";
4182  $params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
4183  break;
4184  }else{
4185  $params[] = "Unknown";
4186  }
4187  }
4188  break;
4190  $message = "death.attack.generic";
4191  break;
4193  $message = "death.attack.outOfWorld";
4194  break;
4196  if($cause instanceof EntityDamageEvent){
4197  if($cause->getFinalDamage() > 2){
4198  $message = "death.fell.accident.generic";
4199  break;
4200  }
4201  }
4202  $message = "death.attack.fall";
4203  break;
4204 
4206  $message = "death.attack.inWall";
4207  break;
4208 
4210  $message = "death.attack.lava";
4211  break;
4212 
4214  $message = "death.attack.onFire";
4215  break;
4216 
4218  $message = "death.attack.inFire";
4219  break;
4220 
4222  $message = "death.attack.drown";
4223  break;
4224 
4226  if($cause instanceof EntityDamageByBlockEvent){
4227  if($cause->getDamager()->getId() === Block::CACTUS){
4228  $message = "death.attack.cactus";
4229  }
4230  }
4231  break;
4232 
4235  if($cause instanceof EntityDamageByEntityEvent){
4236  $e = $cause->getDamager();
4237  if($e instanceof Player){
4238  $message = "death.attack.explosion.player";
4239  $params[] = $e->getDisplayName();
4240  }elseif($e instanceof Living){
4241  $message = "death.attack.explosion.player";
4242  $params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
4243  break;
4244  }
4245  }else{
4246  $message = "death.attack.explosion";
4247  }
4248  break;
4249 
4251  $message = "death.attack.magic";
4252  break;
4253 
4255  break;
4256 
4257  default:
4258  break;
4259 
4260  }
4261 
4262  Entity::kill();
4263 
4264  $ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params));
4265  $ev->setKeepInventory($this->server->keepInventory);
4266  $ev->setKeepExperience($this->server->keepExperience);
4267  $this->server->getPluginManager()->callEvent($ev);
4268 
4269  if(!$ev->getKeepInventory()){
4270  foreach($ev->getDrops() as $item){
4271  $this->level->dropItem($this, $item);
4272  }
4273 
4274  if($this->floatingInventory !== null){
4275  $this->floatingInventory->clearAll();
4276  }
4277 
4278  if($this->inventory !== null){
4279  $this->inventory->clearAll();
4280  }
4281  }
4282 
4283  if($this->server->expEnabled and !$ev->getKeepExperience()){
4284  $exp = min(91, $this->getTotalXp()); //Max 7 levels of exp dropped
4285  $this->getLevel()->spawnXPOrb($this->add(0, 0.2, 0), $exp);
4286  $this->setTotalXp(0, true);
4287  }
4288 
4289  if($ev->getDeathMessage() != ""){
4290  $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
4291  }
4292 
4293  $pos = $this->getSpawn();
4294 
4295  $this->setHealth(0);
4296 
4297  $pk = new RespawnPacket();
4298  $pk->x = $pos->x;
4299  $pk->y = $pos->y;
4300  $pk->z = $pos->z;
4301  $this->dataPacket($pk);
4302  }

◆ linkHookToPlayer()

linkHookToPlayer ( FishingHook  $entity)
Parameters
FishingHook$entity
Returns
bool
301  {
302  if($entity->isAlive()){
303  $this->setFishingHook($entity);
304  $pk = new EntityEventPacket();
305  $pk->eid = $this->getFishingHook()->getId();
307  $this->server->broadcastPacket($this->level->getPlayers(), $pk);
308  return true;
309  }
310  return false;
311  }

◆ onBlockChanged()

onBlockChanged ( Vector3  $block)
Parameters
Vector3$block

Implements ChunkLoader.

4639  {
4640 
4641  }

◆ onChunkChanged()

onChunkChanged ( Chunk  $chunk)
Parameters
Chunk$chunk

Implements ChunkLoader.

4606  {
4607  if(isset($this->usedChunks[$hash = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
4608  $this->usedChunks[$hash] = false;
4609  }
4610  if(!$this->spawned){
4611  $this->nextChunkOrderRun = 0;
4612  }
4613  }

◆ onChunkLoaded()

onChunkLoaded ( Chunk  $chunk)
Parameters
Chunk$chunk

Implements ChunkLoader.

4618  {
4619 
4620  }

◆ onChunkPopulated()

onChunkPopulated ( Chunk  $chunk)
Parameters
Chunk$chunk

Implements ChunkLoader.

4625  {
4626 
4627  }

◆ onChunkUnloaded()

onChunkUnloaded ( Chunk  $chunk)
Parameters
Chunk$chunk

Implements ChunkLoader.

4632  {
4633 
4634  }

◆ onPlayerPreLogin()

onPlayerPreLogin ( )
2128  {
2129  $pk = new PlayStatusPacket();
2130  $pk->status = PlayStatusPacket::LOGIN_SUCCESS;
2131  $this->dataPacket($pk);
2132 
2133  $this->processLogin();
2134  }

◆ onUpdate()

onUpdate (   $currentTick)
Parameters
$currentTick
Returns
bool
1947  {
1948  if(!$this->loggedIn){
1949  return false;
1950  }
1951 
1952  $tickDiff = $currentTick - $this->lastUpdate;
1953 
1954  if($tickDiff <= 0){
1955  return true;
1956  }
1957 
1958  $this->messageCounter = 2;
1959 
1960  $this->lastUpdate = $currentTick;
1961 
1962  $this->sendAttributes();
1963 
1964  if(!$this->isAlive() and $this->spawned){
1965  ++$this->deadTicks;
1966  if($this->deadTicks >= 10){
1967  $this->despawnFromAll();
1968  }
1969  return true;
1970  }
1971 
1972  $this->timings->startTiming();
1973 
1974  if($this->spawned){
1975  if($this->server->netherEnabled){
1976  if(($this->isCreative() or $this->isSurvival() and $this->server->getTick() - $this->portalTime >= 80) and $this->portalTime > 0){
1977  $netherLevel = null;
1978  if($this->server->isLevelLoaded($this->server->netherName) or $this->server->loadLevel($this->server->netherName)){
1979  $netherLevel = $this->server->getLevelByName($this->server->netherName);
1980  }
1981 
1982  if($netherLevel instanceof Level){
1983  if($this->getLevel() !== $netherLevel){
1984  $this->fromPos = $this->getPosition();
1985  $this->fromPos->x = ((int) $this->fromPos->x) + 0.5;
1986  $this->fromPos->z = ((int) $this->fromPos->z) + 0.5;
1987  $this->teleport($this->shouldResPos = $netherLevel->getSafeSpawn());
1988  }elseif($this->fromPos instanceof Position){
1989  if(!($this->getLevel()->isChunkLoaded($this->fromPos->x, $this->fromPos->z))){
1990  $this->getLevel()->loadChunk($this->fromPos->x, $this->fromPos->z);
1991  }
1992  $add = [1, 0, -1, 0, 0, 1, 0, -1];
1993  $tempos = null;
1994  for($j = 2; $j < 5; $j++){
1995  for($i = 0; $i < 4; $i++){
1996  if($this->fromPos->getLevel()->getBlock($this->temporalVector->fromObjectAdd($this->fromPos, $add[$i] * $j, 0, $add[$i + 4] * $j))->getId() === Block::AIR){
1997  if($this->fromPos->getLevel()->getBlock($this->temporalVector->fromObjectAdd($this->fromPos, $add[$i] * $j, 1, $add[$i + 4] * $j))->getId() === Block::AIR){
1998  $tempos = $this->fromPos->add($add[$i] * $j, 0, $add[$i + 4] * $j);
1999  //$this->getLevel()->getServer()->getLogger()->debug($tempos);
2000  break;
2001  }
2002  }
2003  }
2004  if($tempos != null){
2005  break;
2006  }
2007  }
2008  if($tempos === null){
2009  $tempos = $this->fromPos->add(mt_rand(-2, 2), 0, mt_rand(-2, 2));
2010  }
2011  $this->teleport($this->shouldResPos = $tempos);
2012  $add = null;
2013  $tempos = null;
2014  $this->fromPos = null;
2015  }else{
2016  $this->teleport($this->shouldResPos = $this->server->getDefaultLevel()->getSafeSpawn());
2017  }
2018  $this->portalTime = 0;
2019  }
2020  }
2021  }
2022 
2023  $this->processMovement($tickDiff);
2024  $this->entityBaseTick($tickDiff);
2025 
2026  if($this->isOnFire() or $this->lastUpdate % 10 == 0){
2027  if($this->isCreative() and !$this->isInsideOfFire()){
2028  $this->extinguish();
2029  }elseif($this->getLevel()->getWeather()->isRainy()){
2030  if($this->getLevel()->canBlockSeeSky($this)){
2031  $this->extinguish();
2032  }
2033  }
2034  }
2035 
2036  if(!$this->isSpectator() and $this->speed !== null){
2037  if($this->hasEffect(Effect::LEVITATION)){
2038  $this->inAirTicks = 0;
2039  }
2040  if($this->onGround){
2041  if($this->inAirTicks !== 0){
2042  $this->startAirTicks = 5;
2043  }
2044  $this->inAirTicks = 0;
2045  }else{
2046  if($this->getInventory()->getItem($this->getInventory()->getSize() + 1)->getId() == "444"){
2047  #enable use of elytra. todo: check if it is open
2048  $this->inAirTicks = 0;
2049  }
2050  if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){
2051  $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks));
2052  $diff = ($this->speed->y - $expectedVelocity) ** 2;
2053 
2054  if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){
2055  if($this->inAirTicks < 1000){
2056  $this->setMotion(new Vector3(0, $expectedVelocity, 0));
2057  }elseif($this->kick("Flying is not enabled on this server", false)){
2058  $this->timings->stopTiming();
2059 
2060  return false;
2061  }
2062  }
2063  }
2064 
2066  }
2067  }
2068 
2069  if($this->getTransactionQueue() !== null){
2070  $this->getTransactionQueue()->execute();
2071  }
2072  }
2073 
2074  $this->checkTeleportPosition();
2075 
2076  $this->timings->stopTiming();
2077 
2078  if(count($this->messageQueue) > 0){
2079  $pk = new TextPacket();
2080  $pk->type = TextPacket::TYPE_RAW;
2081  $pk->message = implode("\n", $this->messageQueue);
2082  $this->dataPacket($pk);
2083  $this->messageQueue = [];
2084  }
2085 
2086  return true;
2087  }

◆ orderChunks()

orderChunks ( )
protected
Returns
bool
1131  {
1132  if($this->connected === false or $this->viewDistance === -1){
1133  return false;
1134  }
1135 
1136  Timings::$playerChunkOrderTimer->startTiming();
1137 
1138  $this->nextChunkOrderRun = 200;
1139 
1140  $radius = $this->server->getAllowedViewDistance($this->viewDistance);
1141  $radiusSquared = $radius ** 2;
1142 
1143  $newOrder = [];
1144  $unloadChunks = $this->usedChunks;
1145 
1146  $centerX = $this->x >> 4;
1147  $centerZ = $this->z >> 4;
1148 
1149  for($x = 0; $x < $radius; ++$x){
1150  for($z = 0; $z <= $x; ++$z){
1151  if(($x ** 2 + $z ** 2) > $radiusSquared){
1152  break; //skip to next band
1153  }
1154 
1155  //If the chunk is in the radius, others at the same offsets in different quadrants are also guaranteed to be.
1156 
1157  /* Top right quadrant */
1158  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX + $x, $centerZ + $z)]) or $this->usedChunks[$index] === false){
1159  $newOrder[$index] = true;
1160  }
1161  unset($unloadChunks[$index]);
1162 
1163  /* Top left quadrant */
1164  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX - $x - 1, $centerZ + $z)]) or $this->usedChunks[$index] === false){
1165  $newOrder[$index] = true;
1166  }
1167  unset($unloadChunks[$index]);
1168 
1169  /* Bottom right quadrant */
1170  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX + $x, $centerZ - $z - 1)]) or $this->usedChunks[$index] === false){
1171  $newOrder[$index] = true;
1172  }
1173  unset($unloadChunks[$index]);
1174 
1175 
1176  /* Bottom left quadrant */
1177  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX - $x - 1, $centerZ - $z - 1)]) or $this->usedChunks[$index] === false){
1178  $newOrder[$index] = true;
1179  }
1180  unset($unloadChunks[$index]);
1181 
1182  if($x !== $z){
1183  /* Top right quadrant mirror */
1184  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX + $z, $centerZ + $x)]) or $this->usedChunks[$index] === false){
1185  $newOrder[$index] = true;
1186  }
1187  unset($unloadChunks[$index]);
1188 
1189  /* Top left quadrant mirror */
1190  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX - $z - 1, $centerZ + $x)]) or $this->usedChunks[$index] === false){
1191  $newOrder[$index] = true;
1192  }
1193  unset($unloadChunks[$index]);
1194 
1195  /* Bottom right quadrant mirror */
1196  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX + $z, $centerZ - $x - 1)]) or $this->usedChunks[$index] === false){
1197  $newOrder[$index] = true;
1198  }
1199  unset($unloadChunks[$index]);
1200 
1201  /* Bottom left quadrant mirror */
1202  if(!isset($this->usedChunks[$index = Level::chunkHash($centerX - $z - 1, $centerZ - $x - 1)]) or $this->usedChunks[$index] === false){
1203  $newOrder[$index] = true;
1204  }
1205  unset($unloadChunks[$index]);
1206  }
1207  }
1208  }
1209 
1210  foreach($unloadChunks as $index => $bool){
1211  Level::getXZ($index, $X, $Z);
1212  $this->unloadChunk($X, $Z);
1213  }
1214 
1215  $this->loadQueue = $newOrder;
1216 
1217 
1218  Timings::$playerChunkOrderTimer->stopTiming();
1219 
1220  return true;
1221  }

◆ processMovement()

processMovement (   $tickDiff)
protected
Parameters
$tickDiff
1732  {
1733  if(!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null or $this->isSleeping()){
1734  return;
1735  }
1736 
1737  $newPos = $this->newPosition;
1738  $distanceSquared = $newPos->distanceSquared($this);
1739 
1740  $revert = false;
1741 
1742  if(($distanceSquared / ($tickDiff ** 2)) > 100 and !$this->allowMovementCheats){
1743  $this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement");
1744  $revert = true;
1745  }else{
1746  if($this->chunk === null or !$this->chunk->isGenerated()){
1747  $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false);
1748  if($chunk === null or !$chunk->isGenerated()){
1749  $revert = true;
1750  $this->nextChunkOrderRun = 0;
1751  }else{
1752  if($this->chunk !== null){
1753  $this->chunk->removeEntity($this);
1754  }
1755  $this->chunk = $chunk;
1756  }
1757  }
1758  }
1759 
1760  if(!$revert and $distanceSquared != 0){
1761  $dx = $newPos->x - $this->x;
1762  $dy = $newPos->y - $this->y;
1763  $dz = $newPos->z - $this->z;
1764 
1765  $this->move($dx, $dy, $dz);
1766 
1767  $diffX = $this->x - $newPos->x;
1768  $diffY = $this->y - $newPos->y;
1769  $diffZ = $this->z - $newPos->z;
1770 
1771  $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / ($tickDiff ** 2);
1772 
1773  if($this->isSurvival() and !$revert and $diff > 0.0625){
1774  $ev = new PlayerIllegalMoveEvent($this, $newPos);
1775  $ev->setCancelled($this->allowMovementCheats);
1776 
1777  $this->server->getPluginManager()->callEvent($ev);
1778 
1779  if(!$ev->isCancelled()){
1780  $revert = true;
1781  $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()]));
1782  }
1783  }
1784 
1785  if($diff > 0){
1786  $this->x = $newPos->x;
1787  $this->y = $newPos->y;
1788  $this->z = $newPos->z;
1789  $radius = $this->width / 2;
1790  $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius);
1791  }
1792  }
1793 
1794  $from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
1795  $to = $this->getLocation();
1796 
1797  $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2);
1798  $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
1799 
1800  if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){
1801 
1802  $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null);
1803 
1804  $this->lastX = $to->x;
1805  $this->lastY = $to->y;
1806  $this->lastZ = $to->z;
1807 
1808  $this->lastYaw = $to->yaw;
1809  $this->lastPitch = $to->pitch;
1810 
1811  if(!$isFirst){
1812  $ev = new PlayerMoveEvent($this, $from, $to);
1813  $this->setMoving(true);
1814 
1815  $this->server->getPluginManager()->callEvent($ev);
1816 
1817  if(!($revert = $ev->isCancelled())){ //Yes, this is intended
1818  if($this->server->netherEnabled){
1819  if($this->isInsideOfPortal()){
1820  if($this->portalTime == 0){
1821  $this->portalTime = $this->server->getTick();
1822  }
1823  }else{
1824  $this->portalTime = 0;
1825  }
1826  }
1827 
1828  if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
1829  $this->teleport($ev->getTo());
1830  }else{
1831  $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
1832  }
1833 
1834  if($this->fishingHook instanceof FishingHook){
1835  if($this->distance($this->fishingHook) > 33 or $this->inventory->getItemInHand()->getId() !== Item::FISHING_ROD){
1836  $this->setFishingHook();
1837  }
1838  }
1839  }
1840  }
1841 
1842  if(!$this->isSpectator()){
1843  $this->checkNearEntities($tickDiff);
1844  }
1845 
1846  $this->speed = ($to->subtract($from))->divide($tickDiff);
1847  }elseif($distanceSquared == 0){
1848  $this->speed = new Vector3(0, 0, 0);
1849  $this->setMoving(false);
1850  }
1851 
1852  if($revert){
1853 
1854  $this->lastX = $from->x;
1855  $this->lastY = $from->y;
1856  $this->lastZ = $from->z;
1857 
1858  $this->lastYaw = $from->yaw;
1859  $this->lastPitch = $from->pitch;
1860 
1861  $this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET);
1862  $this->forceMovement = new Vector3($from->x, $from->y, $from->z);
1863  }else{
1864  $this->forceMovement = null;
1865  if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
1866  $this->nextChunkOrderRun = 20;
1867  }
1868  }
1869 
1870  $this->newPosition = null;
1871  }

◆ recalculatePermissions()

recalculatePermissions ( )
Returns
void

Implements Permissible.

717  {
718  $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
719  $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
720 
721  if($this->perm === null){
722  return;
723  }
724 
725  $this->perm->recalculatePermissions();
726 
728  $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
729  }
731  $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
732  }
733 
734  $this->sendCommandData();
735  }

◆ removeAchievement()

removeAchievement (   $achievementId)
Parameters
string$achievementId
801  {
802  if($this->hasAchievement($achievementId)){
803  $this->achievements[$achievementId] = false;
804  }
805  }

◆ removeAttachment()

removeAttachment ( PermissionAttachment  $attachment)
Parameters
PermissionAttachment$attachment
Returns
bool

Implements Permissible.

709  {
710  if($this->perm == null){
711  return false;
712  }
713  $this->perm->removeAttachment($attachment);
714  return true;
715  }

◆ removeCreativeItem()

removeCreativeItem ( Item  $item)
Parameters
Item$item
2157  {
2158  $index = $this->getCreativeItemIndex($item);
2159  if($index !== -1){
2160  unset($this->personalCreativeItems[$index]);
2161  }
2162  }

◆ removeMetadata()

removeMetadata (   $metadataKey,
Plugin  $plugin 
)
Parameters
string$metadataKey
Plugin$plugin

Implements Metadatable.

4599  {
4600  $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
4601  }

◆ removeTitles()

removeTitles ( )

Removes the title from the client's screen.

3831  {
3832  $pk = new SetTitlePacket();
3833  $pk->type = SetTitlePacket::TYPE_CLEAR;
3834  $this->dataPacket($pk);
3835  }

◆ removeWindow()

removeWindow ( Inventory  $inventory)
Parameters
Inventory$inventory
4560  {
4561  $inventory->close($this);
4562  if($this->windows->contains($inventory)){
4563  $id = $this->windows[$inventory];
4564  $this->windows->detach($this->windowIndex[$id]);
4565  unset($this->windowIndex[$id]);
4566  }
4567  }

◆ resetFallDistance()

resetFallDistance ( )
608  {
609  parent::resetFallDistance();
610  if($this->inAirTicks !== 0){
611  $this->startAirTicks = 5;
612  }
613  $this->inAirTicks = 0;
614  }

◆ save()

save (   $async = false)

Handles player data saving

Parameters
bool$async
4105  {
4106  if($this->closed){
4107  throw new \InvalidStateException("Tried to save closed player");
4108  }
4109 
4110  parent::saveNBT();
4111  if($this->level instanceof Level){
4112  $this->namedtag->Level = new StringTag("Level", $this->level->getName());
4113  if($this->hasValidSpawnPosition()){
4114  $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName();
4115  $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
4116  $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
4117  $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
4118  }
4119 
4120  foreach($this->achievements as $achievement => $status){
4121  $this->namedtag->Achievements[$achievement] = new ByteTag($achievement, $status === true ? 1 : 0);
4122  }
4123 
4124  $this->namedtag["playerGameType"] = $this->gamemode;
4125  $this->namedtag["lastPlayed"] = new LongTag("lastPlayed", floor(microtime(true) * 1000));
4126  $this->namedtag["Health"] = new ShortTag("Health", $this->getHealth());
4127  $this->namedtag["MaxHealth"] = new ShortTag("MaxHealth", $this->getMaxHealth());
4128 
4129  if($this->username != "" and $this->namedtag instanceof CompoundTag){
4130  $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
4131  }
4132  }
4133  }

◆ sendActionBar()

sendActionBar ( string  $title,
string  $subtitle = "",
int  $fadeIn = -1,
int  $stay = -1,
int  $fadeOut = -1 
)

Adds a title text to the user's screen, with an optional subtitle.

Parameters
string$title
string$subtitle
int$fadeInDuration in ticks for fade-in. If -1 is given, client-sided defaults will be used.
int$stayDuration in ticks to stay on screen for
int$fadeOutDuration in ticks for fade-out.
3795  {
3796  $this->setTitleDuration($fadeIn, $stay, $fadeOut);
3797  if($subtitle !== ""){
3798  $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SUB_TITLE);
3799  }
3800  $this->sendTitleText($title, SetTitlePacket::TYPE_TITLE);
3801  }

◆ sendAttributes()

sendAttributes ( bool  $sendAll = false)
Parameters
bool$sendAll
1929  {
1930  $entries = $sendAll ? $this->attributeMap->getAll() : $this->attributeMap->needSend();
1931  if(count($entries) > 0){
1932  $pk = new UpdateAttributesPacket();
1933  $pk->entityId = $this->id;
1934  $pk->entries = $entries;
1935  $this->dataPacket($pk);
1936  foreach($entries as $entry){
1937  $entry->markSynchronized();
1938  }
1939  }
1940  }

◆ sendChunk()

sendChunk (   $x,
  $z,
  $payload 
)
Parameters
$x
$z
$payload
981  {
982  if($this->connected === false){
983  return;
984  }
985 
986  $this->usedChunks[Level::chunkHash($x, $z)] = true;
987  $this->chunkLoadCount++;
988 
989  if($payload instanceof DataPacket){
990  $this->dataPacket($payload);
991  }else{
992  $pk = new FullChunkDataPacket();
993  $pk->chunkX = $x;
994  $pk->chunkZ = $z;
995  $pk->data = $payload;
996  $this->batchDataPacket($pk);
997  }
998 
999  if($this->spawned){
1000  foreach($this->level->getChunkEntities($x, $z) as $entity){
1001  if($entity !== $this and !$entity->closed and $entity->isAlive()){
1002  $entity->spawnTo($this);
1003  }
1004  }
1005  }
1006  }

◆ sendCommandData()

sendCommandData ( )
744  {
745  $data = new \stdClass();
746  $count = 0;
747  foreach($this->server->getCommandMap()->getCommands() as $command){
748  //if($this->hasPermission($command->getPermission()) or $command->getPermission() == null) {
749  if (($cmdData = $command->generateCustomCommandData($this)) !== null){
750  ++$count;
751  $data->{$command->getName()}->versions[0] = $cmdData;
752  }
753  //}
754  }
755 
756  if($count > 0){
757  //TODO: structure checking
758  $pk = new AvailableCommandsPacket();
759  $pk->commands = json_encode($data);
760  $this->dataPacket($pk);
761  }
762  }

◆ sendGamemode()

sendGamemode ( )
1524  {
1525  $pk = new SetPlayerGameTypePacket();
1526  $pk->gamemode = Player::getClientFriendlyGamemode($this->gamemode);
1527  $this->dataPacket($pk);
1528  }

◆ sendMessage()

sendMessage (   $message)

Sends a direct chat message to a player

Parameters
string | TextContainer$message
Returns
bool

Implements CommandSender.

3886  {
3887  if($message instanceof TextContainer){
3888  if($message instanceof TranslationContainer){
3889  $this->sendTranslation($message->getText(), $message->getParameters());
3890  return false;
3891  }
3892 
3893  $message = $message->getText();
3894  }
3895 
3896  //TODO: Remove this workaround (broken client MCPE 1.0.0)
3897  $this->messageQueue[] = $this->server->getLanguage()->translateString($message);
3898  /*
3899  $pk = new TextPacket();
3900  $pk->type = TextPacket::TYPE_RAW;
3901  $pk->message = $this->server->getLanguage()->translateString($message);
3902  $this->dataPacket($pk);
3903  */
3904  }

◆ sendNextChunk()

sendNextChunk ( )
protected
1008  {
1009  if($this->connected === false){
1010  return;
1011  }
1012 
1013  Timings::$playerChunkSendTimer->startTiming();
1014 
1015  $count = 0;
1016  foreach($this->loadQueue as $index => $distance){
1017  if($count >= $this->chunksPerTick){
1018  break;
1019  }
1020 
1021  $X = null;
1022  $Z = null;
1023  Level::getXZ($index, $X, $Z);
1024 
1025  ++$count;
1026 
1027  $this->usedChunks[$index] = false;
1028  $this->level->registerChunkLoader($this, $X, $Z, false);
1029 
1030  if(!$this->level->populateChunk($X, $Z)){
1031  continue;
1032  }
1033 
1034  unset($this->loadQueue[$index]);
1035  $this->level->requestChunk($X, $Z, $this);
1036  }
1037 
1038  if($this->chunkLoadCount >= $this->spawnThreshold and $this->spawned === false and $this->teleportPosition === null){
1039  $this->doFirstSpawn();
1040  }
1041 
1042  Timings::$playerChunkSendTimer->stopTiming();
1043  }

◆ sendPopup()

sendPopup (   $message,
  $subtitle = "" 
)
Parameters
$message
string$subtitle
Returns
bool
3941  {
3942  $ev = new PlayerTextPreSendEvent($this, $message, PlayerTextPreSendEvent::POPUP);
3943  $this->server->getPluginManager()->callEvent($ev);
3944  if(!$ev->isCancelled()){
3945  $pk = new TextPacket();
3946  $pk->type = TextPacket::TYPE_POPUP;
3947  $pk->source = $ev->getMessage();
3948  $pk->message = $subtitle;
3949  $this->dataPacket($pk);
3950  return true;
3951  }
3952  return false;
3953  }

◆ sendPosition()

sendPosition ( Vector3  $pos,
  $yaw = null,
  $pitch = null,
  $mode = MovePlayerPacket::MODE_NORMAL,
array  $targets = null 
)
Parameters
Vector3$pos
null$yaw
null$pitch
int$mode
array | null$targets
4360  {
4361  $yaw = $yaw === null ? $this->yaw : $yaw;
4362  $pitch = $pitch === null ? $this->pitch : $pitch;
4363 
4364  $pk = new MovePlayerPacket();
4365  $pk->eid = $this->getId();
4366  $pk->x = $pos->x;
4367  $pk->y = $pos->y + $this->getEyeHeight();
4368  $pk->z = $pos->z;
4369  $pk->bodyYaw = $yaw;
4370  $pk->pitch = $pitch;
4371  $pk->yaw = $yaw;
4372  $pk->mode = $mode;
4373 
4374  if($targets !== null){
4375  $this->server->broadcastPacket($targets, $pk);
4376  }else{
4377  $this->dataPacket($pk);
4378  }
4379 
4380  $this->newPosition = null;
4381  }

◆ sendSettings()

sendSettings ( )

Sends all the option flags

1533  {
1534  $pk = new AdventureSettingsPacket();
1535  $pk->flags = 0;
1536  $pk->worldImmutable = $this->isAdventure();
1537  $pk->autoJump = $this->autoJump;
1538  $pk->allowFlight = $this->allowFlight;
1539  $pk->noClip = $this->isSpectator();
1540  $pk->worldBuilder = !($this->isAdventure());
1541  $pk->isFlying = $this->flying;
1543  $this->dataPacket($pk);
1544  }

◆ sendTip()

sendTip (   $message)
Parameters
$message
Returns
bool
3960  {
3961  $ev = new PlayerTextPreSendEvent($this, $message, PlayerTextPreSendEvent::TIP);
3962  $this->server->getPluginManager()->callEvent($ev);
3963  if(!$ev->isCancelled()){
3964  $pk = new TextPacket();
3965  $pk->type = TextPacket::TYPE_TIP;
3966  $pk->message = $ev->getMessage();
3967  $this->dataPacket($pk);
3968  return true;
3969  }
3970  return false;
3971  }

◆ sendTitle()

sendTitle (   $title,
  $subtitle = "",
  $fadein = 20,
  $fadeout = 20,
  $duration = 5 
)

Send a title text or/and with/without a sub title text to a player

Parameters
$title
string$subtitle
int$fadein
int$fadeout
int$duration
Returns
bool
3984  {
3985  return $this->addTitle($title, $subtitle, $fadein, $duration, $fadeout);
3986  }

◆ sendTitleText()

sendTitleText ( string  $title,
int  $type 
)
protected

Internal function used for sending titles.

Parameters
string$title
int$type
3861  {
3862  $pk = new SetTitlePacket();
3863  $pk->type = $type;
3864  $pk->title = $title;
3865  $this->dataPacket($pk);
3866  }

◆ sendTranslation()

sendTranslation (   $message,
array  $parameters = [] 
)
Parameters
$message
array$parameters
Returns
bool
3912  {
3913  $pk = new TextPacket();
3914  if(!$this->server->isLanguageForced()){
3915  $pk->type = TextPacket::TYPE_TRANSLATION;
3916  $pk->message = $this->server->getLanguage()->translateString($message, $parameters, "pocketmine.");
3917  foreach($parameters as $i => $p){
3918  $parameters[$i] = $this->server->getLanguage()->translateString($p, $parameters, "pocketmine.");
3919  }
3920  $pk->parameters = $parameters;
3921  }else{
3922  $pk->type = TextPacket::TYPE_RAW;
3923  $pk->message = $this->server->getLanguage()->translateString($message, $parameters);
3924  }
3925 
3926  $ev = new PlayerTextPreSendEvent($this, $pk->message, PlayerTextPreSendEvent::TRANSLATED_MESSAGE);
3927  $this->server->getPluginManager()->callEvent($ev);
3928  if(!$ev->isCancelled()){
3929  $this->dataPacket($pk);
3930  return true;
3931  }
3932  return false;
3933  }

◆ setAllowFlight()

setAllowFlight (   $value)
Parameters
$value
466  {
467  $this->allowFlight = (bool) $value;
468  $this->sendSettings();
469  }

◆ setAllowInstaBreak()

setAllowInstaBreak ( bool  $value = false)
Parameters
bool$value
532  {
533  $this->allowInstaBreak = $value;
534  }

◆ setAllowMovementCheats()

setAllowMovementCheats ( bool  $value = false)
Parameters
bool$value
518  {
519  $this->allowMovementCheats = $value;
520  }

◆ setAutoJump()

setAutoJump (   $value)
Parameters
$value
496  {
497  $this->autoJump = $value;
498  $this->sendSettings();
499  }

◆ setBanned()

setBanned (   $value)
Parameters
bool$value

Implements IPlayer.

408  {
409  if($value === true){
410  $this->server->getNameBans()->addBan($this->getName(), null, null, null);
411  $this->kick(TextFormat::RED . "You have been banned");
412  }else{
413  $this->server->getNameBans()->remove($this->getName());
414  }
415  }

◆ setDataProperty()

setDataProperty (   $id,
  $type,
  $value 
)
Parameters
int$id
int$type
mixed$value
Returns
bool
1599  {
1600  if(parent::setDataProperty($id, $type, $value)){
1601  $this->sendData($this, [$id => $this->dataProperties[$id]]);
1602  return true;
1603  }
1604 
1605  return false;
1606  }

◆ setDisplayName()

setDisplayName (   $name)
Parameters
string$name
841  {
842  $this->displayName = $name;
843  if($this->spawned){
844  $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinId(), $this->getSkinData());
845  }
846  }

◆ setFishingHook()

setFishingHook ( FishingHook  $entity = null)
Parameters
FishingHook | null$entity
345  {
346  if($entity == null and $this->fishingHook instanceof FishingHook){
347  $this->fishingHook->close();
348  }
349  $this->fishingHook = $entity;
350  }

◆ setFlying()

setFlying ( bool  $value)
Parameters
bool$value
481  {
482  $this->flying = $value;
483  $this->sendSettings();
484  }

◆ setGamemode()

setGamemode ( int  $gm,
bool  $client = false 
)

Sets the gamemode, and if needed, kicks the Player.

Parameters
int$gm
bool$clientif the client made this change in their GUI
Returns
bool
1456  {
1457  if($gm < 0 or $gm > 3 or $this->gamemode === $gm){
1458  return false;
1459  }
1460 
1461  $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, $gm));
1462  if($ev->isCancelled()){
1463  if($client){ //gamemode change by client in the GUI
1464  $this->sendGamemode();
1465  }
1466  return false;
1467  }
1468 
1469  if($this->server->autoClearInv){
1470  $this->inventory->clearAll();
1471  }
1472 
1473  $this->gamemode = $gm;
1474 
1475  $this->allowFlight = $this->isCreative();
1476  if($this->isSpectator()){
1477  $this->flying = true;
1478  $this->despawnFromAll();
1479 
1480  // Client automatically turns off flight controls when on the ground.
1481  // A combination of this hack and a new AdventureSettings flag FINALLY
1482  // fixes spectator flight controls. Thank @robske110 for this hack.
1483  $this->teleport($this->temporalVector->setComponents($this->x, $this->y + 0.1, $this->z));
1484  }else{
1485  if($this->isSurvival()){
1486  $this->flying = false;
1487  }
1488  $this->spawnToAll();
1489  }
1490 
1491  $this->resetFallDistance();
1492 
1493  $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode);
1494 
1495  if(!$client){ //Gamemode changed by server, do not send for client changes
1496  $this->sendGamemode();
1497  }else{
1498  Command::broadcastCommandMessage($this, new TranslationContainer("commands.gamemode.success.self", [Server::getGamemodeString($gm)]));
1499  }
1500 
1501  if($this->gamemode === Player::SPECTATOR){
1502  $pk = new ContainerSetContentPacket();
1504  $this->dataPacket($pk);
1505  }else{
1506  $pk = new ContainerSetContentPacket();
1508  $pk->slots = array_merge(Item::getCreativeItems(), $this->personalCreativeItems);
1509  $this->dataPacket($pk);
1510  }
1511 
1512  $this->sendSettings();
1513 
1514  $this->inventory->sendContents($this);
1515  $this->inventory->sendContents($this->getViewers());
1516  $this->inventory->sendHeldItem($this->hasSpawned);
1517  return true;
1518  }

◆ setHealth()

setHealth (   $amount)
Parameters
int$amount
4307  {
4308  parent::setHealth($amount);
4309  if($this->spawned === true){
4310  $this->foodTick = 0;
4311  $this->getAttributeMap()->getAttribute(Attribute::HEALTH)->setMaxValue($this->getMaxHealth())->setValue($amount, true);
4312  }
4313  }

◆ setMetadata()

setMetadata (   $metadataKey,
MetadataValue  $metadataValue 
)
Parameters
string$metadataKey
MetadataValue$metadataValue

Implements Metadatable.

4573  {
4574  $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
4575  }

◆ setMotion()

setMotion ( Vector3  $mot)
Parameters
Vector3$mot
Returns
bool
1878  {
1879  if(parent::setMotion($mot)){
1880  if($this->chunk !== null){
1881  $this->level->addEntityMotion($this->chunk->getX(), $this->chunk->getZ(), $this->getId(), $this->motionX, $this->motionY, $this->motionZ);
1882  $pk = new SetEntityMotionPacket();
1883  $pk->eid = $this->id;
1884  $pk->motionX = $mot->x;
1885  $pk->motionY = $mot->y;
1886  $pk->motionZ = $mot->z;
1887  $this->dataPacket($pk);
1888  }
1889 
1890  if($this->motionY > 0){
1891  $this->startAirTicks = (-(log($this->gravity / ($this->gravity + $this->drag * $this->motionY))) / $this->drag) * 2 + 5;
1892  }
1893 
1894  return true;
1895  }
1896  return false;
1897  }

◆ setMoving()

setMoving (   $moving)
Parameters
$moving
1915  {
1916  $this->moving = $moving;
1917  }

◆ setOp()

setOp (   $value)
Parameters
bool$value

Implements ServerOperator.

653  {
654  if($value === $this->isOp()){
655  return;
656  }
657 
658  if($value === true){
659  $this->server->addOp($this->getName());
660  }else{
661  $this->server->removeOp($this->getName());
662  }
663 
664  $this->recalculatePermissions();
665  $this->sendSettings();
666  }

◆ setRemoveFormat()

setRemoveFormat (   $remove = true)
Parameters
bool$remove
562  {
563  $this->removeFormat = (bool) $remove;
564  }

◆ setSkin()

setSkin (   $str,
  $skinId 
)
Parameters
string$str
string$skinId
852  {
853  parent::setSkin($str, $skinId);
854  if($this->spawned){
855  $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinId, $str);
856  }
857  }

◆ setSpawn()

setSpawn ( Vector3  $pos)

Sets the spawnpoint of the player (and the compass direction) to a Vector3, or set it on another world with a Position object

Parameters
Vector3 | Position$pos
1361  {
1362  if(!($pos instanceof Position)){
1363  $level = $this->level;
1364  }else{
1365  $level = $pos->getLevel();
1366  }
1367  $this->spawnPosition = new WeakPosition($pos->x, $pos->y, $pos->z, $level);
1368  $pk = new SetSpawnPositionPacket();
1369  $pk->x = (int) $this->spawnPosition->x;
1370  $pk->y = (int) $this->spawnPosition->y;
1371  $pk->z = (int) $this->spawnPosition->z;
1372  $this->dataPacket($pk);
1373  }

◆ setTitleDuration()

setTitleDuration ( int  $fadeIn,
int  $stay,
int  $fadeOut 
)

Sets the title duration.

Parameters
int$fadeInTitle fade-in time in ticks.
int$stayTitle stay time in ticks.
int$fadeOutTitle fade-out time in ticks.
3844  {
3845  if($fadeIn >= 0 and $stay >= 0 and $fadeOut >= 0){
3846  $pk = new SetTitlePacket();
3847  $pk->type = SetTitlePacket::TYPE_TIMES;
3848  $pk->fadeInDuration = $fadeIn;
3849  $pk->duration = $stay;
3850  $pk->fadeOutDuration = $fadeOut;
3851  $this->dataPacket($pk);
3852  }
3853  }

◆ setViewDistance()

setViewDistance ( int  $distance)
Parameters
int$distance
626  {
627  $this->viewDistance = $this->server->getAllowedViewDistance($distance);
628 
629  $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getProperty("chunk-sending.spawn-radius", 4)) ** 2 * M_PI);
630 
631  $pk = new ChunkRadiusUpdatedPacket();
632  $pk->radius = $this->viewDistance;
633  $this->dataPacket($pk);
634  }

◆ setWhitelisted()

setWhitelisted (   $value)
Parameters
bool$value

Implements IPlayer.

427  {
428  if($value === true){
429  $this->server->addWhitelist(strtolower($this->getName()));
430  }else{
431  $this->server->removeWhitelist(strtolower($this->getName()));
432  }
433  }

◆ showPlayer()

showPlayer ( Player  $player)
Parameters
Player$player
589  {
590  if($player === $this){
591  return;
592  }
593  unset($this->hiddenPlayers[$player->getRawUniqueId()]);
594  if($player->isOnline()){
595  $player->spawnTo($this);
596  }
597  }

◆ sleepOn()

sleepOn ( Vector3  $pos)
Parameters
Vector3$pos
Returns
boolean
1324  {
1325  if(!$this->isOnline()){
1326  return false;
1327  }
1328 
1329  foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
1330  if($p instanceof Player){
1331  if($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1){
1332  return false;
1333  }
1334  }
1335  }
1336 
1337  $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
1338  if($ev->isCancelled()){
1339  return false;
1340  }
1341 
1342  $this->sleeping = clone $pos;
1343 
1344  $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
1345  $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true, self::DATA_TYPE_BYTE);
1346 
1347  $this->setSpawn($pos);
1348 
1349  $this->level->sleepTicks = 60;
1350 
1351 
1352  return true;
1353  }

◆ spawnTo()

spawnTo ( Player  $player)
Parameters
Player$player
539  {
540  if($this->spawned and $player->spawned and $this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){
541  parent::spawnTo($player);
542  }
543  }

◆ stopSleep()

stopSleep ( )
1375  {
1376  if($this->sleeping instanceof Vector3){
1377  $this->server->getPluginManager()->callEvent($ev = new PlayerBedLeaveEvent($this, $this->level->getBlock($this->sleeping)));
1378 
1379  $this->sleeping = null;
1380  $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]);
1381  $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE);
1382 
1383 
1384  $this->level->sleepTicks = 0;
1385 
1386  $pk = new AnimatePacket();
1387  $pk->eid = $this->id;
1388  $pk->action = PlayerAnimationEvent::WAKE_UP;
1389  $this->dataPacket($pk);
1390  }
1391 
1392  }

◆ switchLevel()

switchLevel ( Level  $targetLevel)
protected
Parameters
Level$targetLevel
Returns
bool|void
901  {
902  $oldLevel = $this->level;
903  if(parent::switchLevel($targetLevel)){
904  foreach($this->usedChunks as $index => $d){
905  Level::getXZ($index, $X, $Z);
906  $this->unloadChunk($X, $Z, $oldLevel);
907  }
908 
909  $this->usedChunks = [];
910  $pk = new SetTimePacket();
911  $pk->time = $this->level->getTime();
912  $pk->started = $this->level->stopTime == false;
913  $this->dataPacket($pk);
914 
915  if($targetLevel->getDimension() != $oldLevel->getDimension()){
916  $pk = new ChangeDimensionPacket();
917  $pk->dimension = $targetLevel->getDimension();
918  $pk->x = $this->x;
919  $pk->y = $this->y;
920  $pk->z = $this->z;
921  $this->dataPacket($pk);
922  //$this->shouldSendStatus = true;
923  $pk1 = new PlayStatusPacket();
924  $pk1->status = PlayStatusPacket::PLAYER_SPAWN;
925  $this->dataPacket($pk1);
926  }
927  $targetLevel->getWeather()->sendWeather($this);
928 
929  if($this->spawned){
930  $this->spawnToAll();
931  }
932  }
933  }

◆ teleport()

teleport ( Vector3  $pos,
  $yaw = null,
  $pitch = null 
)
Parameters
Vector3 | Position | Location$pos
float$yaw
float$pitch
Returns
bool
4452  {
4453  if(!$this->isOnline()){
4454  return false;
4455  }
4456 
4457  $oldPos = $this->getPosition();
4458  if(parent::teleport($pos, $yaw, $pitch)){
4459 
4460  foreach($this->windowIndex as $window){
4461  if($window === $this->inventory){
4462  continue;
4463  }
4464  $this->removeWindow($window);
4465  }
4466 
4467  $this->teleportPosition = new Vector3($this->x, $this->y, $this->z);
4468 
4469  if(!$this->checkTeleportPosition()){
4470  $this->forceMovement = $oldPos;
4471  }else{
4472  $this->spawnToAll();
4473  }
4474 
4475 
4476  $this->resetFallDistance();
4477  $this->nextChunkOrderRun = 0;
4478  $this->newPosition = null;
4479  $this->stopSleep();
4480  return true;
4481  }
4482  return false;
4483  }

◆ teleportImmediate()

teleportImmediate ( Vector3  $pos,
  $yaw = null,
  $pitch = null 
)

This method may not be reliable. Clients don't like to be moved into unloaded chunks. Use teleport() for a delayed teleport after chunks have been sent.

Parameters
Vector3$pos
float$yaw
float$pitch
4493  {
4494  if(parent::teleport($pos, $yaw, $pitch)){
4495 
4496  foreach($this->windowIndex as $window){
4497  if($window === $this->inventory){
4498  continue;
4499  }
4500  $this->removeWindow($window);
4501  }
4502 
4503  $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
4504  $this->sendPosition($this, $this->yaw, $this->pitch, MovePlayerPacket::MODE_RESET);
4505 
4506 
4507  $this->resetFallDistance();
4508  $this->orderChunks();
4509  $this->nextChunkOrderRun = 0;
4510  $this->newPosition = null;
4511  }
4512  }

◆ transfer()

transfer ( string  $address,
  $port 
)
Parameters
string$address
$port
3872  {
3873  $pk = new TransferPacket();
3874  $pk->address = $address;
3875  $pk->port = $port;
3876  $this->dataPacket($pk);
3877  }

◆ unlinkHookFromPlayer()

unlinkHookFromPlayer ( )
Returns
bool
316  {
317  if($this->fishingHook instanceof FishingHook){
318  $pk = new EntityEventPacket();
319  $pk->eid = $this->fishingHook->getId();
321  $this->server->broadcastPacket($this->level->getPlayers(), $pk);
322  $this->setFishingHook();
323  return true;
324  }
325  return false;
326  }

◆ updateMovement()

updateMovement ( )
protected
1900  {
1901 
1902  }

Field Documentation

◆ $achievements

$achievements = []

◆ $allowFlight

$allowFlight = false
protected

◆ $allowInstaBreak

$allowInstaBreak = false
protected

◆ $allowMovementCheats

$allowMovementCheats = false
protected

◆ $autoJump

$autoJump = true
protected

◆ $chunkLoadCount

$chunkLoadCount = 0
protected

◆ $chunksPerTick

$chunksPerTick
protected

◆ $clientID

$clientID = null
protected

◆ $connected

$connected = true
protected

◆ $craftingType

$craftingType = self::CRAFTING_SMALL

◆ $creationTime

$creationTime = 0

◆ $deviceModel

$deviceModel
protected

◆ $deviceOS

$deviceOS
protected

◆ $displayName

$displayName
protected

◆ $fishingHook

$fishingHook = null

◆ $flying

$flying = false
protected

◆ $foodTick

$foodTick = 0

◆ $foodUsageTime

$foodUsageTime = 0

◆ $forceMovement

$forceMovement = null
protected

◆ $fromPos

$fromPos = null

◆ $gamemode

$gamemode

◆ $hiddenPlayers

$hiddenPlayers = []
protected

◆ $inAirTicks

$inAirTicks = 0
protected

◆ $interface

$interface
protected

◆ $ip

$ip
protected

◆ $iusername

$iusername
protected

◆ $lastBreak

$lastBreak

◆ $lastEnderPearlUse

$lastEnderPearlUse = 0
protected

◆ $loadQueue

$loadQueue = []
protected

◆ $loggedIn

$loggedIn = false

◆ $messageCounter

$messageCounter = 2
protected

◆ $moving

$moving = false
protected

◆ $newPosition

$newPosition
protected

◆ $nextChunkOrderRun

$nextChunkOrderRun = 5
protected

◆ $personalCreativeItems

$personalCreativeItems = []
protected

◆ $playedBefore

$playedBefore = false

◆ $port

$port
protected

◆ $protocol

$protocol
protected

◆ $randomClientId

$randomClientId
protected

◆ $removeFormat

$removeFormat = false
protected

◆ $selectedLev

$selectedLev = []

◆ $selectedPos

$selectedPos = []

◆ $shouldSendStatus

$shouldSendStatus = false
protected

◆ $sleeping

$sleeping = null
protected

◆ $spawned

$spawned = false

◆ $spawnThreshold

$spawnThreshold
protected

◆ $speed

$speed = null

◆ $startAction

$startAction = -1
protected

◆ $startAirTicks

$startAirTicks = 5
protected

◆ $starvationTick

$starvationTick = 0

◆ $stepHeight

$stepHeight = 0.6
protected

◆ $teleportPosition

$teleportPosition = null
protected

◆ $usedChunks

$usedChunks = []

◆ $username

$username
protected

◆ $viewDistance

$viewDistance = -1
protected

◆ $weatherData

$weatherData = [0, 0, 0]

◆ $windowCnt

$windowCnt = 2
protected

◆ $windowIndex

$windowIndex = []
protected

◆ $windows

$windows
protected

◆ ADVENTURE

const ADVENTURE = 2

◆ CRAFTING_ANVIL

const CRAFTING_ANVIL = 2

◆ CRAFTING_BIG

const CRAFTING_BIG = 1

◆ CRAFTING_ENCHANT

const CRAFTING_ENCHANT = 3

◆ CRAFTING_SMALL

const CRAFTING_SMALL = 0

◆ CREATIVE

const CREATIVE = 1

◆ SPECTATOR

const SPECTATOR = 3

◆ SURVIVAL

const SURVIVAL = 0

◆ VIEW

const VIEW = Player::SPECTATOR

The documentation for this class was generated from the following file: