1
0

Main.java 5.1 KB

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