Player exp gain event

This commit is contained in:
Jules 2019-10-29 20:40:41 +01:00
parent b719d88a55
commit 75344e2b6f
2 changed files with 72 additions and 3 deletions

View File

@ -0,0 +1,63 @@
package net.Indyuce.mmocore.api.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
// if null, this is main experience
private final Profession profession;
private int experience;
private boolean cancelled;
public PlayerExperienceGainEvent(PlayerData player, int experience) {
this(player, null, experience);
}
public PlayerExperienceGainEvent(PlayerData player, Profession profession, int experience) {
super(player);
this.profession = profession;
this.experience = experience;
}
public int getExperience() {
return experience;
}
public void setExperience(int experience) {
this.experience = experience;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public boolean hasProfession() {
return profession != null;
}
public Profession getProfession() {
return profession;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -29,6 +29,7 @@ import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.api.event.PlayerCastSkillEvent;
import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
@ -392,8 +393,8 @@ public class PlayerData {
}
public void heal(double heal) {
double healAmount = Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
if(healAmount > 0) getPlayer().setHealth(healAmount);
getPlayer().setHealth(Math.max(0,
Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())));
}
public void addFriend(UUID uuid) {
@ -478,7 +479,12 @@ public class PlayerData {
value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;
experience += value;
PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, value);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
experience += event.getExperience();
int needed;
boolean check = false;