!Added method to StatInstance to easily register temp stats

This commit is contained in:
Indyuce 2019-12-22 15:14:05 +01:00
parent 598aaa3ab3
commit 0ca82a0a2d
3 changed files with 10 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import java.util.Set;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.stat.modifier.StatModifier;
import net.Indyuce.mmocore.api.player.stats.stat.modifier.TemporaryStatModifier;
public class PlayerStats {
private final PlayerData data;
@ -101,6 +102,10 @@ public class PlayerStats {
addModifier(key, new StatModifier(value));
}
public void applyTemporaryModifier(String key, StatModifier modifier, long duration) {
addModifier(key, new TemporaryStatModifier(modifier.getValue(), duration, modifier.isRelative(), key, this));
}
public void addModifier(String key, StatModifier modifier) {
map.put(key, modifier);

View File

@ -8,7 +8,6 @@ public class StatModifier {
private final double d;
private final boolean relative;
public StatModifier(double d) {
this(d, false);
}
@ -33,6 +32,10 @@ public class StatModifier {
public boolean isRelative() {
return relative;
}
public double getValue() {
return d;
}
public double apply(double in) {
return relative ? in * (1 + d / 100) : in + d;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmocore.api.player.stats.PlayerStats.StatInstance;
public class TemporaryStatModifier extends StatModifier {
private final BukkitRunnable runnable;
public TemporaryStatModifier(double d, long duration, boolean relative, String key, StatInstance ins) {
super(d, relative);