9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 16:09:24 +00:00

Implemented the actual functionality

This commit is contained in:
Auxilor
2021-03-12 20:20:26 +00:00
parent 9329e6def8
commit 39aa202955
9 changed files with 240 additions and 520 deletions

View File

@@ -1,6 +1,7 @@
package com.willfp.ecobosses.bosses; package com.willfp.ecobosses.bosses;
import com.willfp.eco.internal.config.AbstractUndefinedConfig; import com.willfp.eco.internal.config.AbstractUndefinedConfig;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; 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.ImmunityOptions;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound; import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
import com.willfp.ecobosses.bosses.util.obj.SpawnTotem; 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.EffectOption;
import com.willfp.ecobosses.bosses.util.obj.attacks.SummonsOption; import com.willfp.ecobosses.bosses.util.obj.attacks.SummonsOption;
import lombok.AccessLevel; import lombok.AccessLevel;
@@ -31,10 +33,12 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SpawnEggMeta; import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -172,6 +176,18 @@ public class EcoBoss extends PluginDependent {
@Getter @Getter
private final List<OptionedSound> summonSounds; private final List<OptionedSound> summonSounds;
/**
* If the boss can teleport.
*/
@Getter
private final boolean teleportationEnabled;
/**
* Teleport options.
*/
@Getter
private final TeleportOptions teleportOptions;
/** /**
* Create a new Boss. * 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()); meta.getPersistentDataContainer().set(this.getPlugin().getNamespacedKeyFactory().create("spawn_egg"), PersistentDataType.STRING, this.getName());
this.spawnEgg.setItemMeta(meta); 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")) { if (this.getConfig().getBool("enabled")) {
EcoBosses.addBoss(this); EcoBosses.addBoss(this);
} }
@@ -338,6 +361,10 @@ public class EcoBoss extends PluginDependent {
assert attackDamage != null; assert attackDamage != null;
attackDamage.setBaseValue(this.getAttackDamage()); attackDamage.setBaseValue(this.getAttackDamage());
for (OptionedSound sound : this.getSpawnSounds()) {
location.getWorld().playSound(location, sound.getSound(), sound.getVolume(), sound.getPitch());
}
if (this.isBossbarEnabled()) { if (this.isBossbarEnabled()) {
createBossBar(entity); createBossBar(entity);
} }
@@ -377,6 +404,57 @@ public class EcoBoss extends PluginDependent {
}).runTaskTimer(0, 1); }).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<ItemStack> 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 @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {

View File

@@ -1,22 +1,19 @@
package com.willfp.ecobosses.bosses.listeners; package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.util.NumberUtils; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@@ -25,138 +22,109 @@ import java.util.List;
public class AttackListeners implements Listener { 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. * @param event The event to listen for.
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onIllusionerAttack(@NotNull final EntityDamageByEntityEvent event) { public void onAttackBoss(@NotNull final EntityDamageByEntityEvent event) {
if (!event.getDamager().getType().equals(EntityType.ILLUSIONER)) { if (!(event.getDamager() instanceof Player)) {
return; 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)) { if (!(event.getEntity() instanceof Player)) {
return; 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. * @param event The event to listen for.
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onAttackIllusioner(@NotNull final EntityDamageByEntityEvent event) { public void defenceListener(@NotNull final EntityDamageEvent event) {
if (!event.getEntity().getType().equals(EntityType.ILLUSIONER)) { if (!(event.getEntity() instanceof LivingEntity)) {
return; return;
} }
Player temp = null; LivingEntity entity = (LivingEntity) event.getEntity();
if (event.getDamager() instanceof Player) { EcoBoss boss = BossUtils.getBoss(entity);
temp = (Player) event.getDamager();
} else if (event.getDamager() instanceof Projectile) {
if (((Projectile) event.getDamager()).getShooter() instanceof Player) {
temp = (Player) ((Projectile) event.getDamager()).getShooter();
}
}
if (temp == null) { if (boss == null) {
return; return;
} }
Player player = temp; ImmunityOptions immunities = boss.getImmunityOptions();
handleAttack((LivingEntity) event.getEntity(), player); if (immunities.isImmuneToFire() && (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) {
} event.setCancelled(true);
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());
} }
IllusionerManager.OPTIONS.getGameplayOptions().getEffectOptions().forEach(effectOption -> { if (immunities.isImmuneToSuffocation() && event.getCause() == EntityDamageEvent.DamageCause.SUFFOCATION) {
if (NumberUtils.randFloat(0, 100) > effectOption.getChance()) { event.setCancelled(true);
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<ItemStack> 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);
}
} }
IllusionerManager.OPTIONS.getGameplayOptions().getSummonerOptions().forEach(summonerOption -> { if (immunities.isImmuneToDrowning() && event.getCause() == EntityDamageEvent.DamageCause.DROWNING) {
if (NumberUtils.randFloat(0, 100) > summonerOption.getChance()) { event.setCancelled(true);
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 (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreExplosionDamage()) { if (immunities.isImmuneToExplosions() && (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION || event.getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION) || event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) { event.setCancelled(true);
event.setCancelled(true);
}
} }
if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreFire()) { if (immunities.isImmuneToProjectiles() && (event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE)) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.FIRE) || event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK)) { event.setCancelled(true);
event.setCancelled(true);
}
} }
if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreSuffocation()) { if (boss.isTeleportationEnabled()) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION)) { if (NumberUtils.randFloat(0, 100) < boss.getTeleportOptions().getChance()) {
event.setCancelled(true); int range = boss.getTeleportOptions().getRange();
}
}
if (IllusionerManager.OPTIONS.getGameplayOptions().isTeleport()) {
if (NumberUtils.randFloat(0, 100) < IllusionerManager.OPTIONS.getGameplayOptions().getTeleportChance()) {
int range = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportRange();
List<Location> valid = new ArrayList<>(); List<Location> valid = new ArrayList<>();
for (int x = -range; x <= range; x++) { for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) { for (int y = -range; y <= range; y++) {
@@ -185,8 +153,6 @@ public class AttackListeners implements Listener {
Location location = valid.get(0); Location location = valid.get(0);
event.getEntity().teleport(location); event.getEntity().teleport(location);
OptionedSound optionedSound = IllusionerManager.OPTIONS.getGameplayOptions().getTeleportSound();
location.getWorld().playSound(location, optionedSound.getSound(), optionedSound.getVolume(), optionedSound.getPitch());
} }
} }
} }

View File

@@ -2,10 +2,10 @@ package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent; 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 com.willfp.ecobosses.bosses.util.obj.OptionedSound;
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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -19,39 +19,36 @@ public class DeathListeners implements Listener {
* @param event The event to listen for. * @param event The event to listen for.
*/ */
@EventHandler @EventHandler
public void onIllusionerDeath(@NotNull final EntityDeathByEntityEvent event) { public void onBossDeath(@NotNull final EntityDeathByEntityEvent event) {
if (!event.getDeathEvent().getEntityType().equals(EntityType.ILLUSIONER)) { LivingEntity entity = event.getVictim();
EcoBoss boss = BossUtils.getBoss(entity);
if (boss == null) {
return; return;
} }
Player player = null; for (OptionedSound sound : boss.getDeathSounds()) {
entity.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch());
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());
}
}
} }
} }
/**
* Handle drops and experience.
*
* @param event The event.
*/
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onOtherDeath(@NotNull final EntityDeathEvent event) { 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; return;
} }
event.getDrops().addAll(IllusionerManager.OPTIONS.getDrops()); event.getDrops().addAll(boss.getDrops());
event.setDroppedExp(IllusionerManager.OPTIONS.generateXp()); event.setDroppedExp(boss.getExperienceOptions().generateXp());
} }
} }

