Skip to content

Commit

Permalink
Readded Damaged Trigger.
Browse files Browse the repository at this point in the history
Made some fixes to WrapperEffect classes.
  • Loading branch information
Xemorr committed Jul 23, 2021
1 parent 9af26fa commit 6c6f98a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/xemor/skillslibrary/effects/AOE.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public boolean useEffect(LivingEntity skillEntity) {
boolean shouldCancel = false;
List<Entity> entities = skillEntity.getNearbyEntities(radius, radius, radius);
for (Entity entity : entities) {
shouldCancel |= handleEffects(skillEntity, entity);
shouldCancel |= handleEffects(skillEntity);
shouldCancel |= handleEffects(skillEntity, entity);
}
return shouldCancel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public boolean useEffect(LivingEntity livingEntity, Entity entity) {
if (entity instanceof Projectile) {
Projectile projectile = (Projectile) entity;
ProjectileSource shooter = projectile.getShooter();
handleEffects(livingEntity);
handleEffects(livingEntity, shooter);
}
else if (!onlyProjectiles) {
handleEffects(livingEntity);
handleEffects(livingEntity, entity);
}
return false;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/me/xemor/skillslibrary/triggers/DamageData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.xemor.skillslibrary.triggers;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.entity.EntityDamageEvent;

import java.util.Set;
import java.util.stream.Collectors;

public class DamageData extends TriggerData {

private Set<EntityDamageEvent.DamageCause> damageCauses;

public DamageData(int trigger, ConfigurationSection configurationSection) {
super(trigger, configurationSection);
damageCauses = configurationSection.getStringList("causes").stream().map(String::toUpperCase).map(EntityDamageEvent.DamageCause::valueOf).collect(Collectors.toSet());
}

public Set<EntityDamageEvent.DamageCause> getDamageCauses() {
return damageCauses;
}


}
1 change: 1 addition & 0 deletions src/main/java/me/xemor/skillslibrary/triggers/Trigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Trigger {
static {
registerTrigger("DAMAGEDENTITY", TriggerData.class);
registerTrigger("DAMAGEDBYENTITY", TriggerData.class);
registerTrigger("DAMAGED", DamageData.class);
registerTrigger("SNEAK", TriggerData.class);
registerTrigger("TOGGLEGLIDE", TriggerData.class);
registerTrigger("PLAYERJUMP", TriggerData.class);
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/me/xemor/skillslibrary/triggers/Triggers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.entity.*;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -104,6 +105,22 @@ public void onEntityDamage(EntityDamageByEntityEvent e) {
}
}

@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
boolean cancel = false;
if (e.getEntity() instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) e.getEntity();
Collection<Skill> skills = SkillsLibrary.getSkillsManager().getSkills(Trigger.getTrigger("DAMAGED"));
for (Skill skill : skills) {
DamageData damageData = (DamageData) skill.getTriggerData();
if (damageData.getDamageCauses().size() == 0 || damageData.getDamageCauses().contains(e.getCause())) {
if (skill.handleEffects(livingEntity)) cancel = true;
}
}
}
e.setCancelled(cancel);
}

@EventHandler
public void onSneak(PlayerToggleSneakEvent e) {
if (e.isSneaking()) {
Expand All @@ -122,10 +139,17 @@ public void onTarget(EntityTargetLivingEntityEvent e) {
@EventHandler
public void onVehicleEnter(VehicleEnterEvent e) {
if (e.getEntered() instanceof LivingEntity) {
e.setCancelled(handleSkills(Trigger.getTrigger("VEHICLE"), (LivingEntity) e.getEntered(), e.getVehicle()));
boolean cancel = handleSkills(Trigger.getTrigger("ENTERVEHICLE"), (LivingEntity) e.getEntered(), e.getVehicle());
cancel |= handleSkills(Trigger.getTrigger("VEHICLE"), (LivingEntity) e.getEntered(), e.getVehicle());
e.setCancelled(cancel);
}
}

@EventHandler(ignoreCancelled = true)
public void onVehicleExit(VehicleExitEvent e) {
e.setCancelled(handleSkills(Trigger.getTrigger("EXITVEHICLE"), e.getExited(), e.getVehicle()));
}

@EventHandler
public void onEntityDeath(EntityDeathEvent e) {
handleSkills(Trigger.getTrigger("DEATH"), e.getEntity(), e.getEntity().getKiller());
Expand Down

0 comments on commit 6c6f98a

Please sign in to comment.