package com.yaohun.enderdragonwars.manager; import com.yaohun.enderdragonwars.effect.GiftEffect; import com.yaohun.enderdragonwars.effect.GiftQueue; import com.yaohun.enderdragonwars.effect.types.BomBomEffect; import com.yaohun.enderdragonwars.effect.types.ClearInventoryEffect; import org.bukkit.scheduler.BukkitTask; import java.util.HashMap; import java.util.Map; import java.util.function.Function; public class GiftEffectManager { private static Map> giftEffectMap = new HashMap<>(); private static Map giftQueues = new HashMap<>(); public static void addGiftEffect(String audience, String effectId) { GiftEffect giftEffect = giftEffectMap.get(effectId).apply(audience); GiftQueue giftQueue = giftQueues.getOrDefault(effectId, new GiftQueue(giftEffect.getQueueTime())); giftQueue.addEffect(giftEffect); giftQueues.put(effectId, giftQueue); } public static void stopQueue() { giftQueues.values().forEach(giftQueue -> { BukkitTask task = giftQueue.getTask(); if (task != null && !task.isCancelled()) { task.cancel(); } }); } public static GiftQueue getGiftQueue(String effectId) { return giftQueues.get(effectId); } public static Map getGiftQueues() { return giftQueues; } public static void registerAll() { registerGiftEffect("清理背包", ClearInventoryEffect::new); registerGiftEffect("火山喷发", BomBomEffect::new); } private static void registerGiftEffect(String id, Function giftEffectGetter) { giftEffectMap.put(id, giftEffectGetter); } }