Add new McMMOPlayerXpLossEvent

This commit is contained in:
GJ 2013-10-21 09:34:16 -04:00 committed by TfT_02
parent fdaa42edd3
commit d0a1d44fa2
6 changed files with 51 additions and 10 deletions

View File

@ -528,7 +528,7 @@ public class McMMOPlayer {
return;
}
if (!EventUtils.handleXpGainEvent(player, skillType, xp)) {
if (!EventUtils.handleXpChangeEvent(player, skillType, xp, true)) {
return;
}

View File

@ -0,0 +1,11 @@
package com.gmail.nossr50.events.experience;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.SkillType;
public abstract class McMMOPlayerXpChangeEvent extends McMMOPlayerExperienceEvent {
public McMMOPlayerXpChangeEvent(Player player, SkillType skill) {
super(player, skill);
}
}

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
/**
* Called when a player gains XP in a skill
*/
public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent {
public class McMMOPlayerXpGainEvent extends McMMOPlayerXpChangeEvent {
private float xpGained;
public McMMOPlayerXpGainEvent(Player player, SkillType skill, float xpGained) {
@ -31,7 +31,7 @@ public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent {
}
/**
* @param xpGained int amount of experience gained in this event
* @param xpGained float amount of experience gained in this event
*/
public void setRawXpGained(float xpGained) {
this.xpGained = xpGained;

View File

@ -0,0 +1,28 @@
package com.gmail.nossr50.events.experience;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.skills.SkillType;
public class McMMOPlayerXpLossEvent extends McMMOPlayerXpChangeEvent {
private float xpLost;
public McMMOPlayerXpLossEvent(Player player, SkillType skill, float xpLost) {
super(player, skill);
this.xpLost = xpLost;
}
/**
* @return The amount of experience lost in this event
*/
public float getRawXpLost() {
return xpLost;
}
/**
* @param xpLost amount of experience lost in this event
*/
public void setRawXpLost(float xpLost) {
this.xpLost = xpLost;
}
}

View File

@ -18,7 +18,9 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelChangeEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpChangeEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpLossEvent;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
@ -108,14 +110,15 @@ public class EventUtils {
mcMMOPlayer.getPartyTeleportRecord().actualizeLastUse();
}
public static boolean handleXpGainEvent(Player player, SkillType skill, float xpGained) {
McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained);
public static boolean handleXpChangeEvent(Player player, SkillType skill, float xpChanged, boolean isXpGain) {
McMMOPlayerXpChangeEvent event = isXpGain ? new McMMOPlayerXpGainEvent(player, skill, xpChanged) : new McMMOPlayerXpLossEvent(player, skill, xpChanged);
mcMMO.p.getServer().getPluginManager().callEvent(event);
boolean isCancelled = event.isCancelled();
if (!isCancelled) {
UserManager.getPlayer(player).addXp(skill, event.getRawXpGained());
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
profile.setSkillXpLevel(skill, profile.getSkillXpLevelRaw(skill) + (isXpGain ? ((McMMOPlayerXpGainEvent) event).getRawXpGained() : -((McMMOPlayerXpLossEvent) event).getRawXpLost()));
}
return !isCancelled;

View File

@ -77,13 +77,12 @@ public final class HardcoreManager {
EventUtils.handleLevelChangeEvent(killer, skillType, levelsStolen, killerXpRemoved, true);
killerProfile.addXp(skillType, xpStolen);
EventUtils.handleXpGainEvent(killer, skillType, xpStolen);
EventUtils.handleXpChangeEvent(killer, skillType, xpStolen, true);
float victimXpRemoved = killerProfile.getSkillXpLevelRaw(skillType);
victimProfile.modifySkill(skillType, victimSkillLevel - levelsStolen);
victimProfile.removeXp(skillType, xpStolen);
EventUtils.handleLevelChangeEvent(victim, skillType, levelsStolen, victimXpRemoved + xpStolen, false);
EventUtils.handleLevelChangeEvent(victim, skillType, levelsStolen, victimXpRemoved, false);
EventUtils.handleXpChangeEvent(killer, skillType, xpStolen, false);
}
if (totalLevelsStolen > 0) {