Advertisement
Guest User

Main Class

a guest
Jun 22nd, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.18 KB | None | 0 0
  1. package com.pixelyeti.goldsiege;
  2.  
  3. import com.pixelyeti.goldsiege.GameMechs.MapManager;
  4. import com.pixelyeti.goldsiege.Listeners.PlayerInteract;
  5. import com.pixelyeti.goldsiege.Listeners.Join;
  6. import com.pixelyeti.goldsiege.Listeners.InvClick;
  7. import com.pixelyeti.goldsiege.Listeners.NameTag;
  8. import com.pixelyeti.goldsiege.GameMechs.Teams;
  9. import com.pixelyeti.goldsiege.Util.FileManager;
  10. import com.pixelyeti.goldsiege.Util.TeamGUI;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.configuration.ConfigurationSection;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.configuration.file.YamlConfiguration;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. import java.io.File;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.util.List;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23.  
  24. /**
  25.  * Created by Callum on 09/06/2015.
  26.  */
  27. public class Main extends JavaPlugin {
  28.  
  29.     public final PlayerInteract PlayerInteract = new PlayerInteract();
  30.     public final Join Join = new Join(this);
  31.     public final InvClick InvClick = new InvClick();
  32.     public final NameTag NameTag = new NameTag();
  33.  
  34.     public static String[] teams = null;
  35.     public static boolean postEnabled = false;
  36.     public ConfigurationSection mapSection = getConfig().getConfigurationSection("Maps");
  37.  
  38.     public static final Logger log = Logger.getLogger("Minecraft");
  39.  
  40.     public static YamlConfiguration config;
  41.     public static File configFile;
  42.  
  43.     public static Main plugin;
  44.  
  45.     public void onEnable() {
  46.         plugin = this;
  47.  
  48.         createConfigFile();
  49.         reloadConfig();
  50.  
  51.         TeamGUI.initiate();
  52.  
  53.         saveConfig();
  54.         getServer().getPluginManager().registerEvents(PlayerInteract, this);
  55.         getServer().getPluginManager().registerEvents(Join, this);
  56.         getServer().getPluginManager().registerEvents(InvClick, this);
  57.         getServer().getPluginManager().registerEvents(NameTag, this);
  58.  
  59.     }
  60.  
  61.     public void onDisable() {
  62.     }
  63.  
  64.     public static ConfigurationSection mapSection() { return mapSection(); }
  65.  
  66.     public static void postEnable(FileConfiguration config) {
  67.         MapManager.initiateMaps();
  68.         int count = 0;
  69.  
  70.         for (String s : config.getConfigurationSection("Game.Teams").getKeys(false)) {
  71.             teams[count] = s;
  72.             count++;
  73.         }
  74.  
  75.         Teams.loadTeams();
  76.         Teams.creatingTeams(teams.length, teams, true);
  77.         Teams.applyRandPrefix();
  78.  
  79.         postEnabled = true;
  80.     }
  81.  
  82.     public void createConfigFile() {
  83.         configFile = new File(getDataFolder(), "config.yml");
  84.         if (!configFile.exists()) {
  85.             try {
  86.                 configFile.createNewFile();
  87.             } catch (IOException e) {
  88.                 getLogger().severe("[GoldSiege]" + ChatColor.DARK_RED
  89.                         + "Could not create config file");
  90.             }
  91.  
  92.             saveConfigFile();
  93.  
  94.             setupConfigFile();
  95.  
  96.             reloadConfigFile();
  97.         }
  98.  
  99.         config = YamlConfiguration.loadConfiguration(configFile);
  100.     }
  101.     public void setupConfigFile() {
  102.         String[] teams = {"Red", "Blue"};
  103.  
  104.         getConfigFile().set("Game.TeamAmount", 2);
  105.         getConfigFile().set("Game.Teams", teams);
  106.         getConfigFile().set("Game.Spectate", true);
  107.         getConfigFile().set("Maps.Example.Name", "Example");
  108.         getConfigFile().set("Maps.Example.NumTeams", 2);
  109.         getConfigFile().set("Maps.Example.WorldFileName", "example");
  110.         getConfigFile().set("Maps.Example.Saving", false);
  111.         getConfigFile().set("Maps.Example.Spawns.1.x", 1);
  112.         getConfigFile().set("Maps.Example.Spawns.1.y", 1);
  113.         getConfigFile().set("Maps.Example.Spawns.1.z", 1);
  114.         getConfigFile().set("Maps.Example.Spawns.1.yaw", 1);
  115.         getConfigFile().set("Maps.Example.Spawns.1.pitch", 1);
  116.         getConfigFile().set("Maps.Example.Spawns.2.x", 1);
  117.         getConfigFile().set("Maps.Example.Spawns.2.y", 1);
  118.         getConfigFile().set("Maps.Example.Spawns.2.z", 1);
  119.         getConfigFile().set("Maps.Example.Spawns.2.yaw", 1);
  120.         getConfigFile().set("Maps.Example.Spawns.2.pitch", 1);
  121.  
  122.         saveConfigFile();
  123.     }
  124.  
  125.     public void saveConfigFile() {
  126.         if (config == null || configFile == null) {
  127.             return;
  128.         }
  129.         try {
  130.             getConfigFile().save(configFile);
  131.         } catch (IOException ex) {
  132.             log.log(Level.SEVERE,
  133.                     "Could not save config to " + configFile, ex);
  134.         }
  135.     }
  136.  
  137.     public FileConfiguration getConfigFile() {
  138.         if (config == null) {
  139.             reloadConfigFile();
  140.         }
  141.         return config;
  142.     }
  143.  
  144.     public final void reloadConfigFile() {
  145.         if (configFile == null) {
  146.             configFile = new File(getDataFolder(), "config.yml");
  147.         }
  148.         config = YamlConfiguration.loadConfiguration(Main.configFile);
  149.         InputStream defConfigStream = getResource("config.yml");
  150.         if (defConfigStream != null) {
  151.             YamlConfiguration defConfig = YamlConfiguration
  152.                     .loadConfiguration(defConfigStream);
  153.             config.setDefaults(defConfig);
  154.         }
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement