001package com.ericlam.mc.minigames.core.event.player; 002 003import com.ericlam.mc.minigames.core.character.GamePlayer; 004import com.ericlam.mc.minigames.core.game.InGameState; 005 006import javax.annotation.Nullable; 007 008/** 009 * 遊戲玩家死亡事件 010 */ 011public class GamePlayerDeathEvent extends GamePlayerEvent { 012 013 private final GamePlayer killer; 014 private final DeathCause deathCause; 015 private final String action; 016 017 public GamePlayerDeathEvent(@Nullable GamePlayer killer, GamePlayer gamePlayer, DeathCause deathCause, InGameState state, String action) { 018 super(gamePlayer, state); 019 this.killer = killer; 020 this.deathCause = deathCause; 021 this.action = action; 022 } 023 024 /** 025 * @return 兇手 026 */ 027 @Nullable 028 public GamePlayer getKiller() { 029 return killer; 030 } 031 032 /** 033 * @return 死亡原因 034 * @see DeathCause 035 */ 036 public DeathCause getDeathCause() { 037 return deathCause; 038 } 039 040 041 /** 042 * 如何死亡 043 * <p> 044 * 例如, `燒死了`, `淹死了` 等等 045 * 046 * @return 如何死亡的訊息 047 */ 048 public String getAction() { 049 return action; 050 } 051 052 /** 053 * 死亡原因 054 */ 055 public enum DeathCause { 056 057 /** 058 * 槍械射死 059 * 060 * @see CrackShotDeathEvent 061 */ 062 CRACKSHOT, 063 064 /** 065 * 普通傷害 066 */ 067 BUKKIT_DAMAGE, 068 069 /** 070 * 普通殺害 071 */ 072 BUKKIT_KILL, 073 074 /** 075 * 普通死亡 076 */ 077 BUKKIT_DEATH, 078 079 /** 080 * 自定義 081 */ 082 CUSTOM; 083 084 private String value; 085 086 /** 087 * 創建自定義死亡的類型 088 * 089 * @param value 死亡原因 090 * @return 死亡類型 091 */ 092 public static DeathCause ofCustom(String value) { 093 CUSTOM.setValue(value); 094 return CUSTOM; 095 } 096 097 /** 098 * 獲取自定義死亡原因 099 * 100 * @return 死亡原因 101 */ 102 public String getValue() { 103 return this == CUSTOM ? value : this.toString().toLowerCase(); 104 } 105 106 /** 107 * 設置自定義死亡原因 108 * 109 * @param value 死亡原因 110 */ 111 private void setValue(String value) { 112 this.value = value; 113 } 114 } 115}