net.minecraft.scoreboard.Scoreboard Java Examples

The following examples show how to use net.minecraft.scoreboard.Scoreboard. 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: 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 #3
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 #4
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 #5
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 #6
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 #7
Source File: CraftScoreboardTranslations.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
static int fromBukkitSlot(DisplaySlot slot) {
    return Scoreboard.getObjectiveDisplaySlotNumber(SLOTS.get(slot));
}
 
Example #8
Source File: CraftScoreboardTranslations.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
static DisplaySlot toBukkitSlot(int i) {
    return SLOTS.inverse().get(Scoreboard.getObjectiveDisplaySlot(i));
}
 
Example #9
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Scoreboard getHandle() {
    return board;
}
 
Example #10
Source File: CraftScoreboard.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
CraftScoreboard(Scoreboard board) {
    this.board = board;
}
 
Example #11
Source File: CraftScore.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isScoreSet() throws IllegalStateException {
    Scoreboard board = objective.checkState().board;

    return board.getObjectiveNames().contains(entry) && board.getObjectivesForEntity(entry).containsKey(objective.getHandle());
}
 
Example #12
Source File: SkyblockAddonsCommand.java    From SkyblockAddons with MIT License 4 votes vote down vote up
/**
 * Opens the main gui, or locations gui if they type /sba edit
 */
@Override
public void processCommand(ICommandSender sender, String[] args) {
    if (args.length > 0) {
        if (args[0].equalsIgnoreCase("edit")) {
            main.getUtils().setFadingIn(false);
            main.getRenderListener().setGuiToOpen(EnumUtils.GUIType.EDIT_LOCATIONS, 0, null);

        } else if (args[0].equalsIgnoreCase("dev") || args[0].equalsIgnoreCase("nbt")) {
            main.setDevMode(!main.isDevMode());

            if (main.isDevMode()) {
                main.getUtils().sendMessage(ChatFormatting.GREEN + "Developer mode enabled! TIP: Press right ctrl to copy nbt!");
            } else {
                main.getUtils().sendMessage(ChatFormatting.RED + "Developer mode disabled!");
            }
        } else if (args[0].equalsIgnoreCase("set")) {
            Integer number = null;
            if (args.length >= 3) {
                try {
                    number = Integer.parseInt(args[2]);
                } catch (NumberFormatException ex) {
                    main.getUtils().sendErrorMessage("Invalid number to set!");
                    return;
                }
            }
            if (number == null) {
                main.getUtils().sendErrorMessage("Invalid number to set!");
                return;
            }

            if (args[1].equalsIgnoreCase("totalzealots") || args[1].equalsIgnoreCase("total")) {
                main.getPersistentValues().setTotalKills(number);
                main.getUtils().sendMessage("Set total zealot count to: "+number+"!");
            } else if (args[1].equalsIgnoreCase("zealots")) {
                main.getPersistentValues().setKills(number);
                main.getUtils().sendMessage("Set current zealot count to: "+number+"!");
            } else if (args[1].equalsIgnoreCase("eyes")) {
                main.getPersistentValues().setSummoningEyeCount(number);
                main.getUtils().sendMessage("Set total summoning eye count to: "+number+"!");
            } else {
                main.getUtils().sendErrorMessage("Invalid selection! Please choose 'zealots', 'totalzealots/total', 'eyes'");
            }
        }  else if (args[0].equalsIgnoreCase("folder")) {
            try {
                Desktop.getDesktop().open(main.getUtils().getSBAFolder());
            } catch (IOException e) {
                logger.catching(e);
                main.getUtils().sendErrorMessage("Failed to open mods folder.");
            }
        }  else if (args[0].equalsIgnoreCase("warp")) {
            main.getRenderListener().setGuiToOpen(EnumUtils.GUIType.WARP);
        } else if (main.isDevMode()) {
            if (args[0].equalsIgnoreCase("sidebar")) {
                Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard();

                if (args.length < 2) {
                    DevUtils.copyScoreboardSideBar(scoreboard);

                } else if (args.length == 2 && args[1].equalsIgnoreCase("formatted")) {
                    DevUtils.copyScoreboardSidebar(scoreboard, false);

                } else {
                    main.getUtils().sendMessage(getCommandUsage(sender), false);
                }
            } else if (args[0].equalsIgnoreCase("brand")) {
                main.getUtils().sendMessage(DevUtils.getServerBrand(Minecraft.getMinecraft()));

            } else {
                main.getUtils().sendMessage(getCommandUsage(sender), false);
            }
        } else {
            main.getUtils().sendMessage(getCommandUsage(sender), false);
        }
    } else {
        // If there's no arguments given, open the main GUI
        main.getUtils().setFadingIn(true);
        main.getRenderListener().setGuiToOpen(EnumUtils.GUIType.MAIN, 1, EnumUtils.GuiTab.MAIN);
    }
}
 
Example #13
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 #14
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 #15
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 #16
Source File: HyperiumScoreboard.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public HyperiumScoreboard(Scoreboard parent) {
    this.parent = parent;
}
 
Example #17
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 #18
Source File: DevUtils.java    From SkyblockAddons with MIT License 2 votes vote down vote up
/**
 * Copies the objective and scores that are being displayed on a scoreboard's sidebar.
 * When copying the sidebar, the control codes (e.g. §a) are removed.
 *
 * @param scoreboard the {@link Scoreboard} to copy the sidebar from
 */
public static void copyScoreboardSideBar(Scoreboard scoreboard) {
    copyScoreboardSidebar(scoreboard, true);
}