Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chickenstyle.vote;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Sound;
- import org.bukkit.boss.BarColor;
- import org.bukkit.boss.BarStyle;
- import org.bukkit.boss.BossBar;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCloseEvent;
- import org.bukkit.plugin.Plugin;
- import com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent;
- public class Events implements Listener {
- BossBar bar;
- FileConfiguration config = Main.getPlugin(Main.class).getConfig();
- String prefix = ChatColor.WHITE + "[" + ChatColor.GRAY + "VotePlugin" + ChatColor.WHITE + "] " + ChatColor.GRAY + ">>> ";
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onVote(PlayerVoteEvent e) {
- Bukkit.getScheduler().cancelTasks((Plugin) this);
- if (bar.getPlayers() != null) {
- bar.removeAll();
- }
- int total = config.getInt("vote_amount");
- int goal = config.getInt("total_goal");
- total++;
- config.set("vote_amount", total);
- double prog= total/goal;
- bar = Bukkit.createBossBar(ChatColor.GOLD + "" + total + ChatColor.GRAY + "/" + ChatColor.GOLD + goal + ChatColor.GRAY + " - Main Vote Goal!", BarColor.RED, BarStyle.SOLID);
- if (prog < 0.3) {
- } else if (prog <= 0.5) {
- bar.setColor(BarColor.RED);
- bar.setProgress(prog);
- } else if (prog <= 0.7) {
- bar.setColor(BarColor.BLUE);
- bar.setProgress(prog);
- } else if (prog <= 0.9) {
- bar.setColor(BarColor.YELLOW);
- bar.setProgress(prog);
- } else if (prog >= 1) {
- bar.setColor(BarColor.GREEN);
- bar.setProgress(1.0);
- }
- for (Player p: Bukkit.getServer().getOnlinePlayers()) {
- if (total != goal) {
- bar.addPlayer(p);
- p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 2f, 1f);
- Bukkit.getScheduler().scheduleAsyncDelayedTask((Plugin) this,() -> {
- bar.removePlayer(p);
- }, 120);
- } else {
- bar.addPlayer(p);
- p.playSound(p.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 2f, 1f);
- p.setExp(p.getExp() + 900);
- Bukkit.getScheduler().scheduleAsyncDelayedTask((Plugin) this,() -> {
- bar.removePlayer(p);
- }, 120);
- }
- }
- }
- @EventHandler
- public void onLeave(InventoryCloseEvent e) {
- if (e.getView().getTitle().equals(ChatColor.GRAY + "" +ChatColor.BOLD + "Set Prize!")) {
- Player player = (Player) e.getPlayer();
- config.set("prize", e.getInventory().getContents());
- Main.getPlugin(Main.class).saveConfig();
- Main.getPlugin(Main.class).reloadConfig();
- player.sendMessage(prefix + ChatColor.GREEN + "Prize was set!");
- }
- }
- @EventHandler
- public void onClick(InventoryClickEvent e) {
- if (e.getView().getTitle().equals(ChatColor.GRAY + "" +ChatColor.BOLD + "Prizes!")) {
- e.setCancelled(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement