Search in sources :

Example 1 with PotionEffect

use of org.bukkit.potion.PotionEffect in project TotalFreedomMod by TotalFreedom.

the class Command_purgeall method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    FUtil.adminAction(sender.getName(), "Purging all player data", true);
    // Purge entities
    plugin.ew.wipeEntities(true);
    for (Player player : server.getOnlinePlayers()) {
        FPlayer fPlayer = plugin.pl.getPlayer(player);
        // Unmute all players
        if (fPlayer.isMuted()) {
            fPlayer.setMuted(false);
        }
        // Unblock all commands
        if (fPlayer.allCommandsBlocked()) {
            fPlayer.setCommandsBlocked(false);
        }
        // Stop orbiting
        if (fPlayer.isOrbiting()) {
            fPlayer.stopOrbiting();
        }
        // Unfreeze
        if (fPlayer.getFreezeData().isFrozen()) {
            fPlayer.getFreezeData().setFrozen(false);
        }
        // Purge potion effects
        for (PotionEffect potion_effect : player.getActivePotionEffects()) {
            player.removePotionEffect(potion_effect.getType());
        }
        // Uncage
        if (fPlayer.getCageData().isCaged()) {
            fPlayer.getCageData().setCaged(false);
        }
    }
    // Unfreeze all players
    plugin.fm.setGlobalFreeze(false);
    // Remove all mobs
    Command_mobpurge.purgeMobs();
    return true;
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect)

Example 2 with PotionEffect

use of org.bukkit.potion.PotionEffect in project TotalFreedomMod by TotalFreedom.

the class Command_potion method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length == 1 || args.length == 2) {
        if (args[0].equalsIgnoreCase("list")) {
            List<String> potionEffectTypeNames = new ArrayList<>();
            for (PotionEffectType potion_effect_type : PotionEffectType.values()) {
                if (potion_effect_type != null) {
                    potionEffectTypeNames.add(potion_effect_type.getName());
                }
            }
            msg("Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
        } else if (args[0].equalsIgnoreCase("clearall")) {
            if (!(plugin.al.isAdmin(sender) || senderIsConsole)) {
                noPerms();
                return true;
            }
            FUtil.adminAction(sender.getName(), "Cleared all potion effects from all players", true);
            for (Player target : server.getOnlinePlayers()) {
                for (PotionEffect potion_effect : target.getActivePotionEffects()) {
                    target.removePotionEffect(potion_effect.getType());
                }
            }
        } else if (args[0].equalsIgnoreCase("clear")) {
            Player target = playerSender;
            if (args.length == 2) {
                target = getPlayer(args[1]);
                if (target == null) {
                    msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
                    return true;
                }
            }
            if (!target.equals(playerSender)) {
                if (!plugin.al.isAdmin(sender)) {
                    msg("Only superadmins can clear potion effects from other players.");
                    return true;
                }
            } else if (senderIsConsole) {
                msg("You must specify a target player when using this command from the console.");
                return true;
            }
            for (PotionEffect potion_effect : target.getActivePotionEffects()) {
                target.removePotionEffect(potion_effect.getType());
            }
            msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
        } else {
            return false;
        }
    } else if (args.length == 4 || args.length == 5) {
        if (args[0].equalsIgnoreCase("add")) {
            Player target = playerSender;
            if (args.length == 5) {
                target = getPlayer(args[4]);
                if (target == null) {
                    msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
                    return true;
                }
            }
            if (!target.equals(playerSender)) {
                if (!plugin.al.isAdmin(sender)) {
                    sender.sendMessage("Only superadmins can apply potion effects to other players.");
                    return true;
                }
            } else if (senderIsConsole) {
                sender.sendMessage("You must specify a target player when using this command from the console.");
                return true;
            }
            PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
            if (potion_effect_type == null) {
                sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type.");
                return true;
            }
            int duration;
            try {
                duration = Integer.parseInt(args[2]);
                duration = Math.min(duration, 100000);
            } catch (NumberFormatException ex) {
                msg("Invalid potion duration.", ChatColor.RED);
                return true;
            }
            int amplifier;
            try {
                amplifier = Integer.parseInt(args[3]);
                amplifier = Math.min(amplifier, 100000);
            } catch (NumberFormatException ex) {
                msg("Invalid potion amplifier.", ChatColor.RED);
                return true;
            }
            PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
            target.addPotionEffect(new_effect, true);
            msg("Added potion effect: " + new_effect.getType().getName() + ", Duration: " + new_effect.getDuration() + ", Amplifier: " + new_effect.getAmplifier() + (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList)

Example 3 with PotionEffect

use of org.bukkit.potion.PotionEffect in project GameCore by Warvale.

the class TeamSelect method onMove.

@EventHandler(priority = EventPriority.HIGHEST)
public void onMove(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    if (!event.getInventory().equals(inv)) {
        if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
            event.setCancelled(true);
            return;
        }
    }
    switch(event.getSlot()) {
        case // Join red
        3:
            if (event.getInventory().equals(inv)) {
                Main.getTeams().getRedTeam().addEntry(event.getWhoClicked().getName());
                event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.RED + "red");
                for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
                if (GameStart.initActive) {
                    player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
                }
                if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
                    GameStart.startCountdown();
                }
                event.setCancelled(true);
                player.closeInventory();
            }
            break;
        case // Close menu
        4:
            if (event.getInventory().equals(inv)) {
                event.setCancelled(true);
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_CLOSE, 1, 1);
                player.closeInventory();
            }
            break;
        case // Join blue
        5:
            if (event.getInventory().equals(inv)) {
                Main.getTeams().getBlueTeam().addEntry(event.getWhoClicked().getName());
                event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.DARK_AQUA + "blue");
                for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
                player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
                if (GameStart.initActive) {
                    player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
                }
                if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
                    GameStart.startCountdown();
                }
                event.setCancelled(true);
                player.closeInventory();
            }
            break;
        default:
            if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
                event.setCancelled(true);
                break;
            }
    }
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) EventHandler(org.bukkit.event.EventHandler)

Example 4 with PotionEffect

use of org.bukkit.potion.PotionEffect in project GameCore by Warvale.

the class Initialization method startGame.

public void startGame() {
    new Bosses().initBoss();
    List<Player> players = new ArrayList<>();
    List<Player> red = new ArrayList<>();
    List<Player> blue = new ArrayList<>();
    Main.getTeams().getBlueTeam().getPlayers().stream().filter(OfflinePlayer::isOnline).forEach(offlinePlayer -> {
        players.add(offlinePlayer.getPlayer());
        blue.add(offlinePlayer.getPlayer());
    });
    Main.getTeams().getRedTeam().getPlayers().stream().filter(OfflinePlayer::isOnline).forEach(offlinePlayer -> {
        players.add(offlinePlayer.getPlayer());
        red.add(offlinePlayer.getPlayer());
    });
    players.forEach(player -> {
        player.addPotionEffects(Arrays.asList(new PotionEffect(PotionEffectType.SLOW, 100000, 128, false), new PotionEffect(PotionEffectType.JUMP, 100000, 250, false)));
        String team = player.getScoreboard().getTeam(player.getName()).getName();
        player.sendMessage((String[]) Arrays.asList("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", ChatUtils.divider, "You are on team " + (team.equals("blue") ? ChatUtils.blue + "blue!" : ChatUtils.red + "red!"), "\n", ChatUtils.gray + "Your goal is to destroy the other teams " + ChatUtils.yellow + "core" + ChatUtils.gray + " 20 times!", "The game is divided into " + ChatUtils.red + "5" + ChatUtils.gray + " stages!", ChatUtils.yellow + "1." + ChatUtils.gray + " During the first " + ChatUtils.red + "20" + ChatUtils.gray + " minutes of the game, your core is invulnerable!", ChatUtils.yellow + "2." + ChatUtils.gray + " At the end of the first stage, a boss spawns in the middle of the map!", ChatUtils.yellow + "3." + ChatUtils.gray + " After that, diamonds will start to appear at middle. Diamonds can be used to craft the strongest armor in the game!", ChatUtils.yellow + "4." + ChatUtils.yellow + " Siege mode!" + ChatUtils.gray + " During this stage of the game, core breaking is 2x as powerful1!", ChatUtils.yellow + "5." + ChatUtils.gray + " During the last stage of the game, cores will be broken instantly!", ChatUtils.divider).toArray());
        new StartTask(this.map).runTaskTimer(Main.get(), 0, 20);
    });
}
Also used : StartTask(net.warvale.core.tasks.StartTask) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) Bosses(net.warvale.core.game.start.Bosses)

Example 5 with PotionEffect

use of org.bukkit.potion.PotionEffect in project GameCore by Warvale.

the class JoinCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        return false;
    }
    if (!(sender instanceof Player)) {
        throw new CommandException("Only players can execute this command.");
    }
    Player player = (Player) sender;
    String team = args[0];
    if (team.equalsIgnoreCase("blue")) {
        if (Main.getTeams().getBlueTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already on the " + ChatColor.DARK_AQUA + "blue team");
        } else {
            // Join the team
            if (Main.getTeams().getRedTeam().getEntries().contains(player.getName())) {
                throw new CommandException(ChatColor.GRAY + "You may not change teams at this time.");
            }
            Main.getTeams().getBlueTeam().addEntry(player.getName());
            player.sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.DARK_AQUA + "blue");
            for (PotionEffect effect : player.getActivePotionEffects()) {
                player.removePotionEffect(effect.getType());
            }
            return true;
        }
    }
    if (team.equalsIgnoreCase("red")) {
        if (Main.getTeams().getRedTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already on the " + ChatColor.RED + "red team");
        } else {
            // Join the team
            if (Main.getTeams().getBlueTeam().getEntries().contains(player.getName())) {
                throw new CommandException(ChatColor.GRAY + "You may not change teams at this time.");
            }
            Main.getTeams().getRedTeam().addEntry(player.getName());
            sender.sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.RED + "red");
            for (PotionEffect effect : player.getActivePotionEffects()) {
                player.removePotionEffect(effect.getType());
            }
            return true;
        }
    }
    if (team.equalsIgnoreCase("spectator")) {
        if (Main.getTeams().getSpectatorTeam().getEntries().contains(player.getName())) {
            throw new CommandException(ChatColor.GRAY + "You're already spectating!");
        } else {
            // Join the team
            if (!player.hasPermission("warvale.mod")) {
                throw new CommandException(ChatColor.GRAY + "You may not spectate at this time.");
            }
            return true;
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) CommandException(net.warvale.core.exceptions.CommandException)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)224 Player (org.bukkit.entity.Player)61 PotionEffectType (org.bukkit.potion.PotionEffectType)39 Location (org.bukkit.Location)37 LivingEntity (org.bukkit.entity.LivingEntity)37 EventHandler (org.bukkit.event.EventHandler)36 ItemStack (org.bukkit.inventory.ItemStack)34 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)23 PotionMeta (org.bukkit.inventory.meta.PotionMeta)18 Vector (org.bukkit.util.Vector)16 Random (java.util.Random)14 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)9 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)9 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 Projectile (org.bukkit.entity.Projectile)7 PotionData (org.bukkit.potion.PotionData)7