mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Added handling for attack-air action (#5912)
This commit is contained in:
parent
fb43f59458
commit
6086ef667c
39
src/event/player/PlayerMissedSwingEvent.php
Normal file
39
src/event/player/PlayerMissedSwingEvent.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 PlayerMissedSwingEvent 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){
|
||||
|
@ -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\PlayerMissedSwingEvent;
|
||||
use pocketmine\event\player\PlayerMoveEvent;
|
||||
use pocketmine\event\player\PlayerPostChunkSendEvent;
|
||||
use pocketmine\event\player\PlayerQuitEvent;
|
||||
@ -1894,6 +1895,18 @@ 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 play the no-damage attack sound and nothing else.
|
||||
*/
|
||||
public function missSwing() : void{
|
||||
$ev = new PlayerMissedSwingEvent($this);
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
$this->broadcastSound(new EntityAttackNoDamageSound());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interacts with the given entity using the currently-held item.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user