Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.85 KB | None | 0 0
  1. package me.sitrismc.footballedition;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.OfflinePlayer;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.scoreboard.Team;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.Collections;
  11. import java.util.List;
  12. import java.util.Random;
  13.  
  14. /**
  15.  * Created by linse_000 on 10/31/2014.
  16.  */
  17. public class FootballUtils {
  18.  
  19.     FootballEdition plugin;
  20.  
  21.     public void randomizeFormation(Team team) {
  22.         Random r = new Random();
  23.  
  24.         if (team.getSize() != 11) {
  25.             Bukkit.broadcastMessage(ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + team.getDisplayName() + " does not have 11 people");
  26.             return;
  27.         }
  28.  
  29.         int formation = r.nextInt(3) + 1;
  30.         if (formation == 1) {
  31.             firstFormation(team);
  32.             return;
  33.         } else if (formation == 2) {
  34.             secondFormation(team);
  35.             return;
  36.         } else if (formation == 3) {
  37.             thirdFormation(team);
  38.             return;
  39.         } else if (formation == 4) {
  40.             fourthFormation(team);
  41.             return;
  42.         } else if (formation == 5) {
  43.             fifthFormation(team);
  44.             return;
  45.         } else {
  46.             firstFormation(team);
  47.         }
  48.     }
  49.  
  50.     public void firstFormation(Team team) {
  51.  
  52.         List<String> randomTeam = new ArrayList<String>();
  53.  
  54.         for (OfflinePlayer p : team.getPlayers()) {
  55.             randomTeam.add(p.getName());
  56.         }
  57.  
  58.         for (int i = 0 ; i < 4 ; i++) {
  59.             plugin.positions.put(randomTeam.get(i), "Defender");
  60.         }
  61.         for (int i = 4 ; i < 8 ; i++) {
  62.             plugin.positions.put(randomTeam.get(i), "Midfielders");
  63.         }
  64.         for (int i = 8 ; i < 10 ; i++) {
  65.             plugin.positions.put(randomTeam.get(i), "Forwards");
  66.         }
  67.         plugin.positions.put(randomTeam.get(10), "Goalkeeper");
  68.  
  69.         Random r = new Random();
  70.         plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
  71.  
  72.         for (OfflinePlayer p : team.getPlayers()) {
  73.             if (p.isOnline()) {
  74.                 Player player = Bukkit.getPlayer(p.getName());
  75.                 player.sendMessage(plugin.getPrefix() + "Positions");
  76.                 for (String s : randomTeam) {
  77.                     if (plugin.captains.contains(s)) {
  78.                         Player potcap = Bukkit.getPlayer(s);
  79.                         if (potcap != null) {
  80.                             player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
  81.                         }
  82.                     } else {
  83.                         player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.     }
  89.  
  90.     public void secondFormation(Team team) {
  91.         List<String> randomTeam = new ArrayList<String>();
  92.  
  93.         for (OfflinePlayer p : team.getPlayers()) {
  94.             randomTeam.add(p.getName());
  95.         }
  96.  
  97.         for (int i = 0 ; i < 4 ; i++) {
  98.             plugin.positions.put(randomTeam.get(i), "Defender");
  99.         }
  100.         for (int i = 4 ; i < 7 ; i++) {
  101.             plugin.positions.put(randomTeam.get(i), "Midfielders");
  102.         }
  103.         for (int i = 7 ; i < 10 ; i++) {
  104.             plugin.positions.put(randomTeam.get(i), "Forwards");
  105.         }
  106.         plugin.positions.put(randomTeam.get(10), "Goalkeeper");
  107.  
  108.         Random r = new Random();
  109.         plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
  110.  
  111.         for (OfflinePlayer p : team.getPlayers()) {
  112.             if (p.isOnline()) {
  113.                 Player player = Bukkit.getPlayer(p.getName());
  114.                 player.sendMessage(plugin.getPrefix() + "Positions");
  115.                 for (String s : randomTeam) {
  116.                     if (plugin.captains.contains(s)) {
  117.                         Player potcap = Bukkit.getPlayer(s);
  118.                         if (potcap != null) {
  119.                             player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
  120.                         }
  121.                     } else {
  122.                         player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
  123.                     }
  124.                 }
  125.             }
  126.         }
  127.     }
  128.  
  129.     public void thirdFormation(Team team) {
  130.         List<String> randomTeam = new ArrayList<String>();
  131.  
  132.         for (OfflinePlayer p : team.getPlayers()) {
  133.             randomTeam.add(p.getName());
  134.         }
  135.  
  136.         for (int i = 0 ; i < 5 ; i++) {
  137.             plugin.positions.put(randomTeam.get(i), "Defender");
  138.         }
  139.         for (int i = 5 ; i < 9 ; i++) {
  140.             plugin.positions.put(randomTeam.get(i), "Midfielders");
  141.         }
  142.         plugin.positions.put(randomTeam.get(9), "Forward");
  143.         plugin.positions.put(randomTeam.get(10), "Goalkeeper");
  144.  
  145.         Random r = new Random();
  146.         plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
  147.  
  148.         for (OfflinePlayer p : team.getPlayers()) {
  149.             if (p.isOnline()) {
  150.                 Player player = Bukkit.getPlayer(p.getName());
  151.                 player.sendMessage(plugin.getPrefix() + "Positions");
  152.                 for (String s : randomTeam) {
  153.                     if (plugin.captains.contains(s)) {
  154.                         Player potcap = Bukkit.getPlayer(s);
  155.                         if (potcap != null) {
  156.                             player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
  157.                         }
  158.                     } else {
  159.                         player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
  160.                     }
  161.                 }
  162.             }
  163.         }
  164.     }
  165.  
  166.     public void fourthFormation(Team team) {
  167.  
  168.     }
  169.  
  170.     public void fifthFormation(Team team) {
  171.  
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement