Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.15 KB | None | 0 0
  1. package com.comugamers.MineLet;
  2.  
  3. import com.comugamers.MineLet.commands.MineletsCommands;
  4. import com.comugamers.MineLet.commands.setMinelet;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.util.ArrayList;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import java.util.Random;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import org.bukkit.Bukkit;
  18. import org.bukkit.ChatColor;
  19. import org.bukkit.Color;
  20. import org.bukkit.FireworkEffect;
  21. import org.bukkit.FireworkEffect.Builder;
  22. import org.bukkit.FireworkEffect.Type;
  23. import org.bukkit.Location;
  24. import org.bukkit.Material;
  25. import org.bukkit.World;
  26. import org.bukkit.block.Block;
  27. import org.bukkit.command.PluginCommand;
  28. import org.bukkit.configuration.file.FileConfiguration;
  29. import org.bukkit.entity.ArmorStand;
  30. import org.bukkit.entity.EntityType;
  31. import org.bukkit.entity.Firework;
  32. import org.bukkit.entity.Item;
  33. import org.bukkit.entity.Player;
  34. import org.bukkit.entity.WitherSkull;
  35. import org.bukkit.event.EventHandler;
  36. import org.bukkit.event.Listener;
  37. import org.bukkit.event.player.PlayerInteractEvent;
  38. import org.bukkit.inventory.ItemStack;
  39. import org.bukkit.inventory.meta.FireworkMeta;
  40. import org.bukkit.plugin.PluginManager;
  41. import org.bukkit.plugin.java.JavaPlugin;
  42. import org.bukkit.scheduler.BukkitRunnable;
  43. import org.bukkit.util.Vector;
  44.  
  45. public class main
  46. extends JavaPlugin
  47. implements Listener
  48. {
  49. public main plugin;
  50. private ArrayList<ArmorStand> armorStands1 = new ArrayList();
  51. private ArrayList<ArmorStand> armorStands2 = new ArrayList();
  52. private ArrayList<WitherSkull> skulls1 = new ArrayList();
  53. private ArrayList<WitherSkull> skulls2 = new ArrayList();
  54. private Connection database;
  55. private PreparedStatement addMinelets;
  56. private PreparedStatement updateMinelets;
  57. private PreparedStatement getMinelets;
  58. public MineletsCommands mineletsCommands = new MineletsCommands(this);
  59. public setMinelet setMinelet = new setMinelet(this);
  60. public List<String> rewardlist;
  61. public Random random = new Random();
  62. public Location mine1;
  63. public Location mine2;
  64. private boolean minelet1OnUse;
  65. private boolean minelet2OnUse;
  66. private String world;
  67. public Color color1;
  68.  
  69. public void onEnable()
  70. {
  71. loadConfig();this.plugin = this;
  72. database1();
  73. this.minelet1OnUse = false;
  74. this.minelet2OnUse = false;
  75. try
  76. {
  77. getCommand("setplayerminelets").setExecutor(this.mineletsCommands);
  78. getCommand("addplayerminelets").setExecutor(this.mineletsCommands);
  79. getCommand("minelets").setExecutor(this.mineletsCommands);
  80. getCommand("setminelet").setExecutor(this.setMinelet);
  81. this.rewardlist = getConfig().getStringList("enabled-rewards");
  82. setMinelets();
  83. }
  84. catch (Exception localException)
  85. {
  86. localException.printStackTrace();
  87. }
  88. saveDefaultConfig();
  89. Bukkit.getPluginManager().registerEvents(this, this);
  90. getLogger().log(Level.INFO, "Has enabled.");
  91. }
  92.  
  93. public void onDisable()
  94. {
  95. this.plugin = null;
  96. getLogger().log(Level.INFO, "Has disabled.");
  97. for (Iterator localIterator = this.armorStands1.iterator(); localIterator.hasNext();)
  98. {
  99. localObject = (ArmorStand)localIterator.next();
  100. ((ArmorStand)localObject).remove();
  101. }
  102. Object localObject;
  103. for (localIterator = this.armorStands2.iterator(); localIterator.hasNext();)
  104. {
  105. localObject = (ArmorStand)localIterator.next();
  106. ((ArmorStand)localObject).remove();
  107. }
  108. for (localIterator = this.skulls1.iterator(); localIterator.hasNext();)
  109. {
  110. localObject = (WitherSkull)localIterator.next();
  111. ((WitherSkull)localObject).remove();
  112. }
  113. for (localIterator = this.skulls2.iterator(); localIterator.hasNext();)
  114. {
  115. localObject = (WitherSkull)localIterator.next();
  116. ((WitherSkull)localObject).remove();
  117. }
  118. }
  119.  
  120. public void setMinelets()
  121. {
  122. if (getConfig().getString("locations.1.x") == null)
  123. {
  124. this.plugin.getLogger().log(Level.WARNING, "Minelet 1 is not created.");
  125. }
  126. else
  127. {
  128. this.world = getConfig().getString("locations.1.world");
  129. this.mine1 = new Location(Bukkit.getWorld(getConfig().getString("locations.1.world")), getConfig().getDouble("locations.1.x"), getConfig().getDouble("locations.1.y"), getConfig().getDouble("locations.1.z"));
  130. this.mine1.getBlock().setType(Material.ENDER_PORTAL_FRAME);
  131. createHolo(this.mine1, ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.mineletitle")), this.armorStands1);
  132. }
  133. if (getConfig().getString("locations.2.x") == null)
  134. {
  135. this.plugin.getLogger().log(Level.WARNING, "Minelet 2 is not created.");
  136. }
  137. else
  138. {
  139. this.mine2 = new Location(Bukkit.getWorld(getConfig().getString("locations.2.world")), getConfig().getDouble("locations.2.x"), getConfig().getDouble("locations.2.y"), getConfig().getDouble("locations.2.z"));
  140. this.mine2.getBlock().setType(Material.ENDER_PORTAL_FRAME);
  141. createHolo(this.mine2, ChatColor.translateAlternateColorCodes('&', getConfig().getString("messages.mineletitle")), this.armorStands2);
  142. }
  143. }
  144.  
  145. public void createHolo(Location paramLocation, String paramString, ArrayList<ArmorStand> paramArrayList)
  146. {
  147. ArmorStand localArmorStand = (ArmorStand)Bukkit.getWorld(this.world).spawnEntity(paramLocation, EntityType.ARMOR_STAND);
  148. localArmorStand.setVisible(false);
  149. localArmorStand.setCustomNameVisible(true);
  150. localArmorStand.setCustomName(paramString);
  151. localArmorStand.setGravity(false);
  152. localArmorStand.setSmall(true);
  153.  
  154. paramArrayList.add(localArmorStand);
  155. }
  156.  
  157. public void database1()
  158. {
  159. try
  160. {
  161. this.database = DriverManager.getConnection("jdbc:mysql://" + getHost() + ":" + Integer.valueOf(getPort()) + "/" + getDB(), getUsername(), getPassword());
  162. Statement localStatement = this.database.createStatement();
  163. localStatement.execute("CREATE TABLE IF NOT EXISTS minelets(uuid VARCHAR(36) PRIMARY KEY NOT NULL, balance DECIMAL(65, 2))");
  164.  
  165. this.getMinelets = this.database.prepareStatement("SELECT balance FROM minelets WHERE uuid=?");
  166. this.updateMinelets = this.database.prepareStatement("UPDATE minelets SET balance=? WHERE uuid=?");
  167. this.addMinelets = this.database.prepareStatement("INSERT INTO minelets(uuid,balance) VALUES(?,?)");
  168. }
  169. catch (SQLException localSQLException)
  170. {
  171. localSQLException.printStackTrace();
  172. localSQLException.getCause();
  173. getLogger().log(Level.SEVERE, "Has disabled because there arent open a connection with the mysql database.");
  174. Bukkit.getPluginManager().disablePlugin(this);
  175. }
  176. }
  177.  
  178. public String getHost()
  179. {
  180. return this.plugin.getConfig().getString("mysql.host");
  181. }
  182.  
  183. public String getPort()
  184. {
  185. return this.plugin.getConfig().getString("mysql.port");
  186. }
  187.  
  188. public String getDB()
  189. {
  190. return this.plugin.getConfig().getString("mysql.database");
  191. }
  192.  
  193. public String getUsername()
  194. {
  195. return this.plugin.getConfig().getString("mysql.username");
  196. }
  197.  
  198. public String getPassword()
  199. {
  200. return this.plugin.getConfig().getString("mysql.password");
  201. }
  202.  
  203. public Integer getMinelets(String paramString)
  204. {
  205. try
  206. {
  207. this.getMinelets.setString(1, paramString);
  208. ResultSet localResultSet = this.getMinelets.executeQuery();
  209. if (localResultSet.next()) {
  210. return Integer.valueOf(localResultSet.getInt("balance"));
  211. }
  212. return null;
  213. }
  214. catch (SQLException localSQLException)
  215. {
  216. localSQLException.printStackTrace();
  217. }
  218. return null;
  219. }
  220.  
  221. public void updateMinelets(String paramString, int paramInt)
  222. {
  223. try
  224. {
  225. this.updateMinelets.setDouble(1, paramInt);
  226. this.updateMinelets.setString(2, paramString);
  227. this.updateMinelets.executeUpdate();
  228. }
  229. catch (SQLException localSQLException)
  230. {
  231. localSQLException.printStackTrace();
  232. }
  233. }
  234.  
  235. public void addMinelets(String paramString, int paramInt)
  236. {
  237. try
  238. {
  239. Integer localInteger = getMinelets(paramString);
  240. if (localInteger == null)
  241. {
  242. this.addMinelets.setString(1, paramString);
  243. this.addMinelets.setDouble(2, paramInt);
  244. this.addMinelets.execute();
  245. }
  246. else
  247. {
  248. updateMinelets(paramString, paramInt);
  249. }
  250. }
  251. catch (SQLException localSQLException)
  252. {
  253. localSQLException.printStackTrace();
  254. }
  255. }
  256.  
  257. @EventHandler
  258. public void interact(final PlayerInteractEvent paramPlayerInteractEvent)
  259. {
  260. if (paramPlayerInteractEvent.getClickedBlock().getType() == Material.ENDER_PORTAL_FRAME)
  261. {
  262. int i = getMinelets(paramPlayerInteractEvent.getPlayer().getName()).intValue();
  263. if (i == 0)
  264. {
  265. paramPlayerInteractEvent.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("messages.notenought")));
  266. return;
  267. }
  268. final int j = paramPlayerInteractEvent.getClickedBlock().getX();
  269. final int k = paramPlayerInteractEvent.getClickedBlock().getY();
  270. final int m = paramPlayerInteractEvent.getClickedBlock().getZ();
  271. Location localLocation = new Location(Bukkit.getWorld(this.world), j, k, m);
  272. final String str = (String)this.rewardlist.get(this.random.nextInt(this.rewardlist.size()));
  273. if (this.minelet1OnUse) {
  274. return;
  275. }
  276. for (final Object localObject = this.armorStands1.iterator(); ((Iterator)localObject).hasNext();)
  277. {
  278. ArmorStand localArmorStand = (ArmorStand)((Iterator)localObject).next();
  279. localArmorStand.setCustomNameVisible(false);
  280. }
  281. this.minelet1OnUse = true;
  282. new BukkitRunnable()
  283. {
  284. public void run()
  285. {
  286. for (Object localObject1 = main.this.armorStands1.iterator(); ((Iterator)localObject1).hasNext();)
  287. {
  288. localObject2 = (ArmorStand)((Iterator)localObject1).next();
  289. ((ArmorStand)localObject2).setCustomNameVisible(true);
  290. ((ArmorStand)localObject2).setCustomName(ChatColor.translateAlternateColorCodes('&', main.this.getConfig().getString("messages.found") + " " + main.this.getConfig().getString(new StringBuilder().append("rewards.").append(str).append(".name").toString())));
  291. }
  292. localObject1 = new Location(Bukkit.getWorld(main.this.world), j + 0.5D, k + 2, m + 0.5D);
  293. final Object localObject2 = Bukkit.getWorld(main.this.world).dropItem((Location)localObject1, new ItemStack(Material.getMaterial(main.this.plugin.getConfig().getString("rewards." + str + ".item").toUpperCase()), 1, (short)main.this.plugin.getConfig().getInt("rewards." + str + ".data")));
  294. ((Item)localObject2).setVelocity(new Vector(0, 0, 0));
  295. new BukkitRunnable()
  296. {
  297. public void run()
  298. {
  299. for (ArmorStand localArmorStand : main.this.armorStands1)
  300. {
  301. localObject2.remove();
  302. localArmorStand.setCustomName(ChatColor.translateAlternateColorCodes('&', main.this.getConfig().getString("messages.mineletitle")));
  303. main.this.minelet1OnUse = false;
  304. }
  305. }
  306. }.runTaskLater(main.this.plugin, 210L);
  307. }
  308. }.runTaskLater(this, 110L);
  309.  
  310. addMinelets(paramPlayerInteractEvent.getPlayer().getName(), i - 1);
  311. localObject = getColor(this.random.nextInt(17) + 1);
  312. new BukkitRunnable()
  313. {
  314. public void run()
  315. {
  316. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 10, m), FireworkEffect.Type.BURST, localObject);
  317. }
  318. }.runTaskLater(this, 10L);
  319.  
  320. new BukkitRunnable()
  321. {
  322. public void run()
  323. {
  324. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 9, m), FireworkEffect.Type.BURST, localObject);
  325. }
  326. }.runTaskLater(this, 20L);
  327.  
  328. new BukkitRunnable()
  329. {
  330. public void run()
  331. {
  332. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 8, m), FireworkEffect.Type.BURST, localObject);
  333. }
  334. }.runTaskLater(this, 30L);
  335.  
  336. new BukkitRunnable()
  337. {
  338. public void run()
  339. {
  340. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 7, m), FireworkEffect.Type.BURST, localObject);
  341. }
  342. }.runTaskLater(this, 40L);
  343.  
  344. new BukkitRunnable()
  345. {
  346. public void run()
  347. {
  348. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 6, m), FireworkEffect.Type.BURST, localObject);
  349. }
  350. }.runTaskLater(this, 50L);
  351.  
  352. new BukkitRunnable()
  353. {
  354. public void run()
  355. {
  356. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 5, m), FireworkEffect.Type.BURST, localObject);
  357. }
  358. }.runTaskLater(this, 60L);
  359.  
  360. new BukkitRunnable()
  361. {
  362. public void run()
  363. {
  364. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 4, m), FireworkEffect.Type.BURST, localObject);
  365. }
  366. }.runTaskLater(this, 70L);
  367.  
  368. new BukkitRunnable()
  369. {
  370. public void run()
  371. {
  372. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 3, m), FireworkEffect.Type.BURST, localObject);
  373. }
  374. }.runTaskLater(this, 80L);
  375.  
  376. new BukkitRunnable()
  377. {
  378. public void run()
  379. {
  380. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 2, m), FireworkEffect.Type.BURST, localObject);
  381. }
  382. }.runTaskLater(this, 90L);
  383.  
  384. new BukkitRunnable()
  385. {
  386. public void run()
  387. {
  388. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k + 1, m), FireworkEffect.Type.BURST, localObject);
  389. }
  390. }.runTaskLater(this, 100L);
  391.  
  392. new BukkitRunnable()
  393. {
  394. public void run()
  395. {
  396. main.this.fireEffect(new Location(Bukkit.getWorld(main.this.world), j, k, m), FireworkEffect.Type.BALL_LARGE, localObject);
  397. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), main.this.plugin.getConfig().getString("rewards." + str + ".command").replace("$player$", paramPlayerInteractEvent.getPlayer().getName()));
  398. }
  399. }.runTaskLater(this, 110L);
  400. }
  401. }
  402.  
  403. public void fireEffect(Location paramLocation, FireworkEffect.Type paramType, Color paramColor)
  404. {
  405. FireworkEffect localFireworkEffect = FireworkEffect.builder().trail(false).flicker(false).withColor(paramColor).withFade(paramColor).with(paramType).build();
  406. final Firework localFirework = (Firework)Bukkit.getWorld(this.world).spawn(paramLocation, Firework.class);
  407. FireworkMeta localFireworkMeta = localFirework.getFireworkMeta();
  408. localFireworkMeta.addEffect(localFireworkEffect);
  409. localFireworkMeta.setPower(0);
  410. localFirework.setFireworkMeta(localFireworkMeta);
  411. new BukkitRunnable()
  412. {
  413. public void run()
  414. {
  415. localFirework.detonate();
  416. }
  417. }.runTaskLater(this, 1L);
  418. }
  419.  
  420. private static Color getColor(int paramInt)
  421. {
  422. switch (paramInt)
  423. {
  424. case 1:
  425. return Color.AQUA;
  426. case 2:
  427. return Color.BLACK;
  428. case 3:
  429. return Color.BLUE;
  430. case 4:
  431. return Color.FUCHSIA;
  432. case 5:
  433. return Color.GRAY;
  434. case 6:
  435. return Color.GREEN;
  436. case 7:
  437. return Color.LIME;
  438. case 8:
  439. return Color.MAROON;
  440. case 9:
  441. return Color.NAVY;
  442. case 10:
  443. return Color.OLIVE;
  444. case 11:
  445. return Color.ORANGE;
  446. case 12:
  447. return Color.PURPLE;
  448. case 13:
  449. return Color.RED;
  450. case 14:
  451. return Color.SILVER;
  452. case 15:
  453. return Color.TEAL;
  454. case 16:
  455. return Color.WHITE;
  456. case 17:
  457. return Color.YELLOW;
  458. }
  459. return null;
  460. }
  461. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement