Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.yazhog.lionhub.utils;
- import java.util.*;
- import java.util.Map.Entry;
- import org.bukkit.Location;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import fr.yazhog.lionapi.spigot.LionSpigot;
- public class Classement {
- private Location loc;
- private ArrayList<ArmorStand> stands = new ArrayList<ArmorStand>();
- private ArrayList<String> top = new ArrayList<String>();
- @SuppressWarnings("unchecked")
- public Classement(Location loc, String title, HashMap<String, Integer> map) {
- this.setLoc(loc);
- Map<String, Integer> tri = sort(map);
- ArmorStand s = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
- s.setGravity(false);
- s.setBasePlate(false);
- s.setVisible(false);
- s.setCustomNameVisible(true);
- loc.add(0, -0.5, 0);
- stands.add(s);
- int i = 0;
- for(Entry<String, Integer> entry : tri.entrySet()) {
- i++;
- if(i > 10) {
- break;
- }
- top.add(entry.getKey());
- ArmorStand stand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
- stand.setGravity(false);
- stand.setBasePlate(false);
- stand.setVisible(false);
- stand.setCustomNameVisible(true);
- stand.setCustomName("§dTest"); // use time format for int or other
- System.out.println(entry.getKey() + " -> " + new FormatTime(entry.getValue()).toString());
- loc.add(0, -0.5, 0);
- stands.add(stand);
- }
- }
- public void update(HashMap<String, Integer> map) {
- top.clear();
- Map<String, Integer> tri = sort(map);
- int i = 0;
- for(Entry<String, Integer> entry : tri.entrySet()) {
- i++;
- if(i > 10) {
- break;
- }
- top.add(entry.getKey());
- }
- i = 1;
- for(String players : top) {
- stands.get(i).setCustomName(players + " -> " + new FormatTime(LionSpigot.get().getAccountManager().get(players).getJump().getSec()).toString());
- }
- }
- public void despawn() {
- for(ArmorStand s : stands) {
- s.setCustomNameVisible(false);
- s.remove();
- }
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private HashMap sort(HashMap map) {
- List linkedlist = new LinkedList(map.entrySet());
- Collections.sort(linkedlist, new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) ((Map.Entry) (o1)).getValue())
- .compareTo(((Map.Entry) (o2)).getValue());
- }
- });
- HashMap sortedHashMap = new LinkedHashMap();
- for (Iterator it = linkedlist.iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- sortedHashMap.put(entry.getKey(), entry.getValue());
- }
- return sortedHashMap;
- }
- public Location getLoc() {
- return loc;
- }
- public void setLoc(Location loc) {
- this.loc = loc;
- }
- public ArrayList<String> getTop() {
- return top;
- }
- public void setTop(ArrayList<String> top) {
- this.top = top;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement