net.minecraft.scoreboard.ScoreObjective Java Examples

The following examples show how to use net.minecraft.scoreboard.ScoreObjective. 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: MixinRenderPlayer.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @author Sk1er
 * @reason Cancel nametag render event when score is renderer
 */
@Overwrite
protected void renderOffsetLivingLabel(AbstractClientPlayer entityIn, double x, double y, double z, String str, float p_177069_9_, double p_177069_10_) {
    if (p_177069_10_ < 100.0D) {
        Scoreboard scoreboard = entityIn.getWorldScoreboard();
        ScoreObjective scoreobjective = scoreboard.getObjectiveInDisplaySlot(2);

        if (scoreobjective != null) {
            Score score = scoreboard.getValueFromObjective(entityIn.getName(), scoreobjective);
            RenderNameTagEvent.CANCEL = true;
            if (entityIn != Minecraft.getMinecraft().thePlayer) {
                renderLivingLabel(entityIn, score.getScorePoints() + " " + scoreobjective.getDisplayName(), x, y, z, 64);
                y += (float) getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * p_177069_9_;
            }

            RenderNameTagEvent.CANCEL = false;
        }
    }

    super.renderOffsetLivingLabel(entityIn, x, y, z, str, p_177069_9_, p_177069_10_);
}
 
Example #2
Source File: CraftScore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public int getScore() throws IllegalStateException {
    Scoreboard board = objective.checkState().board;

    if (board.getObjectiveNames().contains(entry)) { // Lazy
        Map<ScoreObjective, net.minecraft.scoreboard.Score> scores = board.getObjectivesForEntity(entry);
        net.minecraft.scoreboard.Score score = scores.get(objective.getHandle());
        if (score != null) { // Lazy
            return score.getScorePoints();
        }
    }

    return 0; // Lazy
}
 
Example #3
Source File: CraftObjective.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public DisplaySlot getDisplaySlot() throws IllegalStateException {
    CraftScoreboard scoreboard = checkState();
    Scoreboard board = scoreboard.board;
    ScoreObjective objective = this.objective;

    for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
        if (board.getObjectiveInDisplaySlot(i) == objective) {
            return CraftScoreboardTranslations.toBukkitSlot(i);
        }
    }
    return null;
}
 
Example #4
Source File: CraftObjective.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void setDisplaySlot(DisplaySlot slot) throws IllegalStateException {
    CraftScoreboard scoreboard = checkState();
    Scoreboard board = scoreboard.board;
    ScoreObjective objective = this.objective;

    for (int i = 0; i < CraftScoreboardTranslations.MAX_DISPLAY_SLOT; i++) {
        if (board.getObjectiveInDisplaySlot(i) == objective) {
            board.setObjectiveInDisplaySlot(i, null);
        }
    }
    if (slot != null) {
        int slotNumber = CraftScoreboardTranslations.fromBukkitSlot(slot);
        board.setObjectiveInDisplaySlot(slotNumber, getHandle());
    }
}
 
Example #5
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void resetScores(String entry) throws IllegalArgumentException {
    Validate.notNull(entry, "Entry cannot be null");

    for (ScoreObjective objective : (Collection<ScoreObjective>) this.board.getScoreObjectives()) {
        board.removeObjectiveFromEntity(entry, objective);
    }
}
 
Example #6
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException {
    Validate.notNull(entry, "Entry cannot be null");

    ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
    for (ScoreObjective objective : (Collection<ScoreObjective>) this.board.getScoreObjectives()) {
        scores.add(new CraftScore(new CraftObjective(this, objective), entry));
    }
    return scores.build();
}
 
Example #7
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Objective getObjective(DisplaySlot slot) throws IllegalArgumentException {
    Validate.notNull(slot, "Display slot cannot be null");
    ScoreObjective objective = board.getObjectiveInDisplaySlot(CraftScoreboardTranslations.fromBukkitSlot(slot));
    if (objective == null) {
        return null;
    }
    return new CraftObjective(this, objective);
}
 
Example #8
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ImmutableSet<Objective> getObjectives() {
    return ImmutableSet.copyOf(Iterables.transform((Collection<ScoreObjective>) this.board.getScoreObjectives(), new Function<ScoreObjective, Objective>() {

        @Override
        public Objective apply(ScoreObjective input) {
            return new CraftObjective(CraftScoreboard.this, input);
        }
    }));
}
 
Example #9
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ImmutableSet<Objective> getObjectivesByCriteria(String criteria) throws IllegalArgumentException {
    Validate.notNull(criteria, "Criteria cannot be null");

    ImmutableSet.Builder<Objective> objectives = ImmutableSet.builder();
    for (ScoreObjective netObjective : (Collection<ScoreObjective>) this.board.getScoreObjectives()) {
        CraftObjective objective = new CraftObjective(this, netObjective);
        if (objective.getCriteria().equals(criteria)) {
            objectives.add(objective);
        }
    }
    return objectives.build();
}
 
Example #10
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
    Validate.notNull(name, "Objective name cannot be null");
    Validate.notNull(criteria, "Criteria cannot be null");
    Validate.isTrue(name.length() <= 16, "The name '" + name + "' is longer than the limit of 16 characters");
    Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");

    CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
    ScoreObjective objective = board.addScoreObjective(name, craftCriteria.criteria);
    return new CraftObjective(this, objective);
}
 
Example #11
Source File: GuiScreenSidebar.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    super.drawScreen(mouseX, mouseY, partialTicks);
    if (mc.thePlayer != null) {
        ScoreObjective scoreObjective = mc.thePlayer.getWorldScoreboard().getObjectiveInDisplaySlot(1);
        if (scoreObjective != null) sidebar.drawSidebar(scoreObjective, new ScaledResolution(mc));
    }

    if (dragging) {
        sidebar.offsetX += mouseX - lastX;
        sidebar.offsetY += mouseY - lastY;
    }

    lastX = mouseX;
    lastY = mouseY;
}
 
Example #12
Source File: LevelheadGui.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawPingHook(int i, int x, int y, NetworkPlayerInfo playerInfo) {
    if (!Levelhead.getInstance().getDisplayManager().getMasterConfig().isEnabled()) {
        return;
    }

    Levelhead instance = Levelhead.getInstance();
    LevelheadDisplay tab = instance.getDisplayManager().getTab();
    if (tab != null) {
        if (!tab.getConfig().isEnabled()) return;
        if (instance.getLevelheadPurchaseStates().isTab()) {
            String s = tab.getTrueValueCache().get(playerInfo.getGameProfile().getId());
            if (s != null) {
                FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
                int x1 = i + x - 12 - fontRenderer.getStringWidth(s);

                Scoreboard board = Minecraft.getMinecraft().theWorld.getScoreboard();
                ScoreObjective objective = board.getObjectiveInDisplaySlot(0);

                if (objective != null) {
                    int score = board.getValueFromObjective(playerInfo.getGameProfile().getName(), objective).getScorePoints();
                    int extraWidth = fontRenderer.getStringWidth(" " + score);

                    x1 -= extraWidth;
                }

                DisplayConfig config = tab.getConfig();
                if (config.isFooterChroma()) {
                    fontRenderer.drawString(s, x1, y, instance.getRGBColor());
                } else if (config.isFooterRgb()) {
                    fontRenderer.drawString(s, x1, y, new Color(config.getFooterRed(), config.getFooterGreen(), config.getFooterBlue()).getRGB());
                } else {
                    fontRenderer.drawString(config.getFooterColor() + s, x1, y, -1);
                }
            }
        }
    }
}
 
Example #13
Source File: RenderScoreboardEvent.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public RenderScoreboardEvent(double x, double y, @NotNull ScoreObjective objective, @NotNull ScaledResolution resolution) {
    Preconditions.checkNotNull(objective, "objective");
    Preconditions.checkNotNull(resolution, "resolution");

    this.x = x;
    this.y = y;

    this.objective = objective;
    this.resolution = resolution;
}
 
Example #14
Source File: HyperiumGuiIngame.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void renderScoreboard(ScoreObjective objective, ScaledResolution resolution) {
    //For *extra* scoreboards
    ScoreboardDisplay.objective = objective;
    ScoreboardDisplay.resolution = resolution;

    if (renderScoreboard) Hyperium.INSTANCE.getHandlers().getScoreboardRenderer().render(objective, resolution);
}
 
Example #15
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 #16
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 #17
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Objective getObjective(String name) throws IllegalArgumentException {
    Validate.notNull(name, "Name cannot be null");
    ScoreObjective nms = board.getObjective(name);
    return nms == null ? null : new CraftObjective(this, nms);
}
 
Example #18
Source File: MixinGuiPlayerTabOverlay.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 * @reason Friends first in tab
 */
@Overwrite
public void renderPlayerlist(int width, Scoreboard scoreboardIn, ScoreObjective scoreObjectiveIn) {
    hyperiumGuiPlayerTabOverlay.renderPlayerlist(width, scoreboardIn, scoreObjectiveIn, field_175252_a, header, footer, mc);
}
 
Example #19
Source File: MixinGuiIngame.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author ?
 * @reason For extra scoreboards
 */
@Overwrite
private void renderScoreboard(ScoreObjective objective, ScaledResolution resolution) {
    hyperiumGuiIngame.renderScoreboard(objective, resolution);
}
 
Example #20
Source File: AboveHeadRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@InvokeEvent
public void render(RenderPlayerEvent event) {
    if (levelhead == null ||
        levelhead.getDisplayManager() == null ||
        levelhead.getDisplayManager().getMasterConfig() == null ||
        !levelhead.getDisplayManager().getMasterConfig().isEnabled()) {
        return;
    }

    EntityPlayer player = event.getEntity();
    int o = 0;

    for (AboveHeadDisplay display : levelhead.getDisplayManager().getAboveHead()) {
        int index = display.getIndex();
        int extraHead = levelhead.getLevelheadPurchaseStates().getExtraHead();
        if (index > extraHead || !display.getConfig().isEnabled()) continue;

        LevelheadTag levelheadTag = display.getCache().get(player.getUniqueID());

        if (display.loadOrRender(player) && levelheadTag != null && !(levelheadTag instanceof NullLevelheadTag)) {
            if ((event.getEntity().getUniqueID().equals(Levelhead.getInstance().userUuid) && !display.getConfig().isShowSelf()
                || !Hyperium.INSTANCE.getHandlers().getHypixelDetector().isHypixel())) {
                continue;
            }

            if (player.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 64 * 64) {
                double offset = 0.3;
                Scoreboard scoreboard = player.getWorldScoreboard();
                ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(2);

                if (objective != null && event.getEntity().getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 10 * 10) {
                    offset *= 2;
                }

                if (player.getUniqueID().equals(levelhead.userUuid) && !Settings.SHOW_OWN_NAME) offset -= .3;
                if (Hyperium.INSTANCE.getCosmetics().getDeadmau5Cosmetic().isPurchasedBy(event.getEntity().getUniqueID())) {
                    HyperiumPurchase packageIfReady = PurchaseApi.getInstance().getPackageIfReady(event.getEntity().getUniqueID());
                    if (packageIfReady != null) {
                        AbstractHyperiumPurchase purchase = packageIfReady.getPurchase(EnumPurchaseType.DEADMAU5_COSMETIC);
                        if (purchase != null) {
                            if (event.getEntity().getUniqueID() != Minecraft.getMinecraft().thePlayer.getUniqueID()) {
                                if (((EarsCosmetic) purchase).isEnabled()) {
                                    offset += .3;
                                }
                            } else if (Settings.EARS_STATE.equalsIgnoreCase("on")) {
                                offset += .2;
                            }
                        }
                    }
                }

                offset += levelhead.getDisplayManager().getMasterConfig().getOffset();
                renderName(event, levelheadTag, player, event.getX(), event.getY() + offset + o * .3D, event.getZ());
            }
        }

        o++;
    }
}
 
Example #21
Source File: RenderScoreboardEvent.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@NotNull
public final ScoreObjective getObjective() {
    return objective;
}
 
Example #22
Source File: CraftCriteria.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
static CraftCriteria getFromNMS(ScoreObjective objective) {
    return DEFAULTS.get(objective.getCriteria().getName());
}
 
Example #23
Source File: CraftObjective.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
CraftObjective(CraftScoreboard scoreboard, ScoreObjective objective) {
    super(scoreboard);
    this.objective = objective;
    this.criteria = CraftCriteria.getFromNMS(objective);
}
 
Example #24
Source File: CraftObjective.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
ScoreObjective getHandle() {
    return objective;
}
 
Example #25
Source File: IMixinGuiPlayerTabOverlay.java    From Hyperium with GNU Lesser General Public License v3.0 votes vote down vote up
@Invoker void callDrawScoreboardValues(ScoreObjective objective, int p_175247_2_, String name, int p_175247_4_, int p_175247_5_, NetworkPlayerInfo info);