Search in sources :

Example 1 with Beacon

use of org.bukkit.block.Beacon in project Glowstone by GlowstoneMC.

the class BeaconEntity method applyPotionEffects.

private void applyPotionEffects() {
    Beacon beacon = (Beacon) getBlock().getState();
    beacon.getEntitiesInRange().forEach(livingEntity -> {
        for (BeaconEffectPriority priority : BeaconEffectPriority.values()) {
            PotionEffect effect = this.getEffect(priority);
            if (effect == null) {
                continue;
            }
            BeaconEffectEvent event = new BeaconEffectEvent(block, effect, (Player) livingEntity, priority == BeaconEffectPriority.PRIMARY);
            if (!EventFactory.getInstance().callEvent(event).isCancelled()) {
                livingEntity.addPotionEffect(event.getEffect(), true);
            }
        }
    });
}
Also used : BeaconEffectEvent(com.destroystokyo.paper.event.block.BeaconEffectEvent) PotionEffect(org.bukkit.potion.PotionEffect) Beacon(org.bukkit.block.Beacon) GlowBeacon(net.glowstone.block.entity.state.GlowBeacon)

Example 2 with Beacon

use of org.bukkit.block.Beacon in project Glowstone by GlowstoneMC.

the class GlowBeaconInventory method setActiveEffects.

public void setActiveEffects(int primaryId, int secondaryId) {
    if (!ALLOWED_MATERIALS.contains(getItem().getType())) {
        return;
    }
    PotionEffectType primaryType = PotionEffectType.getById(primaryId);
    if (primaryType != null) {
        ((Beacon) getHolder()).setPrimaryEffect(primaryType);
    }
    PotionEffectType secondaryType = PotionEffectType.getById(secondaryId);
    if (secondaryType != null) {
        ((Beacon) getHolder()).setSecondaryEffect(secondaryType);
    }
    getItem().add(-1);
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) Beacon(org.bukkit.block.Beacon)

Aggregations

Beacon (org.bukkit.block.Beacon)2 BeaconEffectEvent (com.destroystokyo.paper.event.block.BeaconEffectEvent)1 GlowBeacon (net.glowstone.block.entity.state.GlowBeacon)1 PotionEffect (org.bukkit.potion.PotionEffect)1 PotionEffectType (org.bukkit.potion.PotionEffectType)1