Skip to content

Commit

Permalink
Updated for 1.14 villager professions.
Browse files Browse the repository at this point in the history
  • Loading branch information
totemo committed Jul 8, 2019
1 parent adc755e commit dabebb9
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 57 deletions.
1 change: 1 addition & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: ${project.version}
description: ${project.description}
author: totemo
website: ${project.url}
api-version: 1.14

commands:
doppel:
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.totemo</groupId>
<artifactId>Doppelganger</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>Doppelganger</name>
<description>Provides custom, summonable mobs that are reminiscent of the built-in golem types.</description>
Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<version>1.14.3-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
Expand Down
4 changes: 2 additions & 2 deletions src/io/github/totemo/doppelganger/CreatureFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/io/github/totemo/doppelganger/CreatureType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")));
Expand Down
224 changes: 172 additions & 52 deletions src/io/github/totemo/doppelganger/PredefinedCreature.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// ----------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -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));

// ------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -216,6 +292,7 @@ public LivingEntity spawn(Location loc) {
villager.setBaby();
}
if (_profession != null) {
villager.setVillagerExperience(1);
villager.setProfession(_profession);
}
return villager;
Expand All @@ -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
Expand All @@ -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;
}

// --------------------------------------------------------------------
Expand All @@ -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;
}

// --------------------------------------------------------------------
Expand All @@ -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;
}

Expand All @@ -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

// ------------------------------------------------------------------------
/**
Expand Down

0 comments on commit dabebb9

Please sign in to comment.