Advertisement
Guest User

Untitled

a guest
May 30th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.70 KB | None | 0 0
  1. package com.projoosh.dev;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Location;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.plugin.PluginDescriptionFile;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. import com.projoosh.dev.game.Game;
  19. import com.projoosh.dev.game.GameManager;
  20. import com.projoosh.dev.game.GameState;
  21.  
  22. public class TournamentPVP extends JavaPlugin {
  23.  
  24. //Create instance
  25. public static TournamentPVP INSTANCE;
  26. FileConfiguration config = this.getConfig();
  27.  
  28. //When Plugin is Enabled
  29. @Override
  30. public void onEnable() {
  31. INSTANCE = this;
  32. saveDefaultConfig();
  33. GameManager.INSTANCE.init();
  34. }
  35.  
  36. //When Plugin is Disabled
  37. @Override
  38. public void onDisable() {
  39. INSTANCE = null;
  40. for (Player player : Bukkit.getOnlinePlayers()) {
  41. player.kickPlayer(ChatColor.RED + "GG! " + ChatColor.GOLD + "The lobby has restarted!");
  42. }
  43. }
  44.  
  45. public List<String> peopleVoted = new ArrayList<String>();
  46.  
  47.  
  48.  
  49.  
  50. //Game Settings
  51. int minPlayers = this.getConfig().getInt("Game.Min-Players", 3);
  52. int killPoints = this.getConfig().getInt("Game.Points-Kill", 75);
  53. int deathPoints = this.getConfig().getInt("Game.Points-Death", 100);
  54. int startPoints = this.getConfig().getInt("Game.Points-Start", 600);
  55. public HashMap<String, Integer> mapVotes = new HashMap<String, Integer>();
  56.  
  57.  
  58.  
  59. //Player spawning Functions, Locations, Variables and Commands
  60. public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
  61.  
  62. //Make sure command sender is player
  63. if(!(sender instanceof Player)){
  64. sender.sendMessage(ChatColor.RED + "You need to be a player to do commands.");
  65. return false;
  66. }
  67.  
  68.  
  69. //Define the sender as a player
  70. Player player = (Player) sender;
  71.  
  72. //Add Arena Command
  73. if(command.getName().equalsIgnoreCase("addarena")){
  74. if(player.hasPermission("tournament.addarena")){
  75. if(args.length == 1){
  76. String name = args[0];
  77. config.set("Arenas." + name + ".Spawns.mWorld", null);
  78. TournamentPVP.INSTANCE.saveConfig();
  79. player.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + name + ChatColor.RED + " was added");
  80. return false;
  81. }else{
  82. player.sendMessage(ChatColor.RED + "Usage: /addarena <name>");
  83. return false;
  84. }
  85. }else{
  86. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  87. return false;
  88. }
  89. }
  90.  
  91. //Delete Arena Command
  92. if(command.getName().equalsIgnoreCase("delarena")){
  93. if(player.hasPermission("tournament.delarena")){
  94. if(args.length == 1){
  95. String name = args[0];
  96.  
  97. if (!config.isSet("Arenas." + name)){
  98. sender.sendMessage(ChatColor.RED + "That arena " + ChatColor.GOLD + name + ChatColor.RED + " does not exist");
  99. return false;
  100. }
  101. config.set("Arenas." + name, null);
  102. sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + name + ChatColor.RED + " was removed");
  103. return false;
  104. }else{
  105. player.sendMessage(ChatColor.RED + "Usage: /delarena <name>");
  106. return false;
  107. }
  108. }else{
  109. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  110. return false;
  111. }
  112. }
  113.  
  114. //Set Lobby Command
  115. if(command.getName().equalsIgnoreCase("setlobbyspawn")){
  116. if(player.hasPermission("tournament.setlobby")){
  117. Location location = player.getLocation();
  118.  
  119. config.set("Settings.LobbySpawn.X", Integer.valueOf(location.getBlockX()));
  120. config.set("Settings.LobbySpawn.Y", Integer.valueOf(location.getBlockY()));
  121. config.set("Settings.LobbySpawn.Z", Integer.valueOf(location.getBlockZ()));
  122. config.set("Settings.LobbySpawn.World", location.getWorld().getName());
  123. player.sendMessage(ChatColor.RED + "The lobby spawn has been set.");
  124. return false;
  125. }else{
  126. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  127. return false;
  128. }
  129. }
  130.  
  131. //Add Spawn Command
  132. if(command.getName().equalsIgnoreCase("addspawn")){
  133. if(player.hasPermission("tournament.addspawn")){
  134. if(args.length == 2){
  135. Location location = player.getLocation();
  136.  
  137. String arena = args[0];
  138. String name = args[1];
  139. if (!config.isSet("Arenas." + arena)){
  140. sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + arena + ChatColor.RED + " does not exist");
  141. return false;
  142. }
  143. config.set("Arenas." + arena + ".Spawns." + name + ".X", Integer.valueOf(location.getBlockX()));
  144. config.set("Arenas." + arena + ".Spawns." + name + ".Y", Integer.valueOf(location.getBlockY()));
  145. config.set("Arenas." + arena + ".Spawns." + name + ".Z", Integer.valueOf(location.getBlockZ()));
  146. config.set("Arenas." + arena + ".Spawns." + name + ".World", location.getWorld().getName());
  147. player.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " was added for the arena " + ChatColor.GOLD + arena);
  148. return false;
  149. }else{
  150. player.sendMessage(ChatColor.RED + "Usage: /addspawn <arena> <number>");
  151. return false;
  152. }
  153. }else{
  154. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  155. return false;
  156. }
  157. }
  158.  
  159. //Delete spawn command
  160. if(command.getName().equalsIgnoreCase("delspawn")){
  161. if(player.hasPermission("tournament.delspawn")){
  162. if(args.length == 2){
  163.  
  164. String arena = args[0];
  165. String name = args[1];
  166. if (!config.isSet("Arenas." + arena)){
  167. sender.sendMessage(ChatColor.RED + "The arena " + ChatColor.GOLD + arena + ChatColor.RED + " does not exist");
  168. return false;
  169. }
  170. if (!config.isSet("Arenas." + arena + ".Spawns." + name)){
  171. sender.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " does not exist in the arena " + ChatColor.GOLD + arena);
  172. return false;
  173. }
  174. config.set("Arenas." + arena + ".Spawns." + name, null);
  175. sender.sendMessage(ChatColor.RED + "The spawn point " + ChatColor.GOLD + name + ChatColor.RED + " was removed in arena " + ChatColor.GOLD + arena);
  176. return false;
  177. }else{
  178. player.sendMessage(ChatColor.RED + "Usage: /delspawn <arena> <number>");
  179. return false;
  180. }
  181. }else{
  182. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  183. return false;
  184. }
  185. }
  186.  
  187. //Server info
  188. PluginDescriptionFile pdf = this.getDescription(); //Gets plugin.yml
  189. pdf.getVersion(); //Gets the version
  190.  
  191. //Plugin Information Command
  192. if(command.getName().equalsIgnoreCase("config")){
  193. if(player.hasPermission("tournament.config")){
  194. player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "------ " + ChatColor.RED + "Information" + ChatColor.GOLD + " ------" + ChatColor.GOLD + "-");
  195. player.sendMessage(ChatColor.GOLD + "Name: " + ChatColor.RED + "TournamentPVP");
  196. player.sendMessage(ChatColor.GOLD + "Creator: " + ChatColor.RED + "JooshYT");
  197. player.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.RED + pdf.getVersion());
  198. player.sendMessage(ChatColor.GOLD + "Min Players: " + ChatColor.RED + minPlayers );
  199. player.sendMessage(ChatColor.GOLD + "Start Points: " + ChatColor.RED + startPoints );
  200. player.sendMessage(ChatColor.GOLD + "Kill Points: " + ChatColor.RED + killPoints );
  201. player.sendMessage(ChatColor.GOLD + "Death Points: " + ChatColor.RED + deathPoints );
  202. player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "-----------------------" + ChatColor.GOLD + "-");
  203. }else{
  204. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  205. return false;
  206. }
  207. }
  208.  
  209.  
  210.  
  211.  
  212. //Vote Command
  213. if(command.getName().equalsIgnoreCase("vote")){
  214. for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
  215. if(mapVotes.get(key) == null){
  216. mapVotes.put(key, 0);
  217. }
  218. }
  219.  
  220. if(player.hasPermission("tournament.vote")){
  221. if(Game.getState() == GameState.VOTING){
  222. if(args.length == 1){
  223. //Get the state from the class Game
  224. String arenaPicked = args[0];
  225. if(this.getConfig().isSet("Arenas." + arenaPicked)){
  226.  
  227.  
  228. for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
  229. if(mapVotes.get(key) == null){
  230. mapVotes.put(key, 0);
  231. }
  232. }
  233.  
  234.  
  235.  
  236. if(inList(player)){
  237. player.sendMessage(ChatColor.RED + "Sorry, you have already voted.");
  238. return false;
  239. }
  240.  
  241.  
  242.  
  243. if(mapVotes.get(arenaPicked) != null){
  244. player.sendMessage(ChatColor.RED + "You have voted for the map: " + ChatColor.GOLD + arenaPicked + ChatColor.RED + ".");
  245. mapVotes.put(arenaPicked, mapVotes.get(arenaPicked)+1);
  246. peopleVoted.add(player.getName());
  247. return false;
  248. }
  249.  
  250.  
  251.  
  252. }else{
  253. player.sendMessage(ChatColor.RED + "Sorry, that map is not found. Please vote again.");
  254. }
  255. }else{
  256.  
  257. player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "----- " + ChatColor.RED + "/vote <name>" + ChatColor.GOLD + " -----" + ChatColor.GOLD + "-");
  258.  
  259. for(String key : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
  260. player.sendMessage(ChatColor.GOLD + "- " + ChatColor.RED + key + ChatColor.RED + " - " + mapVotes.get(key) + " Vote(s)");
  261. }
  262.  
  263. player.sendMessage(ChatColor.GOLD + "-" + ChatColor.GOLD + "----------------------" + ChatColor.GOLD + "-");
  264. }
  265. }else{
  266. player.sendMessage(ChatColor.RED + "You are not allowed to vote now.");
  267. return false;
  268. }
  269. }else{
  270. player.sendMessage(ChatColor.RED + "Sorry, You dont have permission for this.");
  271. return false;
  272. }
  273. }
  274.  
  275.  
  276. //End
  277. return false;
  278. }
  279.  
  280. public boolean inList(Player player) {
  281. return peopleVoted.contains(player.getName());
  282. }
  283.  
  284.  
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement