Advertisement
Guest User

Untitled

a guest
Jul 17th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. package net.voxelmc.donorvote;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.World;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14.  
  15. public class DonorVote extends JavaPlugin {
  16.  
  17. public void onEnable() {
  18. loadConfiguration();
  19. }
  20. public boolean onCommand(CommandSender sender, Command cmd,
  21. String label, String[] args) {
  22. if (cmd.getLabel().equalsIgnoreCase("startvote")) {
  23. if (sender.hasPermission("donorvote.startvote")) {
  24. String type = "type";
  25. if (args[1] == "weather") {
  26. this.getConfig().addDefault(type, "weather");
  27. this.getConfig().addDefault("sun", 0);
  28. this.getConfig().addDefault("rain", 0);
  29. String[] players = { };
  30. this.getConfig().addDefault("players", Arrays.asList(players));
  31. sender.sendMessage("§3Vote started for weather.");
  32. Bukkit.broadcast("§5There is now a vote for weather. Use the /donorvote command and then sun or rain to vote.", "donorvote.vote");
  33. this.getConfig().options().copyDefaults(true);
  34. this.saveConfig();
  35. try {
  36. Thread.sleep(60000);
  37. } catch (InterruptedException e) {
  38. // TODO Auto-generated catch block
  39. e.printStackTrace();
  40. }
  41. Bukkit.broadcast("§5The vote for weather has now stopped.", "donorvote.vote");
  42. int sun = this.getConfig().getInt("sun");
  43. int rain = this.getConfig().getInt("rain");
  44. if (sun > rain) {
  45. World w = ((Player) sender).getWorld();
  46. w.setThundering(false);
  47. w.setStorm(false);
  48. Random rand = new Random();
  49. w.setWeatherDuration(rand.nextInt(100000));
  50. } else {
  51. World w = ((Player) sender).getWorld();
  52. w.setThundering(true);
  53. w.setStorm(true);
  54. }
  55. return true;
  56. } else if (args[1] == "time") {
  57. this.getConfig().addDefault(type, args[1]);
  58. this.getConfig().addDefault("day", 0);
  59. this.getConfig().addDefault("night", 0);
  60. String[] players = { };
  61. this.getConfig().addDefault("players", Arrays.asList(players));
  62. sender.sendMessage("§3Vote started for time.");
  63. Bukkit.broadcast("§5There is now a vote for time. Use the /donorvote command, and then day or night to vote.", "donorvote.vote");
  64. this.getConfig().options().copyDefaults(true);
  65. this.saveConfig();
  66. try {
  67. Thread.sleep(60000);
  68. } catch (InterruptedException e) {
  69. // TODO Auto-generated catch block
  70. e.printStackTrace();
  71. }
  72. Bukkit.broadcast("§5The vote for time has now stopped.", "donorvote.vote");
  73. int day = this.getConfig().getInt("day");
  74. int night = this.getConfig().getInt("night");
  75. World w = ((Player) sender).getWorld();
  76. if (day > night) {
  77. w.setTime(1000);
  78. } else {
  79. w.setTime(12000);
  80. }
  81. return true;
  82. } else {
  83. sender.sendMessage("§4Please enter a valid vote type.");
  84. return false;
  85. }
  86. } else {
  87. sender.sendMessage("§4Sorry, you do not have permission to run this command.");
  88. return false;
  89. }
  90. } else if (cmd.getLabel().equalsIgnoreCase("donorvote")) {
  91. if (sender.hasPermission("donorvote.vote")) {
  92. if (sender instanceof Player) {
  93. String strSender = sender.getName();
  94. List playersList = this.getConfig().getStringList("players");
  95. String[] playerArray = new String[playersList.size()];
  96. playersList.toArray(playerArray);
  97. String userName = "";
  98. int i = 0;
  99. while (userName != null) {
  100. userName = playerArray[i];
  101. if (userName == sender.getName()) {
  102. sender.sendMessage("§4Sorry, you already voted for this.");
  103. return false;
  104. }
  105. i = i + 1;
  106. }
  107. String type = this.getConfig().getString("type");
  108. if (type == "weather") {
  109. if (args[1] == "sun") {
  110. int pastSun = this.getConfig().getInt("sun");
  111. int nowSun = pastSun + 1;
  112. this.getConfig().set("sun", nowSun);
  113. String name = sender.getName();
  114. List playerList = this.getConfig().getStringList("players");
  115. playerList.add(name);
  116. this.getConfig().set("players", playerList);
  117. sender.sendMessage("§2Your vote has been casted!");
  118. return true;
  119. } else if (args[1] == "rain") {
  120. int pastRain = this.getConfig().getInt("rain");
  121. int nowRain = pastRain + 1;
  122. this.getConfig().set("rain", nowRain);
  123. String name = sender.getName();
  124. List playerList = this.getConfig().getStringList("players");
  125. playerList.add(name);
  126. this.getConfig().set("players", playerList);
  127. sender.sendMessage("§2Your vote has been casted!");
  128. return true;
  129. } else {
  130. sender.sendMessage("§4" + args[1] + " is not a valid vote.");
  131. return false;
  132. }
  133. } else {
  134. if (args[1] == "day") {
  135. int pastDay = this.getConfig().getInt("day");
  136. int nowDay = pastDay + 1;
  137. this.getConfig().set("day", nowDay);
  138. String name = sender.getName();
  139. List playerList = this.getConfig().getStringList("players");
  140. playerList.add(name);
  141. this.getConfig().set("players", playerList);
  142. sender.sendMessage("§2Your vote has been casted!");
  143. return true;
  144. } else if (args[1] == "night") {
  145. int pastNight = this.getConfig().getInt("night");
  146. int nowNight = pastNight + 1;
  147. this.getConfig().set("night", nowNight);
  148. String name = sender.getName();
  149. List playerList = this.getConfig().getStringList("players");
  150. playerList.add(name);
  151. this.getConfig().set("players", playerList);
  152. sender.sendMessage("§2Your vote has been casted!");
  153. return true;
  154. } else {
  155. sender.sendMessage("§4" + args[1] + " is not a valid argument.");
  156. return false;
  157. }
  158. }
  159. } else {
  160. return false;
  161. }
  162. } else {
  163. sender.sendMessage("§4Sorry, you do not have permission to use this command.");
  164. return false;
  165. }
  166. } else {
  167. return false;
  168. }
  169. }
  170. public void loadConfiguration() {
  171. this.getConfig().options().copyDefaults(true);
  172. this.saveConfig();
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement