Search in sources :

Example 1 with VillageGameStopEvent

use of pl.plajer.villagedefense3.villagedefenseapi.VillageGameStopEvent in project Village_Defense by Plajer.

the class Arena method stopGame.

/**
 * Stops current arena. Calls VillageGameStopEvent event
 *
 * @param quickStop should arena be stopped immediately? (use only in important cases)
 * @see VillageGameStopEvent
 */
public void stopGame(boolean quickStop) {
    VillageGameStopEvent villageGameStopEvent = new VillageGameStopEvent(this);
    Bukkit.getPluginManager().callEvent(villageGameStopEvent);
    if (getPlayersLeft().size() > 0) {
        for (Player p : getPlayers()) {
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.All-Villagers-Died"));
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Reached-Wave-X").replaceAll("%NUMBER%", String.valueOf(getWave())));
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Teleporting-To-Lobby-In-10-Seconds"));
        }
    } else {
        for (Player p : getPlayers()) {
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.All-Players-Died"));
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Reached-Wave-X").replaceAll("%NUMBER%", String.valueOf(getWave())));
            p.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("In-Game.Messages.Game-End-Messages.Teleporting-To-Lobby-In-10-Seconds"));
        }
    }
    for (final Player player : getPlayers()) {
        setStat(player, "highestwave", wave);
        addExperience(player, wave);
        UserManager.getUser(player.getUniqueId()).removeScoreboard();
        if (!quickStop) {
            if (plugin.getConfig().getBoolean("Firework-When-Game-Ends")) {
                new BukkitRunnable() {

                    int i = 0;

                    public void run() {
                        if (i == 4)
                            this.cancel();
                        if (!getPlayers().contains(player))
                            this.cancel();
                        Util.spawnRandomFirework(player.getLocation());
                        i++;
                    }
                }.runTaskTimer(plugin, 30, 30);
            }
        }
    }
    this.resetRottenFlesh();
    this.restoreDoors();
    for (Zombie zombie : getZombies()) {
        zombie.remove();
    }
    zombies.clear();
    for (IronGolem ironGolem : getIronGolems()) {
        ironGolem.remove();
    }
    ironGolems.clear();
    for (Villager villager : getVillagers()) {
        villager.remove();
    }
    villagers.clear();
    for (Wolf wolf : getWolfs()) {
        wolf.remove();
    }
    wolfs.clear();
    clearZombies();
    clearGolems();
    clearVillagers();
    clearWolfs();
    for (Entity entity : getStartLocation().getWorld().getEntities()) {
        if (entity.getWorld().getName().equalsIgnoreCase(getStartLocation().getWorld().getName()) && entity.getLocation().distance(getStartLocation()) < 300)
            if (entity.getType() != EntityType.PLAYER)
                entity.remove();
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) Zombie(org.bukkit.entity.Zombie) Villager(org.bukkit.entity.Villager) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) VillageGameStopEvent(pl.plajer.villagedefense3.villagedefenseapi.VillageGameStopEvent) IronGolem(org.bukkit.entity.IronGolem) Wolf(org.bukkit.entity.Wolf)

Aggregations

Entity (org.bukkit.entity.Entity)1 IronGolem (org.bukkit.entity.IronGolem)1 Player (org.bukkit.entity.Player)1 Villager (org.bukkit.entity.Villager)1 Wolf (org.bukkit.entity.Wolf)1 Zombie (org.bukkit.entity.Zombie)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 VillageGameStopEvent (pl.plajer.villagedefense3.villagedefenseapi.VillageGameStopEvent)1