mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Added McMMOPlayerVampirismEvent
Expands API possibilities regarding death penalty features.
This commit is contained in:
@ -28,6 +28,7 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerDeathPenaltyEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismPenaltyEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent;
|
||||
@ -163,6 +164,38 @@ public class EventUtils {
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public static boolean handleVampirismEvent(Player killer, Player victim, SkillType skillType, int levelsStolen, int xpStolen) {
|
||||
McMMOPlayerVampirismPenaltyEvent eventKiller = new McMMOPlayerVampirismPenaltyEvent(killer, skillType, levelsStolen, xpStolen);
|
||||
McMMOPlayerVampirismPenaltyEvent eventVictim = new McMMOPlayerVampirismPenaltyEvent(victim, skillType, -levelsStolen, -xpStolen);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventKiller);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventVictim);
|
||||
|
||||
boolean isCancelled = eventKiller.isCancelled() || eventVictim.isCancelled();
|
||||
|
||||
if (!isCancelled) {
|
||||
McMMOPlayer killerPlayer = UserManager.getPlayer(killer);
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
|
||||
|
||||
killerPlayer.addLevels(skillType, eventKiller.getLevelChanged());
|
||||
killerPlayer.beginUnsharedXpGain(skillType, eventKiller.getExperienceChanged(), XPGainReason.VAMPIRISM);
|
||||
|
||||
// For victims McMMOPlayerVampirismPenaltyEvent is fired with negative levels changed and XP changed
|
||||
victimProfile.modifySkill(skillType, victimSkillLevel + eventVictim.getLevelChanged());
|
||||
victimProfile.removeXp(skillType, (int) - eventVictim.getExperienceChanged());
|
||||
|
||||
if (victimProfile.getSkillXpLevel(skillType) < 0) {
|
||||
victimProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
|
||||
if (victimProfile.getSkillLevel(skillType) < 0) {
|
||||
victimProfile.modifySkill(skillType, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, AbilityType ability) {
|
||||
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, SkillType.byAbility(ability));
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
@ -191,8 +224,8 @@ public class EventUtils {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static McMMOPlayerDeathPenaltyEvent callDeathPenaltyEvent(Player player) {
|
||||
McMMOPlayerDeathPenaltyEvent event = new McMMOPlayerDeathPenaltyEvent(player);
|
||||
public static McMMOPlayerDeathPenaltyEvent callDeathPenaltyEvent(Player player, SkillType skill) {
|
||||
McMMOPlayerDeathPenaltyEvent event = new McMMOPlayerDeathPenaltyEvent(player, skill);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return event;
|
||||
|
@ -3,10 +3,8 @@ package com.gmail.nossr50.util;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -57,8 +55,7 @@ public final class HardcoreManager {
|
||||
double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
|
||||
int levelThreshold = Config.getInstance().getHardcoreVampirismLevelThreshold();
|
||||
|
||||
McMMOPlayer killerPlayer = UserManager.getPlayer(killer);
|
||||
PlayerProfile killerProfile = killerPlayer.getProfile();
|
||||
PlayerProfile killerProfile = UserManager.getPlayer(killer).getProfile();
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
int totalLevelsStolen = 0;
|
||||
|
||||
@ -80,20 +77,8 @@ public final class HardcoreManager {
|
||||
int levelsStolen = (int) statsStolen;
|
||||
int xpStolen = (int) Math.floor(victimSkillXpLevel * (statsStolen - levelsStolen));
|
||||
|
||||
totalLevelsStolen += levelsStolen;
|
||||
|
||||
killerPlayer.addLevels(skillType, levelsStolen);
|
||||
killerPlayer.beginUnsharedXpGain(skillType, xpStolen, XPGainReason.VAMPIRISM);
|
||||
|
||||
victimProfile.modifySkill(skillType, victimSkillLevel - levelsStolen);
|
||||
victimProfile.removeXp(skillType, xpStolen);
|
||||
|
||||
if (victimProfile.getSkillXpLevel(skillType) < 0) {
|
||||
victimProfile.setSkillXpLevel(skillType, 0);
|
||||
}
|
||||
|
||||
if (victimProfile.getSkillLevel(skillType) < 0) {
|
||||
victimProfile.modifySkill(skillType, 0);
|
||||
if (EventUtils.handleVampirismEvent(killer, victim, skillType, levelsStolen, xpStolen)) {
|
||||
totalLevelsStolen += levelsStolen;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user