forked from Upstream/mmocore
fixed resource update events
This commit is contained in:
parent
e85ce8ea79
commit
baf8c468b5
@ -1,62 +0,0 @@
|
||||
package net.Indyuce.mmocore.api.event;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
|
||||
public class PlayerRegenResourceEvent extends PlayerDataEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/*
|
||||
* type of resource being regenerated. this way all three re
|
||||
*/
|
||||
private final PlayerResource resource;
|
||||
|
||||
/*
|
||||
* amount of resource regenerated. whole point of the event is to be able to
|
||||
* change it.
|
||||
*/
|
||||
private double amount;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerRegenResourceEvent(PlayerData playerData, PlayerResource resource, double amount) {
|
||||
super(playerData);
|
||||
|
||||
this.resource = resource;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public PlayerResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package net.Indyuce.mmocore.api.event;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerResourceUpdateEvent extends PlayerDataEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* Type of resource being regenerated, this way
|
||||
* this event handles all four resources.
|
||||
*/
|
||||
private final PlayerResource resource;
|
||||
private final UpdateReason reason;
|
||||
|
||||
/**
|
||||
* Amount of resource regenerated. The whole point of the event is
|
||||
* being able to modify it, for instance to apply the mana regeneration stat.
|
||||
*/
|
||||
private double amount;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Called when a player gains some resource back. This can
|
||||
* be used to handle stats like health or mana regeneration.
|
||||
* <p>
|
||||
* Example use: {@link net.Indyuce.mmocore.skill.Neptune_Gift} which is a skill
|
||||
* that temporarily increases resource regeneration for a short amount of time.
|
||||
*
|
||||
* @param playerData Player regenerating
|
||||
* @param resource Resource being increased
|
||||
* @param amount Amount being taken away/regenerated
|
||||
* @param reason The reason why this event was called
|
||||
*/
|
||||
public PlayerResourceUpdateEvent(PlayerData playerData, PlayerResource resource, double amount, UpdateReason reason) {
|
||||
super(playerData);
|
||||
|
||||
this.resource = resource;
|
||||
this.amount = amount;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public PlayerResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the amount of resource given/taken away
|
||||
*
|
||||
* @param amount New amount
|
||||
*/
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public enum UpdateReason {
|
||||
|
||||
/**
|
||||
* When resource is being regenerated
|
||||
*/
|
||||
REGENERATION,
|
||||
|
||||
/**
|
||||
* When some resource is gained, or consumed by some skills
|
||||
*/
|
||||
SKILL_REGENERATION,
|
||||
|
||||
/**
|
||||
* When some resource is gained, or consumed by some skills
|
||||
*/
|
||||
SKILL_COST,
|
||||
|
||||
/**
|
||||
* Used by quests triggers
|
||||
* - {@link net.Indyuce.mmocore.api.quest.trigger.ManaTrigger}
|
||||
* - {@link net.Indyuce.mmocore.api.quest.trigger.StaminaTrigger}
|
||||
* - {@link net.Indyuce.mmocore.api.quest.trigger.StelliumTrigger}
|
||||
*/
|
||||
TRIGGER,
|
||||
|
||||
/**
|
||||
* When using the resource command {@link net.Indyuce.mmocore.command.rpg.admin.ResourceCommandTreeNode}
|
||||
*/
|
||||
COMMAND,
|
||||
|
||||
/**
|
||||
* Anything else
|
||||
*/
|
||||
OTHER;
|
||||
|
||||
public boolean isSkill() {
|
||||
return this == SKILL_COST || this == SKILL_REGENERATION;
|
||||
}
|
||||
}
|
||||
}
|
@ -317,19 +317,30 @@ public class PlayerData extends OfflinePlayerData {
|
||||
lastLootChest = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Provide a heal reason with {@link #heal(double, PlayerResourceUpdateEvent.UpdateReason)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void heal(double heal) {
|
||||
this.heal(heal, PlayerResourceUpdateEvent.UpdateReason.OTHER);
|
||||
}
|
||||
|
||||
public void heal(double heal, PlayerResourceUpdateEvent.UpdateReason reason) {
|
||||
if (!isOnline())
|
||||
return;
|
||||
|
||||
// Avoid calling an useless event
|
||||
double newest = Math.max(0, Math.min(getPlayer().getHealth() + heal, getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||
if (getPlayer().getHealth() == newest)
|
||||
return;
|
||||
|
||||
PlayerRegenResourceEvent event = new PlayerRegenResourceEvent(this, PlayerResource.HEALTH, heal);
|
||||
PlayerResourceUpdateEvent event = new PlayerResourceUpdateEvent(this, PlayerResource.HEALTH, heal, reason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
getPlayer().setHealth(newest);
|
||||
// Use updated amount from event
|
||||
getPlayer().setHealth(getPlayer().getHealth() + event.getAmount());
|
||||
}
|
||||
|
||||
public void addFriend(UUID uuid) {
|
||||
@ -373,6 +384,12 @@ public class PlayerData extends OfflinePlayerData {
|
||||
MMOCore.plugin.requestManager.registerRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the player to a specific waypoint. This applies
|
||||
* the stellium waypoint cost and plays the teleport animation.
|
||||
*
|
||||
* @param waypoint Target waypoint
|
||||
*/
|
||||
public void warp(Waypoint waypoint) {
|
||||
if (!isOnline())
|
||||
return;
|
||||
@ -384,7 +401,7 @@ public class PlayerData extends OfflinePlayerData {
|
||||
*/
|
||||
lastWaypoint = System.currentTimeMillis();
|
||||
|
||||
giveStellium(-waypoint.getStelliumCost());
|
||||
giveStellium(-waypoint.getStelliumCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
|
||||
new BukkitRunnable() {
|
||||
final int x = getPlayer().getLocation().getBlockX();
|
||||
@ -399,7 +416,7 @@ public class PlayerData extends OfflinePlayerData {
|
||||
|| getPlayer().getLocation().getBlockZ() != z) {
|
||||
MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_CANCELLED);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(getPlayer());
|
||||
giveStellium(waypoint.getStelliumCost());
|
||||
giveStellium(waypoint.getStelliumCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
@ -501,44 +518,76 @@ public class PlayerData extends OfflinePlayerData {
|
||||
return profess == null ? MMOCore.plugin.classManager.getDefaultClass() : profess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Provide reason with {@link #giveMana(double, PlayerResourceUpdateEvent.UpdateReason)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void giveMana(double amount) {
|
||||
giveMana(amount, PlayerResourceUpdateEvent.UpdateReason.OTHER);
|
||||
}
|
||||
|
||||
public void giveMana(double amount, PlayerResourceUpdateEvent.UpdateReason reason) {
|
||||
|
||||
// Avoid calling useless event
|
||||
double newest = Math.max(0, Math.min(getStats().getStat(StatType.MAX_MANA), mana + amount));
|
||||
if (mana == newest)
|
||||
return;
|
||||
|
||||
PlayerRegenResourceEvent event = new PlayerRegenResourceEvent(this, PlayerResource.MANA, amount);
|
||||
PlayerResourceUpdateEvent event = new PlayerResourceUpdateEvent(this, PlayerResource.MANA, amount, reason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
mana = newest;
|
||||
// Use updated amount from Bukkit event
|
||||
setMana(mana + event.getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Provide reason with {@link #giveStamina(double, PlayerResourceUpdateEvent.UpdateReason)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void giveStamina(double amount) {
|
||||
giveStamina(amount, PlayerResourceUpdateEvent.UpdateReason.OTHER);
|
||||
}
|
||||
|
||||
public void giveStamina(double amount, PlayerResourceUpdateEvent.UpdateReason reason) {
|
||||
|
||||
// Avoid calling useless event
|
||||
double newest = Math.max(0, Math.min(getStats().getStat(StatType.MAX_STAMINA), stamina + amount));
|
||||
if (stamina == newest)
|
||||
return;
|
||||
|
||||
PlayerRegenResourceEvent event = new PlayerRegenResourceEvent(this, PlayerResource.STAMINA, amount);
|
||||
PlayerResourceUpdateEvent event = new PlayerResourceUpdateEvent(this, PlayerResource.STAMINA, amount, reason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
stamina = newest;
|
||||
|
||||
// Use updated amount from Bukkit event
|
||||
setStamina(stamina + event.getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Provide reason with {@link #giveStellium(double, PlayerResourceUpdateEvent.UpdateReason)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void giveStellium(double amount) {
|
||||
giveStellium(amount, PlayerResourceUpdateEvent.UpdateReason.OTHER);
|
||||
}
|
||||
|
||||
public void giveStellium(double amount, PlayerResourceUpdateEvent.UpdateReason reason) {
|
||||
|
||||
// Avoid calling useless event
|
||||
double newest = Math.max(0, Math.min(getStats().getStat(StatType.MAX_STELLIUM), stellium + amount));
|
||||
if (stellium == newest)
|
||||
return;
|
||||
|
||||
PlayerRegenResourceEvent event = new PlayerRegenResourceEvent(this, PlayerResource.STELLIUM, amount);
|
||||
PlayerResourceUpdateEvent event = new PlayerResourceUpdateEvent(this, PlayerResource.STELLIUM, amount, reason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
stellium = newest;
|
||||
// Use updated amount from Bukkit event
|
||||
setStellium(stellium + event.getAmount());
|
||||
}
|
||||
|
||||
public double getMana() {
|
||||
@ -794,8 +843,8 @@ public class PlayerData extends OfflinePlayerData {
|
||||
flatCooldownReduction *= flatCooldownReduction > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) * 1000 : 0;
|
||||
|
||||
skillData.setLastCast(cast.getSkill(), System.currentTimeMillis() - (long) flatCooldownReduction);
|
||||
giveMana(-cast.getManaCost());
|
||||
giveStamina(-cast.getStaminaCost());
|
||||
giveMana(-cast.getManaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
giveStamina(-cast.getStaminaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
}
|
||||
|
||||
PlayerPostCastSkillEvent postEvent = new PlayerPostCastSkillEvent(this, skill, cast);
|
||||
|
@ -1,36 +1,72 @@
|
||||
package net.Indyuce.mmocore.api.player.profess.resource;
|
||||
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
|
||||
public enum PlayerResource {
|
||||
|
||||
HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN, (data) -> data.getPlayer().getHealth(),
|
||||
(data) -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), PlayerData::heal),
|
||||
MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN, PlayerData::getMana,
|
||||
(data) -> data.getStats().getStat(StatType.MAX_MANA), PlayerData::giveMana),
|
||||
STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN, PlayerData::getStamina,
|
||||
(data) -> data.getStats().getStat(StatType.MAX_STAMINA), PlayerData::giveStamina),
|
||||
STELLIUM(StatType.STELLIUM_REGENERATION, ClassOption.OFF_COMBAT_STELLIUM_REGEN, PlayerData::getStellium,
|
||||
(data) -> data.getStats().getStat(StatType.MAX_STELLIUM), PlayerData::giveStellium);
|
||||
HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN,
|
||||
(data) -> data.getPlayer().getHealth(),
|
||||
data -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(),
|
||||
(data, amount) -> data.heal(amount, PlayerResourceUpdateEvent.UpdateReason.REGENERATION),
|
||||
(data, amount) -> data.heal(amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.heal(-amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.getPlayer().setHealth(amount)),
|
||||
|
||||
MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN,
|
||||
PlayerData::getMana,
|
||||
data -> data.getStats().getStat(StatType.MAX_MANA),
|
||||
(data, amount) -> data.giveMana(amount, PlayerResourceUpdateEvent.UpdateReason.REGENERATION),
|
||||
(data, amount) -> data.giveMana(amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.giveMana(-amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.setMana(amount)),
|
||||
|
||||
STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN,
|
||||
PlayerData::getStamina,
|
||||
data -> data.getStats().getStat(StatType.MAX_STAMINA),
|
||||
(data, amount) -> data.giveStamina(amount, PlayerResourceUpdateEvent.UpdateReason.REGENERATION),
|
||||
(data, amount) -> data.giveStamina(amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.giveStamina(-amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.setStamina(amount)),
|
||||
|
||||
STELLIUM(StatType.STELLIUM_REGENERATION, ClassOption.OFF_COMBAT_STELLIUM_REGEN,
|
||||
PlayerData::getStellium,
|
||||
data -> data.getStats().getStat(StatType.MAX_STELLIUM),
|
||||
(data, amount) -> data.giveStellium(amount, PlayerResourceUpdateEvent.UpdateReason.REGENERATION),
|
||||
(data, amount) -> data.giveStellium(amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.giveStellium(-amount, PlayerResourceUpdateEvent.UpdateReason.COMMAND),
|
||||
(data, amount) -> data.setStellium(amount));
|
||||
|
||||
private final StatType regenStat;
|
||||
private final ClassOption offCombatRegen;
|
||||
private final Function<PlayerData, Double> current, max;
|
||||
private final BiConsumer<PlayerData, Double> regen;
|
||||
|
||||
PlayerResource(StatType regenStat, ClassOption offCombatRegen, Function<PlayerData, Double> current, Function<PlayerData, Double> max, BiConsumer<PlayerData, Double> regen) {
|
||||
// Used for MMOCore commands
|
||||
private final BiConsumer<PlayerData, Double> set, give, take;
|
||||
|
||||
PlayerResource(StatType regenStat, ClassOption offCombatRegen,
|
||||
Function<PlayerData, Double> current,
|
||||
Function<PlayerData, Double> max,
|
||||
BiConsumer<PlayerData, Double> regen,
|
||||
BiConsumer<PlayerData, Double> give,
|
||||
BiConsumer<PlayerData, Double> take,
|
||||
BiConsumer<PlayerData, Double> set) {
|
||||
this.regenStat = regenStat;
|
||||
this.offCombatRegen = offCombatRegen;
|
||||
this.current = current;
|
||||
this.max = max;
|
||||
this.regen = regen;
|
||||
this.give = give;
|
||||
this.take = take;
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,13 +100,27 @@ public enum PlayerResource {
|
||||
|
||||
/**
|
||||
* Regens a player resource. Whatever resource, a bukkit event is triggered
|
||||
*
|
||||
* @param player
|
||||
* Player to regen
|
||||
* @param amount
|
||||
* Amount to regen
|
||||
*
|
||||
* @param player Player to regen
|
||||
* @param amount Amount to regen
|
||||
*/
|
||||
public void regen(PlayerData player, double amount) {
|
||||
regen.accept(player, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by MMOCore admin commands here: {@link net.Indyuce.mmocore.command.rpg.admin.ResourceCommandTreeNode}
|
||||
*/
|
||||
public BiConsumer<PlayerData, Double> getConsumer(ManaTrigger.Operation operation) {
|
||||
switch (operation) {
|
||||
case SET:
|
||||
return set;
|
||||
case TAKE:
|
||||
return take;
|
||||
case GIVE:
|
||||
return give;
|
||||
default:
|
||||
throw new IllegalArgumentException("Operation cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
|
||||
public class ManaTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
@ -19,23 +20,17 @@ public class ManaTrigger extends Trigger {
|
||||
@Override
|
||||
public void apply(PlayerData player) {
|
||||
|
||||
/*
|
||||
* give mana
|
||||
*/
|
||||
// Give mana
|
||||
if (operation == Operation.GIVE)
|
||||
player.giveMana(amount.calculate());
|
||||
player.giveMana(amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
|
||||
/*
|
||||
* set mana
|
||||
*/
|
||||
// Set mana
|
||||
else if (operation == Operation.SET)
|
||||
player.setMana(amount.calculate());
|
||||
|
||||
/*
|
||||
* take mana
|
||||
*/
|
||||
// Take mana
|
||||
else
|
||||
player.giveMana(-amount.calculate());
|
||||
player.giveMana(-amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
}
|
||||
|
||||
public enum Operation {
|
||||
|
@ -1,8 +1,10 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger.Operation;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
|
||||
public class StaminaTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
@ -19,28 +21,16 @@ public class StaminaTrigger extends Trigger {
|
||||
@Override
|
||||
public void apply(PlayerData player) {
|
||||
|
||||
/*
|
||||
* give mana
|
||||
*/
|
||||
// Give stamina
|
||||
if (operation == Operation.GIVE)
|
||||
player.giveStamina(amount.calculate());
|
||||
player.giveStamina(amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
|
||||
/*
|
||||
* set mana
|
||||
*/
|
||||
// Set stamina
|
||||
else if (operation == Operation.SET)
|
||||
player.setStamina(amount.calculate());
|
||||
|
||||
/*
|
||||
* take mana
|
||||
*/
|
||||
// Take stamina
|
||||
else
|
||||
player.giveStamina(-amount.calculate());
|
||||
}
|
||||
|
||||
public enum Operation {
|
||||
GIVE,
|
||||
SET,
|
||||
TAKE
|
||||
player.giveStamina(-amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger.Operation;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
|
||||
public class StelliumTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
@ -20,22 +21,16 @@ public class StelliumTrigger extends Trigger {
|
||||
@Override
|
||||
public void apply(PlayerData player) {
|
||||
|
||||
/*
|
||||
* give mana
|
||||
*/
|
||||
// Give stellium
|
||||
if (operation == Operation.GIVE)
|
||||
player.giveStellium(amount.calculate());
|
||||
player.giveStellium(amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
|
||||
/*
|
||||
* set mana
|
||||
*/
|
||||
// Set stellium
|
||||
else if (operation == Operation.SET)
|
||||
player.setStellium(amount.calculate());
|
||||
|
||||
/*
|
||||
* take mana
|
||||
*/
|
||||
// Take stellium
|
||||
else
|
||||
player.giveStellium(-amount.calculate());
|
||||
player.giveStellium(-amount.calculate(), PlayerResourceUpdateEvent.UpdateReason.TRIGGER);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public abstract class Trigger {
|
||||
private final long delay;
|
||||
@ -28,10 +27,10 @@ public abstract class Trigger {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, () -> apply(player), delay);
|
||||
}
|
||||
|
||||
/*
|
||||
* this method must not be used directly when executing triggers after quest
|
||||
/**
|
||||
* This method must not be used directly when executing triggers after quest
|
||||
* objectives for example, because this method does NOT take into account
|
||||
* trigger delay
|
||||
* trigger delay, {@link #schedule(PlayerData)} is used instead.
|
||||
*/
|
||||
public abstract void apply(PlayerData player);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class AdminCommandTreeNode extends CommandTreeNode {
|
||||
public AdminCommandTreeNode(CommandTreeNode parent) {
|
||||
@ -25,10 +25,8 @@ public class AdminCommandTreeNode extends CommandTreeNode {
|
||||
addChild(new PointsCommandTreeNode("attribute", this, PlayerData::setAttributePoints, PlayerData::giveAttributePoints, PlayerData::getAttributePoints));
|
||||
addChild(new PointsCommandTreeNode("attr-realloc", this, PlayerData::setAttributeReallocationPoints, PlayerData::giveAttributeReallocationPoints, PlayerData::getAttributeReallocationPoints));
|
||||
|
||||
addChild(new ResourceCommandTreeNode("health", this, (data, value) -> data.getPlayer().setHealth(value), PlayerData::heal, (data, value) -> data.heal(-value), (data) -> data.getPlayer().getHealth()));
|
||||
addChild(new ResourceCommandTreeNode("mana", this, PlayerData::setMana, PlayerData::giveMana, (data, value) -> data.giveMana(-value), PlayerData::getMana));
|
||||
addChild(new ResourceCommandTreeNode("stamina", this, PlayerData::setStamina, PlayerData::giveStamina, (data, value) -> data.giveStamina(-value), PlayerData::getStamina));
|
||||
addChild(new ResourceCommandTreeNode("stellium", this, PlayerData::setStellium, PlayerData::giveStellium, (data, value) -> data.giveStellium(-value), PlayerData::getStellium));
|
||||
for (PlayerResource res : PlayerResource.values())
|
||||
addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,38 +1,35 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode;
|
||||
import io.lumine.mythic.lib.mmolibcommands.api.Parameter;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger;
|
||||
import net.Indyuce.mmocore.command.CommandVerbose;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode;
|
||||
import io.lumine.mythic.lib.mmolibcommands.api.Parameter;
|
||||
|
||||
public class ResourceCommandTreeNode extends CommandTreeNode {
|
||||
private final String type;
|
||||
private final Function<PlayerData, Double> get;
|
||||
private final PlayerResource resource;
|
||||
|
||||
public ResourceCommandTreeNode(String type, CommandTreeNode parent, BiConsumer<PlayerData, Double> set, BiConsumer<PlayerData, Double> give,
|
||||
BiConsumer<PlayerData, Double> take, Function<PlayerData, Double> get) {
|
||||
public ResourceCommandTreeNode(String type, CommandTreeNode parent, PlayerResource resource) {
|
||||
super(parent, "resource-" + type);
|
||||
|
||||
this.type = type;
|
||||
this.get = get;
|
||||
this.resource = resource;
|
||||
|
||||
addChild(new ActionCommandTreeNode(this, "set", set));
|
||||
addChild(new ActionCommandTreeNode(this, "give", give));
|
||||
addChild(new ActionCommandTreeNode(this, "take", take));
|
||||
addChild(new ActionCommandTreeNode(this, "set", ManaTrigger.Operation.SET));
|
||||
addChild(new ActionCommandTreeNode(this, "give", ManaTrigger.Operation.GIVE));
|
||||
addChild(new ActionCommandTreeNode(this, "take", ManaTrigger.Operation.TAKE));
|
||||
}
|
||||
|
||||
public class ActionCommandTreeNode extends CommandTreeNode {
|
||||
private final BiConsumer<PlayerData, Double> action;
|
||||
private final ManaTrigger.Operation action;
|
||||
|
||||
public ActionCommandTreeNode(CommandTreeNode parent, String type, BiConsumer<PlayerData, Double> action) {
|
||||
public ActionCommandTreeNode(CommandTreeNode parent, String type, ManaTrigger.Operation action) {
|
||||
super(parent, type);
|
||||
|
||||
this.action = action;
|
||||
@ -61,10 +58,10 @@ public class ResourceCommandTreeNode extends CommandTreeNode {
|
||||
}
|
||||
|
||||
PlayerData data = PlayerData.get(player);
|
||||
action.accept(data, amount);
|
||||
resource.getConsumer(action).accept(data, amount);
|
||||
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESOURCE,
|
||||
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data)
|
||||
+ ChatColor.YELLOW + " " + type + " points.");
|
||||
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + resource.getCurrent(data)
|
||||
+ ChatColor.YELLOW + " " + type + " points.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerRegenResourceEvent;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
@ -19,7 +19,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@ -70,16 +69,20 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning: this really is not the best way to interface with MMOCore
|
||||
* generation. Use instead PlayerRegenResourceEvent to be able to access
|
||||
* directly the PlayerData without an extra map lookup.
|
||||
* Using the Bukkit health update event is not a good way of interacting
|
||||
* with MMOCore health regeneration. The PlayerResourceUpdateEvent
|
||||
* should be heavily prioritized if possible.
|
||||
* <p>
|
||||
* This method makes sure that all the plugins which utilize this event
|
||||
* can also communicate with MMOCore
|
||||
*/
|
||||
@Deprecated
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void g(PlayerRegenResourceEvent event) {
|
||||
public void g(PlayerResourceUpdateEvent event) {
|
||||
if (event.getResource() == PlayerResource.HEALTH) {
|
||||
EntityRegainHealthEvent bukkitEvent = new EntityRegainHealthEvent(event.getPlayer(), event.getAmount(), RegainReason.CUSTOM);
|
||||
Bukkit.getPluginManager().callEvent(bukkitEvent);
|
||||
|
||||
// Update event values
|
||||
event.setCancelled(bukkitEvent.isCancelled());
|
||||
event.setAmount(bukkitEvent.getAmount());
|
||||
}
|
||||
|
@ -1,24 +1,19 @@
|
||||
package net.Indyuce.mmocore.skill;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import io.lumine.mythic.lib.api.DamageType;
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.skill.Skill;
|
||||
import net.Indyuce.mmocore.api.skill.SkillResult;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||
import net.Indyuce.mmocore.api.util.math.particle.ParabolicProjectile;
|
||||
import io.lumine.mythic.lib.api.DamageType;
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Ambers extends Skill implements Listener {
|
||||
public Ambers() {
|
||||
@ -79,7 +74,7 @@ public class Ambers extends Skill implements Listener {
|
||||
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1, 1);
|
||||
// data.getSkillData().ambers++;
|
||||
data.giveMana((data.getStats().getStat(StatType.MAX_MANA) - data.getMana()) * percent);
|
||||
data.giveMana((data.getStats().getStat(StatType.MAX_MANA) - data.getMana()) * percent, PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION);
|
||||
|
||||
cancel();
|
||||
return;
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerRegenResourceEvent;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.skill.Skill;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||
@ -29,7 +29,7 @@ public class Neptune_Gift extends Skill implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(PlayerRegenResourceEvent event) {
|
||||
public void a(PlayerResourceUpdateEvent event) {
|
||||
PlayerData data = event.getData();
|
||||
if (event.getPlayer().getLocation().getBlock().getType() == Material.WATER) {
|
||||
Optional<SkillInfo> skill = data.getProfess().findSkill(this);
|
||||
|
Loading…
Reference in New Issue
Block a user