自动添加和删除Tablist中的项目

时间:2016-09-05 22:22:15

标签: java bukkit

嘿伙计们,我只是制作我的tablist插件。我已经尝试过一点了。我尝试了很多东西,到目前为止还没有一个出现过。我的目标是自动添加一个派系成员名称,如果他们加入显示在线成员的选项卡列表并自动删除它。

更清楚的解释: 派系成员名称在加入时必须显示在选项卡列表中。我尝试过这样做,它只是将它们组合在一个条目列表中的1个条目或1个插槽中。 我希望它们在1个标签页中显示1个名称。

我怎么能这样做呢?

有人有任何想法吗?这是我的代码(这不包括自动加入和离开)

代码几乎没用,但在这里

 if (fplayer.hasFaction())
{
  list.setSlot(0, "", ChatColor.DARK_PURPLE + "Home:", "");
  if (faction.hasHome())
  {
    int x = faction.getHome().getBlockX();
    int z = faction.getHome().getBlockZ();

    String xz = x + ", " + z;

    list.setSlot(3, "", ChatColor.BLUE.toString(), ChatColor.YELLOW + xz);
  }
  else
  {
    list.setSlot(3, "", ChatColor.DARK_RED.toString(), ChatColor.YELLOW + "Not Set");
  }
  list.setSlot(1, "", ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("SERVER-NAME")), "");

  list.setSlot(2, "", ChatColor.DARK_PURPLE + "End Portals:", "");
  list.setSlot(5, "", ChatColor.YELLOW + plugin.getConfig().getString("END-PORTAL-COORDS"), "");
  list.setSlot(8, "", ChatColor.YELLOW + "in each ", ChatColor.YELLOW + "quadrant.");


  int KILLS = Stats.kdc.getInt("p." + p.getUniqueId().toString() + ".kills");
  String KILLSS = Integer.toString(KILLS);
  int DEATHS = Stats.kdc.getInt("p." + p.getUniqueId().toString() + ".deaths");
  String DEATHSS = Integer.toString(DEATHS);

  list.setSlot(22, "", ChatColor.DARK_BLUE.toString(), ChatColor.DARK_PURPLE + "Player Info:");
  list.setSlot(25, "", ChatColor.YELLOW + "Kills: ", ChatColor.YELLOW + KILLSS);
  list.setSlot(28, "", ChatColor.YELLOW + "Deaths: ", ChatColor.YELLOW + DEATHSS);

  DecimalFormat dtrf = new DecimalFormat("#.###");

  list.setSlot(10, "", ChatColor.DARK_GREEN.toString(), ChatColor.DARK_PURPLE + "Faction Info:");
  list.setSlot(13, "", ChatColor.YELLOW + "DTR: ", String.valueOf(dtrf.format(faction.getDTR())));
  list.setSlot(16, "", ChatColor.YELLOW + "Online: ", String.valueOf(faction.getOnlinePlayers().size() + "/" + faction.getSize()));

  int x = p.getLocation().getBlockX();
  int z = p.getLocation().getBlockZ();

  String xz = "(" + x + ", " + z + ")";

  list.setSlot(34, "", ChatColor.DARK_PURPLE + "Location:", "");

  list.setSlot(37, "", ChatColor.UNDERLINE.toString(), ChatColor.YELLOW + "Unknown");

  list.setSlot(40, ChatColor.GRAY + "[" + getCardinalDirection(p) + "] ", ChatColor.MAGIC.toString(), ChatColor.GRAY + xz);

  list.setSlot(46, "", ChatColor.DARK_PURPLE + "KoTH:", "");
  list.setSlot(49, "", ChatColor.YELLOW + "Name: ", ChatColor.YELLOW + "None");
  list.setSlot(52, "", ChatColor.YELLOW + "Loc: ", ChatColor.YELLOW + "None");
  list.setSlot(55, "", ChatColor.YELLOW + "Time: ", ChatColor.YELLOW + "None");

  list.setSlot(15, "", ChatColor.DARK_PURPLE + "Kit:", "");
  list.setSlot(18, "", ChatColor.YELLOW + plugin.getConfig().getString("MAP-KIT"), "");

  list.setSlot(24, "", ChatColor.DARK_PURPLE + "Border:", "");
  list.setSlot(27, "", ChatColor.YELLOW + plugin.getConfig().getString("BORDER-COORDS"), "");

  int i = 0;
  for (Player o : Bukkit.getOnlinePlayers()) {
    i++;
  }
  list.setSlot(33, "", ChatColor.DARK_PURPLE + "Players Online ", ChatColor.DARK_PURPLE + ": ");
  list.setSlot(36, "", ChatColor.WHITE.toString(), ChatColor.YELLOW + String.valueOf(i));

  list.setDefaultPing(1);

1 个答案:

答案 0 :(得分:0)

你可以挂钩派系并听取玩家加入/离开阵营时被解雇的事件,然后循环通过源和目标派系的玩家,在路上更新他们的列表。

或者你可以通过设置 ASYC 重复任务来实现更加滞后的方式,该任务尝试更新所有玩家的选项卡列表而不管其派系状态如何。我之所以说 ASYC ,是因为如果方法失败,你就不会在主服务器线程上造成中断。