2013-10-15 19:03:33 +02:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
2019-01-28 03:11:51 +01:00
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
2013-11-11 17:42:57 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
2019-01-13 08:54:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
2019-01-13 04:56:54 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelChangeEvent;
|
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
|
2013-10-15 19:03:33 +02:00
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.events.fake.*;
|
2014-08-17 05:04:19 +02:00
|
|
|
import com.gmail.nossr50.events.hardcore.McMMOPlayerPreDeathPenaltyEvent;
|
|
|
|
import com.gmail.nossr50.events.hardcore.McMMOPlayerStatLossEvent;
|
|
|
|
import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismEvent;
|
2013-11-11 17:42:57 +01:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
2013-11-11 17:42:57 +01:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent;
|
2013-10-15 19:03:33 +02:00
|
|
|
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
|
|
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
|
|
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent;
|
|
|
|
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent;
|
2018-12-29 14:24:55 +01:00
|
|
|
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
2018-07-24 04:13:57 +02:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2019-01-09 04:52:52 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
2018-07-24 04:13:57 +02:00
|
|
|
import org.bukkit.entity.FishHook;
|
2019-01-09 04:52:52 +01:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2018-07-24 04:13:57 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2019-01-09 04:52:52 +01:00
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2018-07-24 04:13:57 +02:00
|
|
|
import org.bukkit.event.player.PlayerFishEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2013-10-15 19:03:33 +02:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
/**
|
|
|
|
* This class is meant to help make event related code less boilerplate
|
|
|
|
*/
|
2013-10-15 19:03:33 +02:00
|
|
|
public class EventUtils {
|
2019-01-09 04:52:52 +01:00
|
|
|
/*
|
|
|
|
* Quality of Life methods
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Checks to see if damage is from natural sources
|
|
|
|
* This cannot be used to determine if damage is from vanilla MC, it just checks to see if the damage is from a complex behaviour in mcMMO such as bleed.
|
|
|
|
*
|
|
|
|
* @param event this event
|
|
|
|
* @return true if damage is NOT from an unnatural mcMMO skill (such as bleed DOTs)
|
|
|
|
*/
|
|
|
|
public static boolean isDamageFromMcMMOComplexBehaviour(Event event) {
|
2019-08-25 15:51:19 +02:00
|
|
|
return event instanceof FakeEntityDamageEvent;
|
2019-01-09 04:52:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This little method is just to make the code more readable
|
|
|
|
* @param entity target entity
|
|
|
|
* @return the associated McMMOPlayer for this entity
|
|
|
|
*/
|
|
|
|
public static McMMOPlayer getMcMMOPlayer(Entity entity)
|
|
|
|
{
|
|
|
|
return UserManager.getPlayer((Player)entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a Player was damaged in this EntityDamageEvent
|
|
|
|
*
|
|
|
|
* This method checks for the following things and if they are all true it returns true
|
|
|
|
*
|
|
|
|
* 1) The player is real and not an NPC
|
|
|
|
* 2) The player is not in god mode
|
|
|
|
* 3) The damage dealt is above 0
|
|
|
|
* 4) The player is loaded into our mcMMO user profiles
|
|
|
|
*
|
|
|
|
* @param entityDamageEvent
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static boolean isRealPlayerDamaged(EntityDamageEvent entityDamageEvent)
|
|
|
|
{
|
|
|
|
//Make sure the damage is above 0
|
|
|
|
double damage = entityDamageEvent.getFinalDamage();
|
|
|
|
|
|
|
|
if (damage <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity entity = entityDamageEvent.getEntity();
|
|
|
|
|
|
|
|
//Check to make sure the entity is not an NPC
|
2019-06-17 16:00:39 +02:00
|
|
|
if(Misc.isNPCEntityExcludingVillagers(entity))
|
2019-01-09 04:52:52 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!entity.isValid() || !(entity instanceof LivingEntity)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LivingEntity livingEntity = (LivingEntity) entity;
|
|
|
|
|
|
|
|
if (CombatUtils.isInvincible(livingEntity, damage)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (livingEntity instanceof Player) {
|
|
|
|
Player player = (Player) entity;
|
|
|
|
|
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
2019-04-13 00:17:05 +02:00
|
|
|
return true;
|
2019-01-09 04:52:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
if(mcMMOPlayer == null)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
/* Check for invincibility */
|
|
|
|
if (mcMMOPlayer.getGodMode()) {
|
|
|
|
entityDamageEvent.setCancelled(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Others
|
|
|
|
*/
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, PrimarySkillType skill) {
|
2013-10-15 19:03:33 +02:00
|
|
|
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2014-05-11 14:58:08 +02:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
/**
|
|
|
|
* Calls a new SubSkillEvent for this SubSkill and then returns it
|
|
|
|
* @param player target player
|
|
|
|
* @param subSkillType target subskill
|
|
|
|
* @return the event after it has been fired
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public static SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) {
|
|
|
|
SubSkillEvent event = new SubSkillEvent(player, subSkillType);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a new SubSkillEvent for this SubSkill and then returns it
|
|
|
|
* @param player target player
|
|
|
|
* @param abstractSubSkill target subskill
|
|
|
|
* @return the event after it has been fired
|
|
|
|
*/
|
|
|
|
public static SubSkillEvent callSubSkillEvent(Player player, AbstractSubSkill abstractSubSkill) {
|
|
|
|
SubSkillEvent event = new SubSkillEvent(player, abstractSubSkill);
|
2014-05-11 14:58:08 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
2013-10-15 19:03:33 +02:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FakePlayerAnimationEvent callFakeArmSwingEvent(Player player) {
|
|
|
|
FakePlayerAnimationEvent event = new FakePlayerAnimationEvent(player);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2019-06-22 23:48:16 +02:00
|
|
|
public static boolean tryLevelChangeEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason) {
|
2014-04-18 21:56:03 +02:00
|
|
|
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
|
2013-10-15 19:03:33 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (isCancelled) {
|
|
|
|
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
|
|
|
|
2013-10-18 15:23:40 +02:00
|
|
|
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged));
|
2013-10-29 16:02:57 +01:00
|
|
|
profile.addXp(skill, xpRemoved);
|
2013-10-18 14:31:00 +02:00
|
|
|
}
|
|
|
|
|
2019-06-22 23:48:16 +02:00
|
|
|
return isCancelled;
|
2013-10-15 19:03:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-22 23:48:16 +02:00
|
|
|
public static boolean tryLevelEditEvent(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) {
|
2019-03-31 01:44:06 +01:00
|
|
|
McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged - oldLevel, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (isCancelled) {
|
|
|
|
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
|
|
|
|
|
|
|
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged));
|
|
|
|
profile.addXp(skill, xpRemoved);
|
|
|
|
}
|
|
|
|
|
2019-06-22 23:48:16 +02:00
|
|
|
return isCancelled;
|
2019-03-31 01:44:06 +01:00
|
|
|
}
|
|
|
|
|
2013-10-15 19:03:33 +02:00
|
|
|
/**
|
|
|
|
* Simulate a block break event.
|
|
|
|
*
|
|
|
|
* @param block The block to break
|
|
|
|
* @param player The player breaking the block
|
|
|
|
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
|
|
|
|
* @return true if the event wasn't cancelled, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean simulateBlockBreak(Block block, Player player, boolean shouldArmSwing) {
|
|
|
|
PluginManager pluginManager = mcMMO.p.getServer().getPluginManager();
|
|
|
|
|
|
|
|
// Support for NoCheat
|
|
|
|
if (shouldArmSwing) {
|
|
|
|
callFakeArmSwingEvent(player);
|
|
|
|
}
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getInventory().getItemInMainHand(), true);
|
2013-10-15 19:03:33 +02:00
|
|
|
pluginManager.callEvent(damageEvent);
|
|
|
|
|
|
|
|
FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player);
|
|
|
|
pluginManager.callEvent(breakEvent);
|
|
|
|
|
|
|
|
return !damageEvent.isCancelled() && !breakEvent.isCancelled();
|
|
|
|
}
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
|
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
|
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
if(mcMMOPlayer == null)
|
|
|
|
return;
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(teleportingPlayer, targetPlayer, mcMMOPlayer.getParty().getName());
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
teleportingPlayer.teleport(targetPlayer);
|
|
|
|
|
|
|
|
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
|
|
|
|
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
|
|
|
|
|
2013-10-28 20:47:47 +01:00
|
|
|
mcMMOPlayer.getPartyTeleportRecord().actualizeLastUse();
|
2013-10-18 14:31:00 +02:00
|
|
|
}
|
|
|
|
|
2013-11-11 17:42:57 +01:00
|
|
|
public static boolean handlePartyXpGainEvent(Party party, float xpGained) {
|
|
|
|
McMMOPartyXpGainEvent event = new McMMOPartyXpGainEvent(party, xpGained);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (!isCancelled) {
|
|
|
|
party.addXp(event.getRawXpGained());
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isCancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean handlePartyLevelChangeEvent(Party party, int levelsChanged, float xpRemoved) {
|
|
|
|
McMMOPartyLevelUpEvent event = new McMMOPartyLevelUpEvent(party, levelsChanged);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (isCancelled) {
|
|
|
|
|
|
|
|
party.setLevel(party.getLevel() + levelsChanged);
|
|
|
|
party.addXp(xpRemoved);
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isCancelled;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
public static boolean handleXpGainEvent(Player player, PrimarySkillType skill, float xpGained, XPGainReason xpGainReason) {
|
2014-04-18 21:56:03 +02:00
|
|
|
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained, xpGainReason);
|
2013-10-18 14:31:00 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (!isCancelled) {
|
2013-10-29 16:02:57 +01:00
|
|
|
UserManager.getPlayer(player).addXp(skill, event.getRawXpGained());
|
2013-10-27 06:44:03 +01:00
|
|
|
UserManager.getPlayer(player).getProfile().registerXpGain(skill, event.getRawXpGained());
|
2013-10-18 14:31:00 +02:00
|
|
|
}
|
|
|
|
|
2013-10-19 14:08:04 +02:00
|
|
|
return !isCancelled;
|
2013-10-18 14:31:00 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 05:04:19 +02:00
|
|
|
public static boolean handleStatsLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
2019-04-13 00:17:05 +02:00
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
return true;
|
|
|
|
|
2014-08-17 05:04:19 +02:00
|
|
|
McMMOPlayerStatLossEvent event = new McMMOPlayerStatLossEvent(player, levelChanged, experienceChanged);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
boolean isCancelled = event.isCancelled();
|
|
|
|
|
|
|
|
if (!isCancelled) {
|
|
|
|
levelChanged = event.getLevelChanged();
|
|
|
|
experienceChanged = event.getExperienceChanged();
|
|
|
|
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
|
|
|
|
String skillName = primarySkillType.toString();
|
|
|
|
int playerSkillLevel = playerProfile.getSkillLevel(primarySkillType);
|
2014-08-17 05:04:19 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
playerProfile.modifySkill(primarySkillType, playerSkillLevel - levelChanged.get(skillName));
|
|
|
|
playerProfile.removeXp(primarySkillType, experienceChanged.get(skillName));
|
2014-08-17 05:04:19 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (playerProfile.getSkillXpLevel(primarySkillType) < 0) {
|
|
|
|
playerProfile.setSkillXpLevel(primarySkillType, 0);
|
2014-08-17 05:04:19 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (playerProfile.getSkillLevel(primarySkillType) < 0) {
|
|
|
|
playerProfile.modifySkill(primarySkillType, 0);
|
2014-08-17 05:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isCancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean handleVampirismEvent(Player killer, Player victim, HashMap<String, Integer> levelChanged, HashMap<String, Float> experienceChanged) {
|
|
|
|
McMMOPlayerVampirismEvent eventKiller = new McMMOPlayerVampirismEvent(killer, false, levelChanged, experienceChanged);
|
|
|
|
McMMOPlayerVampirismEvent eventVictim = new McMMOPlayerVampirismEvent(victim, true, levelChanged, experienceChanged);
|
2014-03-16 20:59:03 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(eventKiller);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(eventVictim);
|
|
|
|
|
|
|
|
boolean isCancelled = eventKiller.isCancelled() || eventVictim.isCancelled();
|
|
|
|
|
|
|
|
if (!isCancelled) {
|
2014-08-17 05:04:19 +02:00
|
|
|
HashMap<String, Integer> levelChangedKiller = eventKiller.getLevelChanged();
|
|
|
|
HashMap<String, Float> experienceChangedKiller = eventKiller.getExperienceChanged();
|
|
|
|
|
|
|
|
HashMap<String, Integer> levelChangedVictim = eventVictim.getLevelChanged();
|
|
|
|
HashMap<String, Float> experienceChangedVictim = eventVictim.getExperienceChanged();
|
|
|
|
|
2014-03-16 20:59:03 +01:00
|
|
|
McMMOPlayer killerPlayer = UserManager.getPlayer(killer);
|
2019-04-13 00:17:05 +02:00
|
|
|
|
|
|
|
//Not loaded
|
|
|
|
if(killerPlayer == null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
//Not loaded
|
|
|
|
if(UserManager.getPlayer(victim) == null)
|
|
|
|
return true;
|
|
|
|
|
2014-03-16 20:59:03 +01:00
|
|
|
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
|
|
|
|
String skillName = primarySkillType.toString();
|
|
|
|
int victimSkillLevel = victimProfile.getSkillLevel(primarySkillType);
|
2014-03-16 20:59:03 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
killerPlayer.addLevels(primarySkillType, levelChangedKiller.get(skillName));
|
2019-01-28 03:11:51 +01:00
|
|
|
killerPlayer.beginUnsharedXpGain(primarySkillType, experienceChangedKiller.get(skillName), XPGainReason.VAMPIRISM, XPGainSource.VAMPIRISM);
|
2014-03-16 20:59:03 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
victimProfile.modifySkill(primarySkillType, victimSkillLevel - levelChangedVictim.get(skillName));
|
|
|
|
victimProfile.removeXp(primarySkillType, experienceChangedVictim.get(skillName));
|
2014-08-17 05:04:19 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (victimProfile.getSkillXpLevel(primarySkillType) < 0) {
|
|
|
|
victimProfile.setSkillXpLevel(primarySkillType, 0);
|
2014-08-17 05:04:19 +02:00
|
|
|
}
|
2014-03-16 20:59:03 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (victimProfile.getSkillLevel(primarySkillType) < 0) {
|
|
|
|
victimProfile.modifySkill(primarySkillType, 0);
|
2014-08-17 05:04:19 +02:00
|
|
|
}
|
2014-03-16 20:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isCancelled;
|
|
|
|
}
|
|
|
|
|
2019-01-13 04:56:54 +01:00
|
|
|
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
|
2019-01-13 08:54:53 +01:00
|
|
|
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, PrimarySkillType.byAbility(ability));
|
2013-10-18 14:31:00 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static McMMOPlayerFishingTreasureEvent callFishingTreasureEvent(Player player, ItemStack treasureDrop, int treasureXp, Map<Enchantment, Integer> enchants) {
|
|
|
|
McMMOPlayerFishingTreasureEvent event = enchants.isEmpty() ? new McMMOPlayerFishingTreasureEvent(player, treasureDrop, treasureXp) : new McMMOPlayerMagicHunterEvent(player, treasureDrop, treasureXp, enchants);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
public static FakePlayerFishEvent callFakeFishEvent(Player player, FishHook hook) {
|
2013-10-18 14:31:00 +02:00
|
|
|
FakePlayerFishEvent event = new FakePlayerFishEvent(player, null, hook, PlayerFishEvent.State.FISHING);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static McMMOPlayerRepairCheckEvent callRepairCheckEvent(Player player, short durability, ItemStack repairMaterial, ItemStack repairedObject) {
|
|
|
|
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, durability, repairMaterial, repairedObject);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2014-08-17 05:04:19 +02:00
|
|
|
public static McMMOPlayerPreDeathPenaltyEvent callPreDeathPenaltyEvent(Player player) {
|
|
|
|
McMMOPlayerPreDeathPenaltyEvent event = new McMMOPlayerPreDeathPenaltyEvent(player);
|
2013-10-18 14:31:00 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static McMMOPlayerDisarmEvent callDisarmEvent(Player defender) {
|
|
|
|
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
2018-04-02 18:59:00 +02:00
|
|
|
|
|
|
|
public static McMMOPlayerSalvageCheckEvent callSalvageCheckEvent(Player player, ItemStack salvageMaterial, ItemStack salvageResults, ItemStack enchantedBook) {
|
|
|
|
McMMOPlayerSalvageCheckEvent event = new McMMOPlayerSalvageCheckEvent(player, salvageMaterial, salvageResults, enchantedBook);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
2019-01-09 04:52:52 +01:00
|
|
|
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
}
|