package pl.kacperduras.funnytab; 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.entity.Player; import pl.kacperduras.protocoltab.ProtocolTabAPI; import pl.kacperduras.protocoltab.manager.ProtocolTab; import java.util.Calendar; public class FunnyTabTask implements Runnable { private final FunnyTabPlugin plugin; public FunnyTabTask(FunnyTabPlugin plugin) { Validate.isTrue(plugin != null, "Plugin can not be null!"); this.plugin = plugin; } @Override public void run() { for (Player player : this.plugin.getServer().getOnlinePlayers()) { for (int i = 0; i < 80; i++) { String cell = this.plugin.getConfiguration().getCells().get(i + 1); if (cell == null) { cell = ProtocolTab.BLANK_TEXT; } cell = this.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 ProtocolTab.BLANK_TEXT; } // time Calendar time = Calendar.getInstance(); int hour = time.get(Calendar.HOUR_OF_DAY); int minute = time.get(Calendar.MINUTE); int second = time.get(Calendar.SECOND); 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)); } // guild if (user.hasGuild()) { cell = StringUtils.replace(cell, "{GUILD}", user.getGuild().getName()); cell = StringUtils.replace(cell, "{TAG}", user.getGuild().getTag().toUpperCase()); cell = StringUtils.replace(cell, "{G-OWNER}", (user.getGuild().getOwner().getName())); cell = StringUtils.replace(cell, "{G-LIVES}", String.valueOf(user.getGuild().getLives())); if((user.getGuild()).getPvP()){ cell = StringUtils.replace(cell, "{G-PVP}", "&awlaczony"); } else { cell = StringUtils.replace(cell, "{G-PVP}", "&cwylaczony"); } cell = StringUtils.replace(cell, "{G-DEPUTY}", (user.getGuild()).getDeputy().getName()); cell = StringUtils.replace(cell, "{G-ALLIES}", String.valueOf((user.getGuild()).getAllies().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().getBasic())); if(user.isOwner()){ cell = StringUtils.replace(cell, "{G-ROLE}", "Zalozyciel"); } else if(user.isDeputy()){ cell = StringUtils.replace(cell, "{G-ROLE}", "Zastepca"); } else{ cell = StringUtils.replace(cell, "{G-ROLE}", "Czlonek"); } } else { cell = StringUtils.replace(cell, "{GUILD}", ""); cell = StringUtils.replace(cell, "{TAG}", ""); cell = StringUtils.replace(cell, "{G-OWNER}", ""); cell = StringUtils.replace(cell, "{G-LIVES}", ""); cell = StringUtils.replace(cell, "{G-PVP}", ""); cell = StringUtils.replace(cell, "{G-DEPUTY}", ""); cell = StringUtils.replace(cell, "{G-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, "{G-ALLIES}", ""); } 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().getBasic())); cell = StringUtils.replace(cell, "{ONLINE}", String.valueOf(this.plugin.getServer().getOnlinePlayers().size())); cell = StringUtils.replace(cell, "{TPS}", Ticking.getTPS()); // parser String temp = Parser.parseRank(cell); if (temp != null) { cell = temp; } return cell; } }