Divided PlayerCastSkillEvent into a Pre and Post event

If you're a dev and used the PlayerCastSkillEvent,
please use the PlayerPreCastSkillEvent
This commit is contained in:
ASangarin 2020-07-31 20:57:12 +02:00
parent b2699ef313
commit 3419a2ef09
3 changed files with 55 additions and 6 deletions

View File

@ -0,0 +1,44 @@
package net.Indyuce.mmocore.api.event;
import org.bukkit.event.HandlerList;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.api.skill.SkillResult;
public class PlayerPostCastSkillEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
private final SkillInfo skill;
private final SkillResult result;
private final boolean successful;
public PlayerPostCastSkillEvent(PlayerData playerData, SkillInfo skill, SkillResult result, boolean successful) {
super(playerData);
this.skill = skill;
this.result = result;
this.successful = successful;
}
public SkillInfo getCast() {
return skill;
}
public SkillResult getResult() {
return result;
}
public boolean wasSuccessful() {
return successful;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -6,14 +6,14 @@ import org.bukkit.event.HandlerList;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
public class PlayerCastSkillEvent extends PlayerDataEvent implements Cancellable {
public class PlayerPreCastSkillEvent extends PlayerDataEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final SkillInfo skill;
private boolean cancelled;
public PlayerCastSkillEvent(PlayerData playerData, SkillInfo skill) {
public PlayerPreCastSkillEvent(PlayerData playerData, SkillInfo skill) {
super(playerData);
this.skill = skill;

View File

@ -25,9 +25,10 @@ import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
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.event.PlayerPostCastSkillEvent;
import net.Indyuce.mmocore.api.event.PlayerPreCastSkillEvent;
import net.Indyuce.mmocore.api.event.PlayerRegenResourceEvent;
import net.Indyuce.mmocore.api.experience.EXPSource;
import net.Indyuce.mmocore.api.experience.PlayerProfessions;
@ -716,9 +717,9 @@ public class PlayerData extends OfflinePlayerData {
public SkillResult cast(SkillInfo skill) {
PlayerCastSkillEvent event = new PlayerCastSkillEvent(this, skill);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
PlayerPreCastSkillEvent preEvent = new PlayerPreCastSkillEvent(this, skill);
Bukkit.getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled())
return new SkillResult(this, skill, CancelReason.OTHER);
/*
@ -739,6 +740,8 @@ public class PlayerData extends OfflinePlayerData {
MMOCore.plugin.configManager.getSimpleMessage("casting.on-cooldown").send(getPlayer());
}
PlayerPostCastSkillEvent postEvent = new PlayerPostCastSkillEvent(this, skill, cast, false);
Bukkit.getPluginManager().callEvent(postEvent);
return cast;
}
@ -750,6 +753,8 @@ public class PlayerData extends OfflinePlayerData {
giveMana(-cast.getManaCost());
}
PlayerPostCastSkillEvent postEvent = new PlayerPostCastSkillEvent(this, skill, cast, true);
Bukkit.getPluginManager().callEvent(postEvent);
return cast;
}