View File

@@ -1,21 +1,16 @@
package com.willfp.ecobosses.bosses.listeners; package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; 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.bosses.util.obj.SpawnTotem;
import com.willfp.ecobosses.proxy.proxies.CustomIllusionerProxy;
import com.willfp.ecobosses.util.ProxyUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Illusioner;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
public class SpawnListeners extends PluginDependent implements Listener { public class SpawnListeners extends PluginDependent implements Listener {
/** /**
* Create new spawn listeners and link them to a plugin. * 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. * @param event The event to listen for.
*/ */
@EventHandler @EventHandler
public void onSpawn(@NotNull final BlockPlaceEvent event) { public void spawnTotem(@NotNull final BlockPlaceEvent event) {
boolean matches = false;
Set<Block> match = new HashSet<>();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Block block1; Block block1;
Block block2; Block block2;
@@ -54,54 +47,19 @@ public class SpawnListeners extends PluginDependent implements Listener {
block3 = event.getBlock().getRelative(0, 1, 0); block3 = event.getBlock().getRelative(0, 1, 0);
} }
matches = SpawnTotem.matches(new SpawnTotem(block1.getType(), block2.getType(), block3.getType())); SpawnTotem placedTotem = new SpawnTotem(block1.getType(), block2.getType(), block3.getType());
if (matches) {
match.add(block1); for (EcoBoss boss : EcoBosses.values()) {
match.add(block2); if (boss.isSpawnTotemEnabled()) {
match.add(block3); if (boss.getSpawnTotem().equals(placedTotem)) {
break; 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());
} }
} }

View File

@@ -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<EffectOption> effectOptions = new HashSet<>();
/**
* The mob summon options.
*/
@Getter
private final Set<SummonerOption> 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));
});
}
}

View File

@@ -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<OptionedSound> spawnSounds;
/**
* The death sounds.
*/
@Getter
private Set<OptionedSound> deathSounds;
/**
* The xp bounds.
*/
private Pair<Integer, Integer> 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<ItemStack> 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());
}
}

View File

@@ -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);
}
}

View File

@@ -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) {
}
}

View File

@@ -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;
}