From dabebb99c3c813b732bbc5e4f9cb5ddcf54e0f11 Mon Sep 17 00:00:00 2001 From: totemo Date: Mon, 8 Jul 2019 19:59:57 +0930 Subject: [PATCH] Updated for 1.14 villager professions. --- plugin.yml | 1 + pom.xml | 4 +- .../totemo/doppelganger/CreatureFactory.java | 4 +- .../totemo/doppelganger/CreatureType.java | 2 +- .../doppelganger/PredefinedCreature.java | 224 ++++++++++++++---- 5 files changed, 178 insertions(+), 57 deletions(-) diff --git a/plugin.yml b/plugin.yml index 1e15352..d1adaa7 100644 --- a/plugin.yml +++ b/plugin.yml @@ -4,6 +4,7 @@ version: ${project.version} description: ${project.description} author: totemo website: ${project.url} +api-version: 1.14 commands: doppel: diff --git a/pom.xml b/pom.xml index 31b9fef..bdafbf5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.github.totemo Doppelganger - 1.0.0 + 1.1.0 jar Doppelganger Provides custom, summonable mobs that are reminiscent of the built-in golem types. @@ -15,7 +15,7 @@ org.bukkit bukkit - 1.11-R0.1-SNAPSHOT + 1.14.3-R0.1-SNAPSHOT diff --git a/src/io/github/totemo/doppelganger/CreatureFactory.java b/src/io/github/totemo/doppelganger/CreatureFactory.java index ad862fd..8d87809 100644 --- a/src/io/github/totemo/doppelganger/CreatureFactory.java +++ b/src/io/github/totemo/doppelganger/CreatureFactory.java @@ -392,8 +392,8 @@ protected LivingEntity spawnCreature(String creatureType, Location loc, String n */ protected static void setPlayerHead(LivingEntity doppelganger, String name) { ItemStack helmet = doppelganger.getEquipment().getHelmet(); - if (helmet == null || helmet.getType() != Material.SKULL_ITEM) { - helmet = new ItemStack(Material.SKULL_ITEM, 1); + if (helmet == null || helmet.getType() != Material.PLAYER_HEAD) { + helmet = new ItemStack(Material.PLAYER_HEAD, 1); } SkullMeta meta = (SkullMeta) helmet.getItemMeta(); diff --git a/src/io/github/totemo/doppelganger/CreatureType.java b/src/io/github/totemo/doppelganger/CreatureType.java index f3e35ef..ea8da42 100644 --- a/src/io/github/totemo/doppelganger/CreatureType.java +++ b/src/io/github/totemo/doppelganger/CreatureType.java @@ -566,7 +566,7 @@ protected static ItemStack loadItem(ConfigurationSection section, Logger logger) } // Load additional customisation specific to books. - if (material == Material.BOOK_AND_QUILL || material == Material.WRITTEN_BOOK) { + if (material == Material.WRITABLE_BOOK || material == Material.WRITTEN_BOOK) { BookMeta bookMeta = (BookMeta) meta; bookMeta.setTitle(translate(section.getString("title", ""))); bookMeta.setAuthor(translate(section.getString("author", ""))); diff --git a/src/io/github/totemo/doppelganger/PredefinedCreature.java b/src/io/github/totemo/doppelganger/PredefinedCreature.java index 883c7b4..5971cd6 100644 --- a/src/io/github/totemo/doppelganger/PredefinedCreature.java +++ b/src/io/github/totemo/doppelganger/PredefinedCreature.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Zombie; +import org.bukkit.entity.ZombieVillager; // ---------------------------------------------------------------------------- /** @@ -64,50 +65,125 @@ public LivingEntity spawn(Location loc) { } }), - Blacksmith(new PredefinedVillager(false, Profession.BLACKSMITH)), BabyBlacksmith( - new PredefinedVillager(true, Profession.BLACKSMITH)), ZombieBlacksmith(new PredefinedZombie(false, Profession.BLACKSMITH)), BabyZombieBlacksmith( - new PredefinedZombie(true, Profession.BLACKSMITH)), Butcher(new PredefinedVillager(false, Profession.BUTCHER)), BabyButcher( - new PredefinedVillager(true, Profession.BUTCHER)), ZombieButcher(new PredefinedZombie(false, Profession.BUTCHER)), BabyZombieButcher( - new PredefinedZombie(true, Profession.BUTCHER)), Farmer(new PredefinedVillager(false, Profession.FARMER)), BabyFarmer( - new PredefinedVillager(true, Profession.FARMER)), ZombieFarmer(new PredefinedZombie(false, Profession.FARMER)), BabyZombieFarmer( - new PredefinedZombie(true, Profession.FARMER)), Librarian(new PredefinedVillager(false, Profession.LIBRARIAN)), BabyLibrarian( - new PredefinedVillager(true, Profession.LIBRARIAN)), ZombieLibrarian(new PredefinedZombie(false, Profession.LIBRARIAN)), BabyZombieLibrarian( - new PredefinedZombie(true, Profession.LIBRARIAN)), Priest(new PredefinedVillager(false, Profession.PRIEST)), BabyPriest( - new PredefinedVillager(true, Profession.PRIEST)), ZombiePriest( - new PredefinedZombie(false, Profession.PRIEST)), BabyZombiePriest(new PredefinedZombie(true, Profession.PRIEST)), - - BabyVillager(new PredefinedVillager(true, null)), BabyZombie(new PredefinedZombie(true, null)), - - ZombieVillager(new IPredefinedCreature() { - @Override - public boolean isInstance(LivingEntity living) { - return living instanceof Zombie && ((Zombie) living).isVillager(); - } + Armorer(new PredefinedVillager(false, Profession.ARMORER)), - @Override - public LivingEntity spawn(Location loc) { - Zombie zombie = loc.getWorld().spawn(loc, Zombie.class); - zombie.setVillagerProfession(getRandomVillagerProfession()); - return zombie; - } - }), + BabyArmorer(new PredefinedVillager(true, Profession.ARMORER)), - BabyZombieVillager(new IPredefinedCreature() { - @Override - public boolean isInstance(LivingEntity living) { - return living instanceof Zombie && - ((Zombie) living).isVillager() && - ((Zombie) living).isBaby(); - } + ZombieArmorer(new PredefinedZombieVillager(false, Profession.ARMORER)), - @Override - public LivingEntity spawn(Location loc) { - Zombie zombie = loc.getWorld().spawn(loc, Zombie.class); - zombie.setBaby(true); - zombie.setVillagerProfession(getRandomVillagerProfession()); - return zombie; - } - }); + BabyZombieArmorer(new PredefinedZombieVillager(true, Profession.ARMORER)), + + Butcher(new PredefinedVillager(false, Profession.BUTCHER)), + + BabyButcher(new PredefinedVillager(true, Profession.BUTCHER)), + + ZombieButcher(new PredefinedZombieVillager(false, Profession.BUTCHER)), + + BabyZombieButcher(new PredefinedZombieVillager(true, Profession.BUTCHER)), + + Cartographer(new PredefinedVillager(false, Profession.CARTOGRAPHER)), + + BabyCartographer(new PredefinedVillager(true, Profession.CARTOGRAPHER)), + + ZombieCartographer(new PredefinedZombieVillager(false, Profession.CARTOGRAPHER)), + + BabyZombieCartographer(new PredefinedZombieVillager(true, Profession.CARTOGRAPHER)), + + Cleric(new PredefinedVillager(false, Profession.CLERIC)), + + BabyCleric(new PredefinedVillager(true, Profession.CLERIC)), + + ZombieCleric(new PredefinedZombieVillager(false, Profession.CLERIC)), + + BabyZombieCleric(new PredefinedZombieVillager(true, Profession.CLERIC)), + + Farmer(new PredefinedVillager(false, Profession.FARMER)), + + BabyFarmer(new PredefinedVillager(true, Profession.FARMER)), + + ZombieFarmer(new PredefinedZombieVillager(false, Profession.FARMER)), + + BabyZombieFarmer(new PredefinedZombieVillager(true, Profession.FARMER)), + + Fisherman(new PredefinedVillager(false, Profession.FISHERMAN)), + + BabyFisherman(new PredefinedVillager(true, Profession.FISHERMAN)), + + ZombieFisherman(new PredefinedZombieVillager(false, Profession.FISHERMAN)), + + BabyZombieFisherman(new PredefinedZombieVillager(true, Profession.FISHERMAN)), + + Fletcher(new PredefinedVillager(false, Profession.FLETCHER)), + + BabyFletcher(new PredefinedVillager(true, Profession.FLETCHER)), + + ZombieFletcher(new PredefinedZombieVillager(false, Profession.FLETCHER)), + + BabyZombieFletcher(new PredefinedZombieVillager(true, Profession.FLETCHER)), + + Leatherworker(new PredefinedVillager(false, Profession.LEATHERWORKER)), + + BabyLeatherworker(new PredefinedVillager(true, Profession.LEATHERWORKER)), + + ZombieLeatherworker(new PredefinedZombieVillager(false, Profession.LEATHERWORKER)), + + BabyZombieLeatherworker(new PredefinedZombieVillager(true, Profession.LEATHERWORKER)), + + Librarian(new PredefinedVillager(false, Profession.LIBRARIAN)), + + BabyLibrarian(new PredefinedVillager(true, Profession.LIBRARIAN)), + + ZombieLibrarian(new PredefinedZombieVillager(false, Profession.LIBRARIAN)), + + BabyZombieLibrarian(new PredefinedZombieVillager(true, Profession.LIBRARIAN)), + + Mason(new PredefinedVillager(false, Profession.MASON)), + + BabyMason(new PredefinedVillager(true, Profession.MASON)), + + ZombieMason(new PredefinedZombieVillager(false, Profession.MASON)), + + BabyZombieMason(new PredefinedZombieVillager(true, Profession.MASON)), + + Nitwit(new PredefinedVillager(false, Profession.NITWIT)), + + BabyNitwit(new PredefinedVillager(true, Profession.NITWIT)), + + ZombieNitwit(new PredefinedZombieVillager(false, Profession.NITWIT)), + + BabyZombieNitwit(new PredefinedZombieVillager(true, Profession.NITWIT)), + + Shepherd(new PredefinedVillager(false, Profession.SHEPHERD)), + + BabyShepherd(new PredefinedVillager(true, Profession.SHEPHERD)), + + ZombieShepherd(new PredefinedZombieVillager(false, Profession.SHEPHERD)), + + BabyZombieShepherd(new PredefinedZombieVillager(true, Profession.SHEPHERD)), + + Toolsmith(new PredefinedVillager(false, Profession.TOOLSMITH)), + + BabyToolsmith(new PredefinedVillager(true, Profession.TOOLSMITH)), + + ZombieToolsmith(new PredefinedZombieVillager(false, Profession.TOOLSMITH)), + + BabyZombieToolsmith(new PredefinedZombieVillager(true, Profession.TOOLSMITH)), + + Weaponsmith(new PredefinedVillager(false, Profession.WEAPONSMITH)), + + BabyWeaponsmith(new PredefinedVillager(true, Profession.WEAPONSMITH)), + + ZombieWeaponsmith(new PredefinedZombieVillager(false, Profession.WEAPONSMITH)), + + BabyZombieWeaponsmith(new PredefinedZombieVillager(true, Profession.WEAPONSMITH)), + + BabyVillager(new PredefinedVillager(true, null)), + + BabyZombie(new PredefinedZombie(true, null)), + + ZombieVillager(new PredefinedZombieVillager(false, null)), + + BabyZombieVillager(new PredefinedZombieVillager(true, null)); // ------------------------------------------------------------------------ /** @@ -216,6 +292,7 @@ public LivingEntity spawn(Location loc) { villager.setBaby(); } if (_profession != null) { + villager.setVillagerExperience(1); villager.setProfession(_profession); } return villager; @@ -236,7 +313,7 @@ public LivingEntity spawn(Location loc) { // ------------------------------------------------------------------------ /** * PredefinedCreature implementation delegate for zombies with specified age - * (adult or baby) and villager profession. + * (adult or baby). * * Bukkit Villager and Zombie interfaces don't share a common superinterface * to control age, so this implementation must be distinct from that of @@ -248,12 +325,9 @@ static final class PredefinedZombie implements IPredefinedCreature { * * @param baby if true, the zombie villager is a baby; otherwise it is * an adult. - * @param profession the zombie villager's profession; or null for no - * profession (a non-villager). */ public PredefinedZombie(boolean baby, Profession profession) { _baby = baby; - _profession = profession; } // -------------------------------------------------------------------- @@ -263,8 +337,7 @@ public PredefinedZombie(boolean baby, Profession profession) { @Override public boolean isInstance(LivingEntity living) { return living instanceof Zombie && - ((Zombie) living).isBaby() == _baby && - ((Zombie) living).getVillagerProfession() == _profession; + ((Zombie) living).isBaby() == _baby; } // -------------------------------------------------------------------- @@ -275,9 +348,56 @@ public boolean isInstance(LivingEntity living) { public LivingEntity spawn(Location loc) { Zombie zombie = loc.getWorld().spawn(loc, Zombie.class); zombie.setBaby(_baby); - if (_profession != null) { - zombie.setVillagerProfession(_profession); - } + return zombie; + } + + // -------------------------------------------------------------------- + /** + * True if a baby. + */ + protected boolean _baby; + + }; // inner class PredefinedZombie + + // ------------------------------------------------------------------------ + /** + * PredefinedCreature implementation delegate for zombie villagers with + * specified age (adult or baby) and villager profession. + */ + static final class PredefinedZombieVillager implements IPredefinedCreature { + /** + * Constructor. + * + * @param baby if true, the zombie villager is a baby; otherwise it is + * an adult. + * @param profession the zombie villager's profession; or null for a + * random profession. + */ + public PredefinedZombieVillager(boolean baby, Profession profession) { + _baby = baby; + _profession = profession; + } + + // -------------------------------------------------------------------- + /** + * @see io.github.totemo.doppelganger.IPredefinedCreature#isInstance(org.bukkit.entity.LivingEntity) + */ + @Override + public boolean isInstance(LivingEntity living) { + return living instanceof ZombieVillager && + ((ZombieVillager) living).isBaby() == _baby && + (_profession == null || ((ZombieVillager) living).getVillagerProfession() == _profession); + } + + // -------------------------------------------------------------------- + /** + * @see io.github.totemo.doppelganger.IPredefinedCreature#spawn(org.bukkit.Location) + */ + @Override + public LivingEntity spawn(Location loc) { + ZombieVillager zombie = loc.getWorld().spawn(loc, ZombieVillager.class); + zombie.setBaby(_baby); + zombie.setVillagerProfession(_profession != null ? _profession : getRandomVillagerProfession()); return zombie; } @@ -288,10 +408,10 @@ public LivingEntity spawn(Location loc) { protected boolean _baby; /** - * Villager profession, or null for a generic zombie. + * Villager profession, or null for random. */ protected Profession _profession; - }; // inner class PredefinedZombie + }; // inner class PredefinedZombieVillager // ------------------------------------------------------------------------ /**