damage api refactor to add support for MM skill damage

This commit is contained in:
Indyuce 2019-08-31 22:03:58 +02:00
parent 772ee48b84
commit 762e41d1a9
18 changed files with 148 additions and 93 deletions

View File

@ -16,6 +16,7 @@ import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.Ability.CastingMode; import net.Indyuce.mmoitems.api.Ability.CastingMode;
import net.Indyuce.mmoitems.api.item.NBTItem; import net.Indyuce.mmoitems.api.item.NBTItem;
import net.Indyuce.mmoitems.api.player.PlayerStats.TemporaryStats; import net.Indyuce.mmoitems.api.player.PlayerStats.TemporaryStats;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.ItemStat;
public class AttackResult { public class AttackResult {
@ -37,13 +38,17 @@ public class AttackResult {
} }
public AttackResult(boolean successful, double damage, DamageType... types) { public AttackResult(boolean successful, double damage, DamageType... types) {
Validate.isTrue(types.length > 0, "Attack must have at least one damage type!"); this(successful, damage, Arrays.asList(types));
}
public AttackResult(boolean successful, double damage, List<DamageType> types) {
Validate.isTrue(types.size() > 0, "Attack must have at least one damage type!");
this.successful = successful; this.successful = successful;
this.initial = damage; this.initial = damage;
this.damage = damage; this.damage = damage;
this.damageTypes = Arrays.asList(types); this.damageTypes = types;
} }
public AttackResult(AttackResult result) { public AttackResult(AttackResult result) {
@ -162,6 +167,10 @@ public class AttackResult {
return this; return this;
} }
public DamageInfo toDamageInfo() {
return new DamageInfo(damage, damageTypes);
}
public enum DamageType { public enum DamageType {
/* /*

View File

@ -11,27 +11,23 @@ import com.evill4mer.RealDualWield.Api.PlayerDamageEntityWithOffhandEvent;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.AttackResult; import net.Indyuce.mmoitems.api.AttackResult;
import net.Indyuce.mmoitems.api.TypeSet;
import net.Indyuce.mmoitems.api.AttackResult.DamageType; import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.TypeSet;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.item.NBTItem; import net.Indyuce.mmoitems.api.item.NBTItem;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.PlayerStats.TemporaryStats; import net.Indyuce.mmoitems.api.player.PlayerStats.TemporaryStats;
public class RealDualWieldHook implements Listener { public class RealDualWieldHook implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void a(PlayerDamageEntityWithOffhandEvent event) { public void a(PlayerDamageEntityWithOffhandEvent event) {
// check for npc // check for npc
// safety checks // safety checks
if (event.getEntity().hasMetadata("NPC") || event.isCancelled() || !(event.getEntity() instanceof LivingEntity) || event.getDamage() == 0) if (event.getEntity().hasMetadata("NPC") || !(event.getEntity() instanceof LivingEntity) || event.getDamage() == 0)
return; return;
// custom damage check
LivingEntity target = (LivingEntity) event.getEntity(); LivingEntity target = (LivingEntity) event.getEntity();
if (MMOItems.plugin.getDamage().isDamaged(target) || !MMOItems.plugin.getRPG().canBeDamaged(target))
return;
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
TemporaryStats stats = null; TemporaryStats stats = null;

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmoitems.comp.mmocore; package net.Indyuce.mmoitems.comp.mmocore;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -7,7 +9,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent; import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
@ -15,14 +16,17 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Attribute; import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Attribute;
import net.Indyuce.mmoitems.comp.rpg.RPGHandler; import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageHandler;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageInfo;
import net.Indyuce.mmoitems.stat.type.DoubleStat; import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.version.VersionMaterial; import net.Indyuce.mmoitems.version.VersionMaterial;
public class MMOCoreHook implements RPGHandler, Listener { public class MMOCoreHook implements RPGHandler, Listener, DamageHandler {
private final ItemStat manaRegen = new DoubleStat(VersionMaterial.LAPIS_LAZULI.toItem(), "Mana Regeneration", new String[] { "Increases mana regen." }, "mana-regen"); private final ItemStat manaRegen = new DoubleStat(VersionMaterial.LAPIS_LAZULI.toItem(), "Mana Regeneration", new String[] { "Increases mana regen." }, "mana-regen");
private final ItemStat maxStamina = new DoubleStat(VersionMaterial.LIGHT_BLUE_DYE.toItem(), "Max Stamina", new String[] { "Adds stamina to your max stamina bar." }, "max-stamina"); private final ItemStat maxStamina = new DoubleStat(VersionMaterial.LIGHT_BLUE_DYE.toItem(), "Max Stamina", new String[] { "Adds stamina to your max stamina bar." }, "max-stamina");
@ -40,7 +44,8 @@ public class MMOCoreHook implements RPGHandler, Listener {
/* /*
* register custom damage * register custom damage
*/ */
MMOCore.plugin.damage.registerHandler(new MMOCoreDamageHandler()); MMOCore.plugin.damage.registerHandler(new MMOItemsDamageHandler());
MMOItems.plugin.getDamage().registerHandler(this);
MMOItems.plugin.getStats().register("MANA_REGENERATION", manaRegen); MMOItems.plugin.getStats().register("MANA_REGENERATION", manaRegen);
MMOItems.plugin.getStats().register("MAX_STAMINA", maxStamina); MMOItems.plugin.getStats().register("MAX_STAMINA", maxStamina);
@ -57,8 +62,14 @@ public class MMOCoreHook implements RPGHandler, Listener {
} }
@Override @Override
public boolean canBeDamaged(Entity entity) { public boolean hasDamage(Entity entity) {
return !MMOCore.plugin.damage.hasDamage(entity); return MMOCore.plugin.damage.hasDamage(entity);
}
@Override
public DamageInfo getDamage(Entity entity) {
net.Indyuce.mmocore.comp.rpg.damage.DamageInfo info = MMOCore.plugin.damage.getDamage(entity);
return new DamageInfo(info.getValue(), info.getTypes().stream().map((type) -> DamageType.valueOf(type.name())).collect(Collectors.toList()));
} }
@Override @Override

View File

@ -8,14 +8,13 @@ import net.Indyuce.mmocore.comp.rpg.damage.DamageHandler;
import net.Indyuce.mmocore.comp.rpg.damage.DamageInfo; import net.Indyuce.mmocore.comp.rpg.damage.DamageInfo;
import net.Indyuce.mmocore.comp.rpg.damage.DamageInfo.DamageType; import net.Indyuce.mmocore.comp.rpg.damage.DamageInfo.DamageType;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.AttackResult;
public class MMOItemsDamageHandler implements DamageHandler { public class MMOItemsDamageHandler implements DamageHandler {
@Override @Override
public DamageInfo getDamage(Entity entity) { public DamageInfo getDamage(Entity entity) {
AttackResult result = MMOItems.plugin.getDamage().getDamage(entity); net.Indyuce.mmoitems.comp.rpg.damage.DamageInfo result = MMOItems.plugin.getDamage().getDamage(entity);
return new DamageInfo(result.getDamage(), result.getTypes().stream().map((type) -> DamageType.valueOf(type.name())).collect(Collectors.toSet())); return new DamageInfo(result.getValue(), result.getTypes().stream().map((type) -> DamageType.valueOf(type.name())).collect(Collectors.toSet()));
} }
@Override @Override

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -30,11 +29,6 @@ public class BattleLevelsHook implements RPGHandler, Listener {
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
public class BattleLevelsPlayer extends RPGPlayer { public class BattleLevelsPlayer extends RPGPlayer {
public BattleLevelsPlayer(PlayerData playerData) { public BattleLevelsPlayer(PlayerData playerData) {
super(playerData); super(playerData);

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerLevelChangeEvent;
@ -15,11 +14,6 @@ public class DefaultHook implements RPGHandler, Listener {
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
@Override @Override
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }

View File

@ -1,5 +1,9 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -7,24 +11,41 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.herocraftonline.heroes.Heroes; import com.herocraftonline.heroes.Heroes;
import com.herocraftonline.heroes.api.SkillUseInfo;
import com.herocraftonline.heroes.api.events.HeroChangeLevelEvent; import com.herocraftonline.heroes.api.events.HeroChangeLevelEvent;
import com.herocraftonline.heroes.api.events.SkillDamageEvent; import com.herocraftonline.heroes.api.events.SkillDamageEvent;
import com.herocraftonline.heroes.characters.Hero; import com.herocraftonline.heroes.characters.Hero;
import com.herocraftonline.heroes.characters.skill.SkillType; import com.herocraftonline.heroes.characters.skill.SkillType;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageHandler;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.ItemStat;
public class HeroesHook implements RPGHandler, Listener { public class HeroesHook implements RPGHandler, Listener, DamageHandler {
private final Map<SkillType, DamageType> damages = new HashMap<>();
public HeroesHook() { public HeroesHook() {
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
MMOItems.plugin.getDamage().registerHandler(this);
damages.put(SkillType.ABILITY_PROPERTY_PHYSICAL, DamageType.PHYSICAL);
damages.put(SkillType.ABILITY_PROPERTY_MAGICAL, DamageType.MAGICAL);
damages.put(SkillType.ABILITY_PROPERTY_PROJECTILE, DamageType.PROJECTILE);
} }
@Override @Override
public boolean canBeDamaged(Entity player) { public boolean hasDamage(Entity entity) {
return !Heroes.getInstance().getDamageManager().isSpellTarget(player); return Heroes.getInstance().getDamageManager().isSpellTarget(entity);
}
@Override
public DamageInfo getDamage(Entity entity) {
SkillUseInfo info = Heroes.getInstance().getDamageManager().getSpellTargetInfo(entity);
return new DamageInfo(0, info.getSkill().getTypes().stream().filter(type -> damages.containsKey(type)).map(type -> damages.get(type)).collect(Collectors.toList()));
} }
@Override @Override

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -38,11 +37,6 @@ public class McMMOHook implements RPGHandler, Listener {
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
public class McMMOPlayer extends RPGPlayer { public class McMMOPlayer extends RPGPlayer {
public McMMOPlayer(PlayerData playerData) { public McMMOPlayer(PlayerData playerData) {
super(playerData); super(playerData);

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -30,11 +29,6 @@ public class McRPGHook implements RPGHandler, Listener {
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
public class McRPGPlayer extends RPGPlayer { public class McRPGPlayer extends RPGPlayer {
public McRPGPlayer(PlayerData playerData) { public McRPGPlayer(PlayerData playerData) {
super(playerData); super(playerData);

View File

@ -2,8 +2,6 @@ package net.Indyuce.mmoitems.comp.rpg;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.entity.Entity;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
@ -14,8 +12,6 @@ public interface RPGHandler {
public void refreshStats(PlayerData data); public void refreshStats(PlayerData data);
public boolean canBeDamaged(Entity entity);
public enum PluginEnum { public enum PluginEnum {
MMOCORE("MMOCore", MMOCoreHook.class), MMOCORE("MMOCore", MMOCoreHook.class),
HEROES("Heroes", HeroesHook.class), HEROES("Heroes", HeroesHook.class),

View File

@ -1,18 +1,11 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.entity.Entity;
import me.baks.rpl.PlayerList; import me.baks.rpl.PlayerList;
import me.baks.rpl.api.API; import me.baks.rpl.api.API;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
public class RPGPlayerLevelingHook implements RPGHandler { public class RPGPlayerLevelingHook implements RPGHandler {
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
@Override @Override
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -40,11 +39,6 @@ public class SkillAPIHook implements RPGHandler, Listener {
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).scheduleDelayedInventoryUpdate(); net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).scheduleDelayedInventoryUpdate();
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
@Override @Override
public void refreshStats(net.Indyuce.mmoitems.api.player.PlayerData data) { public void refreshStats(net.Indyuce.mmoitems.api.player.PlayerData data) {
} }

View File

@ -2,7 +2,6 @@ package net.Indyuce.mmoitems.comp.rpg;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -26,11 +25,6 @@ public class SkillsHook implements RPGHandler, Listener {
PlayerData.get(player).scheduleDelayedInventoryUpdate(); PlayerData.get(player).scheduleDelayedInventoryUpdate();
} }
@Override
public boolean canBeDamaged(Entity entity) {
return true;
}
@Override @Override
public void refreshStats(PlayerData data) { public void refreshStats(PlayerData data) {
} }

View File

@ -0,0 +1,9 @@
package net.Indyuce.mmoitems.comp.rpg.damage;
import org.bukkit.entity.Entity;
public interface DamageHandler {
public DamageInfo getDamage(Entity entity);
public boolean hasDamage(Entity entity);
}

View File

@ -0,0 +1,37 @@
package net.Indyuce.mmoitems.comp.rpg.damage;
import java.util.Arrays;
import java.util.List;
import net.Indyuce.mmoitems.api.AttackResult;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
public class DamageInfo {
private final double damage;
private final List<DamageType> damageTypes;
public DamageInfo(double damage, DamageType... damageTypes) {
this(damage, Arrays.asList(damageTypes));
}
public DamageInfo(double damage, List<DamageType> damageTypes) {
this.damage = damage;
this.damageTypes = damageTypes;
}
public double getValue() {
return damage;
}
public List<DamageType> getTypes() {
return damageTypes;
}
public boolean hasType(DamageType type) {
return damageTypes.contains(type);
}
public AttackResult toAttackResult() {
return new AttackResult(true, damage, damageTypes);
}
}

View File

@ -26,9 +26,9 @@ import org.bukkit.inventory.EquipmentSlot;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.AttackResult; import net.Indyuce.mmoitems.api.AttackResult;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.TypeSet; import net.Indyuce.mmoitems.api.TypeSet;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.interaction.GemStone; import net.Indyuce.mmoitems.api.interaction.GemStone;
import net.Indyuce.mmoitems.api.interaction.GemStone.ApplyResult; import net.Indyuce.mmoitems.api.interaction.GemStone.ApplyResult;
@ -96,17 +96,17 @@ public class ItemUse implements Listener {
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void b(EntityDamageByEntityEvent event) { public void b(EntityDamageByEntityEvent event) {
// check for npc // check for npc
// safety checks // safety checks
if (event.getEntity().hasMetadata("NPC") || event.isCancelled() || !(event.getDamager() instanceof Player) || !(event.getEntity() instanceof LivingEntity) || event.getDamage() == 0 || event.getCause() != DamageCause.ENTITY_ATTACK) if (event.getEntity().hasMetadata("NPC") || !(event.getDamager() instanceof Player) || !(event.getEntity() instanceof LivingEntity) || event.getDamage() == 0 || event.getCause() != DamageCause.ENTITY_ATTACK)
return; return;
// custom damage check // custom damage check
LivingEntity target = (LivingEntity) event.getEntity(); LivingEntity target = (LivingEntity) event.getEntity();
if (MMOItems.plugin.getDamage().isDamaged(target) || !MMOItems.plugin.getRPG().canBeDamaged(target)) if (MMOItems.plugin.getDamage().findInfo(target) != null)
return; return;
Player player = (Player) event.getDamager(); Player player = (Player) event.getDamager();

View File

@ -23,8 +23,8 @@ import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.ability.Magical_Shield; import net.Indyuce.mmoitems.ability.Magical_Shield;
import net.Indyuce.mmoitems.api.Ability.CastingMode; import net.Indyuce.mmoitems.api.Ability.CastingMode;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.AttackResult; import net.Indyuce.mmoitems.api.AttackResult;
import net.Indyuce.mmoitems.api.AttackResult.DamageType;
import net.Indyuce.mmoitems.api.SoulboundInfo; import net.Indyuce.mmoitems.api.SoulboundInfo;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.PlayerStats; import net.Indyuce.mmoitems.api.player.PlayerStats;
@ -46,19 +46,21 @@ public class PlayerListener implements Listener {
event.setDamage(event.getDamage() * (1 - Math.max(values[1], 1))); event.setDamage(event.getDamage() * (1 - Math.max(values[1], 1)));
} }
// damage reduction stats /*
* damage reduction
*/
if (MMOItems.plugin.getDamage().findInfo(player) != null)
return;
PlayerStats stats = PlayerData.get(player).getStats(); PlayerStats stats = PlayerData.get(player).getStats();
if (MMOItems.plugin.getRPG().canBeDamaged(player) && !MMOItems.plugin.getDamage().isDamaged(player)) { if (event.getCause() == DamageCause.FIRE)
if (event.getCause() == DamageCause.FIRE) event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FIRE_DAMAGE_REDUCTION) / 100));
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FIRE_DAMAGE_REDUCTION) / 100)); else if (event.getCause() == DamageCause.FALL)
else if (event.getCause() == DamageCause.FALL) event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FALL_DAMAGE_REDUCTION) / 100));
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.FALL_DAMAGE_REDUCTION) / 100)); else if (event.getCause() == DamageCause.MAGIC)
else if (event.getCause() == DamageCause.MAGIC) event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.MAGIC_DAMAGE_REDUCTION) / 100));
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.MAGIC_DAMAGE_REDUCTION) / 100)); else if (event.getCause() == DamageCause.ENTITY_ATTACK || event.getCause() == DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == DamageCause.PROJECTILE)
else if (event.getCause() == DamageCause.ENTITY_ATTACK || event.getCause() == DamageCause.ENTITY_SWEEP_ATTACK || event.getCause() == DamageCause.PROJECTILE) event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.PHYSICAL_DAMAGE_REDUCTION) / 100));
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.PHYSICAL_DAMAGE_REDUCTION) / 100));
}
event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.DAMAGE_REDUCTION) / 100)); event.setDamage(event.getDamage() * (1 - stats.getStat(ItemStat.DAMAGE_REDUCTION) / 100));
} }

View File

@ -1,30 +1,45 @@
package net.Indyuce.mmoitems.manager; package net.Indyuce.mmoitems.manager;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Wither;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import net.Indyuce.mmoitems.api.AttackResult; import net.Indyuce.mmoitems.api.AttackResult;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageHandler;
import net.Indyuce.mmoitems.comp.rpg.damage.DamageInfo;
public class DamageManager implements Listener { public class DamageManager implements Listener, DamageHandler {
private final Map<Integer, AttackResult> customDamage = new HashMap<>(); private final Map<Integer, DamageInfo> customDamage = new HashMap<>();
private final List<DamageHandler> handlers = new ArrayList<>();
public DamageManager() {
handlers.add(this);
}
public void registerHandler(DamageHandler handler) {
handlers.add(handler);
}
public boolean isDamaged(Entity entity) { public boolean isDamaged(Entity entity) {
return customDamage.containsKey(entity.getEntityId()); return customDamage.containsKey(entity.getEntityId());
} }
public AttackResult getDamage(Entity entity) { @Override
public boolean hasDamage(Entity entity) {
return customDamage.containsKey(entity.getEntityId());
}
public DamageInfo getDamage(Entity entity) {
return customDamage.get(entity.getEntityId()); return customDamage.get(entity.getEntityId());
} }
@ -40,7 +55,7 @@ public class DamageManager implements Listener {
* calculate extra damage depending on the type of attack and the entity * calculate extra damage depending on the type of attack and the entity
* that is being damaged * that is being damaged
*/ */
customDamage.put(target.getEntityId(), result); customDamage.put(target.getEntityId(), result.toDamageInfo());
if (!knockback) { if (!knockback) {
final double baseKnockbackValue = target.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).getBaseValue(); final double baseKnockbackValue = target.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).getBaseValue();
@ -56,8 +71,11 @@ public class DamageManager implements Listener {
target.damage(result.getDamage(), player); target.damage(result.getDamage(), player);
} }
public boolean isUndead(Entity entity) { public DamageInfo findInfo(Entity entity) {
return entity instanceof Zombie || entity instanceof Skeleton || entity instanceof Wither; for (DamageHandler handler : handlers)
if (handler.hasDamage(entity))
return handler.getDamage(entity);
return null;
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)