!Moved damage modifiers to MMOLib

This commit is contained in:
Indyuce 2019-12-23 21:23:05 +01:00
parent d98489dcb4
commit 07b7ca7786
15 changed files with 26 additions and 203 deletions

View File

@ -62,7 +62,6 @@ import net.Indyuce.mmocore.listener.PartyListener;
import net.Indyuce.mmocore.listener.PlayerListener;
import net.Indyuce.mmocore.listener.SpellCast;
import net.Indyuce.mmocore.listener.WaypointsListener;
import net.Indyuce.mmocore.listener.event.PlayerAttackEventListener;
import net.Indyuce.mmocore.listener.option.DeathExperienceLoss;
import net.Indyuce.mmocore.listener.option.HealthScale;
import net.Indyuce.mmocore.listener.option.NoSpawnerEXP;
@ -113,14 +112,14 @@ public class MMOCore extends JavaPlugin {
public ConfigItemManager configItems;
public SkillManager skillManager;
public final ProfessionManager professionManager = new ProfessionManager();
//public final SQLManager sqlManager = new SQLManager();
// public final SQLManager sqlManager = new SQLManager();
public VaultEconomy economy;
public HologramSupport hologramSupport;
public PlaceholderParser placeholderParser = new DefaultParser();
public final EntityManager entities = new EntityManager();
public InventoryManager inventoryManager;
public RegionHandler regionHandler;
public PlayerActionBar actionBarManager ;
public PlayerActionBar actionBarManager;
/*
* professions
@ -143,7 +142,7 @@ public class MMOCore extends JavaPlugin {
*/
if (Bukkit.getPluginManager().getPlugin("MMOItems") != null)
loadManager.registerLoader(new MMOItemsMMOLoader());
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
loadManager.registerLoader(new WorldGuardMMOLoader());
@ -160,7 +159,7 @@ public class MMOCore extends JavaPlugin {
public void onEnable() {
new Metrics(this);
new MMOLibHook();
if (Bukkit.getPluginManager().getPlugin("Vault") != null)
@ -271,8 +270,6 @@ public class MMOCore extends JavaPlugin {
if (getConfig().getBoolean("death-exp-loss.enabled"))
Bukkit.getPluginManager().registerEvents(new DeathExperienceLoss(), this);
Bukkit.getPluginManager().registerEvents(new PlayerAttackEventListener(), this);
Bukkit.getPluginManager().registerEvents(new WaypointsListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), this);
@ -335,8 +332,8 @@ public class MMOCore extends JavaPlugin {
MMOCoreCommand mmoCoreCommand = new MMOCoreCommand();
getCommand("mmocore").setExecutor(mmoCoreCommand);
getCommand("mmocore").setTabCompleter(mmoCoreCommand);
if(getConfig().getBoolean("auto-save.enabled")) {
if (getConfig().getBoolean("auto-save.enabled")) {
int autosave = getConfig().getInt("auto-save.interval") * 20;
new BukkitRunnable() {
public void run() {
@ -429,11 +426,11 @@ public class MMOCore extends JavaPlugin {
}
public boolean isMILoaded() {
if(!miChecked) {
if (!miChecked) {
miLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems");
miChecked = true;
}
return miLoaded;
}
}

View File

@ -1,64 +0,0 @@
package net.Indyuce.mmocore.api.event;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.api.AttackResult;
import net.mmogroup.mmolib.api.DamageType;
public class PlayerAttackEvent extends PlayerDataEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final EntityDamageByEntityEvent event;
private final AttackResult attack;
public PlayerAttackEvent(PlayerData data, EntityDamageByEntityEvent event, AttackResult attack) {
super(data);
this.event = event;
this.attack = attack;
}
@Override
public boolean isCancelled() {
return event.isCancelled();
}
@Override
public void setCancelled(boolean value) {
event.setCancelled(value);
}
public AttackResult getAttackInfo() {
return attack;
}
// @Deprecated
public boolean isWeapon() {
return attack.getTypes().contains(DamageType.WEAPON);
}
public Entity getEntity() {
return event.getEntity();
}
public double getDamage() {
return event.getDamage();
}
public void setDamage(double value) {
event.setDamage(value);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -11,7 +11,7 @@ public class PlayerCombatEvent extends PlayerDataEvent {
public PlayerCombatEvent(PlayerData playerData, boolean enter) {
super(playerData);
this.enter = enter;
}

View File

@ -3,11 +3,11 @@ package net.Indyuce.mmocore.api.player.profess.event.trigger;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler;
import net.mmogroup.mmolib.api.DamageType;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class AttackEventTrigger implements EventTriggerHandler {
@ -18,7 +18,7 @@ public class AttackEventTrigger implements EventTriggerHandler {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerAttackEvent event) {
PlayerData player = event.getData();
PlayerData player = event.getData().getMMOCore();
PlayerClass profess = player.getProfess();
for (DamageType type : event.getAttackInfo().getTypes()) {

View File

@ -10,6 +10,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.AttackResult;
import net.mmogroup.mmolib.api.DamageType;
import net.mmogroup.mmolib.api.player.MMOData;
import net.mmogroup.mmolib.api.stat.StatInstance;
import net.mmogroup.mmolib.api.stat.StatMap;
@ -23,12 +24,7 @@ public class PlayerStats {
public PlayerStats(PlayerData data) {
this.data = data;
/*
* retrieve stat map (where all stat data is saved) and refresh MMOCore
* data
*/
this.map = StatMap.get(data.getPlayer());
map.getPlayerData().setMMOCore(data);
map = MMOData.get(data.getPlayer()).setMMOCore(data).getStatMap();
}
public PlayerData getData() {

View File

@ -21,7 +21,7 @@ import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason;
public class MythicMobSkill extends Skill {
private final io.lumine.xikage.mythicmobs.skills.Skill skill;
// private final BiFunction<PlayerData, SkillInfo, SkillResult> cast;
// private final BiFunction<PlayerDataManager, SkillInfo, SkillResult> cast;
public MythicMobSkill(String id, FileConfiguration config) {
super(id);

View File

@ -269,11 +269,11 @@ public class EditableFriendList extends EditableInventory {
// continue;
// }
//
// PlayerData data;
// PlayerDataManager data;
// ItemStack item = offline.isOnline() ? new
// ConfigItem("ONLINE_FRIEND").addPlaceholders("name", offline.getName(),
// "online_since", "" + new DelayFormat(2).format(System.currentTimeMillis()
// - (data = PlayerData.get(offline)).getLastLogin()), "class",
// - (data = PlayerDataManager.get(offline)).getLastLogin()), "class",
// data.getProfess().getName(), "level", "" + data.getLevel()).build() : new
// ConfigItem("OFFLINE_FRIEND").addPlaceholders("name", offline.getName(),
// "last_seen", new DelayFormat(2).format(System.currentTimeMillis() -

View File

@ -14,13 +14,9 @@ import org.bukkit.event.player.PlayerQuitEvent;
import com.codingforcookies.armorequip.ArmorEquipEvent;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.event.PlayerCombatEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.PlayerStats;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.gui.api.PluginInventory;
import net.mmogroup.mmolib.api.DamageType;
import net.mmogroup.mmolib.api.stat.SharedStat;
public class PlayerListener implements Listener {
@ -93,19 +89,4 @@ public class PlayerListener implements Listener {
public void g(ArmorEquipEvent event) {
PlayerData.get(event.getPlayer()).getStats().getMap().update(SharedStat.MOVEMENT_SPEED);
}
/*
* apply damage modifiers.
*/
@EventHandler
public void h(PlayerAttackEvent event) {
double damage = event.getDamage();
double d = 1;
PlayerStats stats = event.getData().getStats();
for (DamageType type : event.getAttackInfo().getTypes())
d += (stats.getStat((StatType) type.getMMOCoreStat())) / 100;
event.setDamage(damage * d);
}
}

View File

@ -1,87 +0,0 @@
package net.Indyuce.mmocore.listener.event;
import org.bukkit.Bukkit;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import net.Indyuce.mmocore.api.event.EntityKillEntityEvent;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.AttackResult;
import net.mmogroup.mmolib.api.DamageType;
public class PlayerAttackEventListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void a(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Damageable))
return;
/*
* check for event.
*/
AttackResult result = new AttackResult(true);
Entity damager = getDamager(result, event);
/*
* check for last damage
*/
if (damager == null && (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
damager = getDamager(result, (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause());
/*
* if the damage source cannot be found, just return.
*/
if (damager == null)
return;
/*
* check damage systems from other MMOCore plugins + from MMOCore, and
* register an attack damage for easier plugin calculations
*/
if (damager instanceof Player && !damager.hasMetadata("NPC")) {
AttackResult found = MMOLib.plugin.getDamage().findInfo(event.getEntity());
if (found != null)
result.mergeTypes(found);
Bukkit.getPluginManager().callEvent(new PlayerAttackEvent(PlayerData.get((Player) damager), event, result));
}
/*
* checks for killing
*/
if (event.getFinalDamage() >= ((Damageable) event.getEntity()).getHealth())
Bukkit.getPluginManager().callEvent(new EntityKillEntityEvent(damager, event.getEntity()));
}
private Entity getDamager(AttackResult result, EntityDamageByEntityEvent event) {
/*
* check direct damager
*/
if (event.getDamager() instanceof LivingEntity)
return event.getDamager();
/*
* checks projectile and add damage type, which supports every vanilla
* projectile like snowballs, tridents and arrows
*/
if (event.getDamager() instanceof Projectile) {
Projectile proj = (Projectile) event.getDamager();
if (proj.getShooter() instanceof Entity) {
result.getTypes().add(DamageType.PROJECTILE);
return (Entity) proj.getShooter();
}
}
return null;
}
}

View File

@ -11,7 +11,6 @@ import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.math.particle.ParabolicProjectile;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -19,6 +18,7 @@ import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class Ambers extends Skill implements Listener {
public Ambers() {
@ -34,7 +34,7 @@ public class Ambers extends Skill implements Listener {
@EventHandler
public void a(PlayerAttackEvent event) {
PlayerData data = event.getData();
PlayerData data = event.getData().getMMOCore();
if (event.isWeapon() || !data.getProfess().hasSkill(this))
return;

View File

@ -12,7 +12,6 @@ import org.bukkit.util.Vector;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.MMOCoreUtils;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -21,6 +20,7 @@ import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.AttackResult;
import net.mmogroup.mmolib.api.DamageType;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
import net.mmogroup.mmolib.version.VersionMaterial;
import net.mmogroup.mmolib.version.VersionSound;

View File

@ -10,12 +10,12 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
import net.mmogroup.mmolib.version.VersionSound;
public class Evade extends Skill {

View File

@ -6,10 +6,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class Fire_Berserker extends Skill implements Listener {
public Fire_Berserker() {
@ -27,7 +27,7 @@ public class Fire_Berserker extends Skill implements Listener {
@EventHandler
public void a(PlayerAttackEvent event) {
PlayerData data = event.getData();
PlayerData data = event.getData().getMMOCore();
if (event.getPlayer().getFireTicks() > 0 && data.hasSkillUnlocked(this))
event.setDamage(event.getDamage() * (1 + data.getProfess().getSkill(this).getModifier("extra", data.getSkillLevel(this))));
}

View File

@ -17,7 +17,6 @@ import org.bukkit.util.Vector;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.MMOCoreUtils;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.math.particle.ParabolicProjectile;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -25,6 +24,7 @@ import net.Indyuce.mmocore.api.player.stats.PlayerStats.CachedStats;
import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.api.DamageType;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
import net.mmogroup.mmolib.version.VersionMaterial;
import net.mmogroup.mmolib.version.VersionSound;
@ -45,7 +45,7 @@ public class Power_Mark extends Skill implements Listener {
@EventHandler
public void a(PlayerAttackEvent event) {
PlayerData data = event.getData();
PlayerData data = event.getData().getMMOCore();
if (!event.isWeapon() || !data.getProfess().hasSkill(this))
return;

View File

@ -6,11 +6,11 @@ import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import net.Indyuce.mmocore.api.event.PlayerAttackEvent;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.SkillResult;
import net.mmogroup.mmolib.api.event.PlayerAttackEvent;
public class Sneaky_Picky extends Skill {
public Sneaky_Picky() {
@ -26,7 +26,7 @@ public class Sneaky_Picky extends Skill {
@EventHandler
public void a(PlayerAttackEvent event) {
PlayerData data = event.getData();
PlayerData data = event.getData().getMMOCore();
if (!event.isWeapon() || data.isInCombat() || !data.getProfess().hasSkill(this))
return;