Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
Add trident behaviors
  • Loading branch information
MarioFinale committed Jul 14, 2023
1 parent 1f9895f commit 0bf3e48
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion out/production/VillagerSaver/plugin.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
53 changes: 46 additions & 7 deletions src/cl/mariofinale/VillagerSaver_Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 0bf3e48

Please sign in to comment.