Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4. import java.util.HashMap;
  5. import java.util.LinkedHashMap;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Map.Entry;
  10. import java.util.UUID;
  11.  
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.Location;
  15. import org.bukkit.Material;
  16. import org.bukkit.SkullType;
  17. import org.bukkit.block.Block;
  18. import org.bukkit.block.BlockFace;
  19. import org.bukkit.block.BlockState;
  20. import org.bukkit.block.Sign;
  21. import org.bukkit.block.Skull;
  22. import org.bukkit.configuration.file.FileConfiguration;
  23.  
  24. public class Leaderboard {
  25.    
  26.     protected Object convertUUID(String s) {
  27.         if (s.matches("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")) {
  28.             return UUID.fromString(s);
  29.         } else {
  30.             return s;
  31.         }
  32.     }
  33.    
  34.      protected static Map<Integer, String> sortByComparator(Map<String, Integer> unsortMap, final boolean order) {
  35.          List<Entry<String, Integer>> list = new LinkedList<Entry<String, Integer>>(unsortMap.entrySet());
  36.          
  37.          Collections.sort(list, new Comparator<Entry<String, Integer>>() {
  38.              public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
  39.                  if (order) {
  40.                      return o1.getValue().compareTo(o2.getValue());
  41.                  } else {
  42.                      return o2.getValue().compareTo(o1.getValue());
  43.                  }
  44.              }
  45.          });
  46.          
  47.          Map<Integer, String> sortedMap = new LinkedHashMap<Integer, String>();
  48.          for (Entry<String, Integer> entry : list) {
  49.              for (int i = 1; i < 4; i++) {
  50.                  if (!sortedMap.containsKey(i)) {
  51.                      sortedMap.put(i, entry.getKey());
  52.                      break;
  53.                  }
  54.              }
  55.          }
  56.          
  57.          return sortedMap;
  58.      }
  59.  
  60.      
  61.      @SuppressWarnings("deprecation")
  62.      public Leaderboard(Location firstPlace, Location secondPlace, Location thirdPlace, Material firstBlockType, Material secondBlockType, Material thirdBlockType, BlockFace direction, FileConfiguration configurationFile, String configurationFormat) {
  63.          String[] a = configurationFormat.split("\\.");
  64.          
  65.          int playerConfigLocation = -1;
  66.          
  67.          for (int i = 0; i < a.length; i++) {
  68.              if (a[i].equals("player")) {
  69.                  playerConfigLocation = i;
  70.              }
  71.          }
  72.          
  73.          if (playerConfigLocation == -1) return;
  74.        
  75.          ArrayList<String> b = new ArrayList<String>();
  76.        
  77.          for (String ba : a) {
  78.              if (!ba.equals("player")) {
  79.                  b.add(ba);
  80.              } else {
  81.                  break;
  82.              }
  83.          }
  84.        
  85.          ArrayList<String> c = new ArrayList<String>();
  86.          
  87.          for (String ca : a) {
  88.              if (!ca.equals("integer")) {
  89.                  c.add(ca);
  90.              } else {
  91.                  break;
  92.              }
  93.          }
  94.        
  95.          HashMap<String, Integer> playersEdit = new HashMap<String, Integer>();
  96.          HashMap<String, Integer> playersKeep = new HashMap<String, Integer>();
  97.        
  98.          for (String player : configurationFile.getConfigurationSection(b.toString().replace("[", "").replace("]", "").replace(", ", ".")).getKeys(false)) {
  99.              playersEdit.put(player, configurationFile.getInt(c.toString().replace("[", "").replace("]", "").replace(", ", ".").replace("player", player)));
  100.              playersKeep.put(player, configurationFile.getInt(c.toString().replace("[", "").replace("]", "").replace(", ", ".").replace("player", player)));
  101.          }
  102.        
  103.          Map<Integer, String> leaderboard = sortByComparator(playersEdit, false);
  104.          
  105.          firstPlace.getBlock().setType(firstBlockType);
  106.          secondPlace.getBlock().setType(secondBlockType);
  107.          thirdPlace.getBlock().setType(thirdBlockType);
  108.          
  109.          ArrayList<BlockState> signBlockState = new ArrayList<BlockState>();
  110.          
  111.          Block firstSign = firstPlace.getBlock().getRelative(direction);
  112.          Block secondSign = secondPlace.getBlock().getRelative(direction);
  113.          Block thirdSign = thirdPlace.getBlock().getRelative(direction);
  114.          
  115.          switch (direction) {
  116.         case EAST:
  117.             firstSign.setTypeIdAndData(68, (byte) 0x5, true);
  118.             secondSign.setTypeIdAndData(68, (byte) 0x5, true);
  119.             thirdSign.setTypeIdAndData(68, (byte) 0x5, true);
  120.             break;
  121.         case NORTH:
  122.             firstSign.setTypeIdAndData(68, (byte) 0x2, true);
  123.             secondSign.setTypeIdAndData(68, (byte) 0x2, true);
  124.             thirdSign.setTypeIdAndData(68, (byte) 0x2, true);
  125.             break;
  126.         case SOUTH:
  127.             firstSign.setTypeIdAndData(68, (byte) 0x3, true);
  128.             secondSign.setTypeIdAndData(68, (byte) 0x3, true);
  129.             thirdSign.setTypeIdAndData(68, (byte) 0x3, true);
  130.             break;
  131.         case WEST:
  132.             firstSign.setTypeIdAndData(68, (byte) 0x4, true);
  133.             secondSign.setTypeIdAndData(68, (byte) 0x4, true);
  134.             thirdSign.setTypeIdAndData(68, (byte) 0x4, true);
  135.             break;
  136.         default:
  137.             break;
  138.          
  139.          }
  140.          
  141.          signBlockState.add(firstSign.getState());
  142.          signBlockState.add(secondSign.getState());
  143.          signBlockState.add(thirdSign.getState());
  144.        
  145.          for (BlockState bs : signBlockState) {
  146.              if (bs instanceof Sign) {
  147.                  Sign s = (Sign) bs;
  148.                  
  149.                  if (leaderboard.containsKey(signBlockState.indexOf(bs) + 1)) {
  150.                      if (convertUUID(leaderboard.get(signBlockState.indexOf(bs) + 1)) instanceof UUID) {
  151.                          s.setLine(1, Bukkit.getPlayer((UUID) convertUUID(leaderboard.get(signBlockState.indexOf(bs) + 1))).getName());
  152.                      } else {
  153.                          s.setLine(1, leaderboard.get(signBlockState.indexOf(bs) + 1));
  154.                      }
  155.                      
  156.                      switch (signBlockState.indexOf(bs) + 1) {
  157.                      case 1:
  158.                          s.setLine(0, ChatColor.AQUA + "" + ChatColor.BOLD + "1st");
  159.                          break;
  160.                      case 2:
  161.                          s.setLine(0, ChatColor.YELLOW + "" + ChatColor.BOLD + "2nd");
  162.                          break;
  163.                      case 3:
  164.                          s.setLine(0, ChatColor.DARK_RED + "" + ChatColor.BOLD + "3rd");
  165.                          break;
  166.                      }
  167.                  }
  168.                  s.setLine(2, playersKeep.get(leaderboard.get(signBlockState.indexOf(bs) + 1)) + " Points");
  169.                  bs.getBlock().getChunk().load();
  170.                  s.update(true);
  171.              }
  172.         }
  173.          
  174.          Location firstSkull = firstPlace.getBlock().getLocation().add(0, 1, 0);
  175.          Location secondSkull = secondPlace.getBlock().getLocation().add(0, 1, 0);
  176.          Location thirdSkull = thirdPlace.getBlock().getLocation().add(0, 1, 0);
  177.          
  178.          firstSkull.getBlock().setType(Material.SKULL);
  179.          secondSkull.getBlock().setType(Material.SKULL);
  180.          thirdSkull.getBlock().setType(Material.SKULL);
  181.          
  182.          ArrayList<BlockState> skullBlockState = new ArrayList<BlockState>();
  183.        
  184.          skullBlockState.add(firstSkull.getBlock().getState());
  185.          skullBlockState.add(secondSkull.getBlock().getState());
  186.          skullBlockState.add(thirdSkull.getBlock().getState());
  187.          
  188.          for (BlockState bs : skullBlockState) {
  189.              if (bs instanceof Skull) {
  190.                  Skull s = (Skull) bs;
  191.                  s.setSkullType(SkullType.PLAYER);
  192.                  s.setRawData((byte) 1);
  193.                  s.setRotation(direction);
  194.                  
  195.                  if (leaderboard.containsKey(skullBlockState.indexOf(bs) + 1)) {
  196.                      if (convertUUID(leaderboard.get(skullBlockState.indexOf(bs) + 1)) instanceof UUID) {
  197.                          s.setOwner(Bukkit.getPlayer((UUID) convertUUID(leaderboard.get(skullBlockState.indexOf(bs) + 1))).getName());
  198.                      } else {
  199.                          s.setOwner(leaderboard.get(skullBlockState.indexOf(bs) + 1));
  200.                      }
  201.                  }
  202.                  
  203.                  bs.getBlock().getChunk().load();
  204.                  s.update(true);
  205.              }
  206.          }
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement