Skip to content

Commit

Permalink
Add Divine Fur ability implementation (6/7)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondDagger590 committed Jun 9, 2020
1 parent 419c550 commit 7d750cb
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package us.eunoians.mcrpg.api.events.mcrpg.taming;

import lombok.Getter;
import lombok.Setter;
import org.bukkit.event.entity.EntityDamageEvent;
import us.eunoians.mcrpg.abilities.taming.DivineFur;
import us.eunoians.mcrpg.api.events.mcrpg.AbilityActivateEvent;
import us.eunoians.mcrpg.players.McRPGPlayer;
import us.eunoians.mcrpg.types.AbilityEventType;

public class DivineFurEvent extends AbilityActivateEvent{

@Getter
private EntityDamageEvent.DamageCause damageCause;

@Getter @Setter
private double percentProtected;

public DivineFurEvent(McRPGPlayer mcRPGPlayer, DivineFur divineFur, EntityDamageEvent.DamageCause damageCause, double percentProtected){
super(divineFur, mcRPGPlayer, AbilityEventType.RECREATIONAL);
this.damageCause = damageCause;
this.percentProtected = percentProtected;
}
}
148 changes: 139 additions & 9 deletions src/main/java/us/eunoians/mcrpg/events/vanilla/VanillaDamageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import us.eunoians.mcrpg.abilities.swords.SerratedStrikes;
import us.eunoians.mcrpg.abilities.swords.TaintedBlade;
import us.eunoians.mcrpg.abilities.taming.Comradery;
import us.eunoians.mcrpg.abilities.taming.DivineFur;
import us.eunoians.mcrpg.abilities.taming.Gore;
import us.eunoians.mcrpg.abilities.taming.LinkedFangs;
import us.eunoians.mcrpg.abilities.taming.SharpenedFangs;
Expand All @@ -73,6 +74,7 @@
import us.eunoians.mcrpg.api.events.mcrpg.swords.SerratedStrikesEvent;
import us.eunoians.mcrpg.api.events.mcrpg.swords.TaintedBladeEvent;
import us.eunoians.mcrpg.api.events.mcrpg.taming.ComraderyEvent;
import us.eunoians.mcrpg.api.events.mcrpg.taming.DivineFurEvent;
import us.eunoians.mcrpg.api.events.mcrpg.taming.GoreEvent;
import us.eunoians.mcrpg.api.events.mcrpg.taming.LinkedFangsEvent;
import us.eunoians.mcrpg.api.events.mcrpg.taming.SharpenedFangsEvent;
Expand Down Expand Up @@ -102,10 +104,16 @@
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

public class VanillaDamageEvent implements Listener {

private static final String FALL_DAMAGE_DIVINE_FUR_KEY = "Fall_Damage";
private static final String FIRE_DAMAGE_DIVINE_FUR_KEY = "Fire_Damage";
private static final String MAGIC_DAMAGE_DIVINE_FUR_KEY = "Magic_Damage";
private static final String ALL_DAMAGE_DIVINE_FUR_KEY = "All_Damage";

public static void handleHealthbars(Entity attacker, LivingEntity target, double damage){
if(!(attacker instanceof Player) || target instanceof ArmorStand){
Expand Down Expand Up @@ -148,13 +156,135 @@ private static boolean isNPCEntity(Entity entity){
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void fallListener(EntityDamageEvent e){
public void genericDamageListener(EntityDamageEvent e){
//Disabled Worlds
if(McRPG.getInstance().getConfig().contains("Configuration.DisabledWorlds") &&
McRPG.getInstance().getConfig().getStringList("Configuration.DisabledWorlds").contains(e.getEntity().getWorld().getName())) {
return;
}
FileConfiguration config = McRPG.getInstance().getFileManager().getFile(FileManager.Files.FITNESS_CONFIG);

if(e.getEntity() instanceof Wolf){
Wolf wolf = (Wolf) e.getEntity();
if(wolf.getOwner() != null){
McRPGPlayer mcRPGPlayer;
try{
mcRPGPlayer = PlayerManager.getPlayer(wolf.getOwner().getUniqueId());
} catch(McRPGPlayerNotFoundException exception){
return;
}

if(UnlockedAbilities.DIVINE_FUR.isEnabled() && mcRPGPlayer.doesPlayerHaveAbilityInLoadout(UnlockedAbilities.DIVINE_FUR)
&& mcRPGPlayer.getBaseAbility(UnlockedAbilities.DIVINE_FUR).isToggled()){

FileConfiguration tamingConfig = McRPG.getInstance().getFileManager().getFile(FileManager.Files.TAMING_CONFIG);
DivineFur divineFur = (DivineFur) mcRPGPlayer.getBaseAbility(UnlockedAbilities.DIVINE_FUR);
String tier = Methods.convertToNumeral(divineFur.getCurrentTier());

List<String> damagePreventions = tamingConfig.getStringList("DivineFurConfig.Tier" + tier + ".Protections");
Map<String, Double> preventionAmounts = new HashMap<>();

for(String prevention : damagePreventions){
String[] data = prevention.split(":");
preventionAmounts.put(data[0], Double.parseDouble(data[1]));
}

if(e.getCause() == EntityDamageEvent.DamageCause.FALL){
if(preventionAmounts.containsKey(FALL_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(FALL_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
else if(preventionAmounts.containsKey(ALL_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(ALL_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
}
else if(e.getCause() == EntityDamageEvent.DamageCause.FIRE || e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){
if(preventionAmounts.containsKey(FIRE_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(FIRE_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
else if(preventionAmounts.containsKey(ALL_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(ALL_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
}
else if(e.getCause() == EntityDamageEvent.DamageCause.MAGIC || e.getCause() == EntityDamageEvent.DamageCause.DRAGON_BREATH){
if(preventionAmounts.containsKey(MAGIC_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(MAGIC_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
else if(preventionAmounts.containsKey(ALL_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(ALL_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
}
else{
if(preventionAmounts.containsKey(ALL_DAMAGE_DIVINE_FUR_KEY)){
DivineFurEvent divineFurEvent = new DivineFurEvent(mcRPGPlayer, divineFur, e.getCause(), preventionAmounts.get(ALL_DAMAGE_DIVINE_FUR_KEY));
Bukkit.getPluginManager().callEvent(divineFurEvent);
if(!divineFurEvent.isCancelled()){
if(divineFurEvent.getPercentProtected() >= 100.0d){
e.setCancelled(true);
}
else{
e.setDamage(e.getDamage() - (e.getDamage() * divineFurEvent.getPercentProtected()));
}
}
}
}
}
}
}

FileConfiguration fitnessConfig = McRPG.getInstance().getFileManager().getFile(FileManager.Files.FITNESS_CONFIG);
if(!(e instanceof EntityDamageByEntityEvent)){
if(e.isCancelled() || !Skills.FITNESS.isEnabled() || e.getEntity().isInsideVehicle()){
return;
Expand Down Expand Up @@ -228,10 +358,10 @@ public void fallListener(EntityDamageEvent e){
int diffInX = Math.abs(oldLoc.getBlockX() - currentLocation.getBlockX());
int diffInY = Math.abs(oldLoc.getBlockY() - currentLocation.getBlockY());
int diffInZ = Math.abs(oldLoc.getBlockZ() - currentLocation.getBlockZ());
int numOfDiffAxis = diffInY <= config.getInt("AntiAFK.YRange") ? 1 : 0;
numOfDiffAxis += diffInX <= config.getInt("AntiAfk.XRange") ? 1 : 0;
numOfDiffAxis += diffInZ <= config.getInt("AntiAfk.ZRange") ? 1 : 0;
afk = numOfDiffAxis >= config.getInt("AntiAFK.AmountOfDifferences", 1);
int numOfDiffAxis = diffInY <= fitnessConfig.getInt("AntiAFK.YRange") ? 1 : 0;
numOfDiffAxis += diffInX <= fitnessConfig.getInt("AntiAfk.XRange") ? 1 : 0;
numOfDiffAxis += diffInZ <= fitnessConfig.getInt("AntiAfk.ZRange") ? 1 : 0;
afk = numOfDiffAxis >= fitnessConfig.getInt("AntiAFK.AmountOfDifferences", 1);
}
if(mcRPGPlayer.getLastFallLocation().size() >= 4){
while(mcRPGPlayer.getLastFallLocation().size() >= 4){
Expand All @@ -241,8 +371,8 @@ public void fallListener(EntityDamageEvent e){
}
}
if(!afk && player.getHealth() - e.getDamage() > 0){
expAwarded = config.getInt("ExpAwardedPerDamage.FALL_DAMAGE");
Parser equation = new Parser(config.getString("FallEquation"));
expAwarded = fitnessConfig.getInt("ExpAwardedPerDamage.FALL_DAMAGE");
Parser equation = new Parser(fitnessConfig.getString("FallEquation"));
equation.setVariable("damage", e.getDamage());
equation.setVariable("exp_awarded", expAwarded);
equation.setVariable("feather_falling_level", featherFallingLevel);
Expand All @@ -254,7 +384,7 @@ public void fallListener(EntityDamageEvent e){
}
Roll roll = (Roll) mcRPGPlayer.getBaseAbility(DefaultAbilities.ROLL);
if(roll.getGenericAbility().isEnabled() && roll.isToggled()){
Parser rollEquation = new Parser(config.getString("RollConfig.RollChanceEquation"));
Parser rollEquation = new Parser(fitnessConfig.getString("RollConfig.RollChanceEquation"));
rollEquation.setVariable("fitness_level", mcRPGPlayer.getSkill(Skills.FITNESS).getCurrentLevel());
int chance = (int) (rollEquation.getValue() * 1000);
Random rand = new Random();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/skills/taming.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ DivineFurConfig:
Protections:
- 'Fall_Damage:100'
- 'Fire_Damage:100'
- 'Magic_Resistance:100'
- 'Magic_Damage:100'
TierIV:
Protections:
- 'Fall_Damage:100'
Expand Down

0 comments on commit 7d750cb

Please sign in to comment.