From 0ca82a0a2df119494f5030db6d663cbc77516aae Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 22 Dec 2019 15:14:05 +0100 Subject: [PATCH] !Added method to StatInstance to easily register temp stats --- .../net/Indyuce/mmocore/api/player/stats/PlayerStats.java | 5 +++++ .../mmocore/api/player/stats/stat/modifier/StatModifier.java | 5 ++++- .../player/stats/stat/modifier/TemporaryStatModifier.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java b/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java index 71359cf5..c0a720b2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/stats/PlayerStats.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/StatModifier.java b/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/StatModifier.java index 4032cf98..ade41db6 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/StatModifier.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/StatModifier.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/TemporaryStatModifier.java b/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/TemporaryStatModifier.java index 1c484071..5878b4a9 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/TemporaryStatModifier.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/stats/stat/modifier/TemporaryStatModifier.java @@ -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);