diff --git a/changelog.md b/changelog.md index 9f70c35..0b57f19 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ These changes will (most likely) be included in the next version. ## [Unreleased] ### Added - New monster variant `angry-bees` can be used to spawn angry bees. +- Pet names are now per-class configurable via the optional `pet-name` property, which defaults to `'s pet` (the `` variable is also supported). - (API) MobArena's internal command handler now supports registering pre-instantiated subcommand instances. This should make it easier for extensions to avoid the Singleton anti-pattern for command dependencies. - (API) MobArena now fires MobArenaPreReloadEvent and MobArenaReloadEvent before and after, respectively, reloading its config-file. This should allow extensions and other plugins to better respond to configuration changes. diff --git a/src/main/java/com/garbagemule/MobArena/ArenaClass.java b/src/main/java/com/garbagemule/MobArena/ArenaClass.java index bf4d030..217f6f9 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaClass.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaClass.java @@ -27,6 +27,7 @@ public class ArenaClass private boolean unbreakableWeapons, unbreakableArmor; private Thing price; private Location classchest; + private String petName; /** * Create a new, empty arena class with the given name. @@ -146,6 +147,14 @@ public class ArenaClass this.effects = effects; } + public String getPetName() { + return this.petName; + } + + public void setPetName(String petName) { + this.petName = petName; + } + public boolean hasPermission(Player p) { String key = "mobarena.classes." + slug; if (p.isPermissionSet(key)) { diff --git a/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java index a31d425..cd9bbd8 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java @@ -393,6 +393,10 @@ public class ArenaMasterImpl implements ArenaMaster throw new ConfigError("Failed to parse classchest location for class " + classname + " because: " + e.getMessage()); } + // Load pet name + String petName = section.getString("pet-name", "'s pet"); + arenaClass.setPetName(petName); + // Finally add the class to the classes map. classes.put(arenaClass.getSlug(), arenaClass); return arenaClass; diff --git a/src/main/java/com/garbagemule/MobArena/SpawnsPets.java b/src/main/java/com/garbagemule/MobArena/SpawnsPets.java index 7abab72..fc5132e 100644 --- a/src/main/java/com/garbagemule/MobArena/SpawnsPets.java +++ b/src/main/java/com/garbagemule/MobArena/SpawnsPets.java @@ -1,6 +1,7 @@ package com.garbagemule.MobArena; import com.garbagemule.MobArena.framework.Arena; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -42,11 +43,11 @@ public class SpawnsPets { } for (Map.Entry entry : materialToEntity.entrySet()) { - spawnPetsFor(player, arena, entry.getKey(), entry.getValue()); + spawnPetsFor(player, arena, entry.getKey(), entry.getValue(), ac.getPetName()); } } - private void spawnPetsFor(Player player, Arena arena, Material material, EntityType entity) { + private void spawnPetsFor(Player player, Arena arena, Material material, EntityType entity, String petName) { PlayerInventory inv = player.getInventory(); int index = inv.first(material); @@ -57,8 +58,14 @@ public class SpawnsPets { int amount = inv.getItem(index).getAmount(); for (int i = 0; i < amount; i++) { Entity pet = arena.getWorld().spawn(player.getLocation(), entity.getEntityClass()); - pet.setCustomName(player.getDisplayName() + "'s pet"); - pet.setCustomNameVisible(true); + if (!petName.isEmpty()) { + String resolved = petName + .replace("", player.getName()) + .replace("", player.getDisplayName()); + String colorized = ChatColor.translateAlternateColorCodes('&', resolved); + pet.setCustomName(colorized); + pet.setCustomNameVisible(true); + } if (pet instanceof Tameable) { Tameable tameable = (Tameable) pet; tameable.setTamed(true);