From 0747a0a3d4b9a062b31b4514a54f97dd9a052690 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Mon, 20 Sep 2021 22:00:01 +0300 Subject: [PATCH] Added ability to use "charged_creeper" as 'base-mob:' or in 'summon:' effect to spawn charged creepers --- .../bosses/util/bosstype/BossEntityUtils.java | 5 +++++ .../bosses/util/bosstype/VanillaBossType.java | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossEntityUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossEntityUtils.java index 9bdc61d..b8813b7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossEntityUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossEntityUtils.java @@ -5,6 +5,7 @@ import io.lumine.xikage.mythicmobs.mobs.MythicMob; import lombok.Getter; import lombok.Setter; import lombok.experimental.UtilityClass; +import org.bukkit.entity.Creeper; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Zombie; @@ -40,6 +41,10 @@ public class BossEntityUtils { } } + if (id.equalsIgnoreCase("charged_creeper")) { + return new VanillaBossType(Creeper.class, true); + } + try { Class type = (Class) EntityType.valueOf(id.toUpperCase()).getEntityClass(); assert type != null; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/VanillaBossType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/VanillaBossType.java index 7899d6b..708b6ea 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/VanillaBossType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/VanillaBossType.java @@ -1,6 +1,7 @@ package com.willfp.ecobosses.bosses.util.bosstype; import org.bukkit.Location; +import org.bukkit.entity.Creeper; import org.bukkit.entity.LivingEntity; import org.jetbrains.annotations.NotNull; @@ -12,6 +13,11 @@ class VanillaBossType extends BossType { */ private final Class entityClass; + /** + * If the entity is Creeper and should or should not be charged. + */ + private final boolean creeperCharged; + /** * Create new vanilla boss type. * @@ -19,10 +25,24 @@ class VanillaBossType extends BossType { */ VanillaBossType(@NotNull final Class entityClass) { this.entityClass = entityClass; + this.creeperCharged = false; + } + + /** + * Create new vanilla boss type. + * + * @param entityClass The entity class. + * @param creeperCharged The creeper power state. + */ + VanillaBossType(@NotNull final Class entityClass, boolean creeperCharged) { + this.entityClass = entityClass; + this.creeperCharged = creeperCharged; } @Override public LivingEntity spawnBossEntity(@NotNull final Location location) { - return Objects.requireNonNull(location.getWorld()).spawn(location, entityClass); + LivingEntity result = Objects.requireNonNull(location.getWorld()).spawn(location, entityClass); + if (result instanceof Creeper creeper && creeperCharged) creeper.setPowered(true); + return result; } }