Experience PreGain event

This commit is contained in:
Shane Freeder 2020-10-25 14:43:33 +00:00
parent 556515eefd
commit 67a4b6c7c1
2 changed files with 57 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.experience.McMMOPlayerPreXpGainEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
@ -56,6 +57,8 @@ import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.block.Block;
@ -601,6 +604,10 @@ public class McMMOPlayer implements Identified {
return;
}
final McMMOPlayerPreXpGainEvent mcMMOPlayerPreXpGainEvent = new McMMOPlayerPreXpGainEvent(player, primarySkillType, xp, xpGainReason);
Bukkit.getPluginManager().callEvent(mcMMOPlayerPreXpGainEvent);
xp = mcMMOPlayerPreXpGainEvent.getXpGained();
if (primarySkillType.isChildSkill()) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(primarySkillType);

View File

@ -0,0 +1,50 @@
package com.gmail.nossr50.events.experience;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player gains XP in a skill
*/
public class McMMOPlayerPreXpGainEvent extends McMMOPlayerExperienceEvent {
private float xpGained;
@Deprecated
public McMMOPlayerPreXpGainEvent(Player player, PrimarySkillType skill, float xpGained) {
super(player, skill, XPGainReason.UNKNOWN);
this.xpGained = xpGained;
}
public McMMOPlayerPreXpGainEvent(Player player, PrimarySkillType skill, float xpGained, XPGainReason xpGainReason) {
super(player, skill, xpGainReason);
this.xpGained = xpGained;
}
/**
* @return int amount of experience gained in this event
*/
public int getXpGained() {
return (int) xpGained;
}
/**
* @param xpGained int amount of experience gained in this event
*/
public void setXpGained(int xpGained) {
this.xpGained = xpGained;
}
private static final HandlerList handlers = new HandlerList();
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}