Skip to content

Commit

Permalink
EliteMobs 9.1.8:
Browse files Browse the repository at this point in the history
- [New] Weaving potions are now blocked in EliteMobs worlds to prevent creating permanent cobwebs where they shouldn't be
- [New] Seriously optimized bosses with dynamic levels, which should result in big performance boosts for all servers running EliteMobs shrines, especially those who pregenerated their worlds
- [Fix] Now handling null quest objectives better
- [Fix] Fixed issues that were preventing people from compiling EliteMobs locally or depending on EliteMobs

Signed-off-by: MagmaGuy <tiagoarnaut@gmail.com>
  • Loading branch information
MagmaGuy committed Aug 27, 2024
1 parent ae0cb9d commit f1f0e0d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ processResources {
}

group 'com.magmaguy'
version '9.1.7'
version '9.1.8'

repositories {
maven {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/magmaguy/elitemobs/EliteMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.magmaguy.elitemobs.items.customitems.CustomItem;
import com.magmaguy.elitemobs.menus.ProceduralShopMenu;
import com.magmaguy.elitemobs.mobconstructor.PersistentObjectHandler;
import com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity;
import com.magmaguy.elitemobs.mobconstructor.custombosses.CustomMusic;
import com.magmaguy.elitemobs.mobconstructor.custombosses.InstancedBossEntity;
import com.magmaguy.elitemobs.mobconstructor.custombosses.RegionalBossEntity;
Expand Down Expand Up @@ -278,6 +279,7 @@ public void onEnable() {
VersionChecker.check();

DynamicQuest.startRandomizingQuests();
CustomBossEntity.startUpdatingDynamicLevels();
}

@Override
Expand Down Expand Up @@ -339,6 +341,7 @@ public void onDisable() {
BossBarUtil.shutdown();
ScriptAction.shutdown();
CustomMusic.shutdown();
CustomBossEntity.shutdown();
Logger.info("Saving EliteMobs databases...");
PlayerData.closeConnection();
MagmaCore.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffectType;

import java.util.HashSet;
import java.util.Locale;
Expand All @@ -22,8 +20,8 @@
public class DungeonProtector implements Listener {
private static final HashSet<UUID> bypassingPlayers = new HashSet<>();

public static boolean toggleBypass (UUID playerUUID){
if (bypassingPlayers.contains(playerUUID)){
public static boolean toggleBypass(UUID playerUUID) {
if (bypassingPlayers.contains(playerUUID)) {
bypassingPlayers.remove(playerUUID);
return false;
}
Expand Down Expand Up @@ -168,4 +166,24 @@ public void preventDoorOpeningSpawning(EntityChangeBlockEvent event) {
event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void preventCobwebPotions(LingeringPotionSplashEvent event) {
if (!EliteMobsWorld.isEliteMobsWorld(event.getEntity().getWorld().getUID())) return;
if (event.getEntity().getShooter() == null) return;
if (!(event.getEntity().getShooter() instanceof Player)) return;
event.getEntity().getEffects().forEach(potionEffect -> {
if (potionEffect.getType().equals(PotionEffectType.WEAVING)) event.setCancelled(true);
});
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void preventCobwebPotions(PotionSplashEvent event) {
if (!EliteMobsWorld.isEliteMobsWorld(event.getEntity().getWorld().getUID())) return;
if (event.getEntity().getShooter() == null) return;
if (!(event.getEntity().getShooter() instanceof Player)) return;
event.getEntity().getEffects().forEach(potionEffect -> {
if (potionEffect.getType().equals(PotionEffectType.WEAVING)) event.setCancelled(true);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
import org.bukkit.scheduler.BukkitTask;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.*;

public class CustomBossEntity extends EliteEntity implements Listener, PersistentObject, PersistentMovingEntity {

Expand Down Expand Up @@ -102,7 +100,7 @@ public class CustomBossEntity extends EliteEntity implements Listener, Persisten
@Getter
@Setter
private boolean dynamicLevel = false;
private BukkitTask dynamicLevelUpdater = null;
public static Set<CustomBossEntity> dynamicLevelBossEntities = new HashSet<>();

/**
* Uses a builder pattern in order to construct a CustomBossEntity at an arbitrary point in the future. Does not
Expand Down Expand Up @@ -364,6 +362,45 @@ private void spawnMessage() {
if (customBossesConfigFields.getAnnouncementPriority() < 3) return;
new DiscordSRVAnnouncement(ChatColorConverter.convert(customBossesConfigFields.getSpawnMessage()));
}
private static BukkitTask dynamicLevelUpdater = null;

public static void addToUpdatingDynamicLevels(CustomBossEntity customBossEntity){
if (!customBossEntity.dynamicLevel) return;
dynamicLevelBossEntities.add(customBossEntity);
}

public static void startUpdatingDynamicLevels(){
dynamicLevelUpdater = new BukkitRunnable() {
@Override
public void run() {
Iterator<CustomBossEntity> iterator = dynamicLevelBossEntities.iterator();
while (iterator.hasNext()) {
CustomBossEntity customBossEntity = iterator.next();
if (!customBossEntity.isValid()) {
iterator.remove(); // Remove from the list instead of canceling
continue; // Skip to the next iteration
}
int currentLevel = customBossEntity.getLevel();
customBossEntity.getDynamicLevel(customBossEntity.getLocation());
int newLevel = customBossEntity.getLevel();

if (currentLevel == newLevel) {
continue; // Skip to the next iteration if the level hasn't changed
}

// In theory, the damage should update automatically; the only thing that needs updating should be the health
customBossEntity.setMaxHealth();
customBossEntity.setNormalizedHealth();
CustomBossMegaConsumer.setName(customBossEntity.getLivingEntity(), customBossEntity, customBossEntity.level);
}
}
}.runTaskTimer(MetadataHandler.PLUGIN, 20 * 5L, 20 * 5L);
}

public static void shutdown(){
dynamicLevelUpdater.cancel();
dynamicLevelBossEntities.clear();
}

public void getDynamicLevel(Location bossLocation) {
int bossLevel = 1;
Expand All @@ -378,39 +415,16 @@ public void getDynamicLevel(Location bossLocation) {
bossLevel = level;
}
}
updateDynamicLevel();
startUpdatingDynamicLevel();
super.setLevel(bossLevel);
}

/**
* Upsettingly due to how chunk generation works regional bosses in general don't play along well with dynamic bosses
*/
private void updateDynamicLevel() {
private void startUpdatingDynamicLevel() {
if (dynamicLevelUpdater != null) return;
CustomBossEntity customBossEntity = this;
dynamicLevelUpdater = new BukkitRunnable() {
@Override
public void run() {
if (customBossEntity.isInCombat()) return;
if (!customBossEntity.isValid() && !customBossEntity.isPersistent) {
cancel();
return;
}
//for unloaded but persistent bosses
if (customBossEntity.getLivingEntity() == null || !customBossEntity.isValid()) {
return;
}
int currentLevel = customBossEntity.getLevel();
customBossEntity.getDynamicLevel(customBossEntity.getLocation());
int newLevel = customBossEntity.getLevel();
if (currentLevel == newLevel) return;
//In theory the damage should update automatically, the only thing that needs updating should be the health
customBossEntity.setMaxHealth();
setNormalizedHealth();
CustomBossMegaConsumer.setName(getLivingEntity(), customBossEntity, level);

}
}.runTaskTimer(MetadataHandler.PLUGIN, 20 * 5L, 20 * 5L);
dynamicLevelBossEntities.add(this);
}

private void startBossTrails() {
Expand Down Expand Up @@ -488,7 +502,7 @@ public void fullHeal() {

@Override
public void remove(RemovalReason removalReason) {
if (dynamicLevelUpdater != null) dynamicLevelUpdater.cancel();
dynamicLevelBossEntities.remove(this);
if (livingEntity != null) persistentLocation = livingEntity.getLocation();
//Remove the living entity
super.remove(removalReason);
Expand Down Expand Up @@ -613,6 +627,12 @@ public void onExitCombat(EliteMobExitCombatEvent event) {
return;
((CustomBossEntity) event.getEliteMobEntity()).cullReinforcements(false);
}

@EventHandler
public void onEliteSpawnEvent(EliteMobSpawnEvent event){
if (event.getEliteMobEntity() instanceof CustomBossEntity customBossEntity)
addToUpdatingDynamicLevels(customBossEntity);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.magmaguy.elitemobs.utils.EventCaller;
import com.magmaguy.elitemobs.utils.SimpleScoreboard;
import com.magmaguy.magmacore.util.ChatColorConverter;
import com.magmaguy.magmacore.util.Logger;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -81,11 +82,16 @@ public boolean isOver() {
//used by the force bypass
if (forceOver) return true;
boolean checkOver = true;
for (Objective objective : objectives)
for (Objective objective : objectives) {
if (objective == null) {
Logger.warn("Found a null objective for quest " + quest.getQuestName());
continue;
}
if (!objective.isObjectiveCompleted()) {
checkOver = false;
break;
}
}
return checkOver;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: EliteMobs
version: 9.1.7
version: 9.1.8
author: MagmaGuy
main: com.magmaguy.elitemobs.EliteMobs
api-version: 1.14
Expand Down

0 comments on commit f1f0e0d

Please sign in to comment.