158 lines
6.8 KiB
Java
158 lines
6.8 KiB
Java
package eu.univento.trashgames.timers;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.Utils;
|
|
import eu.univento.core.api.blocks.banners.BannerString;
|
|
import eu.univento.core.api.blocks.banners.FloatingText;
|
|
import eu.univento.core.api.game.PlayerManager;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.schematic.Cuboid;
|
|
import eu.univento.trashgames.TrashGames;
|
|
import eu.univento.trashgames.game.Duck;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.block.Banner;
|
|
import org.bukkit.entity.Entity;
|
|
import org.bukkit.entity.Item;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class GameCountdown extends BukkitRunnable {
|
|
|
|
private int time = 611;
|
|
private Cuboid blocks;
|
|
|
|
public GameCountdown() {
|
|
runTaskTimer(TrashGames.getInstance(), 20L, 20L);
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
time--;
|
|
|
|
if(time == 610) {
|
|
blocks = new Cuboid(Config.readLocation("TrashGames.Locs.Corner.1"), Config.readLocation("TrashGames.Locs.Corner.2"));
|
|
int i = 0;
|
|
for(CustomPlayer player : PlayerManager.getPlayers()) {
|
|
i++;
|
|
player.teleport(Config.readLocation("TrashGames.Locs.Spawn." + i));
|
|
}
|
|
|
|
ArrayList<Banner> wallBanners = blocks.getBlocks().stream().filter(block -> block.getType() == Material.WALL_BANNER).map(block -> (Banner) block.getState()).collect(Collectors.toCollection(ArrayList::new));
|
|
ArrayList<Banner> banners = blocks.getBlocks().stream().filter(block -> block.getType() == Material.STANDING_BANNER).map(block -> (Banner) block.getState()).collect(Collectors.toCollection(ArrayList::new));
|
|
|
|
BannerString string = new BannerString(wallBanners);
|
|
FloatingText text = new FloatingText("univentoEU", 4);
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
string.draw(text.next());
|
|
}
|
|
}.runTaskTimer(TrashGames.getInstance(), 2, 3);
|
|
|
|
BannerString string1 = new BannerString(banners);
|
|
FloatingText text1 = new FloatingText("TrashGames", 4);
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
string1.draw(text1.next());
|
|
}
|
|
}.runTaskTimer(TrashGames.getInstance(), 2, 3);
|
|
}
|
|
|
|
if (time == 600) {
|
|
for(CustomPlayer player : PlayerManager.getPlayers()) {
|
|
dropItems(player.getLocation().add(0.0D, 2.0D, 0.0D));
|
|
player.sendTitle("§5Los", "§egehts");
|
|
}
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
blocks.getEntities().stream().filter(entity -> entity instanceof Item).forEach(Entity::remove);
|
|
}
|
|
}.runTaskLater(TrashGames.getInstance(), 10 * 20L);
|
|
}
|
|
|
|
if (time == 300) {
|
|
Bukkit.broadcastMessage("§aDie Hälfte ist geschaft");
|
|
|
|
new Duck(PlayerManager.getPlayers().get(0).getLocation()).fly();
|
|
|
|
blocks.getBlocks().stream().filter(block -> block.getType() == Material.CHEST).forEach(block -> {
|
|
for (CustomPlayer players : PlayerManager.getPlayers()) {
|
|
players.changeChestState(block.getLocation(), true);
|
|
players.playSound(block.getLocation(), Sound.BLOCK_CHEST_OPEN, 1.0F, 1.0F);
|
|
}
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
List<Material> materials = Arrays.asList(Material.DIAMOND_SWORD, Material.IRON_SWORD, Material.DIAMOND_AXE, Material.DIAMOND_CHESTPLATE,
|
|
Material.DEAD_BUSH, Material.DEAD_BUSH, Material.DEAD_BUSH, Material.DEAD_BUSH, Material.DEAD_BUSH, Material.DEAD_BUSH, Material.DEAD_BUSH);
|
|
int random = new Random().nextInt(materials.size());
|
|
Item item = block.getWorld().dropItem(block.getLocation().add(0.0D, 1.0D, 0.0D), new ItemStack(materials.get(random)));
|
|
item.setPickupDelay(5);
|
|
for (CustomPlayer player : PlayerManager.getPlayers())
|
|
player.playSound(block.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0F, 1.0F);
|
|
}
|
|
}.runTaskLater(TrashGames.getInstance(), 3 * 20L);
|
|
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
for (CustomPlayer players : PlayerManager.getPlayers()) {
|
|
players.changeChestState(block.getLocation(), false);
|
|
players.playSound(block.getLocation(), Sound.BLOCK_CHEST_CLOSE, 1.0F, 1.0F);
|
|
}
|
|
}
|
|
}.runTaskLater(TrashGames.getInstance(), 5 * 20L);
|
|
});
|
|
|
|
}
|
|
|
|
if (time == 0) {
|
|
for(CustomPlayer player : PlayerManager.getPlayers()) {
|
|
player.setVelocity(player.getLocation().getDirection().multiply(0.0D).setY(10.0D));
|
|
player.setGliding(true);
|
|
player.setInvulnerable(true);
|
|
}
|
|
this.cancel();
|
|
Utils.restart();
|
|
for(CustomPlayer players : Core.getOnlinePlayers())
|
|
players.sendTitle("§eBesser als", "CrazyCubics.net, Portzone.net");
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
for(CustomPlayer players : Core.getOnlinePlayers())
|
|
players.sendTitle("§3Besser als", "Revlax.de, Tubehome.net");
|
|
}
|
|
}.runTaskLater(TrashGames.getInstance(), 5 * 20L);
|
|
}
|
|
for (CustomPlayer player : Core.getOnlinePlayers())
|
|
player.setLevel(time);
|
|
}
|
|
|
|
private void dropItems(Location loc) {
|
|
List<ItemStack> items = Arrays.asList(new ItemStack(Material.APPLE, 64), new ItemStack(Material.WORKBENCH),
|
|
new ItemStack(Material.COBBLESTONE, 2), new ItemStack(Material.STICK, 4), new ItemStack(Material.ROTTEN_FLESH, 64),
|
|
new ItemStack(Material.APPLE, 20), new ItemStack(Material.BOW), new ItemStack(Material.ARROW, 20));
|
|
for (ItemStack itemStack : items) {
|
|
Item item = loc.getWorld().dropItemNaturally(loc, itemStack);
|
|
item.setPickupDelay(3);
|
|
for (CustomPlayer player : PlayerManager.getPlayers())
|
|
player.playSound(item.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0F, 1.0F);
|
|
}
|
|
}
|
|
} |