Guest User

Untitled

a guest
May 11th, 2016
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import org.bukkit.Material;
  3. import org.bukkit.Server;
  4. import org.bukkit.configuration.file.*;
  5. import org.bukkit.inventory.*;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7.  
  8. public class ReCraft extends JavaPlugin
  9. {
  10.  
  11. public ReCraft()
  12. {
  13. customConfig = null;
  14. customConfigFile = null;
  15. }
  16.  
  17. public void onDisabled()
  18. {
  19. System.out.println("[РЕВЕРС-КРАФТ] Выгрузка рецетов.");
  20. getServer().resetRecipes();
  21. System.out.println("[РЕВЕРС-КРАФТ] Теперь отключён.");
  22. }
  23.  
  24. public void onEnable()
  25. {
  26. System.out.println("[РЕВЕРС-КРАФТ] Загрузка рецетов.");
  27. System.out.println((new StringBuilder("[РЕВЕРС-КРАФТ] Коэфициент возврата: ")).append(getConfig().getDouble("Factor")).toString());
  28. LoadConfiguration();
  29. for(int i = 0; i < getConfig().getInt("BurnR"); i++)
  30. {
  31. String number = String.valueOf(i);
  32. String name = getCustomConfig().getString((new StringBuilder("burn.")).append(number).append(".name").toString());
  33. String materialItemStack = getCustomConfig().getString((new StringBuilder("burn.")).append(number).append(".material").toString());
  34. Integer quantity = Integer.valueOf((int)Math.round((double)getCustomConfig().getInt((new StringBuilder("burn.")).append(number).append(".quantity").toString()) * getConfig().getDouble("Factor")));
  35. ItemStack material = new ItemStack(Material.getMaterial(materialItemStack), quantity.intValue());
  36. FurnaceRecipe recipe = new FurnaceRecipe(material, Material.getMaterial(name));
  37. getServer().addRecipe(recipe);
  38. }
  39.  
  40. for(int i = 0; i < getConfig().getInt("CrafR"); i++)
  41. {
  42. String number = String.valueOf(i);
  43. String name = getCustomConfig().getString((new StringBuilder("craft.")).append(number).append(".name").toString());
  44. String materialItemStack = getCustomConfig().getString((new StringBuilder("craft.")).append(number).append(".material").toString());
  45. Integer quantity = Integer.valueOf((int)Math.round((double)getCustomConfig().getInt((new StringBuilder("craft.")).append(number).append(".quantity").toString()) * getConfig().getDouble("Factor")));
  46. ItemStack material = new ItemStack(Material.getMaterial(materialItemStack), quantity.intValue());
  47. ShapelessRecipe recipe = (new ShapelessRecipe(material)).addIngredient(Material.getMaterial(name));
  48. getServer().addRecipe(recipe);
  49. }
  50.  
  51. System.out.println("[РЕВЕРС-КРАФТ] Рецепты загружены.");
  52. System.out.println("[РЕВЕРС-КРАФТ] Теперь включён.");
  53. }
  54.  
  55. public void LoadConfiguration()
  56. {
  57. String factor = "Factor";
  58. String burnr = "BurnR";
  59. String crafr = "CrafR";
  60. getConfig().addDefault(factor, Integer.valueOf(1));
  61. getConfig().addDefault(burnr, Integer.valueOf(1));
  62. getConfig().addDefault(crafr, Integer.valueOf(1));
  63. getConfig().options().copyDefaults(true);
  64. saveConfig();
  65. }
  66.  
  67. public void reloadCustomConfig()
  68. {
  69. if(customConfigFile == null)
  70. customConfigFile = new File(getDataFolder(), "items.yml");
  71. customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
  72. InputStream defConfigStream = getResource("items.yml");
  73. if(defConfigStream != null)
  74. {
  75. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  76. customConfig.setDefaults(defConfig);
  77. }
  78. }
  79.  
  80. public FileConfiguration getCustomConfig()
  81. {
  82. if(customConfig == null)
  83. reloadCustomConfig();
  84. return customConfig;
  85. }
  86.  
  87. private FileConfiguration customConfig;
  88. private File customConfigFile;
  89. }
RAW Paste Data