Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.minecade.lobby;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Set;
- import java.util.concurrent.ConcurrentHashMap;
- import net.minecraft.server.v1_7_R4.ChatBaseComponent;
- import net.minecraft.util.org.apache.commons.lang3.StringUtils;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Objective;
- import org.bukkit.scoreboard.Score;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.Team;
- import org.bukkit.util.Vector;
- import com.minecade.engine.persistence.AccountData;
- import com.minecade.engine.persistence.AccountData.Rank;
- import com.minecade.engine.utils.HologramWrapper;
- import com.minecade.engine.utils.IconMenu;
- import com.minecade.engine.utils.PacketUtils;
- import com.minecade.engine.utils.ScrollableText;
- import com.minecade.lobby.LobbyOptionsMenu.LobbyOptionItem;
- import com.minecade.lobby.holograms.Hologram;
- import com.minecade.lobby.store.Extras;
- import com.minecade.lobby.store.ExtrasItemMenu;
- import com.minecade.lobby.store.ItemForSale;
- import com.minecade.lobby.store.Pet;
- import com.minecade.lobby.store.PetMenu;
- import com.minecade.lobby.store.StatsMenu;
- import com.minecade.lobby.store.Trail;
- import com.minecade.lobby.store.TrailMenu;
- import com.minecade.lobby.tasks.ServerPingTask;
- public class LobbyPlayer {
- public enum Visibility {
- ALL, RANK, NONE;
- public Visibility next() {
- return values()[(ordinal() + 1) % values().length];
- }
- public String getFormmatedName() {
- String formmatedName = LobbyPlugin.getInstance().getColoredMessage(String.format("visibility.%s", name().toLowerCase()));
- if (!formmatedName.equalsIgnoreCase(String.format("visibility.%s", name().toLowerCase()))) {
- return formmatedName;
- }
- return name();
- }
- }
- private final Player player;
- private final AccountData data;
- private LobbyPlayerScoreboard scoreboard;
- private Visibility othersVisibility = Visibility.ALL;
- private Visibility chatVisibility = Visibility.ALL;
- private boolean allowingPMs = true;
- private String lastMessage;
- private Pet pet;
- private HashSet<Trail> trail = new HashSet<Trail>();
- private Vector lastTrailVector;
- private Set<Hologram> holograms = new HashSet<Hologram>();
- private Map<String, IconMenu> personalMenues = new ConcurrentHashMap<String, IconMenu>();
- private int paintballs_left = -1, time_left = 0;
- public LobbyPlayer(Player player, AccountData data) {
- super();
- this.player = player;
- this.data = data;
- // set default log level
- String defaultOthersVisibility = LobbyPlugin.getInstance().getConfig().getString("lobby.default-others-visibility");
- if (StringUtils.isNotBlank(defaultOthersVisibility)) {
- othersVisibility = Visibility.valueOf(defaultOthersVisibility.toUpperCase());
- }
- }
- public int getPaintballsLeft() {
- return paintballs_left;
- }
- public int getTimeLeft() {
- return time_left;
- }
- public void setTimeLeft(int time) {
- this.time_left = time;
- }
- public void setPaintballsLeft(int left) {
- this.paintballs_left = left;
- }
- public String getLastMessage() {
- return lastMessage;
- }
- public void setLastMessage(String s) {
- this.lastMessage = s;
- }
- public Visibility getChatVisibility() {
- return chatVisibility;
- }
- public void setOthersVisibility(Visibility othersVisibility) {
- this.othersVisibility = othersVisibility;
- }
- public void setChatVisibility(Visibility chatVisibility) {
- this.chatVisibility = chatVisibility;
- }
- public AccountData getData() {
- return data;
- }
- public LobbyPlayerScoreboard getScoreboard() {
- return scoreboard;
- }
- public String getName() {
- return player.getName();
- }
- public Player getPlayer() {
- return player;
- }
- public Visibility getOthersVisibility() {
- return othersVisibility;
- }
- public boolean isAllowingPMs() {
- return allowingPMs;
- }
- public void setAllowingPMs(boolean allowPMs) {
- this.allowingPMs = allowPMs;
- }
- public boolean isAdmin() {
- return data.hasRank(Rank.ADMIN);
- }
- public boolean isGm() {
- return data.hasRank(Rank.GM);
- }
- public boolean isOwner() {
- return data.hasRank(Rank.OWNER);
- }
- public boolean isDev() {
- return data.hasRank(Rank.DEV);
- }
- public boolean isVip() {
- return data.hasRank(Rank.VIP);
- }
- public boolean isTitan() {
- return data.hasRank(Rank.TITAN);
- }
- public Rank getHighestRank() {
- return data.getHighestRank();
- }
- public void replaceRanks(List<Rank> newRanks) {
- data.replaceRanks(newRanks);
- }
- public Visibility toggleChatVisibility() {
- this.chatVisibility = chatVisibility.next();
- return this.chatVisibility;
- }
- public Visibility toggleOthersVisibility() {
- this.othersVisibility = othersVisibility.next();
- return this.othersVisibility;
- }
- public void setVisibilityFor(LobbyPlayer other) {
- switch (other.getOthersVisibility()) {
- case ALL:
- if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
- String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
- if (null != newName) {
- PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
- PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutNamedEntitySpawnPacket(this.getPlayer(), newName));
- }
- } else {
- other.getPlayer().showPlayer(player);
- }
- break;
- case RANK:
- AccountData otherData = other.getData();
- if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
- String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
- if (null != newName) {
- PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
- // PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutNamedEntitySpawnPacket(this.getPlayer(), newName));
- }
- } else {
- if (data.getDisplayRank().isVisibleFor(otherData.getDisplayRank())) {
- other.getPlayer().showPlayer(player);
- } else {
- other.getPlayer().hidePlayer(player);
- }
- }
- break;
- case NONE:
- if (LobbyPlugin.getInstance().getWorld().isPlayerWithNameChanged(this.getPlayer().getName())) {
- String newName = LobbyPlugin.getInstance().getWorld().getNewPlayerUsername(this.getPlayer().getName());
- if (null != newName) {
- PacketUtils.sendPacketToClient(other.getPlayer(), PacketUtils.getPacketPlayOutEntityDestroyPacket(this.getPlayer()));
- }
- } else {
- other.getPlayer().hidePlayer(player);
- }
- }
- }
- public String getDisplayName() {
- return player.getDisplayName();
- }
- public void onReset() {
- long started = System.nanoTime();
- if (null == scoreboard) {
- scoreboard = new LobbyPlayerScoreboard();
- }
- scoreboard.updatePlayerTeam();
- scoreboard.update();
- long finished = System.nanoTime();
- if (LobbyPlugin.getInstance().isDebugMode()) {
- Bukkit.getLogger().info(String.format("LobbyPlayer.onReset() ran on [%s] nanoseconds for Player: [%s]", finished - started, getName()));
- }
- }
- public void removeHolograms(){
- for (Hologram hologram : holograms){
- hologram.destroy();
- }
- this.holograms = null;
- }
- public void onQuit() {
- if (null != scoreboard) {
- scoreboard.destroy();
- }
- if (null != pet) {
- pet.destroy();
- }
- this.removeHolograms();
- }
- public void onInventoryClick(Inventory inventory, int slot) {
- if (personalMenues.containsKey(inventory.getName())) {
- personalMenues.get(inventory.getName()).onClick(this, slot);
- }
- }
- public void registerClickableIconMenu(IconMenu menu) {
- personalMenues.put(menu.getTitle(), menu);
- }
- public void updateScoreboard() {
- if (null != scoreboard) {
- scoreboard.update();
- }
- }
- public void addHologram(HologramWrapper hologram){
- if(null != hologram){
- this.holograms.add(hologram.getHologram());
- }
- }
- public void setPet(Pet pet) {
- this.pet = pet;
- }
- public Pet getPet() {
- return this.pet;
- }
- public HashSet<Trail> getTrails() {
- return trail;
- }
- public void addTrail(Trail trail) {
- this.trail.add(trail);
- }
- public void removeTrail(Trail trail) {
- this.trail.remove(trail);
- }
- public void clearTrails() {
- this.trail = new HashSet<Trail>();
- }
- public Vector getLastTrailVector() {
- return lastTrailVector;
- }
- public void setLastTrailVector(Vector lastTrailVector) {
- this.lastTrailVector = lastTrailVector;
- }
- public boolean ownsItem(ItemForSale item) {
- return data.ownsItem(item);
- }
- /*
- * public void openLobbyOptionsMenu() { String title = LobbyPlugin.getInstance().getColoredMessage("lobby.options.title"); IconMenu lobbyOptionsMenu =
- * personalMenues.get(title); if (null == lobbyOptionsMenu) { lobbyOptionsMenu = new LobbyOptionsMenu(title, 9, getName());
- * personalMenues.put(lobbyOptionsMenu.getTitle(), lobbyOptionsMenu); } lobbyOptionsMenu.open(player); }
- */
- Inventory lobbyOptions;
- public void openLobbyOptionsMenu() {
- String title = LobbyPlugin.getInstance().getColoredMessage("lobby.options.title");
- if (lobbyOptions == null) {
- // Make the inventory and set the items.
- lobbyOptions = Bukkit.createInventory(null, 54, title);
- equipInv(lobbyOptions);
- getPlayer().openInventory(lobbyOptions);
- } else {
- // Update their items so incase the server changes or whatever
- equipInv(lobbyOptions);
- updateItems();
- getPlayer().openInventory(lobbyOptions);
- }
- }
- public void equipInv(Inventory e) {
- e.setItem(21, othersVisibility.equals(Visibility.ALL) ? enchantItem(LobbyOptionItem.VISIBILITY_ALL.getIcon().clone()) : LobbyOptionItem.VISIBILITY_ALL.getIcon().clone());
- e.setItem(22, othersVisibility.equals(Visibility.RANK) ? enchantItem(LobbyOptionItem.VISIBILITY_RANK.getIcon().clone()) : LobbyOptionItem.VISIBILITY_RANK.getIcon().clone());
- e.setItem(23, othersVisibility.equals(Visibility.NONE) ? enchantItem(LobbyOptionItem.VISIBILITY_NONE.getIcon().clone()) : LobbyOptionItem.VISIBILITY_NONE.getIcon().clone());
- // Others
- e.setItem(30, chatVisibility.equals(Visibility.ALL) ? enchantItem(LobbyOptionItem.CHAT_ALL.getIcon().clone()) : LobbyOptionItem.CHAT_ALL.getIcon().clone());
- e.setItem(31, chatVisibility.equals(Visibility.RANK) ? enchantItem(LobbyOptionItem.CHAT_RANK.getIcon().clone()) : LobbyOptionItem.CHAT_RANK.getIcon().clone());
- e.setItem(32, chatVisibility.equals(Visibility.NONE) ? enchantItem(LobbyOptionItem.CHAT_NONE.getIcon().clone()) : LobbyOptionItem.CHAT_NONE.getIcon().clone());
- // Lobby options
- ItemStack is = LobbyOptionItem.MESSAGES_TOGGLE.getIcon();
- if (isAllowingPMs()) {
- is.setDurability((short) 5);
- } else {
- is.setDurability((short) 14);
- }
- e.setItem(40, is);
- addBorder(e);
- addSelector(e);
- }
- public ItemStack enchantItem(ItemStack is){
- is.addUnsafeEnchantment(IconMenu.activeEnchant(), 1);
- return is;
- }
- public void addBorder(Inventory inv) {
- ItemStack is = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
- ItemMeta im = is.getItemMeta();
- im.setDisplayName(" ");
- is.setItemMeta(im);
- // Border
- for (int i = 0; i < 8; i++) {
- inv.setItem(i, is);
- }
- for (int i = 9; i < 45; i += 9) {
- inv.setItem(i, is);
- }
- for (int i = 8; i < 53; i += 9) {
- inv.setItem(i, is);
- }
- for (int i = 45; i < 54; i++) {
- inv.setItem(i, is);
- }
- }
- public void updateItems() {
- if (lobbyOptions == null)
- return;
- ItemStack is = LobbyOptionItem.MESSAGES_TOGGLE.getIcon();
- if (isAllowingPMs()) {
- is.setDurability((short) 5);
- } else {
- is.setDurability((short) 14);
- }
- lobbyOptions.setItem(40, is);
- addSelector(lobbyOptions);
- }
- public void addSelector(Inventory inv) {
- int index = 12;
- // Generate our lobby list.
- int size = ServerPingTask.lobby_servers.size();
- for (Entry<String, Integer> data : ServerPingTask.lobby_servers.entrySet()) {
- String bungee_id = data.getKey();
- int pcount = data.getValue();
- ChatColor cc = ChatColor.YELLOW;
- ItemStack server_icon = new ItemStack(Material.STAINED_CLAY, 1, (short) 11);
- if (bungee_id.contains("viplobby")) {
- server_icon = new ItemStack(Material.GOLD_BLOCK, 1);
- }
- if (bungee_id.equalsIgnoreCase(LobbyPlugin.getInstance().getBungeeId())) {
- // This is the player's local server, differentiate.
- server_icon.setDurability((short) 5);
- cc = ChatColor.GREEN;
- enchantItem(server_icon);
- }
- ItemMeta im = server_icon.getItemMeta();
- im.setDisplayName(cc + ChatColor.GOLD.toString() + "Lobby " + cc + bungee_id + ChatColor.GRAY + " (" + pcount + "/500)");
- int amount = 1;
- // Dont update this for vip lobby
- if (bungee_id.contains("l") && !bungee_id.contains("vip")) {
- amount = Integer.parseInt(bungee_id.split("l")[1]);
- }
- server_icon.setAmount(amount);
- if (server_icon.getType() != Material.GOLD_BLOCK) {
- if (server_icon.getDurability() == 11) {
- // Foreign server.
- im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.connect"))));
- } else {
- // Local server.
- im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.local-server"))));
- }
- } else {
- im.setLore(new ArrayList<String>(Arrays.asList(LobbyPlugin.getInstance().getColoredMessage("options.selector.connect"))));
- }
- server_icon.setItemMeta(im);
- int add_index = size == 1 ? 1 : size == 2 ? 2 : 1;
- if (size == 1) {
- // center it
- index = 13;
- } else if (size == 2) {
- index = 12;
- }
- inv.setItem(index, server_icon);
- index += add_index;
- }
- }
- public void openPetMenu() {
- String title = LobbyPlugin.getInstance().getColoredMessage("pet.store.title");
- IconMenu petMenu = personalMenues.get(title);
- if (null == petMenu) {
- petMenu = new PetMenu(title, 36 + 9, getName());
- personalMenues.put(petMenu.getTitle(), petMenu);
- }
- petMenu.open(player);
- }
- public void openTrailMenu() {
- String title = LobbyPlugin.getInstance().getColoredMessage("trail.store.title");
- IconMenu trailMenu = personalMenues.get(title);
- if (null == trailMenu) {
- trailMenu = new TrailMenu(title, 36, getName());
- personalMenues.put(trailMenu.getTitle(), trailMenu);
- }
- trailMenu.open(player);
- }
- public void updateMenues() {
- for (IconMenu menu : personalMenues.values()) {
- menu.update();
- }
- }
- public void updateScoreboardTeamFor(LobbyPlayer otherLPlayer) {
- if (null != scoreboard) {
- scoreboard.updateScoreboardTeamFor(otherLPlayer);
- }
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- LobbyPlayer other = (LobbyPlayer) obj;
- if (getName() == null) {
- if (other.getName() != null)
- return false;
- } else if (!getName().equals(other.getName()))
- return false;
- return true;
- }
- class LobbyPlayerScoreboard {
- private Scoreboard board;
- private Objective sidebar;
- private HashMap<Integer, String> scores = new HashMap<Integer, String>();
- // private HashMap<Integer, ScrollableText> scrollables = new HashMap<Integer, ScrollableText>();
- private ScrollableText displayName;
- private ScrollableText buy_rank;
- public LobbyPlayerScoreboard() {
- init();
- }
- private void setScore(int slot, String text) {
- if (StringUtils.isBlank(text)) {
- text = ChatColor.values()[slot].toString();
- }
- // FIXME scrollable text will cause a fucking flickering
- if (text.length() > 16) {
- // cut in the meanwhile
- text = ChatColor.stripColor(text).substring(0, 16);
- // ScrollableText scrollable = new ScrollableText(text);
- // scrollables.put(slot, scrollable);
- // text = scrollable.getVisibleText();
- }
- String oldText = scores.put(slot, text);
- if (null != oldText) {
- if (oldText.equals(text)) {
- return;
- }
- Score newScore = sidebar.getScore(text);
- // PacketUtils.sendPacketToClient(lPlayer.getPlayer(), PacketUtils.getPlayOutScoreboardScorePacket(oldText, null, 0, true));
- // PacketUtils.sendPacketToClient(lPlayer.getPlayer(), PacketUtils.getPlayOutScoreboardScorePacket(text, sidebar.getName(), slot, false));
- board.resetScores(oldText);
- newScore.setScore(slot);
- } else {
- // PacketUtils.sendPacketToClient(player, PacketUtils.getPlayOutScoreboardScorePacket(text, sidebar.getName(), slot, false));
- Score newScore = sidebar.getScore(text);
- newScore.setScore(slot);
- }
- }
- private void removeScore(int slot) {
- String oldText = scores.remove(slot);
- if (null != oldText) {
- board.resetScores(oldText);
- }
- }
- @SuppressWarnings("deprecation")
- private void init() {
- board = Bukkit.getScoreboardManager().getNewScoreboard();
- // try {
- // board = LobbyPlugin.getInstance().getServer().getScheduler().callSyncMethod(LobbyPlugin.getInstance(), new Callable<Scoreboard>(){
- // public Scoreboard call(){
- // return LobbyPlugin.sb_manager.getNewScoreboard();
- // }
- // }).get();
- // } catch (InterruptedException | ExecutionException e) {
- // e.printStackTrace();
- // }
- //
- for (Rank rank : Rank.values()) {
- if (board.getTeam(rank.getTranslatedName()) == null) {
- board.registerNewTeam(rank.getTranslatedName()).setPrefix(
- rank.getFormattedPrefix() + (rank.equals(Rank.BASIC) ? "" : String.format("%s %s", ChatColor.GRAY, ChatColor.RESET)));
- }
- }
- board.getTeam(LobbyPlayer.this.getData().getDisplayRank().getTranslatedName()).addPlayer(LobbyPlayer.this.getPlayer());
- sidebar = board.registerNewObjective("sidebar", "dummy");
- String playerName = null;
- if (LobbyPlayer.this.getName().length() > 14) {
- playerName = LobbyPlayer.this.getName();
- } else {
- playerName = ChatColor.BOLD + LobbyPlayer.this.getName();
- }
- playerName = StringUtils.center(playerName, 16);
- if (LobbyPlugin.getInstance().isOlimpoNetwork()) {
- this.setScore(15, StringUtils.EMPTY);
- this.setScore(14, playerName);
- this.setScore(13, StringUtils.EMPTY);
- this.setScore(12, ChatColor.GOLD + "══════════");
- // this.setScore(15, "");
- this.setScore(11, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
- // this.setScore(10, String.valueOf(LobbyPlayer.this.getData().getCoins()));
- this.setScore(9, StringUtils.EMPTY);
- this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
- // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
- // this.setScore(7, lPlayer.getData().getHighestRank().getFormattedPrefix());
- this.setScore(4, StringUtils.EMPTY);
- this.setScore(3, LobbyPlugin.getInstance().getColoredMessage("lobby.name.title"));
- this.setScore(2,
- String.format("%s%sLobby %s", ChatColor.GOLD, ChatColor.BOLD, LobbyPlugin.getInstance().getConfig().getString("lobby.id", "-1")));
- // this.setScore(4, (null != Bukkit.getPlayer("SkyTheKidRS"))?"YES":"NO");
- this.setScore(1, ChatColor.GOLD + "──────────");
- displayName = new ScrollableText(LobbyPlugin.getInstance().getColoredMessage("score.announce"), 16);
- } else if (LobbyPlugin.getInstance().isSkyNetwork()) {
- // Sky network stuff
- String name = ChatColor.GRAY.toString() + ChatColor.BOLD + getName();
- if (name.length() > 16) {
- name = name.substring(0, 16);
- }
- // this.setScore(15, "---------------");
- this.setScore(14, "----------------");
- // Empty space.
- this.setScore(13, ChatColor.GOLD.toString());
- this.setScore(12, ChatColor.GOLD + ChatColor.BOLD.toString() + "Butter Coins");
- // this.setScore(11, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
- // this.setScore(10, String.valueOf(lPlayer.getData().getCoins()));
- this.setScore(10, "");
- this.setScore(9, ChatColor.GOLD.toString() + ChatColor.BOLD + "Rank");
- // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
- this.setScore(8, StringUtils.isBlank(getData().getHighestRank().getFormattedPrefix()) ? ChatColor.RED.toString() + ChatColor.BOLD + "NONE"
- : getData().getHighestRank().getFormattedPrefix());
- // Empty space
- this.setScore(7, ChatColor.RED.toString());
- setScore(6, ChatColor.GOLD + ChatColor.BOLD.toString() + "Is Sky On?");
- // If hes online at the time then set yes.
- this.setScore(5,
- (null != Bukkit.getPlayerExact("SkyTheKidRS")) ? ChatColor.GREEN.toString() + ChatColor.BOLD + "YES" : ChatColor.RED.toString()
- + ChatColor.BOLD + "NO");
- setScore(4, ChatColor.YELLOW.toString());
- setScore(3, ChatColor.GOLD.toString() + ChatColor.BOLD + "Website");
- setScore(2, ChatColor.WHITE + "TheBudder.com");
- setScore(1, ChatColor.BLUE.toString());
- setScore(0, ChatColor.GOLD + ChatColor.BOLD.toString() + "Lobby: " + ChatColor.WHITE
- + (LobbyPlugin.getInstance().getBungeeId().equalsIgnoreCase("") ? "<3" : LobbyPlugin.getInstance().getBungeeId()));
- displayName = new ScrollableText(ChatColor.WHITE + ChatColor.BOLD.toString() + "Welcome " + ChatColor.AQUA + ChatColor.BOLD + getName()
- + ChatColor.WHITE.toString() + ChatColor.BOLD + " to the " + ChatColor.AQUA.toString() + ChatColor.BOLD + "SkyDoesMinecraft Network!",
- 20);
- } else {
- // Minecade
- this.setScore(15, "----------------");
- this.setScore(14, playerName);
- // this.setScore(13, "");
- this.setScore(13, " ");
- // this.setScore(15, "");
- this.setScore(12, LobbyPlugin.getInstance().getColoredMessage("coins.title"));
- // this.setScore(10, String.valueOf(lPlayer.getData().getCoins()));
- this.setScore(10, " ");
- this.setScore(9, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
- // this.setScore(8, LobbyPlugin.getInstance().getColoredMessage("rank.title"));
- // this.setScore(7, lPlayer.getData().getHighestRank().getFormattedPrefix());
- if (StringUtils.isBlank(LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix())) {
- buy_rank = new ScrollableText(ChatColor.WHITE + "Purchase a rank at " + ChatColor.AQUA + "minecade.com", 16);
- } else {
- setScore(8, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
- }
- this.setScore(7, " ");
- this.setScore(6, ChatColor.AQUA.toString() + ChatColor.BOLD + "Website");
- this.setScore(5, "minecade.com");
- // this.setScore(4, (null != Bukkit.getPlayer("SkyTheKidRS"))?"YES":"NO");
- // this.setScore(1, "────────────");
- this.setScore(4, " ");
- String lobbyInfo = ChatColor.AQUA + ChatColor.BOLD.toString() + "Lobby: " + ChatColor.WHITE
- + (LobbyPlugin.getInstance().getBungeeId().equalsIgnoreCase("") ? "<3" : LobbyPlugin.getInstance().getBungeeId());
- if (lobbyInfo.length() <= 16) {
- this.setScore(0, lobbyInfo);
- } else {
- this.setScore(0, lobbyInfo.substring(0, 16));
- }
- displayName = new ScrollableText(ChatColor.WHITE + ChatColor.BOLD.toString() + "Welcome " + ChatColor.AQUA + ChatColor.BOLD + getName()
- + ChatColor.WHITE.toString() + ChatColor.BOLD + " to the " + ChatColor.AQUA.toString() + ChatColor.BOLD + "Minecade Network!", 16);
- }
- updateDynamicScores();
- sidebar.setDisplayName(displayName.getVisibleText());
- sidebar.setDisplaySlot(DisplaySlot.SIDEBAR);
- if (LobbyPlayer.this.getPlayer().isOnline()) {
- LobbyPlayer.this.getPlayer().setScoreboard(board);
- } else {
- destroy();
- }
- }
- public void update() {
- if (null != displayName) {
- displayName.scrollText();
- sidebar.setDisplayName(displayName.getVisibleText());
- }
- if (buy_rank != null) {
- buy_rank.scrollText();
- removeScore(8);
- setScore(8, buy_rank.getVisibleText());
- }
- updateDynamicScores();
- }
- private void updateDynamicScores() {
- if (LobbyPlugin.getInstance().isOlimpoNetwork()) {
- this.setScore(10, String.format("%s%s%s", ChatColor.GOLD, ChatColor.BOLD, String.valueOf(LobbyPlayer.this.getData().getCoins())));
- } else if (LobbyPlugin.getInstance().isSkyNetwork()) {
- this.setScore(11, String.valueOf(LobbyPlayer.this.getData().getCoins()));
- if (Bukkit.getPlayerExact("SkyTheKidRS") != null) {
- // Hes online
- removeScore(5);
- setScore(5, ChatColor.GREEN.toString() + ChatColor.BOLD + "YES");
- } else {
- removeScore(5);
- setScore(5, ChatColor.RED.toString() + ChatColor.BOLD + "NO");
- }
- return;
- } else {
- this.setScore(11, ChatColor.BOLD + String.valueOf(LobbyPlayer.this.getData().getCoins()));
- }
- if (!StringUtils.isBlank(LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix())) {
- if (!LobbyPlugin.getInstance().isMinecadeNetwork()) {
- this.setScore(7, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
- this.removeScore(6);
- this.removeScore(5);
- } else {
- this.setScore(8, LobbyPlayer.this.getData().getHighestRank().getFormattedPrefix());
- }
- } else {
- if (!LobbyPlugin.getInstance().isMinecadeNetwork()) {
- this.setScore(7, LobbyPlugin.getInstance().getMessage("purchase.rank.1"));
- this.setScore(6, LobbyPlugin.getInstance().getMessage("purchase.rank.2"));
- this.setScore(5, LobbyPlugin.getInstance().getMessage("purchase.rank.3"));
- }
- }
- }
- private void destroy() {
- if (LobbyPlayer.this.getPlayer().isOnline()) {
- LobbyPlayer.this.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
- }
- for (String player : board.getEntries()) {
- board.resetScores(player);
- }
- for (Team team : board.getTeams()) {
- team.unregister();
- }
- sidebar.unregister();
- }
- private void updatePlayerTeam() {
- // long currentTime = 0;
- // if (LobbyPlugin.getInstance().isDebugMode()) {
- // for (Team team : board.getTeams()) {
- // Bukkit.getLogger().info(
- // String.format("Player: [%s] - Team: [%s] - Size: [%s]", getName(), team.getName(),
- // team.getSize()));
- // }
- // currentTime = System.currentTimeMillis();
- // }
- board.getTeam(LobbyPlayer.this.getData().getDisplayRank().getTranslatedName()).addPlayer(LobbyPlayer.this.getPlayer());
- // if (LobbyPlugin.getInstance().isDebugMode()) {
- // Bukkit.getLogger().info(
- // String.format("LobbyPlayerScoreboard.updatePlayerTeam took [%s] milliseconds",
- // System.currentTimeMillis() - currentTime));
- // }
- }
- public void updateScoreboardTeamFor(LobbyPlayer otherLPlayer) {
- // long currentTime = 0;
- // if (LobbyPlugin.getInstance().isDebugMode()) {
- // for (Team team : board.getTeams()) {
- // Bukkit.getLogger().info(
- // String.format("Player: [%s] - Team: [%s] - Size: [%s]", getName(), team.getName(),
- // team.getSize()));
- // }
- // currentTime = System.currentTimeMillis();
- // }
- Team otherPlayerTeam = board.getTeam(otherLPlayer.getData().getDisplayRank().getTranslatedName());
- if (null == otherPlayerTeam) {
- otherPlayerTeam = board.registerNewTeam(otherLPlayer.getData().getDisplayRank().getTranslatedName());
- otherPlayerTeam.setPrefix(otherLPlayer.getData().getDisplayRank().getFormattedPrefix()
- + String.format("%s %s", ChatColor.GRAY, ChatColor.RESET));
- }
- otherPlayerTeam.addPlayer(otherLPlayer.getPlayer());
- // if (LobbyPlugin.getInstance().isDebugMode()) {
- // Bukkit.getLogger().info(
- // String.format("LobbyPlayerScoreboard.updateScoreboardTeamFor took [%s] milliseconds",
- // System.currentTimeMillis() - currentTime));
- // }
- }
- }
- public Inventory stats_menu;
- public Inventory extras_menu;
- public void openStatsMenu() {
- if (stats_menu == null) {
- stats_menu = new StatsMenu().getInventory(getPlayer());
- }
- new BukkitRunnable() {
- public void run() {
- getPlayer().openInventory(stats_menu);
- }
- }.runTaskLater(LobbyPlugin.getInstance(), 3);
- }
- public Inventory getStatsMenu() {
- return stats_menu;
- }
- public void setStatsMenu(Inventory inv) {
- this.stats_menu = inv;
- }
- public void openExtrasMenu() {
- if (extras_menu == null) {
- extras_menu = new ExtrasItemMenu().getInventory(getPlayer());
- }
- getPlayer().openInventory(extras_menu);
- }
- public void reloadExtrasMenu() {
- for (Extras e : getData().enabledExtras()) {
- // Moves them to the front of their inventorys so theres no gap
- getPlayer().getInventory().remove(e.getDisplay());
- getPlayer().getInventory().addItem(e.getDisplay());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement