Main.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package de.Linus122.customoregen;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.List;
  11. import java.util.Set;
  12. import java.util.UUID;
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.Location;
  15. import org.bukkit.Material;
  16. import org.bukkit.World;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.plugin.PluginManager;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20. public class Main extends JavaPlugin{
  21. public static List<GeneratorConfig> generatorConfigs = new ArrayList<GeneratorConfig>();
  22. public static World activeInWorld;
  23. @Override
  24. public void onEnable(){
  25. PluginManager pm = Bukkit.getPluginManager();
  26. pm.registerEvents(new Events(), this);
  27. Bukkit.getPluginCommand("customoregen").setExecutor(new Cmd(this));
  28. try {
  29. loadConfig();
  30. } catch (IOException e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. }
  34. if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
  35. activeInWorld = com.wasteofplastic.askyblock.ASkyBlock.getIslandWorld();
  36. }else
  37. if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
  38. activeInWorld = com.wasteofplastic.acidisland.ASkyBlock.getIslandWorld();
  39. }else
  40. if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
  41. activeInWorld = us.talabrek.ultimateskyblock.uSkyBlock.getSkyBlockWorld();
  42. }
  43. }
  44. @Override
  45. public void onDisable(){
  46. }
  47. public static int getLevel(Player p){
  48. if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
  49. return com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().getIslandLevel(p.getUniqueId());
  50. }else
  51. if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
  52. return com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getIslandLevel(p.getUniqueId());
  53. }else
  54. if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
  55. return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getAPI().getIslandLevel(p));
  56. }
  57. return 0;
  58. }
  59. static HashMap<UUID, Player> map = new HashMap<UUID, Player>();
  60. public static Player getOwner(Location loc){
  61. Set<Location> set = new HashSet<Location>();
  62. set.add(loc);
  63. UUID uuid = null;
  64. if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
  65. uuid = com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().getOwner(com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
  66. }else
  67. if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
  68. uuid = com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getOwner(com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
  69. }else
  70. if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
  71. String player = us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandInfo(loc).getLeader();
  72. if(Bukkit.getPlayer(player) != null){
  73. if(Bukkit.getPlayer(player).getUniqueId() != null){
  74. uuid = Bukkit.getPlayer(player).getUniqueId();
  75. }
  76. }
  77. }
  78. Player p = Bukkit.getPlayer(uuid);
  79. //Offline buffering
  80. if(p != null){
  81. map.put(uuid, p);
  82. }else{
  83. if(map.containsKey(uuid)){
  84. p = map.get(uuid);
  85. }
  86. }
  87. return p;
  88. }
  89. public void reload() throws IOException{
  90. this.reloadConfig();
  91. loadConfig();
  92. }
  93. public void loadConfig() throws IOException{
  94. File cfg = new File("plugins/CustomOreGen/config.yml");
  95. File dir = new File("plugins/CustomOreGen/");
  96. if(!dir.exists()) dir.mkdirs();
  97. if(!cfg.exists()){
  98. FileOutputStream writer = new FileOutputStream(new File(getDataFolder() + "/config.yml"));
  99. InputStream out = this.getClassLoader().getResourceAsStream("config.yml");
  100. byte[] linebuffer = new byte[4096];
  101. int lineLength = 0;
  102. while((lineLength = out.read(linebuffer)) > 0)
  103. {
  104. writer.write(linebuffer, 0, lineLength);
  105. }
  106. writer.close();
  107. }
  108. generatorConfigs = new ArrayList<GeneratorConfig>();
  109. int i = 0;
  110. while(true){
  111. i++;
  112. if(this.getConfig().contains("generators.generator" + i)){
  113. GeneratorConfig gc = new GeneratorConfig();
  114. gc.permission = this.getConfig().getString("generators.generator" + i + ".permission");
  115. gc.unlock_islandLevel = this.getConfig().getInt("generators.generator" + i + ".unlock_islandLevel");
  116. for(String raw : this.getConfig().getStringList("generators.generator" + i + ".blocks")){
  117. try{
  118. if(!raw.contains("!")){
  119. String material = raw.split(":")[0];
  120. double percent = Double.parseDouble(raw.split(":")[1]);
  121. gc.itemList.add(new GeneratorItem(material, (byte) 0, percent));
  122. }else{
  123. String material = raw.split("!")[0];
  124. double percent = Double.parseDouble(raw.split(":")[1]);
  125. int damage = Integer.parseInt(raw.split("!")[1].split(":")[0]);
  126. gc.itemList.add(new GeneratorItem(material, (byte) damage, percent));
  127. }
  128. }catch(Exception e){
  129. }
  130. }
  131. generatorConfigs.add(gc);
  132. }else{
  133. break;
  134. }
  135. }
  136. //this.saveConfig();
  137. }
  138. }