Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.sitrismc.footballedition;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.scoreboard.Team;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Random;
- /**
- * Created by linse_000 on 10/31/2014.
- */
- public class FootballUtils {
- FootballEdition plugin;
- public void randomizeFormation(Team team) {
- Random r = new Random();
- if (team.getSize() != 11) {
- Bukkit.broadcastMessage(ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + team.getDisplayName() + " does not have 11 people");
- return;
- }
- int formation = r.nextInt(3) + 1;
- if (formation == 1) {
- firstFormation(team);
- return;
- } else if (formation == 2) {
- secondFormation(team);
- return;
- } else if (formation == 3) {
- thirdFormation(team);
- return;
- } else if (formation == 4) {
- fourthFormation(team);
- return;
- } else if (formation == 5) {
- fifthFormation(team);
- return;
- } else {
- firstFormation(team);
- }
- }
- public void firstFormation(Team team) {
- List<String> randomTeam = new ArrayList<String>();
- for (OfflinePlayer p : team.getPlayers()) {
- randomTeam.add(p.getName());
- }
- for (int i = 0 ; i < 4 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Defender");
- }
- for (int i = 4 ; i < 8 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Midfielders");
- }
- for (int i = 8 ; i < 10 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Forwards");
- }
- plugin.positions.put(randomTeam.get(10), "Goalkeeper");
- Random r = new Random();
- plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
- for (OfflinePlayer p : team.getPlayers()) {
- if (p.isOnline()) {
- Player player = Bukkit.getPlayer(p.getName());
- player.sendMessage(plugin.getPrefix() + "Positions");
- for (String s : randomTeam) {
- if (plugin.captains.contains(s)) {
- Player potcap = Bukkit.getPlayer(s);
- if (potcap != null) {
- player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
- }
- } else {
- player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
- }
- }
- }
- }
- }
- public void secondFormation(Team team) {
- List<String> randomTeam = new ArrayList<String>();
- for (OfflinePlayer p : team.getPlayers()) {
- randomTeam.add(p.getName());
- }
- for (int i = 0 ; i < 4 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Defender");
- }
- for (int i = 4 ; i < 7 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Midfielders");
- }
- for (int i = 7 ; i < 10 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Forwards");
- }
- plugin.positions.put(randomTeam.get(10), "Goalkeeper");
- Random r = new Random();
- plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
- for (OfflinePlayer p : team.getPlayers()) {
- if (p.isOnline()) {
- Player player = Bukkit.getPlayer(p.getName());
- player.sendMessage(plugin.getPrefix() + "Positions");
- for (String s : randomTeam) {
- if (plugin.captains.contains(s)) {
- Player potcap = Bukkit.getPlayer(s);
- if (potcap != null) {
- player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
- }
- } else {
- player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
- }
- }
- }
- }
- }
- public void thirdFormation(Team team) {
- List<String> randomTeam = new ArrayList<String>();
- for (OfflinePlayer p : team.getPlayers()) {
- randomTeam.add(p.getName());
- }
- for (int i = 0 ; i < 5 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Defender");
- }
- for (int i = 5 ; i < 9 ; i++) {
- plugin.positions.put(randomTeam.get(i), "Midfielders");
- }
- plugin.positions.put(randomTeam.get(9), "Forward");
- plugin.positions.put(randomTeam.get(10), "Goalkeeper");
- Random r = new Random();
- plugin.captains.add(randomTeam.get(r.nextInt(randomTeam.size())));
- for (OfflinePlayer p : team.getPlayers()) {
- if (p.isOnline()) {
- Player player = Bukkit.getPlayer(p.getName());
- player.sendMessage(plugin.getPrefix() + "Positions");
- for (String s : randomTeam) {
- if (plugin.captains.contains(s)) {
- Player potcap = Bukkit.getPlayer(s);
- if (potcap != null) {
- player.sendMessage(ChatColor.GREEN + s + plugin.getMain() + ": " + plugin.positions.get(s));
- }
- } else {
- player.sendMessage(plugin.getMain() + s + ": " + plugin.positions.get(s));
- }
- }
- }
- }
- }
- public void fourthFormation(Team team) {
- }
- public void fifthFormation(Team team) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement