h31ix

Untitled

Jan 10th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. package net.h31ix.nas.commands.essentials;
  2.  
  3. /*
  4. * NAS for Bukkit
  5. *
  6. * @author Hu.
  7. *
  8. * H31IX.NET
  9. * WWW.NITRATEGAMING.COM
  10. */
  11.  
  12. import java.util.List;
  13. import org.bukkit.World;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandExecutor;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.entity.Player;
  18. import net.h31ix.nas.Nas;
  19. import org.bukkit.ChatColor;
  20.  
  21. public class CommandVote implements CommandExecutor {
  22. private final Nas plugin;
  23.  
  24. public CommandVote(Nas plugin){
  25. this.plugin = plugin;
  26. }
  27.  
  28.  
  29. public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
  30. Player player = (Player)cs;
  31. if (cmd.getName().equalsIgnoreCase("createvote"))
  32. {
  33. if (player.hasPermission("nas.createvote"))
  34. {
  35. if (args.length == 1)
  36. {
  37. if (args[0].equalsIgnoreCase("Day"))
  38. {
  39. player.getServer().broadcastMessage("Vote started for "+ChatColor.GREEN+"Day"+ChatColor.WHITE+" type "+ChatColor.GREEN+"/vote YES "+ChatColor.WHITE+"or "+ChatColor.GREEN+"/vote NO "+ChatColor.WHITE+"to cast your vote");
  40.  
  41. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  42. public void run() {
  43. if (plugin.yes > plugin.no)
  44. {
  45. List l = plugin.getServer().getWorlds();
  46. for (int i=0;i!=l.size();i++)
  47. {
  48. World w = (World)l.get(i);
  49. w.setTime(0);
  50. }
  51. plugin.getServer().broadcastMessage("Vote passed! Changing to day...");
  52. }
  53. else if (plugin.no > plugin.yes)
  54. {
  55. plugin.getServer().broadcastMessage("Vote failed!");
  56. }
  57. else
  58. {
  59. plugin.getServer().broadcastMessage("The vote was tied! No time change.");
  60. }
  61. plugin.yes = 0;
  62. plugin.no = 0;
  63. plugin.voted.clear();
  64. }
  65.  
  66. }, 600L);
  67. }
  68. else if (args[0].equalsIgnoreCase("night"))
  69. {
  70. player.getServer().broadcastMessage("Vote started for "+ChatColor.GREEN+"Night"+ChatColor.WHITE+" type "+ChatColor.GREEN+"/vote YES "+ChatColor.WHITE+"or "+ChatColor.GREEN+"/vote NO "+ChatColor.WHITE+"to cast your vote");
  71.  
  72. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  73. public void run() {
  74. if (plugin.yes > plugin.no)
  75. {
  76. List l = plugin.getServer().getWorlds();
  77. for (int i=0;i!=l.size();i++)
  78. {
  79. World w = (World)l.get(i);
  80. w.setTime(13500);
  81. }
  82. plugin.getServer().broadcastMessage("Vote passed! Changing to night...");
  83. }
  84. else if (plugin.no > plugin.yes)
  85. {
  86. plugin.getServer().broadcastMessage("Vote failed!");
  87. }
  88. plugin.yes = 0;
  89. plugin.no = 0;
  90. }
  91.  
  92. }, 600L);
  93. }
  94.  
  95. else
  96. {
  97. player.sendMessage("Usage: /createvote [day/night]");
  98. }
  99. }
  100. else
  101. {
  102. player.sendMessage("Usage: /createvote [day/night]");
  103. }
  104. }
  105. else
  106. {
  107. player.sendMessage("Insufficient permissisons!");
  108. }
  109. }
  110. if (cmd.getName().equalsIgnoreCase("vote"))
  111. {
  112. if (args.length == 1)
  113. {
  114. if (args[0].equalsIgnoreCase("yes"))
  115. {
  116. if (plugin.voted.contains(player))
  117. {
  118. player.sendMessage("You have already voted!");
  119. }
  120. else
  121. {
  122. player.getServer().broadcastMessage(player.getName()+" voted YES!");
  123. plugin.yes++;
  124. plugin.voted.add(player);
  125. }
  126. }
  127. else if (args[0].equalsIgnoreCase("no"))
  128. {
  129. if (plugin.voted.contains(player))
  130. {
  131. player.sendMessage("You have already voted!");
  132. }
  133. else
  134. {
  135. player.getServer().broadcastMessage(player.getName()+" voted NO!");
  136. plugin.no++;
  137. plugin.voted.add(player);
  138. }
  139. }
  140. else
  141. {
  142. player.sendMessage("Usage: /vote [yes/no]");
  143. }
  144. }
  145. }
  146. return true;
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment