use of org.bukkit.event.entity.EntityDamageEvent in project primplugin by Fangoboyo.
the class playerDamageListener method PlayerDamageEvent.
@EventHandler
public void PlayerDamageEvent(EntityDamageEvent e) {
if (e.getEntity().getType().isAlive()) {
EntityDamageEvent event = (EntityDamageEvent) e;
// defines damage and entities
int finalDamage = e.getDamage();
int reflectedDamage = 0;
LivingEntity entityVictim = (LivingEntity) e.getEntity();
LivingEntity entityDamager = (LivingEntity) entityVictim.getLastDamageCause().getEntity();
// Entity damageCause checker
if (e.getCause() == DamageCause.ENTITY_ATTACK) {
// victim player checker
if (entityVictim instanceof Player) {
Player playerVictim = (Player) entityVictim;
// define the 2 final damage stuff things
defenseManager d = new defenseManager();
getDamage dmg = new getDamage();
// gets the attackers armor damage and weapon damage && handles factions stuff
if (entityDamager instanceof Player) {
Player playerDamager = (Player) entityDamager;
// --------- Factions stuff -----------
UPlayer uPlayerDamager = UPlayer.get(playerDamager);
UPlayer uPlayerVictim = UPlayer.get(playerVictim);
if (uPlayerVictim.getFaction().equals(uPlayerDamager.getFaction())) {
e.setCancelled(true);
return;
}
// --------------------------------------
// ----------- Set bonus manager ---------------------
setBonuses set = new setBonuses();
// Cactus set bonus manager
if (set.getPlayerSetBonus(playerVictim).equals("cac")) {
reflectedDamage = e.getDamage() / 3;
}
// ------------------ Victim defense calculator ------------------
int playerDefense = d.getdefense(playerVictim);
int playerDefPerc = Math.round((100 * (playerDefense)) / ((100 * (playerDefense)) + 100));
int def = playerDefPerc / 100;
finalDamage = finalDamage + d.getArmorDamage(playerDamager) + dmg.getItemDamage(playerDamager.getItemInHand());
}
// TODO: finish revamping the rest of thsi stuff
// Does the final damage
}
}
// --------------- Magic Damage Calculator (WIP) -----------------
if (event.getCause() == DamageCause.ENTITY_EXPLOSION && event.getEntity() instanceof TNTPrimed) {
TNTPrimed tnt = (TNTPrimed) event.getEntity();
magicDamageManager m = new magicDamageManager();
// and adds it to the finalDamage int
if (m.checkTNTContains(tnt)) {
finalDamage = finalDamage + m.getActiveTNT(tnt);
m.removeTNT(tnt);
}
}
e.setCancelled(true);
entityVictim.setHealth(entityVictim.getHealth() - finalDamage);
if (entityVictim instanceof Player) {
Player p = (Player) entityVictim;
p.sendMessage("works yayy");
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project primplugin by Fangoboyo.
the class toolAbilities method onHit.
@EventHandler
public void onHit(EntityDamageEvent e) {
EntityDamageEvent event = (EntityDamageEvent) e;
// checks if the event damage cause is an entity attack
if (event.getCause() == DamageCause.ENTITY_ATTACK) {
Player p = (Player) event.getEntity();
// checks if the last damage cause is a player
if (p.getLastDamageCause().getEntity() instanceof Player) {
Player damager = (Player) p.getLastDamageCause().getEntity();
if (damager.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Thunderbolt of Zeus")) {
World world = p.getWorld();
// creates an explosion at the location of the damaged player that has a power of 1 and cannot damage blocks
world.createExplosion(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 1, true, false);
world.strikeLightning(p.getLocation());
}
if (damager.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Bloodthirsty Blade")) {
ItemStack Idamage = damager.getItemInHand();
Idamage.setDurability((short) -3);
getDamage dmg = new getDamage();
dmg.setDamage(Idamage, 3);
}
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project MiniGameWorld by MiniGameWorlds.
the class MiniGameCustomOption method processEvent.
/**
* Process event related with custom option before pass to a minigame<br>
*
* @param event Event to set cancel or not with options
*/
public void processEvent(Event event) {
if (event instanceof AsyncPlayerChatEvent) {
((AsyncPlayerChatEvent) event).setCancelled(!(boolean) get(Option.CHAT));
} else if (event instanceof BlockBreakEvent) {
((BlockBreakEvent) event).setCancelled(!(boolean) this.get(Option.BLOCK_BREAK));
} else if (event instanceof BlockPlaceEvent) {
((BlockPlaceEvent) event).setCancelled(!(boolean) this.get(Option.BLOCK_PLACE));
} else if (event instanceof PlayerDeathEvent) {
PlayerDeathEvent e = (PlayerDeathEvent) event;
if ((boolean) this.get(Option.INVENTORY_SAVE)) {
// keep inv
e.setKeepInventory(true);
// remove drops
e.getDrops().clear();
} else {
e.setKeepInventory(false);
}
} else if (event instanceof PlayerRespawnEvent) {
if ((boolean) this.get(Option.MINIGAME_RESPAWN)) {
PlayerRespawnEvent e = (PlayerRespawnEvent) event;
e.setRespawnLocation(this.minigame.getLocation());
}
} else if (event instanceof FoodLevelChangeEvent) {
FoodLevelChangeEvent e = (FoodLevelChangeEvent) event;
e.setCancelled(!(boolean) get(Option.FOOD_LEVEL_CHANGE));
} else if (event instanceof EntityDamageEvent) {
/*
* PLAYER_HURT
*/
EntityDamageEvent damageEvent = (EntityDamageEvent) event;
if (damageEvent.getEntity() instanceof Player) {
damageEvent.setCancelled(!(boolean) get(Option.PLAYER_HURT));
}
if (event instanceof EntityDamageByEntityEvent) {
// cancel damage by entity (
// when victim == minigame player && damager == minigame player
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
// PVP
processPVP(e);
// PVE
processPVE(e);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project MiniGameWorld by MiniGameWorlds.
the class MiniGameManager method passEventToViewManager.
private boolean passEventToViewManager(Event event) {
Player p = null;
if (event instanceof AsyncPlayerChatEvent) {
p = ((AsyncPlayerChatEvent) event).getPlayer();
} else if (event instanceof PlayerRespawnEvent) {
p = ((PlayerRespawnEvent) event).getPlayer();
} else if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
if (e.getEntity() instanceof Player) {
p = (Player) e.getEntity();
}
}
// check null
if (p == null) {
return false;
}
// check player is a viewer
if (!isViewingMiniGame(p)) {
return false;
}
// pass event to view manager
MiniGame minigame = getViewingMiniGame(p);
minigame.getViewManager().processEvent(event);
return true;
}
use of org.bukkit.event.entity.EntityDamageEvent in project Nokaut by smaks6.
the class Main method onDisable.
@Override
public void onDisable() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (!PlayerUtility.isNull(player)) {
if (Main.getInstance().getConfig().getString("DeathOnEnd").equals("true")) {
EntityDamageEvent lastDamageCause = player.getLastDamageCause();
if (lastDamageCause instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damageByEntityEvent = (EntityDamageByEntityEvent) lastDamageCause;
Entity damager = damageByEntityEvent.getDamager();
player.damage(500, damager);
PoseUtility.stop(player);
} else {
player.setHealth(0);
}
PoseUtility.stop(player);
} else {
PoseUtility.stop(player);
player.removePotionEffect(PotionEffectType.BLINDNESS);
}
}
}
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (ArmorStandNokaut.isNokautArmorStand(entity))
entity.remove();
}
}
}
Aggregations