From 7d08f613d063b8984c525b8145f1adf533084b7f Mon Sep 17 00:00:00 2001 From: AMinecraftDev Date: Sun, 1 Jul 2018 22:34:44 +0800 Subject: [PATCH] 3.0.0-SNAPSHOT-U17 Fixed up EntityTypeMechanic to now use EntityFinder, added a new Debug message. --- .../mechanics/EntityTypeMechanic.java | 22 +++++-------------- .../custombosses/utils/Debug.java | 3 ++- .../custombosses/utils/EntityFinder.java | 19 ++++++++++++++++ pom.xml | 2 +- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/plugin-modules/Core/src/net/aminecraftdev/custombosses/mechanics/EntityTypeMechanic.java b/plugin-modules/Core/src/net/aminecraftdev/custombosses/mechanics/EntityTypeMechanic.java index 90e4666..a6d6bad 100644 --- a/plugin-modules/Core/src/net/aminecraftdev/custombosses/mechanics/EntityTypeMechanic.java +++ b/plugin-modules/Core/src/net/aminecraftdev/custombosses/mechanics/EntityTypeMechanic.java @@ -2,9 +2,8 @@ package net.aminecraftdev.custombosses.mechanics; import net.aminecraftdev.custombosses.entity.BossEntity; import net.aminecraftdev.custombosses.holder.ActiveBossHolder; -import net.aminecraftdev.custombosses.utils.EntityTypeUtil; +import net.aminecraftdev.custombosses.utils.EntityFinder; import net.aminecraftdev.custombosses.utils.IMechanic; -import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; /** @@ -17,23 +16,14 @@ public class EntityTypeMechanic implements IMechanic { @Override public boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder) { String bossEntityType = bossEntity.getMainStats().getEntityType(); - LivingEntity livingEntity; + String input = bossEntityType.split(":")[0]; + EntityFinder entityFinder = EntityFinder.get(input); - try { - livingEntity = EntityTypeUtil.get(bossEntityType, activeBossHolder.getLocation()); - } catch (NullPointerException ex) { - return false; - } + if(entityFinder == null) return false; - if(livingEntity == null) { - EntityType entityType = EntityType.valueOf(bossEntityType.toUpperCase()); + LivingEntity livingEntity = entityFinder.spawnNewLivingEntity(bossEntityType, activeBossHolder.getLocation()); - try { - livingEntity = (LivingEntity) activeBossHolder.getLocation().getWorld().spawnEntity(activeBossHolder.getLocation(), entityType); - } catch (Exception ex) { - return false; - } - } + if(livingEntity == null) return false; activeBossHolder.setLivingEntity(livingEntity); return true; diff --git a/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/Debug.java b/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/Debug.java index 5561540..86fdcc3 100644 --- a/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/Debug.java +++ b/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/Debug.java @@ -13,7 +13,8 @@ public enum Debug { MAX_HEALTH("You cannot set the max health higher than {0}. You can adjust your max health in the spigot.yml file and restart your server to increase this."), MECHANIC_APPLICATION_FAILED("Some mechanics have failed to be applied. It got stuck at {0} mechanic."), - ATTEMPTED_TO_SPAWN_WHILE_DISABLED("The {0} boss/minion attempted to spawn while editing is enabled."); + ATTEMPTED_TO_SPAWN_WHILE_DISABLED("The {0} boss/minion attempted to spawn while editing is enabled."), + FAILED_ATTEMPT_TO_SPAWN_BOSS("A boss has attempted to spawn but cannot spawn for the following reason: \n{0}"); private String message; diff --git a/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/EntityFinder.java b/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/EntityFinder.java index 1e7838e..138cf8e 100644 --- a/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/EntityFinder.java +++ b/plugin-modules/Core/src/net/aminecraftdev/custombosses/utils/EntityFinder.java @@ -3,7 +3,9 @@ package net.aminecraftdev.custombosses.utils; import lombok.Getter; import net.aminecraftdev.custombosses.utils.entity.ICustomEntityHandler; import net.aminecraftdev.custombosses.utils.entity.handlers.*; +import org.bukkit.Location; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import java.util.ArrayList; import java.util.Arrays; @@ -93,6 +95,23 @@ public enum EntityFinder { this.customEntityHandler = null; } + public LivingEntity spawnNewLivingEntity(String input, Location location) { + if(this.customEntityHandler != null) { + LivingEntity livingEntity; + + try { + livingEntity = this.customEntityHandler.getBaseEntity(input, location); + } catch (NullPointerException ex) { + Debug.FAILED_ATTEMPT_TO_SPAWN_BOSS.debug(ex.getMessage()); + return null; + } + + return livingEntity; + } else { + return (LivingEntity) location.getWorld().spawnEntity(location, getEntityType()); + } + } + public static EntityFinder get(String name) { for(EntityFinder entityFinder : values()) { for (String s : entityFinder.getNames()) { diff --git a/pom.xml b/pom.xml index d6f64c1..1932cd5 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 3.0.0-SNAPSHOT-U16 + 3.0.0-SNAPSHOT-U17 CustomBosses net.aminecraftdev.custombosses.CustomBosses AMinecraftDev