Initial commit
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package net.crankedpvp.crankedutils.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.crankedutils.CrankedUtils;
|
||||
import net.crankedpvp.crankedutils.potion.PotionCache;
|
||||
import net.crankedpvp.crankedutils.potion.PotionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class PotionEffectUtils implements Listener {
|
||||
|
||||
private static final PotionManager potionManager = CrankedUtils.getInstance().getPotionManager();
|
||||
|
||||
private PotionEffectUtils() {
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static final Set<PotionEffectType> debuffsList = new HashSet<>(Arrays.asList(
|
||||
PotionEffectType.BLINDNESS,
|
||||
PotionEffectType.CONFUSION,
|
||||
PotionEffectType.HARM,
|
||||
PotionEffectType.SLOW,
|
||||
PotionEffectType.SLOW_DIGGING,
|
||||
PotionEffectType.WEAKNESS,
|
||||
PotionEffectType.WITHER,
|
||||
PotionEffectType.POISON
|
||||
));
|
||||
|
||||
public static void bless(Player player) {
|
||||
List<String> idsToRemove = new ArrayList<>();
|
||||
for (PotionCache potionCache : potionManager.getCrankedPotionPlayer(player.getUniqueId()).getPotionCacheMap().values()) {
|
||||
if (getDebuffsList().contains(potionCache.getType())) {
|
||||
idsToRemove.add(potionCache.getId());
|
||||
}
|
||||
}
|
||||
|
||||
for (String id : idsToRemove) {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).removePotionEffect(id);
|
||||
}
|
||||
|
||||
//Just to make sure we didn't miss one
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
|
||||
if (getDebuffsList().contains(potionEffect.getType())) {
|
||||
player.removePotionEffect(potionEffect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addPotionEffect(Player player, PotionEffectType type, int level, String id, int durationInSeconds) {
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), () -> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).addPotionEffect(type, level, durationInSeconds * 20, id);
|
||||
}, 1L);
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), ()-> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).removePotionEffect(id);
|
||||
}, (durationInSeconds* 20L) + 1);
|
||||
}
|
||||
|
||||
//This means, if player already has enchant x, it will add y to the level
|
||||
public static void addExtraPotionEffect(Player player, PotionEffectType type, int level, String id, int durationInSeconds) {
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), () -> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).addExtraPotionEffect(type, level, durationInSeconds * 20, id);
|
||||
}, 1L);
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), ()-> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).removePotionEffect(id);
|
||||
}, (durationInSeconds* 20L) + 1);
|
||||
}
|
||||
|
||||
//This means, if player already has enchant x, it will add y to the level
|
||||
public static void addExtraPotionEffect(Player player, PotionEffectType type, int level, String id) {
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), () -> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).addExtraPotionEffect(type, level, Integer.MAX_VALUE, id);
|
||||
}, 1L);
|
||||
|
||||
}
|
||||
|
||||
public static void addPotionEffect(Player player, PotionEffectType type, int level, String id) {
|
||||
Bukkit.getScheduler().runTaskLater(CrankedUtils.getInstance(), () -> {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).addPotionEffect(type, level, id);
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
public static int getPlayerEffectLevel(Player player, PotionEffectType type) {
|
||||
for (PotionCache potionCache : potionManager.getCrankedPotionPlayer(player.getUniqueId()).getPotionCacheMap().values()) {
|
||||
if (potionCache.getType() == type) {
|
||||
return potionCache.getLevel();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean hasPotionEffect(Player player, String string) {
|
||||
for(PotionCache value : potionManager.getCrankedPotionPlayer(player.getUniqueId()).getPotionCacheMap().values()) {
|
||||
if(value.getId().equals(string)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void removePotionEffect(Player player, String id) {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).removePotionEffect(id);
|
||||
}
|
||||
|
||||
|
||||
public static void clearPlayerEffects(Player player) {
|
||||
potionManager.getCrankedPotionPlayer(player.getUniqueId()).clearEffects();
|
||||
player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user