76 lines
3.2 KiB
Java
76 lines
3.2 KiB
Java
package eu.univento.woolget.game;
|
|
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.game.TeamManager;
|
|
import eu.univento.core.api.map.Map;
|
|
import eu.univento.core.api.player.Spectator;
|
|
import eu.univento.core.api.schematic.Cuboid;
|
|
import eu.univento.woolget.WoolGet;
|
|
import eu.univento.woolget.listeners.Blocks;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
class WarmupCounter extends BukkitRunnable{
|
|
|
|
private int time = 60;
|
|
|
|
private ArrayList<Location> usedLocations = new ArrayList<>();
|
|
|
|
public void run() {
|
|
if(WoolGet.getGameStage() == GameStage.Warmup) {
|
|
if(time == 60) {
|
|
Map map = WoolGet.getVoting().getWinningMap();
|
|
Cuboid blue = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Blue.MinPos"), Config.readLocation("Strive." + map.getName() + ".Blue.MaxPos"));
|
|
Cuboid yellow = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Yellow.MinPos"), Config.readLocation("Strive." + map.getName() + ".Yellow.MaxPos"));
|
|
|
|
for (int i = 0; i <= 25; i++) {
|
|
Location blueChest = blue.getRandomLocation();
|
|
Location yellowChest = yellow.getRandomLocation();
|
|
if (isSafeLocation(blueChest) && !usedLocations.contains(blueChest)) {
|
|
blueChest.getBlock().setType(Material.CHEST);
|
|
usedLocations.add(blueChest);
|
|
} else i--;
|
|
if (isSafeLocation(yellowChest) && !usedLocations.contains(yellowChest)) {
|
|
yellowChest.getBlock().setType(Material.CHEST);
|
|
|
|
usedLocations.add(yellowChest);
|
|
} else i--;
|
|
}
|
|
blue.getRandomLocation().getBlock().setType(Material.ENCHANTMENT_TABLE);
|
|
yellow.getRandomLocation().getBlock().setType(Material.ENCHANTMENT_TABLE);
|
|
}
|
|
for(Player players : Bukkit.getOnlinePlayers()) {
|
|
players.setLevel(time);
|
|
}
|
|
if(time == 0) {
|
|
WoolGet.setGameStage(GameStage.Game);
|
|
WoolGet.gameID = WoolGet.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(WoolGet.getInstance(), new GameCounter(), 20L, 20L);
|
|
Bukkit.getScheduler().cancelTask(WoolGet.warmupID);
|
|
|
|
WoolGet.getPlayers().stream().filter(players -> !Blocks.placedBlocksBlue.containsKey(players) || !Blocks.placedBlocksYellow.containsKey(players)).forEach(players -> {
|
|
WoolGet.getPlayers().remove(players);
|
|
new Spectator(players);
|
|
TeamManager.getTeam(players).removePlayer(players);
|
|
Bukkit.broadcastMessage(players.getDisplayName() + "hat seinen Block nicht platziert");
|
|
});
|
|
}
|
|
time--;
|
|
}
|
|
}
|
|
|
|
private boolean isSafeLocation(Location loc) {
|
|
return loc.getBlock().getType() != Material.WATER && loc.getBlock().getType() != Material.STATIONARY_WATER;
|
|
|
|
}
|
|
|
|
}
|