Giter VIP home page Giter VIP logo

protocolsidebar's Introduction

ProtocolSidebar

Powerful feature-packed Minecraft scoreboard library

Build License Nexus Minecraft Versions

Sidebar

Donations

Buy Me a Coffee

Features

  • No flickering (without using a buffer)
  • Does not require any additional libraries/plugins on the server
  • Easy to use
  • Optionally supports Adventure API, MiniMessage, MiniPlaceholders
  • Extremely fast, can be used asynchronously
  • Cool inbuilt animations
  • Inbuilt pager for showing multiple sidebars to the player
  • Automatic score management system: sidebar reorders lines automatically
  • Everything is at the packet level, so it works with other plugins using scoreboard and/or teams
  • Supports up to 30 characters per line on 1.12.2 and below
  • No character limit on 1.13 and higher
  • Supports hex colors on 1.16 and higher
  • Minimized NMS interaction, means that packets are constructed at the byte buffer level and then sent directly to the player's channel.

Adding To Your Project

Instead of manually bundling the library into your JAR file, you can use the standalone plugin.

Simply run ./gradlew clean shadowJar and put the resulting JAR file located in bin folder into your plugins folder.

In other cases, you must use something like shadow (for Gradle) or maven-shade-plugin (for Maven).

Maven

<repository>
    <id>sonatype-snapshots</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<dependency>
    <groupId>me.catcoder</groupId>
    <artifactId>bukkit-sidebar</artifactId>
    <version>6.2.6-SNAPSHOT</version>
</dependency>

Gradle

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
    implementation 'me.catcoder:bukkit-sidebar:6.2.6-SNAPSHOT'
}

Gradle (Kotlin DSL)

repositories {
    maven("https://oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
    implementation("me.catcoder:bukkit-sidebar:6.2.6-SNAPSHOT")
}

Basic Usage

// create sidebar which uses Adventure API
// you can also use other methods from ProtocolSidebar class
// for another text providers such as BungeeCord Chat, MiniMessage...
Sidebar<Component> sidebar = ProtocolSidebar.newAdventureSidebar(
        TextIterators.textFadeHypixel("SIDEBAR"), this);

// let's add some lines
sidebar.addLine(
    Component.text("Just a static line").color(NamedTextColor.GREEN));
// add an empty line
sidebar.addBlankLine();
// also you can add updatable lines which applies to all players receiving this sidebar
sidebar.addUpdatableLine(
    player -> Component.text("Your Hunger: ")
        .append(Component.text(player.getFoodLevel())
        .color(NamedTextColor.GREEN))
    );

sidebar.addBlankLine();
sidebar.addUpdatableLine(
    player -> Component.text("Your Health: ")
        .append(Component.text(player.getHealth())
        .color(NamedTextColor.GREEN))
);
sidebar.addBlankLine();
sidebar.addLine(
    Component.text("https://github.com/CatCoderr/ProtocolSidebar")
        .color(NamedTextColor.YELLOW
));

// update all lines except static ones every 10 ticks
sidebar.updateLinesPeriodically(0, 10);

// ...

// show to the player
sidebar.addViewer(player);
// ...hide from the player
sidebar.removeViewer(player);

Example

Conditional Lines

The visibility of these lines depends on the condition you set. If the condition is true, the line will be shown, otherwise it will be hidden. It's an updatable line, so it will update along with other updatable lines.

Score number formatting

You can use scoreNumberFormat method in both ScoreboardObjective and SidebarLine classes to format score numbers.

This feature is available starting from 1.20.4 version.

// removes scores completely for all lines
sidebar.getObjective().scoreNumberFormatBlank();
// set's custom fixed text for all lines
sidebar.getObjective().scoreNumberFormatFixed(player -> Component.text("Test").color(NamedTextColor.BLUE));

// set's score number format for specific line (overrides objective's format)
var line = sidebar.addLine(Component.text("Some line").color(NamedTextColor.YELLOW));
line.scoreNumberFormatFixed(player -> Component.text("Test").color(NamedTextColor.BLUE));

Sidebar Title Animations

Library has built-in title animations, but you can also create your own. Hypixel-like animation

Animations also can be used in updatable lines:

TextIterator animation = TextIterators.textFadeHypixel("Hello World!");
SidebarLine<?> line = sidebar.addUpdatableLine(sidebar.asLineUpdater(animation));

line.updatePeriodically(0, 1, sidebar);

Sidebar Pager

You can also use sidebar pager, which allows you to show player multiple pages of information.

Sidebar<Component> anotherSidebar = ProtocolSidebar.newAdventureSidebar(
        TextIterators.textFadeHypixel("ANOTHER SIDEBAR"), this);

Sidebar<Component> firstSidebar = ProtocolSidebar.newAdventureSidebar(
        TextIterators.textFadeHypixel("SIDEBAR"), this);

SidebarPager<Component> pager = new SidebarPager<>(
        Arrays.asList(firstSidebar, anotherSidebar), 20 * 5, this);

// add page status line to all sidebars in pager
pager.addPageLine((page, maxPage, sidebar) ->
        sidebar.addLine(Component.text("Page " + page + "/" + maxPage)
            .color(NamedTextColor.GREEN)));

pager.applyToAll(Sidebar::addBlankLine);

// ...add some lines

// show to player
pager.show(player);

// ...
// hide from the player
pager.hide(player);

Pager example

protocolsidebar's People

Contributors

16depression16 avatar 4drian3d avatar catcoderr avatar rchomczyk avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

protocolsidebar's Issues

Метод update не обнавляет значения.

Делаю значит в скорборде отображение префикса, и через шедуляр обновляю через метод update, а оно не обновляется. Только перезаход обновляет

Error when update text animation when a player is quitting

java.lang.RuntimeException: An error occurred while updating sidebar for player: rafalino132
at me.catcoder.sidebar.Sidebar.broadcast(Sidebar.java:459) ~[?:?]
at me.catcoder.sidebar.Sidebar.updateLine(Sidebar.java:312) ~[?:?]
at me.catcoder.sidebar.SidebarLine.lambda$updatePeriodically$0(SidebarLine.java:59) ~[?:?]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[unknown]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:58) ~[unknown]
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[unknown]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: net.kyori.adventure.text.minimessage.internal.parser.ParsingExceptionImpl: Legacy formatting codes have been detected in a MiniMessage string - this is unsupported behaviour. Please refer to the Adventure documentation (https://docs.adventure.kyori.net) for more information.
§9☄ §fdc.mine_
^^

    ProtocolSidebar.newMiniMessageSidebar
    
    TextIterator discordAnimation = TextIterators.textTyping("www.minestar.pl", "_", 1, 5);
    SidebarLine<String> discord = page1.addUpdatableLine(player -> "<color:#8f0555>✉ <color:#FFFFFF>" + page1.toLineUpdater(discordAnimation).apply(player));
    discord.updatePeriodically(1, 5, page1);

NoClassDefFoundError

Spigot version: 1.19.2
ProtocoleSidebar version: 6.1.4

Erreur : NoClassDefFoundError on AdventureLIB/API

java.lang.NoClassDefFoundError: net/kyori/adventure/text/minimessage/MiniMessage

Or again

java.lang.NoClassDefFoundError: net/kyori/adventure/text/serializer/gson/GsonComponentSerializer

[question] per player title

I would like to change the title name to match the player's client language.
Is it possible to change the display of the title for each player?

Can't find dependency when plugin is run in server (NoClassDefFoundError)

I've tried for a few hours to get a plugin to run with multiple versions of this api. I want to use it so badly because it looks so cool and simple, but I can't get past this part. I've even tried bundling it with my jar. I've tried multiple versions of minecraft and multiple versions of Paper. No luck. I can see the dependency in Intellij, code completion happens and I can even ctrl+click into the classes. But when I build the plugin and deploy it to the server, I get the error below:

java.lang.NoClassDefFoundError: me/catcoder/sidebar/ProtocolSidebar
        at org.braekpo1nt.mctmanager.games.footrace.FootRaceGame.<init>(FootRaceGame.java:67) ~[MCTManager-0.1.0-0.jar:?]
        at org.braekpo1nt.mctmanager.games.GameManager.<init>(GameManager.java:43) ~[MCTManager-0.1.0-0.jar:?]
        at org.braekpo1nt.mctmanager.Main.onEnable(Main.java:47) ~[MCTManager-0.1.0-0.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:371) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:544) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:578) ~[paper-1.19.3.jar:git-Paper-384]
        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugins(CraftServer.java:492) ~[paper-1.19.3.jar:git-Paper-384]
        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.reload(CraftServer.java:1038) ~[paper-1.19.3.jar:git-Paper-384]
        at org.bukkit.Bukkit.reload(Bukkit.java:930) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.3.jar:git-Paper-384]
        at org.bukkit.craftbukkit.v1_19_R2.CraftServer.dispatchServerCommand(CraftServer.java:892) ~[paper-1.19.3.jar:git-Paper-384]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:494) ~[paper-1.19.3.jar:git-Paper-384]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:441) ~[paper-1.19.3.jar:git-Paper-384]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.3.jar:git-Paper-384]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1173) ~[paper-1.19.3.jar:git-Paper-384]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316) ~[paper-1.19.3.jar:git-Paper-384]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassNotFoundException: me.catcoder.sidebar.ProtocolSidebar
        at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:177) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:124) ~[paper-api-1.19.3-R0.1-SNAPSHOT.jar:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        ... 20 more

1.20.6 packet changes makes kick occur

1.20.6 has changed some packets probably. Kick message mentions the packet set_experience.

Internal Exception: io.netty.handler.codec.DecoderException: Java.io.IOException: Packet play/clientbound/minecraft:set_experience (afr) was larger than I expected, found 63 bytes extra whilst reading packet clientbound/minecraft:set_experience

On experimental paper 1.20.6 build 36

(Issue similar to 1.20.4 issues from a couple months back)

NullPointer exception in pager

Null pointer exception when join two players on the server:

Stacktrace:
java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1597) ~[?:?]
at java.util.HashMap$KeyIterator.next(HashMap.java:1620) ~[?:?]
at me.catcoder.sidebar.Sidebar.removeViewers(Sidebar.java:347) ~[GreenLibrary-1.0.0.b57.jar:?]
at me.catcoder.sidebar.pager.SidebarPager.switchPage(SidebarPager.java:51) ~[GreenLibrary-1.0.0.b57.jar:?]
at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.19.2.jar:git-Paper-307]
at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[paper-1.19.2.jar:git-Paper-307]
at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1473) ~[paper-1.19.2.jar:git-Paper-307]
at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:446) ~[paper-1.19.2.jar:git-Paper-307]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.2.jar:git-Paper-307]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1173) ~[paper-1.19.2.jar:git-Paper-307]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-307]
at java.lang.Thread.run(Thread.java:833) ~[?:?]

i'm use a this code:
BoardStorage.pager = new SidebarPager<>(
BoardStorage.sidebars, 20L * settings.getPageShowTime(), instance
);

Then:
public static void show (Player player) {
if (pager != null) {
pager.show(player);
}
}

1.20.4 implementation of Score and Objective packets

I am using the ProtocolSidebar 6.2.5 Snapshot to create a pager that updates every x seconds. MC 1.20.4 has unfortunately broken something. A player kick occurs with no further stack trace or text in either the server console or minecraft client log.
image
I've singled the issue out to somewhere in the class where I show the pager, probably on the pager.show() statement.
As soon as this code is reached, the corresponding player is kicked (haven't tested with multiple players) with the following message.
For further invenstigation, this is the method where I call pager.show().
The following simplified method gets called every x seconds, or on plugin start. (for full class - here)

public void refreshLeaderboard() {
        Set<Player> players = PlayerUtils.getPlayersInWorld(plugin.getConfig().getString("world"));

        List<String> enabled = plugin.getConfig().getStringList("enabled-slides");

        ArrayList<Sidebar<Component>> enabledSidebars = new ArrayList<>();

        Component titleComponent = LanguageConfig.lang.get("SCOREBOARD_MAIN_TITLE");

        Sidebar<Component> personalStatsSidebar = ProtocolSidebar.newAdventureSidebar(titleComponent, plugin);
                    enabledSidebars.add(personalStatsSidebar);

        long period = plugin.getConfig().getInt("scoreboard-period") * 20L;
        SidebarPager<Component> pager = new SidebarPager<>(
                enabledSidebars, period, plugin);

        for (Player player : players){
            pager.show(player); // **Probably cause of kick**
            if (!(plugin.getConfig().getBoolean("scoreboard-enabled"))){
                pager.hide(player);
            }
        }

        new BukkitRunnable() {
            @Override
            public void run() {
                if (plugin.getConfig().getBoolean("scoreboard-enabled")){
                    refreshLeaderboard();
                }
                pager.destroy();
            }
        }.runTaskLater(plugin, period * 2);
    }

Using latest experimental paper build 1.20.4 Build #326

Add support for 1.20.3 number formatting

Minecraft 1.20.3 added a few new scoreboard features:

  1. The ability to give a player a sort of "nickname" in the scoreboard, the vanilla command is as follows:
    "/scoreboard players display name "
    and reset:
    "/scoreboard players display name "

  2. The ability to modify the "score" as blank or as a string/format
    vanilla commands:
    "/scoreboard players display numberformat "
    "/scoreboard objectives modify numberformat "
    and reset:
    "/scoreboard players display numberformat "
    "/scoreboard objectives modify numberformat"

Number formats:

styled <style>
The score will be displayed with the selected style (e.g.
{"bold":true}

fixed
The score is replaced by the given text component.

blank
The score is not shown.

This Pull Request implements it in another Scoreboard API if it helps

Thank you for your consideration

When the sidebar is displayed, players will not be able to join the server.

I use SideBar to display scores for fishing competitions.
When I display the SideBar, the server kicks me and I cannot join the server.
image

log

[20:00:07] [Server thread/INFO]: [ProtocolSidebar] Server version: (MC: 1.20.2) (protocol 763)
[20:00:07] [Server thread/INFO]: [ProtocolSidebar] Please report any bugs to the developer: https://github.com/CatCoderr/ProtocolSidebar/issues
[20:00:07] [Server thread/INFO]: 🎣 この大会は10分0秒あるよ!
[20:00:07] [Server thread/INFO]: Kazane_1210 lost connection: Disconnected
[20:00:07] [Server thread/INFO]: namanamayan lost connection: Disconnected
[20:00:07] [Server thread/INFO]: Kafilistan lost connection: Disconnected

code
https://github.com/NamiUni/more-fish/blob/rewrite/src/main/java/com/github/namiuni/morefish/competition/CompetitionSideBar.java

"Packet 0/84 (yl) was larger that I expected"

Hello,

While using this API in 1.19.4, with the correct ProtocolLib version (#618) I can not join my server because of an error related to packets. I am not getting any errors in the console, only in the Minecraft Client.
I will leave a screenshot of this error below:

Error

Thank you,
Joseda.

Move on from ProtocolLib 📌

Currently, we use ProtocolLib in the library in two places: sending raw packets as byte buffers and retrieving the current protocol version of the Minecraft server.

We plan to replace wire packets with Netty ByteBufs and use some reflection hacks to send them directly to the player's channel. As for retrieving the version, we will parse the version of Bukkit and match its protocol version, as ProtocolLib currently does.

It can be done without significant breaking changes, as all protocol-related functionality is behind the API area.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
server/docker-compose.yaml
github-actions
.github/workflows/build.yaml
  • actions/checkout v4
  • actions/setup-java v3
gradle
settings.gradle.kts
build.gradle.kts
  • io.github.gradle-nexus.publish-plugin 1.3.0
  • junit:junit 4.13.2
  • org.mockito:mockito-core 5.7.0
  • org.powermock:powermock-module-junit4 2.0.9
  • org.powermock:powermock-api-mockito2 2.0.9
  • io.papermc.paper:paper-api 1.20.1-R0.1-SNAPSHOT
  • com.github.steveice10:opennbt 1.6
  • org.projectlombok:lombok 1.18.30
  • com.viaversion:viaversion-bukkit 4.8.1
  • io.netty:netty-buffer 4.1.101.Final
  • io.netty:netty-handler 4.1.101.Final
  • io.github.miniplaceholders:miniplaceholders-api 2.2.3
  • net.kyori:adventure-api 4.16.0
  • net.kyori:adventure-text-minimessage 4.16.0
  • net.kyori:adventure-text-serializer-gson 4.16.0
  • net.kyori:adventure-text-serializer-legacy 4.16.0
standalone-plugin/build.gradle.kts
  • com.github.johnrengelman.shadow 8.1.1
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.4

  • Check this box to trigger a request for Renovate to run again on this repository

Добавь WrappedChatComponent

Привет! Приятно было узнать, что такую красоту написал наш земляк. Беда в том, что использовать коды форматирования уже не канон, майнкрафт перешёл на json. Очень хотелось бы поддержку wrappedChatComponent в линиях скорборда.

[SUGGESTION] Add new type of lines which their visibility depends on something

Hello,
It would be amazing if you could add a new type of line to the API. This new type will only be visible if a condition is met. For example, if you are in a team, a new line (which couldn't be seen before) in the scoreboard would appear telling you your team, and when you leave the team, that line will disappear again making the scoreboard smaller.
I don't mean a line that would just be an empty space and then when the condition is met, some text appears, but rather a line that does not exist visually in the scoreboard, and when it appears, the scoreboard would be made bigger, and when it disappears, the scoreboard would be made smaller again.

Thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.