net.minecraft.scoreboard.ScorePlayerTeam Java Examples

The following examples show how to use net.minecraft.scoreboard.ScorePlayerTeam. 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: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if the given entity is an NPC
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is an NPC, {@code false} otherwise
 */
public static boolean isNPC(Entity entity) {
    if (entity instanceof EntityOtherPlayerMP) {
        EntityOtherPlayerMP player = (EntityOtherPlayerMP) entity;
        ScorePlayerTeam playerTeam = (ScorePlayerTeam) player.getTeam();

        // If it doesn't have a team, it's likely not a player.
        if (player.getTeam() == null) {
            return false;
        }

        // If it doesn't have a color prefix, it's not a player.
        return playerTeam.getColorPrefix().equals("");
    } else if (entity instanceof EntityArmorStand) {
        return entity.isInvisible();
    } else {
        return false;
    }
}
 
Example #2
Source File: HyperiumEntityPlayer.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public IChatComponent getDisplayName() {
    if (cachedName == null || System.currentTimeMillis() - lastChangeTime > 50L) {
        IChatComponent ichatcomponent = new ChatComponentText(ScorePlayerTeam
            .formatPlayerName(parent.getTeam(), displayName));
        ichatcomponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + parent.getName() + " "));
        //Unneeded for client
        if (Minecraft.getMinecraft().isIntegratedServerRunning()) {
            ichatcomponent.getChatStyle()
                .setChatHoverEvent(((IMixinEntity) parent).callGetHoverEvent());
        }
        ichatcomponent.getChatStyle().setInsertion(parent.getName());
        cachedName = ichatcomponent;
    }

    return cachedName;
}
 
Example #3
Source File: EntityUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void setGlowing(Entity entity, TextFormatting color, String teamName) {
	ScorePlayerTeam team = mc.world.getScoreboard().getTeamNames().contains(teamName) ?
			mc.world.getScoreboard().getTeam(teamName) :
			mc.world.getScoreboard().createTeam(teamName);
       
	mc.world.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), team);
	mc.world.getScoreboard().getTeam(teamName).setColor(color);
	
	entity.setGlowing(true);
}
 
Example #4
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ImmutableSet<Team> getTeams() {
    return ImmutableSet.copyOf(Iterables.transform((Collection<ScorePlayerTeam>) this.board.getTeams(), new Function<ScorePlayerTeam, Team>() {

        @Override
        public Team apply(ScorePlayerTeam input) {
            return new CraftTeam(CraftScoreboard.this, input);
        }
    }));
}
 
Example #5
Source File: DevUtils.java    From SkyblockAddons with MIT License 4 votes vote down vote up
/**
 * Copies the objective and scores that are being displayed on a scoreboard's sidebar.
 *
 * @param scoreboard the {@link Scoreboard} to copy the sidebar from
 * @param stripControlCodes if {@code true}, the control codes will be removed, otherwise they will be copied
 */
public static void copyScoreboardSidebar(Scoreboard scoreboard, boolean stripControlCodes) {
    Utils utils = SkyblockAddons.getInstance().getUtils();

    if (scoreboard == null) {
        utils.sendErrorMessage("No scoreboard found!");
        return;
    }

    ScoreObjective sideBarObjective = scoreboard.getObjectiveInDisplaySlot(1);
    if (sideBarObjective == null) {
        utils.sendErrorMessage("Nothing is being displayed in the sidebar!");
        return;
    }

    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb, Locale.CANADA);

    String objectiveName = sideBarObjective.getDisplayName();
    List<Score> scores = (List<Score>) scoreboard.getSortedScores(sideBarObjective);

    if (scores == null || scores.isEmpty()) {
        SkyblockAddons.getInstance().getUtils().sendErrorMessage("No scores were found!");
    }
    else {
        int width = SIDEBAR_COPY_WIDTH;

        if (stripControlCodes) {
            objectiveName = StringUtils.stripControlCodes(objectiveName);
        }

        // Remove scores that aren't rendered.
        scores = scores.stream().filter(input -> input.getPlayerName() != null && !input.getPlayerName().startsWith("#"))
                .skip(Math.max(scores.size() - 15, 0)).collect(Collectors.toList());

        /*
        Minecraft renders the scoreboard from bottom to top so to keep the same order when writing it from top
        to bottom, we need to reverse the scores' order.
        */
        Collections.reverse(scores);

        for (Score score:
                scores) {
            ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(score.getPlayerName());
            String playerName = ScorePlayerTeam.formatPlayerName(scoreplayerteam, score.getPlayerName());

            // Strip colours and emoji player names.
            playerName = RegexUtil.strip(playerName, RegexUtil.SIDEBAR_PLAYER_NAME_PATTERN);

            if (stripControlCodes) {
                playerName = StringUtils.stripControlCodes(playerName);
            }

            int points = score.getScorePoints();

            width = Math.max(width, (playerName + " " + points).length());
            formatter.format("%-" + width + "." +
                    width + "s %d%n", playerName, points);
        }

        // Insert the objective name at the top of the sidebar string.
        sb.insert(0, "\n").insert(0, org.apache.commons.lang3.StringUtils.center(objectiveName, width));

        copyStringToClipboard(sb.toString(), "Sidebar copied to clipboard!");
    }
}
 
Example #6
Source File: EntityUtils.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
public static String getName(final NetworkPlayerInfo networkPlayerInfoIn) {
    return networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() :
            ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName());
}
 
Example #7
Source File: HyperiumScoreboard.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void removeTeam(ScorePlayerTeam team, Map<String, ScorePlayerTeam> teams, Map<String, ScorePlayerTeam> teamMemberships) {
    if (team == null) return;
    if (team.getRegisteredName() != null) teams.remove(team.getRegisteredName());
    team.getMembershipCollection().forEach(teamMemberships::remove);
    parent.func_96513_c(team);
}
 
Example #8
Source File: ScoreboardDisplay.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void draw(int starX, double startY, boolean config) {
    if (objective != null) {
        boolean guiF = false;

        Scoreboard scoreboard = objective.getScoreboard();
        Collection<Score> collection = scoreboard.getSortedScores(objective);
        List<Score> list = collection.stream().filter(p_apply_1_ -> p_apply_1_.getPlayerName() != null &&
            !p_apply_1_.getPlayerName().startsWith("#")).collect(Collectors.toList());

        collection = list.size() > 15 ? Lists.newArrayList(Iterables.skip(list, collection.size() - 15)) : list;

        int i = Minecraft.getMinecraft().fontRendererObj.getStringWidth(objective.getDisplayName());

        for (Score score : collection) {
            ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(score.getPlayerName());
            String s = ScorePlayerTeam.formatPlayerName(scoreplayerteam, score.getPlayerName()) + ": " + EnumChatFormatting.RED + score.getScorePoints();
            i = Math.max(i, Minecraft.getMinecraft().fontRendererObj.getStringWidth(s));
        }

        int i1 = collection.size() * Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT;
        int l1 = starX;
        if (ElementRenderer.getCurrent().isRightSided()) l1 -= i;
        int j = 0;

        int k;
        for (Score score1 : collection) {
            ++j;
            ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score1.getPlayerName());
            String s1 = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score1.getPlayerName());
            String s2 = EnumChatFormatting.RED + "" + score1.getScorePoints();
            k = ((int) startY) + (collection.size() - j + 1) * Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT;

            if (ElementRenderer.getCurrent().isHighlighted()) {
                if (guiF) {
                    Gui.drawRect(l1 - 2, k, l1 + i, k + Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, 1342177280);
                } else {
                    RenderUtils.drawRect(l1 - 2, k, l1 + i, k + Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, 1342177280);
                }
            }

            Minecraft.getMinecraft().fontRendererObj.drawString(s1, l1, k, Color.WHITE.getRGB());
            if (data.optBoolean("numbers")) {
                Minecraft.getMinecraft().fontRendererObj.drawString(s2, l1 + i - Minecraft.getMinecraft().fontRendererObj.getStringWidth(s2), k, Color.WHITE.getRGB());
            }

            if (j == collection.size()) {
                String s3 = objective.getDisplayName();
                if (ElementRenderer.getCurrent().isHighlighted()) {
                    if (guiF) {
                        Gui.drawRect(l1 - 2, k - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT - 1, l1 + i, k - 1, 1610612736);
                        Gui.drawRect(l1 - 2, k - 1, l1 + i, k, 1342177280);
                    } else {
                        RenderUtils.drawRect(l1 - 2, k - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT - 1, l1 + i, k - 1, 1610612736);
                        RenderUtils.drawRect(l1 - 2, k - 1, l1 + i, k, 1342177280);
                    }
                }

                Minecraft.getMinecraft().fontRendererObj.drawString(s3, l1 + i / 2 - Minecraft.getMinecraft().fontRendererObj.getStringWidth(s3) / 2, k - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, Color.WHITE.getRGB());
            }
        }

        width = i - (data.optBoolean("numbers") ? 0 : 10);
        height = i1 + 10;
    }
}
 
Example #9
Source File: MixinScoreboard.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author boomboompower
 * @reason Fix NPE's
 */
@Overwrite
public void removeTeam(ScorePlayerTeam team) {
    hyperiumScoreboard.removeTeam(team, teams, teamMemberships);
}
 
Example #10
Source File: ScoreboardRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void render(ScoreObjective objective, ScaledResolution resolution) {
    RenderScoreboardEvent renderEvent = new RenderScoreboardEvent(xLocation, yLocation, objective, resolution);
    EventBus.INSTANCE.post(renderEvent);
    if (!renderEvent.isCancelled()) {
        Scoreboard scoreboard = objective.getScoreboard();
        Collection<Score> collection = scoreboard.getSortedScores(objective);
        List<Score> list = collection.stream().filter(p_apply_1_ -> p_apply_1_.getPlayerName() != null
            && !p_apply_1_.getPlayerName().startsWith("#")).collect(Collectors.toList());

        collection = list.size() > 15 ? Lists.newArrayList(Iterables.skip(list, collection.size() - 15)) : list;
        int i = getFontRenderer().getStringWidth(objective.getDisplayName());

        for (Score score : collection) {
            ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(score.getPlayerName());
            String s = ScorePlayerTeam.formatPlayerName(scoreplayerteam, score.getPlayerName()) + ": " + EnumChatFormatting.RED + score.getScorePoints();
            i = Math.max(i, getFontRenderer().getStringWidth(s));
        }

        int i1 = collection.size() * getFontRenderer().FONT_HEIGHT;
        int j1 = (int) (resolution.getScaledHeight_double() * yLocation) + i1 / 3;
        int k1 = 3;
        int l1 = (int) (resolution.getScaledWidth_double() * xLocation) - i - k1;
        int j = 0;

        for (Score score1 : collection) {
            ++j;
            ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score1.getPlayerName());
            String s1 = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score1.getPlayerName());
            String s2 = EnumChatFormatting.RED.toString() + score1.getScorePoints();
            int k = j1 - j * getFontRenderer().FONT_HEIGHT;
            int l = (int) (resolution.getScaledWidth_double() * xLocation) - k1 + 2;
            RenderUtils.drawRect(l1 - 2, k, l, k + getFontRenderer().FONT_HEIGHT, 1342177280);
            getFontRenderer().drawString(s1, l1, k, 553648127);
            getFontRenderer().drawString(s2, l - getFontRenderer().getStringWidth(s2), k, 553648127);

            if (j == collection.size()) {
                String s3 = objective.getDisplayName();
                RenderUtils.drawRect(l1 - 2, k - getFontRenderer().FONT_HEIGHT - 1, l, k - 1, 1610612736);
                RenderUtils.drawRect(l1 - 2, k - 1, l, k, 1342177280);
                getFontRenderer().drawString(s3, l1 + i / 2 - getFontRenderer().getStringWidth(s3) / 2, k - getFontRenderer().FONT_HEIGHT, 553648127);
            }
        }
    }
}
 
Example #11
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Team getPlayerTeam(OfflinePlayer player) throws IllegalArgumentException {
    Validate.notNull(player, "OfflinePlayer cannot be null");

    ScorePlayerTeam team = board.getPlayersTeam(player.getName());
    return team == null ? null : new CraftTeam(this, team);
}
 
Example #12
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Team getEntryTeam(String entry) throws IllegalArgumentException {
    Validate.notNull(entry, "Entry cannot be null");

    ScorePlayerTeam team = board.getPlayersTeam(entry);
    return team == null ? null : new CraftTeam(this, team);
}
 
Example #13
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Team getTeam(String teamName) throws IllegalArgumentException {
    Validate.notNull(teamName, "Team name cannot be null");

    ScorePlayerTeam team = board.getTeam(teamName);
    return team == null ? null : new CraftTeam(this, team);
}
 
Example #14
Source File: CraftTeam.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
CraftTeam(CraftScoreboard scoreboard, ScorePlayerTeam team) {
    super(scoreboard);
    this.team = team;
}