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;
}
}
}
}
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());
}
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();
}
}
}
};
}
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());
}
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);
}
Aggregations