Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.h31ix.nas;
- import java.util.List;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- public class CommandVote implements CommandExecutor {
- private final Nas plugin;
- public CommandVote(Nas plugin){
- this.plugin = plugin;
- }
- public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
- Player player = (Player)cs;
- if (cmd.getName().equalsIgnoreCase("createvote"))
- {
- if (player.hasPermission("nas.createvote"))
- {
- if (args.length == 1)
- {
- if (args[0].equalsIgnoreCase("Sun"))
- {
- player.getServer().broadcastMessage("Vote started for sun, type /vote YES or /vote NO to cast your vote");
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- public void run() {
- if (plugin.yes > plugin.no)
- {
- List l = plugin.getServer().getWorlds();
- for (int i=0;i!=l.size();i++)
- {
- World w = (World)l.get(i);
- w.setTime(0);
- }
- plugin.getServer().broadcastMessage("Vote passed! Changing to day...");
- }
- else if (plugin.no > plugin.yes)
- {
- plugin.getServer().broadcastMessage("Vote failed!");
- }
- else
- {
- plugin.getServer().broadcastMessage("The vote was tied! No time change.");
- }
- plugin.yes = 0;
- plugin.no = 0;
- plugin.voted.clear();
- }
- }, 600L);
- }
- else if (args[0].equalsIgnoreCase("night"))
- {
- player.getServer().broadcastMessage("Vote started for Night, type /vote YES or /vote NO to cast your vote");
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- public void run() {
- if (plugin.yes > plugin.no)
- {
- List l = plugin.getServer().getWorlds();
- for (int i=0;i!=l.size();i++)
- {
- World w = (World)l.get(i);
- w.setTime(13500);
- }
- plugin.getServer().broadcastMessage("Vote passed! Changing to night...");
- }
- else if (plugin.no > plugin.yes)
- {
- plugin.getServer().broadcastMessage("Vote failed!");
- }
- plugin.yes = 0;
- plugin.no = 0;
- }
- }, 600L);
- }
- else
- {
- player.sendMessage("Usage: /createvote [sun /night]");
- }
- }
- else
- {
- player.sendMessage("Usage: /createvote [sun /night]");
- }
- }
- else
- {
- player.sendMessage("Insufficient permissisons!");
- }
- }
- if (cmd.getName().equalsIgnoreCase("vote"))
- {
- if (args.length == 1)
- {
- if (args[0].equalsIgnoreCase("yes"))
- {
- if (plugin.voted.contains(player))
- {
- player.sendMessage("You have already voted!");
- }
- else
- {
- player.getServer().broadcastMessage(player.getName()+" voted YES!");
- plugin.yes++;
- plugin.voted.add(player);
- }
- }
- else if (args[0].equalsIgnoreCase("no"))
- {
- if (plugin.voted.contains(player))
- {
- player.sendMessage("You have already voted!");
- }
- else
- {
- player.getServer().broadcastMessage(player.getName()+" voted NO!");
- plugin.no++;
- plugin.voted.add(player);
- }
- }
- else
- {
- player.sendMessage("Usage: /vote [yes/no]");
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment