Search in sources :

Example 6 with ASkyBlock

use of com.wasteofplastic.askyblock.ASkyBlock in project askyblock by tastybento.

the class ControlPanel method loadControlPanel.

/**
 * This loads the control panel from the controlpanel.yml file
 */
public static void loadControlPanel() {
    ASkyBlock plugin = ASkyBlock.getPlugin();
    // Map of known panel contents by name
    panels.clear();
    // Map of panel inventories by name
    controlPanel.clear();
    cpFile = Util.loadYamlFile("controlpanel.yml");
    ConfigurationSection controlPanels = cpFile.getRoot();
    if (controlPanels == null) {
        plugin.getLogger().severe("Controlpanel.yml is corrupted! Delete so it can be regenerated or fix!");
        return;
    }
    // Go through the yml file and create inventories and panel maps
    for (String panel : controlPanels.getKeys(false)) {
        // plugin.getLogger().info("DEBUG: Panel " + panel);
        ConfigurationSection panelConf = cpFile.getConfigurationSection(panel);
        if (panelConf != null) {
            // New panel map
            HashMap<Integer, CPItem> cp = new HashMap<Integer, CPItem>();
            String panelName = ChatColor.translateAlternateColorCodes('&', panelConf.getString("panelname", "Commands"));
            if (panel.equalsIgnoreCase("default")) {
                defaultPanelName = panelName;
            }
            ConfigurationSection buttons = cpFile.getConfigurationSection(panel + ".buttons");
            if (buttons != null) {
                // Get how many buttons can be in the CP
                int size = buttons.getKeys(false).size() + 8;
                size -= (size % 9);
                // Add inventory to map of inventories
                controlPanel.put(panelName, Bukkit.createInventory(null, size, panelName));
                // Run through buttons
                int slot = 0;
                for (String item : buttons.getKeys(false)) {
                    try {
                        String m = buttons.getString(item + ".material", "BOOK");
                        // Split off damage
                        String[] icon = m.split(":");
                        Material material = Material.matchMaterial(icon[0]);
                        if (material == null) {
                            material = Material.PAPER;
                            plugin.getLogger().severe("Error in controlpanel.yml " + icon[0] + " is an unknown material, using paper.");
                        }
                        String description = ChatColor.translateAlternateColorCodes('&', buttons.getString(item + ".description", ""));
                        String command = buttons.getString(item + ".command", "").replace("[island]", Settings.ISLANDCOMMAND);
                        String nextSection = buttons.getString(item + ".nextsection", "");
                        ItemStack i = new ItemStack(material);
                        if (icon.length == 2) {
                            i.setDurability(Short.parseShort(icon[1]));
                        }
                        CPItem cpItem = new CPItem(i, description, command, nextSection);
                        cp.put(slot, cpItem);
                        controlPanel.get(panelName).setItem(slot, cpItem.getItem());
                        slot++;
                    } catch (Exception e) {
                        plugin.getLogger().warning("Problem loading control panel " + panel + " item #" + slot);
                        plugin.getLogger().warning(e.getMessage());
                        e.printStackTrace();
                    }
                }
                // Add overall control panel
                panels.put(panelName, cp);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ASkyBlock(com.wasteofplastic.askyblock.ASkyBlock) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 7 with ASkyBlock

use of com.wasteofplastic.askyblock.ASkyBlock in project askyblock by tastybento.

the class ControlPanel method loadShop.

// The first parameter, is the inventory owner. I make it null to let
// everyone use it.
// The second parameter, is the slots in a inventory. Must be a multiple of
// 9. Can be up to 54.
// The third parameter, is the inventory name. This will accept chat colors.
/**
 * This loads the minishop from the minishop.yml file
 */
public static void loadShop() {
    // The first parameter is the Material, then the durability (if wanted),
    // slot, descriptions
    // Minishop
    store.clear();
    miniShopFile = Util.loadYamlFile("minishop.yml");
    allowSelling = miniShopFile.getBoolean("config.allowselling", false);
    ConfigurationSection items = miniShopFile.getConfigurationSection("items");
    ASkyBlock plugin = ASkyBlock.getPlugin();
    if (items != null) {
        // Create the store
        // Get how many the store should be
        int size = items.getKeys(false).size() + 8;
        size -= (size % 9);
        miniShop = Bukkit.createInventory(null, size, plugin.myLocale().islandMiniShopTitle);
        // Run through items
        int slot = 0;
        for (String item : items.getKeys(false)) {
            try {
                String m = items.getString(item + ".material");
                Material material = Material.matchMaterial(m);
                int quantity = items.getInt(item + ".quantity", 0);
                String extra = items.getString(item + ".extra", "");
                double price = items.getDouble(item + ".price", -1D);
                double sellPrice = items.getDouble(item + ".sellprice", -1D);
                if (!allowSelling) {
                    sellPrice = -1;
                }
                String description = ChatColor.translateAlternateColorCodes('&', items.getString(item + ".description", ""));
                MiniShopItem shopItem = new MiniShopItem(material, extra, slot, description, quantity, price, sellPrice);
                store.put(slot, shopItem);
                miniShop.setItem(slot, shopItem.getItem());
                slot++;
            } catch (Exception e) {
                plugin.getLogger().warning("Problem loading minishop item #" + slot);
                plugin.getLogger().warning(e.getMessage());
                e.printStackTrace();
            }
        }
    }
}
Also used : ASkyBlock(com.wasteofplastic.askyblock.ASkyBlock) Material(org.bukkit.Material) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ASkyBlock (com.wasteofplastic.askyblock.ASkyBlock)7 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 EventHandler (org.bukkit.event.EventHandler)4 HashMultiset (com.google.common.collect.HashMultiset)2 Multiset (com.google.common.collect.Multiset)2 Island (com.wasteofplastic.askyblock.Island)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Location (org.bukkit.Location)2 Biome (org.bukkit.block.Biome)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ASLocale (com.wasteofplastic.askyblock.ASLocale)1 FileLister (com.wasteofplastic.askyblock.FileLister)1 SettingsFlag (com.wasteofplastic.askyblock.Island.SettingsFlag)1 SetBiome (com.wasteofplastic.askyblock.panels.SetBiome)1