Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.anticheater.syrix.managers.koth;
- import org.bukkit.configuration.file.*;
- import org.bukkit.entity.*;
- import me.anticheater.syrix.*;
- import java.io.*;
- import org.bukkit.*;
- import me.anticheater.syrix.utils.*;
- import org.bukkit.plugin.*;
- import java.util.*;
- public class KothManager
- {
- private static File file;
- private static YamlConfiguration configuration;
- public static String kothprefix;
- public static ArrayList<Player> capturer;
- public static boolean active;
- public static String activekoth;
- public static double kothtime;
- public static int kothtimer;
- public static int kingchecktimer;
- public static int kothbroadcasttimer;
- static {
- KothManager.file = new File(Main.getInstance().getDataFolder(), "koths.yml");
- KothManager.configuration = YamlConfiguration.loadConfiguration(KothManager.file);
- KothManager.kothprefix = "&8[&6KoTh&8] ";
- KothManager.capturer = new ArrayList<Player>();
- KothManager.active = false;
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- }
- public static YamlConfiguration getConfiguration() {
- return KothManager.configuration;
- }
- public static void saveFile() {
- try {
- KothManager.configuration.save(KothManager.file);
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void startKoth(final String name) {
- KothManager.active = true;
- KothManager.activekoth = name;
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588\u2588\u2588\u2588\u2588&7\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
- Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&9" + KothManager.activekoth + " &ekoth has been started!"));
- Bukkit.broadcastMessage(Main.translate("&cCoords: &7Under developing..."));
- Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
- KothManager.kothtime = 120.0;
- new LocationUtils(getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.x"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.x"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.y"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.y"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.z"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.z"), getConfiguration().getString(String.valueOf(KothManager.activekoth.toLowerCase()) + ".world"));
- KothManager.kothtimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
- @Override
- public void run() {
- if (!KothManager.active) {
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
- KothManager.capturer.clear();
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
- }
- if (!KothManager.capturer.isEmpty()) {
- if (KothManager.kothtime > 0.0) {
- KothManager.kothtime -= 0.1;
- }
- }
- else if (KothManager.kothtime != 120.0) {
- KothManager.kothtime = 120.0;
- }
- }
- }, 2L, 2L);
- KothManager.kingchecktimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
- @Override
- public void run() {
- if (!KothManager.active) {
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
- KothManager.capturer.clear();
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
- }
- for (final Player online : Bukkit.getServer().getOnlinePlayers()) {
- if (KothManager.capturer.isEmpty() && LocationUtils.hasPlayerInside(online)) {
- KothManager.capturer.add(online);
- online.sendMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eNow you are capturing..."));
- }
- else if (KothManager.capturer.contains(online) && !LocationUtils.hasPlayerInside(online)) {
- KothManager.capturer.remove(online);
- KothManager.kothtime = 120.0;
- online.sendMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eKnocked..."));
- }
- else {
- if (KothManager.kothtime > 0.0) {
- continue;
- }
- Player winner = null;
- if (KothManager.capturer.contains(online)) {
- winner = Bukkit.getServer().getPlayer(online.getName());
- }
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588\u2588\u2588\u2588\u2588&7\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
- Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
- Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&9" + KothManager.activekoth + " &ekoth captured by &c" + winner.getName() + "&e."));
- Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
- KothManager.active = false;
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
- KothManager.capturer.clear();
- }
- }
- }
- }, 1L, 1L);
- KothManager.kothbroadcasttimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
- @Override
- public void run() {
- if (!KothManager.active) {
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
- KothManager.capturer.clear();
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
- }
- if (!KothManager.capturer.isEmpty()) {
- Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eSomebody capturing &c" + name + " &ekoth."));
- }
- else {
- Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eNobody capturing &c" + name + " &ekoth."));
- }
- }
- }, 500L, 500L);
- }
- public static void stopKoth() {
- KothManager.active = false;
- KothManager.activekoth = null;
- KothManager.kothtime = 120.0;
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
- Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
- }
- public static boolean isActive() {
- return KothManager.active;
- }
- public static String formatMillisecondsToMinutes(final Double d) {
- final int m1 = (int)(d % 60.0);
- final int m2 = (int)(d / 60.0);
- final String string = String.format("%02d:%02d", m2, m1);
- return string;
- }
- public static String formatMillisecondsToSeconds(final Double d) {
- final String timer = String.format("%1$.1f", d);
- final String string = String.valueOf(timer.replace(",", "."));
- return string;
- }
- public static String getTime() {
- if (KothManager.kothtime > 60.0) {
- return formatMillisecondsToMinutes(KothManager.kothtime);
- }
- return String.valueOf(formatMillisecondsToSeconds(KothManager.kothtime)) + "s";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement