mirror of
https://github.com/SimplexDevelopment/ArcanumOcculta.git
synced 2025-07-03 06:26:40 +00:00
API completed, Implementation required (#1)
New API, ready to go. Implementations required.
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
package app.simplexdev.arcanumocculta.cooldown;
|
||||
|
||||
import app.simplexdev.arcanumocculta.api.caster.Caster;
|
||||
import app.simplexdev.arcanumocculta.api.spell.Spell;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CooldownService
|
||||
{
|
||||
private final Map<Caster, List<CooldownStatus>> cooldowns = new HashMap<>();
|
||||
|
||||
public void tick()
|
||||
{
|
||||
cooldowns.forEach((c, sl) -> {
|
||||
sl.removeIf(CooldownStatus::hasExpired);
|
||||
|
||||
if (sl.isEmpty()) cooldowns.remove(c);
|
||||
});
|
||||
}
|
||||
|
||||
public void include(final Caster caster, final CooldownStatus status)
|
||||
{
|
||||
List<CooldownStatus> statuses = cooldowns.get(caster);
|
||||
if (status == null) statuses = new ArrayList<>();
|
||||
|
||||
statuses.add(status);
|
||||
cooldowns.put(caster, statuses);
|
||||
}
|
||||
|
||||
public void exclude(final CooldownStatus status)
|
||||
{
|
||||
cooldowns.forEach((c, sl) -> sl.removeIf(s -> s.getSpellUUID().equals(status.getSpellUUID())));
|
||||
}
|
||||
|
||||
public boolean isOnCooldown(final Spell spell)
|
||||
{
|
||||
tick();
|
||||
return cooldowns.values()
|
||||
.stream()
|
||||
.flatMap(List::stream)
|
||||
.anyMatch(status -> status.getSpellUUID().equals(spell.getUniqueId()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user