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 e958c7d..6ad7726 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 @@ -1,6 +1,7 @@ package com.willfp.ecobosses.bosses; import com.willfp.eco.internal.config.AbstractUndefinedConfig; +import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; @@ -11,6 +12,7 @@ import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions; import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions; import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import com.willfp.ecobosses.bosses.util.obj.SpawnTotem; +import com.willfp.ecobosses.bosses.util.obj.TeleportOptions; import com.willfp.ecobosses.bosses.util.obj.attacks.EffectOption; import com.willfp.ecobosses.bosses.util.obj.attacks.SummonsOption; import lombok.AccessLevel; @@ -31,10 +33,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SpawnEggMeta; import org.bukkit.persistence.PersistentDataType; +import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -172,6 +176,18 @@ public class EcoBoss extends PluginDependent { @Getter private final List summonSounds; + /** + * If the boss can teleport. + */ + @Getter + private final boolean teleportationEnabled; + + /** + * Teleport options. + */ + @Getter + private final TeleportOptions teleportOptions; + /** * Create a new Boss. * @@ -315,6 +331,13 @@ public class EcoBoss extends PluginDependent { meta.getPersistentDataContainer().set(this.getPlugin().getNamespacedKeyFactory().create("spawn_egg"), PersistentDataType.STRING, this.getName()); this.spawnEgg.setItemMeta(meta); + // Teleportation + this.teleportationEnabled = this.getConfig().getBool("defence.teleport.enabled"); + this.teleportOptions = new TeleportOptions( + this.getConfig().getInt("defence.teleport.range"), + this.getConfig().getDouble("defence.teleport.chance") + ); + if (this.getConfig().getBool("enabled")) { EcoBosses.addBoss(this); } @@ -338,6 +361,10 @@ public class EcoBoss extends PluginDependent { assert attackDamage != null; attackDamage.setBaseValue(this.getAttackDamage()); + for (OptionedSound sound : this.getSpawnSounds()) { + location.getWorld().playSound(location, sound.getSound(), sound.getVolume(), sound.getPitch()); + } + if (this.isBossbarEnabled()) { createBossBar(entity); } @@ -377,6 +404,57 @@ public class EcoBoss extends PluginDependent { }).runTaskTimer(0, 1); } + /** + * Handle an attack to the player. + * + * @param entity The entity. + * @param player The player. + */ + public void handleAttack(@NotNull final LivingEntity entity, + @NotNull final Player player) { + for (OptionedSound sound : this.getInjureSounds()) { + player.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch()); + } + + for (EffectOption effect : this.getEffects()) { + if (NumberUtils.randFloat(0, 100) > effect.getChance()) { + return; + } + + player.addPotionEffect(new PotionEffect(effect.getEffectType(), effect.getDuration(), effect.getLevel())); + } + + if (NumberUtils.randFloat(0, 100) < this.getShuffleChance()) { + List hotbar = new ArrayList<>(); + for (int i = 0; i < 9; i++) { + hotbar.add(player.getInventory().getItem(i)); + } + Collections.shuffle(hotbar); + int i2 = 0; + for (ItemStack item : hotbar) { + player.getInventory().setItem(i2, item); + i2++; + } + player.playSound(player.getLocation(), Sound.ENTITY_ENDER_PEARL_THROW, 1, 0.5f); + } + + for (SummonsOption summon : this.getSummons()) { + if (NumberUtils.randFloat(0, 100) > summon.getChance()) { + return; + } + + Location loc = player.getLocation().add(NumberUtils.randInt(2, 6), 0, NumberUtils.randInt(2, 6)); + while (!loc.getBlock().getType().equals(Material.AIR)) { + loc.add(0, 1, 0); + } + player.getWorld().spawnEntity(loc, summon.getType()); + + for (OptionedSound sound : this.getSummonSounds()) { + player.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch()); + } + } + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/AttackListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/AttackListeners.java index 344c9d2..1904b74 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/AttackListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/AttackListeners.java @@ -1,22 +1,19 @@ package com.willfp.ecobosses.bosses.listeners; import com.willfp.eco.util.NumberUtils; -import com.willfp.ecobosses.bosses.util.obj.OptionedSound; +import com.willfp.ecobosses.bosses.EcoBoss; +import com.willfp.ecobosses.bosses.util.BossUtils; +import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -25,138 +22,109 @@ import java.util.List; public class AttackListeners implements Listener { /** - * Called when a player attacks an illusioner. + * Called when a player attacks a boss. * * @param event The event to listen for. */ @EventHandler(ignoreCancelled = true) - public void onIllusionerAttack(@NotNull final EntityDamageByEntityEvent event) { - if (!event.getDamager().getType().equals(EntityType.ILLUSIONER)) { + public void onAttackBoss(@NotNull final EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player)) { return; } + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + + LivingEntity entity = (LivingEntity) event.getEntity(); + + Player player = (Player) event.getDamager(); + + EcoBoss boss = BossUtils.getBoss(entity); + + if (boss == null) { + return; + } + + if (boss.isAttackOnInjure()) { + boss.handleAttack(entity, player); + } + } + + /** + * Called when a boss attacks a player. + * + * @param event The event to listen for. + */ + @EventHandler(ignoreCancelled = true) + public void onAttackPlayer(@NotNull final EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Player)) { return; } - handleAttack((LivingEntity) event.getDamager(), (Player) event.getEntity()); + if (!(event.getDamager() instanceof LivingEntity)) { + return; + } + + LivingEntity entity = (LivingEntity) event.getDamager(); + + Player player = (Player) event.getEntity(); + + EcoBoss boss = BossUtils.getBoss(entity); + + if (boss == null) { + return; + } + + if (boss.isAttackOnInjure()) { + boss.handleAttack(entity, player); + } } /** - * Called when a player attacks an illusioner. + * Called when a boss is damaged. * * @param event The event to listen for. */ @EventHandler(ignoreCancelled = true) - public void onAttackIllusioner(@NotNull final EntityDamageByEntityEvent event) { - if (!event.getEntity().getType().equals(EntityType.ILLUSIONER)) { + public void defenceListener(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof LivingEntity)) { return; } - Player temp = null; + LivingEntity entity = (LivingEntity) event.getEntity(); - if (event.getDamager() instanceof Player) { - temp = (Player) event.getDamager(); - } else if (event.getDamager() instanceof Projectile) { - if (((Projectile) event.getDamager()).getShooter() instanceof Player) { - temp = (Player) ((Projectile) event.getDamager()).getShooter(); - } - } + EcoBoss boss = BossUtils.getBoss(entity); - if (temp == null) { + if (boss == null) { return; } - Player player = temp; + ImmunityOptions immunities = boss.getImmunityOptions(); - handleAttack((LivingEntity) event.getEntity(), player); - } - - private void handleAttack(@NotNull final LivingEntity illusioner, - @NotNull final Player player) { - OptionedSound hitSound = IllusionerManager.OPTIONS.getGameplayOptions().getHitSound(); - if (hitSound.isBroadcast()) { - player.getWorld().playSound(illusioner.getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch()); - } else { - player.playSound(illusioner.getLocation(), hitSound.getSound(), hitSound.getVolume(), hitSound.getPitch()); + if (immunities.isImmuneToFire() && (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) { + event.setCancelled(true); } - IllusionerManager.OPTIONS.getGameplayOptions().getEffectOptions().forEach(effectOption -> { - if (NumberUtils.randFloat(0, 100) > effectOption.getChance()) { - return; - } - - player.addPotionEffect(new PotionEffect(effectOption.getEffectType(), effectOption.getDuration(), effectOption.getLevel() - 1)); - }); - - if (IllusionerManager.OPTIONS.getGameplayOptions().isShuffle()) { - if (NumberUtils.randFloat(0, 100) < IllusionerManager.OPTIONS.getGameplayOptions().getShuffleChance()) { - List hotbar = new ArrayList<>(); - for (int i = 0; i < 9; i++) { - hotbar.add(player.getInventory().getItem(i)); - } - Collections.shuffle(hotbar); - int i2 = 0; - for (ItemStack item : hotbar) { - player.getInventory().setItem(i2, item); - i2++; - } - player.playSound(player.getLocation(), Sound.ENTITY_ENDER_PEARL_THROW, 1, 0.5f); - } + if (immunities.isImmuneToSuffocation() && event.getCause() == EntityDamageEvent.DamageCause.SUFFOCATION) { + event.setCancelled(true); } - IllusionerManager.OPTIONS.getGameplayOptions().getSummonerOptions().forEach(summonerOption -> { - if (NumberUtils.randFloat(0, 100) > summonerOption.getChance()) { - return; - } - - Location loc = player.getLocation().add(NumberUtils.randInt(2, 6), 0, NumberUtils.randInt(2, 6)); - while (!loc.getBlock().getType().equals(Material.AIR)) { - loc.add(0, 1, 0); - } - player.getWorld().spawnEntity(loc, summonerOption.getType()); - - OptionedSound summonSound = IllusionerManager.OPTIONS.getGameplayOptions().getSummonSound(); - if (summonSound.isBroadcast()) { - player.getWorld().playSound(illusioner.getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch()); - } else { - player.playSound(illusioner.getLocation(), summonSound.getSound(), summonSound.getVolume(), summonSound.getPitch()); - } - }); - } - - /** - * Called when the illusioner is damaged. - * - * @param event The event to listen for. - */ - @EventHandler(ignoreCancelled = true) - public void onIllusionerDamage(@NotNull final EntityDamageEvent event) { - if (!event.getEntity().getType().equals(EntityType.ILLUSIONER)) { - return; + if (immunities.isImmuneToDrowning() && event.getCause() == EntityDamageEvent.DamageCause.DROWNING) { + event.setCancelled(true); } - if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreExplosionDamage()) { - if (event.getCause().equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) || event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) { - event.setCancelled(true); - } + if (immunities.isImmuneToExplosions() && (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION || event.getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)) { + event.setCancelled(true); } - if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreFire()) { - if (event.getCause().equals(EntityDamageEvent.DamageCause.FIRE) || event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK)) { - event.setCancelled(true); - } + if (immunities.isImmuneToProjectiles() && (event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE)) { + event.setCancelled(true); } - if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreSuffocation()) { - if (event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION)) { - event.setCancelled(true); - } - } - - if (IllusionerManager.OPTIONS.getGameplayOptions().isTeleport()) { - if (NumberUtils.randFloat(0, 100) < IllusionerManager.OPTIONS.getGameplayOptions().getTeleportChance()) { - int range = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportRange(); + if (boss.isTeleportationEnabled()) { + if (NumberUtils.randFloat(0, 100) < boss.getTeleportOptions().getChance()) { + int range = boss.getTeleportOptions().getRange(); List valid = new ArrayList<>(); for (int x = -range; x <= range; x++) { for (int y = -range; y <= range; y++) { @@ -185,8 +153,6 @@ public class AttackListeners implements Listener { Location location = valid.get(0); event.getEntity().teleport(location); - OptionedSound optionedSound = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportSound(); - location.getWorld().playSound(location, optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch()); } } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java index 48fefcf..610f459 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java @@ -2,10 +2,10 @@ package com.willfp.ecobosses.bosses.listeners; import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent; +import com.willfp.ecobosses.bosses.EcoBoss; +import com.willfp.ecobosses.bosses.util.BossUtils; import com.willfp.ecobosses.bosses.util.obj.OptionedSound; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -19,39 +19,36 @@ public class DeathListeners implements Listener { * @param event The event to listen for. */ @EventHandler - public void onIllusionerDeath(@NotNull final EntityDeathByEntityEvent event) { - if (!event.getDeathEvent().getEntityType().equals(EntityType.ILLUSIONER)) { + public void onBossDeath(@NotNull final EntityDeathByEntityEvent event) { + LivingEntity entity = event.getVictim(); + + EcoBoss boss = BossUtils.getBoss(entity); + + if (boss == null) { return; } - Player player = null; - - if (event.getKiller() instanceof Player) { - player = (Player) event.getKiller(); - } else if (event.getKiller() instanceof Projectile) { - if (((Projectile) event.getKiller()).getShooter() instanceof Player) { - player = (Player) ((Projectile) event.getKiller()).getShooter(); - } - } - - for (OptionedSound sound : IllusionerManager.OPTIONS.getDeathSounds()) { - if (sound.isBroadcast()) { - event.getKiller().getWorld().playSound(event.getVictim().getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch()); - } else { - if (player != null) { - player.playSound(event.getVictim().getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch()); - } - } + for (OptionedSound sound : boss.getDeathSounds()) { + entity.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch()); } } + /** + * Handle drops and experience. + * + * @param event The event. + */ @EventHandler(priority = EventPriority.LOW) public void onOtherDeath(@NotNull final EntityDeathEvent event) { - if (event.getEntityType() != EntityType.ILLUSIONER) { + LivingEntity entity = event.getEntity(); + + EcoBoss boss = BossUtils.getBoss(entity); + + if (boss == null) { return; } - event.getDrops().addAll(IllusionerManager.OPTIONS.getDrops()); - event.setDroppedExp(IllusionerManager.OPTIONS.generateXp()); + event.getDrops().addAll(boss.getDrops()); + event.setDroppedExp(boss.getExperienceOptions().generateXp()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/SpawnListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/SpawnListeners.java index 6457ef3..d0d0419 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/SpawnListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/SpawnListeners.java @@ -1,21 +1,16 @@ package com.willfp.ecobosses.bosses.listeners; import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.ecobosses.bosses.EcoBoss; +import com.willfp.ecobosses.bosses.EcoBosses; import com.willfp.ecobosses.bosses.util.obj.SpawnTotem; -import com.willfp.ecobosses.proxy.proxies.CustomIllusionerProxy; -import com.willfp.ecobosses.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.Illusioner; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntitySpawnEvent; import org.jetbrains.annotations.NotNull; -import java.util.HashSet; -import java.util.Set; - public class SpawnListeners extends PluginDependent implements Listener { /** * Create new spawn listeners and link them to a plugin. @@ -32,9 +27,7 @@ public class SpawnListeners extends PluginDependent implements Listener { * @param event The event to listen for. */ @EventHandler - public void onSpawn(@NotNull final BlockPlaceEvent event) { - boolean matches = false; - Set match = new HashSet<>(); + public void spawnTotem(@NotNull final BlockPlaceEvent event) { for (int i = 0; i < 3; i++) { Block block1; Block block2; @@ -54,54 +47,19 @@ public class SpawnListeners extends PluginDependent implements Listener { block3 = event.getBlock().getRelative(0, 1, 0); } - matches = SpawnTotem.matches(new SpawnTotem(block1.getType(), block2.getType(), block3.getType())); - if (matches) { - match.add(block1); - match.add(block2); - match.add(block3); - break; + SpawnTotem placedTotem = new SpawnTotem(block1.getType(), block2.getType(), block3.getType()); + + for (EcoBoss boss : EcoBosses.values()) { + if (boss.isSpawnTotemEnabled()) { + if (boss.getSpawnTotem().equals(placedTotem)) { + block1.setType(Material.AIR); + block2.setType(Material.AIR); + block3.setType(Material.AIR); + + boss.spawn(event.getBlock().getLocation()); + } + } } } - - if (!matches) { - return; - } - - match.forEach(block -> block.setType(Material.AIR)); - IllusionerManager.OPTIONS.getSpawnSounds().forEach(optionedSound -> { - if (optionedSound.isBroadcast()) { - event.getBlock().getWorld().playSound(event.getBlock().getLocation(), optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch()); - } else { - event.getPlayer().playSound(event.getBlock().getLocation(), optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch()); - } - }); - - CustomIllusionerProxy illusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).spawn(event.getBlock().getLocation()); - illusioner.createBossbar(this.getPlugin()); - } - - /** - * Called on vanilla illusioner spawn. - * - * @param event The event to listen for. - */ - @EventHandler - public void onExternalSpawn(@NotNull final EntitySpawnEvent event) { - if (!(event.getEntity() instanceof Illusioner)) { - return; - } - - if (!IllusionerManager.OPTIONS.isOverride()) { - return; - } - - Illusioner illusioner = (Illusioner) event.getEntity(); - - CustomIllusionerProxy internalIllusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).adapt(illusioner); - - if (internalIllusioner == null) { - return; - } - internalIllusioner.createBossbar(this.getPlugin()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/GameplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/GameplayOptions.java deleted file mode 100644 index bd94652..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/GameplayOptions.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.willfp.ecobosses.bosses.options; - -import com.willfp.eco.util.internal.PluginDependent; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.ecobosses.bosses.util.obj.attacks.EffectOption; -import com.willfp.ecobosses.bosses.util.obj.OptionedSound; -import lombok.Getter; -import lombok.ToString; -import org.bukkit.Sound; -import org.bukkit.entity.EntityType; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; - -import java.util.HashSet; -import java.util.Set; - -@ToString -public class GameplayOptions extends PluginDependent { - /** - * The sound played when the illusioner takes damage. - */ - @Getter - private OptionedSound hitSound; - - /** - * The sound played when the illusioner spawns. - */ - @Getter - private OptionedSound summonSound; - - /** - * The potion effect options. - */ - @Getter - private final Set effectOptions = new HashSet<>(); - - /** - * The mob summon options. - */ - @Getter - private final Set summonerOptions = new HashSet<>(); - - /** - * If the illusioner should shuffle hotbars. - */ - @Getter - private boolean shuffle; - - /** - * The chance of the illusioner shuffling a hotbar. - */ - @Getter - private double shuffleChance; - - /** - * If the illusioner is immune to explosion damage. - */ - @Getter - private boolean ignoreExplosionDamage; - - /** - * If the illusioner is immune to fire damage. - */ - @Getter - private boolean ignoreFire; - - /** - * If the illusioner is immune to suffocation damage. - */ - @Getter - private boolean ignoreSuffocation; - - /** - * If the illusioner can teleport. - */ - @Getter - private boolean teleport; - - /** - * Teleport range. - */ - @Getter - private int teleportRange; - - /** - * Teleport chance. - */ - @Getter - private double teleportChance; - - /** - * Teleport sound. - */ - @Getter - private OptionedSound teleportSound; - - /** - * Gameplay options. - * - * @param plugin The plugin. - */ - public GameplayOptions(@NotNull final AbstractEcoPlugin plugin) { - super(plugin); - } - - /** - * Reload the options. - */ - public void reload() { - hitSound = new OptionedSound( - Sound.valueOf(EcoBossesConfigs.SOUNDS.getString("hit.sound")), - (float) EcoBossesConfigs.SOUNDS.getDouble("hit.volume"), - (float) EcoBossesConfigs.SOUNDS.getDouble("hit.pitch"), - EcoBossesConfigs.SOUNDS.getBool("hit.broadcast") - ); - - summonSound = new OptionedSound( - Sound.valueOf(EcoBossesConfigs.SOUNDS.getString("summon.sound")), - (float) EcoBossesConfigs.SOUNDS.getDouble("summon.volume"), - (float) EcoBossesConfigs.SOUNDS.getDouble("summon.pitch"), - EcoBossesConfigs.SOUNDS.getBool("summon.broadcast") - ); - - shuffle = EcoBossesConfigs.ATTACKS.getBool("shuffle.enabled"); - shuffleChance = EcoBossesConfigs.ATTACKS.getDouble("shuffle.chance"); - - ignoreExplosionDamage = this.getPlugin().getConfigYml().getBool("ignore-explosion-damage"); - ignoreFire = this.getPlugin().getConfigYml().getBool("ignore-fire-damage"); - ignoreSuffocation = this.getPlugin().getConfigYml().getBool("ignore-suffocation-damage"); - - teleport = this.getPlugin().getConfigYml().getBool("teleport-on-damage.enabled"); - teleportRange = this.getPlugin().getConfigYml().getInt("teleport-on-damage.range"); - teleportChance = this.getPlugin().getConfigYml().getDouble("teleport-on-damage.chance"); - - Sound sound = Sound.valueOf(EcoBossesConfigs.SOUNDS.getString("teleport.sound")); - float volume = (float) EcoBossesConfigs.SOUNDS.getDouble("teleport.volume"); - float pitch = (float) EcoBossesConfigs.SOUNDS.getDouble("teleport.pitch"); - teleportSound = new OptionedSound(sound, volume, pitch, true); - - effectOptions.clear(); - EcoBossesConfigs.ATTACKS.getConfig().getConfigurationSection("effects").getKeys(false).forEach(key -> { - PotionEffectType type = PotionEffectType.getByName(EcoBossesConfigs.ATTACKS.getString("effects." + key + ".type")); - int level = EcoBossesConfigs.ATTACKS.getInt("effects." + key + ".level"); - int duration = EcoBossesConfigs.ATTACKS.getInt("effects." + key + ".duration"); - double chance = EcoBossesConfigs.ATTACKS.getDouble("effects." + key + ".chance"); - effectOptions.add(new EffectOption(chance, level, duration, type)); - }); - - summonerOptions.clear(); - EcoBossesConfigs.ATTACKS.getConfig().getConfigurationSection("summons").getKeys(false).forEach(key -> { - EntityType type = EntityType.valueOf(EcoBossesConfigs.ATTACKS.getString("summons." + key + ".type")); - double chance = EcoBossesConfigs.ATTACKS.getDouble("summons." + key + ".chance"); - summonerOptions.add(new SummonerOption(chance, type)); - }); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/IllusionerOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/IllusionerOptions.java deleted file mode 100644 index 590d27a..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/options/IllusionerOptions.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.willfp.ecobosses.bosses.options; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.internal.PluginDependent; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; -import com.willfp.eco.util.tuples.Pair; -import com.willfp.ecobosses.bosses.util.obj.SpawnTotem; -import com.willfp.ecobosses.bosses.util.obj.OptionedSound; -import lombok.Getter; -import lombok.ToString; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarStyle; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -@ToString -public class IllusionerOptions extends PluginDependent { - /** - * The boss bar color. - */ - @Getter - private BarColor color; - - /** - * The boss bar style. - */ - @Getter - private BarStyle style; - - /** - * The name of the illusioner. - */ - @Getter - private String name; - - /** - * The spawn sounds. - */ - @Getter - private Set spawnSounds; - - /** - * The death sounds. - */ - @Getter - private Set deathSounds; - - /** - * The xp bounds. - */ - private Pair xpBounds; - - /** - * The spawn block structure. - */ - @Getter - private SpawnTotem spawnStructure; - - /** - * The max health. - */ - @Getter - private double maxHealth; - - /** - * The attack damage. - */ - @Getter - private double attackDamage; - - /** - * The drops. - */ - @Getter - private List drops; - - /** - * The gameplay options. - */ - @Getter - private final GameplayOptions gameplayOptions = new GameplayOptions(this.getPlugin()); - - /** - * If plugin-based illusioners should override vanilla illusioners. - */ - @Getter - private boolean override; - - /** - * Create new illusioner options. - * - * @param plugin The plugin. - */ - public IllusionerOptions(@NotNull final AbstractEcoPlugin plugin) { - super(plugin); - reload(); - } - - /** - * Reload options from config. - */ - public void reload() { - color = BarColor.valueOf(this.getPlugin().getConfigYml().getString("bossbar.color")); - style = BarStyle.valueOf(this.getPlugin().getConfigYml().getString("bossbar.style")); - name = this.getPlugin().getConfigYml().getString("name"); - xpBounds = new Pair<>(this.getPlugin().getConfigYml().getInt("xp.minimum"), this.getPlugin().getConfigYml().getInt("xp.maximum")); - maxHealth = this.getPlugin().getConfigYml().getDouble("max-health"); - attackDamage = this.getPlugin().getConfigYml().getDouble("attack-damage"); - override = this.getPlugin().getConfigYml().getBool("override"); - - spawnSounds = new HashSet<>(); - EcoBossesConfigs.SOUNDS.getConfig().getConfigurationSection("spawn").getKeys(false).forEach(key -> { - Sound sound = Sound.valueOf(EcoBossesConfigs.SOUNDS.getString("spawn." + key + ".sound")); - boolean broadcast = EcoBossesConfigs.SOUNDS.getBool("spawn." + key + ".broadcast"); - float volume = (float) EcoBossesConfigs.SOUNDS.getDouble("spawn." + key + ".volume"); - float pitch = (float) EcoBossesConfigs.SOUNDS.getDouble("spawn." + key + ".pitch"); - spawnSounds.add(new OptionedSound(sound, volume, pitch, broadcast)); - }); - - deathSounds = new HashSet<>(); - EcoBossesConfigs.SOUNDS.getConfig().getConfigurationSection("death").getKeys(false).forEach(key -> { - Sound sound = Sound.valueOf(EcoBossesConfigs.SOUNDS.getString("death." + key + ".sound")); - boolean broadcast = EcoBossesConfigs.SOUNDS.getBool("death." + key + ".broadcast"); - float volume = (float) EcoBossesConfigs.SOUNDS.getDouble("death." + key + ".volume"); - float pitch = (float) EcoBossesConfigs.SOUNDS.getDouble("death." + key + ".pitch"); - deathSounds.add(new OptionedSound(sound, volume, pitch, broadcast)); - }); - - spawnStructure = new SpawnTotem( - Material.valueOf(this.getPlugin().getConfigYml().getString("spawn.bottom-block")), - Material.valueOf(this.getPlugin().getConfigYml().getString("spawn.middle-block")), - Material.valueOf(this.getPlugin().getConfigYml().getString("spawn.top-block")) - ); - - gameplayOptions.reload(); - - drops = new ArrayList<>(); - for (String key : EcoBossesConfigs.DROPS.getConfig().getKeys(false)) { - ItemStack itemStack = EcoBossesConfigs.DROPS.getConfig().getItemStack(key); - if (itemStack == null || itemStack.getType() == Material.AIR) { - continue; - } - drops.add(itemStack); - } - } - - /** - * Generate xp to drop. - * - * @return The amount of xp to drop. - */ - public int generateXp() { - return NumberUtils.randInt(xpBounds.getFirst(), xpBounds.getSecond()); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossUtils.java new file mode 100644 index 0000000..92e45d7 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossUtils.java @@ -0,0 +1,39 @@ +package com.willfp.ecobosses.bosses.util; + +import com.willfp.ecobosses.EcoBossesPlugin; +import com.willfp.ecobosses.bosses.EcoBoss; +import com.willfp.ecobosses.bosses.EcoBosses; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.LivingEntity; +import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@UtilityClass +public class BossUtils { + /** + * Instance of EcoBosses. + */ + private static final EcoBossesPlugin PLUGIN = EcoBossesPlugin.getInstance(); + + /** + * Get {@link EcoBoss} from an entity. + * + * @param entity The entity. + * @return The boss, or null if not a boss. + */ + @Nullable + public EcoBoss getBoss(@NotNull final LivingEntity entity) { + if (!entity.getPersistentDataContainer().has(PLUGIN.getNamespacedKeyFactory().create("boss"), PersistentDataType.STRING)) { + return null; + } + + String bossName = entity.getPersistentDataContainer().get(PLUGIN.getNamespacedKeyFactory().create("boss"), PersistentDataType.STRING); + + if (bossName == null) { + return null; + } + + return EcoBosses.getByName(bossName); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossbarUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossbarUtils.java deleted file mode 100644 index 4b45605..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/BossbarUtils.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.willfp.ecobosses.bosses.util; - -import lombok.experimental.UtilityClass; -import org.bukkit.Bukkit; -import org.bukkit.attribute.Attribute; -import org.bukkit.boss.BarFlag; -import org.bukkit.boss.BossBar; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -@UtilityClass -public class BossbarUtils { - public BossBar createBossBar(@NotNull final LivingEntity entity) { - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/obj/TeleportOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/obj/TeleportOptions.java new file mode 100644 index 0000000..f4ff280 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/util/obj/TeleportOptions.java @@ -0,0 +1,16 @@ +package com.willfp.ecobosses.bosses.util.obj; + +import lombok.Data; + +@Data +public class TeleportOptions { + /** + * The teleportation range. + */ + private final int range; + + /** + * The chance to teleport. + */ + private final double chance; +}