From 0bf3e48da1a38a7b2ed9add70da68a2d2cb23bd2 Mon Sep 17 00:00:00 2001 From: MarioFinale Date: Fri, 14 Jul 2023 01:52:40 -0400 Subject: [PATCH] 1.4.0 Add trident behaviors --- README.md | 6 +++ out/production/VillagerSaver/plugin.yml | 2 +- .../mariofinale/VillagerSaver_Listener.java | 53 ++++++++++++++++--- src/plugin.yml | 2 +- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6368041..de532be 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ It preserves trades, homes, job location and updates reputation. ## Changelog +### 1.4.0 +- Now it converts Villagers Killed by Drowned tridents or a [TNT explosion primed by a Trident](https://www.youtube.com/watch?v=qR_jv8wefAY). + +### 1.3.5 +- Specify API version as String. + ### 1.3.4 - Minor changes. - Updated to 1.20.1. diff --git a/out/production/VillagerSaver/plugin.yml b/out/production/VillagerSaver/plugin.yml index d29cdf8..be330fb 100644 --- a/out/production/VillagerSaver/plugin.yml +++ b/out/production/VillagerSaver/plugin.yml @@ -1,5 +1,5 @@ name: VillagerSaver -version: 1.3.4 +version: 1.4.0 authors: [MarioFinale, Kasama, Kyle Hunady] main: cl.mariofinale.VillagerSaver api-version: '1.20' diff --git a/src/cl/mariofinale/VillagerSaver_Listener.java b/src/cl/mariofinale/VillagerSaver_Listener.java index d606f63..f69c362 100644 --- a/src/cl/mariofinale/VillagerSaver_Listener.java +++ b/src/cl/mariofinale/VillagerSaver_Listener.java @@ -12,18 +12,57 @@ public class VillagerSaver_Listener implements Listener { public void onEntityDeath(EntityDeathEvent event) { //Check if dead entity is a villager if(!(event.getEntity() instanceof Villager)) return; + Villager villagerEnt = (Villager) event.getEntity(); - - //Check if death was caused by another entity - if(!(villagerEnt.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK)) return; - Entity damagerEnt = ((EntityDamageByEntityEvent) villagerEnt.getLastDamageCause()).getDamager(); - + EntityDamageEvent damageCauseEvent = villagerEnt.getLastDamageCause(); + EntityDamageEvent.DamageCause cause = damageCauseEvent.getCause(); + + //Check if death was caused by another entity or an explosion or a projectile + if(!isValidDamageCause(cause)) return; + + //Get the Killer entity + Entity killerEntity = getKillerEntity(damageCauseEvent, cause); + + //Check if killer is not null + if (killerEntity == null) return; + + //Check if killer is a valid Entity + if (!killerEntity.isValid()) return; + //Check if killer is a zombie variant - if(!(VillagerSaver_PluginVars.ZombieTypes.contains(damagerEnt.getType()))) return; + if(!isZombieVariant(killerEntity)) return; //Check if villager is in a blacklisted world - if (VillagerSaver.WorldBlackList.contains(villagerEnt.getWorld().getName())) return; + if (isVillagerWorldBlacklisted(villagerEnt)) return; + //Zombify Villager! villagerEnt.zombify(); } + + + private Entity getKillerEntity(EntityDamageEvent damageCauseEvent, EntityDamageEvent.DamageCause cause) { + switch (cause) { + case PROJECTILE: //Set damager as the entity that shot the projectile + return (Entity) ((Projectile)((EntityDamageByEntityEvent) damageCauseEvent).getDamager()).getShooter(); + case ENTITY_ATTACK: //Set damager as the entity attacking + return ((EntityDamageByEntityEvent) damageCauseEvent).getDamager(); + case ENTITY_EXPLOSION: //Set damager as the entity that primed the TNT + return ((TNTPrimed) ((EntityDamageByEntityEvent) damageCauseEvent).getDamager()).getSource(); + } + return null; + } + + private boolean isValidDamageCause(EntityDamageEvent.DamageCause cause) { + return cause == EntityDamageEvent.DamageCause.ENTITY_ATTACK || + cause == EntityDamageEvent.DamageCause.PROJECTILE || + cause == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; + } + + private boolean isZombieVariant(Entity entity) { + return VillagerSaver_PluginVars.ZombieTypes.contains(entity.getType()); + } + + private boolean isVillagerWorldBlacklisted(Villager villagerEnt) { + return VillagerSaver.WorldBlackList.contains(villagerEnt.getWorld().getName()); + } } \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index d29cdf8..be330fb 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: VillagerSaver -version: 1.3.4 +version: 1.4.0 authors: [MarioFinale, Kasama, Kyle Hunady] main: cl.mariofinale.VillagerSaver api-version: '1.20'