Untitled
unknown
plain_text
a year ago
2.5 kB
4
Indexable
import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import java.util.HashMap; import java.util.Map; public class PotionEffectMemoryPlugin extends JavaPlugin implements Listener { private Map<Player, SavedPotionEffect> playerEffects; @Override public void onEnable() { playerEffects = new HashMap<>(); getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerConsume(PlayerItemConsumeEvent event) { Player player = event.getPlayer(); for (PotionEffect effect : player.getActivePotionEffects()) { if (effect.getType().equals(PotionEffectType.INCREASE_DAMAGE)) { SavedPotionEffect currentEffect = new SavedPotionEffect(effect.getType(), effect.getAmplifier(), effect.getDuration()); SavedPotionEffect previousEffect = playerEffects.get(player); if (previousEffect == null || currentEffect.getAmplifier() > previousEffect.getAmplifier()) { playerEffects.put(player, currentEffect); } } } } // Метод для применения сохраненного эффекта к игроку private void applySavedEffect(Player player) { SavedPotionEffect savedEffect = playerEffects.get(player); if (savedEffect != null) { player.addPotionEffect(new PotionEffect(savedEffect.getType(), savedEffect.getDuration(), savedEffect.getAmplifier())); } } // Вспомогательный класс для сохранения информации о зелье private static class SavedPotionEffect { private final PotionEffectType type; private final int amplifier; private final int duration; public SavedPotionEffect(PotionEffectType type, int amplifier, int duration) { this.type = type; this.amplifier = amplifier; this.duration = duration; } public PotionEffectType getType() { return type; } public int getAmplifier() { return amplifier; } public int getDuration() { return duration; } } }
Editor is loading...
Leave a Comment