!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.PlayerData;
import net.Indyuce.mmocore.api.player.stats.stat.modifier.StatModifier; import net.Indyuce.mmocore.api.player.stats.stat.modifier.StatModifier;
import net.Indyuce.mmocore.api.player.stats.stat.modifier.TemporaryStatModifier;
public class PlayerStats { public class PlayerStats {
private final PlayerData data; private final PlayerData data;
@ -101,6 +102,10 @@ public class PlayerStats {
addModifier(key, new StatModifier(value)); 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) { public void addModifier(String key, StatModifier modifier) {
map.put(key, modifier); map.put(key, modifier);

View File

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