diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java index 0df1b24..c98e992 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java @@ -4,6 +4,9 @@ import com.google.common.collect.ImmutableMap; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.PluginDependent; import com.willfp.eco.core.config.interfaces.Config; +import com.willfp.eco.core.entities.CustomEntity; +import com.willfp.eco.core.entities.Entities; +import com.willfp.eco.core.entities.TestableEntity; import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry; import com.willfp.eco.core.items.Items; import com.willfp.eco.core.items.builder.ItemBuilder; @@ -16,8 +19,7 @@ import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; import com.willfp.ecobosses.bosses.effects.Effect; import com.willfp.ecobosses.bosses.effects.Effects; -import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils; -import com.willfp.ecobosses.bosses.util.bosstype.BossType; +import com.willfp.ecobosses.bosses.util.BossUtils; import com.willfp.ecobosses.bosses.util.obj.ArgumentedEffectName; import com.willfp.ecobosses.bosses.util.obj.BossbarProperties; import com.willfp.ecobosses.bosses.util.obj.EquipmentPiece; @@ -62,7 +64,7 @@ public class EcoBoss extends PluginDependent { * The name of the boss. */ @Getter - private final String name; + private final String id; /** * The config of the set. @@ -79,7 +81,7 @@ public class EcoBoss extends PluginDependent { /** * The base entity spawner. */ - private final BossType bossType; + private final TestableEntity bossType; /** * If the boss bar is enabled. @@ -317,16 +319,16 @@ public class EcoBoss extends PluginDependent { /** * Create a new Boss. * - * @param name The name of the set. + * @param id The name of the set. * @param config The set's config. * @param plugin Instance of EcoBosses. */ - public EcoBoss(@NotNull final String name, + public EcoBoss(@NotNull final String id, @NotNull final Config config, @NotNull final EcoPlugin plugin) { super(plugin); this.config = config; - this.name = name; + this.id = id; this.livingBosses = new HashMap<>(); this.isGlowing = this.getConfig().getBool("glowing"); this.baby = this.getConfig().getBool("baby"); @@ -334,7 +336,7 @@ public class EcoBoss extends PluginDependent { this.displayName = this.getConfig().getFormattedString("name"); // Boss Type - this.bossType = BossEntityUtils.getBossType(this.getConfig().getString("base-mob")); + this.bossType = Entities.lookup("base-mob"); // Boss Bar this.bossbarEnabled = this.getConfig().getBool("bossbar.enabled"); @@ -419,7 +421,7 @@ public class EcoBoss extends PluginDependent { // Rewards this.drops = new ArrayList<>(); - drops.addAll(this.getConfig().getStrings("rewards.drops", false)); + drops.addAll(this.getConfig().getStrings("rewards.drops")); this.experienceOptions = new ExperienceOptions( this.getConfig().getInt("rewards.xp.minimum"), @@ -516,7 +518,7 @@ public class EcoBoss extends PluginDependent { this.topDamagerCommands = new HashMap<>(); for (int i = 1; i <= 3; i++) { this.topDamagerCommands.put(i, new ArrayList<>()); - for (String string : this.getConfig().getStrings("rewards.top-damager-commands." + i, false)) { + for (String string : this.getConfig().getStrings("rewards.top-damager-commands." + i)) { double chance = 100; if (string.contains("::")) { String[] split = string.split("::"); @@ -532,7 +534,7 @@ public class EcoBoss extends PluginDependent { // Nearby Rewards this.nearbyRadius = this.getConfig().getDouble("rewards.nearby-player-commands.radius"); this.nearbyPlayersCommands = new HashMap<>(); - for (String string : this.getConfig().getStrings("rewards.nearby-player-commands.commands", false)) { + for (String string : this.getConfig().getStrings("rewards.nearby-player-commands.commands")) { double chance = 100; if (string.contains("::")) { String[] split = string.split("::"); @@ -547,18 +549,13 @@ public class EcoBoss extends PluginDependent { for (String string : this.getConfig().getStrings("effects")) { String effectName = string.split(":")[0]; List args = new ArrayList<>(Arrays.asList(string.replace(effectName + ":", "").split(":"))); - if (args.contains("mythicmobs")) { - String newArg = "mythicmobs:" + args.get(args.indexOf("mythicmobs")+1); - args.set(args.indexOf("mythicmobs"), newArg); - args.remove(args.get(args.indexOf(newArg)+1)); - } this.effectNames.add(new ArgumentedEffectName(effectName, args)); } for (ArgumentedEffectName effectName : new ArrayList<>(this.effectNames)) { if (Effects.getEffect(effectName.name(), effectName.args()) == null) { this.effectNames.remove(effectName); - Bukkit.getLogger().warning("Invalid effect " + effectName.name() + " specified in " + this.name); + Bukkit.getLogger().warning("Invalid effect " + effectName.name() + " specified in " + this.id); } } @@ -583,12 +580,12 @@ public class EcoBoss extends PluginDependent { } new PlaceholderEntry( - "timeuntilspawn_"+this.name, - (player) -> new BigDecimal(this.timeUntilSpawn/20).setScale(1, RoundingMode.HALF_UP).toString(), + "timeuntilspawn_" + this.id, + (player) -> new BigDecimal(this.timeUntilSpawn / 20).setScale(1, RoundingMode.HALF_UP).toString(), false ).register(); - for (String req : config.getStrings("spawn-requirements", false)) { + for (String req : config.getStrings("spawn-requirements")) { List split = Arrays.asList(req.split(":")); if (split.size() < 2) { continue; @@ -608,7 +605,7 @@ public class EcoBoss extends PluginDependent { ItemBuilder builder = new ItemStackBuilder(material) .setDisplayName(this.getConfig().getString("spawn-egg.name")) .addLoreLines(this.getConfig().getStrings("spawn-egg.lore")) - .writeMetaKey(this.getPlugin().getNamespacedKeyFactory().create("spawn_egg"), PersistentDataType.STRING, this.getName()); + .writeMetaKey(this.getPlugin().getNamespacedKeyFactory().create("spawn_egg"), PersistentDataType.STRING, this.getId()); if (this.getConfig().getBool("spawn-egg.glow")) { builder.addEnchantment(Enchantment.DURABILITY, 1) @@ -620,9 +617,9 @@ public class EcoBoss extends PluginDependent { if (this.getConfig().getBool("spawn-egg.craftable")) { Recipes.createAndRegisterRecipe( this.getPlugin(), - "spawn_egg_" + this.getName(), + "spawn_egg_" + this.getId(), this.getSpawnEgg(), - this.getConfig().getStrings("spawn-egg.recipe", false) + this.getConfig().getStrings("spawn-egg.recipe") ); } } else { @@ -631,6 +628,17 @@ public class EcoBoss extends PluginDependent { if (this.getConfig().getBool("enabled")) { EcoBosses.addBoss(this); + + new CustomEntity( + this.getPlugin().getNamespacedKeyFactory().create(this.id), + test -> { + if (!(test instanceof LivingEntity living)) { + return false; + } + return Objects.equals(this, BossUtils.getBoss(living)); + }, + this::spawn + ).register(); } } @@ -676,7 +684,7 @@ public class EcoBoss extends PluginDependent { ItemStack itemStack = Items.lookup(dropName).getItem(); if (itemStack.getType() == Material.AIR) { - Bukkit.getLogger().warning(this.getName() + " has an invalid drop configured! (" + dropName + ")"); + Bukkit.getLogger().warning(this.getId() + " has an invalid drop configured! (" + dropName + ")"); continue; } @@ -707,16 +715,17 @@ public class EcoBoss extends PluginDependent { * * @param location The location. */ - public void spawn(@NotNull final Location location) { + public LivingEntity spawn(@NotNull final Location location) { location.getChunk().load(); - LivingEntity entity = bossType.spawnBossEntity(location); + LivingEntity entity = (LivingEntity) bossType.spawn(location); this.livingBosses.put(entity, new LivingEcoBoss( this.getPlugin(), entity, this ) ); + return entity; } /** @@ -757,18 +766,18 @@ public class EcoBoss extends PluginDependent { return false; } - return this.getName().equals(boss.getName()); + return this.getId().equals(boss.getId()); } @Override public int hashCode() { - return Objects.hash(this.getName()); + return Objects.hash(this.getId()); } @Override public String toString() { return "EcoBoss{" - + this.getName() + + this.getId() + "}"; } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBosses.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBosses.java index 8dd3157..a64143a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBosses.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBosses.java @@ -89,8 +89,8 @@ public class EcoBosses { * @param set The {@link EcoBoss} to add. */ public static void addBoss(@NotNull final EcoBoss set) { - BY_NAME.remove(set.getName()); - BY_NAME.put(set.getName(), set); + BY_NAME.remove(set.getId()); + BY_NAME.put(set.getId(), set); } /** @@ -99,6 +99,6 @@ public class EcoBosses { * @param set The {@link EcoBoss} to remove. */ public static void removeBoss(@NotNull final EcoBoss set) { - BY_NAME.remove(set.getName()); + BY_NAME.remove(set.getId()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/LivingEcoBoss.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/LivingEcoBoss.java index e2fe248..18d255e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/LivingEcoBoss.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/LivingEcoBoss.java @@ -98,7 +98,7 @@ public class LivingEcoBoss extends PluginDependent { } private void onSpawn() { - entity.getPersistentDataContainer().set(this.getPlugin().getNamespacedKeyFactory().create("boss"), PersistentDataType.STRING, boss.getName()); + entity.getPersistentDataContainer().set(this.getPlugin().getNamespacedKeyFactory().create("boss"), PersistentDataType.STRING, boss.getId()); entity.setPersistent(true); entity.setRemoveWhenFarAway(false); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/effects/effects/EffectSummon.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/effects/effects/EffectSummon.java index 9f06981..963add6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/effects/effects/EffectSummon.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/effects/effects/EffectSummon.java @@ -1,10 +1,10 @@ package com.willfp.ecobosses.bosses.effects.effects; +import com.willfp.eco.core.entities.Entities; +import com.willfp.eco.core.entities.TestableEntity; import com.willfp.eco.util.NumberUtils; import com.willfp.ecobosses.bosses.EcoBoss; import com.willfp.ecobosses.bosses.effects.Effect; -import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils; -import com.willfp.ecobosses.bosses.util.bosstype.BossType; import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import org.bukkit.Location; import org.bukkit.Material; @@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; public class EffectSummon extends Effect { - private final BossType type; + private final TestableEntity type; private final double chance; public EffectSummon(@NotNull final List args) { @@ -27,7 +27,7 @@ public class EffectSummon extends Effect { showConfigError("Incorrect amount of arguments!"); } - type = BossEntityUtils.getBossType(args.get(0)); + type = Entities.lookup(args.get(0)); chance = Double.parseDouble(args.get(1)); } @@ -53,7 +53,7 @@ public class EffectSummon extends Effect { loc.add(0, 1, 0); } - Entity summonedEntity = type.spawnBossEntity(loc); + Entity summonedEntity = type.spawn(loc); if (summonedEntity instanceof Mob) { ((Mob) summonedEntity).setTarget(player); } 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 deleted file mode 100644 index cc50e7c..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossEntityUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.willfp.ecobosses.bosses.util.bosstype; - -import io.lumine.xikage.mythicmobs.MythicMobs; -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; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -@UtilityClass -@SuppressWarnings("unchecked") -public class BossEntityUtils { - /** - * Get boss type. - * - * @param id The name. - * @return The boss type. - */ - public static BossType getBossType(@NotNull String id) { - - if (id.startsWith("mythicmobs:")) { - int level; - - try { - level = Integer.parseInt(Arrays.stream(id.split("_")).toList().get(id.split("_").length - 1)); - } catch (NumberFormatException exception) { - level = 1; - } - - MythicMob mob = MythicMobs.inst().getMobManager().getMythicMob(id.replace("mythicmobs:", "") - .replace("_" + level, "")); - - if (mob != null) { - return new MythicMobsBossType(mob, level); - } - } - - if (id.equalsIgnoreCase("charged_creeper")) { - return new ChargedCreeperBossType(); - } - - try { - Class type = (Class) EntityType.valueOf(id.toUpperCase()).getEntityClass(); - assert type != null; - return new VanillaBossType(type); - } catch (IllegalArgumentException ignored) { - } - - return new VanillaBossType(Zombie.class); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossType.java deleted file mode 100644 index 0a55461..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/BossType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.willfp.ecobosses.bosses.util.bosstype; - -import org.bukkit.Location; -import org.bukkit.entity.LivingEntity; -import org.jetbrains.annotations.NotNull; - -public abstract class BossType { - /** - * Spawn boss entity. - * - * @param location The location. - * @return The entity. - */ - public abstract LivingEntity spawnBossEntity(@NotNull Location location); -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/ChargedCreeperBossType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/ChargedCreeperBossType.java deleted file mode 100644 index c867868..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/ChargedCreeperBossType.java +++ /dev/null @@ -1,30 +0,0 @@ -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; - -import java.util.Objects; - -class ChargedCreeperBossType extends VanillaBossType { - /** - * Create new Charged Creeper boss type. - */ - ChargedCreeperBossType() { - super(Creeper.class); - } - - /** - * Spawn a charged creeper. - * - * @param location The location. - * @return The entity. - */ - @Override - public LivingEntity spawnBossEntity(@NotNull final Location location) { - Creeper creeper = Objects.requireNonNull(location.getWorld()).spawn(location, Creeper.class); - creeper.setPowered(true); - return creeper; - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/MythicMobsBossType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/MythicMobsBossType.java deleted file mode 100644 index 1ef6a02..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/MythicMobsBossType.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.willfp.ecobosses.bosses.util.bosstype; - -import io.lumine.xikage.mythicmobs.MythicMobs; -import io.lumine.xikage.mythicmobs.adapters.AbstractLocation; -import io.lumine.xikage.mythicmobs.adapters.AbstractWorld; -import io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException; -import io.lumine.xikage.mythicmobs.mobs.MythicMob; -import org.bukkit.Location; -import org.bukkit.entity.LivingEntity; -import org.jetbrains.annotations.NotNull; - -public class MythicMobsBossType extends BossType { - - /** - * The entity type. - */ - private final MythicMob boss; - - /** - * Level of MythicMobs mob - */ - private final int level; - - /** - * Create new vanilla boss type. - * - * @param boss The MythicMob. - */ - public MythicMobsBossType(MythicMob boss, int level) { - this.boss = boss; - this.level = level; - } - - - @Override - public LivingEntity spawnBossEntity(@NotNull Location location) { - try { - return (LivingEntity) MythicMobs.inst().getAPIHelper().spawnMythicMob(boss, location, level); - } catch (InvalidMobTypeException e) { - e.printStackTrace(); - } - return 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 deleted file mode 100644 index f1f3195..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/bosstype/VanillaBossType.java +++ /dev/null @@ -1,30 +0,0 @@ -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; - -import java.util.Objects; - -class VanillaBossType extends BossType { - /** - * The entity type. - */ - private final Class entityClass; - - /** - * Create new vanilla boss type. - * - * @param entityClass The entity class. - */ - VanillaBossType(@NotNull final Class entityClass) { - this.entityClass = entityClass; - } - - @Override - public LivingEntity spawnBossEntity(@NotNull final Location location) { - LivingEntity result = Objects.requireNonNull(location.getWorld()).spawn(location, entityClass); - return result; - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java index d283ae1..766a965 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandGive.java @@ -56,7 +56,7 @@ public class CommandGive extends Subcommand { BOSS_NAMES.clear(); BOSS_NAMES.addAll(EcoBosses.values().stream() .filter(boss -> boss.getSpawnEgg() != null) - .map(EcoBoss::getName) + .map(EcoBoss::getId) .collect(Collectors.toList())); } @@ -101,7 +101,7 @@ public class CommandGive extends Subcommand { } String message = this.getPlugin().getLangYml().getMessage("give-success"); - message = message.replace("%boss%", boss.getName()).replace("%recipient%", reciever.getName()); + message = message.replace("%boss%", boss.getId()).replace("%recipient%", reciever.getName()); sender.sendMessage(message); ItemStack itemStack = boss.getSpawnEgg(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java index daf433b..8594ccf 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/commands/CommandSpawn.java @@ -48,7 +48,7 @@ public class CommandSpawn extends Subcommand { @ConfigUpdater public static void reload() { BOSS_NAMES.clear(); - BOSS_NAMES.addAll(EcoBosses.values().stream().map(EcoBoss::getName).collect(Collectors.toList())); + BOSS_NAMES.addAll(EcoBosses.values().stream().map(EcoBoss::getId).collect(Collectors.toList())); } @Override