Advertisement
Guest User

Main Class

a guest
May 23rd, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. package net.minenite.warzairdrops;
  2.  
  3. import java.util.Random;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Material;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.block.Chest;
  12. import org.bukkit.inventory.ItemStack;
  13. import org.bukkit.plugin.Plugin;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.scheduler.BukkitRunnable;
  16.  
  17.  
  18. public class MainClass
  19. extends JavaPlugin {
  20. public static MainClass instance;
  21. public static final Logger log = Logger.getLogger("Minecraft");
  22.  
  23. public static Integer item1c1;
  24.  
  25. public static Integer item2c1;
  26.  
  27. public static Integer item3c1;
  28.  
  29. public static Integer item4c1;
  30.  
  31. public static Integer item5c1;
  32.  
  33. public static Integer item1c1a;
  34.  
  35. public static Integer item2c1a;
  36.  
  37. public static Integer item3c1a;
  38.  
  39. public static Integer item4c1a;
  40.  
  41. public static Integer item5c1a;
  42.  
  43. public static Integer item1c2;
  44.  
  45. public static Integer item2c2;
  46.  
  47. public static Integer item3c2;
  48.  
  49. public static Integer item4c2;
  50. public static Integer item5c2;
  51. public static Integer item1c2a;
  52. public static Integer item2c2a;
  53. public static Integer item3c2a;
  54. public static Integer item4c2a;
  55. public static Integer item5c2a;
  56. public static Integer item1c3;
  57. public static Integer item2c3;
  58. public static Integer item3c3;
  59. public static Integer item4c3;
  60. public static Integer item5c3;
  61. public static Integer item1c3a;
  62. public static Integer item2c3a;
  63. public static Integer item3c3a;
  64. public static Integer item4c3a;
  65. public static Integer item5c3a;
  66. public static Integer item1c4;
  67. public static Integer item2c4;
  68. public static Integer item3c4;
  69. public static Integer item4c4;
  70. public static Integer item5c4;
  71. public static Integer item1c4a;
  72. public static Integer item2c4a;
  73. public static Integer item3c4a;
  74. public static Integer item4c4a;
  75. public static Integer item5c4a;
  76. public static Integer item1c5;
  77. public static Integer item2c5;
  78. public static Integer item3c5;
  79. public static Integer item4c5;
  80. public static Integer item5c5;
  81. public static Integer item1c5a;
  82. public static Integer item2c5a;
  83. public static Integer item3c5a;
  84. public static Integer item4c5a;
  85. public static Integer item5c5a;
  86. public static Double chest1Chance;
  87. public static Double chest2Chance;
  88. public static Double chest3Chance;
  89. public static Double chest4Chance;
  90. public static Double chest5Chance;
  91. public static Integer ZRange;
  92. public static Integer XRange;
  93. public static Integer TBD;
  94. public static Integer centerX;
  95. public static Integer centerZ;
  96. public static Integer dLX;
  97. public static Integer dLZ;
  98. public static Integer dLY;
  99. public static String dropWorld;
  100. public static Boolean enabled;
  101. protected static Plugin plugin;
  102.  
  103. public void onEnable() {
  104. enabled = Boolean.valueOf(true);
  105.  
  106. getCommand("ad").setExecutor(new CommandsClass());
  107. loadConfiguration();
  108.  
  109. if (chest1Chance.doubleValue() + chest2Chance.doubleValue() + chest3Chance.doubleValue() + chest4Chance.doubleValue() + chest5Chance.doubleValue() != 1.0D) {
  110. Bukkit.getServer().broadcastMessage(ChatColor.RED + "[Airdrop+] The drop chances do not add up to 1 (100%).");
  111. Bukkit.getServer().broadcastMessage(ChatColor.RED + "All chest chances have been set to 0.2 (20%)");
  112. chest1Chance = Double.valueOf(0.2D);
  113. chest2Chance = Double.valueOf(0.2D);
  114. chest3Chance = Double.valueOf(0.2D);
  115. chest4Chance = Double.valueOf(0.2D);
  116. chest5Chance = Double.valueOf(0.2D);
  117. log("WARNING WARNING WARNING. CHEST DROP CHANCES DO NOT ADD UP. RESETTING TO 20% ON ALL CHESTS.", Level.INFO);
  118. }
  119.  
  120. log("AirDropsPlus has been enabled!", Level.INFO);
  121.  
  122. plugin = this;
  123. (new BukkitRunnable() {
  124. public void run() {
  125. if (!MainClass.enabled.booleanValue()) {
  126. return;
  127. }
  128.  
  129. if (Bukkit.getServer().getOnlinePlayers().size() == 0) {
  130. return;
  131. }
  132.  
  133. Random rand = new Random();
  134. int coordx = rand.nextInt(MainClass.XRange.intValue() * 2) - MainClass.XRange.intValue() + MainClass.centerX.intValue();
  135. Random randc = new Random();
  136. int chance1Hundred = randc.nextInt(100);
  137. int chestNumber = 1;
  138.  
  139. Random rand1 = new Random();
  140. int coordz = rand1.nextInt(MainClass.ZRange.intValue() * 2) - MainClass.ZRange.intValue() + MainClass.centerZ.intValue();
  141.  
  142. double luckofthedraw = chance1Hundred / 100.0D;
  143.  
  144. if (luckofthedraw <= MainClass.chest1Chance.doubleValue()) {
  145. chestNumber = 1;
  146. } else if (MainClass.chest1Chance.doubleValue() < luckofthedraw && luckofthedraw <= MainClass.chest2Chance.doubleValue() + MainClass.chest1Chance.doubleValue()) {
  147. chestNumber = 2;
  148. } else if (MainClass.chest2Chance.doubleValue() + MainClass.chest1Chance.doubleValue() < luckofthedraw && luckofthedraw <= MainClass.chest1Chance.doubleValue() + MainClass.chest2Chance.doubleValue() + MainClass.chest3Chance.doubleValue()) {
  149. chestNumber = 3;
  150. } else if (MainClass.chest1Chance.doubleValue() + MainClass.chest2Chance.doubleValue() + MainClass.chest3Chance.doubleValue() < luckofthedraw && luckofthedraw <= MainClass.chest1Chance.doubleValue() + MainClass.chest2Chance.doubleValue() + MainClass.chest3Chance.doubleValue() + MainClass.chest4Chance.doubleValue()) {
  151. chestNumber = 4;
  152. } else if (MainClass.chest1Chance.doubleValue() + MainClass.chest2Chance.doubleValue() + MainClass.chest3Chance.doubleValue() + MainClass.chest4Chance.doubleValue() < luckofthedraw && luckofthedraw <= MainClass.chest1Chance.doubleValue() + MainClass.chest2Chance.doubleValue() + MainClass.chest3Chance.doubleValue() + MainClass.chest4Chance.doubleValue() + MainClass.chest5Chance.doubleValue()) {
  153. chestNumber = 5;
  154. }
  155.  
  156.  
  157. World world1 = Bukkit.getServer().getWorld(MainClass.dropWorld);
  158. int coordy = world1.getHighestBlockYAt(coordx, coordz);
  159. Block cBlock = world1.getBlockAt(coordx, coordy, coordz);
  160.  
  161. Bukkit.getServer().broadcastMessage(ChatColor.RED + "Previous Airdrop has timed out.");
  162.  
  163. MainClass.dLX = Integer.valueOf(MainClass.this.getConfig().getInt("dropLocationX"));
  164. MainClass.dLY = Integer.valueOf(MainClass.this.getConfig().getInt("dropLocationY"));
  165. MainClass.dLZ = Integer.valueOf(MainClass.this.getConfig().getInt("dropLocationZ"));
  166.  
  167. if (world1.getBlockAt(MainClass.dLX.intValue(), MainClass.dLY.intValue(), MainClass.dLZ.intValue()).getType().equals(Material.CHEST)) {
  168. Chest chestDel = (Chest) world1.getBlockAt(MainClass.dLX.intValue(), MainClass.dLY.intValue(), MainClass.dLZ.intValue()).getState();
  169. chestDel.getBlockInventory().clear();
  170. world1.getBlockAt(MainClass.dLX.intValue(), MainClass.dLY.intValue(), MainClass.dLZ.intValue()).setType(Material.AIR);
  171. }
  172.  
  173. cBlock.setType(Material.CHEST);
  174. Chest chest = (Chest) cBlock.getState();
  175.  
  176. MainClass.this.getConfig().set("dropLocationX", Integer.valueOf(coordx));
  177. MainClass.this.getConfig().set("dropLocationY", Integer.valueOf(coordy));
  178. MainClass.this.getConfig().set("dropLocationZ", Integer.valueOf(coordz));
  179. MainClass.this.saveConfig();
  180. MainClass.this.reloadConfig();
  181.  
  182.  
  183. if (chestNumber == 1) {
  184. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item1c1.intValue(), MainClass.item1c1a.intValue())});
  185. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item2c1.intValue(), MainClass.item2c1a.intValue())});
  186. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item3c1.intValue(), MainClass.item3c1a.intValue())});
  187. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item4c1.intValue(), MainClass.item4c1a.intValue())});
  188. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item5c1.intValue(), MainClass.item5c1a.intValue())});
  189. } else if (chestNumber == 2) {
  190. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item1c2.intValue(), MainClass.item1c2a.intValue())});
  191. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item2c2.intValue(), MainClass.item2c2a.intValue())});
  192. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item3c2.intValue(), MainClass.item3c2a.intValue())});
  193. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item4c2.intValue(), MainClass.item4c2a.intValue())});
  194. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item5c2.intValue(), MainClass.item5c2a.intValue())});
  195. } else if (chestNumber == 3) {
  196. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item1c3.intValue(), MainClass.item1c3a.intValue())});
  197. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item2c3.intValue(), MainClass.item2c3a.intValue())});
  198. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item3c3.intValue(), MainClass.item3c3a.intValue())});
  199. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item4c3.intValue(), MainClass.item4c3a.intValue())});
  200. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item5c3.intValue(), MainClass.item5c3a.intValue())});
  201. } else if (chestNumber == 4) {
  202. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item1c4.intValue(), MainClass.item1c4a.intValue())});
  203. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item2c4.intValue(), MainClass.item2c4a.intValue())});
  204. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item3c4.intValue(), MainClass.item3c4a.intValue())});
  205. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item4c4.intValue(), MainClass.item4c4a.intValue())});
  206. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item5c4.intValue(), MainClass.item5c4a.intValue())});
  207. } else if (chestNumber == 5) {
  208. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item1c5.intValue(), MainClass.item1c5a.intValue())});
  209. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item2c5.intValue(), MainClass.item2c5a.intValue())});
  210. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item3c5.intValue(), MainClass.item3c5a.intValue())});
  211. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item4c5.intValue(), MainClass.item4c5a.intValue())});
  212. chest.getInventory().addItem(new ItemStack[]{new ItemStack(MainClass.item5c5.intValue(), MainClass.item5c5a.intValue())});
  213. }
  214.  
  215.  
  216. Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "Airdrop at location: " + ChatColor.GOLD + coordx + ", " + coordz);
  217. Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "You have " + MainClass.TBD + " minutes to retrieve the object before it self-destructs.");
  218. }
  219. }).runTaskTimer(plugin, 100L, (TBD.intValue() * 20 * 60));
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement