160 lines
6.2 KiB
Java
Raw Normal View History

2012-07-17 15:50:34 -06:00
package me.Travja.HungerArena;
2012-07-18 07:14:50 +10:00
2012-08-29 17:58:39 -06:00
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
2012-07-18 07:14:50 +10:00
import java.util.ArrayList;
import java.util.HashSet;
2012-08-25 11:58:12 -06:00
import java.util.List;
2012-08-29 17:58:39 -06:00
import java.util.logging.Level;
2012-07-18 07:14:50 +10:00
import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration;
2012-08-29 17:58:39 -06:00
import org.bukkit.configuration.file.YamlConfiguration;
2012-07-18 07:14:50 +10:00
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
static final Logger log = Logger.getLogger("Minecraft");
public ArrayList<String> Playing = new ArrayList<String>();
public ArrayList<String> Ready = new ArrayList<String>();
public ArrayList<String> Dead = new ArrayList<String>();
public ArrayList<String> Quit = new ArrayList<String>();
public ArrayList<String> Out = new ArrayList<String>();
public ArrayList<String> Watching = new ArrayList<String>();
public ArrayList<String> NeedConfirm = new ArrayList<String>();
public HashSet<String> Frozen = new HashSet<String>();
2012-08-25 11:58:12 -06:00
public List<String> worlds;
2012-07-18 07:14:50 +10:00
public Listener DeathListener = new DeathListener(this);
public Listener SpectatorListener = new SpectatorListener(this);
public Listener FreezeListener = new FreezeListener(this);
public Listener JoinAndQuitListener = new JoinAndQuitListener(this);
public Listener ChatListener = new ChatListener(this);
public Listener Chests = new Chests(this);
public Listener PvP = new PvP(this);
public Listener Blocks = new Blocks(this);
public Listener CommandBlock = new CommandBlock(this);
2012-07-17 15:50:34 -06:00
public Listener Damage = new DmgListener(this);
public Listener Teleport = new TeleportListener(this);
2012-07-18 07:14:50 +10:00
public Listener Signs = new Signs(this);
public Listener BlockStorage = new BlockStorage(this);
2012-07-17 15:50:34 -06:00
public Listener WinGames = new WinGamesListener(this);
2012-07-18 07:14:50 +10:00
public CommandExecutor HaCommands = new HaCommands(this);
public CommandExecutor SponsorCommands = new SponsorCommands(this);
public CommandExecutor SpawnsCommand = new SpawnsCommand(this);
public boolean canjoin;
public boolean exists;
2012-08-25 10:09:49 -06:00
public boolean restricted;
2012-08-29 17:58:39 -06:00
public boolean open = true;
2012-07-17 17:06:57 -06:00
public FileConfiguration config;
2012-08-29 17:58:39 -06:00
public FileConfiguration spawns = null;
public File spawnsFile = null;
2012-07-18 07:14:50 +10:00
public ItemStack Reward;
public ItemStack Cost;
2012-07-17 15:50:34 -06:00
public boolean vault = false;
public Economy econ = null;
2012-07-18 07:14:50 +10:00
public void onEnable(){
2012-07-17 17:06:57 -06:00
config = this.getConfig();
2012-07-18 07:14:50 +10:00
config.options().copyDefaults(true);
this.saveDefaultConfig();
2012-08-29 17:58:39 -06:00
this.getSpawns();
spawns.options().copyDefaults(true);
this.saveSpawns();
2012-07-17 17:06:57 -06:00
log.info("[HungerArena] enabled v" + getDescription().getVersion());
2012-07-18 07:14:50 +10:00
getServer().getPluginManager().registerEvents(DeathListener, this);
getServer().getPluginManager().registerEvents(SpectatorListener, 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(Blocks, this);
getServer().getPluginManager().registerEvents(CommandBlock, this);
getServer().getPluginManager().registerEvents(Signs, this);
getServer().getPluginManager().registerEvents(BlockStorage, this);
2012-07-17 15:50:34 -06:00
getServer().getPluginManager().registerEvents(WinGames, this);
getServer().getPluginManager().registerEvents(Damage, this);
2012-07-18 07:14:50 +10:00
getCommand("Ha").setExecutor(HaCommands);
getCommand("Sponsor").setExecutor(SponsorCommands);
getCommand("Startpoint").setExecutor(SpawnsCommand);
2012-07-17 15:50:34 -06:00
if (setupEconomy()) {
log.info(ChatColor.AQUA + "[HungerArena] Found Vault! Hooking in for economy!");
}
if (config.getDouble("config.version") != 1.3) {
config.set("config.version", 1.3);
config.set("eco.enabled", false);
config.set("eco.reward", 100);
}
if (config.getBoolean("eco.enabled", true)) {
if (vault == true) {
log.info(ChatColor.AQUA + "Economy hook deployed.");
} else {
log.info(ChatColor.RED + "You want economy support... yet you don't have Vault. Sorry, can't give you it.");
}
}
if (config.getBoolean("eco.enabled", false)) {
if (vault == true) {
log.info(ChatColor.GREEN + "We see that you have Vault on your server. To set economy support to true, enable it in the config.");
}
}
2012-07-18 07:14:50 +10:00
Reward = new ItemStack(config.getInt("Reward.ID"), config.getInt("Reward.Amount"));
Cost = new ItemStack(config.getInt("Sponsor_Cost.ID"), config.getInt("Sponsor_Cost.Amount"));
2012-08-25 11:58:12 -06:00
worlds = config.getStringList("worlds");
if(worlds.isEmpty()){
2012-08-25 10:09:49 -06:00
restricted = false;
2012-08-25 11:58:12 -06:00
}else if(!worlds.isEmpty()){
2012-08-25 10:09:49 -06:00
restricted = true;
}
2012-07-18 07:14:50 +10:00
}
2012-07-17 15:50:34 -06:00
public void onDisable(){
log.info("[HungerArena] disabled v" + getDescription().getVersion());
}
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 econ != null;
}
2012-08-29 17:58:39 -06:00
public void reloadSpawns() {
if (spawnsFile == null) {
spawnsFile = new File(getDataFolder(), "spawns.yml");
}
spawns = YamlConfiguration.loadConfiguration(spawnsFile);
// Look for defaults in the jar
InputStream defConfigStream = this.getResource("spawns.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
spawns.setDefaults(defConfig);
}
}
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);
}
}
2012-07-18 07:14:50 +10:00
}