mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 07:59:28 +00:00
Moved more entity-specific code into LivingEcoBoss
This commit is contained in:
@@ -375,24 +375,6 @@ public class EcoBoss extends PluginDependent {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn egg
|
|
||||||
/*
|
|
||||||
Material eggMaterial = Material.matchMaterial(this.getConfig().getString("spawn-egg.egg-material").toUpperCase());
|
|
||||||
assert eggMaterial != null;
|
|
||||||
this.spawnEgg = new ItemStack(eggMaterial);
|
|
||||||
SpawnEggMeta meta = (SpawnEggMeta) this.spawnEgg.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (String string : this.getConfig().getStrings("spawn-egg.lore")) {
|
|
||||||
lore.add(StringUtils.translate(string));
|
|
||||||
}
|
|
||||||
meta.setLore(lore);
|
|
||||||
meta.setDisplayName(this.getConfig().getString("spawn-egg.display-name"));
|
|
||||||
meta.getPersistentDataContainer().set(this.getPlugin().getNamespacedKeyFactory().create("spawn_egg"), PersistentDataType.STRING, this.getName());
|
|
||||||
this.spawnEgg.setItemMeta(meta);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Messages
|
// Messages
|
||||||
this.spawnMessages = new ArrayList<>();
|
this.spawnMessages = new ArrayList<>();
|
||||||
for (String string : this.getConfig().getStrings("broadcast.spawn")) {
|
for (String string : this.getConfig().getStrings("broadcast.spawn")) {
|
||||||
@@ -453,13 +435,23 @@ public class EcoBoss extends PluginDependent {
|
|||||||
public void spawn(@NotNull final Location location) {
|
public void spawn(@NotNull final Location location) {
|
||||||
LivingEntity entity = bossType.spawnBossEntity(location);
|
LivingEntity entity = bossType.spawnBossEntity(location);
|
||||||
this.livingBosses.put(entity.getUniqueId(), new LivingEcoBoss(
|
this.livingBosses.put(entity.getUniqueId(), new LivingEcoBoss(
|
||||||
this.getPlugin(),
|
this.getPlugin(),
|
||||||
entity,
|
entity,
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get {@link LivingEcoBoss} from an entity.
|
||||||
|
*
|
||||||
|
* @param entity The entity.
|
||||||
|
* @return The living boss, or null if not a boss.
|
||||||
|
*/
|
||||||
|
public LivingEcoBoss getLivingBoss(@NotNull final LivingEntity entity) {
|
||||||
|
return this.livingBosses.get(entity.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove living boss.
|
* Remove living boss.
|
||||||
*
|
*
|
||||||
@@ -469,60 +461,6 @@ public class EcoBoss extends PluginDependent {
|
|||||||
this.livingBosses.remove(uuid);
|
this.livingBosses.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
Entity summonedEntity = player.getWorld().spawnEntity(loc, summon.getType());
|
|
||||||
if (summonedEntity instanceof Mob) {
|
|
||||||
((Mob) summonedEntity).setTarget(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.willfp.ecobosses.bosses;
|
package com.willfp.ecobosses.bosses;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.NumberUtils;
|
||||||
import com.willfp.eco.util.StringUtils;
|
import com.willfp.eco.util.StringUtils;
|
||||||
import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable;
|
import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable;
|
||||||
import com.willfp.eco.util.internal.PluginDependent;
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
@@ -8,7 +9,12 @@ import com.willfp.ecobosses.bosses.tick.BossTicker;
|
|||||||
import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
|
import com.willfp.ecobosses.bosses.tick.tickers.BossBarTicker;
|
||||||
import com.willfp.ecobosses.bosses.tick.tickers.HealthPlaceholderTicker;
|
import com.willfp.ecobosses.bosses.tick.tickers.HealthPlaceholderTicker;
|
||||||
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
|
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
|
||||||
|
import com.willfp.ecobosses.bosses.util.obj.attacks.EffectOption;
|
||||||
|
import com.willfp.ecobosses.bosses.util.obj.attacks.SummonsOption;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.boss.BarFlag;
|
import org.bukkit.boss.BarFlag;
|
||||||
@@ -16,10 +22,15 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Mob;
|
import org.bukkit.entity.Mob;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@@ -80,6 +91,58 @@ public class LivingEcoBoss extends PluginDependent {
|
|||||||
}).runTaskTimer(0, 1);
|
}).runTaskTimer(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an attack to the player.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
*/
|
||||||
|
public void handleAttack(@NotNull final Player player) {
|
||||||
|
for (OptionedSound sound : boss.getInjureSounds()) {
|
||||||
|
player.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EffectOption effect : boss.getEffects()) {
|
||||||
|
if (NumberUtils.randFloat(0, 100) > effect.getChance()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.addPotionEffect(new PotionEffect(effect.getEffectType(), effect.getDuration(), effect.getLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NumberUtils.randFloat(0, 100) < boss.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 : boss.getSummons()) {
|
||||||
|
if (NumberUtils.randFloat(0, 100) > summon.getChance()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
Entity summonedEntity = player.getWorld().spawnEntity(loc, summon.getType());
|
||||||
|
if (summonedEntity instanceof Mob) {
|
||||||
|
((Mob) summonedEntity).setTarget(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (OptionedSound sound : boss.getSummonSounds()) {
|
||||||
|
player.getWorld().playSound(entity.getLocation(), sound.getSound(), sound.getVolume(), sound.getPitch());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onSpawn() {
|
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.getName());
|
||||||
entity.setPersistent(true);
|
entity.setPersistent(true);
|
||||||
@@ -130,6 +193,7 @@ public class LivingEcoBoss extends PluginDependent {
|
|||||||
ticker.onDeath(boss, entity, tick);
|
ticker.onDeath(boss, entity, tick);
|
||||||
}
|
}
|
||||||
runnable.cancel();
|
runnable.cancel();
|
||||||
|
boss.removeLivingBoss(entity.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.willfp.eco.util.NumberUtils;
|
|||||||
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.EcoBoss;
|
||||||
|
import com.willfp.ecobosses.bosses.LivingEcoBoss;
|
||||||
import com.willfp.ecobosses.bosses.util.BossUtils;
|
import com.willfp.ecobosses.bosses.util.BossUtils;
|
||||||
import com.willfp.ecobosses.bosses.util.obj.DamagerProperty;
|
import com.willfp.ecobosses.bosses.util.obj.DamagerProperty;
|
||||||
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
|
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
|
||||||
@@ -70,8 +71,10 @@ public class AttackListeners extends PluginDependent implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LivingEcoBoss livingEcoBoss = boss.getLivingBoss(entity);
|
||||||
|
|
||||||
if (boss.isAttackOnInjure()) {
|
if (boss.isAttackOnInjure()) {
|
||||||
boss.handleAttack(entity, player);
|
livingEcoBoss.handleAttack(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +153,9 @@ public class AttackListeners extends PluginDependent implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boss.handleAttack(entity, player);
|
LivingEcoBoss livingEcoBoss = boss.getLivingBoss(entity);
|
||||||
|
|
||||||
|
livingEcoBoss.handleAttack(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user