// Damage Hook public void onEntityDamage(EntityDamageEvent event) { // No point in running if this has been stopped if (event.isCancelled()) { return; } // Is this a player? if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); PotionEntry entry = getPlugin().BuffList.get(player); // Elixir of Obsidian Skin if (entry != null && entry.HasBuff.get(Name) != null && entry.HasBuff.get(Name)) { // Halve all damages that have sources. // (Note, this means that direct damage through plugins // and such are left alone) if (event.getCause() != null) { int damage = event.getDamage(); damage = (int) (damage * 0.5); damage = Math.max(damage, 1); event.setDamage(damage); } } } }
public void giveBuff(PotionEntry entry) { entry.HasBuff.put(Name, true); if (entry.BuffTicks.get(Name) != null) { entry.BuffTicks.put(Name, entry.BuffTicks.get(Name) + ticksPerDrink); } else { entry.BuffTicks.put(Name, ticksPerDrink); } }
// Damage Hook public void onEntityDamage(EntityDamageEvent event) { // No point in running if this has been stopped if (event.isCancelled()) { return; } // Check if Firetouch user hit another entity ElixirMod plugin = getPlugin(); if (event instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); Entity damagee = event.getEntity(); // Check if damager is a player if (damager instanceof Player) { Player player = (Player) damager; PotionEntry entry = plugin.BuffList.get(player); // See if that player has Firetouch if (entry != null) { if (entry.HasBuff.get(Name) != null && entry.HasBuff.get(Name)) { // Check if we can ignite with any damage, else unarmed only boolean canIgnite = false; if (unarmedOnly) { if (((Player) damager).getItemInHand().getTypeId() == 0) { canIgnite = true; } } else { canIgnite = true; } if (canIgnite) { // If target is on fire, ignore, else ignite if (damagee.getFireTicks() <= 0) { // Chance ignite int chance = 1 + (int) (Math.random() * (100 - 1)); if (chance <= igniteChance) { damagee.setFireTicks(igniteLength * 20); } } } } } } } }
public void takeBuff(PotionEntry entry) { entry.HasBuff.put(Name, false); entry.BuffTicks.put(Name, 0); }