1248 lines
53 KiB
Java
1248 lines
53 KiB
Java
package net.knarcraft.hungerarena;
|
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
import net.knarcraft.hungerarena.Listeners.BlockStorage;
|
|
import net.knarcraft.hungerarena.Listeners.Boundaries;
|
|
import net.knarcraft.hungerarena.Listeners.ChatListener;
|
|
import net.knarcraft.hungerarena.Listeners.DeathListener;
|
|
import net.knarcraft.hungerarena.Listeners.FreezeListener;
|
|
import net.knarcraft.hungerarena.Listeners.JoinAndQuitListener;
|
|
import net.knarcraft.hungerarena.Listeners.PvP;
|
|
import net.knarcraft.hungerarena.Listeners.SignsAndBeds;
|
|
import net.knarcraft.hungerarena.Listeners.SignsAndBedsOld;
|
|
import net.knarcraft.hungerarena.Listeners.SpectatorListener;
|
|
import net.knarcraft.hungerarena.Listeners.SpectatorListenerOld;
|
|
import net.knarcraft.hungerarena.Listeners.TeleportListener;
|
|
import net.knarcraft.hungerarena.Listeners.WorldChange;
|
|
import net.knarcraft.hungerarena.Listeners.spawnsListener;
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Color;
|
|
import org.bukkit.FireworkEffect;
|
|
import org.bukkit.FireworkEffect.Type;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.entity.EntityType;
|
|
import org.bukkit.entity.Firework;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.FireworkMeta;
|
|
import org.bukkit.material.MaterialData;
|
|
import org.bukkit.metadata.MetadataValue;
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.bukkit.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
import org.bukkit.scoreboard.DisplaySlot;
|
|
import org.bukkit.scoreboard.Objective;
|
|
import org.bukkit.scoreboard.Score;
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.Reader;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.EnumSet;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
public class HungerArena extends JavaPlugin {
|
|
|
|
static Logger log;
|
|
public final HashMap<Integer, List<UUID>> Playing = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> Ready = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> Dead = new HashMap<>();
|
|
public final HashMap<Integer, String> MatchRunning = new HashMap<>();
|
|
public final HashMap<Integer, Boolean> canJoin = new HashMap<>();
|
|
public final HashMap<Integer, Boolean> open = new HashMap<>();
|
|
private final HashMap<Integer, Integer> countDownTimer = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> Quit = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> Out = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> Watching = new HashMap<>();
|
|
public final HashMap<String, Integer> Kills = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> NeedConfirm = new HashMap<>();
|
|
public final HashMap<Integer, HashMap<Integer, Location>> location = new HashMap<>();
|
|
public final HashMap<Integer, List<UUID>> inArena = new HashMap<>();
|
|
//public final HashMap<Integer, List<String>> Frozen = new HashMap<>();
|
|
public final HashMap<Integer, Integer> maxPlayers = new HashMap<>();
|
|
public final HashMap<String, String> setting = new HashMap<>();
|
|
public final HashMap<Integer, Integer> gp = new HashMap<>();
|
|
public final ArrayList<Player> Tele = new ArrayList<>();
|
|
public final ArrayList<String> needInv = new ArrayList<>();
|
|
public final HashMap<Integer, String> worldNames = new HashMap<>();
|
|
public final Map<Integer, Arena> arenas = new HashMap<>();
|
|
public final Map<UUID, ArenaPlayer> arenaPlayers = new HashMap<>();
|
|
|
|
public final HashMap<String, Scoreboard> scoreboards = new HashMap<>();
|
|
|
|
final Listener DeathListener = new DeathListener(this);
|
|
Listener SpectatorListener = null;
|
|
Listener SpectatorListenerOld = null;
|
|
final Listener FreezeListener = new FreezeListener(this);
|
|
final Listener JoinAndQuitListener = new JoinAndQuitListener(this);
|
|
final Listener ChatListener = new ChatListener(this);
|
|
final Listener Chests = new Chests(this);
|
|
final Listener PvP = new PvP(this);
|
|
final Listener CommandBlock = new CommandBlock(this);
|
|
Listener Teleport = new TeleportListener(this);
|
|
SignsAndBeds SignsAndBeds = null;
|
|
SignsAndBedsOld SignsAndBedsOld = null;
|
|
final Listener BlockStorage = new BlockStorage(this);
|
|
//Listener WinGames = new WinGamesListener(this);
|
|
final Listener WorldChange = new WorldChange(this);
|
|
final Listener Boundaries = new Boundaries(this);
|
|
final Listener spawnsListener = new spawnsListener(this);
|
|
final CommandExecutor HaCommands = new HaCommands(this);
|
|
final CommandExecutor SponsorCommands = new SponsorCommands(this);
|
|
final CommandExecutor SpawnsCommand = new SpawnsCommand(this);
|
|
|
|
public boolean exists;
|
|
public boolean restrictedWorlds;
|
|
|
|
public FileConfiguration config;
|
|
public FileConfiguration spawns = null;
|
|
public File spawnsFile = null;
|
|
public FileConfiguration data = null;
|
|
public File dataFile = null;
|
|
public FileConfiguration management = null;
|
|
public File managementFile = null;
|
|
|
|
public FileConfiguration MyChests = null;
|
|
public File ChestsFile = null;
|
|
|
|
public final ArrayList<ItemStack> Reward = new ArrayList<>();
|
|
public final ArrayList<ItemStack> Cost = new ArrayList<>();
|
|
public final ArrayList<ItemStack> Fee = new ArrayList<>();
|
|
public final ArrayList<ItemStack> ChestPay = new ArrayList<>();
|
|
|
|
public boolean vault = false;
|
|
public boolean eco = false;
|
|
public Economy econ = null;
|
|
|
|
int i = 0;
|
|
int v = 0;
|
|
int arenaId = 0;
|
|
|
|
final File PFilePath = new File(getDataFolder(), "/inventories");
|
|
|
|
public void onEnable() {
|
|
log = this.getLogger();
|
|
|
|
getConfig().options().copyDefaults(true);
|
|
getConfig().options().copyHeader(true);
|
|
saveDefaultConfig();
|
|
saveConfig();
|
|
config = getConfig();
|
|
spawns = getSpawns();
|
|
data = getData();
|
|
data.options().copyDefaults(true);
|
|
if (!new File(this.getDataFolder(), "Data.yml").exists()) {
|
|
this.saveData();
|
|
}
|
|
management = this.getManagement();
|
|
management.options().copyDefaults(true);
|
|
if (!new File(this.getDataFolder(), "commandAndBlockManagement.yml").exists()) {
|
|
this.saveManagement();
|
|
}
|
|
MyChests = this.getChests();
|
|
MyChests.options().copyDefaults(true);
|
|
if (!new File(this.getDataFolder(), "Chests.yml").exists()) {
|
|
this.saveChests();
|
|
}
|
|
getServer().getPluginManager().registerEvents(DeathListener, this);
|
|
getServer().getPluginManager().registerEvents(FreezeListener, this);
|
|
getServer().getPluginManager().registerEvents(JoinAndQuitListener, this);
|
|
getServer().getPluginManager().registerEvents(ChatListener, this);
|
|
getServer().getPluginManager().registerEvents(Chests, this);
|
|
getServer().getPluginManager().registerEvents(PvP, this);
|
|
getServer().getPluginManager().registerEvents(CommandBlock, this);
|
|
|
|
try {
|
|
Class.forName("org.bukkit.Tag");
|
|
SignsAndBeds = new SignsAndBeds(this);
|
|
getServer().getPluginManager().registerEvents(SignsAndBeds, this);
|
|
SpectatorListener = new SpectatorListener(this);
|
|
getServer().getPluginManager().registerEvents(SpectatorListener, this);
|
|
getLogger().info("Events 1.13+ enabled!");
|
|
} catch (NoClassDefFoundError | ClassNotFoundException exp) {
|
|
SignsAndBedsOld = new SignsAndBedsOld(this);
|
|
getServer().getPluginManager().registerEvents(SignsAndBedsOld, this);
|
|
SpectatorListenerOld = new SpectatorListenerOld(this);
|
|
getServer().getPluginManager().registerEvents(SpectatorListenerOld, this);
|
|
getLogger().info("Events 1.12- enabled!");
|
|
}
|
|
getServer().getPluginManager().registerEvents(BlockStorage, this);
|
|
//getServer().getPluginManager().registerEvents(WinGames, this);
|
|
getServer().getPluginManager().registerEvents(WorldChange, this);
|
|
getServer().getPluginManager().registerEvents(Boundaries, this);
|
|
getServer().getPluginManager().registerEvents(spawnsListener, this);
|
|
|
|
getCommand("Ha").setExecutor(HaCommands);
|
|
getCommand("Sponsor").setExecutor(SponsorCommands);
|
|
getCommand("Startpoint").setExecutor(SpawnsCommand);
|
|
|
|
if (!PFilePath.exists()) {
|
|
PFilePath.mkdirs();
|
|
}
|
|
for (File file : PFilePath.listFiles()) {
|
|
String filename = file.getName();
|
|
int lastIndex = filename.lastIndexOf('.');
|
|
filename = filename.substring(0, Math.max(lastIndex, 0));
|
|
needInv.add(filename);
|
|
}
|
|
|
|
i = 1;
|
|
|
|
this.reloadSpawnPoints(true);
|
|
|
|
if (setupEconomy()) {
|
|
log.info("Found Vault! Hooking in for economy!");
|
|
}
|
|
if (config.getDouble("config.version") != 1.4) {
|
|
config.set("config.version", 1.4);
|
|
config.set("rewardEco.enabled", false);
|
|
config.set("rewardEco.reward", 100);
|
|
}
|
|
if (config.getBoolean("rewardEco.enabled", true) || config.getBoolean("sponsorEco.enabled", true) || config.getBoolean("EntryFee.eco", true)) {
|
|
if (vault) {
|
|
log.info("Economy hook deployed.");
|
|
eco = true;
|
|
} else {
|
|
log.info("You want economy support... yet you either don't have Vault or don't have an economy plugin. Sorry, can't give you it.");
|
|
}
|
|
}
|
|
if (!eco) {
|
|
if (vault) {
|
|
log.info("We see that you have Vault on your server. To set economy support to true, enable it in the config.");
|
|
}
|
|
}
|
|
try {
|
|
List<String> RewardItemList = new ArrayList<>();
|
|
List<String> SponsorItemList = new ArrayList<>();
|
|
List<String> EntryfeeItemList = new ArrayList<>();
|
|
List<String> PayForChests = new ArrayList<>();
|
|
|
|
for (String rewards : config.getStringList("Reward")) {
|
|
String[] rinfo = rewards.split(",");
|
|
Material NewMat = getNewMaterial(rinfo[0], 0);
|
|
if (NewMat != null) {
|
|
Reward.add(new ItemStack(NewMat, Integer.parseInt(rinfo[1])));
|
|
RewardItemList.add(NewMat.name() + "," + Integer.parseInt(rinfo[1]));
|
|
}
|
|
}
|
|
config.set("Reward", RewardItemList);
|
|
|
|
for (String scost : config.getStringList("Sponsor_Cost")) {
|
|
String[] sinfo = scost.split(",");
|
|
Material NewMat = getNewMaterial(sinfo[0], 0);
|
|
if (NewMat != null) {
|
|
Cost.add(new ItemStack(NewMat, Integer.parseInt(sinfo[1])));
|
|
SponsorItemList.add(NewMat.name() + "," + Integer.parseInt(sinfo[1]));
|
|
}
|
|
}
|
|
config.set("Sponsor_Cost", SponsorItemList);
|
|
|
|
if (config.getBoolean("EntryFee.enabled")) {
|
|
for (String fee : config.getStringList("EntryFee.fee")) {
|
|
String[] finfo = fee.split(",");
|
|
Material NewMat = getNewMaterial(finfo[0], 0);
|
|
if (NewMat != null) {
|
|
Fee.add(new ItemStack(NewMat, Integer.parseInt(finfo[1])));
|
|
EntryfeeItemList.add(NewMat.name() + "," + Integer.parseInt(finfo[1]));
|
|
}
|
|
}
|
|
config.set("EntryFee.fee", EntryfeeItemList);
|
|
}
|
|
|
|
if (config.getBoolean("ChestPay.enabled")) {
|
|
for (String paychests : config.getStringList("ChestPay.items")) {
|
|
String[] rew = paychests.split(",");
|
|
Material NewMat = getNewMaterial(rew[0], 0);
|
|
if (NewMat != null) {
|
|
ChestPay.add(new ItemStack(NewMat, Integer.parseInt(rew[1])));
|
|
PayForChests.add(NewMat.name() + "," + Integer.parseInt(rew[1]));
|
|
}
|
|
}
|
|
config.set("ChestPay.items", PayForChests);
|
|
}
|
|
|
|
ArrayList<String> newList = new ArrayList<>();
|
|
for (String block : management.getStringList("blocks.whitelist")) {
|
|
Material NewMat = getNewMaterial(block, 0);
|
|
if (NewMat != null) {
|
|
newList.add(NewMat.name());
|
|
}
|
|
}
|
|
management.set("blocks.whitelist", newList);
|
|
this.saveManagement();
|
|
} catch (Exception e) {
|
|
log.warning("Could not add a reward/sponsor/entry cost or whitelist/blacklist! One of them is wrong!");
|
|
}
|
|
|
|
try {
|
|
String spt = config.getString("spawnsTool");
|
|
if (!spt.trim().toLowerCase().contains("[a-z]")) {
|
|
config.set("spawnsTool", getNewMaterial(spt, 0).name());
|
|
}
|
|
} catch (Exception e) {
|
|
}
|
|
restrictedWorlds = config.getBoolean("Restricted");
|
|
saveConfig();
|
|
scoreboardInit();
|
|
log.info("Enabled v" + getDescription().getVersion());
|
|
}
|
|
|
|
public Material getNewMaterial(String base, int data) {
|
|
Material NewMat = null;
|
|
if (Material.getMaterial(base) != null) {
|
|
NewMat = Material.getMaterial(base);
|
|
} else if (base.replaceAll("[0-9]", "").equals("")) {
|
|
NewMat = findOldMaterial(Integer.parseInt(base), (byte) data);
|
|
} else {
|
|
try {
|
|
NewMat = Material.getMaterial(base, true);
|
|
} catch (NoSuchMethodError n) {
|
|
}
|
|
}
|
|
return NewMat;
|
|
}
|
|
|
|
public Material findOldMaterial(int typeId, byte dataValue) {
|
|
for (Material i : EnumSet.allOf(Material.class)) {
|
|
try {
|
|
if (i.getId() == typeId) {
|
|
return Bukkit.getUnsafe().fromLegacy(new MaterialData(i, dataValue));
|
|
}
|
|
} catch (IllegalArgumentException | NoSuchMethodError e) {
|
|
try {
|
|
if (i.getId() == typeId) {
|
|
return new MaterialData(i, dataValue).getItemType();
|
|
}
|
|
} catch (IllegalArgumentException ee) {
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
public void onDisable() {
|
|
log.info("Disabled v" + getDescription().getVersion());
|
|
}
|
|
|
|
public void reloadSpawnPoints(boolean verbose) {
|
|
if (spawns.getConfigurationSection("Spawns") != null) {
|
|
Map<String, Object> temp = spawns.getConfigurationSection("Spawns").getValues(false);
|
|
for (Entry<String, Object> entry : temp.entrySet()) {
|
|
if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) {
|
|
Integer a = Integer.parseInt(entry.getKey());
|
|
worldNames.put(a, "none_meaning_this_is_not_a_map");
|
|
location.computeIfAbsent(a, k -> new HashMap<>());
|
|
Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false);
|
|
for (Map.Entry<String, Object> e : temp2.entrySet()) {
|
|
if (spawns.get("Spawns." + entry.getKey() + "" + e.getKey()) != null) {
|
|
String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(",");
|
|
Integer s = Integer.parseInt(e.getKey());
|
|
location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3])));
|
|
worldNames.put(a, coords[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int arenaId : location.keySet()) {
|
|
if (location.get(arenaId).size() != 0) {
|
|
if (verbose) {
|
|
log.info("Loaded " + location.get(arenaId).size() + " tribute spawns for arena " + arenaId + "!");
|
|
}
|
|
Playing.put(arenaId, new ArrayList<>());
|
|
Ready.put(arenaId, new ArrayList<>());
|
|
Dead.put(arenaId, new ArrayList<>());
|
|
MatchRunning.put(arenaId, null);
|
|
Quit.put(arenaId, new ArrayList<>());
|
|
Out.put(arenaId, new ArrayList<>());
|
|
Watching.put(arenaId, new ArrayList<>());
|
|
NeedConfirm.put(arenaId, new ArrayList<>());
|
|
inArena.put(arenaId, new ArrayList<>());
|
|
|
|
Arena arena = arenas.get(arenaId);
|
|
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
|
|
if (arenaPlayer.getArena() == arena) {
|
|
arenaPlayer.setFrozen(false);
|
|
}
|
|
}
|
|
canJoin.put(arenaId, false);
|
|
maxPlayers.put(arenaId, location.get(arenaId).size());
|
|
open.put(arenaId, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public WorldEditPlugin hookWE() {
|
|
Plugin wPlugin = getServer().getPluginManager().getPlugin("WorldEdit");
|
|
|
|
if ((!(wPlugin instanceof WorldEditPlugin))) {
|
|
return null;
|
|
}
|
|
|
|
return (WorldEditPlugin) wPlugin;
|
|
}
|
|
|
|
public boolean setupEconomy() {
|
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
|
return false;
|
|
}
|
|
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
|
if (rsp == null) {
|
|
return false;
|
|
}
|
|
econ = rsp.getProvider();
|
|
vault = true;
|
|
return true;
|
|
}
|
|
|
|
public void reloadSpawns() {
|
|
if (spawnsFile == null) {
|
|
spawnsFile = new File(getDataFolder(), "spawns.yml");
|
|
}
|
|
if (!spawnsFile.exists()) {
|
|
this.saveResource("spawns.yml", false);
|
|
}
|
|
|
|
spawns = YamlConfiguration.loadConfiguration(spawnsFile);
|
|
|
|
InputStream defaultSpawnsConfigStream = this.getResource("spawns.yml");
|
|
if (defaultSpawnsConfigStream != null) {
|
|
YamlConfiguration defaultSpawnsConfig = loadConfigStream(defaultSpawnsConfigStream);
|
|
if (defaultSpawnsConfig != null) {
|
|
spawns.addDefaults(defaultSpawnsConfig);
|
|
spawns.options().copyDefaults(true);
|
|
saveSpawns();
|
|
}
|
|
}
|
|
|
|
String spawnsSet = spawns.getString("Spawns_set");
|
|
if (spawnsSet != null && (spawnsSet.equalsIgnoreCase("false") ||
|
|
spawnsSet.equalsIgnoreCase("true"))) {
|
|
|
|
//Move the spawns_set value to spawns_set.0, and unset Spawns_set
|
|
spawns.set("Spawns_set", null);
|
|
spawns.set("Spawns_set.0", spawnsSet);
|
|
|
|
String spawnCoordinatesValue = spawns.getString("Spawn_coordinates");
|
|
spawns.set("Spawn_coordinates", null);
|
|
spawns.set("Spawn_coordinates.0", spawnCoordinatesValue);
|
|
if (spawns.getConfigurationSection("Spawns") != null) {
|
|
Set<String> spawnConfigKeys = spawns.getConfigurationSection("Spawns").getValues(false).keySet();
|
|
for (String entry : spawnConfigKeys) {
|
|
if (spawns.getString("Spawns_set_" + entry) != null) {
|
|
spawns.set("Spawns_set." + entry, spawns.getString("Spawns_set_" + entry));
|
|
spawns.set("Spawns_set_" + entry, null);
|
|
}
|
|
if (spawns.getString("Spawn_coordinates_" + entry) != null) {
|
|
spawns.set("Spawn_coordinates." + entry, spawns.getString("Spawn_coordinates_" + entry));
|
|
spawns.set("Spawn_coordinates_" + entry, null);
|
|
}
|
|
}
|
|
}
|
|
saveSpawns();
|
|
}
|
|
}
|
|
|
|
public FileConfiguration getSpawns() {
|
|
if (spawns == null) {
|
|
this.reloadSpawns();
|
|
}
|
|
return spawns;
|
|
}
|
|
|
|
public void saveSpawns() {
|
|
if (spawns == null || spawnsFile == null) {
|
|
return;
|
|
}
|
|
try {
|
|
getSpawns().save(spawnsFile);
|
|
} catch (IOException ex) {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + spawnsFile, ex);
|
|
}
|
|
}
|
|
|
|
public void reloadData() {
|
|
if (dataFile == null) {
|
|
dataFile = new File(getDataFolder(), "Data.yml");
|
|
}
|
|
if (!dataFile.exists()) {
|
|
this.saveResource("Data.yml", false);
|
|
}
|
|
|
|
data = YamlConfiguration.loadConfiguration(dataFile);
|
|
|
|
InputStream defaultConfigStream = this.getResource("Data.yml");
|
|
if (defaultConfigStream != null) {
|
|
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
|
|
if (defaultConfig != null) {
|
|
data.addDefaults(defaultConfig);
|
|
data.options().copyDefaults(true);
|
|
saveData();
|
|
}
|
|
}
|
|
}
|
|
|
|
public FileConfiguration getData() {
|
|
if (data == null) {
|
|
this.reloadData();
|
|
}
|
|
return data;
|
|
}
|
|
|
|
public void saveData() {
|
|
if (data == null || dataFile == null) {
|
|
return;
|
|
}
|
|
try {
|
|
getData().save(dataFile);
|
|
} catch (IOException ex) {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + dataFile, ex);
|
|
}
|
|
}
|
|
|
|
public void reloadManagement() {
|
|
if (managementFile == null) {
|
|
managementFile = new File(getDataFolder(), "commandAndBlockManagement.yml");
|
|
}
|
|
if (!managementFile.exists()) {
|
|
this.saveResource("commandAndBlockManagement.yml", false);
|
|
}
|
|
|
|
management = YamlConfiguration.loadConfiguration(managementFile);
|
|
|
|
InputStream defaultConfigStream = this.getResource("commandAndBlockManagement.yml");
|
|
if (defaultConfigStream != null) {
|
|
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
|
|
if (defaultConfig != null) {
|
|
management.addDefaults(defaultConfig);
|
|
management.options().copyHeader(true);
|
|
management.options().copyDefaults(true);
|
|
saveManagement();
|
|
}
|
|
}
|
|
}
|
|
|
|
public FileConfiguration getManagement() {
|
|
if (management == null) {
|
|
this.reloadManagement();
|
|
}
|
|
return management;
|
|
}
|
|
|
|
public void saveManagement() {
|
|
if (management == null || managementFile == null) {
|
|
return;
|
|
}
|
|
try {
|
|
getManagement().save(managementFile);
|
|
} catch (IOException ex) {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex);
|
|
}
|
|
}
|
|
|
|
public void reloadChests() {
|
|
if (ChestsFile == null) {
|
|
ChestsFile = new File(getDataFolder(), "Chests.yml");
|
|
}
|
|
MyChests = YamlConfiguration.loadConfiguration(ChestsFile);
|
|
}
|
|
|
|
public FileConfiguration getChests() {
|
|
if (MyChests == null) {
|
|
this.reloadChests();
|
|
}
|
|
return MyChests;
|
|
}
|
|
|
|
public void saveChests() {
|
|
if (MyChests == null || ChestsFile == null) {
|
|
return;
|
|
}
|
|
try {
|
|
getChests().save(ChestsFile);
|
|
} catch (IOException ex) {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + ChestsFile, ex);
|
|
}
|
|
}
|
|
|
|
File PFile = null;
|
|
FileConfiguration PConfig = null;
|
|
|
|
public void reloadPFile(String pname) {
|
|
if (PFile == null) {
|
|
PFile = new File(PFilePath, pname + ".yml");
|
|
}
|
|
PConfig = YamlConfiguration.loadConfiguration(PFile);
|
|
InputStream defaultConfigStream = this.getResource("Player.yml");
|
|
if (defaultConfigStream != null) {
|
|
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
|
|
if (defaultConfig != null) {
|
|
this.PConfig.setDefaults(defaultConfig);
|
|
}
|
|
}
|
|
}
|
|
|
|
private YamlConfiguration loadConfigStream(InputStream defaultConfigStream) {
|
|
Reader defaultConfigReader = null;
|
|
YamlConfiguration defaultConfig = null;
|
|
if (defaultConfigStream != null) {
|
|
defaultConfigReader = new java.io.InputStreamReader(defaultConfigStream, StandardCharsets.UTF_8);
|
|
}
|
|
|
|
if (defaultConfigReader != null) {
|
|
defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigReader);
|
|
} else {
|
|
log.warning("A default resource in the plugin jar could not be read.");
|
|
}
|
|
try {
|
|
if (defaultConfigReader != null) {
|
|
defaultConfigReader.close();
|
|
}
|
|
} catch (IOException e) {
|
|
log.warning("An error occured while trying to close the resource file.");
|
|
}
|
|
return defaultConfig;
|
|
}
|
|
|
|
public FileConfiguration getPConfig(String pname) {
|
|
PFile = null;
|
|
this.reloadPFile(pname);
|
|
return PConfig;
|
|
}
|
|
|
|
public void savePFile(String pname) {
|
|
if (PConfig.getString("player").equals(pname)) {
|
|
try {
|
|
this.PConfig.save(PFile);
|
|
} catch (IOException ex) {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + PFile, ex);
|
|
}
|
|
} else {
|
|
this.getLogger().log(Level.SEVERE, "Could not save config to " + pname + ".yml ! It's not this players inventory!?");
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public void restoreInventory(Player p, String pname) {
|
|
for (int u : Playing.keySet()) {
|
|
if (Playing.get(u) != null) {
|
|
if (Playing.get(u).contains(pname)) {
|
|
Playing.get(u).remove(pname);
|
|
p.sendMessage(ChatColor.AQUA + "You have left the game!");
|
|
if (config.getBoolean("broadcastAll")) {
|
|
p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!");
|
|
} else {
|
|
for (UUID gn : Playing.get(u)) {
|
|
Player g = getServer().getPlayer(gn);
|
|
g.sendMessage(ChatColor.RED + pname + " Quit!");
|
|
}
|
|
}
|
|
if (canJoin.get(u)) {
|
|
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
|
scoreboards.remove(p.getName());
|
|
Kills.remove(p.getName());
|
|
}
|
|
|
|
}
|
|
}
|
|
if (Ready.get(u) != null) {
|
|
Ready.get(u).remove(pname);
|
|
}
|
|
}
|
|
if (new File(PFilePath, pname + ".yml").exists()) {
|
|
FileConfiguration pinfo = this.getPConfig(pname);
|
|
if ((pinfo.getString("player").equals(pname)) && (this.needInv.contains(pname))) {
|
|
try {
|
|
ItemStack[] pinv = null;
|
|
Object o = pinfo.get("inv");
|
|
if (o instanceof ItemStack[]) {
|
|
pinv = (ItemStack[]) o;
|
|
} else if (o instanceof List) {
|
|
pinv = ((List<ItemStack>) o).toArray(new ItemStack[0]);
|
|
}
|
|
p.getInventory().setContents(pinv);
|
|
p.updateInventory();
|
|
|
|
ItemStack[] parmor = null;
|
|
o = pinfo.get("armor");
|
|
if (o instanceof ItemStack[]) {
|
|
parmor = (ItemStack[]) o;
|
|
} else if (o instanceof List) {
|
|
parmor = ((List<ItemStack>) o).toArray(new ItemStack[0]);
|
|
}
|
|
p.getInventory().setArmorContents(parmor);
|
|
p.updateInventory();
|
|
|
|
p.sendMessage(ChatColor.GOLD + "[HA] " + ChatColor.GREEN + "Your inventory has been restored!");
|
|
new File(PFilePath, pname + ".yml").delete();
|
|
|
|
while (needInv.contains(pname)) {
|
|
needInv.remove(pname);
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
p.sendMessage(ChatColor.RED + "Something went wrong when trying to restore your inv, please contact an administrator.");
|
|
this.getLogger().warning("Error occured when trying to restore the inv of " + pname + ":");
|
|
System.out.println(e);
|
|
}
|
|
}
|
|
}
|
|
if (p.hasMetadata("HA-Location")) {
|
|
p.removeMetadata("HA-Location", this);
|
|
}
|
|
}
|
|
|
|
public void winner(final Integer a) {
|
|
if (Playing.get(a).size() == 1) {
|
|
String[] Spawncoords;
|
|
if (spawns.getString("Spawn_coordinates." + a) != null) {
|
|
Spawncoords = spawns.getString("Spawn_coordinates." + a).split(",");
|
|
} else {
|
|
Spawncoords = spawns.getString("Spawn_coordinates.0").split(",");
|
|
}
|
|
World spawnw = getServer().getWorld(Spawncoords[3]);
|
|
double spawnx = Double.parseDouble(Spawncoords[0]);
|
|
double spawny = Double.parseDouble(Spawncoords[1]);
|
|
double spawnz = Double.parseDouble(Spawncoords[2]);
|
|
Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
|
|
|
|
for (i = 0; i < Playing.get(a).size(); i++) {
|
|
UUID winnerId = Playing.get(a).get(i);
|
|
final Player winner = getServer().getPlayer(winnerId);
|
|
//TODO: Figure out exactly what needs to be done in this case
|
|
if (winner == null) {
|
|
continue;
|
|
}
|
|
String winnerName = winner.getName();
|
|
if (canJoin.get(a)) {
|
|
getServer().broadcastMessage(ChatColor.GREEN + winnerName + " is the victor of this Hunger Games!");
|
|
}
|
|
winner.getInventory().clear();
|
|
winner.getInventory().setBoots(null);
|
|
winner.getInventory().setChestplate(null);
|
|
winner.getInventory().setHelmet(null);
|
|
winner.getInventory().setLeggings(null);
|
|
winner.setLevel(0);
|
|
for (PotionEffect pe : winner.getActivePotionEffects()) {
|
|
PotionEffectType potion = pe.getType();
|
|
winner.removePotionEffect(potion);
|
|
}
|
|
Tele.add(winner);
|
|
needInv.add(winnerName);
|
|
|
|
winner.teleport(Spawn);
|
|
|
|
this.restoreInventory(winner, winnerName);
|
|
|
|
if (canJoin.get(a)) {
|
|
winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
|
|
scoreboards.remove(winner.getName());
|
|
Kills.remove(winner.getName());
|
|
|
|
////////////////////////////////////////////////////////
|
|
//////////////////// FIREWORKS ///////////////////////
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
|
//Spawn the Fireworks, get the FireworkMeta.
|
|
Firework fw = (Firework) winner.getWorld().spawnEntity(winner.getLocation(), EntityType.FIREWORK);
|
|
FireworkMeta fwm = fw.getFireworkMeta();
|
|
|
|
//Our random generator
|
|
Random r = new Random();
|
|
|
|
//Get the type
|
|
int rt = r.nextInt(4) + 1;
|
|
Type type = Type.BALL;
|
|
if (rt == 1) {
|
|
type = Type.BALL;
|
|
}
|
|
if (rt == 2) {
|
|
type = Type.BALL_LARGE;
|
|
}
|
|
if (rt == 3) {
|
|
type = Type.BURST;
|
|
}
|
|
if (rt == 4) {
|
|
type = Type.CREEPER;
|
|
}
|
|
if (rt == 5) {
|
|
type = Type.STAR;
|
|
}
|
|
|
|
//Get our random colours
|
|
int r1i = r.nextInt(17) + 1;
|
|
int r2i = r.nextInt(17) + 1;
|
|
Color c1 = getColor(r1i);
|
|
Color c2 = getColor(r2i);
|
|
|
|
//Create our effect with this
|
|
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
|
|
|
|
//Then apply the effect to the meta
|
|
fwm.addEffect(effect);
|
|
|
|
//Generate some random power and set it
|
|
int rp = r.nextInt(2) + 1;
|
|
fwm.setPower(rp);
|
|
|
|
//Then apply this to our rocket
|
|
fw.setFireworkMeta(fwm);
|
|
}, 20 + i * 20L);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////
|
|
|
|
if (!config.getBoolean("rewardEco.enabled")) {
|
|
for (ItemStack Rewards : Reward) {
|
|
winner.getInventory().addItem(Rewards);
|
|
}
|
|
} else {
|
|
for (ItemStack Rewards : Reward) {
|
|
winner.getInventory().addItem(Rewards);
|
|
}
|
|
econ.depositPlayer(winner, config.getDouble("rewardEco.reward"));
|
|
}
|
|
}
|
|
|
|
if (deathtime.get(a) != null) {
|
|
getServer().getScheduler().cancelTask(deathtime.get(a));
|
|
deathtime.put(a, null);
|
|
}
|
|
if (graceSchedulerIds.get(a) != null) {
|
|
getServer().getScheduler().cancelTask(graceSchedulerIds.get(a));
|
|
graceSchedulerIds.put(a, null);
|
|
}
|
|
if (start.get(a) != null) {
|
|
getServer().getScheduler().cancelTask(start.get(a));
|
|
start.put(a, null);
|
|
}
|
|
}
|
|
Playing.get(a).clear();
|
|
Quit.get(a).clear();
|
|
Dead.get(a).clear();
|
|
|
|
//Show spectators
|
|
for (UUID s1 : Watching.get(a)) {
|
|
Player spectator = getServer().getPlayer(s1);
|
|
spectator.setAllowFlight(false);
|
|
spectator.teleport(Spawn);
|
|
for (Player online : getServer().getOnlinePlayers()) {
|
|
online.showPlayer(this, spectator);
|
|
}
|
|
}
|
|
if (config.getBoolean("Auto_Restart")) {
|
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a), 220L);
|
|
}
|
|
MatchRunning.put(a, null);
|
|
}
|
|
}
|
|
|
|
private Color getColor(int i) {
|
|
if (i == 1) {
|
|
return Color.AQUA;
|
|
} else if (i == 2) {
|
|
return Color.BLACK;
|
|
} else if (i == 3) {
|
|
return Color.BLUE;
|
|
} else if (i == 4) {
|
|
return Color.FUCHSIA;
|
|
} else if (i == 5) {
|
|
return Color.GRAY;
|
|
} else if (i == 6) {
|
|
return Color.GREEN;
|
|
} else if (i == 7) {
|
|
return Color.LIME;
|
|
} else if (i == 8) {
|
|
return Color.MAROON;
|
|
} else if (i == 9) {
|
|
return Color.NAVY;
|
|
} else if (i == 10) {
|
|
return Color.OLIVE;
|
|
} else if (i == 11) {
|
|
return Color.ORANGE;
|
|
} else if (i == 12) {
|
|
return Color.PURPLE;
|
|
} else if (i == 13) {
|
|
return Color.RED;
|
|
} else if (i == 14) {
|
|
return Color.SILVER;
|
|
} else if (i == 15) {
|
|
return Color.TEAL;
|
|
} else if (i == 16) {
|
|
return Color.WHITE;
|
|
} else {
|
|
return Color.YELLOW;
|
|
}
|
|
}
|
|
|
|
private void scoreboardInit() {
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
|
Collection<? extends Player> online = getServer().getOnlinePlayers();
|
|
for (Player pl : online) {
|
|
updateScoreboard(pl);
|
|
}
|
|
}, 20L, 10L);
|
|
}
|
|
|
|
public void updateScoreboard(Player p) {
|
|
if (getArena(p) != null || isSpectating(p)) {
|
|
if (getArena(p) != null) {
|
|
arenaId = getArena(p).getArenaId();
|
|
} else if (getSpectating(p) != null) {
|
|
arenaId = getSpectating(p).getArenaId();
|
|
}
|
|
if (scoreboards.get(p.getName()) != null && scoreboards.get(p.getName()).getObjective("HA") != null) {
|
|
Scoreboard sb = scoreboards.get(p.getName());
|
|
Objective obj = sb.getObjective("HA");
|
|
if (obj != null) {
|
|
Score kills = obj.getScore(ChatColor.RED + "Kills");
|
|
Score players = obj.getScore(ChatColor.RED + "Players");
|
|
Score spectators = obj.getScore(ChatColor.RED + "Spectators");
|
|
Score allkills = obj.getScore(ChatColor.RED + "Deaths");
|
|
players.setScore(Playing.get(arenaId).size());
|
|
if (Kills.containsKey(p.getName())) {
|
|
kills.setScore(Kills.get(p.getName()));
|
|
}
|
|
if (Kills.containsKey("__SuM__")) {
|
|
allkills.setScore(Kills.get("__SuM__"));
|
|
}
|
|
|
|
if (Watching.get(arenaId) != null) {
|
|
spectators.setScore(Watching.get(arenaId).size());
|
|
}
|
|
if (config.getInt("DeathMatch") != 0) {
|
|
if (timetodeath.get(arenaId) != null) {
|
|
if (timetodeath.get(arenaId) > 0) {
|
|
int ttd = timetodeath.get(arenaId) - timetodeath.get(arenaId) / 60 * 60;
|
|
String secs = String.valueOf((ttd < 10) ? "0" + ttd : ttd);
|
|
obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + timetodeath.get(arenaId) / 60 + ":" + secs);
|
|
} else {
|
|
obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH");
|
|
}
|
|
}
|
|
} else {
|
|
obj.setDisplayName(ChatColor.GREEN + "HungerArena");
|
|
}
|
|
p.setScoreboard(sb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public final HashMap<Integer, Integer> graceSchedulerIds = new HashMap<>();
|
|
public final HashMap<Integer, Integer> start = new HashMap<>();
|
|
public final HashMap<Integer, Integer> deathtime = new HashMap<>();
|
|
public final HashMap<Integer, Integer> timetodeath = new HashMap<>();
|
|
|
|
public void startGames(final int arenaId) {
|
|
if ((MatchRunning.get(arenaId) != null) && (MatchRunning.get(arenaId).equals("true"))) {
|
|
return;
|
|
}
|
|
|
|
final String msg = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message"));
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
|
|
Objective sobj;
|
|
try {
|
|
sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting");
|
|
} catch (NoSuchMethodError e) {
|
|
sobj = scoreboard.registerNewObjective("HA", "HAData");
|
|
sobj.setDisplayName(ChatColor.GREEN + "HA - Starting");
|
|
}
|
|
Score skills = sobj.getScore(ChatColor.RED + "Kills");
|
|
skills.setScore(0);
|
|
Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators");
|
|
sdeaths.setScore(0);
|
|
Score splayers = sobj.getScore(ChatColor.RED + "Players");
|
|
splayers.setScore(0);
|
|
Score allkills = sobj.getScore(ChatColor.RED + "Deaths");
|
|
allkills.setScore(0);
|
|
sobj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
|
Bukkit.getPlayer(gn).setScoreboard(scoreboard);
|
|
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
|
|
}
|
|
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + arenaId);
|
|
MatchRunning.put(arenaId, "true");
|
|
if (start.get(arenaId) != null) {
|
|
getServer().getScheduler().cancelTask(start.get(arenaId));
|
|
}
|
|
if (config.getString("Countdown").equalsIgnoreCase("true")) {
|
|
displayCountDown(arenaId, msg);
|
|
} else {
|
|
Arena arena = arenas.get(arenaId);
|
|
setTorch(arenaId, true);
|
|
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
|
|
if (arenaPlayer.getArena() == arena) {
|
|
arenaPlayer.setFrozen(false);
|
|
}
|
|
}
|
|
if (config.getBoolean("broadcastAll")) {
|
|
getServer().broadcastMessage(msg);
|
|
} else {
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Player g = getServer().getPlayer(gn);
|
|
g.sendMessage(msg);
|
|
}
|
|
}
|
|
}
|
|
canJoin.put(arenaId, true);
|
|
}
|
|
|
|
private void broadCastArenaStartingSoon(int arenaId) {
|
|
if (!config.getBoolean("broadcastAll")) {
|
|
//Broadcast that a game is starting soon to all players in the arena
|
|
for (ArenaPlayer player : arenas.get(arenaId).getArenaPlayers()) {
|
|
player.getPlayer().sendMessage(ChatColor.AQUA + "Game starting in: " + countDownTimer.get(arenaId));
|
|
}
|
|
} else if (!restrictedWorlds) {
|
|
//Broadcast that a game is starting soon to all players
|
|
getServer().broadcastMessage(ChatColor.AQUA + "Game " + arenaId + " starting in: " +
|
|
countDownTimer.get(arenaId));
|
|
} else {
|
|
//Broadcast to all players in the arena world that a game is starting soon
|
|
for (String worldName : worldNames.values()) {
|
|
World world = getServer().getWorld(worldName);
|
|
//If the world doesn't exist, skip it
|
|
if (world == null) {
|
|
continue;
|
|
}
|
|
for (Player worldPlayer : world.getPlayers()) {
|
|
worldPlayer.sendMessage(String.valueOf(countDownTimer.get(arenaId)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void announceGracePeriod(int arenaId) {
|
|
Arena arena = arenas.get(arenaId);
|
|
arena.setGracePeriod(config.getInt("Grace_Period"));
|
|
|
|
if (this.graceSchedulerIds.get(arenaId) == null) {
|
|
return;
|
|
}
|
|
|
|
int taskId = getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
|
//Reduce grace period by one
|
|
arena.setGracePeriod(arena.getGracePeriod() - 1);
|
|
int gracePeriod = arena.getGracePeriod();
|
|
boolean broadcastAll = config.getBoolean("broadcastAll");
|
|
|
|
String gracePeriodMessage = null;
|
|
if (gracePeriod == 30 || gracePeriod == 15 || (gracePeriod < 11 && gracePeriod > 0)) {
|
|
//Print when 30 seconds left, 15 seconds left, and count down from 10
|
|
gracePeriodMessage = ChatColor.GREEN + "Grace period ends in " + gracePeriod + " seconds!";
|
|
} else if (gracePeriod <= 0) {
|
|
//Print when the grace period expires
|
|
gracePeriodMessage = ChatColor.GREEN + "Grace period is over, FIGHT!";
|
|
}
|
|
if (gracePeriodMessage != null) {
|
|
if (broadcastAll) {
|
|
//Broadcast to all players
|
|
getServer().broadcastMessage(gracePeriodMessage);
|
|
} else {
|
|
//Broadcast to all players in the arena's world
|
|
for (Player player : arena.getWorld().getPlayers()) {
|
|
player.sendMessage(gracePeriodMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Cancel the scheduler if the grace period is over
|
|
if (gracePeriod <= 0) {
|
|
getServer().getScheduler().cancelTask(graceSchedulerIds.get(arenaId));
|
|
graceSchedulerIds.put(arenaId, null);
|
|
}
|
|
}, 20L, 20L);
|
|
graceSchedulerIds.put(arenaId, taskId);
|
|
}
|
|
|
|
private void displayCountDown(int arenaId, String msg) {
|
|
countDownTimer.put(arenaId, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10));
|
|
start.put(arenaId, getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
|
if (countDownTimer.get(arenaId) > 0) {
|
|
broadCastArenaStartingSoon(arenaId);
|
|
}
|
|
countDownTimer.put(arenaId, countDownTimer.get(arenaId) - 1);
|
|
if (countDownTimer.get(arenaId) == -1) {
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
|
|
Objective sobj;
|
|
try {
|
|
sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting");
|
|
} catch (NoSuchMethodError e) {
|
|
sobj = scoreboard.registerNewObjective("HA", "HAData");
|
|
sobj.setDisplayName(ChatColor.GREEN + "HA - Starting");
|
|
}
|
|
Score sKills = sobj.getScore(ChatColor.RED + "Kills");
|
|
sKills.setScore(0);
|
|
Score sDeaths = sobj.getScore(ChatColor.RED + "Spectators");
|
|
sDeaths.setScore(0);
|
|
Score sPlayers = sobj.getScore(ChatColor.RED + "Players");
|
|
sPlayers.setScore(0);
|
|
Score allKills = sobj.getScore(ChatColor.RED + "Deaths");
|
|
allKills.setScore(0);
|
|
sobj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
|
Bukkit.getPlayer(gn).setScoreboard(scoreboard);
|
|
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
|
|
}
|
|
Arena arena = arenas.get(arenaId);
|
|
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
|
|
if (arenaPlayer.getArena() == arena) {
|
|
arenaPlayer.setFrozen(false);
|
|
}
|
|
}
|
|
if (config.getBoolean("broadcastAll")) {
|
|
getServer().broadcastMessage(msg);
|
|
} else {
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Player g = getServer().getPlayer(gn);
|
|
g.sendMessage(msg);
|
|
}
|
|
}
|
|
if (config.getInt("Grace_Period") != 0) {
|
|
announceGracePeriod(arenaId);
|
|
}
|
|
if (config.getInt("DeathMatch") != 0) {
|
|
int death = config.getInt("DeathMatch");
|
|
timetodeath.put(arenaId, death * 60);
|
|
if (deathtime.get(arenaId) == null) {
|
|
deathtime.put(arenaId, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), () -> {
|
|
timetodeath.put(arenaId, timetodeath.get(arenaId) - 1);
|
|
if (timetodeath.get(arenaId) % 300 == 0) {
|
|
if (config.getBoolean("broadcastAll")) {
|
|
for (Player wp : location.get(arenaId).get(1).getWorld().getPlayers()) {
|
|
if (timetodeath.get(arenaId) != 0) {
|
|
wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(arenaId) / 60) + ChatColor.RED + " mins till the death match!");
|
|
}
|
|
}
|
|
} else {
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Player g = getServer().getPlayer(gn);
|
|
g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(arenaId)) + ChatColor.RED + " mins till the death match!");
|
|
}
|
|
}
|
|
}
|
|
if (timetodeath.get(arenaId) <= 0) {
|
|
int i = 1;
|
|
for (UUID playing : Playing.get(arenaId)) {
|
|
Player tribute = getServer().getPlayer(playing);
|
|
|
|
Location pLoc = null;
|
|
if (tribute.hasMetadata("HA-Location")) {
|
|
List<MetadataValue> l = tribute.getMetadata("HA-Location");
|
|
if (l != null && l.size() != 0) {
|
|
try {
|
|
pLoc = (Location) l.get(0).value();
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
if (pLoc != null) {
|
|
tribute.teleport(pLoc); //random
|
|
} else {
|
|
tribute.teleport(location.get(arenaId).get(i)); //row
|
|
}
|
|
}
|
|
i += 1;
|
|
for (PotionEffect pe : tribute.getActivePotionEffects()) {
|
|
PotionEffectType potion = pe.getType();
|
|
tribute.removePotionEffect(potion);
|
|
}
|
|
if (tribute.getAllowFlight()) {
|
|
tribute.setAllowFlight(false);
|
|
}
|
|
}
|
|
if (config.getBoolean("broadcastAll")) {
|
|
for (Player wp : location.get(arenaId).get(1).getWorld().getPlayers()) {
|
|
wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(arenaId).size() + " tributes will be facing off!");
|
|
}
|
|
} else {
|
|
for (UUID gn : Playing.get(arenaId)) {
|
|
Player g = getServer().getPlayer(gn);
|
|
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(arenaId).size() + " tributes will be facing off!");
|
|
}
|
|
}
|
|
stopTaskDelayed(deathtime.get(arenaId));
|
|
deathtime.put(arenaId, null);
|
|
}
|
|
}, 20L, 20L));
|
|
}
|
|
}
|
|
setTorch(arenaId, true);
|
|
stopTaskDelayed(start.get(arenaId));
|
|
}
|
|
}, 20L, 20L));
|
|
}
|
|
|
|
private void stopTaskDelayed(final int task) {
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getScheduler().cancelTask(task), 10L);
|
|
}
|
|
|
|
public Arena getArena(Player player) {
|
|
ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
|
|
if (arenaPlayer != null) {
|
|
return arenaPlayer.getArena();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Arena getSpectating(Player player) {
|
|
ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
|
|
if (arenaPlayer != null && arenaPlayer.isWatching()) {
|
|
return arenaPlayer.getArena();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean isSpectating(Player p) {
|
|
return getSpectating(p) != null;
|
|
}
|
|
|
|
public void setTorch(int arenaId, boolean set) {
|
|
if (spawns.getString("Start_torch." + arenaId) != null) {
|
|
String[] torchCoordinates = spawns.getString("Start_torch." + arenaId).split(",");
|
|
double torchX = Double.parseDouble(torchCoordinates[0]);
|
|
double torchY = Double.parseDouble(torchCoordinates[1]);
|
|
double torchZ = Double.parseDouble(torchCoordinates[2]);
|
|
String torchWorldName = torchCoordinates[3];
|
|
World torchWorld = getServer().getWorld(torchWorldName);
|
|
Location torchLocation = new Location(torchWorld, torchX, torchY, torchZ);
|
|
if (set) {
|
|
torchLocation.getBlock().setType(Material.REDSTONE_TORCH);
|
|
} else {
|
|
torchLocation.getBlock().setType(Material.AIR);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|