Advertisement
Yazhog_g

Untitled

Mar 21st, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. package fr.yazhog.lionhub.utils;
  2.  
  3. import java.util.*;
  4. import java.util.Map.Entry;
  5.  
  6. import org.bukkit.Location;
  7. import org.bukkit.entity.ArmorStand;
  8. import org.bukkit.entity.EntityType;
  9. import org.bukkit.entity.Player;
  10.  
  11. import fr.yazhog.lionapi.spigot.LionSpigot;
  12.  
  13. public class Classement {
  14.  
  15.     private Location loc;
  16.     private ArrayList<ArmorStand> stands = new ArrayList<ArmorStand>();
  17.     private ArrayList<String> top = new ArrayList<String>();
  18.  
  19.  
  20.     @SuppressWarnings("unchecked")
  21.     public Classement(Location loc, String title, HashMap<String, Integer> map) {
  22.         this.setLoc(loc);
  23.         Map<String, Integer> tri = sort(map);
  24.         ArmorStand s = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
  25.         s.setGravity(false);
  26.         s.setBasePlate(false);
  27.         s.setVisible(false);
  28.         s.setCustomNameVisible(true);
  29.         loc.add(0, -0.5, 0);
  30.         stands.add(s);
  31.         int i = 0;
  32.         for(Entry<String, Integer> entry : tri.entrySet()) {
  33.             i++;
  34.             if(i > 10) {
  35.                 break;
  36.             }
  37.             top.add(entry.getKey());
  38.             ArmorStand stand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
  39.             stand.setGravity(false);
  40.             stand.setBasePlate(false);
  41.             stand.setVisible(false);
  42.             stand.setCustomNameVisible(true);
  43.             stand.setCustomName("§dTest"); // use time format for int or other
  44.             System.out.println(entry.getKey() + " -> " + new FormatTime(entry.getValue()).toString());
  45.             loc.add(0, -0.5, 0);
  46.             stands.add(stand);
  47.         }
  48.     }
  49.  
  50.     public void update(HashMap<String, Integer> map) {
  51.         top.clear();
  52.         Map<String, Integer> tri = sort(map);
  53.         int i = 0;
  54.         for(Entry<String, Integer> entry : tri.entrySet()) {
  55.             i++;
  56.             if(i > 10) {
  57.                 break;
  58.             }
  59.             top.add(entry.getKey());
  60.         }
  61.         i = 1;
  62.         for(String players : top) {
  63.             stands.get(i).setCustomName(players + " -> " + new FormatTime(LionSpigot.get().getAccountManager().get(players).getJump().getSec()).toString());
  64.         }
  65.     }
  66.  
  67.     public void despawn() {
  68.         for(ArmorStand s : stands) {
  69.             s.setCustomNameVisible(false);
  70.             s.remove();
  71.         }
  72.     }
  73.  
  74.     @SuppressWarnings({ "unchecked", "rawtypes" })
  75.     private HashMap sort(HashMap map) {
  76.         List linkedlist = new LinkedList(map.entrySet());
  77.         Collections.sort(linkedlist, new Comparator() {
  78.             public int compare(Object o1, Object o2) {
  79.                 return ((Comparable) ((Map.Entry) (o1)).getValue())
  80.                         .compareTo(((Map.Entry) (o2)).getValue());
  81.             }
  82.         });
  83.         HashMap sortedHashMap = new LinkedHashMap();
  84.         for (Iterator it = linkedlist.iterator(); it.hasNext();) {
  85.             Map.Entry entry = (Map.Entry) it.next();
  86.             sortedHashMap.put(entry.getKey(), entry.getValue());
  87.         }
  88.         return sortedHashMap;
  89.     }
  90.  
  91.     public Location getLoc() {
  92.         return loc;
  93.     }
  94.  
  95.     public void setLoc(Location loc) {
  96.         this.loc = loc;
  97.     }
  98.  
  99.     public ArrayList<String> getTop() {
  100.         return top;
  101.     }
  102.  
  103.     public void setTop(ArrayList<String> top) {
  104.         this.top = top;
  105.     }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement