Skip to content

Commit

Permalink
Added support for bosses and trial spawners (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fly1337 authored Aug 12, 2024
1 parent 5adf884 commit df98c5f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/main/java/dev/aurelium/auramobs/AuraMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ public boolean isAuraMob(LivingEntity m) {
}

public boolean isInvalidEntity(Entity entity) {
if (entity instanceof Boss || !(entity instanceof LivingEntity)) return true; // Types to exclude
if (entity instanceof Hoglin || entity instanceof Slime) return false; // Types to include
return !(entity instanceof Monster);
if (!(entity instanceof LivingEntity mob)) return true;
if (entity instanceof Hoglin || entity instanceof Slime) return false; // Mobs that don't inherit from LivingEntity
return !(entity instanceof Monster) && !isBossMob(mob);
}

public boolean isBossMob(LivingEntity entity) {
return entity instanceof Boss || entity instanceof ElderGuardian;
}

public Formatter getFormatter() {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Zombie;
import org.bukkit.persistence.PersistentDataType;
Expand All @@ -33,14 +34,15 @@ public AureliumMob(LivingEntity mob, int level, AuraMobs plugin) {
Location mobloc = mob.getLocation();
Location spawnpoint = mob.getWorld().getSpawnLocation();
double distance = mobloc.distance(spawnpoint);
double startDamage = BigDecimal.valueOf(mob.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getBaseValue()).setScale(2, RoundingMode.CEILING).doubleValue();
double startDamage = mob instanceof EnderDragon ? 0 : BigDecimal.valueOf(mob.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getBaseValue()).setScale(2, RoundingMode.CEILING).doubleValue();
double startHealth = BigDecimal.valueOf(mob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()).setScale(2, RoundingMode.CEILING).doubleValue();
String damageFormula = MessageUtils.setPlaceholders(null, plugin.optionString("mob_defaults.damage.formula")
String prefix = plugin.isBossMob(mob) ? "bosses." : "mob_defaults.";
String damageFormula = MessageUtils.setPlaceholders(null, plugin.optionString(prefix + "damage.formula")
.replace("{mob_damage}", String.valueOf(startDamage))
.replace("{level}", String.valueOf(level1))
.replace("{distance}", Double.toString(distance))
);
String healthFormula = MessageUtils.setPlaceholders(null, plugin.optionString("mob_defaults.health.formula")
String healthFormula = MessageUtils.setPlaceholders(null, plugin.optionString(prefix + "health.formula")
.replace("{mob_health}", String.valueOf(startHealth))
.replace("{level}", Integer.toString(level1))
.replace("{distance}", Double.toString(distance))
Expand All @@ -56,7 +58,8 @@ public AureliumMob(LivingEntity mob, int level, AuraMobs plugin) {
if (damage > plugin.getMaxDamage()) {
damage = plugin.getMaxDamage();
}
mob.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(damage);

if (!(mob instanceof EnderDragon)) mob.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(damage);

AttributeInstance healthAttr = mob.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (healthAttr == null) return;
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/dev/aurelium/auramobs/listeners/MobSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public void onSpawn(CreatureSpawnEvent e) {
if (plugin.isInvalidEntity(e.getEntity())) {
return;
}

LivingEntity entity = e.getEntity();

if (!plugin.optionBoolean("bosses.enabled") && plugin.isBossMob(entity)) {
return;
}

if (!passWorld(e.getEntity().getWorld())) return;

if (plugin.getWorldGuard() != null) {
Expand Down Expand Up @@ -130,12 +135,13 @@ public void run() {
};
}

private int getCalculatedLevel(Entity entity, List<Entity> players, double distance, int maxlevel, int minlevel, int sumlevel) {
private int getCalculatedLevel(LivingEntity entity, List<Entity> players, double distance, int maxlevel, int minlevel, int sumlevel) {
int level;
String lformula;
String prefix = plugin.isBossMob(entity) ? "bosses.level." : "mob_level.";
int globalOnline = plugin.getServer().getOnlinePlayers().size();
if (players.isEmpty()) {
lformula = MessageUtils.setPlaceholders(null, plugin.optionString("mob_level.backup_formula")
lformula = MessageUtils.setPlaceholders(null, plugin.optionString(prefix + "backup_formula")
.replace("{distance}", Double.toString(distance))
.replace("{sumlevel_global}", Integer.toString(plugin.getGlobalLevel()))
.replace("{playercount}", globalOnline > 0 ? String.valueOf(globalOnline) : "1")
Expand All @@ -146,7 +152,7 @@ private int getCalculatedLevel(Entity entity, List<Entity> players, double dista
.replace("{random_double}", String.valueOf(random.nextDouble()))
);
} else {
lformula = MessageUtils.setPlaceholders(null, plugin.optionString("mob_level.formula")
lformula = MessageUtils.setPlaceholders(null, plugin.optionString(prefix + "formula")
.replace("{highestlvl}", Integer.toString(maxlevel))
.replace("{lowestlvl}", Integer.toString(minlevel))
.replace("{sumlevel}", Integer.toString(sumlevel))
Expand All @@ -161,7 +167,7 @@ private int getCalculatedLevel(Entity entity, List<Entity> players, double dista
);
}
level = (int) new ExpressionBuilder(lformula).build().evaluate();
level = Math.min(level, plugin.optionInt("mob_level.max_level"));
level = Math.min(level, plugin.optionInt(prefix + "max_level"));
return level;
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ mob_level:
formula: '{sumlevel}/{playercount}'
backup_formula: '{distance}*0.01'
max_level: 100
bosses:
enabled: false
health:
formula: '{mob_health} * (1 + ({level} - 1) / 25)'
damage:
formula: '{mob_damage} + ({mob_damage} * ({level} - 1) / 25)'
level:
formula: '{sumlevel}/{playercount}'
backup_formula: '{distance}*0.01'
max_level: 50
player_level:
check_radius: 128
formula: '{average}'
Expand Down Expand Up @@ -43,6 +53,7 @@ spawn_reasons:
- 'NATURAL'
- 'JOCKEY'
- 'SPAWNER'
- 'TRIAL_SPAWNER'
- 'EGG'
- 'SPAWNER_EGG'
- 'LIGHTNING'
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/messages_de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ mobs:
warden: Wärter
breeze: Böe
bogged: Sumpfskelett
ender_dragon: Enderdrache
wither: Wither
elder_guardian: Großwächter
file_version: 1
3 changes: 3 additions & 0 deletions src/main/resources/messages/messages_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ mobs:
warden: Warden
breeze: Breeze
bogged: Bogged
ender_dragon: Ender Dragon
wither: Wither
elder_guardian: Elder Guardian
file_version: 1
3 changes: 3 additions & 0 deletions src/main/resources/messages/messages_es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ mobs:
warden: Warden
breeze: Breeze
bogged: Bogged
ender_dragon: Enderdragón
wither: Wither
elder_guardian: Guardián anciano
file_version: 1
3 changes: 3 additions & 0 deletions src/main/resources/messages/messages_nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ mobs:
warden: Hoeder
breeze: Vlaag
bogged: Zomper
ender_dragon: Enderdraak
wither: Wither
elder_guardian: Oude bewaker
file_version: 1

0 comments on commit df98c5f

Please sign in to comment.