Search in sources :

Example 21 with PotionEffect

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

the class JungleRaidEffectProcessor method globalPotionEffects.

private static void globalPotionEffects(JungleRaidInstance inst) {
    boolean isSuddenDeath = inst.isSuddenDeath();
    for (Player player : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
        if (isSuddenDeath) {
            List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>());
            potionEffects.add(PotionEffect.of(PotionEffectTypes.GLOWING, 1, 20 * 20));
            player.offer(Keys.POTION_EFFECTS, potionEffects);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

Example 22 with PotionEffect

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

the class EntityPotionDataProcessor method set.

@Override
protected boolean set(EntityLivingBase dataHolder, List<PotionEffect> value) {
    dataHolder.clearActivePotions();
    for (PotionEffect effect : value) {
        net.minecraft.potion.PotionEffect mcEffect = PotionUtil.copyToNative(effect);
        dataHolder.addPotionEffect(mcEffect);
    }
    return true;
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

Example 23 with PotionEffect

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

the class PotionEntityPotionDataProcessor method getVal.

@Override
protected Optional<List<PotionEffect>> getVal(EntityPotion dataHolder) {
    ItemStack potionItem = dataHolder.getPotion();
    if (potionItem == null) {
        return Optional.empty();
    }
    Collection<net.minecraft.potion.PotionEffect> effects = PotionUtils.getEffectsFromStack(potionItem);
    if (effects == null || effects.isEmpty()) {
        return Optional.empty();
    }
    List<PotionEffect> apiEffects = new ArrayList<>();
    for (net.minecraft.potion.PotionEffect potionEffect : effects) {
        apiEffects.add(((PotionEffect) potionEffect));
    }
    return Optional.of(apiEffects);
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 24 with PotionEffect

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

the class ItemPotionDataProcessor method set.

@Override
protected boolean set(ItemStack dataHolder, List<PotionEffect> value) {
    if (!dataHolder.hasTagCompound()) {
        dataHolder.setTagCompound(new NBTTagCompound());
    }
    final NBTTagCompound mainCompound = dataHolder.getTagCompound();
    final NBTTagList potionList = new NBTTagList();
    for (PotionEffect effect : value) {
        final NBTTagCompound potionCompound = new NBTTagCompound();
        ((net.minecraft.potion.PotionEffect) effect).writeCustomPotionEffectToNBT(potionCompound);
        potionList.appendTag(potionCompound);
    }
    mainCompound.setTag(NbtDataUtil.CUSTOM_POTION_EFFECTS, potionList);
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 25 with PotionEffect

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

the class RPPlayerListener method RegionFlags.

private void RegionFlags(final Region r, Region er, final Player p) {
    // enter Gamemode flag
    if (r.canEnter(p) && r.flagExists("gamemode") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.gamemode")) {
        p.offer(Keys.GAME_MODE, (GameMode) RPUtil.getRegistryFor(GameMode.class, r.getFlagString("gamemode")));
    }
    // Exit gamemode
    if (er != null && er.flagExists("gamemode") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.gamemode")) {
        p.offer(Keys.GAME_MODE, p.getWorld().getProperties().getGameMode());
    }
    // Enter command as player
    if (r.canEnter(p) && r.flagExists("player-enter-command") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.server-enter-command")) {
        String[] cmds = r.getFlagString("player-enter-command").split(",");
        for (String cmd : cmds) {
            if (cmd.startsWith("/")) {
                cmd = cmd.substring(1);
            }
            RedProtect.get().game.getCommandManager().process(p, cmd.replace("{player}", p.getName()).replace("{region}", r.getName()));
        }
    }
    // Enter command as console
    if (r.canEnter(p) && r.flagExists("server-enter-command") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.server-enter-command")) {
        String[] cmds = r.getFlagString("server-enter-command").split(",");
        for (String cmd : cmds) {
            if (cmd.startsWith("/")) {
                cmd = cmd.substring(1);
            }
            RedProtect.get().game.getCommandManager().process(RedProtect.get().serv.getConsole(), cmd.replace("{player}", p.getName()).replace("{region}", r.getName()));
        }
    }
    // Check portal (/rp flag set-portal <rp> <world>
    if (r.canEnter(p) && r.flagExists("set-portal")) {
        String[] cmds = r.getFlagString("set-portal").split(" ");
        RedProtect.get().game.getCommandManager().process(RedProtect.get().serv.getConsole(), "rp teleport " + p.getName() + " " + cmds[0] + " " + cmds[1]);
    }
    if (er != null) {
        // Exit effect
        if (er.flagExists("effects") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.effects")) {
            String[] effects = er.getFlagString("effects").split(",");
            for (String effect : effects) {
                if (PlayertaskID.containsValue(p.getName())) {
                    String eff = effect.split(" ")[0];
                    /*String amplifier = effect.split(" ")[1];
						PotionEffect fulleffect = PotionEffect.builder()
								.particles(false)
								.potionType(RPUtil.getPotType(eff))
								.amplifier(Integer.parseInt(amplifier))
								.build();*/
                    p.remove(Keys.POTION_EFFECTS);
                    List<String> removeTasks = new ArrayList<>();
                    for (String taskId : PlayertaskID.keySet()) {
                        String id = taskId.split("_")[0];
                        String ideff = id + "_" + eff + er.getName();
                        if (PlayertaskID.containsKey(ideff) && PlayertaskID.get(ideff).equals(p.getName())) {
                            Sponge.getScheduler().getTaskById(UUID.fromString(id)).get().cancel();
                            removeTasks.add(taskId);
                            RedProtect.get().logger.debug("player", "(RegionFlags-eff)Removed task ID: " + taskId + " for player " + p.getName());
                        }
                    }
                    for (String key : removeTasks) {
                        PlayertaskID.remove(key);
                    }
                    removeTasks.clear();
                }
            }
        } else // exit fly flag
        if (er.flagExists("forcefly") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.forcefly") && (p.gameMode().get().equals(GameModes.SURVIVAL) || p.gameMode().get().equals(GameModes.ADVENTURE))) {
            if (PlayertaskID.containsValue(p.getName())) {
                if (r.flagExists("forcefly")) {
                    p.offer(Keys.CAN_FLY, r.getFlagBool("forcefly"));
                    p.offer(Keys.IS_FLYING, r.getFlagBool("forcefly"));
                } else {
                    p.offer(Keys.CAN_FLY, false);
                    p.offer(Keys.IS_FLYING, false);
                }
                List<String> removeTasks = new ArrayList<>();
                for (String taskId : PlayertaskID.keySet()) {
                    String id = taskId.split("_")[0];
                    String ideff = id + "_" + "forcefly" + er.getName();
                    if (PlayertaskID.containsKey(ideff) && PlayertaskID.get(ideff).equals(p.getName())) {
                        Sponge.getScheduler().getTaskById(UUID.fromString(id)).get().cancel();
                        removeTasks.add(taskId);
                        RedProtect.get().logger.debug("player", "(RegionFlags fly)Removed task ID: " + taskId + " for player " + p.getName());
                    }
                }
                for (String key : removeTasks) {
                    PlayertaskID.remove(key);
                }
                removeTasks.clear();
            }
        } else {
            stopTaskPlayer(p);
        }
        // Exit command as player
        if (er.flagExists("player-exit-command") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.player-exit-command")) {
            String[] cmds = er.getFlagString("player-exit-command").split(",");
            for (String cmd : cmds) {
                if (cmd.startsWith("/")) {
                    cmd = cmd.substring(1);
                }
                RedProtect.get().game.getCommandManager().process(p, cmd.replace("{player}", p.getName()).replace("{region}", er.getName()));
            }
        }
        // Exit command as console
        if (er.flagExists("server-exit-command") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.server-exit-command")) {
            String[] cmds = er.getFlagString("server-exit-command").split(",");
            for (String cmd : cmds) {
                if (cmd.startsWith("/")) {
                    cmd = cmd.substring(1);
                }
                RedProtect.get().game.getCommandManager().process(RedProtect.get().serv.getConsole(), cmd.replace("{player}", p.getName()).replace("{region}", er.getName()));
            }
        }
    }
    // Enter effect
    if (r.canEnter(p) && r.flagExists("effects") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.effects")) {
        String[] effects = r.getFlagString("effects").split(",");
        for (String effect : effects) {
            String eff = effect.split(" ")[0];
            String amplifier = effect.split(" ")[1];
            PotionEffect fulleffect = PotionEffect.builder().particles(false).potionType((PotionEffectType) RPUtil.getRegistryFor(PotionEffectType.class, eff)).amplifier(Integer.parseInt(amplifier)).build();
            String TaskId = Sponge.getScheduler().createAsyncExecutor(RedProtect.get().container).scheduleWithFixedDelay(new Runnable() {

                public void run() {
                    if (p.isOnline() && r.flagExists("effects")) {
                        p.offer(Keys.POTION_EFFECTS, Collections.singletonList(fulleffect));
                    } else {
                        p.offer(Keys.CAN_FLY, false);
                        try {
                            this.finalize();
                        } catch (Throwable e) {
                            RedProtect.get().logger.debug("player", "Effects not finalized...");
                        }
                    }
                }
            }, 0, 20, TimeUnit.SECONDS).getTask().getUniqueId().toString();
            PlayertaskID.put(TaskId + "_" + eff + r.getName(), p.getName());
            RedProtect.get().logger.debug("player", "Added task ID: " + TaskId + "_" + eff + " for player " + p.getName());
        }
    }
    // enter fly flag
    if (r.canEnter(p) && r.flagExists("forcefly") && !RedProtect.get().ph.hasPermOrBypass(p, "RedProtect.get().admin.flag.forcefly") && (p.gameMode().get().equals(GameModes.SURVIVAL) || p.gameMode().get().equals(GameModes.ADVENTURE))) {
        p.offer(Keys.CAN_FLY, r.getFlagBool("forcefly"));
        p.offer(Keys.IS_FLYING, r.getFlagBool("forcefly"));
        String TaskId = Sponge.getScheduler().createAsyncExecutor(RedProtect.get().container).scheduleWithFixedDelay(new Runnable() {

            public void run() {
                if (p.isOnline() && r.flagExists("forcefly")) {
                    p.offer(Keys.CAN_FLY, r.getFlagBool("forcefly"));
                    p.offer(Keys.IS_FLYING, r.getFlagBool("forcefly"));
                } else {
                    p.offer(Keys.CAN_FLY, false);
                    p.offer(Keys.IS_FLYING, false);
                    try {
                        this.finalize();
                    } catch (Throwable e) {
                        RedProtect.get().logger.debug("player", "forcefly not finalized...");
                    }
                }
            }
        }, 0, 80, TimeUnit.SECONDS).getTask().getUniqueId().toString();
        PlayertaskID.put(TaskId + "_" + "forcefly" + r.getName(), p.getName());
        RedProtect.get().logger.debug("player", "(RegionFlags fly)Added task ID: " + TaskId + "_" + "forcefly" + " for player " + p.getName());
    }
}
Also used : PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

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