Added zombie resistance talisman
This commit is contained in:
@@ -18,6 +18,7 @@ import com.willfp.talismans.talismans.talismans.RaidTalisman;
|
||||
import com.willfp.talismans.talismans.talismans.SharpnessTalisman;
|
||||
import com.willfp.talismans.talismans.talismans.SkeletonTalisman;
|
||||
import com.willfp.talismans.talismans.talismans.SpiderTalisman;
|
||||
import com.willfp.talismans.talismans.talismans.ZombieResistanceTalisman;
|
||||
import com.willfp.talismans.talismans.talismans.ZombieTalisman;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -51,6 +52,7 @@ public class Talismans {
|
||||
public static final Talisman EXPERIENCE_TALISMAN = new ExperienceTalisman();
|
||||
public static final Talisman EXTRACTION_TALISMAN = new ExtractionTalisman();
|
||||
public static final Talisman SHARPNESS_TALISMAN = new SharpnessTalisman();
|
||||
public static final Talisman ZOMBIE_RESISTANCE_TALISMAN = new ZombieResistanceTalisman();
|
||||
|
||||
/**
|
||||
* Get all registered {@link Talisman}s.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.talismans.talismans.talismans;
|
||||
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ZombieResistanceTalisman extends Talisman {
|
||||
public ZombieResistanceTalisman() {
|
||||
super("zombie_resistance_talisman");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageByEntity(@NotNull final Player victim,
|
||||
@NotNull final Entity attacker,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(attacker instanceof Zombie)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(event.getDamage() * (1 - (this.getConfig().getDouble(Talismans.CONFIG_LOCATION + "percent-less-damage")) / 100));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.willfp.talismans.talismans.util;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Trident;
|
||||
@@ -140,6 +141,19 @@ public interface Watcher {
|
||||
// Empty default as talismans only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player takes damage from another entity.
|
||||
*
|
||||
* @param victim The player that took damage.
|
||||
* @param attacker The entity that damaged the player.
|
||||
* @param event The event that called this watcher.
|
||||
*/
|
||||
default void onDamageByEntity(@NotNull final Player victim,
|
||||
@NotNull final Entity attacker,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
// Empty default as talismans only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player damages a block.
|
||||
*
|
||||
|
||||
@@ -498,6 +498,40 @@ public class WatcherTriggers extends PluginDependent implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity takes damage wearing armor.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDamageByEntity(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player victim = (Player) event.getEntity();
|
||||
|
||||
TalismanChecks.getTalismansOnPlayer(victim).forEach(talisman -> {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!talisman.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (talisman.getDisabledWorlds().contains(victim.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
talisman.onDamageByEntity(victim, event.getDamager(), event);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player damages a block.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
name: "Zombie Resistance Talisman"
|
||||
description: Take 10% less damage from zombies.
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
# Recipes are left-right, top-bottom
|
||||
# The first item is the top left, the second is top middle, and so on. The last is bottom right.
|
||||
recipe:
|
||||
- rotten_flesh
|
||||
- rotten_flesh
|
||||
- rotten_flesh
|
||||
|
||||
- rotten_flesh
|
||||
- shield
|
||||
- rotten_flesh
|
||||
|
||||
- rotten_flesh
|
||||
- rotten_flesh
|
||||
- rotten_flesh
|
||||
|
||||
general-config:
|
||||
disabled-in-worlds: []
|
||||
# Texture is base64, https://minecraft-heads.com has a list of skulls.
|
||||
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTBkMTZlNTY3ODM0N2U2ZDk4Y2YxZGFmZTY2ZDE3ZTg4OTM4NzNlZWNiMjlmZDVhMTEyZjUxNTI1YjkxMSJ9fX0=
|
||||
|
||||
config:
|
||||
percent-less-damage: 10
|
||||
Reference in New Issue
Block a user