Search in sources :

Example 26 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project RedProtect by FabioZumbi12.

the class RPPlayerListener method PlayerTrownPotion.

@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerTrownPotion(LaunchProjectileEvent e) {
    Entity ent = e.getTargetEntity();
    RedProtect.get().logger.debug("player", "Is PotionSplashEvent event.");
    Region r = RedProtect.get().rm.getTopRegion(ent.getLocation());
    if (ent instanceof ThrownPotion) {
        ThrownPotion potion = (ThrownPotion) e.getTargetEntity();
        ProjectileSource thrower = potion.getShooter();
        if (thrower instanceof Player) {
            if (r != null && !r.usePotions((Player) thrower)) {
                RPLang.sendMessage((Player) thrower, "playerlistener.region.cantuse");
                e.setCancelled(true);
                return;
            }
        }
        List<PotionEffect> pottypes = potion.get(Keys.POTION_EFFECTS).get();
        // deny potion
        List<String> Pots = RedProtect.get().cfgs.getStringList("server-protection.deny-potions");
        for (PotionEffect t : pottypes) {
            if (Pots.size() > 0 && Pots.contains(t.getType().getName().toUpperCase())) {
                e.setCancelled(true);
                if (thrower instanceof Player) {
                    RPLang.sendMessage((Player) thrower, RPLang.get("playerlistener.denypotion"));
                }
                return;
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Example 27 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeAPI by SpongePowered.

the class ApplicableEffectProperty method compareTo.

@Override
public int compareTo(Property<?, ?> o) {
    if (o instanceof ApplicableEffectProperty) {
        ApplicableEffectProperty effect = (ApplicableEffectProperty) o;
        Set<PotionEffect> set = Sets.newHashSet(effect.getValue() == null ? new HashSet<>() : effect.getValue());
        Set<PotionEffect> thisSet = this.getValue() == null ? new HashSet<>() : this.getValue();
        for (PotionEffect effect1 : thisSet) {
            if (set.contains(effect1)) {
                set.remove(effect1);
            } else {
                return 1;
            }
        }
        return set.size() > 0 ? -set.size() : 0;
    }
    return this.getClass().getName().compareTo(o.getClass().getName());
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) HashSet(java.util.HashSet)

Example 28 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project Skree by Skelril.

the class WildernessWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event, int level) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender) {
            if (allowsPvP(level)) {
                return;
            }
            Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
            if (optService.isPresent()) {
                PvPService service = optService.get();
                if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
                    return;
                }
            }
            attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this part of the Wilderness!"));
            attacker.sendMessage(Text.of(TextColors.RED, "Mandatory PvP is from level ", getFirstPvPLevel(), " and on."));
            event.setCancelled(true);
        }

        @Override
        public void processMonsterAttack(Living attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            DamageEntityEvent dEvent = (DamageEntityEvent) event;
            // If they're endermites they hit through armor, otherwise they get a damage boost
            if (attacker.getType() == EntityTypes.ENDERMITE) {
                for (DamageFunction modifier : dEvent.getModifiers()) {
                    dEvent.setDamage(modifier.getModifier(), (a) -> 0D);
                }
                dEvent.setBaseDamage(Probability.getCompoundRandom(getDamageMod(level), 3));
                if (Probability.getChance(5)) {
                    List<PotionEffect> potionEffects = defender.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>());
                    potionEffects.add(PotionEffect.of(PotionEffectTypes.POISON, 2, 30 * 20));
                    defender.offer(Keys.POTION_EFFECTS, potionEffects);
                }
            } else {
                dEvent.setBaseDamage(dEvent.getBaseDamage() + getDamageMod(level));
            }
            // Only apply scoring while in survival mode
            if (defender.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(defender.getUniqueId());
            if (meta != null) {
                meta.hit();
            }
        }

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            Task.builder().delayTicks(1).execute(() -> healthPrinter.print(MessageChannel.fixed(attacker), defender)).submit(SkreePlugin.inst());
            if (!(defender instanceof Monster) || defender instanceof Creeper) {
                return;
            }
            // Only apply scoring while in survival mode
            if (attacker.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(attacker.getUniqueId());
            if (meta != null) {
                meta.attack();
                if (meta.getRatio() > 30 && meta.getFactors() > 35) {
                    Deque<Entity> spawned = new ArrayDeque<>();
                    for (int i = Probability.getRandom(5); i > 0; --i) {
                        Entity entity = attacker.getWorld().createEntity(EntityTypes.ENDERMITE, defender.getLocation().getPosition());
                        entity.getWorld().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                        spawned.add(entity);
                    }
                    IntegratedRunnable runnable = new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            Entity mob = spawned.poll();
                            if (mob.isLoaded() && mob.getWorld().equals(attacker.getWorld())) {
                                mob.setLocation(attacker.getLocation());
                            }
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    };
                    TimedRunnable timedRunnable = new TimedRunnable<>(runnable, spawned.size());
                    timedRunnable.setTask(Task.builder().execute(timedRunnable).delayTicks(40).intervalTicks(20).submit(SkreePlugin.inst()));
                }
                if (System.currentTimeMillis() - meta.getLastReset() >= TimeUnit.MINUTES.toMillis(5)) {
                    meta.reset();
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Living(org.spongepowered.api.entity.living.Living) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TimedRunnable(com.skelril.nitro.time.TimedRunnable) PvPService(com.skelril.skree.service.PvPService) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) Monster(org.spongepowered.api.entity.living.monster.Monster) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 29 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class SpongePotionBuilder method buildContent.

@Override
protected Optional<PotionEffect> buildContent(final DataView container) throws InvalidDataException {
    checkNotNull(container);
    if (!container.contains(Constants.Item.Potions.POTION_TYPE) || !container.contains(Constants.Item.Potions.POTION_DURATION) || !container.contains(Constants.Item.Potions.POTION_AMPLIFIER) || !container.contains(Constants.Item.Potions.POTION_AMBIANCE) || !container.contains(Constants.Item.Potions.POTION_SHOWS_PARTICLES)) {
        return Optional.empty();
    }
    final String effectName = container.getString(Constants.Item.Potions.POTION_TYPE).get();
    final Optional<PotionEffectType> optional = Sponge.game().registry(RegistryTypes.POTION_EFFECT_TYPE).findValue(ResourceKey.resolve(effectName));
    if (!optional.isPresent()) {
        throw new InvalidDataException("The container has an invalid potion type name: " + effectName);
    }
    final Ticks duration = Ticks.of(container.getInt(Constants.Item.Potions.POTION_DURATION).get());
    final int amplifier = container.getInt(Constants.Item.Potions.POTION_AMPLIFIER).get();
    final boolean ambience = container.getBoolean(Constants.Item.Potions.POTION_AMBIANCE).get();
    final boolean particles = container.getBoolean(Constants.Item.Potions.POTION_SHOWS_PARTICLES).get();
    final PotionEffect.Builder builder = new SpongePotionBuilder();
    return Optional.of(builder.potionType(optional.get()).showParticles(particles).duration(duration).amplifier(amplifier).ambient(ambience).build());
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) Ticks(org.spongepowered.api.util.Ticks) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException)

Example 30 with PotionEffect

use of org.spongepowered.api.effect.potion.PotionEffect in project SpongeCommon by SpongePowered.

the class PotionItemStackData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.COLOR).get(h -> Color.ofRgb(PotionUtils.getColor(h))).set((h, v) -> {
        final CompoundTag tag = h.getOrCreateTag();
        tag.putInt(Constants.Item.CUSTOM_POTION_COLOR, v.rgb());
    }).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_COLOR)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION).create(Keys.POTION_EFFECTS).get(h -> {
        final List<MobEffectInstance> effects = PotionUtils.getMobEffects(h);
        return effects.isEmpty() ? null : ImmutableList.copyOf((List<PotionEffect>) (Object) effects);
    }).set((h, v) -> {
        final CompoundTag tag = h.getOrCreateTag();
        final ListTag list = v.stream().map(effect -> {
            final CompoundTag potionTag = new CompoundTag();
            ((MobEffectInstance) effect).save(potionTag);
            return potionTag;
        }).collect(NBTCollectors.toTagList());
        tag.put(Constants.Item.CUSTOM_POTION_EFFECTS, list);
    }).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_EFFECTS)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW).create(Keys.POTION_TYPE).get(h -> (PotionType) PotionUtils.getPotion(h)).set((h, v) -> {
        h.getOrCreateTag();
        PotionUtils.setPotion(h, (Potion) v);
    }).delete(h -> {
        if (h.hasTag()) {
            PotionUtils.setPotion(h, Potions.EMPTY);
        }
    }).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW);
}
Also used : PotionUtils(net.minecraft.world.item.alchemy.PotionUtils) Items(net.minecraft.world.item.Items) Constants(org.spongepowered.common.util.Constants) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) Potions(net.minecraft.world.item.alchemy.Potions) Potion(net.minecraft.world.item.alchemy.Potion) Keys(org.spongepowered.api.data.Keys) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ImmutableList(com.google.common.collect.ImmutableList) NBTCollectors(org.spongepowered.common.util.NBTCollectors) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Color(org.spongepowered.api.util.Color) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) PotionType(org.spongepowered.api.item.potion.PotionType) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PotionType(org.spongepowered.api.item.potion.PotionType) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)37 Entity (org.spongepowered.api.entity.Entity)11 Player (org.spongepowered.api.entity.living.player.Player)11 ArrayList (java.util.ArrayList)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 List (java.util.List)5 PotionEffectType (org.spongepowered.api.effect.potion.PotionEffectType)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)4 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)3 TimedRunnable (com.skelril.nitro.time.TimedRunnable)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 BlockType (org.spongepowered.api.block.BlockType)3 Keys (org.spongepowered.api.data.Keys)3 Keys (org.spongepowered.api.data.key.Keys)3 Listener (org.spongepowered.api.event.Listener)3 Cause (org.spongepowered.api.event.cause.Cause)3