chumanista

Untitled

Jun 29th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. package com.chumanista.youtube;
  2.  
  3. import java.io.File;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  7. import org.bukkit.configuration.ConfigurationSection;
  8. import org.bukkit.configuration.file.YamlConfiguration;
  9. import org.bukkit.inventory.ItemStack;
  10.  
  11. public class FileManager {
  12.    
  13.     public static void checkFiles() {
  14.        
  15.         if (!PremiumCase.getPlugin().getDataFolder().exists()) {
  16.             PremiumCase.getPlugin().getDataFolder().mkdir();
  17.         }
  18.        
  19.         if (!new File(PremiumCase.getPlugin().getDataFolder(), "config.yml").exists()) {
  20.             PremiumCase.getPlugin().saveDefaultConfig();
  21.         }
  22.        
  23.         if (!new File(PremiumCase.getPlugin().getDataFolder(), "caseDrop.yml").exists()) {
  24.             PremiumCase.getPlugin().saveResource("caseDrop.yml", true);
  25.         }
  26.     }  
  27.    
  28.     public static void loadDrop() {
  29.         YamlConfiguration caseDrop = YamlConfiguration.loadConfiguration(new File(PremiumCase.getPlugin().getDataFolder(), "caseDrop.yml"));
  30.         ConfigurationSection cs1 = caseDrop.getConfigurationSection("PremiumCaseDrop");
  31.        
  32.         ItemToDrop i = new ItemToDrop();
  33.        
  34.         for (String s : cs1.getKeys(false)) {
  35.             ConfigurationSection cs = cs1.getConfigurationSection(s);
  36.             i.setPremiumCase(ItemStacks.getPremiumCase());
  37.            
  38.             Material dm = Material.matchMaterial(cs.getString("material").toUpperCase());
  39.             if (dm == null) {
  40.                 Utils.error(s + " -> Wrong 'material' name!");
  41.                 Bukkit.getPluginManager().disablePlugin(PremiumCase.getPlugin());
  42.             }
  43.            
  44.             i.setDrop(new ItemStack(dm, 1, (short) (cs.getString("metadata") != null ? (short) cs.getInt("metadata") : 0)));
  45.            
  46.             if (cs.getDouble("chance") == 0) {
  47.                 Utils.error(s + " -> Wrong 'chance'! Data must be higher than 0.0!");
  48.                 Bukkit.getPluginManager().disablePlugin(PremiumCase.getPlugin());
  49.             }
  50.            
  51.             i.setChance(cs.getDouble("chance"));
  52.             int min = cs.getInt("minAmount");
  53.             int max = cs.getInt("maxAmount");
  54.            
  55.             if (min > max) {
  56.                 Utils.error(s + " -> Wrong 'minAmount'! maxAmount must be higher than minAmount!");
  57.                 Bukkit.getPluginManager().disablePlugin(PremiumCase.getPlugin());
  58.             }
  59.            
  60.             if (min == 0 || max == 0) {
  61.                 min = 1;
  62.                 max = 1;
  63.             }
  64.            
  65.             i.setMinAmount(min);
  66.             i.setMaxAmount(max);
  67.         }
  68.        
  69.         PremiumCase.dropy.add(i);
  70.     }
  71. }
Add Comment
Please, Sign In to add comment