Advertisement
danik159

Untitled

Oct 12th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package com.chickenstyle.vote;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Sound;
  6. import org.bukkit.boss.BarColor;
  7. import org.bukkit.boss.BarStyle;
  8. import org.bukkit.boss.BossBar;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.inventory.InventoryClickEvent;
  14. import org.bukkit.event.inventory.InventoryCloseEvent;
  15. import org.bukkit.plugin.Plugin;
  16.  
  17. import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
  18.  
  19.  
  20. public class Events implements Listener {
  21. BossBar bar;
  22. FileConfiguration config = Main.getPlugin(Main.class).getConfig();
  23. String prefix = ChatColor.WHITE + "[" + ChatColor.GRAY + "VotePlugin" + ChatColor.WHITE + "] " + ChatColor.GRAY + ">>> ";
  24.  
  25. @SuppressWarnings("deprecation")
  26. @EventHandler
  27. public void onVote(PlayerVoteEvent e) {
  28. Bukkit.getScheduler().cancelTasks((Plugin) this);
  29. if (bar.getPlayers() != null) {
  30. bar.removeAll();
  31. }
  32. int total = config.getInt("vote_amount");
  33. int goal = config.getInt("total_goal");
  34. total++;
  35. config.set("vote_amount", total);
  36. double prog= total/goal;
  37. bar = Bukkit.createBossBar(ChatColor.GOLD + "" + total + ChatColor.GRAY + "/" + ChatColor.GOLD + goal + ChatColor.GRAY + " - Main Vote Goal!", BarColor.RED, BarStyle.SOLID);
  38. if (prog < 0.3) {
  39. } else if (prog <= 0.5) {
  40. bar.setColor(BarColor.RED);
  41. bar.setProgress(prog);
  42. } else if (prog <= 0.7) {
  43. bar.setColor(BarColor.BLUE);
  44. bar.setProgress(prog);
  45. } else if (prog <= 0.9) {
  46. bar.setColor(BarColor.YELLOW);
  47. bar.setProgress(prog);
  48. } else if (prog >= 1) {
  49. bar.setColor(BarColor.GREEN);
  50. bar.setProgress(1.0);
  51. }
  52.  
  53. for (Player p: Bukkit.getServer().getOnlinePlayers()) {
  54. if (total != goal) {
  55. bar.addPlayer(p);
  56. p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 2f, 1f);
  57. Bukkit.getScheduler().scheduleAsyncDelayedTask((Plugin) this,() -> {
  58. bar.removePlayer(p);
  59. }, 120);
  60. } else {
  61. bar.addPlayer(p);
  62. p.playSound(p.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 2f, 1f);
  63. p.setExp(p.getExp() + 900);
  64. Bukkit.getScheduler().scheduleAsyncDelayedTask((Plugin) this,() -> {
  65. bar.removePlayer(p);
  66. }, 120);
  67. }
  68. }
  69.  
  70. }
  71. @EventHandler
  72. public void onLeave(InventoryCloseEvent e) {
  73. if (e.getView().getTitle().equals(ChatColor.GRAY + "" +ChatColor.BOLD + "Set Prize!")) {
  74. Player player = (Player) e.getPlayer();
  75. config.set("prize", e.getInventory().getContents());
  76. Main.getPlugin(Main.class).saveConfig();
  77. Main.getPlugin(Main.class).reloadConfig();
  78. player.sendMessage(prefix + ChatColor.GREEN + "Prize was set!");
  79. }
  80. }
  81. @EventHandler
  82. public void onClick(InventoryClickEvent e) {
  83. if (e.getView().getTitle().equals(ChatColor.GRAY + "" +ChatColor.BOLD + "Prizes!")) {
  84. e.setCancelled(true);
  85. }
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement