Advertisement
Guest User

RankedPlayer.java

a guest
Jan 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. package org.thewolfbadger.prisontop.api;
  2.  
  3. import org.thewolfbadger.prisontop.main.PrisonTop;
  4.  
  5. import java.util.List;
  6.  
  7. /**
  8.  * Created by user on 1/17/2018.
  9.  */
  10. public class RankedPlayer implements Comparable<RankedPlayer> {
  11.     private int prestige = 0;
  12.     private int rankLevel = 1;
  13.     private int balance = 0;
  14.     private String uuid = "";
  15.     private PrisonTop pt;
  16.     public RankedPlayer(PrisonTop pt, String uuid, int prestige, int rankLevel, int balance) {
  17.         this.pt = pt;
  18.         this.uuid = uuid;
  19.         this.prestige = prestige;
  20.         this.rankLevel = rankLevel;
  21.         this.balance = balance;
  22.     }
  23.     /**
  24.      *
  25.      * @param otherPlayer the object to be compared.
  26.      * @return a negative integer, zero, or a positive integer as this object
  27.      * is less than, equal to, or greater than the specified object.
  28.      * @throws NullPointerException if the specified object is null
  29.      * @throws ClassCastException   if the specified object's type prevents it
  30.      *                              from being compared to this object.
  31.      */
  32.     @Override
  33.     public int compareTo(RankedPlayer otherPlayer) {
  34.         /*
  35.          * -1 : This is less than otherPlayer
  36.          *  0 : This is equal to otherPlayer
  37.          *  1 : This is greater than otherPlayer
  38.          */
  39.         if(otherPlayer.getPrestige() > this.prestige) {
  40.             // They are higher prestige
  41.             return -1;
  42.         } else
  43.             if(otherPlayer.getPrestige() == this.prestige) {
  44.                 // They are same prestige
  45.                 if(otherPlayer.getRankLevel() > this.rankLevel) {
  46.                     //They are higher rank
  47.                     return -1;
  48.                 } else
  49.                     if(otherPlayer.getRankLevel() == this.rankLevel) {
  50.                         //They are same rank as us
  51.                         if(otherPlayer.getBalance() > this.balance) {
  52.                             //They have more money
  53.                             return -1;
  54.                         } else
  55.                             if(otherPlayer.getBalance() == this.balance) {
  56.                                 //They have same money as well... Equal ranking
  57.                                 return 0;
  58.                             }
  59.                     }
  60.             }
  61.         return 1;
  62.     }
  63.  
  64.     public int getRankingComparedTo(List<RankedPlayer> otherPlayers) {
  65.         int ranking = 1;
  66.         for(RankedPlayer otherPlayer : otherPlayers) {
  67.             if(!otherPlayer.getID().equals(this.uuid)) {
  68.                 if (otherPlayer.compareTo(this) == 1) {
  69.                     // Other player is higher ranking
  70.                     ranking++;
  71.                 } else
  72.                     if (otherPlayer.compareTo(this) == 0) {
  73.                     // Other player is of equal ranking
  74.                 }
  75.             }
  76.         }
  77.         return ranking;
  78.     }
  79.  
  80.  
  81.     public String getID() {
  82.         return this.uuid;
  83.     }
  84.     public int getPrestige() {
  85.         return this.prestige;
  86.     }
  87.     public int getRankLevel() {
  88.         return this.rankLevel;
  89.     }
  90.     public int getBalance() {
  91.         return this.balance;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement