Skip to content

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
Updated to 1.16.5
Fixes #7
  • Loading branch information
MarioFinale committed Jan 22, 2021
1 parent 23bbd11 commit a61f3c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions VillagerSaver.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Desktop/Test srv/cache/patched_1.16.4.jar!/" />
<root url="jar://$USER_HOME$/Desktop/Test srv/cache/patched_1.16.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/Desktop/Test srv/cache/patched_1.16.4.jar!/" />
<root url="jar://$USER_HOME$/Desktop/Test srv/cache/patched_1.16.5.jar!/" />
</SOURCES>
</library>
</orderEntry>
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.1.1
version: 1.1.3
author: MarioFinale
main: cl.mariofinale.villagerSaver
api-version: 1.13
Expand Down
39 changes: 27 additions & 12 deletions src/cl/mariofinale/VillagerSaver_Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -150,9 +152,9 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
LivingEntity tVillager = (LivingEntity)villager;
if (event.getDamager() == null) return;
Entity tKiller = event.getDamager();
if (!(tVillager.getType() == EntityType.VILLAGER)) return;
if (!((tKiller.getType() == EntityType.ZOMBIE) || (tKiller.getType() == EntityType.ZOMBIE_VILLAGER))) return;
if (!(tVillager.getHealth() - event.getDamage() <= 0)) return;
if (!(tVillager.getType() == EntityType.VILLAGER)) return;
if (!((tKiller.getType() == EntityType.ZOMBIE) || (tKiller.getType() == EntityType.ZOMBIE_VILLAGER) || (tKiller.getType() == EntityType.DROWNED))) return;
if (villagerSaver.WorldBlackList.contains(tVillager.getWorld().getName())) return;
StoreAndClearVillager(villager);
event.setCancelled(true);
Expand All @@ -165,21 +167,34 @@ public void StoreAndClearVillager(Entity villager){ //CALLED WHEN A VILLAGER IS
Ageable tAVillager = (Ageable) villager;
Villager oldVillager = (Villager) villager;
if (tAVillager.isAdult()){
Entity newZombie = tWorld.spawnEntity(tLoc, EntityType.ZOMBIE_VILLAGER);
villagerSaver.VillagersReputation.put(newZombie.getUniqueId(), oldVillager.getReputations());
villagerSaver.VillagersTypes.put(newZombie.getUniqueId(),oldVillager.getVillagerType());
villagerSaver.VillagersProfessions.put(newZombie.getUniqueId(),oldVillager.getProfession());
villagerSaver.VillagersLevels.put(newZombie.getUniqueId(), oldVillager.getVillagerLevel());
villagerSaver.VillagersExp.put(newZombie.getUniqueId(), oldVillager.getVillagerExperience());
villagerSaver.VillagersTrades.put(newZombie.getUniqueId(), new ArrayList<>(oldVillager.getRecipes()));
villagerSaver.VillagersJobSites.put(newZombie.getUniqueId(), oldVillager.getMemory(MemoryKey.JOB_SITE));
villagerSaver.VillagersHomes.put(newZombie.getUniqueId(), oldVillager.getMemory(MemoryKey.HOME));
Map<UUID,Reputation> villagerReputations = oldVillager.getReputations();
Villager.Type villagerType = oldVillager.getVillagerType();
Villager.Profession villagerProfession = oldVillager.getProfession();
int villagerLevel = oldVillager.getVillagerLevel();
int villagerExp = oldVillager.getVillagerExperience();
List<MerchantRecipe> villagerTrades = new ArrayList<>(oldVillager.getRecipes());
Location villagerJobSite = oldVillager.getMemory(MemoryKey.JOB_SITE);
Location villagerHome = oldVillager.getMemory(MemoryKey.HOME);

tVillager.setMemory(MemoryKey.JOB_SITE, new Location(tVillager.getWorld(), 0d,0d,0d));
tVillager.setMemory(MemoryKey.HOME, new Location(tVillager.getWorld(), 0d,0d,0d));
tVillager.remove();

Entity newZombie = tWorld.spawnEntity(tLoc, EntityType.ZOMBIE_VILLAGER);
ZombieVillager zVillager = (ZombieVillager) newZombie;
zVillager.setVillagerProfession(oldVillager.getProfession());
zVillager.setVillagerProfession(villagerProfession);
zVillager.setAdult();
UUID zombieUUID = newZombie.getUniqueId();

villagerSaver.VillagersReputation.put(zombieUUID, villagerReputations);
villagerSaver.VillagersTypes.put(zombieUUID,villagerType);
villagerSaver.VillagersProfessions.put(zombieUUID,villagerProfession);
villagerSaver.VillagersLevels.put(zombieUUID, villagerLevel);
villagerSaver.VillagersExp.put(zombieUUID, villagerExp);
villagerSaver.VillagersTrades.put(zombieUUID, villagerTrades);
villagerSaver.VillagersJobSites.put(zombieUUID, villagerJobSite);
villagerSaver.VillagersHomes.put(zombieUUID, villagerHome);

}else{
tVillager.remove();
Entity newZombie = tWorld.spawnEntity(tLoc, EntityType.ZOMBIE_VILLAGER);
Expand Down
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.1.2
version: 1.1.3
author: MarioFinale
main: cl.mariofinale.villagerSaver
api-version: 1.13
Expand Down

0 comments on commit a61f3c9

Please sign in to comment.