Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.35 KB | None | 0 0
  1. package com.kNoAPP.Zones.aspects;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Color;
  9. import org.bukkit.entity.Player;
  10.  
  11. import com.kNoAPP.Zones.mapdata.Area;
  12.  
  13. public enum GameTeam {
  14.    
  15.     WHITE("White", RGB.WHITE, ChatColor.WHITE, Color.WHITE, (byte) 0, 0),
  16.     RED("Red", RGB.RED, ChatColor.RED, Color.RED, (byte) 14, 1),
  17.     BLUE("Blue", RGB.BLUE, ChatColor.BLUE, Color.BLUE, (byte) 11, 2),
  18.     GREEN("Green", RGB.GREEN, ChatColor.GREEN, Color.GREEN, (byte) 5, 3),
  19.     YELLOW("Yellow", RGB.YELLOW, ChatColor.YELLOW, Color.YELLOW, (byte) 4, 4);
  20.    
  21.     public static GameTeam winner;
  22.    
  23.     private String name;
  24.     private RGB rgb;
  25.     private ChatColor color;
  26.     private Color c;
  27.     private byte data;
  28.     private int priority;
  29.    
  30.     private List<Player> players = new ArrayList<Player>();
  31.    
  32.     private GameTeam(String name, RGB rgb, ChatColor color, Color c, byte data, int priority) {
  33.         this.name = name;
  34.         this.rgb = rgb;
  35.         this.color = color;
  36.         this.c = c;
  37.         this.data = data;
  38.         this.priority = priority;
  39.     }
  40.    
  41.     public String getName() {
  42.         return name;
  43.     }
  44.    
  45.     public RGB getRGB() {
  46.         return rgb;
  47.     }
  48.    
  49.     public ChatColor getColor() {
  50.         return color;
  51.     }
  52.    
  53.     public Color getC() {
  54.         return c;
  55.     }
  56.    
  57.     public byte getData() {
  58.         return data;
  59.     }
  60.    
  61.     public int getPriority() {
  62.         return priority;
  63.     }
  64.    
  65.     public List<Player> getPlayers() {
  66.         return players;
  67.     }
  68.    
  69.     public void addPlayer(Player p) {
  70.         if(!players.contains(p)) {
  71.             players.add(p);
  72.         }
  73.     }
  74.    
  75.     public void removePlayer(Player p) {
  76.         if(players.contains(p)) {
  77.             players.remove(p);
  78.         }
  79.     }
  80.    
  81.     public boolean hasWon() {
  82.         for(Area a : GameMap.current.getAreas()) {
  83.             if(a.getOwner() != this) {
  84.                 return false;
  85.             }
  86.         }
  87.         return true;
  88.     }
  89.    
  90.     public static void wipePlayer(Player p) {
  91.         for(GameTeam gt : values()) {
  92.             if(gt.getPlayers().contains(p)) {
  93.                 gt.removePlayer(p);
  94.             }
  95.         }
  96.     }
  97.    
  98.     public static GameTeam getPlayer(Player p) {
  99.         for(GameTeam gt : values()) {
  100.             if(gt.getPlayers().contains(p)) {
  101.                 return gt;
  102.             }
  103.         }
  104.         return null;
  105.     }
  106.    
  107.     public static GameTeam getTeamByName(String n) {
  108.         for(GameTeam t : GameTeam.values()) {
  109.             if(t.getName().equalsIgnoreCase(n)) {
  110.                 return t;
  111.             }
  112.         }
  113.         return null;
  114.     }
  115.    
  116.     public static ArrayList<GameTeam> getTeams(int team) {
  117.         ArrayList<GameTeam> teams = new ArrayList<GameTeam>();
  118.         for(GameTeam t : values()) {
  119.             if(t.getPriority() <= team) {
  120.                 teams.add(t);
  121.             }
  122.         }
  123.         return teams;
  124.     }
  125.    
  126.     public static GameTeam lowest() {
  127.         GameTeam lowest = RED;
  128.         for(GameTeam gt : GameMap.current.getTeams()) {
  129.             if(lowest.getPlayers().size() > gt.getPlayers().size()) {
  130.                 lowest = gt;
  131.             }
  132.         }
  133.         return lowest;
  134.     }
  135.    
  136.     public static GameTeam zoneLeader() {
  137.         HashMap<GameTeam, Double> score = new HashMap<GameTeam, Double>();
  138.         for(GameTeam gt : GameMap.current.getTeams()) {
  139.             score.put(gt, 0.0);
  140.         }
  141.        
  142.         for(Area a : GameMap.current.getAreas()) {
  143.             double tS = score.get(a.getLeader());
  144.             tS += a.getCapture();
  145.             score.put(a.getLeader(), tS);
  146.         }
  147.        
  148.         //Find Highest
  149.         double h = Double.MIN_VALUE;
  150.         GameTeam minGt = GameTeam.WHITE;
  151.         for(GameTeam gt : score.keySet()) {
  152.             double v = score.get(gt);
  153.             if(v > h) {
  154.                 h = v;
  155.                 minGt = gt;
  156.             } else if(v == h){
  157.                 return GameTeam.WHITE;
  158.             }
  159.         }
  160.         return minGt;
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement