package pl.kacperduras.funnytab; import java.util.Calendar; import java.util.Collection; import java.util.Map; import net.dzikoysk.funnyguilds.basic.Guild; import net.dzikoysk.funnyguilds.basic.Rank; import net.dzikoysk.funnyguilds.basic.User; import net.dzikoysk.funnyguilds.util.Parser; import net.dzikoysk.funnyguilds.util.runnable.Ticking; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; import pl.kacperduras.protocoltab.ProtocolTabAPI; import pl.kacperduras.protocoltab.manager.ProtocolTab; public class FunnyTabTask implements Runnable { private final FunnyTabPlugin plugin; public FunnyTabTask(FunnyTabPlugin plugin) { Validate.isTrue(plugin != null, "Plugin can not be null!", new Object[0]); this.plugin = plugin; } public void run() { for (Player player : this.plugin.getServer().getOnlinePlayers()) { for (int i = 0; i < 80; i++) { String cell = (String)this.plugin.getConfiguration().getCells().get(Integer.valueOf(i + 1)); if (cell == null) { cell = " "; } cell = parseCell(cell, player); ProtocolTabAPI.getTablist(player).setSlot(i, cell); } ProtocolTabAPI.getTablist(player).setHeader(this.plugin.getConfiguration().getHeader()); ProtocolTabAPI.getTablist(player).setFooter(this.plugin.getConfiguration().getFooter()); ProtocolTabAPI.getTablist(player).update(); } } private String parseCell(String cell, Player target) { User user = User.get(target); if (user == null) { return " "; } Calendar time = Calendar.getInstance(); int hour = time.get(11); int minute = time.get(12); int second = time.get(13); if (hour < 10) { cell = StringUtils.replace(cell, "{HOUR}", "0" + String.valueOf(hour)); } else { cell = StringUtils.replace(cell, "{HOUR}", String.valueOf(hour)); } if (minute < 10) { cell = StringUtils.replace(cell, "{MINUTE}", "0" + String.valueOf(minute)); } else { cell = StringUtils.replace(cell, "{HOUR}", String.valueOf(hour)); } if (second < 10) { cell = StringUtils.replace(cell, "{SECOND}", "0" + String.valueOf(second)); } else { cell = StringUtils.replace(cell, "{HOUR}", String.valueOf(hour)); } if (user.hasGuild()) { cell = StringUtils.replace(cell, "{GUILD}", user.getGuild().getName()); cell = StringUtils.replace(cell, "{TAG}", user.getGuild().getTag().toUpperCase()); cell = StringUtils.replace(cell, "{OWNER}", (user.getGuild().getOwner().getName())); cell = StringUtils.replace(cell, "{LIVES}", String.valueOf(user.getGuild().getLives())); if((user.getGuild()).getPvP()){ cell = StringUtils.replace(cell, "{PVP}", "&awlaczony"); } else { cell = StringUtils.replace(cell, "{PVP}", "&cwylaczony"); } cell = StringUtils.replace(cell, "{DEPUTY}", (user.getGuild()).getDeputy().getName()); cell = StringUtils.replace(cell, "{ALLIES}", (user.getGuild()).getAllies().toString()); cell = StringUtils.replace(cell, "{G-ONLINE}", cell, (user.getGuild()).getMembers().size()); cell = StringUtils.replace(cell, "{G-POINTS}", String.valueOf(user.getGuild().getRank().getPoints())); cell = StringUtils.replace(cell, "{G-KILLS}", String.valueOf(user.getGuild().getRank().getKills())); cell = StringUtils.replace(cell, "{G-DEATHS}", String.valueOf(user.getGuild().getRank().getDeaths())); cell = StringUtils.replace(cell, "{G-POSITIONS}", String.valueOf(user.getGuild().getRank().getPosition())); if(user.isOwner()){ cell = StringUtils.replace(cell, "{ROLE}", "Zalozyciel"); } else if(user.isDeputy()){ cell = StringUtils.replace(cell, "{ROLE}", "Zastepca"); } else{ cell = StringUtils.replace(cell, "{ROLE}", "Czlonek"); } } else { cell = StringUtils.replace(cell, "{GUILD}", ""); cell = StringUtils.replace(cell, "{TAG}", ""); cell = StringUtils.replace(cell, "{OWNER}", ""); cell = StringUtils.replace(cell, "{LIVES}", ""); cell = StringUtils.replace(cell, "{PVP}", ""); cell = StringUtils.replace(cell, "{DEPUTY}", ""); cell = StringUtils.replace(cell, "{G-ONLINE}", ""); cell = StringUtils.replace(cell, "{ROLE}", ""); cell = StringUtils.replace(cell, "{G-POINTS}", ""); cell = StringUtils.replace(cell, "{G-KILLS}", ""); cell = StringUtils.replace(cell, "{G-DEATHS}", ""); cell = StringUtils.replace(cell, "{G-POSITIONS}", ""); } cell = StringUtils.replace(cell, "{PLAYER}", target.getName()); cell = StringUtils.replace(cell, "{PING}", String.valueOf(user.getPing())); cell = StringUtils.replace(cell, "{POINTS}", String.valueOf(user.getRank().getPoints())); cell = StringUtils.replace(cell, "{KILLS}", String.valueOf(user.getRank().getKills())); cell = StringUtils.replace(cell, "{DEATHS}", String.valueOf(user.getRank().getDeaths())); cell = StringUtils.replace(cell, "{POSITIONS}", String.valueOf(user.getRank().getPosition())); cell = StringUtils.replace(cell, "{ONLINE}", String.valueOf(Bukkit.getOnlinePlayers())); cell = StringUtils.replace(cell, "{TPS}", Ticking.getTPS()); String temp = Parser.parseRank(cell); if (temp != null) { cell = temp; } return cell; } }