h31ix

Untitled

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