161 lines
7.0 KiB
Java
161 lines
7.0 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.map.Cuboid;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.trashgames.TrashGames;
|
|
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.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
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 = 3611;
|
|
private Cuboid blocks;
|
|
|
|
public GameCountdown() {
|
|
runTaskTimer(TrashGames.getInstance(), 20L, 20L);
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
Core.getCommons().getLoggingHandler().getTrashGames().info("GameCountdown running: " + time);
|
|
time--;
|
|
|
|
if(time == 3610) {
|
|
Bukkit.broadcastMessage("Teleport");
|
|
blocks = new Cuboid(Config.readLocation("TrashGames.Locs.Corner.1"), Config.readLocation("TrashGames.Locs.Corner.2"));
|
|
Bukkit.broadcastMessage("Blocks: " + blocks.getBlocks().size());
|
|
int i = 0;
|
|
for(CustomPlayer player : PlayerManager.getPlayers()) {
|
|
i++;
|
|
player.teleport(Config.readLocation("TrashGames.Locs.Spawn." + i));
|
|
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 10, 10000, false));
|
|
}
|
|
|
|
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("§FeuniventoEU", 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("§F3TrashGames", 4);
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
string1.draw(text1.next());
|
|
}
|
|
}.runTaskTimer(TrashGames.getInstance(), 2, 3);
|
|
}
|
|
|
|
if (time == 3600) {
|
|
for(CustomPlayer player : PlayerManager.getPlayers()) {
|
|
dropItems(player.getLocation().add(0.0D, 3.0D, 0.0D));
|
|
player.sendTitle(1, 5, 1, "§5Los", "§egehts");
|
|
}
|
|
Bukkit.broadcastMessage("Jetzt aber schnell");
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
blocks.getEntities().stream().filter(entity -> entity instanceof Item).forEach(Entity::remove);
|
|
}
|
|
}.runTaskLater(TrashGames.getInstance(), 10 * 20L);
|
|
}
|
|
|
|
if (time == 3400) {
|
|
Bukkit.broadcastMessage("Die Hälfte ist geschaft");
|
|
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);
|
|
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);
|
|
item.setGlowing(true);
|
|
item.setVelocity(item.getLocation().getDirection().multiply(0D).setY(0.5D));
|
|
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) {
|
|
Bukkit.broadcastMessage("Die Zeit ist um");
|
|
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));
|
|
for (ItemStack itemStack : items) {
|
|
Item item = loc.getWorld().dropItemNaturally(loc, itemStack);
|
|
item.setPickupDelay(3);
|
|
item.setGlowing(true);
|
|
item.setVelocity(item.getLocation().getDirection().multiply(0D).setY(0.5D));
|
|
for (CustomPlayer player : PlayerManager.getPlayers())
|
|
player.playSound(item.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0F, 1.0F);
|
|
}
|
|
}
|
|
} |