Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameTask extends BukkitRunnable {
- @Override
- public void run() {
- Game game = UHC.getInstance().getGame();
- if (!game.isPurchased()) this.cancel();
- if (!UHC.getInstance().getTwitterManager().isVerified()) this.cancel();
- FileConfig fileConfig = UHC.getInstance().getMessagesConfig();
- ConfigCursor configCursor = new ConfigCursor(fileConfig, "game");
- WorldManager worldManager = UHC.getInstance().getWorldManager();
- game.setGameTime(game.getGameTime() + 1);
- UHCPlayer.getPlayers().values().forEach(uhcPlayer -> {
- if (uhcPlayer.getLogger() != null) {
- Logger logger = uhcPlayer.getLogger();
- if (logger.getCooldown().hasExpired()) {
- Bukkit.getPluginManager().callEvent(new LoggerExpireTimeEvent(uhcPlayer, logger.getDrops()));
- logger.handleDeath();
- }
- }
- });
- if (game.isEnded() && game.getEndCooldown().hasExpired()) {
- Bukkit.getServer().shutdown();
- return;
- }
- Common.getCounter(game.getGameTime(), game.getHealTime(), Common.format(configCursor.getString("finalHealCounter"), "<time>"));
- if (game.getGameTime() >= game.getHealTime() && !game.isHealTimeAlready()) {
- game.setHealTimeAlready(true);
- Bukkit.broadcastMessage(Common.format(configCursor.getString("finalHeal")));
- UHCPlayer.getPlayers().values().forEach(uhcPlayer -> {
- if (uhcPlayer.isAlive()) {
- if (uhcPlayer.isOnline() && uhcPlayer.getLogger() == null) {
- uhcPlayer.getPlayer().setHealth(20.0D);
- } else {
- Logger logger = uhcPlayer.getLogger();
- if (!logger.getZombie().isDead()) logger.getZombie().setHealth(20.0D);
- }
- }
- });
- }
- Common.getCounter(game.getGameTime(), game.getPvpTime(), Common.format(configCursor.getString("gracePeriodCounter"), "<time>"));
- if (game.getGameTime() >= game.getPvpTime() && !game.isPvpTimeAlready()) {
- game.setPvpTimeAlready(true);
- game.setAllowNether(true);
- worldManager.getUhcWorld().setPVP(true);
- worldManager.getUhcWorldNether().setPVP(true);
- worldManager.getUhcWorldDeathMatch().setPVP(true);
- Bukkit.broadcastMessage(Common.format(configCursor.getString("gracePeriod")));
- Moles moles = (Moles) Gamemode.getByName("Moles");
- if (game.isTeams() && moles.isEnabled()) {
- for (UHCTeam team : game.getGameManager().getAliveTeams()) {
- List<UHCPlayer> players = team.getTeamPlayers().stream().filter(uhcPlayer -> uhcPlayer.isAlive() && uhcPlayer.isOnline()).collect(Collectors.toList());
- if (players.size() == 0) continue;
- Collections.shuffle(players);
- UHCPlayer uhcPlayer = players.get(0);
- if (uhcPlayer == null) continue;
- uhcPlayer.getPlayer().sendMessage("ยงaYou have assigned as the Mole of your team!");
- uhcPlayer.setMole(true);
- moles.getMolesTeam().add(uhcPlayer);
- }
- moles.getMolesTeam().forEach(uhcPlayer -> game.getGameManager().colorize(uhcPlayer));
- game.getHost().forEach(uhcPlayer -> game.getGameManager().colorize(uhcPlayer));
- game.getModerators().forEach(uhcPlayer -> game.getGameManager().colorize(uhcPlayer));
- }
- }
- Common.getCounter(game.getGameTime(), game.getGlobalChat(), Common.format(configCursor.getString("globalChatCounter"), "<time>"));
- if (game.getGameTime() >= game.getGlobalChat() && !game.isGlobalChatAlready()) {
- game.setGlobalChatAlready(true);
- Bukkit.broadcastMessage(Common.format(configCursor.getString("globalChat")));
- }
- Gamemode skyHigh = Gamemode.getByName("Sky High");
- if (skyHigh.isEnabled() && game.isPvpTimeAlready()) {
- String time = Common.calculate(game.getGameTime());
- if (time.endsWith(":30") || time.endsWith(":00")) {
- game.getGameManager().getAlivePlayers().stream().filter(UHCPlayer::isOnline).forEach(uhcPlayer -> {
- Player player = uhcPlayer.getPlayer();
- if (player.getLocation().getBlockY() < 100) {
- player.sendMessage("ยงcYou have been beaten for being below y: 100!");
- player.damage(1.0);
- }
- });
- }
- }
- if (game.getGameTime() >= (game.getBorderTime() - game.getTimePerShrink()) && !game.isBorderTimeAlready()) {
- game.setBorderTimeAlready(true);
- World world = worldManager.getUhcWorld();
- world.setTime(0);
- world.setGameRuleValue("doDaylightCycle", "false");
- Bukkit.broadcastMessage(Common.format(configCursor.getString("permanentDay")));
- if (game.getShrinks().isEmpty()) {
- if (skyHigh.isEnabled()) {
- game.setShrink(null);
- return;
- }
- game.setDeathmatchTime(game.getDeathmatchTime() + game.getGameTime());
- game.setDeathmatchTimeAlready(true);
- game.setShrink(null);
- return;
- } else game.setShrink(new Shrink(game.getCurrentBorder(), Integer.valueOf(game.getShrinks().remove(0))));
- }
- if (game.isDeathmatchRunning()) {
- Common.getOnlinePlayers().forEach(player -> {
- if (player.getWorld() != worldManager.getUhcWorldDeathMatch()) {
- player.teleport(Common.randomLocation(worldManager.getUhcWorldDeathMatch(), worldManager.getUhcWorldDeathmatchSize()));
- }
- });
- return;
- }
- if (game.isDeathmatchTimeAlready()) {
- Common.getCounter(game.getGameTime(), game.getDeathmatchTime(), Common.format(configCursor.getString("deathmatchCounter"), "<time>"));
- if (game.getGameTime() >= game.getDeathmatchTime() && !game.isDeathmatchRunning()) {
- game.setDeathmatchRunning(true);
- Bukkit.broadcastMessage(Common.format(configCursor.getString("deathmatch")));
- Bukkit.getPluginManager().registerEvents(new DeathmatchListener(), UHC.getInstance());
- Bukkit.getPluginManager().callEvent(new DeathMatchStartEvent(UHC.getInstance().getWorldManager()));
- }
- return;
- }
- if (game.isBorderTimeAlready() && game.getShrink() != null) {
- Common.getCounter(game.getGameTime(), game.getShrink().getTime(), Common.format(configCursor.getString("borderCounter"), game.getShrink().getNewBorder(), "<time>"));
- if (game.getShrink().getTimeLeft() == 10) worldManager.shrinkBorder(game.getShrink().getNewBorder(), 1);
- if (game.getShrink().canShrink()) {
- Bukkit.getPluginManager().callEvent(new BorderShrinkEvent(game.getShrink().getNewBorder(), game.getShrink().getCurrentBorder()));
- game.setCurrentBorder(game.getShrink().getNewBorder());
- if (game.getShrinks().isEmpty()) {
- if (skyHigh.isEnabled()) {
- game.setShrink(null);
- return;
- }
- game.setDeathmatchTime(game.getDeathmatchTime() + game.getGameTime());
- game.setDeathmatchTimeAlready(true);
- game.setShrink(null);
- return;
- }
- game.setShrink(new Shrink(game.getCurrentBorder(), Integer.valueOf(game.getShrinks().remove(0))));
- }
- }
- if (!game.isNether() || !game.isAllowNether()) {
- Common.getOnlinePlayers().forEach(player -> {
- if (player.getWorld() == worldManager.getUhcWorldNether()) {
- player.teleport(Common.randomLocation(worldManager.getUhcWorld(), game.getCurrentBorder()));
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement