mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
PlayerInteractEvent: added APIs to independently control reaction of item and block (#4683)
This allows, for example, banning the usage of spawn eggs, without preventing opening of doors, without the need for item ID whitelists. It also allows customizing the behaviour of item and block interactions when sneaking - it's now possible to force spawn eggs to work when sneaking, or force containers to open. Finally, this also allows preventing any interaction at all without preventing block placement (by setting both to false). Since cancelling the event will typically prevent placement too (which might not be desired). Side note: Blocks are now always synced when right-clicking on a block. This differs from the previous behaviour, where the blocks were only synced when the action "failed". However, since this change introduces a situation where the action may succeed but have different results than the client expects, it's best to just always sync blocks in this situation. Fixes #3267
This commit is contained in:
@ -2173,19 +2173,25 @@ class World implements ChunkManager{
|
||||
|
||||
if($player !== null){
|
||||
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $face, PlayerInteractEvent::RIGHT_CLICK_BLOCK);
|
||||
if($player->isSneaking()){
|
||||
$ev->setUseItem(false);
|
||||
$ev->setUseBlock($item->isNull()); //opening doors is still possible when sneaking if using an empty hand
|
||||
}
|
||||
if($player->isSpectator()){
|
||||
$ev->cancel(); //set it to cancelled so plugins can bypass this
|
||||
}
|
||||
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
if((!$player->isSneaking() || $item->isNull()) && $blockClicked->onInteract($item, $face, $clickVector, $player, $returnedItems)){
|
||||
if($ev->useBlock() && $blockClicked->onInteract($item, $face, $clickVector, $player, $returnedItems)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$result = $item->onInteractBlock($player, $blockReplace, $blockClicked, $face, $clickVector, $returnedItems);
|
||||
if($result !== ItemUseResult::NONE){
|
||||
return $result === ItemUseResult::SUCCESS;
|
||||
if($ev->useItem()){
|
||||
$result = $item->onInteractBlock($player, $blockReplace, $blockClicked, $face, $clickVector, $returnedItems);
|
||||
if($result !== ItemUseResult::NONE){
|
||||
return $result === ItemUseResult::SUCCESS;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user