Search in sources :

Example 1 with SignBase

use of au.com.mineauz.minigames.signs.SignBase in project Minigames by AddstarMC.

the class Minigames method onEnable.

public void onEnable() {
    try {
        plugin = this;
        PluginDescriptionFile desc = this.getDescription();
        MinigameSave sv = new MinigameSave("lang/" + getConfig().getString("lang"));
        lang = sv.getConfig();
        loadLang();
        lang.setDefaults(defLang);
        getLogger().info("Using lang " + getConfig().getString("lang"));
        String prespath = getDataFolder() + "/presets/";
        String[] presets = { "spleef", "lms", "ctf", "infection" };
        File pres;
        for (String preset : presets) {
            pres = new File(prespath + preset + ".yml");
            if (!pres.exists()) {
                saveResource("presets/" + preset + ".yml", false);
            }
        }
        mdata = new MinigameData();
        pdata = new PlayerData();
        display = new DisplayManager();
        mdata.addMinigameType(new SingleplayerType());
        //		mdata.addMinigameType(new FreeForAllType());
        //		mdata.addMinigameType(new TeamsType());
        mdata.addMinigameType(new MultiplayerType());
        MinigameSave completion = new MinigameSave("completion");
        mdata.addConfigurationFile("completion", completion.getConfig());
        getServer().getPluginManager().registerEvents(new Events(), this);
        getServer().getPluginManager().registerEvents(new BasicRecorder(), this);
        try {
            this.getConfig().load(this.getDataFolder() + "/config.yml");
            List<String> mgs = new ArrayList<String>();
            if (getConfig().contains("minigames")) {
                mgs = getConfig().getStringList("minigames");
            }
            final List<String> allMGS = new ArrayList<String>();
            allMGS.addAll(mgs);
            if (!mgs.isEmpty()) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        for (String minigame : allMGS) {
                            final Minigame game = new Minigame(minigame);
                            try {
                                game.loadMinigame();
                                mdata.addMinigame(game);
                            } catch (Exception e) {
                                getLogger().severe(ChatColor.RED.toString() + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
                                e.printStackTrace();
                            }
                        }
                    }
                }, 1L);
            }
        } catch (FileNotFoundException ex) {
            log.info("Failed to load config, creating one.");
            try {
                this.getConfig().save(this.getDataFolder() + "/config.yml");
            } catch (IOException e) {
                log.log(Level.SEVERE, "Could not save config.yml!");
                e.printStackTrace();
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to load config!");
            e.printStackTrace();
        }
        if (!setupEconomy()) {
            getLogger().info("No Vault plugin found! You may only reward items.");
        }
        backend = new BackendManager(getLogger());
        if (!backend.initialize(getConfig())) {
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        getConfig().options().copyDefaults(true);
        saveConfig();
        Calendar cal = Calendar.getInstance();
        if (cal.get(Calendar.DAY_OF_MONTH) == 21 && cal.get(Calendar.MONTH) == 8 || cal.get(Calendar.DAY_OF_MONTH) == 25 && cal.get(Calendar.MONTH) == 11 || cal.get(Calendar.DAY_OF_MONTH) == 1 && cal.get(Calendar.MONTH) == 0) {
            getLogger().info(ChatColor.GREEN.name() + "Party Mode enabled!");
            pdata.setPartyMode(true);
        }
        //		pdata.loadDCPlayers();
        pdata.loadDeniedCommands();
        MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
        Set<String> keys = globalLoadouts.getConfig().getKeys(false);
        for (String loadout : keys) {
            mdata.addLoadout(loadout);
            Set<String> items = globalLoadouts.getConfig().getConfigurationSection(loadout).getKeys(false);
            //			}
            for (String slot : items) {
                if (slot.matches("[0-9]+"))
                    mdata.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + "." + slot), Integer.parseInt(slot));
            }
            if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
                Set<String> pots = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions").getKeys(false);
                for (String eff : pots) {
                    if (PotionEffectType.getByName(eff) != null) {
                        PotionEffect effect = new PotionEffect(PotionEffectType.getByName(eff), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
                        mdata.getLoadout(loadout).addPotionEffect(effect);
                    }
                }
            }
            if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
                mdata.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
            }
        }
        minigameSigns = new SignBase();
        mdata.loadRewardSigns();
        CommandDispatcher disp = new CommandDispatcher();
        getCommand("minigame").setExecutor(disp);
        getCommand("minigame").setTabCompleter(disp);
        for (Player player : getServer().getOnlinePlayers()) {
            pdata.addMinigamePlayer(player);
        }
        initMetrics();
        log.info(desc.getName() + " successfully enabled.");
    } catch (Throwable e) {
        plugin = null;
        getLogger().log(Level.SEVERE, "Failed to enable Minigames " + getDescription().getVersion() + ": ", e);
        getPluginLoader().disablePlugin(this);
    }
}
Also used : SingleplayerType(au.com.mineauz.minigames.gametypes.SingleplayerType) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) BasicRecorder(au.com.mineauz.minigames.blockRecorder.BasicRecorder) MultiplayerType(au.com.mineauz.minigames.gametypes.MultiplayerType) CommandDispatcher(au.com.mineauz.minigames.commands.CommandDispatcher) Player(org.bukkit.entity.Player) Calendar(java.util.Calendar) IOException(java.io.IOException) BackendManager(au.com.mineauz.minigames.backend.BackendManager) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SignBase(au.com.mineauz.minigames.signs.SignBase) DisplayManager(au.com.mineauz.minigames.display.DisplayManager) Minigame(au.com.mineauz.minigames.minigame.Minigame) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Aggregations

BackendManager (au.com.mineauz.minigames.backend.BackendManager)1 BasicRecorder (au.com.mineauz.minigames.blockRecorder.BasicRecorder)1 CommandDispatcher (au.com.mineauz.minigames.commands.CommandDispatcher)1 DisplayManager (au.com.mineauz.minigames.display.DisplayManager)1 MultiplayerType (au.com.mineauz.minigames.gametypes.MultiplayerType)1 SingleplayerType (au.com.mineauz.minigames.gametypes.SingleplayerType)1 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 SignBase (au.com.mineauz.minigames.signs.SignBase)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Player (org.bukkit.entity.Player)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1 PotionEffect (org.bukkit.potion.PotionEffect)1