Advertisement
Guest User

Game.java

a guest
Jun 7th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. package main.dartanman.fpvp.game;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Sign;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.player.PlayerInteractEvent;
  18.  
  19. import main.dartanman.fpvp.Main;
  20. import net.md_5.bungee.api.ChatColor;
  21.  
  22. public class Game implements CommandExecutor,Listener{
  23. private Main plugin;
  24.  
  25. public Game(Main pl)
  26. {
  27. this.plugin = pl;
  28. }
  29.  
  30. ArrayList<Player> red = new ArrayList<Player>();
  31. ArrayList<Player> blue = new ArrayList<Player>();
  32.  
  33.  
  34.  
  35. @Override
  36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  37. FileConfiguration config = plugin.getConfig();
  38. Player player = (Player) sender;
  39. if(!(sender instanceof Player)){
  40. sender.sendMessage("Only players can use this command!");
  41. return false;
  42. }
  43. if(args.length == 0){
  44. player.sendMessage(ChatColor.BLUE + "FrostGame Help Menu:");
  45. player.sendMessage(ChatColor.GREEN + "/fg setlobby" + ChatColor.GOLD + " - " + ChatColor.BLUE + "Set the minigame lobby");
  46. return true;
  47. }
  48. if(args.length == 1){
  49. if(args[0].equalsIgnoreCase("setlobby")){
  50.  
  51. Location loc = player.getLocation();
  52.  
  53. config.set("location.World" , loc.getWorld().getName());
  54. config.set("location.X" , loc.getX());
  55. config.set("location.Y" , loc.getY());
  56. config.set("location.Z" , loc.getZ());
  57. player.sendMessage(ChatColor.GREEN + "Lobby set!");
  58. return true;
  59. }
  60. if(args[0].equalsIgnoreCase("setquit")){
  61.  
  62. Location loc = player.getLocation();
  63.  
  64. config.set("location2.World" , loc.getWorld().getName());
  65. config.set("location2.X" , loc.getX());
  66. config.set("location2.Y" , loc.getY());
  67. config.set("location2.Z" , loc.getZ());
  68. player.sendMessage(ChatColor.GREEN + "Quit spot set!");
  69. return true;
  70. }
  71. if(args[0].equalsIgnoreCase("setspawn1")){
  72.  
  73. Location loc = player.getLocation();
  74.  
  75. config.set("location3.World" , loc.getWorld().getName());
  76. config.set("location3.X" , loc.getX());
  77. config.set("location3.Y" , loc.getY());
  78. config.set("location3.Z" , loc.getZ());
  79. player.sendMessage(ChatColor.GREEN + "Spawn 1 set!");
  80. return true;
  81. }
  82. if(args[0].equalsIgnoreCase("setspawn2")){
  83.  
  84. Location loc = player.getLocation();
  85.  
  86. config.set("location4.World" , loc.getWorld().getName());
  87. config.set("location4.X" , loc.getX());
  88. config.set("location4.Y" , loc.getY());
  89. config.set("location4.Z" , loc.getZ());
  90. player.sendMessage(ChatColor.GREEN + "Spawn 2 set!");
  91. return true;
  92. }
  93. if(args[0].equalsIgnoreCase("join")){
  94. Location newLoc = new Location(Bukkit.getWorld((String) config.get("location.World")), config.getDouble("location.X"), config.getDouble("location.Y"), config.getDouble("location.Z"));
  95. player.teleport(newLoc);
  96. if(blue.size() == 0){
  97. blue.add(player);
  98. red.remove(player);
  99. player.sendMessage(ChatColor.BLUE + "You were added to the blue team");
  100. }else if(red.size() == 0){
  101. red.add(player);
  102. blue.remove(player);
  103. player.sendMessage(ChatColor.RED + "You were added to the red team");
  104. }
  105.  
  106. }else if(red.size() == 1 && blue.size() == 1){
  107.  
  108. player.sendMessage("Please wait til the current battle is over");
  109.  
  110. }
  111.  
  112.  
  113. player.sendMessage(ChatColor.GREEN + "You have joined the game!");
  114. return true;
  115. }
  116. if(args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("leave")){
  117. Location newLoc = new Location(Bukkit.getWorld((String) config.get("location2.World")), config.getDouble("location2.X"), config.getDouble("location2.Y"), config.getDouble("location2.Z"));
  118. player.teleport(newLoc);
  119. player.sendMessage(ChatColor.GREEN + "You have joined the game!");
  120. return true;
  121. }
  122. player.sendMessage(ChatColor.RED + "Improper args! Try again!");
  123. return true;
  124. }
  125. @EventHandler
  126. public void onInteract(PlayerInteractEvent event){
  127. FileConfiguration config = plugin.getConfig();
  128. Player player = (Player) event.getPlayer();
  129. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  130. if(event.getClickedBlock().getType() == Material.SIGN ||
  131. event.getClickedBlock().getType() == Material.WALL_SIGN ||
  132. event.getClickedBlock().getType() == Material.SIGN_POST){
  133. Sign sign = (Sign) event.getClickedBlock().getState();
  134. if(sign.getLine(0).equalsIgnoreCase("[FrostPvP]") && sign.getLine(1).equalsIgnoreCase("[Start]")){
  135. if(red.contains(player)){
  136. Location newLoc = new Location(Bukkit.getWorld((String) config.get("location3.World")), config.getDouble("location3.X"), config.getDouble("location3.Y"), config.getDouble("location3.Z"));
  137. player.teleport(newLoc);
  138. player.sendMessage(ChatColor.GREEN + "The game is starting");
  139. }
  140. if(blue.contains(player)){
  141. Location newLoc = new Location(Bukkit.getWorld((String) config.get("location4.World")), config.getDouble("location4.X"), config.getDouble("location4.Y"), config.getDouble("location4.Z"));
  142. player.teleport(newLoc);
  143. player.sendMessage(ChatColor.GREEN + "The game is starting");
  144. } else{
  145. player.sendMessage(ChatColor.RED + "You are not in a game!");
  146. }
  147.  
  148. }
  149.  
  150. }
  151.  
  152. }
  153. }
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement