org.bukkit.scoreboard.NameTagVisibility Java Examples

The following examples show how to use org.bukkit.scoreboard.NameTagVisibility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NMSHacks.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
static Packet teamCreatePacket(
    String name,
    String displayName,
    String prefix,
    String suffix,
    boolean friendlyFire,
    boolean seeFriendlyInvisibles,
    Collection<String> players) {
  return teamPacket(
      0,
      name,
      displayName,
      prefix,
      suffix,
      friendlyFire,
      seeFriendlyInvisibles,
      NameTagVisibility.ALWAYS,
      players);
}
 
Example #2
Source File: ScoreboardMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void updatePartyScoreboardTeam(Party party, Team team, boolean forObservers) {
  match.getLogger().fine("Updating scoreboard team " + toString(team) + " for party " + party);

  team.setDisplayName(TextTranslations.translateLegacy(party.getName(), null));
  team.setPrefix(party.getColor().toString());
  team.setSuffix(ChatColor.WHITE.toString());

  team.setCanSeeFriendlyInvisibles(true);
  team.setAllowFriendlyFire(false);

  if (!forObservers && party instanceof Competitor) {
    NameTagVisibility nameTags = ((Competitor) party).getNameTagVisibility();

    team.setNameTagVisibility(nameTags);
  } else {
    team.setNameTagVisibility(NameTagVisibility.ALWAYS);
  }
}
 
Example #3
Source File: TeamFactory.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create a TeamInfo instance with the specified information.
 *
 * @param id unique id
 * @param defaultName Default name for the team.
 * @param defaultNamePlural Is the default name a plural word?
 * @param defaultColor Default color for the team.
 * @param overheadColor Color to be displayed above the team members' avatars.
 * @param maxPlayers Maximum amount of players that may be on this team.
 * @param nameTagVisibility Who can see the name tags of players on this team
 */
public TeamFactory(
    @Nullable String id,
    String defaultName,
    boolean defaultNamePlural,
    ChatColor defaultColor,
    @Nullable ChatColor overheadColor,
    int minPlayers,
    int maxPlayers,
    int maxOverfill,
    NameTagVisibility nameTagVisibility) {
  super(id);
  this.defaultName = defaultName;
  this.defaultNamePlural = defaultNamePlural;
  this.defaultColor = defaultColor;
  this.overheadColor = overheadColor;
  this.minPlayers = minPlayers;
  this.maxPlayers = maxPlayers;
  this.maxOverfill = maxOverfill;
  this.nameTagVisibility = nameTagVisibility;
}
 
Example #4
Source File: FreeForAllOptions.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public FreeForAllOptions(
    int minPlayers,
    int maxPlayers,
    int maxOverfill,
    NameTagVisibility nameTagVisibility,
    boolean colors) {
  this.minPlayers = minPlayers;
  this.maxPlayers = maxPlayers;
  this.maxOverfill = maxOverfill;
  this.nameTagVisibility = nameTagVisibility;
  this.colors = colors;
}
 
Example #5
Source File: FreeForAllModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public FreeForAllModule parse(MapFactory factory, Logger logger, Document doc)
    throws InvalidXMLException {
  Element elPlayers = doc.getRootElement().getChild("players");

  if (factory.hasModule(TeamModule.class)) {
    if (elPlayers != null)
      throw new InvalidXMLException("Cannot combine <players> and <teams>", elPlayers);
    return null;
  } else {
    int minPlayers = (int) PGM.get().getConfiguration().getMinimumPlayers();
    int maxPlayers = Bukkit.getMaxPlayers();
    int maxOverfill = maxPlayers;
    NameTagVisibility nameTagVisibility = NameTagVisibility.ALWAYS;
    boolean colors = false;

    if (elPlayers != null) {
      minPlayers =
          XMLUtils.parseNumber(elPlayers.getAttribute("min"), Integer.class, minPlayers);
      maxPlayers =
          XMLUtils.parseNumber(elPlayers.getAttribute("max"), Integer.class, maxPlayers);
      maxOverfill =
          XMLUtils.parseNumber(
              elPlayers.getAttribute("max-overfill"), Integer.class, maxOverfill);
      nameTagVisibility =
          XMLUtils.parseNameTagVisibility(
              Node.fromAttr(elPlayers, "show-name-tags"), nameTagVisibility);
      colors = XMLUtils.parseBoolean(Node.fromAttr(elPlayers, "colors"), colors);
    }

    return new FreeForAllModule(
        new FreeForAllOptions(minPlayers, maxPlayers, maxOverfill, nameTagVisibility, colors));
  }
}
 
Example #6
Source File: XMLUtils.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static NameTagVisibility parseNameTagVisibility(Node node, NameTagVisibility def)
    throws InvalidXMLException {
  if (node == null) return def;

  switch (node.getValue()) {
    case "yes":
    case "on":
    case "true":
      return NameTagVisibility.ALWAYS;

    case "no":
    case "off":
    case "false":
      return NameTagVisibility.NEVER;

    case "ally":
    case "allies":
      return NameTagVisibility.HIDE_FOR_OTHER_TEAMS;

    case "enemy":
    case "enemies":
      return NameTagVisibility.HIDE_FOR_OWN_TEAM;

    default:
      throw new InvalidXMLException("Invalid name tag visibility value", node);
  }
}
 
Example #7
Source File: NMSHacks.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static Packet teamPacket(
    int operation,
    String name,
    String displayName,
    String prefix,
    String suffix,
    boolean friendlyFire,
    boolean seeFriendlyInvisibles,
    NameTagVisibility nameTagVisibility,
    Collection<String> players) {

  PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam();
  packet.a = name;
  packet.b = displayName;
  packet.c = prefix;
  packet.d = suffix;
  packet.e = nameTagVisibility == null ? null : CraftTeam.bukkitToNotch(nameTagVisibility).e;
  // packet.f = color
  packet.g = players;
  packet.h = operation;
  if (friendlyFire) {
    packet.i |= 1;
  }
  if (seeFriendlyInvisibles) {
    packet.i |= 2;
  }
  return packet;
}
 
Example #8
Source File: CraftTeam.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static EnumVisible bukkitToNotch(NameTagVisibility visibility) {
    switch (visibility) {
        case ALWAYS:
            return EnumVisible.ALWAYS;
        case NEVER:
            return EnumVisible.NEVER;
        case HIDE_FOR_OTHER_TEAMS:
            return EnumVisible.HIDE_FOR_OTHER_TEAMS;
        case HIDE_FOR_OWN_TEAM:
            return EnumVisible.HIDE_FOR_OWN_TEAM;
        default:
            throw new IllegalArgumentException("Unknown visibility level " + visibility);
    }
}
 
Example #9
Source File: CraftTeam.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static NameTagVisibility notchToBukkit(EnumVisible visibility) {
    switch (visibility) {
        case ALWAYS:
            return NameTagVisibility.ALWAYS;
        case NEVER:
            return NameTagVisibility.NEVER;
        case HIDE_FOR_OTHER_TEAMS:
            return NameTagVisibility.HIDE_FOR_OTHER_TEAMS;
        case HIDE_FOR_OWN_TEAM:
            return NameTagVisibility.HIDE_FOR_OWN_TEAM;
        default:
            throw new IllegalArgumentException("Unknown visibility level " + visibility);
    }
}
 
Example #10
Source File: TeamManager.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the team name tag visibility of a team by team name.
 *
 * @param team The reference name of the team.
 * @param vis  The NameTagVisibility object to be set.
 */
public void setTeamNameTagVisibility(String team, NameTagVisibility vis) {
    if (teamMap.containsKey(team)) {
        teamMap.get(team).setNameTagVisibility(vis);
        for (Object p : Bukkit.getServer().getOnlinePlayers().toArray()) {
            // Debug
            Bukkit.broadcastMessage("Friendly Invisibles set!");
            ((Player) p).getScoreboard().getTeam(team).setNameTagVisibility(vis);
        }
    }
}
 
Example #11
Source File: Tribute.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public NameTagVisibility getNameTagVisibility() {
  return ffa.getOptions().nameTagVisibility;
}
 
Example #12
Source File: Team.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public NameTagVisibility getNameTagVisibility() {
  return info.getNameTagVisibility();
}
 
Example #13
Source File: TeamModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private static TeamFactory parseTeamDefinition(Element el, MapFactory factory)
    throws InvalidXMLException {
  String id = el.getAttributeValue("id");

  String name = el.getTextNormalize();
  if ("".equals(name)) {
    throw new InvalidXMLException("Team name cannot be blank", el);
  }

  boolean plural = XMLUtils.parseBoolean(el.getAttribute("plural"), false);

  ChatColor color = XMLUtils.parseChatColor(Node.fromAttr(el, "color"), ChatColor.WHITE);
  ChatColor overheadColor = XMLUtils.parseChatColor(Node.fromAttr(el, "overhead-color"), null);
  NameTagVisibility nameTagVisibility =
      XMLUtils.parseNameTagVisibility(
          Node.fromAttr(el, "show-name-tags"), NameTagVisibility.ALWAYS);

  int minPlayers = XMLUtils.parseNumber(Node.fromAttr(el, "min"), Integer.class, 0);
  int maxPlayers = XMLUtils.parseNumber(Node.fromRequiredAttr(el, "max"), Integer.class);

  Attribute attrMaxOverfill = el.getAttribute("max-overfill");
  int maxOverfill =
      XMLUtils.parseNumber(attrMaxOverfill, Integer.class, (int) (maxPlayers * OVERFILL_RATIO));
  if (maxOverfill < maxPlayers) {
    throw new InvalidXMLException("Max overfill can not be less then max players.", el);
  }

  TeamFactory teamFactory =
      new TeamFactory(
          id,
          name,
          plural,
          color,
          overheadColor,
          minPlayers,
          maxPlayers,
          maxOverfill,
          nameTagVisibility);
  factory.getFeatures().addFeature(el, teamFactory);

  return teamFactory;
}
 
Example #14
Source File: TeamFactory.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public NameTagVisibility getNameTagVisibility() {
  return nameTagVisibility;
}
 
Example #15
Source File: CraftTeam.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public NameTagVisibility getNameTagVisibility() throws IllegalArgumentException {
    CraftScoreboard scoreboard = checkState();

    return notchToBukkit(team.getNameTagVisibility());
}
 
Example #16
Source File: CraftTeam.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setNameTagVisibility(NameTagVisibility visibility) throws IllegalArgumentException {
    CraftScoreboard scoreboard = checkState();

    team.setNameTagVisibility(bukkitToNotch(visibility));
}
 
Example #17
Source File: VersionUtils_1_8.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setTeamNameTagVisibility(Team team, boolean value){
    team.setNameTagVisibility(value?NameTagVisibility.ALWAYS:NameTagVisibility.NEVER);
}
 
Example #18
Source File: Competitor.java    From PGM with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Get the {@link NameTagVisibility} for {@link MatchPlayer}s.
 *
 * @return The {@link NameTagVisibility}.
 */
NameTagVisibility getNameTagVisibility();