mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Merge branch 'minor-next' into major-next
This commit is contained in:
commit
9997b614bc
2
.github/workflows/discord-release-notify.yml
vendored
2
.github/workflows/discord-release-notify.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup PHP and tools
|
||||
uses: shivammathur/setup-php@2.25.4
|
||||
uses: shivammathur/setup-php@2.25.5
|
||||
with:
|
||||
php-version: 8.1
|
||||
|
||||
|
2
.github/workflows/draft-release.yml
vendored
2
.github/workflows/draft-release.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
||||
submodules: true
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@2.25.4
|
||||
uses: shivammathur/setup-php@2.25.5
|
||||
with:
|
||||
php-version: 8.1
|
||||
|
||||
|
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -173,7 +173,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup PHP and tools
|
||||
uses: shivammathur/setup-php@2.25.4
|
||||
uses: shivammathur/setup-php@2.25.5
|
||||
with:
|
||||
php-version: 8.1
|
||||
tools: php-cs-fixer:3.17
|
||||
|
@ -30,3 +30,22 @@ Released 18th July 2023.
|
||||
|
||||
## Fixes
|
||||
- Fixed login errors due to a new `sandboxId` field appearing in the Xbox Live authentication data in `LoginPacket`. All clients, regardless of version, are affected by this change.
|
||||
|
||||
# 4.23.3
|
||||
Released 24th July 2023.
|
||||
|
||||
## Documentation
|
||||
- Fixed typo in `ChunkSelector::selectChunks()` documentation.
|
||||
|
||||
## Fixes
|
||||
- Fixed the server not stopping properly during crash conditions on *nix platforms.
|
||||
- Fixed `HORSE_EQUIP` and `SMITHING_TABLE_TEMPLATE` container UI types not being handled by `ItemStackContainerIdTranslator`. This bug prevented plugins from implementing missing inventory types.
|
||||
- Player emotes no longer broadcast messages to other players. This was unintended behaviour caused by a client-side behavioural change.
|
||||
- Shulker boxes no longer support the placement of torches or other similar blocks.
|
||||
- Fire can now be placed on upper slabs and the top of upside-down stairs.
|
||||
|
||||
# 4.23.4
|
||||
Released 1st August 2023.
|
||||
|
||||
## Fixes
|
||||
- Fixed exponentially increasing lag when many hundreds of non-mergeable dropped items occupied the same space. This disproportionately affected SkyBlock servers due to large cactus farms using water to collect items together.
|
||||
|
@ -47,3 +47,35 @@ Released 18th July 2023.
|
||||
|
||||
## Internals
|
||||
- Armor pieces are no longer set back into the armor inventory if no change was made. This reduces the number of slot updates sent to clients, as well as avoiding unnecessary updates for armor pieces which have Unbreaking enchantments.
|
||||
|
||||
# 5.3.3
|
||||
Released 24th July 2023.
|
||||
|
||||
## Included releases
|
||||
**This release includes changes from the following releases:**
|
||||
- [4.23.3](https://github.com/pmmp/PocketMine-MP/blob/4.23.3/changelogs/4.23.md#4233) - Various bug fixes
|
||||
|
||||
## Fixes
|
||||
- Added a workaround for PM4 worlds with chunks corrupted by [Refaltor77/CustomItemAPI](https://github.com/Refaltor77/CustomItemAPI).
|
||||
- While this was not the fault of PocketMine-MP itself, a significant number of users were affected by this problem.
|
||||
- This error was not detected by PM4 due to missing validation of certain data which should not have existed in 1.12.
|
||||
- An error will now be logged when this corruption is detected, but the affected chunks should otherwise load normally.
|
||||
- Relaxed validation of expected 3D biome array counts per chunk in LevelDB worlds.
|
||||
- Vanilla Bedrock currently saves 24 palettes (and only 24 are required), but it saved 25, 32, or 64 biome palettes per chunk in older versions.
|
||||
- Core validation for these padding biomes was very strict, enforcing exact compliance with vanilla.
|
||||
- Since only 24 palettes are actually required, the remaining palettes may now be omitted irrespective of the chunk version.
|
||||
- An error will still be logged when this mistake is detected, but the affected chunks will otherwise load normally.
|
||||
- Fixed `/kill` not working on players who had (re)spawned in the 3 seconds immediately after (re)spawning (due to `noDamageTicks`).
|
||||
- Fixed `/kill` not working correctly for players with high levels of Health Boost or other health-altering effects.
|
||||
- Fixed netherite items being destroyed by lava.
|
||||
- Fireproof entities no longer display the burning animation when in fire or lava. This does not apply to creative players, who are immortal rather than being fireproof.
|
||||
- Fixed frosted ice melting in certain conditions which didn't match vanilla Bedrock.
|
||||
|
||||
# 5.3.4
|
||||
Released 1st August 2023.
|
||||
|
||||
## Included releases
|
||||
This release includes changes from the following releases:
|
||||
- [4.23.4](https://github.com/pmmp/PocketMine-MP/blob/4.23.4/changelogs/4.23.md#4234) - Item entity lag fix
|
||||
|
||||
This release contains no other significant changes.
|
||||
|
83
changelogs/5.4.md
Normal file
83
changelogs/5.4.md
Normal file
@ -0,0 +1,83 @@
|
||||
# 5.4.0
|
||||
Released 1st August 2023.
|
||||
|
||||
**For Minecraft: Bedrock Edition 1.20.10**
|
||||
|
||||
This is a minor feature update, including a handful of new gameplay features, new plugin APIs and improvements to error reporting.
|
||||
|
||||
**Plugin compatibility:** Plugins for previous 5.x versions will run unchanged on this release, unless they use internal APIs, reflection, or packages like the `pocketmine\network\mcpe` or `pocketmine\data` namespace.
|
||||
Do not update plugin minimum API versions unless you need new features added in this release.
|
||||
|
||||
**WARNING: If your plugin uses the `pocketmine\network\mcpe` namespace, you're not shielded by API change constraints.**
|
||||
Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you're using packets directly.
|
||||
|
||||
## General
|
||||
- Improved error reporting for async task and thread crashes.
|
||||
- Players may now have different creative inventories.
|
||||
|
||||
## Gameplay
|
||||
### General
|
||||
- Added support for 1.5-block height sneaking.
|
||||
- Fixed missing player arm swing and sounds when punching the air.
|
||||
|
||||
### Blocks
|
||||
- Implemented the following new blocks:
|
||||
- Big Dripleaf Head
|
||||
- Big Dripleaf Stem
|
||||
- Small Dripleaf
|
||||
- Acacia saplings now grow into acacia trees.
|
||||
- Fixed melon and pumpkin stems not attaching to the correct block when growing.
|
||||
- Various blocks now drop more items when mined with a compatible tool enchanted with Fortune.
|
||||
|
||||
### Items
|
||||
- Implemented Strong Slowness potion.
|
||||
- Implemented Fortune enchantment.
|
||||
|
||||
## API
|
||||
### `pocketmine\block`
|
||||
- The following new classes have been added:
|
||||
- `utils\FortuneDropHelper` - utility methods for calculating the drop counts for Fortune-affected blocks
|
||||
- The following new API methods have been added:
|
||||
- `protected Block->getAdjacentSupportType(int $facing) : utils\SupportType` - returns the type of support provided by the block in the given direction on the adjacent face
|
||||
|
||||
### `pocketmine\entity`
|
||||
- The following new API constants have been added:
|
||||
- `Living::DEFAULT_KNOCKBACK_FORCE`
|
||||
- `Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT`
|
||||
|
||||
### `pocketmine\entity\animation`
|
||||
- `ConsumingItemAnimation` now accepts `Living` instances instead of just `Human`.
|
||||
|
||||
### `pocketmine\event`
|
||||
- The following new classes have been added:
|
||||
- `PlayerMissSwingEvent` - called when the player attempts the attack action (left click on desktop) without any target
|
||||
- This is possible thanks to the introduction of new flags in `PlayerAuthInputPacket` in Bedrock 1.20.10
|
||||
- The following new API methods have been added:
|
||||
- `public EntityDamageByEntityEvent->getVerticalKnockBackLimit() : float`
|
||||
- `public EntityDamageByEntityEvent->setVerticalKnockBackLimit(float $verticalKnockBackLimit) : void` - sets the max vertical velocity that can result from the victim being knocked back
|
||||
|
||||
### `pocketmine\player`
|
||||
- The following new API methods have been added:
|
||||
- `public Player->getCreativeInventory() : pocketmine\inventory\CreativeInventory`
|
||||
- `public Player->setCreativeInventory(pocketmine\inventory\CreativeInventory $inventory) : void`
|
||||
- `public Player->missSwing() : void` - performs actions associated with the attack action when there is no target (see `PlayerMissSwingEvent`)
|
||||
|
||||
### `pocketmine\scheduler`
|
||||
- Cancellation functionality has been removed from `AsyncTask`, as it didn't make any sense and wasn't used by anything for what it was intended for.
|
||||
- It broke sequential task execution - later tasks might depend on state from earlier tasks
|
||||
- It didn't actually cancel the task anyway - at best, it prevented it from running, but couldn't interrupt it (though interrupting a task does not make sense either)
|
||||
- The following API methods have been deprecated, and their functionality has been removed:
|
||||
- `AsyncTask->hasCancelledRun()`
|
||||
- `AsyncTask->cancelRun()`
|
||||
|
||||
## Internals
|
||||
- Uncaught exceptions and fatal errors in `AsyncTask`, threads extending `pocketmine\thread\Thread`, and `pocketmine\thread\Worker` are now recorded in crashdumps, making it significantly easier to debug errors in these areas.
|
||||
- JWT signature DER <-> raw conversions are now handled in-house using code in `JwtUtils`
|
||||
- Due to the simplicity of the conversion and only requiring a tiny subset of the ASN.1 spec, it didn't make much sense to introduce another dependency.
|
||||
- `fgrosse/phpasn1` is no longer required. This package was abandoned by its author and only used by PocketMine-MP for this one purpose.
|
||||
- Various usages of `Closure::fromCallable()` have been replaced by PHP 8.1 first-class callable syntax.
|
||||
- Blocks requiring support shifted to a "can be supported at" model, rather than "can be supported by".
|
||||
- This model reduces repeated logic when placing and performing nearby block updates (no need to hardcode facing everywhere).
|
||||
- In addition, this change facilitates the use of the newly introduced `Block->getAdjacentSupportType()` API method, reducing boilerplate support-type checking code.
|
||||
- Bell block code has been simplified and cleaned up.
|
||||
- `TallGrass` and `DoubleTallGrass` now use a shared `TallGrassTrait` to reduce code duplication.
|
@ -93,6 +93,7 @@ use pocketmine\scheduler\AsyncPool;
|
||||
use pocketmine\snooze\SleeperHandler;
|
||||
use pocketmine\stats\SendUsageTask;
|
||||
use pocketmine\thread\log\AttachableThreadSafeLogger;
|
||||
use pocketmine\thread\ThreadCrashException;
|
||||
use pocketmine\thread\ThreadSafeClassLoader;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\timings\TimingsHandler;
|
||||
@ -1517,23 +1518,38 @@ class Server{
|
||||
$trace = $e->getTrace();
|
||||
}
|
||||
|
||||
$errstr = $e->getMessage();
|
||||
$errfile = $e->getFile();
|
||||
$errline = $e->getLine();
|
||||
//If this is a thread crash, this logs where the exception came from on the main thread, as opposed to the
|
||||
//crashed thread. This is intentional, and might be useful for debugging
|
||||
//Assume that the thread already logged the original exception with the correct stack trace
|
||||
$this->logger->logException($e, $trace);
|
||||
|
||||
if($e instanceof ThreadCrashException){
|
||||
$info = $e->getCrashInfo();
|
||||
$type = $info->getType();
|
||||
$errstr = $info->getMessage();
|
||||
$errfile = $info->getFile();
|
||||
$errline = $info->getLine();
|
||||
$printableTrace = $info->getTrace();
|
||||
$thread = $info->getThreadName();
|
||||
}else{
|
||||
$type = get_class($e);
|
||||
$errstr = $e->getMessage();
|
||||
$errfile = $e->getFile();
|
||||
$errline = $e->getLine();
|
||||
$printableTrace = Utils::printableTraceWithMetadata($trace);
|
||||
$thread = "Main";
|
||||
}
|
||||
|
||||
$errstr = preg_replace('/\s+/', ' ', trim($errstr));
|
||||
|
||||
$errfile = Filesystem::cleanPath($errfile);
|
||||
|
||||
$this->logger->logException($e, $trace);
|
||||
|
||||
$lastError = [
|
||||
"type" => get_class($e),
|
||||
"type" => $type,
|
||||
"message" => $errstr,
|
||||
"fullFile" => $e->getFile(),
|
||||
"file" => $errfile,
|
||||
"fullFile" => $errfile,
|
||||
"file" => Filesystem::cleanPath($errfile),
|
||||
"line" => $errline,
|
||||
"trace" => $trace
|
||||
"trace" => $printableTrace,
|
||||
"thread" => $thread
|
||||
];
|
||||
|
||||
global $lastExceptionError, $lastError;
|
||||
|
@ -31,7 +31,7 @@ use function str_repeat;
|
||||
|
||||
final class VersionInfo{
|
||||
public const NAME = "PocketMine-MP";
|
||||
public const BASE_VERSION = "5.3.3";
|
||||
public const BASE_VERSION = "5.4.1";
|
||||
public const IS_DEVELOPMENT_BUILD = true;
|
||||
public const BUILD_CHANNEL = "stable";
|
||||
|
||||
|
@ -23,10 +23,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\FortuneDropHelper;
|
||||
use pocketmine\block\utils\TallGrassTrait;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class DoubleTallGrass extends DoublePlant{
|
||||
use TallGrassTrait {
|
||||
getDropsForIncompatibleTool as traitGetDropsForIncompatibleTool;
|
||||
}
|
||||
|
||||
public function canBeReplaced() : bool{
|
||||
return true;
|
||||
@ -34,7 +37,7 @@ class DoubleTallGrass extends DoublePlant{
|
||||
|
||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||
if($this->top){
|
||||
return FortuneDropHelper::grass($item);
|
||||
return $this->traitGetDropsForIncompatibleTool($item);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\FortuneDropHelper;
|
||||
use pocketmine\block\utils\TallGrassTrait;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -31,10 +31,7 @@ use pocketmine\player\Player;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
|
||||
class TallGrass extends Flowable{
|
||||
|
||||
public function canBeReplaced() : bool{
|
||||
return true;
|
||||
}
|
||||
use TallGrassTrait;
|
||||
|
||||
private function canBeSupportedBy(Block $block) : bool{
|
||||
return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD);
|
||||
@ -53,16 +50,4 @@ class TallGrass extends Flowable{
|
||||
$this->position->getWorld()->useBreakOn($this->position);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||
return FortuneDropHelper::grass($item);
|
||||
}
|
||||
|
||||
public function getFlameEncouragement() : int{
|
||||
return 60;
|
||||
}
|
||||
|
||||
public function getFlammability() : int{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use function max;
|
||||
use function min;
|
||||
use function mt_getrandmax;
|
||||
@ -85,26 +84,6 @@ final class FortuneDropHelper{
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grass have a fixed chance to drop wheat seed.
|
||||
* Fortune level increases the maximum number of seeds that can be dropped.
|
||||
* A discrete uniform distribution is used to determine the number of seeds dropped.
|
||||
*
|
||||
* TODO: I'm not sure this really belongs here, but it's preferable not to duplicate this code between grass and
|
||||
* tall grass.
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public static function grass(Item $usedItem) : array{
|
||||
if(FortuneDropHelper::bonusChanceDivisor($usedItem, 8, 2)){
|
||||
return [
|
||||
VanillaItems::WHEAT_SEEDS()
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the fortune level to the base max and picks a random number between the minimim and adjusted maximum.
|
||||
* Each amount in the range has an equal chance of being picked.
|
||||
|
54
src/block/utils/TallGrassTrait.php
Normal file
54
src/block/utils/TallGrassTrait.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
trait TallGrassTrait{
|
||||
public function canBeReplaced() : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||
if(FortuneDropHelper::bonusChanceDivisor($item, 8, 2)){
|
||||
return [
|
||||
VanillaItems::WHEAT_SEEDS()
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFlameEncouragement() : int{
|
||||
return 60;
|
||||
}
|
||||
|
||||
public function getFlammability() : int{
|
||||
return 100;
|
||||
}
|
||||
}
|
@ -29,11 +29,13 @@ use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\plugin\PluginManager;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\thread\ThreadCrashInfoFrame;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\VersionInfo;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function array_map;
|
||||
use function base64_encode;
|
||||
use function error_get_last;
|
||||
use function file;
|
||||
@ -186,7 +188,7 @@ class CrashDump{
|
||||
if($error === null){
|
||||
throw new \RuntimeException("Crash error information missing - did something use exit()?");
|
||||
}
|
||||
$error["trace"] = Utils::currentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
|
||||
$error["trace"] = Utils::printableTrace(Utils::currentTrace(3)); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
|
||||
$error["fullFile"] = $error["file"];
|
||||
$error["file"] = Filesystem::cleanPath($error["file"]);
|
||||
try{
|
||||
@ -201,9 +203,6 @@ class CrashDump{
|
||||
$error["message"] = mb_scrub($error["message"], 'UTF-8');
|
||||
|
||||
if(isset($lastError)){
|
||||
if(isset($lastError["trace"])){
|
||||
$lastError["trace"] = Utils::printableTrace($lastError["trace"]);
|
||||
}
|
||||
$this->data->lastError = $lastError;
|
||||
$this->data->lastError["message"] = mb_scrub($this->data->lastError["message"], 'UTF-8');
|
||||
}
|
||||
@ -215,10 +214,11 @@ class CrashDump{
|
||||
$this->data->plugin_involvement = self::PLUGIN_INVOLVEMENT_NONE;
|
||||
if(!$this->determinePluginFromFile($error["fullFile"], true)){ //fatal errors won't leave any stack trace
|
||||
foreach($error["trace"] as $frame){
|
||||
if(!isset($frame["file"])){
|
||||
$frameFile = $frame->getFile();
|
||||
if($frameFile === null){
|
||||
continue; //PHP core
|
||||
}
|
||||
if($this->determinePluginFromFile($frame["file"], false)){
|
||||
if($this->determinePluginFromFile($frameFile, false)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -233,7 +233,8 @@ class CrashDump{
|
||||
}
|
||||
}
|
||||
|
||||
$this->data->trace = Utils::printableTrace($error["trace"]);
|
||||
$this->data->trace = array_map(array: $error["trace"], callback: fn(ThreadCrashInfoFrame $frame) => $frame->getPrintableFrame());
|
||||
$this->data->thread = $error["thread"];
|
||||
}
|
||||
|
||||
private function determinePluginFromFile(string $filePath, bool $crashFrame) : bool{
|
||||
|
@ -37,6 +37,8 @@ final class CrashDumpData implements \JsonSerializable{
|
||||
/** @var mixed[] */
|
||||
public array $error;
|
||||
|
||||
public string $thread;
|
||||
|
||||
public string $plugin_involvement;
|
||||
|
||||
public string $plugin = "";
|
||||
|
@ -64,6 +64,7 @@ final class CrashDumpRenderer{
|
||||
|
||||
$this->addLine();
|
||||
|
||||
$this->addLine("Thread: " . $this->data->thread);
|
||||
$this->addLine("Error: " . $this->data->error["message"]);
|
||||
$this->addLine("File: " . $this->data->error["file"]);
|
||||
$this->addLine("Line: " . $this->data->error["line"]);
|
||||
|
@ -80,6 +80,17 @@ use const M_PI;
|
||||
abstract class Living extends Entity{
|
||||
protected const DEFAULT_BREATH_TICKS = 300;
|
||||
|
||||
/**
|
||||
* The default knockback multiplier when an entity is hit by another entity.
|
||||
* Larger values knock the entity back with increased velocity.
|
||||
*/
|
||||
public const DEFAULT_KNOCKBACK_FORCE = 0.4;
|
||||
/**
|
||||
* Limit of an entity's vertical knockback velocity when hit by another entity. Without this limit, the entity
|
||||
* may be knocked far up into the air with large knockback forces.
|
||||
*/
|
||||
public const DEFAULT_KNOCKBACK_VERTICAL_LIMIT = 0.4;
|
||||
|
||||
private const TAG_LEGACY_HEALTH = "HealF"; //TAG_Float
|
||||
private const TAG_HEALTH = "Health"; //TAG_Float
|
||||
private const TAG_BREATH_TICKS = "Air"; //TAG_Short
|
||||
@ -546,14 +557,14 @@ abstract class Living extends Entity{
|
||||
$e = $source->getChild();
|
||||
if($e !== null){
|
||||
$motion = $e->getMotion();
|
||||
$this->knockBack($motion->x, $motion->z, $source->getKnockBack());
|
||||
$this->knockBack($motion->x, $motion->z, $source->getKnockBack(), $source->getVerticalKnockBackLimit());
|
||||
}
|
||||
}elseif($source instanceof EntityDamageByEntityEvent){
|
||||
$e = $source->getDamager();
|
||||
if($e !== null){
|
||||
$deltaX = $this->location->x - $e->location->x;
|
||||
$deltaZ = $this->location->z - $e->location->z;
|
||||
$this->knockBack($deltaX, $deltaZ, $source->getKnockBack());
|
||||
$this->knockBack($deltaX, $deltaZ, $source->getKnockBack(), $source->getVerticalKnockBackLimit());
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,7 +578,7 @@ abstract class Living extends Entity{
|
||||
$this->broadcastAnimation(new HurtAnimation($this));
|
||||
}
|
||||
|
||||
public function knockBack(float $x, float $z, float $force = 0.4, ?float $verticalLimit = 0.4) : void{
|
||||
public function knockBack(float $x, float $z, float $force = self::DEFAULT_KNOCKBACK_FORCE, ?float $verticalLimit = self::DEFAULT_KNOCKBACK_VERTICAL_LIMIT) : void{
|
||||
$f = sqrt($x * $x + $z * $z);
|
||||
if($f <= 0){
|
||||
return;
|
||||
|
@ -123,7 +123,7 @@ class ItemEntity extends Entity{
|
||||
}
|
||||
}
|
||||
|
||||
if($this->hasMovementUpdate() && $this->despawnDelay % self::MERGE_CHECK_PERIOD === 0){
|
||||
if($this->hasMovementUpdate() && $this->isMergeCandidate() && $this->despawnDelay % self::MERGE_CHECK_PERIOD === 0){
|
||||
$mergeable = [$this]; //in case the merge target ends up not being this
|
||||
$mergeTarget = $this;
|
||||
foreach($this->getWorld()->getNearbyEntities($this->boundingBox->expandedCopy(0.5, 0.5, 0.5), $this) as $entity){
|
||||
@ -165,12 +165,19 @@ class ItemEntity extends Entity{
|
||||
}
|
||||
}
|
||||
|
||||
private function isMergeCandidate() : bool{
|
||||
return $this->pickupDelay !== self::NEVER_DESPAWN && $this->item->getCount() < $this->item->getMaxStackSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this item entity can merge with the given one.
|
||||
*/
|
||||
public function isMergeable(ItemEntity $entity) : bool{
|
||||
if(!$this->isMergeCandidate() || !$entity->isMergeCandidate()){
|
||||
return false;
|
||||
}
|
||||
$item = $entity->item;
|
||||
return $entity !== $this && $entity->pickupDelay !== self::NEVER_DESPAWN && $item->canStackWith($this->item) && $item->getCount() + $this->item->getCount() <= $item->getMaxStackSize();
|
||||
return $entity !== $this && $item->canStackWith($this->item) && $item->getCount() + $this->item->getCount() <= $item->getMaxStackSize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,15 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
||||
/**
|
||||
* @param float[] $modifiers
|
||||
*/
|
||||
public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], private float $knockBack = 0.4){
|
||||
public function __construct(
|
||||
Entity $damager,
|
||||
Entity $entity,
|
||||
int $cause,
|
||||
float $damage,
|
||||
array $modifiers = [],
|
||||
private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE,
|
||||
private float $verticalKnockBackLimit = Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
|
||||
){
|
||||
$this->damagerEntityId = $damager->getId();
|
||||
parent::__construct($entity, $cause, $damage, $modifiers);
|
||||
$this->addAttackerModifiers($damager);
|
||||
@ -62,11 +70,39 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
||||
return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->damagerEntityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the force with which the victim will be knocked back from the attacking entity.
|
||||
*
|
||||
* @see Living::DEFAULT_KNOCKBACK_FORCE
|
||||
*/
|
||||
public function getKnockBack() : float{
|
||||
return $this->knockBack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the force with which the victim will be knocked back from the attacking entity.
|
||||
* Larger values will knock the victim back further.
|
||||
* Negative values will pull the victim towards the attacker.
|
||||
*/
|
||||
public function setKnockBack(float $knockBack) : void{
|
||||
$this->knockBack = $knockBack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum upwards velocity the victim may have after being knocked back.
|
||||
* This ensures that the victim doesn't fly up into the sky when high levels of knockback are applied.
|
||||
*
|
||||
* @see Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
|
||||
*/
|
||||
public function getVerticalKnockBackLimit() : float{
|
||||
return $this->verticalKnockBackLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum upwards velocity the victim may have after being knocked back.
|
||||
* Larger values will allow the victim to fly higher if the knockback force is also large.
|
||||
*/
|
||||
public function setVerticalKnockBackLimit(float $verticalKnockBackLimit) : void{
|
||||
$this->verticalKnockBackLimit = $verticalKnockBackLimit;
|
||||
}
|
||||
}
|
||||
|
39
src/event/player/PlayerMissSwingEvent.php
Normal file
39
src/event/player/PlayerMissSwingEvent.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\player\Player;
|
||||
|
||||
/**
|
||||
* Called when a player attempts to perform the attack action (left-click) without a target entity.
|
||||
*/
|
||||
class PlayerMissSwingEvent extends PlayerEvent implements Cancellable{
|
||||
use CancellableTrait;
|
||||
|
||||
public function __construct(Player $player){
|
||||
$this->player = $player;
|
||||
}
|
||||
}
|
@ -236,6 +236,9 @@ class InGamePacketHandler extends PacketHandler{
|
||||
if($packet->hasFlag(PlayerAuthInputFlags::START_JUMPING)){
|
||||
$this->player->jump();
|
||||
}
|
||||
if($packet->hasFlag(PlayerAuthInputFlags::MISSED_SWING)){
|
||||
$this->player->missSwing();
|
||||
}
|
||||
}
|
||||
|
||||
if(!$this->forceMoveSync && $hasMoved){
|
||||
|
@ -39,6 +39,7 @@ use pocketmine\network\NetworkInterfaceStartException;
|
||||
use pocketmine\network\PacketHandlingException;
|
||||
use pocketmine\player\GameMode;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\thread\ThreadCrashException;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\utils\Utils;
|
||||
use raklib\generic\DisconnectReason;
|
||||
@ -154,7 +155,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
||||
if(!$this->rakLib->isRunning()){
|
||||
$e = $this->rakLib->getCrashInfo();
|
||||
if($e !== null){
|
||||
throw new \RuntimeException("RakLib crashed: " . $e->makePrettyMessage());
|
||||
throw new ThreadCrashException("RakLib crashed", $e);
|
||||
}
|
||||
throw new \Exception("RakLib Thread crashed without crash information");
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ use pocketmine\snooze\SleeperHandlerEntry;
|
||||
use pocketmine\thread\log\ThreadSafeLogger;
|
||||
use pocketmine\thread\NonThreadSafeValue;
|
||||
use pocketmine\thread\Thread;
|
||||
use pocketmine\thread\ThreadCrashException;
|
||||
use raklib\generic\SocketException;
|
||||
use raklib\server\ipc\RakLibToUserThreadMessageSender;
|
||||
use raklib\server\ipc\UserToRakLibThreadMessageReceiver;
|
||||
@ -37,17 +38,12 @@ use raklib\server\ServerSocket;
|
||||
use raklib\server\SimpleProtocolAcceptor;
|
||||
use raklib\utils\ExceptionTraceCleaner;
|
||||
use raklib\utils\InternetAddress;
|
||||
use function error_get_last;
|
||||
use function gc_enable;
|
||||
use function ini_set;
|
||||
use function register_shutdown_function;
|
||||
|
||||
class RakLibServer extends Thread{
|
||||
protected bool $cleanShutdown = false;
|
||||
protected bool $ready = false;
|
||||
protected string $mainPath;
|
||||
/** @phpstan-var NonThreadSafeValue<RakLibThreadCrashInfo>|null */
|
||||
public ?NonThreadSafeValue $crashInfo = null;
|
||||
/** @phpstan-var NonThreadSafeValue<InternetAddress> */
|
||||
protected NonThreadSafeValue $address;
|
||||
|
||||
@ -69,86 +65,51 @@ class RakLibServer extends Thread{
|
||||
$this->address = new NonThreadSafeValue($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function shutdownHandler(){
|
||||
if($this->cleanShutdown !== true && $this->crashInfo === null){
|
||||
$error = error_get_last();
|
||||
|
||||
if($error !== null){
|
||||
$this->logger->emergency("Fatal error: " . $error["message"] . " in " . $error["file"] . " on line " . $error["line"]);
|
||||
$this->setCrashInfo(RakLibThreadCrashInfo::fromLastErrorInfo($error));
|
||||
}else{
|
||||
$this->logger->emergency("RakLib shutdown unexpectedly");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getCrashInfo() : ?RakLibThreadCrashInfo{
|
||||
return $this->crashInfo?->deserialize();
|
||||
}
|
||||
|
||||
private function setCrashInfo(RakLibThreadCrashInfo $info) : void{
|
||||
$this->synchronized(function() use ($info) : void{
|
||||
$this->crashInfo = new NonThreadSafeValue($info);
|
||||
$this->notify();
|
||||
});
|
||||
}
|
||||
|
||||
public function startAndWait(int $options = NativeThread::INHERIT_NONE) : void{
|
||||
$this->start($options);
|
||||
$this->synchronized(function() : void{
|
||||
while(!$this->ready && $this->crashInfo === null){
|
||||
while(!$this->ready && $this->getCrashInfo() === null){
|
||||
$this->wait();
|
||||
}
|
||||
$crashInfo = $this->crashInfo?->deserialize();
|
||||
$crashInfo = $this->getCrashInfo();
|
||||
if($crashInfo !== null){
|
||||
if($crashInfo->getClass() === SocketException::class){
|
||||
if($crashInfo->getType() === SocketException::class){
|
||||
throw new SocketException($crashInfo->getMessage());
|
||||
}
|
||||
throw new \RuntimeException("RakLib failed to start: " . $crashInfo->makePrettyMessage());
|
||||
throw new ThreadCrashException("RakLib failed to start", $crashInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function onRun() : void{
|
||||
try{
|
||||
gc_enable();
|
||||
ini_set("display_errors", '1');
|
||||
ini_set("display_startup_errors", '1');
|
||||
gc_enable();
|
||||
ini_set("display_errors", '1');
|
||||
ini_set("display_startup_errors", '1');
|
||||
|
||||
register_shutdown_function([$this, "shutdownHandler"]);
|
||||
|
||||
try{
|
||||
$socket = new ServerSocket($this->address->deserialize());
|
||||
}catch(SocketException $e){
|
||||
$this->setCrashInfo(RakLibThreadCrashInfo::fromThrowable($e));
|
||||
return;
|
||||
}
|
||||
$manager = new Server(
|
||||
$this->serverId,
|
||||
$this->logger,
|
||||
$socket,
|
||||
$this->maxMtuSize,
|
||||
new SimpleProtocolAcceptor($this->protocolVersion),
|
||||
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
||||
new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->sleeperEntry->createNotifier())),
|
||||
new ExceptionTraceCleaner($this->mainPath)
|
||||
);
|
||||
$this->synchronized(function() : void{
|
||||
$this->ready = true;
|
||||
$this->notify();
|
||||
});
|
||||
while(!$this->isKilled){
|
||||
$manager->tickProcessor();
|
||||
}
|
||||
$manager->waitShutdown();
|
||||
$this->cleanShutdown = true;
|
||||
}catch(\Throwable $e){
|
||||
$this->setCrashInfo(RakLibThreadCrashInfo::fromThrowable($e));
|
||||
$this->logger->logException($e);
|
||||
$socket = new ServerSocket($this->address->deserialize());
|
||||
$manager = new Server(
|
||||
$this->serverId,
|
||||
$this->logger,
|
||||
$socket,
|
||||
$this->maxMtuSize,
|
||||
new SimpleProtocolAcceptor($this->protocolVersion),
|
||||
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
||||
new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->sleeperEntry->createNotifier())),
|
||||
new ExceptionTraceCleaner($this->mainPath)
|
||||
);
|
||||
$this->synchronized(function() : void{
|
||||
$this->ready = true;
|
||||
$this->notify();
|
||||
});
|
||||
while(!$this->isKilled){
|
||||
$manager->tickProcessor();
|
||||
}
|
||||
$manager->waitShutdown();
|
||||
}
|
||||
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
parent::onUncaughtException($e);
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
|
||||
public function getThreadName() : string{
|
||||
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\raklib;
|
||||
|
||||
use pocketmine\utils\Filesystem;
|
||||
use function get_class;
|
||||
use function sprintf;
|
||||
|
||||
final class RakLibThreadCrashInfo{
|
||||
|
||||
public function __construct(
|
||||
private ?string $class,
|
||||
private string $message,
|
||||
private string $file,
|
||||
private int $line
|
||||
){}
|
||||
|
||||
public static function fromThrowable(\Throwable $e) : self{
|
||||
return new self(get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param array{message: string, file: string, line: int} $info
|
||||
*/
|
||||
public static function fromLastErrorInfo(array $info) : self{
|
||||
return new self(null, $info["message"], $info["file"], $info["line"]);
|
||||
}
|
||||
|
||||
public function getClass() : ?string{ return $this->class; }
|
||||
|
||||
public function getMessage() : string{ return $this->message; }
|
||||
|
||||
public function getFile() : string{ return $this->file; }
|
||||
|
||||
public function getLine() : int{ return $this->line; }
|
||||
|
||||
public function makePrettyMessage() : string{
|
||||
return sprintf("%s: \"%s\" in %s on line %d", $this->class ?? "Fatal error", $this->message, Filesystem::cleanPath($this->file), $this->line);
|
||||
}
|
||||
}
|
@ -66,6 +66,7 @@ use pocketmine\event\player\PlayerItemUseEvent;
|
||||
use pocketmine\event\player\PlayerJoinEvent;
|
||||
use pocketmine\event\player\PlayerJumpEvent;
|
||||
use pocketmine\event\player\PlayerKickEvent;
|
||||
use pocketmine\event\player\PlayerMissSwingEvent;
|
||||
use pocketmine\event\player\PlayerMoveEvent;
|
||||
use pocketmine\event\player\PlayerPostChunkSendEvent;
|
||||
use pocketmine\event\player\PlayerQuitEvent;
|
||||
@ -1894,6 +1895,19 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs actions associated with the attack action (left-click) without a target entity.
|
||||
* Under normal circumstances, this will just play the no-damage attack sound and the arm-swing animation.
|
||||
*/
|
||||
public function missSwing() : void{
|
||||
$ev = new PlayerMissSwingEvent($this);
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
$this->broadcastSound(new EntityAttackNoDamageSound());
|
||||
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interacts with the given entity using the currently-held item.
|
||||
*/
|
||||
|
@ -26,6 +26,7 @@ namespace pocketmine\scheduler;
|
||||
use pmmp\thread\Thread as NativeThread;
|
||||
use pocketmine\snooze\SleeperHandler;
|
||||
use pocketmine\thread\log\ThreadSafeLogger;
|
||||
use pocketmine\thread\ThreadCrashException;
|
||||
use pocketmine\thread\ThreadSafeClassLoader;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
@ -215,12 +216,17 @@ class AsyncPool{
|
||||
}
|
||||
}
|
||||
}
|
||||
if($crashedTask !== null){
|
||||
$message = "Worker $workerId crashed while running task " . get_class($crashedTask) . "#" . spl_object_id($crashedTask);
|
||||
$info = $entry->worker->getCrashInfo();
|
||||
if($info !== null){
|
||||
if($crashedTask !== null){
|
||||
$message = "Worker $workerId crashed while running task " . get_class($crashedTask) . "#" . spl_object_id($crashedTask);
|
||||
}else{
|
||||
$message = "Worker $workerId crashed while doing unknown work";
|
||||
}
|
||||
throw new ThreadCrashException($message, $info);
|
||||
}else{
|
||||
$message = "Worker $workerId crashed for unknown reason";
|
||||
throw new \RuntimeException("Worker $workerId crashed for unknown reason");
|
||||
}
|
||||
throw new \RuntimeException($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ use pocketmine\thread\Worker;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use function gc_enable;
|
||||
use function ini_set;
|
||||
use function set_exception_handler;
|
||||
|
||||
class AsyncWorker extends Worker{
|
||||
/** @var mixed[] */
|
||||
@ -68,20 +67,17 @@ class AsyncWorker extends Worker{
|
||||
}
|
||||
|
||||
$this->saveToThreadStore(self::TLS_KEY_NOTIFIER, $this->sleeperEntry->createNotifier());
|
||||
}
|
||||
|
||||
set_exception_handler(function(\Throwable $e){
|
||||
$this->logger->logException($e);
|
||||
});
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
parent::onUncaughtException($e);
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
|
||||
public function getLogger() : ThreadSafeLogger{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
public function handleException(\Throwable $e) : void{
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
|
||||
public function getThreadName() : string{
|
||||
return "AsyncWorker#" . $this->id;
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ namespace pocketmine\thread;
|
||||
use pmmp\thread\ThreadSafeArray;
|
||||
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
||||
use pocketmine\Server;
|
||||
use function error_get_last;
|
||||
use function error_reporting;
|
||||
use function register_shutdown_function;
|
||||
use function set_exception_handler;
|
||||
|
||||
trait CommonThreadPartsTrait{
|
||||
/**
|
||||
@ -38,6 +41,8 @@ trait CommonThreadPartsTrait{
|
||||
|
||||
protected bool $isKilled = false;
|
||||
|
||||
private ?ThreadCrashInfo $crashInfo = null;
|
||||
|
||||
/**
|
||||
* @return ThreadSafeClassLoader[]
|
||||
*/
|
||||
@ -88,12 +93,48 @@ trait CommonThreadPartsTrait{
|
||||
}
|
||||
}
|
||||
|
||||
public function getCrashInfo() : ?ThreadCrashInfo{ return $this->crashInfo; }
|
||||
|
||||
final public function run() : void{
|
||||
error_reporting(-1);
|
||||
$this->registerClassLoaders();
|
||||
//set this after the autoloader is registered
|
||||
ErrorToExceptionHandler::set();
|
||||
|
||||
//this permits adding extra functionality to the exception and shutdown handlers via overriding
|
||||
set_exception_handler($this->onUncaughtException(...));
|
||||
register_shutdown_function($this->onShutdown(...));
|
||||
|
||||
$this->onRun();
|
||||
$this->isKilled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by set_exception_handler() when an uncaught exception is thrown.
|
||||
*/
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
$this->synchronized(function() use ($e) : void{
|
||||
$this->crashInfo = ThreadCrashInfo::fromThrowable($e, $this->getThreadName());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by register_shutdown_function() when the thread shuts down. This may be because of a benign shutdown, or
|
||||
* because of a fatal error. Use isKilled to determine which.
|
||||
*/
|
||||
protected function onShutdown() : void{
|
||||
$this->synchronized(function() : void{
|
||||
if(!$this->isKilled && $this->crashInfo === null){
|
||||
$last = error_get_last();
|
||||
if($last !== null){
|
||||
//fatal error
|
||||
$this->crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName());
|
||||
}else{
|
||||
//probably misused exit()
|
||||
$this->crashInfo = ThreadCrashInfo::fromThrowable(new \RuntimeException("Thread crashed without an error - perhaps exit() was called?"), $this->getThreadName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
38
src/thread/ThreadCrashException.php
Normal file
38
src/thread/ThreadCrashException.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\thread;
|
||||
|
||||
final class ThreadCrashException extends ThreadException{
|
||||
|
||||
private ThreadCrashInfo $crashInfo;
|
||||
|
||||
public function __construct(string $message, ThreadCrashInfo $crashInfo){
|
||||
parent::__construct($message);
|
||||
$this->crashInfo = $crashInfo;
|
||||
}
|
||||
|
||||
public function getCrashInfo() : ThreadCrashInfo{
|
||||
return $this->crashInfo;
|
||||
}
|
||||
}
|
89
src/thread/ThreadCrashInfo.php
Normal file
89
src/thread/ThreadCrashInfo.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\thread;
|
||||
|
||||
use pmmp\thread\ThreadSafe;
|
||||
use pmmp\thread\ThreadSafeArray;
|
||||
use pocketmine\errorhandler\ErrorTypeToStringMap;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\Utils;
|
||||
use function get_class;
|
||||
use function sprintf;
|
||||
|
||||
final class ThreadCrashInfo extends ThreadSafe{
|
||||
|
||||
/** @phpstan-var ThreadSafeArray<int, ThreadCrashInfoFrame> */
|
||||
private ThreadSafeArray $trace;
|
||||
|
||||
/**
|
||||
* @param ThreadCrashInfoFrame[] $trace
|
||||
*/
|
||||
public function __construct(
|
||||
private string $type,
|
||||
private string $message,
|
||||
private string $file,
|
||||
private int $line,
|
||||
array $trace,
|
||||
private string $threadName
|
||||
){
|
||||
$this->trace = ThreadSafeArray::fromArray($trace);
|
||||
}
|
||||
|
||||
public static function fromThrowable(\Throwable $e, string $threadName) : self{
|
||||
return new self(get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), Utils::printableTraceWithMetadata($e->getTrace()), $threadName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param array{type: int, message: string, file: string, line: int} $info
|
||||
*/
|
||||
public static function fromLastErrorInfo(array $info, string $threadName) : self{
|
||||
try{
|
||||
$class = ErrorTypeToStringMap::get($info["type"]);
|
||||
}catch(\InvalidArgumentException){
|
||||
$class = "Unknown error type (" . $info["type"] . ")";
|
||||
}
|
||||
return new self($class, $info["message"], $info["file"], $info["line"], Utils::printableTraceWithMetadata(Utils::currentTrace()), $threadName);
|
||||
}
|
||||
|
||||
public function getType() : string{ return $this->type; }
|
||||
|
||||
public function getMessage() : string{ return $this->message; }
|
||||
|
||||
public function getFile() : string{ return $this->file; }
|
||||
|
||||
public function getLine() : int{ return $this->line; }
|
||||
|
||||
/**
|
||||
* @return ThreadCrashInfoFrame[]
|
||||
*/
|
||||
public function getTrace() : array{
|
||||
return (array) $this->trace;
|
||||
}
|
||||
|
||||
public function getThreadName() : string{ return $this->threadName; }
|
||||
|
||||
public function makePrettyMessage() : string{
|
||||
return sprintf("%s: \"%s\" in \"%s\" on line %d", $this->type ?? "Fatal error", $this->message, Filesystem::cleanPath($this->file), $this->line);
|
||||
}
|
||||
}
|
41
src/thread/ThreadCrashInfoFrame.php
Normal file
41
src/thread/ThreadCrashInfoFrame.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\thread;
|
||||
|
||||
use pmmp\thread\ThreadSafe;
|
||||
|
||||
final class ThreadCrashInfoFrame extends ThreadSafe{
|
||||
|
||||
public function __construct(
|
||||
private string $printableFrame,
|
||||
private ?string $file,
|
||||
private int $line,
|
||||
){}
|
||||
|
||||
public function getPrintableFrame() : string{ return $this->printableFrame; }
|
||||
|
||||
public function getFile() : ?string{ return $this->file; }
|
||||
|
||||
public function getLine() : int{ return $this->line; }
|
||||
}
|
@ -31,6 +31,7 @@ use DaveRandom\CallbackValidator\CallbackType;
|
||||
use pocketmine\entity\Location;
|
||||
use pocketmine\errorhandler\ErrorTypeToStringMap;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\thread\ThreadCrashInfoFrame;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use function array_combine;
|
||||
@ -469,6 +470,30 @@ final class Utils{
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link Utils::printableTrace()}, but associates metadata such as file and line number with each frame.
|
||||
* This is used to transmit thread-safe information about crash traces to the main thread when a thread crashes.
|
||||
*
|
||||
* @param mixed[][] $rawTrace
|
||||
* @phpstan-param list<array<string, mixed>> $rawTrace
|
||||
*
|
||||
* @return ThreadCrashInfoFrame[]
|
||||
*/
|
||||
public static function printableTraceWithMetadata(array $rawTrace, int $maxStringLength = 80) : array{
|
||||
$printableTrace = self::printableTrace($rawTrace, $maxStringLength);
|
||||
$safeTrace = [];
|
||||
foreach($printableTrace as $frameId => $printableFrame){
|
||||
$rawFrame = $rawTrace[$frameId];
|
||||
$safeTrace[$frameId] = new ThreadCrashInfoFrame(
|
||||
$printableFrame,
|
||||
$rawFrame["file"] ?? "unknown",
|
||||
$rawFrame["line"] ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
return $safeTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[][]
|
||||
* @phpstan-return list<array<string, mixed>>
|
||||
|
@ -845,6 +845,16 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$file of class pocketmine\\\\thread\\\\ThreadCrashInfoFrame constructor expects string\\|null, mixed given\\.$#"
|
||||
count: 1
|
||||
path: ../../../src/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#3 \\$line of class pocketmine\\\\thread\\\\ThreadCrashInfoFrame constructor expects int, mixed given\\.$#"
|
||||
count: 1
|
||||
path: ../../../src/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#"
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user