Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pixelyeti.goldsiege;
- import com.pixelyeti.goldsiege.GameMechs.MapManager;
- import com.pixelyeti.goldsiege.Listeners.PlayerInteract;
- import com.pixelyeti.goldsiege.Listeners.Join;
- import com.pixelyeti.goldsiege.Listeners.InvClick;
- import com.pixelyeti.goldsiege.Listeners.NameTag;
- import com.pixelyeti.goldsiege.GameMechs.Teams;
- import com.pixelyeti.goldsiege.Util.FileManager;
- import com.pixelyeti.goldsiege.Util.TeamGUI;
- import org.bukkit.ChatColor;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- * Created by Callum on 09/06/2015.
- */
- public class Main extends JavaPlugin {
- public final PlayerInteract PlayerInteract = new PlayerInteract();
- public final Join Join = new Join(this);
- public final InvClick InvClick = new InvClick();
- public final NameTag NameTag = new NameTag();
- public static String[] teams = null;
- public static boolean postEnabled = false;
- public ConfigurationSection mapSection = getConfig().getConfigurationSection("Maps");
- public static final Logger log = Logger.getLogger("Minecraft");
- public static YamlConfiguration config;
- public static File configFile;
- public static Main plugin;
- public void onEnable() {
- plugin = this;
- createConfigFile();
- reloadConfig();
- TeamGUI.initiate();
- saveConfig();
- getServer().getPluginManager().registerEvents(PlayerInteract, this);
- getServer().getPluginManager().registerEvents(Join, this);
- getServer().getPluginManager().registerEvents(InvClick, this);
- getServer().getPluginManager().registerEvents(NameTag, this);
- }
- public void onDisable() {
- }
- public static ConfigurationSection mapSection() { return mapSection(); }
- public static void postEnable(FileConfiguration config) {
- MapManager.initiateMaps();
- int count = 0;
- for (String s : config.getConfigurationSection("Game.Teams").getKeys(false)) {
- teams[count] = s;
- count++;
- }
- Teams.loadTeams();
- Teams.creatingTeams(teams.length, teams, true);
- Teams.applyRandPrefix();
- postEnabled = true;
- }
- public void createConfigFile() {
- configFile = new File(getDataFolder(), "config.yml");
- if (!configFile.exists()) {
- try {
- configFile.createNewFile();
- } catch (IOException e) {
- getLogger().severe("[GoldSiege]" + ChatColor.DARK_RED
- + "Could not create config file");
- }
- saveConfigFile();
- setupConfigFile();
- reloadConfigFile();
- }
- config = YamlConfiguration.loadConfiguration(configFile);
- }
- public void setupConfigFile() {
- String[] teams = {"Red", "Blue"};
- getConfigFile().set("Game.TeamAmount", 2);
- getConfigFile().set("Game.Teams", teams);
- getConfigFile().set("Game.Spectate", true);
- getConfigFile().set("Maps.Example.Name", "Example");
- getConfigFile().set("Maps.Example.NumTeams", 2);
- getConfigFile().set("Maps.Example.WorldFileName", "example");
- getConfigFile().set("Maps.Example.Saving", false);
- getConfigFile().set("Maps.Example.Spawns.1.x", 1);
- getConfigFile().set("Maps.Example.Spawns.1.y", 1);
- getConfigFile().set("Maps.Example.Spawns.1.z", 1);
- getConfigFile().set("Maps.Example.Spawns.1.yaw", 1);
- getConfigFile().set("Maps.Example.Spawns.1.pitch", 1);
- getConfigFile().set("Maps.Example.Spawns.2.x", 1);
- getConfigFile().set("Maps.Example.Spawns.2.y", 1);
- getConfigFile().set("Maps.Example.Spawns.2.z", 1);
- getConfigFile().set("Maps.Example.Spawns.2.yaw", 1);
- getConfigFile().set("Maps.Example.Spawns.2.pitch", 1);
- saveConfigFile();
- }
- public void saveConfigFile() {
- if (config == null || configFile == null) {
- return;
- }
- try {
- getConfigFile().save(configFile);
- } catch (IOException ex) {
- log.log(Level.SEVERE,
- "Could not save config to " + configFile, ex);
- }
- }
- public FileConfiguration getConfigFile() {
- if (config == null) {
- reloadConfigFile();
- }
- return config;
- }
- public final void reloadConfigFile() {
- if (configFile == null) {
- configFile = new File(getDataFolder(), "config.yml");
- }
- config = YamlConfiguration.loadConfiguration(Main.configFile);
- InputStream defConfigStream = getResource("config.yml");
- if (defConfigStream != null) {
- YamlConfiguration defConfig = YamlConfiguration
- .loadConfiguration(defConfigStream);
- config.setDefaults(defConfig);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement