mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-06 23:37:33 +01:00
Fix bug where boss/minions would attack each other
This commit is contained in:
parent
23eec833c0
commit
6c276e3b26
@ -0,0 +1,59 @@
|
||||
package com.songoda.epicbosses.listeners.during;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.events.BossDamageEvent;
|
||||
import com.songoda.epicbosses.holder.ActiveBossHolder;
|
||||
import com.songoda.epicbosses.holder.ActiveMinionHolder;
|
||||
import com.songoda.epicbosses.managers.BossEntityManager;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
|
||||
/**
|
||||
* @author Esophose
|
||||
* @version 1.0.0
|
||||
* @since 05-Apr-19
|
||||
*/
|
||||
public class BossMinionTargetListener implements Listener {
|
||||
|
||||
private BossEntityManager bossEntityManager;
|
||||
|
||||
public BossMinionTargetListener(CustomBosses plugin) {
|
||||
this.bossEntityManager = plugin.getBossEntityManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBossMinionTarget(EntityTargetLivingEntityEvent event) {
|
||||
Entity entityTargeting = event.getEntity();
|
||||
LivingEntity entityTargeted = event.getTarget();
|
||||
|
||||
if (entityTargeting == null || entityTargeted == null) return;
|
||||
if (!(entityTargeting instanceof LivingEntity)) return;
|
||||
|
||||
LivingEntity livingEntity = (LivingEntity) entityTargeting;
|
||||
|
||||
ActiveBossHolder targetingBossHolder = this.bossEntityManager.getActiveBossHolder(livingEntity);
|
||||
ActiveBossHolder targetedBossHolder = this.bossEntityManager.getActiveBossHolder(entityTargeted);
|
||||
|
||||
if (targetingBossHolder != null) {
|
||||
for (ActiveMinionHolder minionHolder : targetingBossHolder.getActiveMinionHolderMap().values()) {
|
||||
if (minionHolder.getLivingEntityMap().containsValue(entityTargeted)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (targetedBossHolder != null) {
|
||||
for (ActiveMinionHolder minionHolder : targetedBossHolder.getActiveMinionHolderMap().values()) {
|
||||
if (minionHolder.getLivingEntityMap().containsValue(entityTargeting)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package com.songoda.epicbosses.managers;
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.listeners.after.BossDeathListener;
|
||||
import com.songoda.epicbosses.listeners.during.BossDamageListener;
|
||||
import com.songoda.epicbosses.listeners.during.BossMinionTargetListener;
|
||||
import com.songoda.epicbosses.listeners.during.BossSkillListener;
|
||||
import com.songoda.epicbosses.listeners.pre.BossSpawnListener;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
@ -34,6 +35,7 @@ public class BossListenerManager implements ILoadable {
|
||||
|
||||
serverUtils.registerListener(new BossSpawnListener(this.plugin));
|
||||
serverUtils.registerListener(new BossDamageListener(this.plugin));
|
||||
serverUtils.registerListener(new BossMinionTargetListener(this.plugin));
|
||||
serverUtils.registerListener(new BossSkillListener(this.plugin));
|
||||
serverUtils.registerListener(new BossDeathListener(this.plugin));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user