Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 34.41 KB | None | 0 0
  1. package com.minecade.lobby;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Map.Entry;
  10. import java.util.Set;
  11. import java.util.concurrent.ConcurrentHashMap;
  12.  
  13. import net.minecraft.server.v1_7_R4.ChatBaseComponent;
  14. import net.minecraft.util.org.apache.commons.lang3.StringUtils;
  15.  
  16. import org.bukkit.Bukkit;
  17. import org.bukkit.ChatColor;
  18. import org.bukkit.Material;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.Inventory;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.inventory.meta.ItemMeta;
  23. import org.bukkit.scheduler.BukkitRunnable;
  24. import org.bukkit.scoreboard.DisplaySlot;
  25. import org.bukkit.scoreboard.Objective;
  26. import org.bukkit.scoreboard.Score;
  27. import org.bukkit.scoreboard.Scoreboard;
  28. import org.bukkit.scoreboard.Team;
  29. import org.bukkit.util.Vector;
  30.  
  31. import com.minecade.engine.persistence.AccountData;
  32. import com.minecade.engine.persistence.AccountData.Rank;
  33. import com.minecade.engine.utils.HologramWrapper;
  34. import com.minecade.engine.utils.IconMenu;
  35. import com.minecade.engine.utils.PacketUtils;
  36. import com.minecade.engine.utils.ScrollableText;
  37. import com.minecade.lobby.LobbyOptionsMenu.LobbyOptionItem;
  38. import com.minecade.lobby.holograms.Hologram;
  39. import com.minecade.lobby.store.Extras;
  40. import com.minecade.lobby.store.ExtrasItemMenu;
  41. import com.minecade.lobby.store.ItemForSale;
  42. import com.minecade.lobby.store.Pet;
  43. import com.minecade.lobby.store.PetMenu;
  44. import com.minecade.lobby.store.StatsMenu;
  45. import com.minecade.lobby.store.Trail;
  46. import com.minecade.lobby.store.TrailMenu;
  47. import com.minecade.lobby.tasks.ServerPingTask;
  48.  
  49. public class LobbyPlayer {
  50.  
  51.     public enum Visibility {
  52.         ALL, RANK, NONE;
  53.  
  54.         public Visibility next() {
  55.             return values()[(ordinal() + 1) % values().length];
  56.         }
  57.  
  58.         public String getFormmatedName() {
  59.             String formmatedName = LobbyPlugin.getInstance().getColoredMessage(String.format("visibility.%s", name().toLowerCase()));
  60.             if (!formmatedName.equalsIgnoreCase(String.format("visibility.%s", name().toLowerCase()))) {
  61.                 return formmatedName;
  62.             }
  63.             return name();
  64.         }
  65.     }
  66.  
  67.     private final Player player;
  68.     private final AccountData data;
  69.     private LobbyPlayerScoreboard scoreboard;
  70.     private Visibility othersVisibility = Visibility.ALL;
  71.     private Visibility chatVisibility = Visibility.ALL;
  72.     private boolean allowingPMs = true;
  73.     private String lastMessage;
  74.     private Pet pet;
  75.     private HashSet<Trail> trail = new HashSet<Trail>();
  76.     private Vector lastTrailVector;
  77.     private Set<Hologram> holograms = new HashSet<Hologram>();
  78.  
  79.     private Map<String, IconMenu> personalMenues = new ConcurrentHashMap<String, IconMenu>();
  80.     private int paintballs_left = -1, time_left = 0;
  81.  
  82.     public LobbyPlayer(Player player, AccountData data) {
  83.         super();
  84.         this.player = player;
  85.         this.data = data;
  86.  
  87.         // set default log level
  88.         String defaultOthersVisibility = LobbyPlugin.getInstance().getConfig().getString("lobby.default-others-visibility");
  89.         if (StringUtils.isNotBlank(defaultOthersVisibility)) {
  90.             othersVisibility = Visibility.valueOf(defaultOthersVisibility.toUpperCase());
  91.         }
  92.     }
  93.  
  94.     public int getPaintballsLeft() {
  95.         return paintballs_left;
  96.     }
  97.  
  98.     public int getTimeLeft() {
  99.         return time_left;
  100.     }
  101.  
  102.     public void setTimeLeft(int time) {
  103.         this.time_left = time;
  104.     }
  105.  
  106.     public void setPaintballsLeft(int left) {
  107.         this.paintballs_left = left;
  108.     }
  109.  
  110.     public String getLastMessage() {
  111.         return lastMessage;
  112.     }
  113.  
  114.     public void setLastMessage(String s) {
  115.         this.lastMessage = s;
  116.     }
  117.  
  118.     public Visibility getChatVisibility() {
  119.         return chatVisibility;
  120.     }
  121.  
  122.     public void setOthersVisibility(Visibility othersVisibility) {
  123.         this.othersVisibility = othersVisibility;
  124.     }
  125.  
  126.     public void setChatVisibility(Visibility chatVisibility) {
  127.         this.chatVisibility = chatVisibility;
  128.     }
  129.  
  130.     public AccountData getData() {
  131.         return data;
  132.     }
  133.  
  134.     public LobbyPlayerScoreboard getScoreboard() {
  135.         return scoreboard;
  136.     }
  137.  
  138.     public String getName() {
  139.         return player.getName();
  140.     }
  141.  
  142.     public Player getPlayer() {
  143.         return player;
  144.     }
  145.  
  146.     public Visibility getOthersVisibility() {
  147.         return othersVisibility;
  148.     }
  149.  
  150.     public boolean isAllowingPMs() {
  151.         return allowingPMs;
  152.     }
  153.  
  154.     public void setAllowingPMs(boolean allowPMs) {
  155.         this.allowingPMs = allowPMs;
  156.     }
  157.  
  158.     public boolean isAdmin() {
  159.         return data.hasRank(Rank.ADMIN);
  160.     }
  161.  
  162.     public boolean isGm() {
  163.         return data.hasRank(Rank.GM);
  164.     }
  165.  
  166.     public boolean isOwner() {
  167.         return data.hasRank(Rank.OWNER);
  168.     }
  169.  
  170.     public boolean isDev() {
  171.         return data.hasRank(Rank.DEV);
  172.     }
  173.  
  174.     public boolean isVip() {
  175.         return data.hasRank(Rank.VIP);
  176.     }
  177.  
  178.     public boolean isTitan() {
  179.         return data.hasRank(Rank.TITAN);
  180.     }
  181.  
  182.     public Rank getHighestRank() {
  183.         return data.getHighestRank();
  184.     }
  185.  
  186.     public void replaceRanks(List<Rank> newRanks) {
  187.         data.replaceRanks(newRanks);
  188.     }
  189.  
  190.     public Visibility toggleChatVisibility() {
  191.         this.chatVisibility = chatVisibility.next();
  192.         return this.chatVisibility;
  193.     }
  194.  
  195.     public Visibility toggleOthersVisibility() {
  196.         this.othersVisibility = othersVisibility.next();
  197.         return this.othersVisibility;
  198.     }
  199.  
  200.     public void setVisibilityFor(LobbyPlayer other) {
  201.         switch (other.getOthersVisibility()) {
  202.         case ALL:
  203.             if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
  204.                 String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
  205.                 if (null != newName) {
  206.                     PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
  207.                     PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutNamedEntitySpawnPacket(this.getPlayer(), newName));
  208.                 }
  209.             } else {
  210.                 other.getPlayer().showPlayer(player);
  211.             }
  212.             break;
  213.         case RANK:
  214.             AccountData otherData = other.getData();
  215.  
  216.             if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
  217.                 String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
  218.                 if (null != newName) {
  219.                     PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
  220.                     // PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutNamedEntitySpawnPacket(this.getPlayer(), newName));
  221.                 }
  222.             } else {
  223.                 if (data.getDisplayRank().isVisibleFor(otherData.getDisplayRank())) {
  224.                     other.getPlayer().showPlayer(player);
  225.                 } else {
  226.                     other.getPlayer().hidePlayer(player);
  227.                 }
  228.             }
  229.             break;
  230.         case NONE:
  231.             if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
  232.                 String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
  233.                 if (null != newName) {
  234.                     PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
  235.                 }
  236.             } else {
  237.                 other.getPlayer().hidePlayer(player);
  238.             }
  239.         }
  240.     }
  241.  
  242.     public String getDisplayName() {
  243.         return player.getDisplayName();
  244.     }
  245.  
  246.     public void onReset() {
  247.         long started = System.nanoTime();
  248.         if (null == scoreboard) {
  249.             scoreboard = new LobbyPlayerScoreboard();
  250.         }
  251.         scoreboard.updatePlayerTeam();
  252.         scoreboard.update();
  253.         long finished = System.nanoTime();
  254.         if (LobbyPlugin.getInstance().isDebugMode()) {
  255.             Bukkit.getLogger().info(String.format("LobbyPlayer.onReset() ran on [%s] nanoseconds for Player: [%s]", finished - started, getName()));
  256.         }
  257.     }
  258.    
  259.     public void removeHolograms(){
  260.         for (Hologram hologram : holograms){
  261.             hologram.destroy();
  262.         }
  263.         this.holograms = null;
  264.     }
  265.  
  266.     public void onQuit() {
  267.         if (null != scoreboard) {
  268.             scoreboard.destroy();
  269.         }
  270.         if (null != pet) {
  271.             pet.destroy();
  272.         }
  273.         this.removeHolograms();
  274.     }
  275.  
  276.     public void onInventoryClick(Inventory inventory, int slot) {
  277.         if (personalMenues.containsKey(inventory.getName())) {
  278.             personalMenues.get(inventory.getName()).onClick(this, slot);
  279.         }
  280.     }
  281.  
  282.     public void registerClickableIconMenu(IconMenu menu) {
  283.         personalMenues.put(menu.getTitle(), menu);
  284.     }
  285.  
  286.     public void updateScoreboard() {
  287.         if (null != scoreboard) {
  288.             scoreboard.update();
  289.         }
  290.     }
  291.    
  292.     public void addHologram(HologramWrapper hologram){
  293.         if(null != hologram){
  294.             this.holograms.add(hologram.getHologram());
  295.         }
  296.     }
  297.  
  298.     public void setPet(Pet pet) {
  299.         this.pet = pet;
  300.     }
  301.  
  302.     public Pet getPet() {
  303.         return this.pet;
  304.     }
  305.  
  306.     public HashSet<Trail> getTrails() {
  307.         return trail;
  308.     }
  309.  
  310.     public void addTrail(Trail trail) {
  311.         this.trail.add(trail);
  312.     }
  313.  
  314.     public void removeTrail(Trail trail) {
  315.         this.trail.remove(trail);
  316.     }
  317.  
  318.     public void clearTrails() {
  319.         this.trail = new HashSet<Trail>();
  320.     }
  321.  
  322.     public Vector getLastTrailVector() {
  323.         return lastTrailVector;
  324.     }
  325.  
  326.     public void setLastTrailVector(Vector lastTrailVector) {
  327.         this.lastTrailVector = lastTrailVector;
  328.     }
  329.  
  330.     public boolean ownsItem(ItemForSale item) {
  331.         return data.ownsItem(item);
  332.     }
  333.  
  334.     /*
  335.      * public void openLobbyOptionsMenu() { String title = LobbyPlugin.getInstance().getColoredMessage("lobby.options.title"); IconMenu lobbyOptionsMenu =
  336.      * personalMenues.get(title); if (null == lobbyOptionsMenu) { lobbyOptionsMenu = new LobbyOptionsMenu(title, 9, getName());
  337.      * personalMenues.put(lobbyOptionsMenu.getTitle(), lobbyOptionsMenu); } lobbyOptionsMenu.open(player); }
  338.      */
  339.  
  340.     Inventory lobbyOptions;
  341.  
  342.     public void openLobbyOptionsMenu() {
  343.         String title = LobbyPlugin.getInstance().getColoredMessage("lobby.options.title");
  344.         if (lobbyOptions == null) {
  345.             // Make the inventory and set the items.
  346.             lobbyOptions = Bukkit.createInventory(null, 54, title);
  347.             equipInv(lobbyOptions);
  348.             getPlayer().openInventory(lobbyOptions);
  349.         } else {
  350.             // Update their items so incase the server changes or whatever
  351.             equipInv(lobbyOptions);
  352.             updateItems();
  353.             getPlayer().openInventory(lobbyOptions);
  354.         }
  355.     }
  356.  
  357.     public void equipInv(Inventory e) {
  358.         e.setItem(21, othersVisibility.equals(Visibility.ALL) ? enchantItem(LobbyOptionItem.VISIBILITY_ALL.getIcon().clone()) : LobbyOptionItem.VISIBILITY_ALL.getIcon().clone());
  359.         e.setItem(22, othersVisibility.equals(Visibility.RANK) ? enchantItem(LobbyOptionItem.VISIBILITY_RANK.getIcon().clone()) : LobbyOptionItem.VISIBILITY_RANK.getIcon().clone());
  360.         e.setItem(23, othersVisibility.equals(Visibility.NONE) ? enchantItem(LobbyOptionItem.VISIBILITY_NONE.getIcon().clone()) : LobbyOptionItem.VISIBILITY_NONE.getIcon().clone());
  361.  
  362.         // Others
  363.         e.setItem(30, chatVisibility.equals(Visibility.ALL) ? enchantItem(LobbyOptionItem.CHAT_ALL.getIcon().clone()) : LobbyOptionItem.CHAT_ALL.getIcon().clone());
  364.         e.setItem(31, chatVisibility.equals(Visibility.RANK) ? enchantItem(LobbyOptionItem.CHAT_RANK.getIcon().clone()) : LobbyOptionItem.CHAT_RANK.getIcon().clone());
  365.         e.setItem(32, chatVisibility.equals(Visibility.NONE) ? enchantItem(LobbyOptionItem.CHAT_NONE.getIcon().clone()) : LobbyOptionItem.CHAT_NONE.getIcon().clone());
  366.  
  367.         // Lobby options
  368.         ItemStack is = LobbyOptionItem.MESSAGES_TOGGLE.getIcon();
  369.         if (isAllowingPMs()) {
  370.             is.setDurability((short) 5);
  371.         } else {
  372.             is.setDurability((short) 14);
  373.         }
  374.         e.setItem(40, is);
  375.         addBorder(e);
  376.         addSelector(e);
  377.     }
  378.     public ItemStack enchantItem(ItemStack is){
  379.         is.addUnsafeEnchantment(IconMenu.activeEnchant(), 1);
  380.         return is;
  381.     }
  382.     public void addBorder(Inventory inv) {
  383.         ItemStack is = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
  384.         ItemMeta im = is.getItemMeta();
  385.         im.setDisplayName(" ");
  386.         is.setItemMeta(im);
  387.         // Border
  388.         for (int i = 0; i < 8; i++) {
  389.             inv.setItem(i, is);
  390.         }
  391.         for (int i = 9; i < 45; i += 9) {
  392.             inv.setItem(i, is);
  393.         }
  394.         for (int i = 8; i < 53; i += 9) {
  395.             inv.setItem(i, is);
  396.         }
  397.         for (int i = 45; i < 54; i++) {
  398.             inv.setItem(i, is);
  399.         }
  400.     }
  401.  
  402.     public void updateItems() {
  403.         if (lobbyOptions == null)
  404.             return;
  405.         ItemStack is = LobbyOptionItem.MESSAGES_TOGGLE.getIcon();
  406.         if (isAllowingPMs()) {
  407.             is.setDurability((short) 5);
  408.         } else {
  409.             is.setDurability((short) 14);
  410.         }
  411.         lobbyOptions.setItem(40, is);
  412.         addSelector(lobbyOptions);
  413.     }
  414.  
  415.     public void addSelector(Inventory inv) {
  416.         int index = 12;
  417.         // Generate our lobby list.
  418.         int size = ServerPingTask.lobby_servers.size();
  419.         for (Entry<String, Integer> data : ServerPingTask.lobby_servers.entrySet()) {
  420.             String bungee_id = data.getKey();
  421.             int pcount = data.getValue();
  422.  
  423.             ChatColor cc = ChatColor.YELLOW;
  424.             ItemStack server_icon = new ItemStack(Material.STAINED_CLAY, 1, (short) 11);
  425.             if (bungee_id.contains("viplobby")) {
  426.                 server_icon = new ItemStack(Material.GOLD_BLOCK, 1);
  427.             }
  428.             if (bungee_id.equalsIgnoreCase(LobbyPlugin.getInstance().getBungeeId())) {
  429.                 // This is the player's local server, differentiate.
  430.                 server_icon.setDurability((short) 5);
  431.                 cc = ChatColor.GREEN;
  432.                 enchantItem(server_icon);
  433.             }
  434.  
  435.             ItemMeta im = server_icon.getItemMeta();
  436.             im.setDisplayName(cc + ChatColor.GOLD.toString() + "Lobby " + cc + bungee_id + ChatColor.GRAY + " (" + pcount + "/500)");
  437.             int amount = 1;
  438.             // Dont update this for vip lobby
  439.             if (bungee_id.contains("l") && !bungee_id.contains("vip")) {
  440.                 amount = Integer.parseInt(bungee_id.split("l")[1]);
  441.             }
  442.             server_icon.setAmount(amount);
  443.             if (server_icon.getType() != Material.GOLD_BLOCK) {
  444.  
  445.                 if (server_icon.getDurability() == 11) {
  446.                     // Foreign server.
  447.                     im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.connect"))));
  448.                 } else {
  449.                     // Local server.
  450.                     im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.local-server"))));
  451.                 }
  452.             } else {
  453.                 im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.connect"))));
  454.             }
  455.             server_icon.setItemMeta(im);
  456.             int add_index = size == 1 ? 1 : size == 2 ? 2 : 1;
  457.             if (size == 1) {
  458.                 // center it
  459.                 index = 13;
  460.             } else if (size == 2) {
  461.                 index = 12;
  462.             }
  463.  
  464.             inv.setItem(index, server_icon);
  465.             index += add_index;
  466.         }
  467.  
  468.     }
  469.  
  470.     public void openPetMenu() {
  471.         String title = LobbyPlugin.getInstance().getColoredMessage("pet.store.title");
  472.         IconMenu petMenu = personalMenues.get(title);
  473.         if (null == petMenu) {
  474.             petMenu = new PetMenu(title, 36 + 9, getName());
  475.             personalMenues.put(petMenu.getTitle(), petMenu);
  476.         }
  477.         petMenu.open(player);
  478.     }
  479.  
  480.     public void openTrailMenu() {
  481.         String title = LobbyPlugin.getInstance().getColoredMessage("trail.store.title");
  482.         IconMenu trailMenu = personalMenues.get(title);
  483.         if (null == trailMenu) {
  484.             trailMenu = new TrailMenu(title, 36, getName());
  485.             personalMenues.put(trailMenu.getTitle(), trailMenu);
  486.         }
  487.         trailMenu.open(player);
  488.     }
  489.  
  490.     public void updateMenues() {
  491.         for (IconMenu menu : personalMenues.values()) {
  492.             menu.update();
  493.         }
  494.     }
  495.  
  496.     public void updateScoreboardTeamFor(LobbyPlayer otherLPlayer) {
  497.         if (null != scoreboard) {
  498.             scoreboard.updateScoreboardTeamFor(otherLPlayer);
  499.         }
  500.     }
  501.  
  502.     @Override
  503.     public int hashCode() {
  504.         final int prime = 31;
  505.         int result = 1;
  506.         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
  507.         return result;
  508.     }
  509.  
  510.     @Override
  511.     public boolean equals(Object obj) {
  512.         if (this == obj)
  513.             return true;
  514.         if (obj == null)
  515.             return false;
  516.         if (getClass() != obj.getClass())
  517.             return false;
  518.         LobbyPlayer other = (LobbyPlayer) obj;
  519.         if (getName() == null) {
  520.             if (other.getName() != null)
  521.                 return false;
  522.         } else if (!getName().equals(other.getName()))
  523.             return false;
  524.         return true;
  525.     }
  526.  
  527.     class LobbyPlayerScoreboard {
  528.  
  529.         private Scoreboard board;
  530.         private Objective sidebar;
  531.  
  532.         private HashMap<Integer, String> scores = new HashMap<Integer, String>();
  533.         // private HashMap<Integer, ScrollableText> scrollables = new HashMap<Integer, ScrollableText>();
  534.         private ScrollableText displayName;
  535.         private ScrollableText buy_rank;
  536.  
  537.         public LobbyPlayerScoreboard() {
  538.             init();
  539.         }
  540.  
  541.         private void setScore(int slot, String text) {
  542.             if (StringUtils.isBlank(text)) {
  543.                 text = ChatColor.values()[slot].toString();
  544.             }
  545.  
  546.             // FIXME scrollable text will cause a fucking flickering
  547.             if (text.length() > 16) {
  548.                 // cut in the meanwhile
  549.                 text = ChatColor.stripColor(text).substring(0, 16);
  550.                 // ScrollableText scrollable = new ScrollableText(text);
  551.                 // scrollables.put(slot, scrollable);
  552.                 // text = scrollable.getVisibleText();
  553.             }
  554.  
  555.             String oldText = scores.put(slot, text);
  556.             if (null != oldText) {
  557.                 if (oldText.equals(text)) {
  558.                     return;
  559.                 }
  560.                 Score newScore = sidebar.getScore(text);
  561.                 // PacketUtils.sendPacketToClient(lPlayer.getPlayer(), PacketUtils.getPlayOutScoreboardScorePacket(oldText, null, 0, true));
  562.                 // PacketUtils.sendPacketToClient(lPlayer.getPlayer(), PacketUtils.getPlayOutScoreboardScorePacket(text, sidebar.getName(), slot, false));
  563.                 board.resetScores(oldText);
  564.                 newScore.setScore(slot);
  565.             } else {
  566.                 // PacketUtils.sendPacketToClient(player, PacketUtils.getPlayOutScoreboardScorePacket(text, sidebar.getName(), slot, false));
  567.                 Score newScore = sidebar.getScore(text);
  568.                 newScore.setScore(slot);
  569.             }
  570.         }
  571.  
  572.         private void removeScore(int slot) {
  573.             String oldText = scores.remove(slot);
  574.             if (null != oldText) {
  575.                 board.resetScores(oldText);
  576.             }
  577.         }
  578.  
  579.         @SuppressWarnings("deprecation")
  580.         private void init() {
  581.             board = Bukkit.getScoreboardManager().getNewScoreboard();
  582.             // try {
  583.             // board = LobbyPlugin.getInstance().getServer().getScheduler().callSyncMethod(LobbyPlugin.getInstance(), new Callable<Scoreboard>(){
  584.             // public Scoreboard call(){
  585.             // return LobbyPlugin.sb_manager.getNewScoreboard();
  586.             // }
  587.             // }).get();
  588.             // } catch (InterruptedException | ExecutionException e) {
  589.             // e.printStackTrace();
  590.             // }
  591.             //
  592.             for (Rank rank : Rank.values()) {
  593.                 if (board.getTeam(rank.getTranslatedName()) == null) {
  594.                     board.registerNewTeam(rank.getTranslatedName()).setPrefix(
  595.                             rank.getFormattedPrefix() + (rank.equals(Rank.BASIC) ? "" : String.format("%s %s", ChatColor.GRAY, ChatColor.RESET)));
  596.                 }
  597.             }
  598.  
  599.             board.getTeam(LobbyPlayer.this.getData().getDisplayRank().getTranslatedName()).addPlayer(LobbyPlayer.this.getPlayer());
  600.             sidebar = board.registerNewObjective("sidebar", "dummy");
  601.             String playerName = null;
  602.             if (LobbyPlayer.this.getName().length() > 14) {
  603.                 playerName = LobbyPlayer.this.getName();
  604.             } else {
  605.                 playerName = ChatColor.BOLD + LobbyPlayer.this.getName();
  606.             }
  607.             playerName = StringUtils.center(playerName, 16);
  608.             if (LobbyPlugin.getInstance().isOlimpoNetwork()) {
  609.                 this.setScore(15, StringUtils.EMPTY);
  610.                 this.setScore(14, playerName);
  611.  
  612.                 this.setScore(13, StringUtils.EMPTY);
  613.                 this.setScore(12, ChatColor.GOLD + "══════════");
  614.                 // this.setScore(15, "");
  615.                 this.setScore(11, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
  616.                 // this.setScore(10, String.valueOf(LobbyPlayer.this.getData().getCoins()));
  617.                 this.setScore(9, StringUtils.EMPTY);
  618.                 this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
  619.                 // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
  620.                 // this.setScore(7, lPlayer.getData().getHighestRank().getFormattedPrefix());
  621.                 this.setScore(4, StringUtils.EMPTY);
  622.                 this.setScore(3, LobbyPlugin.getInstance().getColoredMessage("lobby.name.title"));
  623.                 this.setScore(2,
  624.                         String.format("%s%sLobby %s", ChatColor.GOLD, ChatColor.BOLD, LobbyPlugin.getInstance().getConfig().getString("lobby.id", "-1")));
  625.                 // this.setScore(4, (null != Bukkit.getPlayer("SkyTheKidRS"))?"YES":"NO");
  626.                 this.setScore(1, ChatColor.GOLD + "──────────");
  627.                 displayName = new ScrollableText(LobbyPlugin.getInstance().getColoredMessage("score.announce"), 16);
  628.             } else if (LobbyPlugin.getInstance().isSkyNetwork()) {
  629.                 // Sky network stuff
  630.                 String name = ChatColor.GRAY.toString() + ChatColor.BOLD + getName();
  631.                 if (name.length() > 16) {
  632.                     name = name.substring(0, 16);
  633.                 }
  634.                 // this.setScore(15, "---------------");
  635.                 this.setScore(14, "----------------");
  636.                 // Empty space.
  637.                 this.setScore(13, ChatColor.GOLD.toString());
  638.                 this.setScore(12, ChatColor.GOLD + ChatColor.BOLD.toString() + "Butter Coins");
  639.                 // this.setScore(11, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
  640.                 // this.setScore(10, String.valueOf(lPlayer.getData().getCoins()));
  641.                 this.setScore(10, "");
  642.                 this.setScore(9, ChatColor.GOLD.toString() + ChatColor.BOLD + "Rank");
  643.                 // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
  644.                 this.setScore(8, StringUtils.isBlank(getData().getHighestRank().getFormattedPrefix()) ? ChatColor.RED.toString() + ChatColor.BOLD + "NONE"
  645.                         : getData().getHighestRank().getFormattedPrefix());
  646.                 // Empty space
  647.                 this.setScore(7, ChatColor.RED.toString());
  648.                 setScore(6, ChatColor.GOLD + ChatColor.BOLD.toString() + "Is Sky On?");
  649.                 // If hes online at the time then set yes.
  650.                 this.setScore(5,
  651.                         (null != Bukkit.getPlayerExact("SkyTheKidRS")) ? ChatColor.GREEN.toString() + ChatColor.BOLD + "YES" : ChatColor.RED.toString()
  652.                                 + ChatColor.BOLD + "NO");
  653.                 setScore(4, ChatColor.YELLOW.toString());
  654.                 setScore(3, ChatColor.GOLD.toString() + ChatColor.BOLD + "Website");
  655.                 setScore(2, ChatColor.WHITE + "TheBudder.com");
  656.                 setScore(1, ChatColor.BLUE.toString());
  657.                 setScore(0, ChatColor.GOLD + ChatColor.BOLD.toString() + "Lobby: " + ChatColor.WHITE
  658.                         + (LobbyPlugin.getInstance().getBungeeId().equalsIgnoreCase("") ? "<3" : LobbyPlugin.getInstance().getBungeeId()));
  659.                 displayName = new ScrollableText(ChatColor.WHITE + ChatColor.BOLD.toString() + "Welcome " + ChatColor.AQUA + ChatColor.BOLD + getName()
  660.                         + ChatColor.WHITE.toString() + ChatColor.BOLD + " to the " + ChatColor.AQUA.toString() + ChatColor.BOLD + "SkyDoesMinecraft Network!",
  661.                         20);
  662.             } else {
  663.                 // Minecade
  664.                 this.setScore(15, "----------------");
  665.                 this.setScore(14, playerName);
  666.                 // this.setScore(13, "");
  667.                 this.setScore(13, " ");
  668.                 // this.setScore(15, "");
  669.                 this.setScore(12, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
  670.                 // this.setScore(10, String.valueOf(lPlayer.getData().getCoins()));
  671.                 this.setScore(10, "  ");
  672.                 this.setScore(9, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
  673.                 // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
  674.                 // this.setScore(7, lPlayer.getData().getHighestRank().getFormattedPrefix());
  675.                 if (StringUtils.isBlank(LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix())) {
  676.                     buy_rank = new ScrollableText(ChatColor.WHITE + "Purchase a rank at " + ChatColor.AQUA + "minecade.com", 16);
  677.                 } else {
  678.                     setScore(8, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
  679.                 }
  680.                 this.setScore(7, "   ");
  681.                 this.setScore(6, ChatColor.AQUA.toString() + ChatColor.BOLD + "Website");
  682.                 this.setScore(5, "minecade.com");
  683.                 // this.setScore(4, (null != Bukkit.getPlayer("SkyTheKidRS"))?"YES":"NO");
  684.                 // this.setScore(1, "────────────");
  685.                 this.setScore(4, "     ");
  686.                 String lobbyInfo = ChatColor.AQUA + ChatColor.BOLD.toString() + "Lobby: " + ChatColor.WHITE
  687.                         + (LobbyPlugin.getInstance().getBungeeId().equalsIgnoreCase("") ? "<3" : LobbyPlugin.getInstance().getBungeeId());
  688.                 if (lobbyInfo.length() <= 16) {
  689.                     this.setScore(0, lobbyInfo);
  690.                 } else {
  691.                     this.setScore(0, lobbyInfo.substring(0, 16));
  692.                 }
  693.                 displayName = new ScrollableText(ChatColor.WHITE + ChatColor.BOLD.toString() + "Welcome " + ChatColor.AQUA + ChatColor.BOLD + getName()
  694.                         + ChatColor.WHITE.toString() + ChatColor.BOLD + " to the " + ChatColor.AQUA.toString() + ChatColor.BOLD + "Minecade Network!", 16);
  695.             }
  696.  
  697.             updateDynamicScores();
  698.             sidebar.setDisplayName(displayName.getVisibleText());
  699.             sidebar.setDisplaySlot(DisplaySlot.SIDEBAR);
  700.             if (LobbyPlayer.this.getPlayer().isOnline()) {
  701.                 LobbyPlayer.this.getPlayer().setScoreboard(board);
  702.             } else {
  703.                 destroy();
  704.             }
  705.         }
  706.  
  707.         public void update() {
  708.             if (null != displayName) {
  709.                 displayName.scrollText();
  710.                 sidebar.setDisplayName(displayName.getVisibleText());
  711.             }
  712.             if (buy_rank != null) {
  713.                 buy_rank.scrollText();
  714.                 removeScore(8);
  715.                 setScore(8, buy_rank.getVisibleText());
  716.             }
  717.             updateDynamicScores();
  718.         }
  719.  
  720.         private void updateDynamicScores() {
  721.             if (LobbyPlugin.getInstance().isOlimpoNetwork()) {
  722.                 this.setScore(10, String.format("%s%s%s", ChatColor.GOLD, ChatColor.BOLD, String.valueOf(LobbyPlayer.this.getData().getCoins())));
  723.             } else if (LobbyPlugin.getInstance().isSkyNetwork()) {
  724.                 this.setScore(11, String.valueOf(LobbyPlayer.this.getData().getCoins()));
  725.                 if (Bukkit.getPlayerExact("SkyTheKidRS") != null) {
  726.                     // Hes online
  727.                     removeScore(5);
  728.                     setScore(5, ChatColor.GREEN.toString() + ChatColor.BOLD + "YES");
  729.                 } else {
  730.                     removeScore(5);
  731.                     setScore(5, ChatColor.RED.toString() + ChatColor.BOLD + "NO");
  732.                 }
  733.                 return;
  734.             } else {
  735.                 this.setScore(11, ChatColor.BOLD + String.valueOf(LobbyPlayer.this.getData().getCoins()));
  736.             }
  737.  
  738.             if (!StringUtils.isBlank(LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix())) {
  739.                 if (!LobbyPlugin.getInstance().isMinecadeNetwork()) {
  740.                     this.setScore(7, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
  741.                     this.removeScore(6);
  742.                     this.removeScore(5);
  743.                 } else {
  744.                     this.setScore(8, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
  745.                 }
  746.             } else {
  747.                 if (!LobbyPlugin.getInstance().isMinecadeNetwork()) {
  748.                     this.setScore(7, LobbyPlugin.getInstance().getMessage("purchase.rank.1"));
  749.                     this.setScore(6, LobbyPlugin.getInstance().getMessage("purchase.rank.2"));
  750.                     this.setScore(5, LobbyPlugin.getInstance().getMessage("purchase.rank.3"));
  751.                 }
  752.             }
  753.         }
  754.  
  755.         private void destroy() {
  756.             if (LobbyPlayer.this.getPlayer().isOnline()) {
  757.                 LobbyPlayer.this.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
  758.             }
  759.             for (String player : board.getEntries()) {
  760.                 board.resetScores(player);
  761.             }
  762.             for (Team team : board.getTeams()) {
  763.                 team.unregister();
  764.             }
  765.             sidebar.unregister();
  766.         }
  767.  
  768.         private void updatePlayerTeam() {
  769.             // long currentTime = 0;
  770.             // if (LobbyPlugin.getInstance().isDebugMode()) {
  771.             // for (Team team : board.getTeams()) {
  772.             // Bukkit.getLogger().info(
  773.             // String.format("Player: [%s] - Team: [%s] - Size: [%s]", getName(), team.getName(),
  774.             // team.getSize()));
  775.             // }
  776.             // currentTime = System.currentTimeMillis();
  777.             // }
  778.             board.getTeam(LobbyPlayer.this.getData().getDisplayRank().getTranslatedName()).addPlayer(LobbyPlayer.this.getPlayer());
  779.             // if (LobbyPlugin.getInstance().isDebugMode()) {
  780.             // Bukkit.getLogger().info(
  781.             // String.format("LobbyPlayerScoreboard.updatePlayerTeam took [%s] milliseconds",
  782.             // System.currentTimeMillis() - currentTime));
  783.             // }
  784.         }
  785.  
  786.         public void updateScoreboardTeamFor(LobbyPlayer otherLPlayer) {
  787.             // long currentTime = 0;
  788.             // if (LobbyPlugin.getInstance().isDebugMode()) {
  789.             // for (Team team : board.getTeams()) {
  790.             // Bukkit.getLogger().info(
  791.             // String.format("Player: [%s] - Team: [%s] - Size: [%s]", getName(), team.getName(),
  792.             // team.getSize()));
  793.             // }
  794.             // currentTime = System.currentTimeMillis();
  795.             // }
  796.             Team otherPlayerTeam = board.getTeam(otherLPlayer.getData().getDisplayRank().getTranslatedName());
  797.             if (null == otherPlayerTeam) {
  798.                 otherPlayerTeam = board.registerNewTeam(otherLPlayer.getData().getDisplayRank().getTranslatedName());
  799.                 otherPlayerTeam.setPrefix(otherLPlayer.getData().getDisplayRank().getFormattedPrefix()
  800.                         + String.format("%s %s", ChatColor.GRAY, ChatColor.RESET));
  801.             }
  802.             otherPlayerTeam.addPlayer(otherLPlayer.getPlayer());
  803.             // if (LobbyPlugin.getInstance().isDebugMode()) {
  804.             // Bukkit.getLogger().info(
  805.             // String.format("LobbyPlayerScoreboard.updateScoreboardTeamFor took [%s] milliseconds",
  806.             // System.currentTimeMillis() - currentTime));
  807.             // }
  808.         }
  809.  
  810.     }
  811.  
  812.     public Inventory stats_menu;
  813.     public Inventory extras_menu;
  814.  
  815.     public void openStatsMenu() {
  816.         if (stats_menu == null) {
  817.             stats_menu = new StatsMenu().getInventory(getPlayer());
  818.         }
  819.         new BukkitRunnable() {
  820.  
  821.             public void run() {
  822.                 getPlayer().openInventory(stats_menu);
  823.             }
  824.         }.runTaskLater(LobbyPlugin.getInstance(), 3);
  825.     }
  826.  
  827.     public Inventory getStatsMenu() {
  828.         return stats_menu;
  829.     }
  830.  
  831.     public void setStatsMenu(Inventory inv) {
  832.         this.stats_menu = inv;
  833.     }
  834.  
  835.     public void openExtrasMenu() {
  836.         if (extras_menu == null) {
  837.             extras_menu = new ExtrasItemMenu().getInventory(getPlayer());
  838.         }
  839.         getPlayer().openInventory(extras_menu);
  840.     }
  841.  
  842.     public void reloadExtrasMenu() {
  843.         for (Extras e : getData().enabledExtras()) {
  844.             // Moves them to the front of their inventorys so theres no gap
  845.             getPlayer().getInventory().remove(e.getDisplay());
  846.             getPlayer().getInventory().addItem(e.getDisplay());
  847.         }
  848.  
  849.     }
  850.  
  851. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement