PlayerInteractEvent
PlayerInteractEvent는 플레이어의 액션하고 클릭블럭을 알아내는 이벤트입니다
코드로 이해를 해보도록 하겠습니다
@EventHandler
public void PlayerClickBlock(PlayerInteractEvent e) {
Player p =e.getPlayer(); // 플레이어가 액션을 취했을때 플레이어 저장 (Ex: 우클릭, 좌클릭 할때 저장)
Block b = e.getClickedBlock(); // 클릭한 블록
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) && b.getType().equals(Material.ACACIA_DOOR)) { // 만약 블럭을 왠쪽클릭을 하고 클릭한 블럭이 아카시아 문인가?
p.sendMessage("True");//맞다면 그 플레이어한테 True라는 메시지를 보낸다
}
}
PlayerInteractEvent e 로 플레이어가 한 행동을 각종 정보를 e에 담고 있습니다
e.getPlayer()로 행동을 한 플레이어를 저장하고
e.getClickedBlock() 클릭한 블럭을 저장합니다
equals로 비교를 합니다
만약 만약 블럭을 왠쪽클릭 블럭을 하고 클릭한 블럭이 아카시아 문인가?
를 확인하고 맞다면 그 플레이어한테 True라는 메시지를 보냅니다
아니면 메시지가 안오겠죠?
hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractEvent.html
PlayerInteractEvent (Spigot-API 1.16.3-R0.1-SNAPSHOT API)
Represents an event that is called when a player interacts with an object or air, potentially fired once for each hand. The hand can be determined using getHand(). This event will fire as cancelled if the vanilla behavior is to do nothing (e.g interacting
hub.spigotmc.org
spigot은 위에 문서를 참고해 주세요
댓글