Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ef53fc36c | ||
|
|
774ab670c9 | ||
|
|
30641a8c15 | ||
|
|
01e1374db6 | ||
|
|
db58aa35c5 | ||
|
|
35a0565cd1 | ||
|
|
6fab408824 | ||
|
|
b0d6903262 | ||
|
|
acd64b884e | ||
|
|
70eb07c25d | ||
|
|
50d567a4af | ||
|
|
97cd00b598 | ||
|
|
bf0529a11e | ||
|
|
1b752a0694 | ||
|
|
5f093db220 | ||
|
|
651f5b24b7 | ||
|
|
e35fb3503c | ||
|
|
14e16b95a0 | ||
|
|
b30ea7dc44 | ||
|
|
8e09c6d1c1 | ||
|
|
8aa61448e4 | ||
|
|
3762419bc5 | ||
|
|
53bea167d7 | ||
|
|
5eaa7f3c07 | ||
|
|
699cbacf6e | ||
|
|
e6fdd5e513 | ||
|
|
a95c879d10 | ||
|
|
4f6d1dc5b1 | ||
|
|
5c0709a8c4 | ||
|
|
d5c61dc156 | ||
|
|
5466140dc4 | ||
|
|
cc13241968 | ||
|
|
16592c2815 | ||
|
|
8c09c0e97c | ||
|
|
0bbc487f88 | ||
|
|
0cbd54f8f1 | ||
|
|
0551a8f978 | ||
|
|
dd65c812d2 | ||
|
|
a88394223b | ||
|
|
0e579e603a | ||
|
|
71aaa7ac50 | ||
|
|
8521d1deec | ||
|
|
9c1a121e09 | ||
|
|
7f3651d4bf | ||
|
|
2e06fc1d34 | ||
|
|
cb391dd676 | ||
|
|
a36a8c3fd2 | ||
|
|
4f3cf55c01 | ||
|
|
422a36a284 | ||
|
|
a2e5df14e6 | ||
|
|
521bc47dd0 | ||
|
|
09dc3a653d | ||
|
|
b5181d0d81 | ||
|
|
f01f4fd831 | ||
|
|
778b479b91 | ||
|
|
7a1c47045b | ||
|
|
e2c8ff5eb8 | ||
|
|
af426bdfbc | ||
|
|
641223e1f5 | ||
|
|
cf8fa59c86 | ||
|
|
96595d0a41 | ||
|
|
ba6bff7ed1 | ||
|
|
0f96547b37 | ||
|
|
5d02fd625b | ||
|
|
fed9f4c64b | ||
|
|
0c3f942757 | ||
|
|
c1c9d7258b | ||
|
|
93cd55a626 | ||
|
|
0d979d6922 | ||
|
|
cf6b51be40 | ||
|
|
c1199432eb | ||
|
|
bccc777541 | ||
|
|
d14ca9470a | ||
|
|
1889b84373 | ||
|
|
bf629bd7de | ||
|
|
690905774e | ||
|
|
40a35272ff | ||
|
|
f9fdc13443 | ||
|
|
bdce2423b1 | ||
|
|
4955c839a8 | ||
|
|
9b198da189 | ||
|
|
32409d589c | ||
|
|
e016b43822 | ||
|
|
17137a88c4 | ||
|
|
4369acd756 | ||
|
|
4fa40ed032 | ||
|
|
3bf91896b0 | ||
|
|
b71d555391 | ||
|
|
25f236344f | ||
|
|
01d8ef9b29 | ||
|
|
98917376d0 | ||
|
|
cd0607a72c | ||
|
|
8ba9ef40da | ||
|
|
3be7b09631 | ||
|
|
079e867325 | ||
|
|
c9a3c6b3f5 | ||
|
|
f8f542e739 | ||
|
|
fca17dbda4 | ||
|
|
9a77454a9e | ||
|
|
2d30af76f3 | ||
|
|
59198fb117 | ||
|
|
022968489c | ||
|
|
afd64f4fd2 | ||
|
|
d4c553f93f | ||
|
|
3f37335bac | ||
|
|
deaf231965 | ||
|
|
d15ac8c2e8 | ||
|
|
8408a3e279 | ||
|
|
c2ce803f30 | ||
|
|
5f89a47798 | ||
|
|
4d23bc5cfd | ||
|
|
d26eab2110 | ||
|
|
c0a6ec0ec1 | ||
|
|
20245b870f | ||
|
|
715c28732e | ||
|
|
408a379bfe | ||
|
|
caeb7286a8 | ||
|
|
0452126353 | ||
|
|
d8d6ba3a11 | ||
|
|
30b52722cd | ||
|
|
4ad96a9a79 | ||
|
|
5524dd399f | ||
|
|
17ba876a7a | ||
|
|
4e7b21f0ca | ||
|
|
25df9e7262 | ||
|
|
d547387245 | ||
|
|
9fc2c23a9d | ||
|
|
2f07a0e68d | ||
|
|
78442b652c | ||
|
|
57e8470cc7 | ||
|
|
ee16d324e1 | ||
|
|
b0ec7d2d97 | ||
|
|
1c4ec63eea | ||
|
|
8ec3e1082d | ||
|
|
bdbbf155e7 | ||
|
|
40c7fe49be | ||
|
|
3a0b0c1d94 | ||
|
|
226f39ee27 | ||
|
|
8c00d11070 | ||
|
|
f809416599 | ||
|
|
da176b8ea4 | ||
|
|
77dd1b8c65 | ||
|
|
736199d58f | ||
|
|
c2c1977885 | ||
|
|
045b558548 | ||
|
|
34f78377d9 | ||
|
|
f2bb69bd23 | ||
|
|
e2c4b6708e | ||
|
|
e957539c0d | ||
|
|
0f2f3ba432 | ||
|
|
7cf57c471f | ||
|
|
ceabb2edc8 | ||
|
|
7d12c7aa5d | ||
|
|
c3f398ae88 | ||
|
|
ebbb902343 | ||
|
|
ee418c87fd | ||
|
|
fcd8b81a8f | ||
|
|
fbe3d1c6cf | ||
|
|
ab7f574c14 | ||
|
|
b2c756c2cb | ||
|
|
8b930bfe13 | ||
|
|
07d868e180 | ||
|
|
b98e1f007b | ||
|
|
563f132528 | ||
|
|
eccc236d5d | ||
|
|
cc73eea58d | ||
|
|
8b88a58668 | ||
|
|
c2c30b33d7 |
No files matched your search
+16
-16
@@ -1,24 +1,24 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: cachix/install-nix-action@v30
|
||||
- name: Cache Gradle
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
- name: Build the project
|
||||
uses: gradle/gradle-build-action@v2.4.2
|
||||
with:
|
||||
arguments: build
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
- name: ./gradlew build
|
||||
run: nix develop -i -c sh -c "./gradlew build"
|
||||
+6
-1
@@ -2,4 +2,9 @@
|
||||
*.iml
|
||||
|
||||
.gradle
|
||||
build/
|
||||
build/
|
||||
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
bin/
|
||||
+23
-38
@@ -1,39 +1,34 @@
|
||||
# Installation
|
||||
|
||||
Latest version: `2.0.0`
|
||||
Latest version: `2.2.2`
|
||||
|
||||
## Gradle
|
||||
|
||||
Make sure you have the Jitpack repository:
|
||||
|
||||
```kotlin
|
||||
repositories {
|
||||
maven("https://jitpack.io/")
|
||||
mavenCentral()
|
||||
}
|
||||
```
|
||||
|
||||
Then add the dependencies:
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
val scoreboardLibraryVersion = "{VERSION HERE}"
|
||||
implementation("com.github.megavexnetwork.scoreboard-library:scoreboard-library-api:$scoreboardLibraryVersion")
|
||||
runtimeOnly("com.github.megavexnetwork.scoreboard-library:scoreboard-library-implementation:$scoreboardLibraryVersion")
|
||||
implementation("com.github.megavexnetwork.scoreboard-library:scoreboard-library-extra-kotlin:$scoreboardLibraryVersion") // If using Kotlin
|
||||
implementation("net.megavex:scoreboard-library-api:$scoreboardLibraryVersion")
|
||||
runtimeOnly("net.megavex:scoreboard-library-implementation:$scoreboardLibraryVersion")
|
||||
implementation("net.megavex:scoreboard-library-extra-kotlin:$scoreboardLibraryVersion") // Kotlin specific extensions (optional)
|
||||
|
||||
// Add packet adapter implementations you want:
|
||||
runtimeOnly("com.github.megavexnetwork.scoreboard-library:scoreboard-library-modern:$scoreboardLibraryVersion") // 1.17+
|
||||
runtimeOnly("com.github.megavexnetwork.scoreboard-library:scoreboard-library-packetevents:$scoreboardLibraryVersion") // 1.8+
|
||||
runtimeOnly("com.github.megavexnetwork.scoreboard-library:scoreboard-library-v1_8_R3:$scoreboardLibraryVersion") // 1.8
|
||||
runtimeOnly("net.megavex:scoreboard-library-modern:$scoreboardLibraryVersion") // 1.17+
|
||||
runtimeOnly("net.megavex:scoreboard-library-modern:$scoreboardLibraryVersion:mojmap") // Mojang mapped variant (only use if you know what you're doing!)
|
||||
runtimeOnly("net.megavex:scoreboard-library-packetevents:$scoreboardLibraryVersion") // 1.8+
|
||||
runtimeOnly("net.megavex:scoreboard-library-legacy:$scoreboardLibraryVersion") // 1.7.10-1.12.2
|
||||
|
||||
// If using the PacketEvents implementation, scoreboard-library expects PacketEvents to be in the classpath.
|
||||
// Follow either of:
|
||||
// - https://github.com/retrooper/packetevents/wiki/Depending-on-pre-built-PacketEvents
|
||||
// - https://github.com/retrooper/packetevents/wiki/Depending-on-pre%E2%80%90built-PacketEvents
|
||||
// - https://github.com/retrooper/packetevents/wiki/Shading-PacketEvents
|
||||
// Example how to load PacketEvents in your plugin:
|
||||
// https://github.com/retrooper/packetevents-example/blob/24f0c842d47362aef122b794dea29b8fee113fa3/thread-safe-listener/src/main/java/main/Main.java
|
||||
|
||||
// If using the 1.8 version implementation, add Adventure as well:
|
||||
// If targeting a Minecraft version without native Adventure support, add it as well:
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.0.1")
|
||||
}
|
||||
```
|
||||
@@ -43,53 +38,44 @@ like [Shadow](https://imperceptiblethoughts.com/shadow/).
|
||||
|
||||
## Maven
|
||||
|
||||
Make sure you have the Jitpack repository:
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
Then add the dependencies:
|
||||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-api</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-implementation</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- If using Kotlin: -->
|
||||
<!-- Kotlin specific extensions (optional) -->
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-extra-kotlin</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Add packet adapter implementations you want: -->
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-modern</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
<scope>runtime</scope>
|
||||
<!-- For a Mojang mapped variant, uncomment line below (only use if you know what you're doing!): -->
|
||||
<!-- <classifier>mojmap</classifier> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-packetevents</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.megavexnetwork.scoreboard-library</groupId>
|
||||
<artifactId>scoreboard-library-v1_8_R3</artifactId>
|
||||
<groupId>net.megavex</groupId>
|
||||
<artifactId>scoreboard-library-legacy</artifactId>
|
||||
<version>{VERSION HERE}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
@@ -103,7 +89,7 @@ Then add the dependencies:
|
||||
https://github.com/retrooper/packetevents-example/blob/24f0c842d47362aef122b794dea29b8fee113fa3/thread-safe-listener/src/main/java/main/Main.java
|
||||
-->
|
||||
|
||||
<!-- If using the 1.8 version implementation, add Adventure as well: -->
|
||||
<!-- If targeting a Minecraft version without native Adventure support, add it as well: -->
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
@@ -112,5 +98,4 @@ Then add the dependencies:
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
You will need to shade these dependencies and relocate them with something
|
||||
like [maven-shade-plugin](https://maven.apache.org/plugins/maven-shade-plugin/).
|
||||
You will need to shade these dependencies and relocate them with [maven-shade-plugin](https://maven.apache.org/plugins/maven-shade-plugin/).
|
||||
@@ -8,25 +8,27 @@ Join the [Discord](https://discord.gg/v7nmTDTW8W) or create an issue for support
|
||||
|
||||
## Features
|
||||
|
||||
- Sidebars. Up to 42 characters (depends on the formatting) for 1.12.2 and below, no limit for newer versions
|
||||
- Sidebars. Up to 42 characters (depends on the formatting) for 1.12.2-, no limit for newer versions
|
||||
- Teams. Supports showing different properties (display name, prefix, entries etc.) of the same team to different
|
||||
players
|
||||
- Objectives.
|
||||
- Doesn't require extra dependencies (assuming you're targeting the latest version of Paper)
|
||||
- Packet-level, meaning it works with other scoreboard plugins (and is faster)
|
||||
- Full support for new 1.20.4 features (score display names, custom score formats)
|
||||
- Doesn't require extra dependencies (assuming you're targeting modern versions of Paper)
|
||||
- Packet-level, meaning it works with other scoreboard plugins
|
||||
- Supports [Folia](https://github.com/PaperMC/Folia)
|
||||
- Fully async. All packet work is done asynchronously so you can (but don't have to) use the library from the main
|
||||
- Fully async. All packet work is done asynchronously, so you can use the library from the main
|
||||
thread without sacrificing any performance
|
||||
- Works with `TranslatableComponent`s, meaning all components are automatically translated using `GlobalTranslator` for
|
||||
each players client locale (and automatically update whenever the player changes it in their settings)
|
||||
- Automatically works with `TranslatableComponent`s. All components are translated using `GlobalTranslator` for
|
||||
each player's client locale and automatically update whenever the player changes it in their settings
|
||||
|
||||
## Packet Adapters
|
||||
## Available Packet Adapters
|
||||
|
||||
- **modern.** Supports 1.17-1.20.2. Takes advantage of [Paper](https://papermc.io)'s native adventure support to improve
|
||||
performance. [Spigot](https://www.spigotmc.org/) is also supported, but will have worse performance
|
||||
- **PacketEvents.** Requires [PacketEvents 2.0](https://github.com/retrooper/packetevents/tree/2.0) to be loaded in the
|
||||
classpath. Should work on all versions 1.8+
|
||||
- **1.8.8.**
|
||||
- **modern.** Supports 1.17-1.21.4. Can take advantage of [Paper](https://papermc.io)'s native adventure support to be more efficient.
|
||||
- **legacy.** Supports 1.7.10-1.12.2.
|
||||
- **PacketEvents.** Supports 1.8+. Requires [PacketEvents 2.0](https://github.com/retrooper/packetevents/tree/2.0) to be shaded or installed as a plugin.
|
||||
|
||||
> [!NOTE]
|
||||
> You can add multiple packet adapters, the best one will automatically be picked depending on the server version.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -41,6 +43,7 @@ try {
|
||||
} catch (NoPacketAdapterAvailableException e) {
|
||||
// If no packet adapter was found, you can fallback to the no-op implementation:
|
||||
scoreboardLibrary = new NoopScoreboardLibrary();
|
||||
plugin.getLogger().warning("No scoreboard packet adapter available!");
|
||||
}
|
||||
|
||||
// On plugin shutdown:
|
||||
@@ -66,8 +69,7 @@ sidebar.line(3, Component.text("epicserver.net"));
|
||||
|
||||
sidebar.addPlayer(player); // Add the player to the sidebar
|
||||
|
||||
// After you've finished using the Sidebar, make sure to close it to prevent a memory leak:
|
||||
sidebar.close();
|
||||
// Don't forget to call sidebar.close() once you don't need it anymore!
|
||||
```
|
||||
|
||||
### Component sidebars
|
||||
@@ -262,8 +264,7 @@ newTeamDisplay.displayName(Component.text("Other Team Display Name"));
|
||||
// Change the TeamDisplay a player sees like this:
|
||||
team.display(player, newTeamDisplay);
|
||||
|
||||
// After you've finished using the TeamManager, make sure to close it to prevent a memory leak:
|
||||
teamManager.close();
|
||||
// Don't forget to call teamManager.close() once you don't need it anymore!
|
||||
```
|
||||
|
||||
### ObjectiveManager
|
||||
@@ -277,6 +278,5 @@ objectiveManager.display(ObjectiveDisplaySlot.belowName(), objective);
|
||||
|
||||
objectiveManager.addPlayer(player); // Make a player see the objectives
|
||||
|
||||
// After you've finished using the ObjectiveManager, make sure to close it to prevent a memory leak:
|
||||
objectiveManager.close();
|
||||
// Don't forget to call objectiveManager.close() once you don't need it anymore!
|
||||
```
|
||||
@@ -1,3 +1,3 @@
|
||||
plugins {
|
||||
id("net.megavex.scoreboardlibrary.publish-conventions")
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.megavex.scoreboardlibrary.api;
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.exception.NoPacketAdapterAvailableException;
|
||||
import net.megavex.scoreboardlibrary.api.noop.NoopScoreboardLibrary;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveManager;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -14,18 +16,17 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Allows creating {@link Sidebar}s and {@link TeamManager}s.
|
||||
* Each plugin should have it's own instance of this interface.
|
||||
* Note: this class is thread-safe.
|
||||
* Entrypoint of the library. To create an instance of this interface, use {@link #loadScoreboardLibrary}.
|
||||
* For unit testing, take a look at {@link NoopScoreboardLibrary}.
|
||||
* Note: this class is thread-safe, meaning you can safely use it from multiple threads at a time.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface ScoreboardLibrary {
|
||||
/**
|
||||
* Creates an instance of {@link ScoreboardLibrary}.
|
||||
*
|
||||
* @param plugin The plugin that owns this instance
|
||||
* @return A new instance of {@link ScoreboardLibrary}
|
||||
* @throws NoPacketAdapterAvailableException if there is no packet adapter available in the classpath
|
||||
* @param plugin your plugin instance
|
||||
* @throws NoPacketAdapterAvailableException if there is no packet adapter available for the current server version
|
||||
*/
|
||||
static @NotNull ScoreboardLibrary loadScoreboardLibrary(@NotNull Plugin plugin) throws NoPacketAdapterAvailableException {
|
||||
Class<?> implClass;
|
||||
@@ -50,53 +51,58 @@ public interface ScoreboardLibrary {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Sidebar} with max amount of lines set to {@value Sidebar#MAX_LINES} (vanilla limit).
|
||||
* Creates a new {@link Sidebar};
|
||||
*
|
||||
* @return Sidebar
|
||||
* @return newly created sidebar
|
||||
*/
|
||||
default @NotNull Sidebar createSidebar() {
|
||||
return createSidebar(Sidebar.MAX_LINES, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Sidebar}.
|
||||
* Creates a new {@link Sidebar}.
|
||||
*
|
||||
* @param maxLines Max amount of lines the sidebar will have.
|
||||
* Note that vanilla clients can only display {@value Sidebar#MAX_LINES} lines at once
|
||||
* @return Sidebar
|
||||
* @param maxLines max amount of lines the sidebar will have.
|
||||
* Note that vanilla clients can only display at most {@value Sidebar#MAX_LINES}
|
||||
* @return newly created sidebar
|
||||
*/
|
||||
default @NotNull Sidebar createSidebar(@Range(from = 1, to = Integer.MAX_VALUE) int maxLines) {
|
||||
return createSidebar(maxLines, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Sidebar}.
|
||||
* Creates a new {@link Sidebar}.
|
||||
*
|
||||
* @param maxLines Max amount of lines the sidebar will have.
|
||||
* Note that vanilla clients can only display {@value Sidebar#MAX_LINES} lines at once
|
||||
* @param locale Locale which will be used for translating {@link net.kyori.adventure.text.TranslatableComponent}s
|
||||
* @param maxLines max amount of lines the sidebar will have.
|
||||
* Note that vanilla clients can only display at most {@value Sidebar#MAX_LINES}
|
||||
* @param locale locale which will be used for translating {@link net.kyori.adventure.text.TranslatableComponent}s,
|
||||
* or null if the locale should depend on the player
|
||||
* @return Sidebar
|
||||
* @return newly created sidebar
|
||||
*/
|
||||
@NotNull Sidebar createSidebar(@Range(from = 1, to = Sidebar.MAX_LINES) int maxLines, @Nullable Locale locale);
|
||||
@NotNull Sidebar createSidebar(@Range(from = 1, to = Integer.MAX_VALUE) int maxLines, @Nullable Locale locale);
|
||||
|
||||
/**
|
||||
* Creates a {@link TeamManager}.
|
||||
* Creates a new {@link TeamManager}.
|
||||
*
|
||||
* @return TeamManager
|
||||
* @return newly created team manager
|
||||
*/
|
||||
@NotNull TeamManager createTeamManager();
|
||||
|
||||
/**
|
||||
* Creates a new {@link ObjectiveManager}.
|
||||
*
|
||||
* @return newly created objective manager
|
||||
*/
|
||||
@NotNull ObjectiveManager createObjectiveManager();
|
||||
|
||||
/**
|
||||
* Closes this scoreboard-library instance.
|
||||
* Should always be called when the plugin is disabled
|
||||
* Closes this scoreboard library instance.
|
||||
* You should call this in {@link JavaPlugin#onDisable()}.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @return Whether this scoreboard-library instance is closed
|
||||
* @return whether this scoreboard library instance is closed
|
||||
*/
|
||||
boolean closed();
|
||||
}
|
||||
+4
@@ -1,5 +1,9 @@
|
||||
package net.megavex.scoreboardlibrary.api.exception;
|
||||
|
||||
/**
|
||||
* Exception indicating that there is no packet adapter available for the current server version.
|
||||
* As a fallback, consider using the {@link net.megavex.scoreboardlibrary.api.noop.NoopScoreboardLibrary} implementation.
|
||||
*/
|
||||
public final class NoPacketAdapterAvailableException extends Exception {
|
||||
public NoPacketAdapterAvailableException() {
|
||||
}
|
||||
|
||||
@@ -10,13 +10,12 @@ import java.util.*;
|
||||
|
||||
class NoopObjectiveManager implements ObjectiveManager {
|
||||
private final Map<String, ScoreboardObjective> objectives = new HashMap<>();
|
||||
private final Map<ObjectiveDisplaySlot, ScoreboardObjective> displaySlots = new HashMap<>();
|
||||
private final Set<Player> players = new HashSet<>();
|
||||
private boolean isClosed = true;
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective create(@NotNull String name) {
|
||||
return objectives.computeIfAbsent(name, i -> null);
|
||||
return objectives.computeIfAbsent(name, i -> new NoopScoreboardObjective());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,7 +25,6 @@ class NoopObjectiveManager implements ObjectiveManager {
|
||||
|
||||
@Override
|
||||
public void display(@NotNull ObjectiveDisplaySlot displaySlot, @NotNull ScoreboardObjective objective) {
|
||||
displaySlots.put(displaySlot, objective);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,8 +11,9 @@ import org.jetbrains.annotations.Range;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* no-op implementation of ScoreboardLibrary.
|
||||
* No-op implementation of {@link ScoreboardLibrary}.
|
||||
* Can be used as a fallback when there is no packet adapter available
|
||||
* and for unit testing.
|
||||
*/
|
||||
public final class NoopScoreboardLibrary implements ScoreboardLibrary {
|
||||
private boolean closed = false;
|
||||
|
||||
+23
-6
@@ -1,17 +1,24 @@
|
||||
package net.megavex.scoreboardlibrary.api.noop;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreboardObjective;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
public class NoopScoreboardObjective implements ScoreboardObjective {
|
||||
private final Map<String, Integer> scores = new HashMap<>();
|
||||
private Component value;
|
||||
private final Map<String, ObjectiveScore> scores = new HashMap<>();
|
||||
private Component value = empty();
|
||||
private ObjectiveRenderType renderType;
|
||||
private ScoreFormat defaultScoreFormat;
|
||||
|
||||
@Override
|
||||
public @NotNull Component value() {
|
||||
@@ -19,8 +26,8 @@ public class NoopScoreboardObjective implements ScoreboardObjective {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective value(@NotNull Component value) {
|
||||
this.value = value;
|
||||
public @NotNull ScoreboardObjective value(@NotNull ComponentLike value) {
|
||||
this.value = value.asComponent();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -36,12 +43,22 @@ public class NoopScoreboardObjective implements ScoreboardObjective {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer score(@NotNull String entry) {
|
||||
public @Nullable ScoreFormat defaultScoreFormat() {
|
||||
return defaultScoreFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultScoreFormat(@Nullable ScoreFormat defaultScoreFormat) {
|
||||
this.defaultScoreFormat = defaultScoreFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ObjectiveScore scoreInfo(@NotNull String entry) {
|
||||
return scores.get(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective score(@NotNull String entry, int score) {
|
||||
public @NotNull ScoreboardObjective score(@NotNull String entry, ObjectiveScore score) {
|
||||
scores.put(entry, score);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package net.megavex.scoreboardlibrary.api.noop;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import net.megavex.scoreboardlibrary.api.util.SidebarUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -67,15 +68,15 @@ class NoopSidebar implements Sidebar {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void line(int line, @Nullable Component value) {
|
||||
SidebarUtil.checkLineBounds(maxLines, line);
|
||||
public void line(int index, @Nullable ComponentLike value, @Nullable ScoreFormat scoreFormat) {
|
||||
checkLineBounds(index);
|
||||
checkClosed();
|
||||
lines[line] = value;
|
||||
lines[index] = value == null ? null : value.asComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component line(int line) {
|
||||
SidebarUtil.checkLineBounds(maxLines, line);
|
||||
checkLineBounds(line);
|
||||
checkClosed();
|
||||
return lines[line];
|
||||
}
|
||||
@@ -86,10 +87,10 @@ class NoopSidebar implements Sidebar {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void title(@NotNull Component title) {
|
||||
public void title(@NotNull ComponentLike title) {
|
||||
Preconditions.checkNotNull(title);
|
||||
checkClosed();
|
||||
this.title = title;
|
||||
this.title = title.asComponent();
|
||||
}
|
||||
|
||||
private void checkClosed() {
|
||||
@@ -97,4 +98,10 @@ class NoopSidebar implements Sidebar {
|
||||
throw new IllegalStateException("NoopSidebar is closed");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLineBounds(int line) {
|
||||
if (line >= maxLines || line < 0) {
|
||||
throw new IndexOutOfBoundsException("invalid line " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.megavex.scoreboardlibrary.api.noop;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamDisplay;
|
||||
@@ -58,8 +59,8 @@ class NoopTeamDisplay implements TeamDisplay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay displayName(@NotNull Component displayName) {
|
||||
this.displayName = displayName;
|
||||
public @NotNull TeamDisplay displayName(@NotNull ComponentLike displayName) {
|
||||
this.displayName = displayName.asComponent();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -69,8 +70,8 @@ class NoopTeamDisplay implements TeamDisplay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay prefix(@NotNull Component prefix) {
|
||||
this.prefix = prefix;
|
||||
public @NotNull TeamDisplay prefix(@NotNull ComponentLike prefix) {
|
||||
this.prefix = prefix.asComponent();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -80,8 +81,8 @@ class NoopTeamDisplay implements TeamDisplay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay suffix(@NotNull Component suffix) {
|
||||
this.suffix = suffix;
|
||||
public @NotNull TeamDisplay suffix(@NotNull ComponentLike suffix) {
|
||||
this.suffix = suffix.asComponent();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -24,6 +24,9 @@ public interface ObjectiveDisplaySlot {
|
||||
return BelowName.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Minecraft 1.8
|
||||
*/
|
||||
static @NotNull TeamSidebar teamSidebar(@NotNull NamedTextColor teamColor) {
|
||||
Preconditions.checkNotNull(teamColor);
|
||||
return new TeamSidebar(teamColor);
|
||||
|
||||
+32
-21
@@ -1,55 +1,64 @@
|
||||
package net.megavex.scoreboardlibrary.api.objective;
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Manages a group of {@link ScoreboardObjective}s.
|
||||
* Note: this class is not thread-safe.
|
||||
* Represents a group of {@link ScoreboardObjective}s.
|
||||
* To get an instance of this interface, use {@link ScoreboardLibrary#createObjectiveManager()}
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*/
|
||||
public interface ObjectiveManager {
|
||||
/**
|
||||
* Creates an objective
|
||||
* Creates an objective with a name if one doesn't already exist and returns it.
|
||||
*
|
||||
* @param name Name of the objective
|
||||
* @return A newly created objective, or an existing one if the name was already registered
|
||||
* @param name name of the objective
|
||||
* @return objective
|
||||
*/
|
||||
@NotNull ScoreboardObjective create(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Removes an objective.
|
||||
*
|
||||
* @param objective Objective to remove
|
||||
* @param objective objective to remove
|
||||
*/
|
||||
void remove(@NotNull ScoreboardObjective objective);
|
||||
|
||||
/**
|
||||
* Updates the objective shown at a display slot
|
||||
* Updates which objective is shown in a display slot.
|
||||
*
|
||||
* @param displaySlot Display slot value
|
||||
* @param objective Objective to display at that slot
|
||||
* @param displaySlot display slot value to show objective in
|
||||
* @param objective objective to display in that display slot
|
||||
*/
|
||||
void display(@NotNull ObjectiveDisplaySlot displaySlot, @NotNull ScoreboardObjective objective);
|
||||
|
||||
/**
|
||||
* @return Players in this ObjectiveManager
|
||||
* @return unmodifiable collection of viewers in this ObjectiveManager
|
||||
* @see #addPlayer
|
||||
* @see #removePlayer
|
||||
*/
|
||||
@NotNull Collection<Player> players();
|
||||
|
||||
/**
|
||||
* Adds a player to this ObjectiveManager
|
||||
* Adds a viewer to this ObjectiveManager.
|
||||
* Note that a player can only see a single ObjectiveManager at a time.
|
||||
* The ObjectiveManager will internally be added to a queue for this player who
|
||||
* will start seeing it once they are removed from all previous ObjectiveManagers.
|
||||
*
|
||||
* @param player Player to add to ObjectiveManager
|
||||
* @return Whether the player was added
|
||||
* @param player player to add
|
||||
* @return whether the player was added
|
||||
*/
|
||||
boolean addPlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Adds multiple players to this ObjectiveManager
|
||||
* Adds multiple viewers to this ObjectiveManager.
|
||||
*
|
||||
* @param players Players to add
|
||||
* @param players viewers to add
|
||||
* @see #addPlayer
|
||||
*/
|
||||
default void addPlayers(@NotNull Collection<Player> players) {
|
||||
for (Player player : players) {
|
||||
@@ -58,17 +67,17 @@ public interface ObjectiveManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from this ObjectiveManager
|
||||
* Removes a viewer from this ObjectiveManager.
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @return Whether the player was removed
|
||||
* @param player viewer to remove
|
||||
* @return whether the viewer was removed
|
||||
*/
|
||||
boolean removePlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Removes multiple players to this ObjectiveManager
|
||||
* Removes multiple viewers from this ObjectiveManager
|
||||
*
|
||||
* @param players Players to add
|
||||
* @param players viewers to remove
|
||||
*/
|
||||
default void removePlayers(@NotNull Collection<Player> players) {
|
||||
for (Player player : players) {
|
||||
@@ -78,11 +87,13 @@ public interface ObjectiveManager {
|
||||
|
||||
/**
|
||||
* Closes this ObjectiveManager.
|
||||
* This must be called once you no longer need this ObjectiveManager to prevent a memory leak.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @return Whether this ObjectiveManager is closed
|
||||
* @return whether this ObjectiveManager is closed
|
||||
* @see #close
|
||||
*/
|
||||
boolean closed();
|
||||
}
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
package net.megavex.scoreboardlibrary.api.objective;
|
||||
|
||||
/**
|
||||
* Represents all valid render types of an objective.
|
||||
* Represents all possible render types of an objective.
|
||||
* The render type represents the way scores are displayed.
|
||||
*/
|
||||
public enum ObjectiveRenderType {
|
||||
INTEGER,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package net.megavex.scoreboardlibrary.api.objective;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents an objective score.
|
||||
*/
|
||||
public final class ObjectiveScore {
|
||||
private final int value;
|
||||
private final Component displayName;
|
||||
private final ScoreFormat format;
|
||||
|
||||
public ObjectiveScore(int value, @Nullable ComponentLike displayName, @Nullable ScoreFormat format) {
|
||||
this.value = value;
|
||||
this.displayName = displayName == null ? null : displayName.asComponent();
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return score value
|
||||
*/
|
||||
public int value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the score display.
|
||||
*
|
||||
* @return score display
|
||||
* @since Minecraft 1.20.3
|
||||
*/
|
||||
public @Nullable Component displayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the score format, which determines how the scores are rendered in clients.
|
||||
*
|
||||
* @return score format
|
||||
* @since Minecraft 1.20.3
|
||||
*/
|
||||
public @Nullable ScoreFormat format() {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ObjectiveScore{" +
|
||||
"value=" + value +
|
||||
", displayName=" + displayName +
|
||||
", format=" + format +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ObjectiveScore that = (ObjectiveScore) o;
|
||||
|
||||
if (value != that.value) return false;
|
||||
if (!Objects.equals(displayName, that.displayName)) return false;
|
||||
return Objects.equals(format, that.format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = value;
|
||||
result = 31 * result + (displayName != null ? displayName.hashCode() : 0);
|
||||
result = 31 * result + (format != null ? format.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.megavex.scoreboardlibrary.api.objective;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.StyleBuilderApplicable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.format.Style.style;
|
||||
|
||||
/**
|
||||
* Represents all valid objective score formats.
|
||||
*
|
||||
* @since Minecraft 1.20.3
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface ScoreFormat {
|
||||
static @NotNull Blank blank() {
|
||||
return Blank.INSTANCE;
|
||||
}
|
||||
|
||||
static @NotNull Fixed fixed(@NotNull ComponentLike content) {
|
||||
Preconditions.checkNotNull(content);
|
||||
return new Fixed(content.asComponent());
|
||||
}
|
||||
|
||||
static @NotNull Styled styled(@NotNull Style style) {
|
||||
Preconditions.checkNotNull(style);
|
||||
return new Styled(style);
|
||||
}
|
||||
|
||||
static @NotNull Styled styled(@NotNull StyleBuilderApplicable @NotNull ... styleBuilderApplicables) {
|
||||
Preconditions.checkNotNull(styleBuilderApplicables);
|
||||
return new Styled(style(styleBuilderApplicables));
|
||||
}
|
||||
|
||||
class Blank implements ScoreFormat {
|
||||
private static final Blank INSTANCE = new Blank();
|
||||
|
||||
private Blank() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Blank";
|
||||
}
|
||||
}
|
||||
|
||||
class Fixed implements ScoreFormat {
|
||||
private final Component content;
|
||||
|
||||
public Fixed(@NotNull Component content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public @NotNull Component content() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Fixed that = (Fixed) o;
|
||||
return content.equals(that.content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return content.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Fixed{content=" + content + "}";
|
||||
}
|
||||
}
|
||||
|
||||
class Styled implements ScoreFormat {
|
||||
private final Style style;
|
||||
|
||||
public Styled(@NotNull Style style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public @NotNull Style style() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Styled that = (Styled) o;
|
||||
return style.equals(that.style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return style.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Styled{style=" + style + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
+107
-17
@@ -1,54 +1,144 @@
|
||||
package net.megavex.scoreboardlibrary.api.objective;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a scoreboard objective.
|
||||
* To get an instance of this interface, use {@link ObjectiveManager#create}.
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*/
|
||||
public interface ScoreboardObjective {
|
||||
/**
|
||||
* @return The value (display name) of the objective
|
||||
* @return the value (display name) of the objective, defaults to {@link Component#empty}
|
||||
*/
|
||||
@NotNull Component value();
|
||||
|
||||
/**
|
||||
* Sets the value (display name) of the objective
|
||||
* Sets the value (display name) of the objective.
|
||||
*
|
||||
* @param value New value
|
||||
* @param value new value
|
||||
*/
|
||||
@NotNull ScoreboardObjective value(@NotNull Component value);
|
||||
@NotNull ScoreboardObjective value(@NotNull ComponentLike value);
|
||||
|
||||
/**
|
||||
* @return The render type of the objective, default is {@link ObjectiveRenderType#INTEGER}
|
||||
* @return the render type of the objective, defaults to {@link ObjectiveRenderType#INTEGER}
|
||||
*/
|
||||
@NotNull ObjectiveRenderType renderType();
|
||||
|
||||
/**
|
||||
* @param renderType Sets the render type of the objective
|
||||
* Sets the render type of the objective.
|
||||
*
|
||||
* @param renderType new render type
|
||||
*/
|
||||
@NotNull ScoreboardObjective renderType(@NotNull ObjectiveRenderType renderType);
|
||||
|
||||
/**
|
||||
* Gets the score value for an entry, or null if the entry has no score registered
|
||||
*
|
||||
* @param entry Entry to get score of
|
||||
* @return The score, or 0 if score doesn't exist
|
||||
* @return the default score format for all scores in this objective, defaults to null
|
||||
*/
|
||||
Integer score(@NotNull String entry);
|
||||
@Nullable ScoreFormat defaultScoreFormat();
|
||||
|
||||
/**
|
||||
* Sets the score for an entry
|
||||
* Sets the default score format of this objective.
|
||||
*
|
||||
* @param entry Entry to update score of
|
||||
* @param score The new score value
|
||||
* @param defaultScoreFormat new default score format
|
||||
* @see #defaultScoreFormat()
|
||||
*/
|
||||
@NotNull ScoreboardObjective score(@NotNull String entry, int score);
|
||||
void defaultScoreFormat(@Nullable ScoreFormat defaultScoreFormat);
|
||||
|
||||
/**
|
||||
* Removes a score
|
||||
* Get the score for an entry, or null if the entry has no score.
|
||||
*
|
||||
* @param entry Entry to remove score from
|
||||
* @param entry entry to get score of
|
||||
* @return the score value, or null if it doesn't exist for the entry
|
||||
*/
|
||||
@Nullable ObjectiveScore scoreInfo(@NotNull String entry);
|
||||
|
||||
/**
|
||||
* Gets the score value for an entry, or null if the entry has no score.
|
||||
*
|
||||
* @param entry entry to get score of
|
||||
* @return the score value, or null if it doesn't exist for the entry
|
||||
* @deprecated use {@link #scoreInfo(String)} and {@link ObjectiveScore#value()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
default @Nullable Integer score(@NotNull String entry) {
|
||||
ObjectiveScore score = scoreInfo(entry);
|
||||
return score == null ? null : score.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the score of an entry.
|
||||
*
|
||||
* @param entry entry to update score of
|
||||
* @param score score
|
||||
*/
|
||||
@NotNull ScoreboardObjective score(@NotNull String entry, ObjectiveScore score);
|
||||
|
||||
/**
|
||||
* Updates the score of an entry.
|
||||
*
|
||||
* @param entry entry to update score of
|
||||
* @param scoreValue score value
|
||||
*/
|
||||
default @NotNull ScoreboardObjective score(@NotNull String entry, int scoreValue) {
|
||||
return score(entry, new ObjectiveScore(scoreValue, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the score of an entry.
|
||||
*
|
||||
* @param entry entry to update score of
|
||||
* @param scoreValue score value
|
||||
* @param displayName score display name
|
||||
* @param scoreFormat score format
|
||||
*/
|
||||
default @NotNull ScoreboardObjective score(
|
||||
@NotNull String entry,
|
||||
int scoreValue,
|
||||
@Nullable ComponentLike displayName,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
return score(entry, new ObjectiveScore(scoreValue, displayName, scoreFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the score of an entry.
|
||||
*
|
||||
* @param entry entry to update score of
|
||||
* @param scoreValue score value
|
||||
* @param displayName score display name
|
||||
*/
|
||||
default @NotNull ScoreboardObjective score(
|
||||
@NotNull String entry,
|
||||
int scoreValue,
|
||||
@Nullable ComponentLike displayName
|
||||
) {
|
||||
return score(entry, new ObjectiveScore(scoreValue, displayName, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the score of an entry.
|
||||
*
|
||||
* @param entry entry to update score of
|
||||
* @param scoreValue score value
|
||||
* @param scoreFormat score format
|
||||
*/
|
||||
default @NotNull ScoreboardObjective score(
|
||||
@NotNull String entry,
|
||||
int scoreValue,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
return score(entry, new ObjectiveScore(scoreValue, null, scoreFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a score associated with an entry.
|
||||
*
|
||||
* @param entry entry to remove score of
|
||||
*/
|
||||
@NotNull ScoreboardObjective removeScore(@NotNull String entry);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package net.megavex.scoreboardlibrary.api.sidebar;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -11,8 +14,10 @@ import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Provides a low-level utility for showing sidebars to players.
|
||||
* Note: this class is not thread-safe.
|
||||
* Represents a sidebar.
|
||||
* To get an instance of this interface, use {@link ScoreboardLibrary#createSidebar()}.
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface Sidebar {
|
||||
@@ -24,32 +29,52 @@ public interface Sidebar {
|
||||
// Main
|
||||
|
||||
/**
|
||||
* @return Max amount of lines this sidebar can have
|
||||
* @return max amount of lines this sidebar can have
|
||||
*/
|
||||
@Range(from = 1, to = MAX_LINES) int maxLines();
|
||||
@Range(from = 1, to = Integer.MAX_VALUE) int maxLines();
|
||||
|
||||
/**
|
||||
* @return {@link Locale} which is used to translate {@link net.kyori.adventure.text.TranslatableComponent}s
|
||||
* @return locale which is used for translating {@link net.kyori.adventure.text.TranslatableComponent}s,
|
||||
* or null if it depends on each player's client locale.
|
||||
* @see ScoreboardLibrary#createSidebar(int, Locale)
|
||||
*/
|
||||
@Nullable Locale locale();
|
||||
|
||||
// Lines
|
||||
|
||||
/**
|
||||
* Gets a line's value.
|
||||
* Gets a line's value, or null if line isn't set.
|
||||
*
|
||||
* @param line Line
|
||||
* @return Value of line
|
||||
* @param line line index
|
||||
* @return value of line, or null if unset
|
||||
*/
|
||||
@Nullable Component line(@Range(from = 0, to = MAX_LINES - 1) int line);
|
||||
@Nullable Component line(@Range(from = 0, to = Integer.MAX_VALUE - 1) int line);
|
||||
|
||||
/**
|
||||
* Sets a line's value.
|
||||
* A null value hides the line.
|
||||
*
|
||||
* @param line Line
|
||||
* @param value Value
|
||||
* @param index line index
|
||||
* @param value new value, or null to hide
|
||||
*/
|
||||
void line(@Range(from = 0, to = MAX_LINES - 1) int line, @Nullable Component value);
|
||||
default void line(@Range(from = 0, to = Integer.MAX_VALUE - 1) int index, @Nullable ComponentLike value) {
|
||||
line(index, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a line's value with a custom score format.
|
||||
* A null value hides the line.
|
||||
* Note that custom score formats are only supported in Minecraft 1.20.3+.
|
||||
*
|
||||
* @param index line index
|
||||
* @param value new value, or null to hide
|
||||
* @param scoreFormat score format
|
||||
*/
|
||||
void line(
|
||||
@Range(from = 0, to = Integer.MAX_VALUE - 1) int index,
|
||||
@Nullable ComponentLike value,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
);
|
||||
|
||||
/**
|
||||
* Clears all lines in this sidebar.
|
||||
@@ -63,44 +88,41 @@ public interface Sidebar {
|
||||
// Title
|
||||
|
||||
/**
|
||||
* @return Title of the sidebar
|
||||
* @return title of the sidebar, defaults to {@link Component#empty}
|
||||
*/
|
||||
@NotNull Component title();
|
||||
|
||||
/**
|
||||
* Sets the title of the sidebar.
|
||||
*
|
||||
* @param title Title
|
||||
* @param title title
|
||||
*/
|
||||
void title(@NotNull Component title);
|
||||
void title(@NotNull ComponentLike title);
|
||||
|
||||
// Players
|
||||
|
||||
/**
|
||||
* @return The players that have been added to this sidebar.
|
||||
* @return unmodifiable collection of viewers in this Sidebar
|
||||
* @see #addPlayer
|
||||
* @see #removePlayer
|
||||
*/
|
||||
@NotNull Collection<Player> players();
|
||||
|
||||
/**
|
||||
* Adds a player to this sidebar, making it be able to see it.
|
||||
* Adds a viewer to this Sidebar.
|
||||
* Note that a player can only see a single Sidebar at a time.
|
||||
* The Sidebar will internally be added to a queue for this player who
|
||||
* will start seeing it once they are removed from all previous Sidebars.
|
||||
*
|
||||
* @param player Player to add
|
||||
* @return Whether the player has been added
|
||||
* @param player player to add
|
||||
* @return whether the player was added
|
||||
*/
|
||||
boolean addPlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Removes a player from this sidebar, making it not able to see it.
|
||||
* Adds multiple viewers to this Sidebar.
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @return Whether the player has been removed
|
||||
*/
|
||||
boolean removePlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Adds multiple players to this sidebar.
|
||||
*
|
||||
* @param players Players to add
|
||||
* @param players viewers to add
|
||||
* @see #addPlayer
|
||||
*/
|
||||
default void addPlayers(@NotNull Collection<Player> players) {
|
||||
@@ -110,10 +132,17 @@ public interface Sidebar {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes multiple players from this sidebar.
|
||||
* Removes a viewer from this Sidebar.
|
||||
*
|
||||
* @param players Players to remove
|
||||
* @see #removePlayer
|
||||
* @param player viewer to remove
|
||||
* @return whether the viewer was removed
|
||||
*/
|
||||
boolean removePlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Removes multiple viewers from this Sidebar
|
||||
*
|
||||
* @param players viewers to remove
|
||||
*/
|
||||
default void removePlayers(@NotNull Collection<Player> players) {
|
||||
for (Player player : players) {
|
||||
@@ -121,15 +150,15 @@ public interface Sidebar {
|
||||
}
|
||||
}
|
||||
|
||||
// Close
|
||||
|
||||
/**
|
||||
* Closes this sidebar
|
||||
* Closes this Sidebar.
|
||||
* This must be called once you no longer need this Sidebar to prevent a memory leak.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @return Whether this sidebar is closed
|
||||
* @see #close
|
||||
*/
|
||||
boolean closed();
|
||||
}
|
||||
+16
-4
@@ -2,11 +2,17 @@ package net.megavex.scoreboardlibrary.api.sidebar.component;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
/**
|
||||
* Represents a component sidebar layout that can be applied to a {@link Sidebar}.
|
||||
*/
|
||||
public final class ComponentSidebarLayout {
|
||||
private final SidebarComponent titleComponent;
|
||||
private final SidebarComponent linesComponent;
|
||||
@@ -26,6 +32,12 @@ public final class ComponentSidebarLayout {
|
||||
return linesComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the title and line components to a sidebar.
|
||||
* Call this every time you want to update the sidebar.
|
||||
*
|
||||
* @param sidebar sidebar to apply title and line components to
|
||||
*/
|
||||
public void apply(@NotNull Sidebar sidebar) {
|
||||
Preconditions.checkNotNull(sidebar);
|
||||
|
||||
@@ -45,11 +57,11 @@ public final class ComponentSidebarLayout {
|
||||
private Component title;
|
||||
|
||||
@Override
|
||||
public void drawLine(@NotNull Component line) {
|
||||
public void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat) {
|
||||
Preconditions.checkNotNull(line);
|
||||
|
||||
if (title == null) {
|
||||
title = line;
|
||||
title = line.asComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,11 +75,11 @@ public final class ComponentSidebarLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLine(@NotNull Component line) {
|
||||
public void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat) {
|
||||
Preconditions.checkNotNull(line);
|
||||
|
||||
if (index < Sidebar.MAX_LINES) {
|
||||
sidebar.line(index++, line);
|
||||
sidebar.line(index++, line, scoreFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-5
@@ -1,18 +1,30 @@
|
||||
package net.megavex.scoreboardlibrary.api.sidebar.component;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Something lines can be drawn to. This is either the lines of a sidebar or the sidebar title
|
||||
* Something lines can be drawn to line by line. This is either the lines of a sidebar or its title.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface LineDrawable {
|
||||
/**
|
||||
* Draws a line, or does nothing if has reached the limit
|
||||
* Draws the next line, or does nothing if it has reached a limit.
|
||||
*
|
||||
* @param line Line component
|
||||
* @param line line component
|
||||
*/
|
||||
void drawLine(@NotNull Component line);
|
||||
default void drawLine(@NotNull ComponentLike line) {
|
||||
drawLine(line, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the next line with a custom score format, or does nothing if it has reached a limit.
|
||||
*
|
||||
* @param line line component
|
||||
* @param scoreFormat score format
|
||||
*/
|
||||
void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat);
|
||||
}
|
||||
+24
-19
@@ -2,7 +2,8 @@ package net.megavex.scoreboardlibrary.api.sidebar.component;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -13,25 +14,30 @@ import java.util.function.Supplier;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
public interface SidebarComponent {
|
||||
static @NotNull SidebarComponent staticLine(@NotNull Component line) {
|
||||
static @NotNull SidebarComponent staticLine(@NotNull ComponentLike line) {
|
||||
Preconditions.checkNotNull(line);
|
||||
return drawable -> drawable.drawLine(line);
|
||||
}
|
||||
|
||||
static @NotNull SidebarComponent staticLine(@NotNull ComponentLike line, @NotNull ScoreFormat scoreFormat) {
|
||||
Preconditions.checkNotNull(line);
|
||||
return drawable -> drawable.drawLine(line, scoreFormat);
|
||||
}
|
||||
|
||||
static @NotNull SidebarComponent blankLine() {
|
||||
return drawable -> drawable.drawLine(empty());
|
||||
}
|
||||
|
||||
static @NotNull SidebarComponent dynamicLine(@NotNull Supplier<Component> lineSupplier) {
|
||||
static @NotNull <T extends ComponentLike> SidebarComponent dynamicLine(@NotNull Supplier<T> lineSupplier) {
|
||||
return drawable -> drawable.drawLine(lineSupplier.get());
|
||||
}
|
||||
|
||||
static @NotNull SidebarComponent animatedLine(@NotNull SidebarAnimation<Component> animation) {
|
||||
static @NotNull <T extends ComponentLike> SidebarComponent animatedLine(@NotNull SidebarAnimation<T> animation) {
|
||||
Preconditions.checkNotNull(animation);
|
||||
return drawable -> drawable.drawLine(animation.currentFrame());
|
||||
}
|
||||
|
||||
static @NotNull SidebarComponent animatedComponent(@NotNull SidebarAnimation<SidebarComponent> animation) {
|
||||
static @NotNull <T extends SidebarComponent> SidebarComponent animatedComponent(@NotNull SidebarAnimation<T> animation) {
|
||||
Preconditions.checkNotNull(animation);
|
||||
return drawable -> animation.currentFrame().draw(drawable);
|
||||
}
|
||||
@@ -54,29 +60,28 @@ public interface SidebarComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull Builder addStaticLine(@NotNull Component line) {
|
||||
addComponent(SidebarComponent.staticLine(line));
|
||||
return this;
|
||||
public @NotNull Builder addStaticLine(@NotNull ComponentLike line) {
|
||||
return addComponent(SidebarComponent.staticLine(line));
|
||||
}
|
||||
|
||||
public @NotNull Builder addStaticLine(@NotNull ComponentLike line, @NotNull ScoreFormat scoreFormat) {
|
||||
return addComponent(SidebarComponent.staticLine(line, scoreFormat));
|
||||
}
|
||||
|
||||
public @NotNull Builder addBlankLine() {
|
||||
addComponent(SidebarComponent.blankLine());
|
||||
return this;
|
||||
return addComponent(SidebarComponent.blankLine());
|
||||
}
|
||||
|
||||
public @NotNull Builder addDynamicLine(@NotNull Supplier<Component> lineSupplier) {
|
||||
addComponent(SidebarComponent.dynamicLine(lineSupplier));
|
||||
return this;
|
||||
public @NotNull <T extends ComponentLike> Builder addDynamicLine(@NotNull Supplier<T> lineSupplier) {
|
||||
return addComponent(SidebarComponent.dynamicLine(lineSupplier));
|
||||
}
|
||||
|
||||
public @NotNull Builder addAnimatedLine(@NotNull SidebarAnimation<Component> animation) {
|
||||
addComponent(SidebarComponent.animatedLine(animation));
|
||||
return this;
|
||||
public <T extends ComponentLike> @NotNull Builder addAnimatedLine(@NotNull SidebarAnimation<T> animation) {
|
||||
return addComponent(SidebarComponent.animatedLine(animation));
|
||||
}
|
||||
|
||||
public @NotNull Builder addAnimatedComponent(@NotNull SidebarAnimation<SidebarComponent> animation) {
|
||||
addComponent(SidebarComponent.animatedComponent(animation));
|
||||
return this;
|
||||
public @NotNull <T extends SidebarComponent> Builder addAnimatedComponent(@NotNull SidebarAnimation<T> animation) {
|
||||
return addComponent(SidebarComponent.animatedComponent(animation));
|
||||
}
|
||||
|
||||
public @NotNull SidebarComponent build() {
|
||||
|
||||
+5
@@ -8,6 +8,11 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FramedSidebarAnimation} using a predefined collection of frames.
|
||||
*
|
||||
* @param <T> frame type
|
||||
*/
|
||||
public final class CollectionSidebarAnimation<T> implements FramedSidebarAnimation<T> {
|
||||
private final List<T> frames;
|
||||
private int currentFrameIndex;
|
||||
|
||||
+7
-7
@@ -6,26 +6,26 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link SidebarAnimation} with predetermined frames
|
||||
* A {@link SidebarAnimation} with predetermined frames.
|
||||
*
|
||||
* @param <T> Frame type
|
||||
* @param <T> frame type
|
||||
*/
|
||||
public interface FramedSidebarAnimation<T> extends SidebarAnimation<T> {
|
||||
/**
|
||||
* @return All frames in this animation
|
||||
* @return all frames in this animation
|
||||
*/
|
||||
@Unmodifiable @NotNull List<T> frames();
|
||||
|
||||
/**
|
||||
* @return The index of the current frame
|
||||
* @return the index of the current frame
|
||||
*/
|
||||
int currentFrameIndex();
|
||||
|
||||
/**
|
||||
* Switches the current frame
|
||||
* Switches the current frame to specified index
|
||||
*
|
||||
* @param frameIndex The index of the new current frame
|
||||
* @throws ArrayIndexOutOfBoundsException If frame is out of bounds
|
||||
* @param frameIndex the index of the new current frame
|
||||
* @throws ArrayIndexOutOfBoundsException if frame is out of bounds
|
||||
*/
|
||||
void switchFrame(int frameIndex);
|
||||
}
|
||||
+2
-2
@@ -6,11 +6,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* An animation that can be used with {@link ComponentSidebarLayout}s
|
||||
*
|
||||
* @param <T> Frame type
|
||||
* @param <T> frame type
|
||||
*/
|
||||
public interface SidebarAnimation<T> {
|
||||
/**
|
||||
* @return The current frame of the animation
|
||||
* @return the current frame of the animation
|
||||
*/
|
||||
@NotNull T currentFrame();
|
||||
|
||||
|
||||
@@ -5,42 +5,54 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a scoreboard team.
|
||||
* Note: this class is not thread-safe.
|
||||
* To get an instance of this interface, use {@link TeamManager#createIfAbsent}.
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*
|
||||
* @see <a href="https://minecraft.fandom.com/wiki/Scoreboard#Teams">Minecraft Wiki</a>
|
||||
*/
|
||||
public interface ScoreboardTeam {
|
||||
/**
|
||||
* @return {@link TeamManager} of this team
|
||||
* @return TeamManager of this team
|
||||
*/
|
||||
@NotNull TeamManager teamManager();
|
||||
|
||||
/**
|
||||
* @return Name of this team
|
||||
* @return name of this team
|
||||
*/
|
||||
@NotNull String name();
|
||||
|
||||
/**
|
||||
* @return Default {@link TeamDisplay} of this team
|
||||
* Gets the default {@link TeamDisplay} of this team.
|
||||
* All players are added to this display by default.
|
||||
*
|
||||
* @return default team display
|
||||
*/
|
||||
@NotNull TeamDisplay defaultDisplay();
|
||||
|
||||
/**
|
||||
* Gets the {@link TeamDisplay} of a player
|
||||
* Gets the {@link TeamDisplay} that a player sees.
|
||||
*
|
||||
* @param player Player
|
||||
* @return {@link TeamDisplay} of this player
|
||||
* @param player player
|
||||
* @return team display the player sees
|
||||
* @throws IllegalArgumentException if player is not in the TeamManager
|
||||
*/
|
||||
@NotNull TeamDisplay display(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Changes a player's visible {@link TeamDisplay}
|
||||
* Updates the team {@link TeamDisplay} that a player sees for this team.
|
||||
*
|
||||
* @param player Player
|
||||
* @param teamDisplay New {@link TeamDisplay} of Player
|
||||
* @param player player
|
||||
* @param teamDisplay new {@link TeamDisplay} of player
|
||||
* @throws IllegalArgumentException if player is not in the TeamManager
|
||||
*/
|
||||
void display(@NotNull Player player, @NotNull TeamDisplay teamDisplay);
|
||||
|
||||
/**
|
||||
* @return Newly created {@link TeamDisplay} which is assigned to this team
|
||||
* Creates a new {@link TeamDisplay}.
|
||||
* To show it to players, use {@link #display(Player, TeamDisplay)}.
|
||||
*
|
||||
* @return newly created team display
|
||||
*/
|
||||
@NotNull TeamDisplay createDisplay();
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.megavex.scoreboardlibrary.api.team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.team.enums.CollisionRule;
|
||||
import net.megavex.scoreboardlibrary.api.team.enums.NameTagVisibility;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -11,132 +13,161 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Represents the display information of a {@link ScoreboardTeam}.
|
||||
* This includes things like the entries, display name, prefix etc..
|
||||
* Note: this class is not thread-safe.
|
||||
* Represents the display properties of a scoreboard team.
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface TeamDisplay {
|
||||
/**
|
||||
* @return Team which is assigned to this {@link TeamDisplay}
|
||||
* @return team which this team display is assigned to
|
||||
*/
|
||||
@NotNull ScoreboardTeam team();
|
||||
|
||||
// Entries
|
||||
|
||||
/**
|
||||
* Gets the entries. The entries specify which players are members of the team.
|
||||
*
|
||||
* @return entries of the team.
|
||||
*/
|
||||
@NotNull Collection<String> entries();
|
||||
|
||||
/**
|
||||
* Adds an entry.
|
||||
*
|
||||
* @param entry Entry to add
|
||||
* @return Whether the entry was added
|
||||
* @param entry entry to add
|
||||
* @return whether the entry was added
|
||||
* @see #entries
|
||||
*/
|
||||
boolean addEntry(@NotNull String entry);
|
||||
|
||||
/**
|
||||
* Removes an entry.
|
||||
*
|
||||
* @param entry Entry to remove
|
||||
* @return Whether the entry was removed
|
||||
* @param entry entry to remove
|
||||
* @return whether the entry was removed
|
||||
* @see #entries
|
||||
*/
|
||||
boolean removeEntry(@NotNull String entry);
|
||||
|
||||
// Properties
|
||||
|
||||
/**
|
||||
* @return Display name
|
||||
* @return display name, defaults to {@link Component#empty()}
|
||||
*/
|
||||
@NotNull Component displayName();
|
||||
|
||||
/**
|
||||
* Sets the display name.
|
||||
* Updates the display name.
|
||||
*
|
||||
* @param displayName Display name
|
||||
* @param displayName new display name
|
||||
*/
|
||||
@NotNull TeamDisplay displayName(@NotNull Component displayName);
|
||||
@NotNull TeamDisplay displayName(@NotNull ComponentLike displayName);
|
||||
|
||||
/**
|
||||
* @return Prefix
|
||||
* Gets the prefix, which defaults to {@link Component#empty()}.
|
||||
* The suffix is prepended to all team members' names.
|
||||
*
|
||||
* @return prefix, defaults to {@link Component#empty()}
|
||||
*/
|
||||
@NotNull Component prefix();
|
||||
|
||||
/**
|
||||
* Sets the prefix.
|
||||
* Updates the prefix.
|
||||
*
|
||||
* @param prefix Prefix
|
||||
* @param prefix new prefix
|
||||
* @see #prefix()
|
||||
*/
|
||||
@NotNull TeamDisplay prefix(@NotNull Component prefix);
|
||||
@NotNull TeamDisplay prefix(@NotNull ComponentLike prefix);
|
||||
|
||||
/**
|
||||
* @return Suffix
|
||||
* Gets the suffix, which defaults to {@link Component#empty()}.
|
||||
* The suffix is appended to all team members' names.
|
||||
*
|
||||
* @return suffix
|
||||
*/
|
||||
@NotNull Component suffix();
|
||||
|
||||
/**
|
||||
* Sets the suffix.
|
||||
* Updates the suffix.
|
||||
*
|
||||
* @param suffix Suffix
|
||||
* @param suffix new suffix
|
||||
* @see #suffix()
|
||||
*/
|
||||
@NotNull TeamDisplay suffix(@NotNull Component suffix);
|
||||
@NotNull TeamDisplay suffix(@NotNull ComponentLike suffix);
|
||||
|
||||
/**
|
||||
* @return Friendly fire rule
|
||||
* @return friendly fire rule value, defaults to false
|
||||
*/
|
||||
boolean friendlyFire();
|
||||
|
||||
/**
|
||||
* Sets whether friendly fire is allowed.
|
||||
* Updates the friendly fire rule.
|
||||
*
|
||||
* @param friendlyFire whether friendly fire is allowed
|
||||
* @param friendlyFire new rule value
|
||||
*/
|
||||
@NotNull TeamDisplay friendlyFire(boolean friendlyFire);
|
||||
|
||||
/**
|
||||
* @return Can see friendly invisibles rule
|
||||
* Gets the can see friendly invisibles rule value, which is false by default.
|
||||
* If true, team members can see other members with the invisibility effect.
|
||||
*
|
||||
* @return rule value
|
||||
*/
|
||||
boolean canSeeFriendlyInvisibles();
|
||||
|
||||
/**
|
||||
* Sets whether players can see friendly invisibles.
|
||||
* Updates the can see friendly invisibles rule.
|
||||
*
|
||||
* @param canSeeFriendlyInvisibles whether players can see friendly invisibles
|
||||
* @param canSeeFriendlyInvisibles new rule value
|
||||
* @see #canSeeFriendlyInvisibles()
|
||||
*/
|
||||
@NotNull TeamDisplay canSeeFriendlyInvisibles(boolean canSeeFriendlyInvisibles);
|
||||
|
||||
/**
|
||||
* @return Name tag visibility rule
|
||||
* @return name tag visibility rule value
|
||||
* @since Minecraft 1.8
|
||||
*/
|
||||
@NotNull NameTagVisibility nameTagVisibility();
|
||||
|
||||
/**
|
||||
* Sets the {@link NameTagVisibility}.
|
||||
* Updates the name tag visibility rule.
|
||||
*
|
||||
* @param nameTagVisibility Name tag visibility rule
|
||||
* @param nameTagVisibility new rule value
|
||||
* @since Minecraft 1.8
|
||||
*/
|
||||
@NotNull TeamDisplay nameTagVisibility(@NotNull NameTagVisibility nameTagVisibility);
|
||||
|
||||
/**
|
||||
* @return Collision rule
|
||||
* @return collision rule
|
||||
* @since Minecraft 1.9
|
||||
*/
|
||||
@NotNull CollisionRule collisionRule();
|
||||
|
||||
/**
|
||||
* Sets the {@link CollisionRule}.
|
||||
* Updates the collision rule.
|
||||
*
|
||||
* @param collisionRule Collision rule
|
||||
* @param collisionRule new rule value
|
||||
* @since Minecraft 1.9
|
||||
*/
|
||||
@NotNull TeamDisplay collisionRule(@NotNull CollisionRule collisionRule);
|
||||
|
||||
/**
|
||||
* @return Player color
|
||||
* Gets the player color. The player color is the color player name tags are displayed in.
|
||||
* It is also used for displaying team specific sidebars with the {@link ObjectiveDisplaySlot.TeamSidebar}} display slot.
|
||||
*
|
||||
* @return player color
|
||||
* @since Minecraft 1.8
|
||||
*/
|
||||
@Nullable NamedTextColor playerColor();
|
||||
|
||||
/**
|
||||
* Sets the player color.
|
||||
* Updates the player color.
|
||||
*
|
||||
* @param playerColor Player color
|
||||
* @param playerColor new player color
|
||||
* @see #playerColor()
|
||||
* @since Minecraft 1.8
|
||||
*/
|
||||
@NotNull TeamDisplay playerColor(@Nullable NamedTextColor playerColor);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.megavex.scoreboardlibrary.api.team;
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -10,111 +11,121 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Manages a group of {@link ScoreboardTeam}s.
|
||||
* Note: this class is not thread-safe.
|
||||
* Represents a group of {@link ScoreboardTeam}s.
|
||||
* To get an instance of this interface, use {@link ScoreboardLibrary#createTeamManager()}.
|
||||
* Note: this interface is not thread-safe, meaning you can only use it from one thread at a time,
|
||||
* although it does not have to be the main thread.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface TeamManager {
|
||||
// Teams
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable set of teams in this team manager
|
||||
*
|
||||
* @return Teams
|
||||
* @return unmodifiable collection of teams in this TeamManager
|
||||
*/
|
||||
@NotNull Collection<ScoreboardTeam> teams();
|
||||
|
||||
/**
|
||||
* Returns team based on its name
|
||||
* Gets a team by its name.
|
||||
*
|
||||
* @param name Name of team
|
||||
* @return Team with this name
|
||||
* @param name name of team
|
||||
* @return team with the name, or null if one doesn't exist
|
||||
*/
|
||||
@Nullable ScoreboardTeam team(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Returns whether a team by the name exists
|
||||
* Check whether a team with a name exists.
|
||||
*
|
||||
* @param name Name of team
|
||||
* @return Whether a team by the name exists
|
||||
* @param name name of team
|
||||
* @return whether a team by the name exists
|
||||
*/
|
||||
boolean teamExists(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Returns team based on its name. If it doesn't already exist, creates it
|
||||
* Creates a team with a name if one doesn't already exist and returns it.
|
||||
*
|
||||
* @param name Name of team
|
||||
* @return Existing or newly created team with the name
|
||||
* @param name name of team
|
||||
* @return team
|
||||
*/
|
||||
default @NotNull ScoreboardTeam createIfAbsent(@NotNull String name) {
|
||||
return createIfAbsent(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a team based on its name. If it doesn't already exist, it creates it
|
||||
* Creates a team with a name if one doesn't already exist and returns it.
|
||||
*
|
||||
* @param name Name of team
|
||||
* @param teamDisplayFunction A function that provides the team display to set for each player
|
||||
* @return Team with this name
|
||||
* @param name name of team
|
||||
* @param teamDisplayFunction a function that provides the team display to set for each player
|
||||
* @return team
|
||||
*/
|
||||
@NotNull ScoreboardTeam createIfAbsent(@NotNull String name, @Nullable BiFunction<Player, ScoreboardTeam, TeamDisplay> teamDisplayFunction);
|
||||
|
||||
/**
|
||||
* Removes a team
|
||||
* Removes a team by its name.
|
||||
*
|
||||
* @param name Name of team
|
||||
* @return If there was a team with than name
|
||||
* @param name name of team
|
||||
* @return if there was a team with than name
|
||||
*/
|
||||
boolean removeTeam(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Removes a team
|
||||
* Removes a team.
|
||||
*
|
||||
* @param team Team
|
||||
* @throws IllegalArgumentException If the provided team is not owned by this TeamManager
|
||||
* @param team team to remove
|
||||
* @throws IllegalArgumentException if the provided team is not owned by this TeamManager
|
||||
*/
|
||||
void removeTeam(@NotNull ScoreboardTeam team);
|
||||
|
||||
// Players
|
||||
|
||||
/**
|
||||
* @return Players in this TeamManager
|
||||
* @return unmodifiable collection of viewers in this TeamManager
|
||||
* @see #addPlayer
|
||||
* @see #removePlayer
|
||||
*/
|
||||
@NotNull Collection<Player> players();
|
||||
|
||||
/**
|
||||
* Adds a player to this TeamManager
|
||||
* Adds a viewer to this TeamManager.
|
||||
* Note that a player can only see a single TeamManager at a time.
|
||||
* The TeamManager will internally be added to a queue for this player who
|
||||
* will start seeing it once they are removed from all previous TeamManagers.
|
||||
*
|
||||
* @param player Player to add to TeamManager
|
||||
* @return Whether the player was added
|
||||
* @param player player to add
|
||||
* @return whether the player was added
|
||||
*/
|
||||
default boolean addPlayer(@NotNull Player player) {
|
||||
return addPlayer(player, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to this TeamManager
|
||||
* Adds a viewer to this TeamManager.
|
||||
* Note that a player can only see a single TeamManager at a time.
|
||||
* The TeamManager will internally be added to a queue for this player who
|
||||
* will start seeing it once they are removed from all previous TeamManagers.
|
||||
*
|
||||
* @param player Player to add
|
||||
* @param teamDisplayFunction A function that provides the team display to set for each team
|
||||
* @return Whether the player was added
|
||||
* @param player player to add
|
||||
* @param teamDisplayFunction a function that provides the team display to set for each team
|
||||
* @return whether the player was added
|
||||
*/
|
||||
boolean addPlayer(@NotNull Player player, @Nullable Function<ScoreboardTeam, TeamDisplay> teamDisplayFunction);
|
||||
|
||||
/**
|
||||
* Adds a player to this TeamManager
|
||||
* Adds multiple viewers to this TeamManager.
|
||||
*
|
||||
* @param players Players to add
|
||||
* @param players viewers to add
|
||||
* @see #addPlayer
|
||||
*/
|
||||
default void addPlayers(@NotNull Collection<Player> players) {
|
||||
addPlayers(players, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a collection of players to this TeamManager
|
||||
* Adds multiple viewers to this TeamManager.
|
||||
*
|
||||
* @param players Players to add
|
||||
* @param teamDisplayFunction A function that provides the team display to set for each team
|
||||
* @param players viewers to add
|
||||
* @param teamDisplayFunction a function that provides the team display to set for each team
|
||||
* @see #addPlayer
|
||||
*/
|
||||
default void addPlayers(@NotNull Collection<Player> players, @Nullable Function<ScoreboardTeam, TeamDisplay> teamDisplayFunction) {
|
||||
for (Player player : players) {
|
||||
@@ -123,17 +134,17 @@ public interface TeamManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from this TeamManager
|
||||
* Removes a viewer from this TeamManager.
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @return Whether the player wasn't already in this TeamManager
|
||||
* @param player viewer to remove
|
||||
* @return whether the viewer was removed
|
||||
*/
|
||||
boolean removePlayer(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Removes a collection of players from this TeamManager
|
||||
* Removes multiple viewers from this TeamManager.
|
||||
*
|
||||
* @param players Players to remove
|
||||
* @param players viewers to remove
|
||||
*/
|
||||
default void removePlayers(@NotNull Collection<Player> players) {
|
||||
for (Player player : players) {
|
||||
@@ -144,12 +155,14 @@ public interface TeamManager {
|
||||
// Close
|
||||
|
||||
/**
|
||||
* Closes this TeamManager
|
||||
* Closes this TeamManager.
|
||||
* This must be called once you no longer need this TeamManager to prevent a memory leak.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @return Whether this TeamManager is closed
|
||||
* @see #close
|
||||
*/
|
||||
boolean closed();
|
||||
}
|
||||
@@ -2,29 +2,23 @@ package net.megavex.scoreboardlibrary.api.team.enums;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents all possible collision rule values of a team.
|
||||
*
|
||||
* @since Minecraft 1.9
|
||||
*/
|
||||
public enum CollisionRule {
|
||||
ALWAYS("always"),
|
||||
NEVER("never"),
|
||||
PUSH_OTHER_TEAMS("pushOtherTeams"),
|
||||
PUSH_OWN_TEAM("pushOwnTeam");
|
||||
|
||||
private static final CollisionRule[] values = values();
|
||||
private final String key;
|
||||
|
||||
CollisionRule(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static CollisionRule of(byte id) {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public byte id() {
|
||||
return (byte) ordinal();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public String key() {
|
||||
return this.key;
|
||||
|
||||
+3
-11
@@ -2,29 +2,21 @@ package net.megavex.scoreboardlibrary.api.team.enums;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents all possible name tag visibility rule values of a team.
|
||||
*/
|
||||
public enum NameTagVisibility {
|
||||
ALWAYS("always"),
|
||||
NEVER("never"),
|
||||
HIDE_FOR_OTHER_TEAMS("hideForOtherTeams"),
|
||||
HIDE_FOR_OWN_TEAM("hideForOwnTeam");
|
||||
|
||||
private static final NameTagVisibility[] values = values();
|
||||
private final String key;
|
||||
|
||||
NameTagVisibility(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static NameTagVisibility of(byte id) {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public byte id() {
|
||||
return (byte) ordinal();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public String key() {
|
||||
return this.key;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package net.megavex.scoreboardlibrary.api.util;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class SidebarUtil {
|
||||
private SidebarUtil() {
|
||||
}
|
||||
|
||||
public static void checkLineBounds(int maxLines, int line) {
|
||||
if (line >= maxLines || line < 0) {
|
||||
throw new IndexOutOfBoundsException("invalid line " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-43
@@ -1,46 +1,5 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
allprojects {
|
||||
version = "2.0.0"
|
||||
version = "2.2.2"
|
||||
group = "net.megavex"
|
||||
description = "Powerful packet-level sidebar/teams library for Paper/Spigot servers"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java-library")
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT")
|
||||
|
||||
val adventureVersion = "4.14.0"
|
||||
compileOnly("net.kyori:adventure-api:$adventureVersion")
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:$adventureVersion")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:$adventureVersion")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
|
||||
|
||||
testImplementation("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT")
|
||||
testImplementation("net.kyori:adventure-api:$adventureVersion")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
options.encoding = "UTF-8"
|
||||
options.isIncremental = true
|
||||
options.compilerArgs = mutableListOf("-Xlint:-deprecation,-unchecked")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
description = "Powerful packet-level scoreboard library for Paper/Spigot servers"
|
||||
}
|
||||
@@ -3,5 +3,12 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.buildIndra)
|
||||
implementation(libs.buildNmcp)
|
||||
compileOnly(files(libs::class.java.protectionDomain.codeSource.location))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
register("libs") {
|
||||
from(files("../gradle/libs.versions.toml")) // include from parent project
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
|
||||
plugins {
|
||||
`maven-publish`
|
||||
`java-library`
|
||||
id("net.kyori.indra")
|
||||
id("net.kyori.indra.publishing")
|
||||
id("com.gradleup.nmcp")
|
||||
}
|
||||
|
||||
val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class)
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.spigotApi)
|
||||
compileOnly(libs.bundles.adventure)
|
||||
|
||||
testImplementation(libs.spigotApi)
|
||||
testImplementation(libs.bundles.adventure)
|
||||
testImplementation(libs.junitJupiterApi)
|
||||
testRuntimeOnly(libs.junitJupiterEngine)
|
||||
}
|
||||
|
||||
indra {
|
||||
github("MegavexNetwork", "scoreboard-library") {
|
||||
ci(true)
|
||||
}
|
||||
mitLicense()
|
||||
reproducibleBuilds(true)
|
||||
|
||||
javaVersions {
|
||||
target(8)
|
||||
minimumToolchain(21)
|
||||
}
|
||||
|
||||
publishSnapshotsTo("forgejo", "https://git.megavex.net/api/packages/MegavexPublic/maven")
|
||||
configurePublications {
|
||||
pom {
|
||||
url = "https://github.com/MegavexNetwork/scoreboard-library"
|
||||
developers {
|
||||
developer {
|
||||
id = "vytskalt"
|
||||
name = "vytskalt"
|
||||
email = "vytskalt@protonmail.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nmcp {
|
||||
val centralUsername = findProperty("centralUsername") as String?
|
||||
val centralPassword = findProperty("centralPassword") as String?
|
||||
|
||||
if (centralUsername != null && centralPassword != null) {
|
||||
publishAllPublications {
|
||||
username = centralUsername
|
||||
password = centralPassword
|
||||
publicationType = "USER_MANAGED"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.compilerArgs = mutableListOf("-Xlint:-deprecation,-unchecked")
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.create<MavenPublication>("maven") {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("net.megavex.scoreboardlibrary.publish-conventions")
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.commons;
|
||||
|
||||
/**
|
||||
* Represents different strategies of rendering sidebar lines.
|
||||
*/
|
||||
public enum LineRenderingStrategy {
|
||||
/**
|
||||
* For versions older than 1.13, where team properties are stored as strings and have a limit of 16 characters.
|
||||
*/
|
||||
LEGACY,
|
||||
/**
|
||||
* For versions 1.13-1.20.2, where team properties are stored as components with no limits.
|
||||
*/
|
||||
MODERN,
|
||||
/**
|
||||
* For versions 1.20.3+, where the score display name can be used instead of team prefix team.
|
||||
* Not currently being used.
|
||||
*/
|
||||
POST_MODERN
|
||||
}
|
||||
-1
@@ -18,7 +18,6 @@ public final class LocaleProvider {
|
||||
return provider.apply(player);
|
||||
}
|
||||
|
||||
|
||||
private static @NotNull Function<Player, Locale> get() {
|
||||
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
|
||||
try {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.8.21"
|
||||
id("net.megavex.scoreboardlibrary.publish-conventions")
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
alias(libs.plugins.kotlin)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
Generated
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1722987190,
|
||||
"narHash": "sha256-68hmex5efCiM2aZlAAEcQgmFI4ZwWt8a80vOeB/5w3A=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "21cc704b5e918c5fbf4f9fff22b4ac2681706d90",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
|
||||
};
|
||||
|
||||
outputs = { nixpkgs, ... }: let
|
||||
forAllSystems = function:
|
||||
nixpkgs.lib.genAttrs [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
] (system:
|
||||
function (import nixpkgs {
|
||||
inherit system;
|
||||
}));
|
||||
in {
|
||||
devShells = forAllSystems (pkgs: {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgs.temurin-bin-21
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
[versions]
|
||||
adventure = "4.17.0"
|
||||
junitJupiter = "5.11.3"
|
||||
devBundle = "1.21.4-R0.1-20241208.061653-9" # find latest here: https://repo.papermc.io/repository/maven-snapshots/io/papermc/paper/dev-bundle/1.21.4-R0.1-SNAPSHOT/maven-metadata.xml
|
||||
|
||||
[libraries]
|
||||
spigotApi = "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" # do not update
|
||||
packetEvents = "com.github.retrooper:packetevents-spigot:2.6.0"
|
||||
buildIndra = { module = "net.kyori:indra-common", version = "3.1.3" }
|
||||
buildNmcp = "com.gradleup.nmcp:com.gradleup.nmcp.gradle.plugin:0.0.9"
|
||||
|
||||
adventureApi = { module = "net.kyori:adventure-api", version.ref = "adventure" }
|
||||
adventureTextSerializerGson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure" }
|
||||
adventureTextSerializerLegacy = { module = "net.kyori:adventure-text-serializer-legacy", version.ref = "adventure" }
|
||||
|
||||
junitJupiterApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junitJupiter" }
|
||||
junitJupiterEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junitJupiter" }
|
||||
|
||||
[plugins]
|
||||
kotlin = "org.jetbrains.kotlin.jvm:2.1.0"
|
||||
paperweight = "io.papermc.paperweight.userdev:1.7.7"
|
||||
|
||||
[bundles]
|
||||
adventure = [ "adventureApi", "adventureTextSerializerGson", "adventureTextSerializerLegacy" ]
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,5 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -80,13 +82,12 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -133,22 +134,29 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
@@ -205,6 +217,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
Vendored
+94
-89
@@ -1,89 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("net.megavex.scoreboardlibrary.publish-conventions")
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
+62
-19
@@ -9,6 +9,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public final class PacketAdapterLoader {
|
||||
private static final String MODERN = "modern",
|
||||
LEGACY = "legacy",
|
||||
PACKET_EVENTS = "packetevents";
|
||||
|
||||
private PacketAdapterLoader() {
|
||||
}
|
||||
|
||||
@@ -27,6 +31,11 @@ public final class PacketAdapterLoader {
|
||||
|
||||
private static @Nullable Class<?> findAndLoadImplementationClass() {
|
||||
String version = Bukkit.getServer().getBukkitVersion();
|
||||
int dashIndex = version.indexOf('-');
|
||||
if (dashIndex != -1) {
|
||||
version = version.substring(0, dashIndex);
|
||||
}
|
||||
|
||||
Class<?> nmsClass = tryLoadVersion(version);
|
||||
if (nmsClass != null) {
|
||||
return nmsClass;
|
||||
@@ -35,32 +44,66 @@ public final class PacketAdapterLoader {
|
||||
return tryLoadPacketEvents();
|
||||
}
|
||||
|
||||
private static @Nullable Class<?> tryLoadVersion(@NotNull String version) {
|
||||
private static @Nullable Class<?> tryLoadVersion(@NotNull String serverVersion) {
|
||||
// https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-legacy/
|
||||
// https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-10-1-15/
|
||||
// https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-16/
|
||||
switch (version) {
|
||||
case "1.8.8-R0.1-SNAPSHOT":
|
||||
return tryLoadImplementationClass("v1_8_R3");
|
||||
case "1.17-R0.1-SNAPSHOT":
|
||||
case "1.17.1-R0.1-SNAPSHOT":
|
||||
case "1.18-R0.1-SNAPSHOT":
|
||||
case "1.18.1-R0.1-SNAPSHOT":
|
||||
case "1.18.2-R0.1-SNAPSHOT":
|
||||
case "1.19-R0.1-SNAPSHOT":
|
||||
case "1.19.1-R0.1-SNAPSHOT":
|
||||
case "1.19.2-R0.1-SNAPSHOT":
|
||||
case "1.19.3-R0.1-SNAPSHOT":
|
||||
case "1.19.4-R0.1-SNAPSHOT":
|
||||
case "1.20-R0.1-SNAPSHOT":
|
||||
case "1.20.1-R0.1-SNAPSHOT":
|
||||
case "1.20.2-R0.1-SNAPSHOT":
|
||||
return tryLoadImplementationClass("modern");
|
||||
// https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-21/
|
||||
switch (serverVersion) {
|
||||
case "1.7.10":
|
||||
case "1.8":
|
||||
case "1.8.3":
|
||||
case "1.8.4":
|
||||
case "1.8.5":
|
||||
case "1.8.6":
|
||||
case "1.8.7":
|
||||
case "1.8.8":
|
||||
case "1.9":
|
||||
case "1.9.2":
|
||||
case "1.9.4":
|
||||
case "1.10.2":
|
||||
case "1.11":
|
||||
case "1.11.2":
|
||||
case "1.12":
|
||||
case "1.12.1":
|
||||
case "1.12.2":
|
||||
return tryLoadImplementationClass(LEGACY);
|
||||
case "1.17":
|
||||
case "1.17.1":
|
||||
case "1.18":
|
||||
case "1.18.1":
|
||||
case "1.18.2":
|
||||
case "1.19":
|
||||
case "1.19.1":
|
||||
case "1.19.2":
|
||||
case "1.19.3":
|
||||
case "1.19.4":
|
||||
case "1.20":
|
||||
case "1.20.1":
|
||||
case "1.20.2":
|
||||
case "1.20.3":
|
||||
case "1.20.4":
|
||||
case "1.20.5":
|
||||
case "1.20.6":
|
||||
case "1.21":
|
||||
case "1.21.1":
|
||||
case "1.21.2":
|
||||
case "1.21.3":
|
||||
case "1.21.4":
|
||||
return tryLoadImplementationClass(MODERN);
|
||||
default:
|
||||
// Hide from relocation checkers
|
||||
String property = "net.mega".concat("vex.scoreboardlibrary.forceModern");
|
||||
if (System.getProperty(property, "").equalsIgnoreCase("true")) {
|
||||
return tryLoadImplementationClass(MODERN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable Class<?> tryLoadPacketEvents() {
|
||||
Class<?> nmsClass = tryLoadImplementationClass("packetevents");
|
||||
Class<?> nmsClass = tryLoadImplementationClass(PACKET_EVENTS);
|
||||
if (nmsClass == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+15
-8
@@ -3,6 +3,7 @@ package net.megavex.scoreboardlibrary.implementation.objective;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveManager;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreboardObjective;
|
||||
import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.CollectionProvider;
|
||||
@@ -124,7 +125,7 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
return closed;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
public boolean tick() {
|
||||
while (true) {
|
||||
ObjectiveManagerTask task = taskQueue.poll();
|
||||
if (task == null) {
|
||||
@@ -132,7 +133,6 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
}
|
||||
|
||||
if (task instanceof ObjectiveManagerTask.Close) {
|
||||
library.objectiveManagers().remove(this);
|
||||
for (ScoreboardObjectiveImpl objective : objectives.values()) {
|
||||
objective.packetAdapter().remove(displayingPlayers);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
for (Player player : players) {
|
||||
Objects.requireNonNull(library.getPlayer(player)).objectiveManagerQueue().remove(this);
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
} else if (task instanceof ObjectiveManagerTask.AddPlayer) {
|
||||
Player player = ((ObjectiveManagerTask.AddPlayer) task).player();
|
||||
@NotNull ScoreboardLibraryPlayer slPlayer = library.getOrCreatePlayer(player);
|
||||
@@ -159,6 +159,11 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
Collection<Player> singleton = Collections.singleton(player);
|
||||
for (ScoreboardObjectiveImpl objective : objectives.values()) {
|
||||
objective.sendProperties(singleton, PropertiesPacketType.UPDATE);
|
||||
|
||||
for (Map.Entry<String, ObjectiveScore> entry : objective.scores().entrySet()) {
|
||||
ObjectiveScore score = entry.getValue();
|
||||
objective.packetAdapter().sendScore(singleton, entry.getKey(), score.value(), score.displayName(), score.format());
|
||||
}
|
||||
}
|
||||
} else if (task instanceof ObjectiveManagerTask.AddObjective) {
|
||||
ScoreboardObjectiveImpl objective = ((ObjectiveManagerTask.AddObjective) task).objective();
|
||||
@@ -173,9 +178,9 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
ObjectiveManagerTask.UpdateScore updateScoreTask = ((ObjectiveManagerTask.UpdateScore) task);
|
||||
ScoreboardObjectiveImpl objective = updateScoreTask.objective();
|
||||
String entry = updateScoreTask.entry();
|
||||
Integer score = updateScoreTask.score();
|
||||
ObjectiveScore score = updateScoreTask.score();
|
||||
if (score != null) {
|
||||
objective.packetAdapter().sendScore(displayingPlayers, entry, score);
|
||||
objective.packetAdapter().sendScore(displayingPlayers, entry, score.value(), score.displayName(), score.format());
|
||||
} else {
|
||||
objective.packetAdapter().removeScore(displayingPlayers, entry);
|
||||
}
|
||||
@@ -186,17 +191,19 @@ public class ObjectiveManagerImpl implements ObjectiveManager, PlayerDisplayable
|
||||
objective.packetAdapter().display(displayingPlayers, slot);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(@NotNull Player player) {
|
||||
public void display(@NotNull Player player) {
|
||||
displayingPlayers.add(player);
|
||||
Collection<Player> singleton = Collections.singleton(player);
|
||||
|
||||
for (ScoreboardObjectiveImpl objective : objectives.values()) {
|
||||
objective.sendProperties(singleton, PropertiesPacketType.CREATE);
|
||||
for (Map.Entry<String, Integer> entry : objective.scores().entrySet()) {
|
||||
objective.packetAdapter().sendScore(singleton, entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, ObjectiveScore> entry : objective.scores().entrySet()) {
|
||||
ObjectiveScore score = entry.getValue();
|
||||
objective.packetAdapter().sendScore(singleton, entry.getKey(), score.value(), score.displayName(), score.format());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.objective;
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -91,9 +92,9 @@ public class ObjectiveManagerTask {
|
||||
public static final class UpdateScore extends ObjectiveManagerTask {
|
||||
private final ScoreboardObjectiveImpl objective;
|
||||
private final String entry;
|
||||
private final Integer score;
|
||||
private final ObjectiveScore score;
|
||||
|
||||
public UpdateScore(@NotNull ScoreboardObjectiveImpl objective, @NotNull String entry, @Nullable Integer score) {
|
||||
public UpdateScore(@NotNull ScoreboardObjectiveImpl objective, @NotNull String entry, @Nullable ObjectiveScore score) {
|
||||
this.objective = objective;
|
||||
this.entry = entry;
|
||||
this.score = score;
|
||||
@@ -107,7 +108,7 @@ public class ObjectiveManagerTask {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public @Nullable Integer score() {
|
||||
public @Nullable ObjectiveScore score() {
|
||||
return score;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -4,6 +4,7 @@ import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.scheduler.RunningTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ObjectiveUpdaterTask implements Runnable {
|
||||
@@ -27,11 +28,19 @@ public class ObjectiveUpdaterTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
for (ObjectiveManagerImpl objectiveManager : scoreboardLibrary.objectiveManagers()) {
|
||||
Iterator<ObjectiveManagerImpl> iterator = scoreboardLibrary.objectiveManagers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ObjectiveManagerImpl objectiveManager = iterator.next();
|
||||
boolean result;
|
||||
try {
|
||||
objectiveManager.tick();
|
||||
result = objectiveManager.tick();
|
||||
} catch (Exception e) {
|
||||
scoreboardLibrary.plugin().getLogger().log(Level.SEVERE, "an error occurred while updating a ObjectiveManager instance", e);
|
||||
scoreboardLibrary.plugin().getLogger().log(Level.WARNING, "an error occurred while updating an ObjectiveManager instance", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-15
@@ -1,17 +1,18 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.objective;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreboardObjective;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.*;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
@@ -20,9 +21,10 @@ public class ScoreboardObjectiveImpl implements ScoreboardObjective {
|
||||
private final Queue<ObjectiveManagerTask> taskQueue;
|
||||
private final String name;
|
||||
|
||||
private final Map<String, Integer> scores = new HashMap<>();
|
||||
private final Map<String, ObjectiveScore> scores = new HashMap<>();
|
||||
private Component value = empty();
|
||||
private ObjectiveRenderType renderType = ObjectiveRenderType.INTEGER;
|
||||
private ScoreFormat defaultScoreFormat;
|
||||
private boolean closed;
|
||||
|
||||
public ScoreboardObjectiveImpl(@NotNull ObjectivePacketAdapter packetAdapter, @NotNull Queue<ObjectiveManagerTask> taskQueue, @NotNull String name) {
|
||||
@@ -35,7 +37,7 @@ public class ScoreboardObjectiveImpl implements ScoreboardObjective {
|
||||
return packetAdapter;
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Integer> scores() {
|
||||
public @NotNull Map<String, ObjectiveScore> scores() {
|
||||
return scores;
|
||||
}
|
||||
|
||||
@@ -53,9 +55,10 @@ public class ScoreboardObjectiveImpl implements ScoreboardObjective {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective value(@NotNull Component value) {
|
||||
if (!this.value.equals(value)) {
|
||||
this.value = value;
|
||||
public @NotNull ScoreboardObjective value(@NotNull ComponentLike value) {
|
||||
Component component = value.asComponent();
|
||||
if (!this.value.equals(component)) {
|
||||
this.value = component;
|
||||
if (!closed) {
|
||||
taskQueue.add(new ObjectiveManagerTask.UpdateObjective(this));
|
||||
}
|
||||
@@ -80,14 +83,27 @@ public class ScoreboardObjectiveImpl implements ScoreboardObjective {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer score(@NotNull String entry) {
|
||||
public @Nullable ScoreFormat defaultScoreFormat() {
|
||||
return defaultScoreFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultScoreFormat(@Nullable ScoreFormat defaultScoreFormat) {
|
||||
if (!Objects.equals(this.defaultScoreFormat, defaultScoreFormat)) {
|
||||
this.defaultScoreFormat = defaultScoreFormat;
|
||||
taskQueue.add(new ObjectiveManagerTask.UpdateObjective(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ObjectiveScore scoreInfo(@NotNull String entry) {
|
||||
return scores.get(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective score(@NotNull String entry, int score) {
|
||||
Integer oldScore = scores.put(entry, score);
|
||||
if (!closed && (oldScore == null || score != oldScore)) {
|
||||
public @NotNull ScoreboardObjective score(@NotNull String entry, ObjectiveScore score) {
|
||||
ObjectiveScore oldScore = scores.put(entry, score);
|
||||
if (!Objects.equals(oldScore, score)) {
|
||||
taskQueue.add(new ObjectiveManagerTask.UpdateScore(this, entry, score));
|
||||
}
|
||||
return this;
|
||||
@@ -95,13 +111,13 @@ public class ScoreboardObjectiveImpl implements ScoreboardObjective {
|
||||
|
||||
@Override
|
||||
public @NotNull ScoreboardObjective removeScore(@NotNull String entry) {
|
||||
if (scores.remove(entry) != null && !closed) {
|
||||
if (scores.remove(entry) != null) {
|
||||
taskQueue.add(new ObjectiveManagerTask.UpdateScore(this, entry, null));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void sendProperties(@NotNull Collection<Player> players, @NotNull PropertiesPacketType packetType) {
|
||||
packetAdapter.sendProperties(players, packetType, value, renderType);
|
||||
packetAdapter.sendProperties(players, packetType, value, renderType, defaultScoreFormat);
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -25,31 +25,36 @@ public class DisplayableQueue<T extends PlayerDisplayable> {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void add(@NotNull T manager) {
|
||||
if (queue.contains(manager)) {
|
||||
throw new RuntimeException("manager already registered");
|
||||
public synchronized void add(@NotNull T displayable) {
|
||||
if (queue.contains(displayable)) {
|
||||
throw new IllegalStateException("displayable already registered");
|
||||
}
|
||||
|
||||
queue.add(manager);
|
||||
queue.add(displayable);
|
||||
|
||||
if (current() == manager) {
|
||||
if (current() == displayable) {
|
||||
Player player = Bukkit.getPlayer(playerUuid);
|
||||
if (player != null) {
|
||||
manager.show(player);
|
||||
displayable.display(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void remove(@NotNull T manager) {
|
||||
if (!queue.remove(manager)) {
|
||||
throw new RuntimeException("manager not registered");
|
||||
public synchronized void remove(@NotNull T displayable) {
|
||||
boolean wasCurrent = displayable == current();
|
||||
if (!queue.remove(displayable)) {
|
||||
throw new IllegalStateException("displayable not registered");
|
||||
}
|
||||
|
||||
T newTeamManager = current();
|
||||
if (newTeamManager != null) {
|
||||
if (!wasCurrent) {
|
||||
return;
|
||||
}
|
||||
|
||||
T newDisplayable = current();
|
||||
if (newDisplayable != null) {
|
||||
Player player = Bukkit.getPlayer(playerUuid);
|
||||
if (player != null) {
|
||||
newTeamManager.show(player);
|
||||
newDisplayable.display(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PlayerDisplayable {
|
||||
void show(@NotNull Player player);
|
||||
void display(@NotNull Player player);
|
||||
}
|
||||
+58
-35
@@ -2,9 +2,12 @@ package net.megavex.scoreboardlibrary.implementation.sidebar;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.CollectionProvider;
|
||||
@@ -14,7 +17,7 @@ import net.megavex.scoreboardlibrary.implementation.player.PlayerDisplayable;
|
||||
import net.megavex.scoreboardlibrary.implementation.player.ScoreboardLibraryPlayer;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.LocaleLineHandler;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.PlayerNameProvider;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,7 +32,6 @@ import static net.kyori.adventure.text.Component.empty;
|
||||
public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
private final ScoreboardLibraryImpl scoreboardLibrary;
|
||||
private final ObjectivePacketAdapter packetAdapter;
|
||||
private final List<String> linePlayerNames;
|
||||
|
||||
private final GlobalLineInfo[] lines;
|
||||
private Component title = empty();
|
||||
@@ -43,15 +45,14 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
public AbstractSidebar(@NotNull ScoreboardLibraryImpl scoreboardLibrary, int maxLines) {
|
||||
this.scoreboardLibrary = scoreboardLibrary;
|
||||
|
||||
String objectiveName = UUID.randomUUID().toString().substring(0, 5);
|
||||
String objectiveName = RandomStringUtils.randomAlphanumeric(16);
|
||||
this.packetAdapter = scoreboardLibrary.packetAdapter().createObjectiveAdapter(objectiveName);
|
||||
this.linePlayerNames = PlayerNameProvider.provideLinePlayerNames(maxLines);
|
||||
this.lines = new GlobalLineInfo[maxLines];
|
||||
}
|
||||
|
||||
protected abstract @NotNull Set<Player> internalPlayers();
|
||||
|
||||
protected abstract void forEachSidebar(@NotNull Consumer<LocaleLineHandler> consumer);
|
||||
protected abstract void forEachLineHandler(@NotNull Consumer<LocaleLineHandler> consumer);
|
||||
|
||||
protected abstract @Nullable LocaleLineHandler addPlayer0(@NotNull Player player);
|
||||
|
||||
@@ -107,13 +108,18 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void line(@Range(from = 0, to = MAX_LINES - 1) int line, @Nullable Component value) {
|
||||
public final void line(@Range(from = 0, to = MAX_LINES - 1) int index, @Nullable ComponentLike value, @Nullable ScoreFormat scoreFormat) {
|
||||
checkClosed();
|
||||
|
||||
GlobalLineInfo globalLineInfo = getLineInfo(line);
|
||||
if (!Objects.equals(globalLineInfo.value(), value)) {
|
||||
globalLineInfo.value(value);
|
||||
taskQueue.add(new SidebarTask.UpdateLine(line));
|
||||
Component component = value == null ? null : value.asComponent();
|
||||
GlobalLineInfo globalLineInfo = getLineInfo(index);
|
||||
boolean updateValue = !Objects.equals(globalLineInfo.value(), component);
|
||||
boolean updateScore = !Objects.equals(globalLineInfo.scoreFormat(), scoreFormat);
|
||||
|
||||
if (updateValue || updateScore) {
|
||||
globalLineInfo.value(component);
|
||||
globalLineInfo.scoreFormat(scoreFormat);
|
||||
taskQueue.add(new SidebarTask.UpdateLine(index, updateValue, updateScore));
|
||||
updateScores();
|
||||
}
|
||||
}
|
||||
@@ -132,12 +138,13 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void title(@NotNull Component title) {
|
||||
public final void title(@NotNull ComponentLike title) {
|
||||
Preconditions.checkNotNull(title);
|
||||
checkClosed();
|
||||
|
||||
if (!Objects.equals(this.title, title)) {
|
||||
this.title = title;
|
||||
Component component = title.asComponent();
|
||||
if (!Objects.equals(this.title, component)) {
|
||||
this.title = component;
|
||||
taskQueue.add(SidebarTask.UpdateTitle.INSTANCE);
|
||||
}
|
||||
}
|
||||
@@ -158,16 +165,18 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
return taskQueue;
|
||||
}
|
||||
|
||||
public final void show(@NotNull Player player) {
|
||||
packetAdapter.sendProperties(players, PropertiesPacketType.CREATE, title, ObjectiveRenderType.INTEGER);
|
||||
@Override
|
||||
public final void display(@NotNull Player player) {
|
||||
Collection<Player> singleton = Collections.singleton(player);
|
||||
packetAdapter.sendProperties(singleton, PropertiesPacketType.CREATE, title, ObjectiveRenderType.INTEGER, ScoreFormat.blank());
|
||||
|
||||
LocaleLineHandler lineHandler = Objects.requireNonNull(addPlayer0(player));
|
||||
lineHandler.addPlayer(player);
|
||||
lineHandler.show(player);
|
||||
packetAdapter.display(Collections.singleton(player), ObjectiveDisplaySlot.sidebar());
|
||||
packetAdapter.display(singleton, ObjectiveDisplaySlot.sidebar());
|
||||
}
|
||||
|
||||
public final void tick() {
|
||||
public final boolean tick() {
|
||||
while (true) {
|
||||
SidebarTask task = taskQueue.poll();
|
||||
if (task == null) {
|
||||
@@ -175,33 +184,32 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
}
|
||||
|
||||
if (task instanceof SidebarTask.Close) {
|
||||
forEachSidebar(LocaleLineHandler::hide);
|
||||
forEachLineHandler(LocaleLineHandler::hide);
|
||||
packetAdapter.remove(internalPlayers());
|
||||
|
||||
for (Player player : internalPlayers()) {
|
||||
Objects.requireNonNull(scoreboardLibrary.getPlayer(player)).sidebarQueue().remove(this);
|
||||
}
|
||||
|
||||
return;
|
||||
return false;
|
||||
} else if (task instanceof SidebarTask.AddPlayer) {
|
||||
SidebarTask.AddPlayer addPlayerTask = (SidebarTask.AddPlayer) task;
|
||||
ScoreboardLibraryPlayer slPlayer = scoreboardLibrary.getOrCreatePlayer(addPlayerTask.player());
|
||||
slPlayer.sidebarQueue().add(this);
|
||||
} else if (task instanceof SidebarTask.RemovePlayer) {
|
||||
SidebarTask.RemovePlayer removePlayerTask = (SidebarTask.RemovePlayer) task;
|
||||
LocaleLineHandler lineHandler = removePlayer0(removePlayerTask.player());
|
||||
if (lineHandler == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lineHandler.hide(removePlayerTask.player());
|
||||
lineHandler.removePlayer(removePlayerTask.player());
|
||||
packetAdapter.remove(Collections.singleton(removePlayerTask.player()));
|
||||
LocaleLineHandler lineHandler = removePlayer0(removePlayerTask.player());
|
||||
if (lineHandler != null) {
|
||||
lineHandler.hide(removePlayerTask.player());
|
||||
lineHandler.removePlayer(removePlayerTask.player());
|
||||
packetAdapter.remove(Collections.singleton(removePlayerTask.player()));
|
||||
}
|
||||
|
||||
Objects.requireNonNull(scoreboardLibrary.getPlayer(removePlayerTask.player())).sidebarQueue().remove(this);
|
||||
} else if (task instanceof SidebarTask.ReloadPlayer) {
|
||||
SidebarTask.ReloadPlayer reloadPlayerTask = (SidebarTask.ReloadPlayer) task;
|
||||
@Nullable LocaleLineHandler lineHandler = removePlayer0(reloadPlayerTask.player());
|
||||
LocaleLineHandler lineHandler = removePlayer0(reloadPlayerTask.player());
|
||||
if (lineHandler == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -210,20 +218,32 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
lineHandler.hide(reloadPlayerTask.player());
|
||||
lineHandler.removePlayer(reloadPlayerTask.player());
|
||||
|
||||
show(reloadPlayerTask.player());
|
||||
display(reloadPlayerTask.player());
|
||||
} else if (task instanceof SidebarTask.UpdateLine) {
|
||||
SidebarTask.UpdateLine updateLineTask = (SidebarTask.UpdateLine) task;
|
||||
forEachSidebar(sidebar -> {
|
||||
Component value = lines[updateLineTask.line()].value();
|
||||
Component renderedValue = value == null ? null : GlobalTranslator.render(value, sidebar.locale());
|
||||
sidebar.updateLine(updateLineTask.line(), renderedValue);
|
||||
forEachLineHandler(sidebar -> {
|
||||
if (updateLineTask.updateValue()) {
|
||||
Component value = lines[updateLineTask.line()].value();
|
||||
Component renderedValue = value == null ? null : GlobalTranslator.render(value, sidebar.locale());
|
||||
sidebar.updateLine(updateLineTask.line(), renderedValue);
|
||||
}
|
||||
|
||||
if (updateLineTask.updateScore()) {
|
||||
sidebar.updateScoreFormat(updateLineTask.line());
|
||||
}
|
||||
});
|
||||
} else if (task instanceof SidebarTask.UpdateScores) {
|
||||
forEachSidebar(LocaleLineHandler::updateScores);
|
||||
forEachLineHandler(LocaleLineHandler::updateScores);
|
||||
for (GlobalLineInfo line : lines) {
|
||||
if (line != null) {
|
||||
line.updateScore(false);
|
||||
}
|
||||
}
|
||||
} else if (task instanceof SidebarTask.UpdateTitle) {
|
||||
packetAdapter.sendProperties(internalPlayers(), PropertiesPacketType.UPDATE, title, ObjectiveRenderType.INTEGER);
|
||||
packetAdapter.sendProperties(internalPlayers(), PropertiesPacketType.UPDATE, title, ObjectiveRenderType.INTEGER, ScoreFormat.blank());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateScores() {
|
||||
@@ -258,7 +278,10 @@ public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
|
||||
private @NotNull GlobalLineInfo getLineInfo(int line) {
|
||||
GlobalLineInfo globalLineInfo = lines[line];
|
||||
if (globalLineInfo == null) {
|
||||
globalLineInfo = lines[line] = new GlobalLineInfo(this, linePlayerNames.get(line), line);
|
||||
char c = Character.toChars(128 + line)[0];
|
||||
String playerName = "" + LegacyComponentSerializer.SECTION_CHAR + c;
|
||||
|
||||
globalLineInfo = lines[line] = new GlobalLineInfo(this, playerName, line);
|
||||
updateScores();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ public class PlayerDependantLocaleSidebar extends AbstractSidebar {
|
||||
private final Map<Player, LocaleLineHandler> playerMap = new HashMap<>();
|
||||
private final Map<Locale, LocaleLineHandler> localeMap = new HashMap<>();
|
||||
|
||||
public PlayerDependantLocaleSidebar(ScoreboardLibraryImpl scoreboardLibrary, int maxLines) {
|
||||
public PlayerDependantLocaleSidebar(@NotNull ScoreboardLibraryImpl scoreboardLibrary, int maxLines) {
|
||||
super(scoreboardLibrary, maxLines);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PlayerDependantLocaleSidebar extends AbstractSidebar {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forEachSidebar(@NotNull Consumer<LocaleLineHandler> consumer) {
|
||||
protected void forEachLineHandler(@NotNull Consumer<LocaleLineHandler> consumer) {
|
||||
if (localeMap != null) {
|
||||
for (LocaleLineHandler value : localeMap.values()) {
|
||||
consumer.accept(value);
|
||||
|
||||
+12
-1
@@ -52,14 +52,25 @@ public class SidebarTask {
|
||||
|
||||
public static final class UpdateLine extends SidebarTask {
|
||||
private final int line;
|
||||
private final boolean updateValue, updateScore;
|
||||
|
||||
public UpdateLine(int line) {
|
||||
public UpdateLine(int line, boolean updateValue, boolean updateScore) {
|
||||
this.line = line;
|
||||
this.updateValue = updateValue;
|
||||
this.updateScore = updateScore;
|
||||
}
|
||||
|
||||
public int line() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public boolean updateValue() {
|
||||
return updateValue;
|
||||
}
|
||||
|
||||
public boolean updateScore() {
|
||||
return updateScore;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class UpdateScores extends SidebarTask {
|
||||
|
||||
+11
-2
@@ -4,6 +4,7 @@ import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.scheduler.RunningTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SidebarUpdaterTask implements Runnable {
|
||||
@@ -27,11 +28,19 @@ public class SidebarUpdaterTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
for (AbstractSidebar sidebar : scoreboardLibrary.sidebars()) {
|
||||
Iterator<AbstractSidebar> iterator = scoreboardLibrary.sidebars().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AbstractSidebar sidebar = iterator.next();
|
||||
boolean result;
|
||||
try {
|
||||
sidebar.tick();
|
||||
result = sidebar.tick();
|
||||
} catch (Exception e) {
|
||||
scoreboardLibrary.plugin().getLogger().log(Level.WARNING, "an error occurred while updating a Sidebar instance", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -16,11 +16,11 @@ public class SingleLocaleSidebar extends AbstractSidebar {
|
||||
private final LocaleLineHandler sidebar;
|
||||
private final Set<Player> internalPlayers;
|
||||
|
||||
public SingleLocaleSidebar(@NotNull ScoreboardLibraryImpl scoreboardLibrary, int size, Locale locale) {
|
||||
public SingleLocaleSidebar(@NotNull ScoreboardLibraryImpl scoreboardLibrary, int size, @NotNull Locale locale) {
|
||||
super(scoreboardLibrary, size);
|
||||
this.locale = locale;
|
||||
this.sidebar = new LocaleLineHandler(this, locale());
|
||||
this.internalPlayers = CollectionProvider.set(1);
|
||||
this.sidebar = new LocaleLineHandler(this, locale);
|
||||
this.internalPlayers = CollectionProvider.set(8);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,19 +36,17 @@ public class SingleLocaleSidebar extends AbstractSidebar {
|
||||
@Override
|
||||
protected @Nullable LocaleLineHandler addPlayer0(@NotNull Player player) {
|
||||
if (!internalPlayers.add(player)) return null;
|
||||
|
||||
return sidebar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable LocaleLineHandler removePlayer0(@NotNull Player player) {
|
||||
if (!internalPlayers.remove(player)) return null;
|
||||
|
||||
return sidebar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forEachSidebar(@NotNull Consumer<LocaleLineHandler> consumer) {
|
||||
protected void forEachLineHandler(@NotNull Consumer<LocaleLineHandler> consumer) {
|
||||
consumer.accept(sidebar);
|
||||
}
|
||||
}
|
||||
+10
@@ -1,6 +1,7 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.AbstractSidebar;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -11,6 +12,7 @@ public class GlobalLineInfo {
|
||||
private final int line;
|
||||
private final TeamsPacketAdapter packetAdapter;
|
||||
private Component value;
|
||||
private ScoreFormat scoreFormat;
|
||||
private int objectiveScore;
|
||||
private boolean updateScore;
|
||||
|
||||
@@ -43,6 +45,14 @@ public class GlobalLineInfo {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public @Nullable ScoreFormat scoreFormat() {
|
||||
return scoreFormat;
|
||||
}
|
||||
|
||||
public void scoreFormat(@Nullable ScoreFormat scoreFormat) {
|
||||
this.scoreFormat = scoreFormat;
|
||||
}
|
||||
|
||||
public int objectiveScore() {
|
||||
return objectiveScore;
|
||||
}
|
||||
|
||||
+51
-60
@@ -1,8 +1,8 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LineRenderingStrategy;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.AbstractSidebar;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.LineType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -12,107 +12,98 @@ import java.util.Locale;
|
||||
public class LocaleLineHandler {
|
||||
private final AbstractSidebar sidebar;
|
||||
private final Locale locale;
|
||||
private SidebarLineHandler modernLineHandler, legacyLineHandler;
|
||||
private final SidebarLineHandler[] lineHandlers;
|
||||
|
||||
public LocaleLineHandler(AbstractSidebar sidebar, Locale locale) {
|
||||
public LocaleLineHandler(@NotNull AbstractSidebar sidebar, @NotNull Locale locale) {
|
||||
this.sidebar = sidebar;
|
||||
this.locale = locale;
|
||||
this.lineHandlers = new SidebarLineHandler[LineRenderingStrategy.values().length];
|
||||
}
|
||||
|
||||
public AbstractSidebar sidebar() {
|
||||
public @NotNull AbstractSidebar sidebar() {
|
||||
return sidebar;
|
||||
}
|
||||
|
||||
public Locale locale() {
|
||||
public @NotNull Locale locale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public boolean hasPlayers() {
|
||||
return (modernLineHandler != null && !modernLineHandler.players().isEmpty()) || (legacyLineHandler != null && !legacyLineHandler.players().isEmpty());
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null && !lineHandler.players().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addPlayer(@NotNull Player player) {
|
||||
boolean isLegacy = sidebar.scoreboardLibrary().packetAdapter().isLegacy(player);
|
||||
LineType lineType = isLegacy ? LineType.LEGACY : LineType.MODERN;
|
||||
lineHandler(lineType).players().add(player);
|
||||
LineRenderingStrategy strategy = sidebar.scoreboardLibrary().packetAdapter().lineRenderingStrategy(player);
|
||||
lineHandler(strategy).players().add(player);
|
||||
}
|
||||
|
||||
public void removePlayer(@NotNull Player player) {
|
||||
if (modernLineHandler != null && modernLineHandler.players().remove(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (legacyLineHandler != null) {
|
||||
legacyLineHandler.players().remove(player);
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null && lineHandler.players().remove(player)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull SidebarLineHandler lineHandler(@NotNull LineType lineType) {
|
||||
switch (lineType) {
|
||||
case MODERN: {
|
||||
if (modernLineHandler == null) {
|
||||
modernLineHandler = new SidebarLineHandler(LineType.MODERN, this);
|
||||
}
|
||||
|
||||
return modernLineHandler;
|
||||
}
|
||||
case LEGACY: {
|
||||
if (legacyLineHandler == null) {
|
||||
legacyLineHandler = new SidebarLineHandler(LineType.LEGACY, this);
|
||||
}
|
||||
|
||||
return legacyLineHandler;
|
||||
}
|
||||
public @NotNull SidebarLineHandler lineHandler(@NotNull LineRenderingStrategy lineType) {
|
||||
SidebarLineHandler lineHandler = lineHandlers[lineType.ordinal()];
|
||||
if (lineHandler == null) {
|
||||
lineHandler = lineHandlers[lineType.ordinal()] = new SidebarLineHandler(lineType, this);
|
||||
}
|
||||
return lineHandler;
|
||||
}
|
||||
|
||||
throw new RuntimeException();
|
||||
public void updateScoreFormat(int lineIndex) {
|
||||
SidebarLineHandler lineHandler = lineHandlers[LineRenderingStrategy.MODERN.ordinal()];
|
||||
if (lineHandler != null) {
|
||||
lineHandler.updateScore(lineIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLine(int lineIndex, Component renderedValue) {
|
||||
if (modernLineHandler != null) {
|
||||
modernLineHandler.setLine(lineIndex, renderedValue);
|
||||
modernLineHandler.updateLine(lineIndex);
|
||||
}
|
||||
|
||||
if (legacyLineHandler != null) {
|
||||
legacyLineHandler.setLine(lineIndex, renderedValue);
|
||||
legacyLineHandler.updateLine(lineIndex);
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null) {
|
||||
lineHandler.setLine(lineIndex, renderedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScores() {
|
||||
if (modernLineHandler != null) {
|
||||
modernLineHandler.updateScores();
|
||||
}
|
||||
|
||||
if (legacyLineHandler != null) {
|
||||
legacyLineHandler.updateScores();
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null) {
|
||||
lineHandler.updateScores();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void show(Player player) {
|
||||
if (modernLineHandler != null && modernLineHandler.players().contains(player)) {
|
||||
modernLineHandler.show(Collections.singleton(player));
|
||||
} else if (legacyLineHandler != null && legacyLineHandler.players().contains(player)) {
|
||||
legacyLineHandler.show(Collections.singleton(player));
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null && lineHandler.players().contains(player)) {
|
||||
lineHandler.show(Collections.singleton(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hide(Player player) {
|
||||
if (modernLineHandler != null && modernLineHandler.players().contains(player)) {
|
||||
modernLineHandler.hide(Collections.singleton(player));
|
||||
} else if (legacyLineHandler != null && legacyLineHandler.players().contains(player)) {
|
||||
legacyLineHandler.hide(Collections.singleton(player));
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null && lineHandler.players().contains(player)) {
|
||||
lineHandler.hide(Collections.singleton(player));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
if (modernLineHandler != null) {
|
||||
modernLineHandler.hide(modernLineHandler.players());
|
||||
}
|
||||
|
||||
if (legacyLineHandler != null) {
|
||||
legacyLineHandler.hide(legacyLineHandler.players());
|
||||
for (SidebarLineHandler lineHandler : lineHandlers) {
|
||||
if (lineHandler != null) {
|
||||
lineHandler.hide(lineHandler.players());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line;
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerNameProvider {
|
||||
private static final ChatColor[] CHAT_COLORS = ChatColor.values();
|
||||
private static final List<String> DEFAULT_NAMES = createLinePlayerNames(Sidebar.MAX_LINES);
|
||||
|
||||
private PlayerNameProvider() {
|
||||
}
|
||||
|
||||
public static @NotNull @Unmodifiable List<String> provideLinePlayerNames(int maxLines) {
|
||||
return maxLines <= Sidebar.MAX_LINES ? DEFAULT_NAMES : createLinePlayerNames(maxLines);
|
||||
}
|
||||
|
||||
private static @NotNull @Unmodifiable List<String> createLinePlayerNames(int maxLines) {
|
||||
List<String> result = new ArrayList<>(maxLines);
|
||||
|
||||
int i = 0;
|
||||
while (result.size() < maxLines) {
|
||||
for (ChatColor color : CHAT_COLORS) {
|
||||
String legacy = color.toString();
|
||||
String newStr = i == 0 ? legacy : result.get(i - 1) + legacy;
|
||||
|
||||
if (!result.contains(newStr)) {
|
||||
result.add(newStr);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
}
|
||||
+38
-28
@@ -3,8 +3,11 @@ package net.megavex.scoreboardlibrary.implementation.sidebar.line;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.CollectionProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.LineType;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LineRenderingStrategy;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.LegacyLocaleLine;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.LocaleLine;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.ModernLocaleLine;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.locale.PostModernLocaleLine;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -12,13 +15,13 @@ import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class SidebarLineHandler {
|
||||
private final LineType lineType;
|
||||
private final LineRenderingStrategy strategy;
|
||||
private final LocaleLineHandler localeLineHandler;
|
||||
private final Set<Player> players = CollectionProvider.set(1);
|
||||
private final LocaleLine<?>[] lines;
|
||||
private final LocaleLine[] lines;
|
||||
|
||||
public SidebarLineHandler(@NotNull LineType lineType, @NotNull LocaleLineHandler localeLineHandler) {
|
||||
this.lineType = lineType;
|
||||
public SidebarLineHandler(@NotNull LineRenderingStrategy strategy, @NotNull LocaleLineHandler localeLineHandler) {
|
||||
this.strategy = strategy;
|
||||
this.localeLineHandler = localeLineHandler;
|
||||
this.lines = new LocaleLine[localeLineHandler.sidebar().maxLines()];
|
||||
|
||||
@@ -26,7 +29,7 @@ public class SidebarLineHandler {
|
||||
if (line != null) {
|
||||
Component value = line.value();
|
||||
if (value != null) {
|
||||
setLine(line.line(), GlobalTranslator.render(value, localeLineHandler.locale()), false);
|
||||
setLine(line.line(), GlobalTranslator.render(value, localeLineHandler.locale()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,35 +43,28 @@ public class SidebarLineHandler {
|
||||
return players;
|
||||
}
|
||||
|
||||
public void updateLine(int lineIndex) {
|
||||
LocaleLine<?> line = lines[lineIndex];
|
||||
if (line != null) {
|
||||
line.updateTeam();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScores() {
|
||||
for (LocaleLine<?> line : lines) {
|
||||
for (LocaleLine line : lines) {
|
||||
if (line != null && line.info().updateScore()) {
|
||||
line.sendScore(players);
|
||||
line.info().updateScore(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLine(int line, Component renderedLine) {
|
||||
setLine(line, renderedLine, true);
|
||||
public void updateScore(int line) {
|
||||
LocaleLine localeLine = lines[line];
|
||||
localeLine.sendScore(players);
|
||||
}
|
||||
|
||||
private void setLine(int line, Component renderedLine, boolean sendPackets) {
|
||||
LocaleLine<?> localeLine = lines[line];
|
||||
public void setLine(int line, Component renderedLine) {
|
||||
LocaleLine localeLine = lines[line];
|
||||
if (renderedLine == null && localeLine == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newlyCreated = false;
|
||||
if (localeLine == null) {
|
||||
lines[line] = localeLine = lineType.create(localeLineHandler.sidebar().lines()[line], this);
|
||||
lines[line] = localeLine = createLine(strategy, localeLineHandler.sidebar().lines()[line]);
|
||||
newlyCreated = true;
|
||||
}
|
||||
|
||||
@@ -78,17 +74,18 @@ public class SidebarLineHandler {
|
||||
localeLine.value(renderedLine);
|
||||
}
|
||||
|
||||
if (sendPackets) {
|
||||
if (renderedLine == null) {
|
||||
localeLine.hide(players);
|
||||
} else if (newlyCreated) {
|
||||
localeLine.show(players);
|
||||
}
|
||||
if (renderedLine == null) {
|
||||
localeLine.hide(players);
|
||||
} else if (newlyCreated) {
|
||||
localeLine.resetOldPlayer();
|
||||
localeLine.show(players);
|
||||
} else {
|
||||
localeLine.updateTeam();
|
||||
}
|
||||
}
|
||||
|
||||
public void show(Collection<Player> players) {
|
||||
for (LocaleLine<?> line : lines) {
|
||||
for (LocaleLine line : lines) {
|
||||
if (line != null) {
|
||||
line.show(players);
|
||||
}
|
||||
@@ -96,10 +93,23 @@ public class SidebarLineHandler {
|
||||
}
|
||||
|
||||
public void hide(Collection<Player> players) {
|
||||
for (LocaleLine<?> line : lines) {
|
||||
for (LocaleLine line : lines) {
|
||||
if (line != null) {
|
||||
line.hide(players);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull LocaleLine createLine(@NotNull LineRenderingStrategy strategy, @NotNull GlobalLineInfo line) {
|
||||
switch (strategy) {
|
||||
case LEGACY:
|
||||
return new LegacyLocaleLine(line, this);
|
||||
case MODERN:
|
||||
return new ModernLocaleLine(line, this);
|
||||
case POST_MODERN:
|
||||
return new PostModernLocaleLine(line, this);
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
-22
@@ -1,8 +1,11 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line.locale;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
@@ -17,7 +20,8 @@ import java.util.Set;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
|
||||
|
||||
class LegacyLocaleLine implements LocaleLine<String> {
|
||||
// Implementation for versions below 1.13
|
||||
public class LegacyLocaleLine implements LocaleLine, ImmutableTeamProperties<String> {
|
||||
private final GlobalLineInfo info;
|
||||
private final SidebarLineHandler handler;
|
||||
private final TeamDisplayPacketAdapter packetAdapter;
|
||||
@@ -30,7 +34,7 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
this.handler = handler;
|
||||
this.player = info.player();
|
||||
this.packetAdapter = info.packetAdapter().createLegacyTeamDisplayAdapter(this);
|
||||
packetAdapter.updateTeamPackets(entries());
|
||||
packetAdapter.updateTeamPackets();
|
||||
}
|
||||
|
||||
public @NotNull GlobalLineInfo info() {
|
||||
@@ -53,17 +57,16 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<String> entries() {
|
||||
return Collections.singleton(player);
|
||||
public @NotNull Collection<String> syncedEntries() {
|
||||
return ImmutableList.of(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void value(@NotNull Component renderedComponent) {
|
||||
// I really need to rewrite this
|
||||
String legacyValue = legacySection().serialize(renderedComponent);
|
||||
|
||||
@NotNull String legacyValue = legacySection().serialize(renderedComponent);
|
||||
|
||||
oldPlayer = player;
|
||||
String prevPlayer = player;
|
||||
|
||||
if (legacyValue.length() <= 16) {
|
||||
this.prefix = legacyValue;
|
||||
@@ -79,7 +82,7 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
this.prefix = legacyValue.substring(0, prefixEnd);
|
||||
|
||||
String last = prefix + LegacyComponentSerializer.SECTION_CHAR + (endsWithSection ? legacyValue.charAt(16) : "");
|
||||
this.player = info.player() + ChatColor.RESET + ChatColor.getLastColors(last);
|
||||
this.player = info.player() + ChatColor.getLastColors(last);
|
||||
|
||||
int playerEnd = prefixEnd;
|
||||
if (legacyValue.length() > 32) {
|
||||
@@ -90,11 +93,10 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
player += legacyValue.substring(prefixEnd, playerEnd);
|
||||
}
|
||||
|
||||
this.suffix = legacyValue.substring(playerEnd + (endsWithSection ? 2 : 0));
|
||||
this.suffix = ChatColor.getLastColors(this.player) + legacyValue.substring(playerEnd + (endsWithSection ? 2 : 0));
|
||||
if (suffix.length() > 16) {
|
||||
String newSuffix = suffix.substring(0, 16);
|
||||
if (newSuffix.endsWith(String.valueOf(LegacyComponentSerializer.SECTION_CHAR)) &&
|
||||
ChatColor.getByChar(suffix.charAt(16)) != null) {
|
||||
if (newSuffix.endsWith(String.valueOf(LegacyComponentSerializer.SECTION_CHAR))) {
|
||||
newSuffix = newSuffix.substring(0, 15);
|
||||
}
|
||||
|
||||
@@ -104,8 +106,8 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
|
||||
currentValue = legacyValue;
|
||||
|
||||
if (oldPlayer.equals(player)) {
|
||||
oldPlayer = null;
|
||||
if (!player.equals(prevPlayer)) {
|
||||
oldPlayer = prevPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,26 +115,32 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
public void updateTeam() {
|
||||
Set<Player> players = handler.players();
|
||||
if (oldPlayer != null) {
|
||||
ObjectivePacketAdapter pd = handler.localeLineHandler().sidebar().packetAdapter();
|
||||
|
||||
packetAdapter.sendEntries(EntriesPacketType.REMOVE, players, Collections.singleton(oldPlayer));
|
||||
handler.localeLineHandler().sidebar().packetAdapter().removeScore(players, oldPlayer);
|
||||
pd.removeScore(players, oldPlayer);
|
||||
oldPlayer = null;
|
||||
|
||||
Collection<String> entries = entries();
|
||||
packetAdapter.updateTeamPackets(entries);
|
||||
packetAdapter.sendEntries(EntriesPacketType.ADD, players, entries);
|
||||
handler.localeLineHandler().sidebar().packetAdapter().sendScore(players, player, info.objectiveScore());
|
||||
packetAdapter.sendEntries(EntriesPacketType.ADD, players, Collections.singleton(player));
|
||||
pd.sendScore(players, player, info.objectiveScore(), null, null);
|
||||
}
|
||||
|
||||
packetAdapter.sendProperties(PropertiesPacketType.UPDATE, players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetOldPlayer() {
|
||||
oldPlayer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players) {
|
||||
ObjectivePacketAdapter pd = handler.localeLineHandler().sidebar().packetAdapter();
|
||||
if (oldPlayer != null) {
|
||||
handler.localeLineHandler().sidebar().packetAdapter().removeScore(players, oldPlayer);
|
||||
pd.removeScore(players, oldPlayer);
|
||||
}
|
||||
|
||||
handler.localeLineHandler().sidebar().packetAdapter().sendScore(players, player, info.objectiveScore());
|
||||
pd.sendScore(players, player, info.objectiveScore(), null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,11 +151,12 @@ class LegacyLocaleLine implements LocaleLine<String> {
|
||||
|
||||
@Override
|
||||
public void hide(@NotNull Collection<Player> players) {
|
||||
ObjectivePacketAdapter pd = handler.localeLineHandler().sidebar().packetAdapter();
|
||||
if (oldPlayer != null) {
|
||||
handler.localeLineHandler().sidebar().packetAdapter().removeScore(players, oldPlayer);
|
||||
pd.removeScore(players, oldPlayer);
|
||||
}
|
||||
|
||||
handler.localeLineHandler().sidebar().packetAdapter().removeScore(players, player);
|
||||
pd.removeScore(players, player);
|
||||
info.packetAdapter().removeTeam(players);
|
||||
}
|
||||
}
|
||||
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line.locale;
|
||||
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.AbstractSidebar;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.SidebarLineHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public enum LineType {
|
||||
MODERN(ModernLocaleLine::new),
|
||||
LEGACY(LegacyLocaleLine::new);
|
||||
|
||||
private final BiFunction<GlobalLineInfo, SidebarLineHandler, LocaleLine<?>> constructor;
|
||||
|
||||
LineType(BiFunction<GlobalLineInfo, SidebarLineHandler, LocaleLine<?>> constructor) {
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
public static LineType getType(AbstractSidebar sidebar, Player player) {
|
||||
return sidebar.scoreboardLibrary().packetAdapter().isLegacy(player) ? LEGACY : MODERN;
|
||||
}
|
||||
|
||||
public LocaleLine<?> create(GlobalLineInfo line, SidebarLineHandler localeLineHandler) {
|
||||
return constructor.apply(line, localeLineHandler);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,20 +1,22 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line.locale;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface LocaleLine<C> extends ImmutableTeamProperties<C> {
|
||||
public interface LocaleLine {
|
||||
@NotNull GlobalLineInfo info();
|
||||
|
||||
void value(@NotNull Component renderedComponent);
|
||||
|
||||
void updateTeam();
|
||||
|
||||
default void resetOldPlayer() {
|
||||
}
|
||||
|
||||
void sendScore(@NotNull Collection<Player> players);
|
||||
|
||||
void show(@NotNull Collection<Player> players);
|
||||
|
||||
+12
-8
@@ -1,6 +1,8 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line.locale;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
@@ -9,12 +11,11 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
// Implementation for versions above 1.12.2
|
||||
class ModernLocaleLine implements LocaleLine<Component> {
|
||||
// Implementation for versions above 1.13
|
||||
public class ModernLocaleLine implements LocaleLine, ImmutableTeamProperties<Component> {
|
||||
private final GlobalLineInfo info;
|
||||
private final SidebarLineHandler handler;
|
||||
private final Collection<String> entries;
|
||||
@@ -23,9 +24,9 @@ class ModernLocaleLine implements LocaleLine<Component> {
|
||||
public ModernLocaleLine(GlobalLineInfo info, SidebarLineHandler handler) {
|
||||
this.info = info;
|
||||
this.handler = handler;
|
||||
this.entries = Collections.singleton(info.player());
|
||||
this.entries = ImmutableList.of(info.player());
|
||||
this.packetAdapter = info.packetAdapter().createTeamDisplayAdapter(this);
|
||||
packetAdapter.updateTeamPackets(entries);
|
||||
packetAdapter.updateTeamPackets();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,13 +40,16 @@ class ModernLocaleLine implements LocaleLine<Component> {
|
||||
|
||||
@Override
|
||||
public void updateTeam() {
|
||||
packetAdapter.updateTeamPackets(entries);
|
||||
packetAdapter.updateTeamPackets();
|
||||
packetAdapter.sendProperties(PropertiesPacketType.UPDATE, handler.players());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players) {
|
||||
handler.localeLineHandler().sidebar().packetAdapter().sendScore(players, info.player(), info.objectiveScore());
|
||||
handler.localeLineHandler()
|
||||
.sidebar()
|
||||
.packetAdapter()
|
||||
.sendScore(players, info.player(), info.objectiveScore(), null, info.scoreFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +65,7 @@ class ModernLocaleLine implements LocaleLine<Component> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<String> entries() {
|
||||
public @NotNull Collection<String> syncedEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line.locale;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
|
||||
import net.megavex.scoreboardlibrary.implementation.sidebar.line.SidebarLineHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
// Implementation for versions 1.20.3+
|
||||
// This is not yet being used as it might break on servers with plugins such as ViaBackwards,
|
||||
// however it will once Mojang decides to remove legacy chat format support
|
||||
public class PostModernLocaleLine implements LocaleLine {
|
||||
private final GlobalLineInfo info;
|
||||
private final SidebarLineHandler handler;
|
||||
|
||||
public PostModernLocaleLine(GlobalLineInfo info, SidebarLineHandler handler) {
|
||||
this.info = info;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull GlobalLineInfo info() {
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void value(@NotNull Component renderedComponent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTeam() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players) {
|
||||
handler.localeLineHandler()
|
||||
.sidebar()
|
||||
.packetAdapter()
|
||||
.sendScore(players, info.player(), info.objectiveScore(), info.value(), info.scoreFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(@NotNull Collection<Player> players) {
|
||||
sendScore(players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide(@NotNull Collection<Player> players) {
|
||||
handler.localeLineHandler().sidebar().packetAdapter().removeScore(players, info.player());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -111,8 +111,8 @@ public class ScoreboardTeamImpl implements ScoreboardTeam {
|
||||
Collection<Player> singleton = Collections.singleton(player);
|
||||
newTeamDisplay.packetAdapter().sendProperties(PropertiesPacketType.UPDATE, singleton);
|
||||
|
||||
Collection<String> oldEntries = oldTeamDisplay.entries();
|
||||
Collection<String> newEntries = newTeamDisplay.entries();
|
||||
Collection<String> oldEntries = oldTeamDisplay.syncedEntries();
|
||||
Collection<String> newEntries = newTeamDisplay.syncedEntries();
|
||||
|
||||
if (oldEntries.isEmpty()) {
|
||||
newTeamDisplay.packetAdapter().sendEntries(EntriesPacketType.ADD, singleton, newEntries);
|
||||
|
||||
+41
-15
@@ -2,6 +2,7 @@ package net.megavex.scoreboardlibrary.implementation.team;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamDisplay;
|
||||
@@ -9,6 +10,8 @@ import net.megavex.scoreboardlibrary.api.team.enums.CollisionRule;
|
||||
import net.megavex.scoreboardlibrary.api.team.enums.NameTagVisibility;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.CollectionProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,7 +25,8 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
private final ScoreboardTeamImpl team;
|
||||
private final TeamDisplayPacketAdapter packetAdapter;
|
||||
private final Set<Player> players = CollectionProvider.set(4);
|
||||
private final Set<String> entries = CollectionProvider.set(4);
|
||||
private final List<String> entries = CollectionProvider.list(4);
|
||||
private final List<String> syncedEntries = CollectionProvider.list(4);
|
||||
private Component displayName = empty(),
|
||||
prefix = empty(),
|
||||
suffix = empty();
|
||||
@@ -34,7 +38,7 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
public TeamDisplayImpl(@NotNull ScoreboardTeamImpl team) {
|
||||
this.team = team;
|
||||
this.packetAdapter = team.packetAdapter().createTeamDisplayAdapter(this);
|
||||
updateTeamPackets();
|
||||
packetAdapter.updateTeamPackets();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,12 +48,18 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<String> entries() {
|
||||
return Collections.unmodifiableSet(entries);
|
||||
return Collections.unmodifiableCollection(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<String> syncedEntries() {
|
||||
return syncedEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addEntry(@NotNull String entry) {
|
||||
if (entries.add(entry)) {
|
||||
if (!entries.contains(entry)) {
|
||||
entries.add(entry);
|
||||
team.teamManager().taskQueue().add(new TeamManagerTask.AddEntries(this, Collections.singleton(entry)));
|
||||
return true;
|
||||
}
|
||||
@@ -73,11 +83,12 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay displayName(@NotNull Component displayName) {
|
||||
public @NotNull TeamDisplay displayName(@NotNull ComponentLike displayName) {
|
||||
Preconditions.checkNotNull(displayName);
|
||||
|
||||
if (!Objects.equals(this.displayName, displayName)) {
|
||||
this.displayName = displayName;
|
||||
Component component = displayName.asComponent();
|
||||
if (!Objects.equals(this.displayName, component)) {
|
||||
this.displayName = component;
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
@@ -90,11 +101,12 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay prefix(@NotNull Component prefix) {
|
||||
public @NotNull TeamDisplay prefix(@NotNull ComponentLike prefix) {
|
||||
Preconditions.checkNotNull(prefix);
|
||||
|
||||
if (!Objects.equals(this.prefix, prefix)) {
|
||||
this.prefix = prefix;
|
||||
Component component = prefix.asComponent();
|
||||
if (!Objects.equals(this.prefix, component)) {
|
||||
this.prefix = component;
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
@@ -107,11 +119,12 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamDisplay suffix(@NotNull Component suffix) {
|
||||
public @NotNull TeamDisplay suffix(@NotNull ComponentLike suffix) {
|
||||
Preconditions.checkNotNull(suffix);
|
||||
|
||||
if (!Objects.equals(this.suffix, suffix)) {
|
||||
this.suffix = suffix;
|
||||
Component component = suffix.asComponent();
|
||||
if (!Objects.equals(this.suffix, component)) {
|
||||
this.suffix = component;
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
@@ -205,8 +218,21 @@ public class TeamDisplayImpl implements TeamDisplay, ImmutableTeamProperties<Com
|
||||
return players;
|
||||
}
|
||||
|
||||
public void updateTeamPackets() {
|
||||
packetAdapter.updateTeamPackets(entries);
|
||||
public void handleUpdateDisplay() {
|
||||
packetAdapter.updateTeamPackets();
|
||||
packetAdapter().sendProperties(PropertiesPacketType.UPDATE, players());
|
||||
}
|
||||
|
||||
public void handleAddEntries(@NotNull Collection<String> newEntries) {
|
||||
packetAdapter.sendEntries(EntriesPacketType.ADD, players(), newEntries);
|
||||
syncedEntries.addAll(newEntries);
|
||||
packetAdapter.updateTeamPackets();
|
||||
}
|
||||
|
||||
public void handleRemoveEntries(@NotNull Collection<String> oldEntries) {
|
||||
packetAdapter.sendEntries(EntriesPacketType.REMOVE, players(), oldEntries);
|
||||
syncedEntries.removeAll(oldEntries);
|
||||
packetAdapter.updateTeamPackets();
|
||||
}
|
||||
|
||||
private void scheduleUpdate() {
|
||||
|
||||
+14
-12
@@ -7,7 +7,6 @@ import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.CollectionProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.player.PlayerDisplayable;
|
||||
import net.megavex.scoreboardlibrary.implementation.player.ScoreboardLibraryPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -24,6 +23,8 @@ public class TeamManagerImpl implements TeamManager, PlayerDisplayable {
|
||||
private final ScoreboardLibraryImpl scoreboardLibrary;
|
||||
|
||||
private final Set<Player> players = CollectionProvider.set(8);
|
||||
private final List<Player> internalPlayers = CollectionProvider.list(8);
|
||||
|
||||
private final Map<String, ScoreboardTeamImpl> teams = new ConcurrentHashMap<>();
|
||||
private final Queue<TeamManagerTask> taskQueue = new ConcurrentLinkedQueue<>();
|
||||
private boolean closed;
|
||||
@@ -156,13 +157,14 @@ public class TeamManagerImpl implements TeamManager, PlayerDisplayable {
|
||||
return taskQueue;
|
||||
}
|
||||
|
||||
public void show(@NotNull Player player) {
|
||||
@Override
|
||||
public void display(@NotNull Player player) {
|
||||
for (ScoreboardTeamImpl team : teams.values()) {
|
||||
team.addPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
public boolean tick() {
|
||||
while (true) {
|
||||
TeamManagerTask task = taskQueue.poll();
|
||||
if (task == null) {
|
||||
@@ -170,30 +172,30 @@ public class TeamManagerImpl implements TeamManager, PlayerDisplayable {
|
||||
}
|
||||
|
||||
if (task instanceof TeamManagerTask.Close) {
|
||||
scoreboardLibrary.teamManagers().remove(this);
|
||||
|
||||
for (ScoreboardTeamImpl team : teams.values()) {
|
||||
Set<Player> removePlayers = CollectionProvider.set(players.size());
|
||||
Set<Player> removePlayers = CollectionProvider.set(internalPlayers.size());
|
||||
for (TeamDisplayImpl value : team.displayMap().values()) {
|
||||
removePlayers.addAll(value.players());
|
||||
}
|
||||
team.packetAdapter().removeTeam(removePlayers);
|
||||
}
|
||||
|
||||
for (Player player : players) {
|
||||
for (Player player : internalPlayers) {
|
||||
Objects.requireNonNull(scoreboardLibrary.getPlayer(player)).teamManagerQueue().remove(this);
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
} else if (task instanceof TeamManagerTask.AddPlayer) {
|
||||
TeamManagerTask.AddPlayer addPlayerTask = (TeamManagerTask.AddPlayer) task;
|
||||
@NotNull ScoreboardLibraryPlayer slPlayer = scoreboardLibrary.getOrCreatePlayer(addPlayerTask.player());
|
||||
slPlayer.teamManagerQueue().add(this);
|
||||
internalPlayers.add(addPlayerTask.player());
|
||||
} else if (task instanceof TeamManagerTask.RemovePlayer) {
|
||||
TeamManagerTask.RemovePlayer removePlayerTask = (TeamManagerTask.RemovePlayer) task;
|
||||
for (ScoreboardTeamImpl team : teams.values()) {
|
||||
team.removePlayer(removePlayerTask.player());
|
||||
}
|
||||
|
||||
internalPlayers.remove(removePlayerTask.player());
|
||||
Objects.requireNonNull(scoreboardLibrary.getPlayer(removePlayerTask.player())).teamManagerQueue().remove(this);
|
||||
} else if (task instanceof TeamManagerTask.ReloadPlayer) {
|
||||
TeamManagerTask.ReloadPlayer reloadPlayerTask = (TeamManagerTask.ReloadPlayer) task;
|
||||
@@ -227,21 +229,21 @@ public class TeamManagerImpl implements TeamManager, PlayerDisplayable {
|
||||
} else if (task instanceof TeamManagerTask.UpdateTeamDisplay) {
|
||||
TeamManagerTask.UpdateTeamDisplay updateTeamDisplayTask = (TeamManagerTask.UpdateTeamDisplay) task;
|
||||
@NotNull TeamDisplayImpl teamDisplay = updateTeamDisplayTask.teamDisplay();
|
||||
teamDisplay.updateTeamPackets();
|
||||
teamDisplay.packetAdapter().sendProperties(PropertiesPacketType.UPDATE, teamDisplay.players());
|
||||
teamDisplay.handleUpdateDisplay();
|
||||
} else if (task instanceof TeamManagerTask.AddEntries) {
|
||||
TeamManagerTask.AddEntries addEntriesTask = (TeamManagerTask.AddEntries) task;
|
||||
@NotNull TeamDisplayImpl teamDisplay = addEntriesTask.teamDisplay();
|
||||
teamDisplay.packetAdapter().sendEntries(EntriesPacketType.ADD, teamDisplay.players(), addEntriesTask.entries());
|
||||
teamDisplay.handleAddEntries(addEntriesTask.entries());
|
||||
} else if (task instanceof TeamManagerTask.RemoveEntries) {
|
||||
TeamManagerTask.RemoveEntries removeEntriesTask = (TeamManagerTask.RemoveEntries) task;
|
||||
@NotNull TeamDisplayImpl teamDisplay = removeEntriesTask.teamDisplay();
|
||||
teamDisplay.packetAdapter().sendEntries(EntriesPacketType.REMOVE, teamDisplay.players(), removeEntriesTask.entries());
|
||||
teamDisplay.handleRemoveEntries(removeEntriesTask.entries());
|
||||
} else if (task instanceof TeamManagerTask.ChangeTeamDisplay) {
|
||||
TeamManagerTask.ChangeTeamDisplay changeTeamDisplayTask = (TeamManagerTask.ChangeTeamDisplay) task;
|
||||
changeTeamDisplayTask.team().changeTeamDisplay(changeTeamDisplayTask.player(), changeTeamDisplayTask.oldTeamDisplay(), changeTeamDisplayTask.newTeamDisplay());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkClosed() {
|
||||
|
||||
+12
-3
@@ -4,6 +4,7 @@ import net.megavex.scoreboardlibrary.implementation.ScoreboardLibraryImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.scheduler.RunningTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TeamUpdaterTask implements Runnable {
|
||||
@@ -27,11 +28,19 @@ public class TeamUpdaterTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
for (TeamManagerImpl teamManager : scoreboardLibrary.teamManagers()) {
|
||||
Iterator<TeamManagerImpl> iterator = scoreboardLibrary.teamManagers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TeamManagerImpl teamManager = iterator.next();
|
||||
boolean result;
|
||||
try {
|
||||
teamManager.tick();
|
||||
result = teamManager.tick();
|
||||
} catch (Exception e) {
|
||||
scoreboardLibrary.plugin().getLogger().log(Level.SEVERE, "an error occurred while updating a TeamManager instance", e);
|
||||
scoreboardLibrary.plugin().getLogger().log(Level.WARNING, "an error occurred while updating a TeamManager instance", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.sidebar.line;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlayerNameProviderTest {
|
||||
@Test
|
||||
void duplicateTest() {
|
||||
List<String> names = PlayerNameProvider.provideLinePlayerNames(100);
|
||||
Set<String> uniqueNames = new HashSet<>(names.size());
|
||||
for (String name : names) {
|
||||
assertTrue(uniqueNames.add(name), "duplicate player name " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
jdk:
|
||||
- openjdk17
|
||||
|
||||
install:
|
||||
- "bash gradlew build publishToMavenLocal"
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
],
|
||||
"ignoreDeps": [
|
||||
"org.spigotmc:spigot-api"
|
||||
]
|
||||
}
|
||||
+5
-1
@@ -3,7 +3,7 @@ rootProject.name = "scoreboard-library"
|
||||
include(":api")
|
||||
include(":commons")
|
||||
include(":implementation")
|
||||
include("extra-kotlin")
|
||||
include(":extra-kotlin")
|
||||
|
||||
include(":packet-adapter-base")
|
||||
project(":packet-adapter-base").projectDir = file("versions/packet-adapter-base")
|
||||
@@ -14,6 +14,10 @@ project(":packetevents").projectDir = file("versions/packetevents")
|
||||
include(":modern")
|
||||
project(":modern").projectDir = file("versions/modern")
|
||||
|
||||
include(":legacy")
|
||||
project(":legacy").projectDir = file("versions/legacy")
|
||||
|
||||
// For backwards compatibility
|
||||
include(":v1_8_R3")
|
||||
project(":v1_8_R3").projectDir = file("versions/v1_8_R3")
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":scoreboard-library-packet-adapter-base"))
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class ChatColorUtil {
|
||||
private static final MethodHandle FROM_NAME_METHOD, GET_INDEX_METHOD;
|
||||
|
||||
static {
|
||||
Class<?> enumChatFormatClass = ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("EnumChatFormat"));
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
try {
|
||||
Method fromNameMethod = enumChatFormatClass.getMethod("b", String.class);
|
||||
FROM_NAME_METHOD = lookup.unreflect(fromNameMethod);
|
||||
|
||||
Method getIndexMethod = enumChatFormatClass.getMethod("b");
|
||||
GET_INDEX_METHOD = lookup.unreflect(getIndexMethod);
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ChatColorUtil() {
|
||||
}
|
||||
|
||||
public static int getColorIndex(@NotNull NamedTextColor color) {
|
||||
String name = NamedTextColor.NAMES.key(color);
|
||||
try {
|
||||
Object format = FROM_NAME_METHOD.invoke(name);
|
||||
return (int) GET_INDEX_METHOD.invoke(format);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
// TODO: should be moved to MinecraftReflection at some point
|
||||
public final class LegacyMinecraftClasses {
|
||||
private static final String NMS_VERSION_STRING = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
private LegacyMinecraftClasses() {
|
||||
}
|
||||
|
||||
public static @NotNull String server(String path) {
|
||||
return "net.minecraft.server." + NMS_VERSION_STRING + "." + path;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.MinecraftClasses;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class LegacyPacketSender implements PacketSender<Object> {
|
||||
public static final LegacyPacketSender INSTANCE = new LegacyPacketSender();
|
||||
|
||||
private static final MethodHandle GET_HANDLE_METHOD, PLAYER_CONNECTION_FIELD, SEND_PACKET_METHOD;
|
||||
|
||||
static {
|
||||
Class<?> packetClass = ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("Packet"));
|
||||
Class<?> craftPlayerClass = ReflectUtil.getClassOrThrow(MinecraftClasses.craftBukkit("entity.CraftPlayer"));
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
try {
|
||||
Method getHandleMethod = craftPlayerClass.getMethod("getHandle");
|
||||
GET_HANDLE_METHOD = lookup.unreflect(getHandleMethod);
|
||||
|
||||
Field playerConnectionField = getHandleMethod.getReturnType().getField("playerConnection");
|
||||
PLAYER_CONNECTION_FIELD = lookup.unreflectGetter(playerConnectionField);
|
||||
|
||||
Method sendPacketMethod = playerConnectionField.getType().getMethod("sendPacket", packetClass);
|
||||
SEND_PACKET_METHOD = lookup.unreflect(sendPacketMethod);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private LegacyPacketSender() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = GET_HANDLE_METHOD.invoke(player);
|
||||
Object playerConnection = PLAYER_CONNECTION_FIELD.invoke(handle);
|
||||
SEND_PACKET_METHOD.invoke(playerConnection, packet);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-39
@@ -1,38 +1,37 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.v1_8_R3;
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LegacyFormatUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.LocalePacketUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectiveConstants;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.LocalePacketUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ObjectivePacketAdapterImpl implements ObjectivePacketAdapter {
|
||||
private final PacketSender<Packet<?>> sender;
|
||||
private final String objectiveName;
|
||||
private PacketPlayOutScoreboardObjective removePacket;
|
||||
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
|
||||
|
||||
public ObjectivePacketAdapterImpl(@NotNull PacketSender<Packet<?>> sender, @NotNull String objectiveName) {
|
||||
this.sender = sender;
|
||||
public class ObjectivePacketAdapterImpl implements ObjectivePacketAdapter {
|
||||
private final String objectiveName;
|
||||
private Object removePacket;
|
||||
|
||||
public ObjectivePacketAdapterImpl(@NotNull String objectiveName) {
|
||||
this.objectiveName = objectiveName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(@NotNull Collection<Player> players, @NotNull ObjectiveDisplaySlot slot) {
|
||||
PacketPlayOutScoreboardDisplayObjective packet = new PacketPlayOutScoreboardDisplayObjective();
|
||||
PacketAccessors.DISPLAY_OBJECTIVE_POSITION.set(packet, ObjectiveConstants.displaySlotIndex(slot));
|
||||
Object packet = PacketAccessors.DISPLAY_OBJECTIVE_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.DISPLAY_OBJECTIVE_POSITION.set(packet, ObjectiveConstants.displaySlotIndex(slot, false));
|
||||
PacketAccessors.DISPLAY_OBJECTIVE_NAME.set(packet, objectiveName);
|
||||
sender.sendPacket(players, packet);
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,10 +39,11 @@ public class ObjectivePacketAdapterImpl implements ObjectivePacketAdapter {
|
||||
@NotNull Collection<Player> players,
|
||||
@NotNull PropertiesPacketType packetType,
|
||||
@NotNull Component value,
|
||||
@NotNull ObjectiveRenderType renderType
|
||||
@NotNull ObjectiveRenderType renderType,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
LocalePacketUtil.sendLocalePackets(
|
||||
sender,
|
||||
LegacyPacketSender.INSTANCE,
|
||||
players,
|
||||
locale -> createPropertiesPacket(packetType, GlobalTranslator.render(value, locale), renderType)
|
||||
);
|
||||
@@ -52,54 +52,68 @@ public class ObjectivePacketAdapterImpl implements ObjectivePacketAdapter {
|
||||
@Override
|
||||
public void remove(@NotNull Collection<Player> players) {
|
||||
if (removePacket == null) {
|
||||
removePacket = new PacketPlayOutScoreboardObjective();
|
||||
removePacket = PacketAccessors.OBJECTIVE_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.OBJECTIVE_NAME_FIELD.set(removePacket, objectiveName);
|
||||
PacketAccessors.OBJECTIVE_DISPLAY_NAME_FIELD.set(removePacket, "");
|
||||
PacketAccessors.OBJECTIVE_MODE_FIELD.set(removePacket, ObjectiveConstants.MODE_REMOVE);
|
||||
}
|
||||
sender.sendPacket(players, removePacket);
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, removePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players, @NotNull String entry, int value) {
|
||||
PacketPlayOutScoreboardScore packet = new PacketPlayOutScoreboardScore(entry);
|
||||
public void sendScore(
|
||||
@NotNull Collection<Player> players,
|
||||
@NotNull String entry,
|
||||
int value,
|
||||
@Nullable Component display,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
Object packet = PacketAccessors.SCORE_CONSTRUCTOR.invoke(entry);
|
||||
PacketAccessors.SCORE_OBJECTIVE_NAME_FIELD.set(packet, objectiveName);
|
||||
PacketAccessors.SCORE_VALUE_FIELD.set(packet, value);
|
||||
PacketAccessors.SCORE_ACTION_FIELD.set(packet, PacketPlayOutScoreboardScore.EnumScoreboardAction.CHANGE);
|
||||
sender.sendPacket(players, packet);
|
||||
if (PacketAccessors.SCORE_ACTION_FIELD_1_8 != null) {
|
||||
PacketAccessors.SCORE_ACTION_FIELD_1_8.set(packet, PacketAccessors.SCORE_ACTION_CHANGE_1_8);
|
||||
} else {
|
||||
PacketAccessors.SCORE_ACTION_FIELD_1_7.set(packet, 0);
|
||||
}
|
||||
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScore(@NotNull Collection<Player> players, @NotNull String entry) {
|
||||
PacketPlayOutScoreboardScore packet = new PacketPlayOutScoreboardScore(entry);
|
||||
Object packet = PacketAccessors.SCORE_CONSTRUCTOR.invoke(entry);
|
||||
PacketAccessors.SCORE_OBJECTIVE_NAME_FIELD.set(packet, objectiveName);
|
||||
sender.sendPacket(players, packet);
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
private @NotNull PacketPlayOutScoreboardObjective createPropertiesPacket(
|
||||
private @NotNull Object createPropertiesPacket(
|
||||
@NotNull PropertiesPacketType packetType,
|
||||
@NotNull Component value,
|
||||
@NotNull ObjectiveRenderType renderType
|
||||
) {
|
||||
PacketPlayOutScoreboardObjective packet = new PacketPlayOutScoreboardObjective();
|
||||
Object packet = PacketAccessors.OBJECTIVE_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.OBJECTIVE_NAME_FIELD.set(packet, objectiveName);
|
||||
PacketAccessors.OBJECTIVE_MODE_FIELD.set(packet, ObjectiveConstants.mode(packetType));
|
||||
|
||||
String legacyValue = LegacyFormatUtil.limitLegacyText(LegacyComponentSerializer.legacySection().serialize(value), ObjectiveConstants.LEGACY_VALUE_CHAR_LIMIT);
|
||||
String legacyValue = LegacyFormatUtil.limitLegacyText(legacySection().serialize(value), ObjectiveConstants.LEGACY_VALUE_CHAR_LIMIT);
|
||||
PacketAccessors.OBJECTIVE_DISPLAY_NAME_FIELD.set(packet, legacyValue);
|
||||
|
||||
IScoreboardCriteria.EnumScoreboardHealthDisplay nmsRenderType;
|
||||
switch (renderType) {
|
||||
case INTEGER:
|
||||
nmsRenderType = IScoreboardCriteria.EnumScoreboardHealthDisplay.INTEGER;
|
||||
break;
|
||||
case HEARTS:
|
||||
nmsRenderType = IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
if (PacketAccessors.OBJECTIVE_HEALTH_DISPLAY_FIELD != null) {
|
||||
Object nmsRenderType;
|
||||
switch (renderType) {
|
||||
case INTEGER:
|
||||
nmsRenderType = PacketAccessors.HEALTH_DISPLAY_INTEGER;
|
||||
break;
|
||||
case HEARTS:
|
||||
nmsRenderType = PacketAccessors.HEALTH_DISPLAY_HEARTS;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
PacketAccessors.OBJECTIVE_HEALTH_DISPLAY_FIELD.set(packet, nmsRenderType);
|
||||
}
|
||||
|
||||
PacketAccessors.OBJECTIVE_HEALTH_DISPLAY_FIELD.set(packet, nmsRenderType);
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ConstructorAccessor;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.FieldAccessor;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public final class PacketAccessors {
|
||||
public static final Class<?> HEALTH_DISPLAY_CLASS =
|
||||
ReflectUtil.getOptionalClass(LegacyMinecraftClasses.server("IScoreboardCriteria$EnumScoreboardHealthDisplay"));
|
||||
public static final Object HEALTH_DISPLAY_INTEGER = HEALTH_DISPLAY_CLASS != null ? ReflectUtil.getEnumInstance(HEALTH_DISPLAY_CLASS, "INTEGER") : null;
|
||||
public static final Object HEALTH_DISPLAY_HEARTS = HEALTH_DISPLAY_CLASS != null ? ReflectUtil.getEnumInstance(HEALTH_DISPLAY_CLASS, "HEARTS") : null;
|
||||
|
||||
private static final boolean IS_AT_LEAST_1_8 = HEALTH_DISPLAY_INTEGER != null;
|
||||
private static final boolean IS_AT_LEAST_1_9 = ReflectUtil.getOptionalClass(LegacyMinecraftClasses.server("ScoreboardTeamBase$EnumTeamPush")) != null;
|
||||
|
||||
public static final Class<?> OBJECTIVE_CLASS =
|
||||
ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("PacketPlayOutScoreboardObjective"));
|
||||
public static final ConstructorAccessor<?> OBJECTIVE_CONSTRUCTOR = ReflectUtil.findConstructor(OBJECTIVE_CLASS);
|
||||
public static final FieldAccessor<Object, Integer> OBJECTIVE_MODE_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(OBJECTIVE_CLASS, 0, int.class);
|
||||
public static final FieldAccessor<Object, String> OBJECTIVE_NAME_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(OBJECTIVE_CLASS, 0, String.class);
|
||||
public static final FieldAccessor<Object, String> OBJECTIVE_DISPLAY_NAME_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(OBJECTIVE_CLASS, 1, String.class);
|
||||
public static final FieldAccessor<Object, Object> OBJECTIVE_HEALTH_DISPLAY_FIELD =
|
||||
HEALTH_DISPLAY_CLASS != null ? ReflectUtil.findFieldUnchecked(OBJECTIVE_CLASS, 0, HEALTH_DISPLAY_CLASS) : null;
|
||||
|
||||
public static final Class<?> DISPLAY_OBJECTIVE_CLASS =
|
||||
ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("PacketPlayOutScoreboardDisplayObjective"));
|
||||
public static final ConstructorAccessor<?> DISPLAY_OBJECTIVE_CONSTRUCTOR = ReflectUtil.findConstructor(DISPLAY_OBJECTIVE_CLASS);
|
||||
public static final FieldAccessor<Object, Integer> DISPLAY_OBJECTIVE_POSITION =
|
||||
ReflectUtil.findFieldUnchecked(DISPLAY_OBJECTIVE_CLASS, 0, int.class);
|
||||
public static final FieldAccessor<Object, String> DISPLAY_OBJECTIVE_NAME =
|
||||
ReflectUtil.findFieldUnchecked(DISPLAY_OBJECTIVE_CLASS, 0, String.class);
|
||||
|
||||
public static final Class<?> SCORE_CLASS =
|
||||
ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("PacketPlayOutScoreboardScore"));
|
||||
public static final ConstructorAccessor<?> SCORE_CONSTRUCTOR = ReflectUtil.findConstructor(SCORE_CLASS, String.class);
|
||||
public static final FieldAccessor<Object, String> SCORE_OBJECTIVE_NAME_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(SCORE_CLASS, 1, String.class);
|
||||
public static final FieldAccessor<Object, Integer> SCORE_VALUE_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(SCORE_CLASS, 0, int.class);
|
||||
public static final Class<?> SCORE_ACTION_CLASS =
|
||||
ReflectUtil.getOptionalClass(LegacyMinecraftClasses.server("PacketPlayOutScoreboardScore$EnumScoreboardAction"));
|
||||
public static final FieldAccessor<Object, Object> SCORE_ACTION_FIELD_1_8 =
|
||||
SCORE_ACTION_CLASS != null ? ReflectUtil.findFieldUnchecked(SCORE_CLASS, 0, SCORE_ACTION_CLASS) : null;
|
||||
public static final Object SCORE_ACTION_CHANGE_1_8 = SCORE_ACTION_FIELD_1_8 != null ? ReflectUtil.getEnumInstance(SCORE_ACTION_CLASS, "CHANGE") : null;
|
||||
public static final FieldAccessor<Object, Integer> SCORE_ACTION_FIELD_1_7 =
|
||||
SCORE_ACTION_CLASS == null ? ReflectUtil.findFieldUnchecked(SCORE_CLASS, 1, int.class) : null;
|
||||
|
||||
public static final Class<?> TEAM_CLASS =
|
||||
ReflectUtil.getClassOrThrow(LegacyMinecraftClasses.server("PacketPlayOutScoreboardTeam"));
|
||||
public static final ConstructorAccessor<?> TEAM_CONSTRUCTOR = ReflectUtil.findConstructor(TEAM_CLASS);
|
||||
public static final FieldAccessor<Object, String> TEAM_NAME_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, 0, String.class);
|
||||
public static final FieldAccessor<Object, String> TEAM_DISPLAY_NAME_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, 1, String.class);
|
||||
public static final FieldAccessor<Object, String> TEAM_PREFIX_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, 2, String.class);
|
||||
public static final FieldAccessor<Object, String> TEAM_SUFFIX_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, 3, String.class);
|
||||
public static final FieldAccessor<Object, String> TEAM_NAME_TAG_VISIBILITY_FIELD =
|
||||
IS_AT_LEAST_1_8 ? ReflectUtil.findFieldUnchecked(TEAM_CLASS, 4, String.class) : null;
|
||||
public static final FieldAccessor<Object, String> TEAM_COLLISION_RULE_FIELD =
|
||||
IS_AT_LEAST_1_9 ? ReflectUtil.findFieldUnchecked(TEAM_CLASS, 5, String.class) : null;
|
||||
public static final FieldAccessor<Object, Integer> TEAM_COLOR_FIELD =
|
||||
IS_AT_LEAST_1_8 ? ReflectUtil.findFieldUnchecked(TEAM_CLASS, 0, int.class) : null;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final FieldAccessor<Object, Collection> TEAM_ENTRIES_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, 0, Collection.class);
|
||||
public static final FieldAccessor<Object, Integer> TEAM_MODE_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, IS_AT_LEAST_1_8 ? 1 : 0, int.class);
|
||||
public static final FieldAccessor<Object, Integer> TEAM_RULES_FIELD =
|
||||
ReflectUtil.findFieldUnchecked(TEAM_CLASS, IS_AT_LEAST_1_8 ? 2 : 1, int.class);
|
||||
|
||||
private PacketAccessors() {
|
||||
}
|
||||
}
|
||||
+7
-14
@@ -1,33 +1,26 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.v1_8_R3;
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LineRenderingStrategy;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketAdapterProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PacketAdapterProviderImpl implements PacketAdapterProvider, PacketSender<Packet<?>> {
|
||||
public class PacketAdapterProviderImpl implements PacketAdapterProvider {
|
||||
@Override
|
||||
public @NotNull TeamsPacketAdapter createTeamPacketAdapter(@NotNull String teamName) {
|
||||
return new TeamsPacketAdapterImpl(this, teamName);
|
||||
return new TeamsPacketAdapterImpl(teamName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ObjectivePacketAdapter createObjectiveAdapter(@NotNull String objectiveName) {
|
||||
return new ObjectivePacketAdapterImpl(this, objectiveName);
|
||||
return new ObjectivePacketAdapterImpl(objectiveName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLegacy(@NotNull Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(@NotNull Player player, @NotNull Packet<?> packet) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
public @NotNull LineRenderingStrategy lineRenderingStrategy(@NotNull Player player) {
|
||||
return LineRenderingStrategy.LEGACY;
|
||||
}
|
||||
}
|
||||
+26
-16
@@ -1,17 +1,16 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.v1_8_R3;
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.legacy;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LegacyFormatUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamConstants;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.LocalePacketUtil;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardTeam;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -21,24 +20,22 @@ import java.util.Locale;
|
||||
import static net.megavex.scoreboardlibrary.implementation.commons.LegacyFormatUtil.limitLegacyText;
|
||||
|
||||
public class TeamsPacketAdapterImpl implements TeamsPacketAdapter {
|
||||
private final PacketSender<Packet<?>> sender;
|
||||
private final String teamName;
|
||||
private PacketPlayOutScoreboardTeam removePacket;
|
||||
private Object removePacket;
|
||||
|
||||
public TeamsPacketAdapterImpl(@NotNull PacketSender<Packet<?>> sender, @NotNull String teamName) {
|
||||
this.sender = sender;
|
||||
public TeamsPacketAdapterImpl(@NotNull String teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTeam(@NotNull Iterable<Player> players) {
|
||||
if (removePacket == null) {
|
||||
removePacket = new PacketPlayOutScoreboardTeam();
|
||||
removePacket = PacketAccessors.TEAM_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.TEAM_NAME_FIELD.set(removePacket, teamName);
|
||||
PacketAccessors.TEAM_MODE_FIELD.set(removePacket, TeamConstants.MODE_REMOVE);
|
||||
}
|
||||
|
||||
sender.sendPacket(players, removePacket);
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, removePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,33 +57,46 @@ public class TeamsPacketAdapterImpl implements TeamsPacketAdapter {
|
||||
|
||||
@Override
|
||||
public void sendEntries(@NotNull EntriesPacketType packetType, @NotNull Collection<Player> players, @NotNull Collection<String> entries) {
|
||||
PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam();
|
||||
Object packet = PacketAccessors.TEAM_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.TEAM_NAME_FIELD.set(packet, teamName);
|
||||
PacketAccessors.TEAM_MODE_FIELD.set(packet, TeamConstants.mode(packetType));
|
||||
PacketAccessors.TEAM_ENTRIES_FIELD.set(packet, entries);
|
||||
sender.sendPacket(players, packet);
|
||||
LegacyPacketSender.INSTANCE.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendProperties(@NotNull PropertiesPacketType packetType, @NotNull Collection<Player> players) {
|
||||
LocalePacketUtil.sendLocalePackets(
|
||||
sender,
|
||||
LegacyPacketSender.INSTANCE,
|
||||
players,
|
||||
locale -> {
|
||||
String displayName = limitLegacyText(toLegacy(properties.displayName(), locale), TeamConstants.LEGACY_CHAR_LIMIT);
|
||||
String prefix = limitLegacyText(toLegacy(properties.prefix(), locale), TeamConstants.LEGACY_CHAR_LIMIT);
|
||||
String suffix = limitLegacyText(toLegacy(properties.suffix(), locale), TeamConstants.LEGACY_CHAR_LIMIT);
|
||||
|
||||
PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam();
|
||||
Object packet = PacketAccessors.TEAM_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.TEAM_NAME_FIELD.set(packet, teamName);
|
||||
PacketAccessors.TEAM_MODE_FIELD.set(packet, TeamConstants.mode(packetType));
|
||||
PacketAccessors.TEAM_DISPLAY_NAME_FIELD.set(packet, displayName);
|
||||
PacketAccessors.TEAM_PREFIX_FIELD.set(packet, prefix);
|
||||
PacketAccessors.TEAM_SUFFIX_FIELD.set(packet, suffix);
|
||||
PacketAccessors.TEAM_NAME_TAG_VISIBILITY_FIELD.set(packet, properties.nameTagVisibility().key());
|
||||
PacketAccessors.TEAM_RULES_FIELD.set(packet, properties.packOptions());
|
||||
if (PacketAccessors.TEAM_NAME_TAG_VISIBILITY_FIELD != null) {
|
||||
PacketAccessors.TEAM_NAME_TAG_VISIBILITY_FIELD.set(packet, properties.nameTagVisibility().key());
|
||||
}
|
||||
|
||||
NamedTextColor color = properties.playerColor();
|
||||
if (PacketAccessors.TEAM_COLOR_FIELD != null && color != null) {
|
||||
int teamColorField = ChatColorUtil.getColorIndex(color);
|
||||
PacketAccessors.TEAM_COLOR_FIELD.set(packet, teamColorField);
|
||||
}
|
||||
|
||||
if (PacketAccessors.TEAM_COLLISION_RULE_FIELD != null) {
|
||||
PacketAccessors.TEAM_COLLISION_RULE_FIELD.set(packet, properties.collisionRule().key());
|
||||
}
|
||||
|
||||
if (packetType == PropertiesPacketType.CREATE) {
|
||||
PacketAccessors.TEAM_ENTRIES_FIELD.set(packet, properties.entries());
|
||||
PacketAccessors.TEAM_ENTRIES_FIELD.set(packet, ImmutableList.copyOf(properties.syncedEntries()));
|
||||
}
|
||||
|
||||
return packet;
|
||||
@@ -1,25 +1,46 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.5.6"
|
||||
`maven-publish`
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
alias(libs.plugins.paperweight)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":scoreboard-library-packet-adapter-base"))
|
||||
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle(libs.versions.devBundle.get())
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
// Workaround to get it to compile targeting Java 8 while using NMS which targets 17
|
||||
// Why does this work? I have no idea
|
||||
options.release = null
|
||||
}
|
||||
|
||||
// https://github.com/unnamed/hephaestus-engine/blob/db6deabe1ddb0a549306b0c4b519c3e79e6f1ea8/runtime-bukkit/adapt-v1_20_R3/build.gradle.kts#L25
|
||||
reobfJar {
|
||||
outputJar = file("build/libs/scoreboard-library-modern-$version-reobf.jar")
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.create<MavenPublication>("maven") {
|
||||
artifact(tasks.reobfJar)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
disableAutoTargetJvm()
|
||||
}
|
||||
|
||||
indra {
|
||||
includeJavaSoftwareComponentInPublications(false)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.getByName<MavenPublication>("maven") {
|
||||
artifact(tasks.jar) {
|
||||
classifier = "mojmap"
|
||||
}
|
||||
|
||||
artifact(tasks.reobfJar)
|
||||
artifact(tasks.javadocJar)
|
||||
artifact(tasks.sourcesJar)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -2,9 +2,10 @@ package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public interface ComponentProvider {
|
||||
@NotNull net.minecraft.network.chat.Component fromAdventure(@NotNull Component adventure, @NotNull Locale locale);
|
||||
@NotNull net.minecraft.network.chat.Component fromAdventure(@NotNull Component adventure, @Nullable Locale locale);
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util.NativeAdventureUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util.RegistryUtil;
|
||||
import net.minecraft.network.chat.Component.Serializer;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson;
|
||||
|
||||
public class ComponentProviderImpl implements ComponentProvider {
|
||||
private static final MethodHandle FROM_JSON_METHOD;
|
||||
|
||||
static {
|
||||
MethodHandle handle = null;
|
||||
for (Method method : Serializer.class.getMethods()) {
|
||||
if (method.getReturnType() == MutableComponent.class &&
|
||||
method.getParameterCount() >= 1 &&
|
||||
method.getParameterCount() <= 2 &&
|
||||
method.getParameterTypes()[0] == JsonElement.class
|
||||
) {
|
||||
try {
|
||||
handle = MethodHandles.lookup().unreflect(method);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handle == null) {
|
||||
throw new ExceptionInInitializerError("failed to find chat component fromJson method");
|
||||
}
|
||||
|
||||
FROM_JSON_METHOD = handle;
|
||||
}
|
||||
|
||||
private final boolean isNativeAdventure;
|
||||
|
||||
public ComponentProviderImpl(boolean isNativeAdventure) {
|
||||
this.isNativeAdventure = isNativeAdventure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.network.chat.@NotNull Component fromAdventure(@NotNull Component adventure, @Nullable Locale locale) {
|
||||
if (isNativeAdventure) {
|
||||
return NativeAdventureUtil.fromAdventureComponent(adventure);
|
||||
}
|
||||
|
||||
Component translated = adventure;
|
||||
if (locale != null) {
|
||||
translated = GlobalTranslator.render(adventure, locale);
|
||||
}
|
||||
|
||||
JsonElement json = gson().serializeToTree(translated);
|
||||
Object[] args;
|
||||
if (PacketAccessors.IS_1_20_5_OR_ABOVE) {
|
||||
args = new Object[]{json, RegistryUtil.MINECRAFT_REGISTRY};
|
||||
} else {
|
||||
args = new Object[]{json};
|
||||
}
|
||||
|
||||
try {
|
||||
return (net.minecraft.network.chat.Component) FROM_JSON_METHOD.invokeWithArguments(args);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
-26
@@ -6,52 +6,100 @@ import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.P
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.numbers.NumberFormat;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetScorePacket;
|
||||
import net.minecraft.server.ServerScoreboard;
|
||||
import net.minecraft.world.scores.Objective;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PacketAccessors {
|
||||
public static final PacketConstructor<ClientboundSetObjectivePacket> OBJECTIVE_PACKET_CONSTRUCTOR =
|
||||
ReflectUtil.findPacketConstructor(ClientboundSetObjectivePacket.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, String> OBJECTIVE_NAME_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "d", String.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, net.minecraft.network.chat.Component> OBJECTIVE_VALUE_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "e", net.minecraft.network.chat.Component.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, ObjectiveCriteria.RenderType> OBJECTIVE_RENDER_TYPE_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "f", ObjectiveCriteria.RenderType.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, Integer> OBJECTIVE_MODE_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "g", int.class);
|
||||
static {
|
||||
boolean is1_20_2OrAbove = false;
|
||||
try {
|
||||
Class.forName("net.minecraft.world.scores.DisplaySlot");
|
||||
is1_20_2OrAbove = true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
IS_1_20_2_OR_ABOVE = is1_20_2OrAbove;
|
||||
|
||||
boolean is1_20_3OrAbove = false;
|
||||
try {
|
||||
Class.forName("net.minecraft.network.chat.numbers.NumberFormat");
|
||||
is1_20_3OrAbove = true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
IS_1_20_3_OR_ABOVE = is1_20_3OrAbove;
|
||||
|
||||
boolean is1_20_5OrAbove = false;
|
||||
try {
|
||||
Class.forName("net.minecraft.network.protocol.common.ClientboundTransferPacket"); // Random 1.20.5 class
|
||||
is1_20_5OrAbove = true;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
IS_1_20_5_OR_ABOVE = is1_20_5OrAbove;
|
||||
|
||||
if (is1_20_5OrAbove) {
|
||||
OBJECTIVE_NUMBER_FORMAT_FIELD = ReflectUtil.findFieldUnchecked(ClientboundSetObjectivePacket.class, 0, Optional.class);
|
||||
SCORE_1_20_2_CONSTRUCTOR = null;
|
||||
SCORE_1_20_3_CONSTRUCTOR = null;
|
||||
} else if (is1_20_3OrAbove) {
|
||||
OBJECTIVE_NUMBER_FORMAT_FIELD = ReflectUtil.findFieldUnchecked(ClientboundSetObjectivePacket.class, 0, NumberFormat.class);
|
||||
SCORE_1_20_3_CONSTRUCTOR = ReflectUtil.findConstructor(ClientboundSetScorePacket.class, String.class, String.class, int.class, Component.class, NumberFormat.class);
|
||||
SCORE_1_20_2_CONSTRUCTOR = null;
|
||||
} else {
|
||||
OBJECTIVE_NUMBER_FORMAT_FIELD = null;
|
||||
SCORE_1_20_3_CONSTRUCTOR = null;
|
||||
SCORE_1_20_2_CONSTRUCTOR = ReflectUtil.findConstructor(ClientboundSetScorePacket.class, ServerScoreboard.Method.class, String.class, String.class, int.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static final boolean IS_1_20_2_OR_ABOVE, IS_1_20_3_OR_ABOVE, IS_1_20_5_OR_ABOVE;
|
||||
|
||||
public static final PacketConstructor<ClientboundSetObjectivePacket> OBJECTIVE_PACKET_CONSTRUCTOR =
|
||||
ReflectUtil.getEmptyConstructor(ClientboundSetObjectivePacket.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, String> OBJECTIVE_NAME_FIELD =
|
||||
ReflectUtil.findField(ClientboundSetObjectivePacket.class, 0, String.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, net.minecraft.network.chat.Component> OBJECTIVE_VALUE_FIELD =
|
||||
ReflectUtil.findField(ClientboundSetObjectivePacket.class, 0, net.minecraft.network.chat.Component.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, ObjectiveCriteria.RenderType> OBJECTIVE_RENDER_TYPE_FIELD =
|
||||
ReflectUtil.findField(ClientboundSetObjectivePacket.class, 0, ObjectiveCriteria.RenderType.class);
|
||||
// Optional<NumberFormat> for 1.20.5+, NumberFormat for below
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, Object> OBJECTIVE_NUMBER_FORMAT_FIELD;
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, Integer> OBJECTIVE_MODE_FIELD =
|
||||
ReflectUtil.findField(ClientboundSetObjectivePacket.class, 0, int.class);
|
||||
|
||||
public static final ConstructorAccessor<ClientboundSetDisplayObjectivePacket> DISPLAY_1_20_1_CONSTRUCTOR =
|
||||
ReflectUtil.findOptionalConstructor(ClientboundSetDisplayObjectivePacket.class, int.class, Objective.class);
|
||||
public static final FieldAccessor<ClientboundSetDisplayObjectivePacket, String> DISPLAY_OBJECTIVE_NAME =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetDisplayObjectivePacket.class, "b", String.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, String> SET_OBJECTIVE_NAME =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "d", String.class);
|
||||
public static final FieldAccessor<ClientboundSetObjectivePacket, Integer> SET_OBJECTIVE_MODE =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetObjectivePacket.class, "g", int.class);
|
||||
ReflectUtil.findField(ClientboundSetDisplayObjectivePacket.class, 0, String.class);
|
||||
|
||||
public static final ConstructorAccessor<ClientboundSetScorePacket> SCORE_1_20_3_CONSTRUCTOR;
|
||||
public static final ConstructorAccessor<ClientboundSetScorePacket> SCORE_1_20_2_CONSTRUCTOR;
|
||||
|
||||
public static final ConstructorAccessor<ClientboundSetPlayerTeamPacket> TEAM_PACKET_CONSTRUCTOR =
|
||||
ReflectUtil.constructorAccessor(ClientboundSetPlayerTeamPacket.class, String.class, int.class, Optional.class, Collection.class);
|
||||
ReflectUtil.findConstructor(ClientboundSetPlayerTeamPacket.class, String.class, int.class, Optional.class, Collection.class);
|
||||
public static final PacketConstructor<ClientboundSetPlayerTeamPacket.Parameters> PARAMETERS_CONSTRUCTOR =
|
||||
ReflectUtil.getEmptyConstructor(ClientboundSetPlayerTeamPacket.Parameters.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, Component> DISPLAY_NAME_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "a", net.minecraft.network.chat.Component.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 0, net.minecraft.network.chat.Component.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, net.minecraft.network.chat.Component> PREFIX_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "b", net.minecraft.network.chat.Component.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 1, net.minecraft.network.chat.Component.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, net.minecraft.network.chat.Component> SUFFIX_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "c", net.minecraft.network.chat.Component.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 2, net.minecraft.network.chat.Component.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, String> NAME_TAG_VISIBILITY_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "d", String.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 0, String.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, String> COLLISION_RULE_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "e", String.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 1, String.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, ChatFormatting> COLOR_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "f", ChatFormatting.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 0, ChatFormatting.class);
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket.Parameters, Integer> OPTIONS_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.Parameters.class, "g", int.class);
|
||||
@SuppressWarnings("rawtypes") // how tf do i fix this
|
||||
public static final FieldAccessor<ClientboundSetPlayerTeamPacket, Collection> ENTRIES_FIELD =
|
||||
ReflectUtil.fieldAccessor(ClientboundSetPlayerTeamPacket.class, "j", Collection.class);
|
||||
ReflectUtil.findField(ClientboundSetPlayerTeamPacket.Parameters.class, 0, int.class);
|
||||
|
||||
private PacketAccessors() {
|
||||
}
|
||||
|
||||
+13
-27
@@ -1,29 +1,23 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.commons.LineRenderingStrategy;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketAdapterProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.objective.PaperObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.objective.SpigotObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.team.PaperTeamsPacketAdapterImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.team.SpigotTeamsPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util.NativeAdventureUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util.PacketUtil;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson;
|
||||
|
||||
public class PacketAdapterProviderImpl implements PacketAdapterProvider, PacketSender<Packet<?>>, ComponentProvider {
|
||||
public class PacketAdapterProviderImpl implements PacketAdapterProvider, PacketSender<Packet<?>> {
|
||||
private boolean isNativeAdventure;
|
||||
private final ComponentProvider componentProvider;
|
||||
|
||||
public PacketAdapterProviderImpl() {
|
||||
try {
|
||||
@@ -38,39 +32,31 @@ public class PacketAdapterProviderImpl implements PacketAdapterProvider, PacketS
|
||||
}
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
|
||||
this.componentProvider = new ComponentProviderImpl(isNativeAdventure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ObjectivePacketAdapter createObjectiveAdapter(@NotNull String objectiveName) {
|
||||
return isNativeAdventure
|
||||
? new PaperObjectivePacketAdapter(this, this, objectiveName)
|
||||
: new SpigotObjectivePacketAdapter(this, this, objectiveName);
|
||||
? new PaperObjectivePacketAdapter(this, componentProvider, objectiveName)
|
||||
: new SpigotObjectivePacketAdapter(this, componentProvider, objectiveName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TeamsPacketAdapter createTeamPacketAdapter(@NotNull String teamName) {
|
||||
return isNativeAdventure
|
||||
? new PaperTeamsPacketAdapterImpl(this, this, teamName)
|
||||
: new SpigotTeamsPacketAdapter(this, this, teamName);
|
||||
? new PaperTeamsPacketAdapterImpl(this, componentProvider, teamName)
|
||||
: new SpigotTeamsPacketAdapter(this, componentProvider, teamName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLegacy(@NotNull Player player) {
|
||||
return false;
|
||||
public @NotNull LineRenderingStrategy lineRenderingStrategy(@NotNull Player player) {
|
||||
return LineRenderingStrategy.MODERN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(@NotNull Player player, @NotNull Packet<?> packet) {
|
||||
PacketUtil.sendPacket(player, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.network.chat.@NotNull Component fromAdventure(@NotNull Component adventure, @NotNull Locale locale) {
|
||||
if (isNativeAdventure) {
|
||||
return NativeAdventureUtil.fromAdventureComponent(adventure);
|
||||
}
|
||||
|
||||
JsonElement json = gson().serializeToTree(GlobalTranslator.render(adventure, locale));
|
||||
return Objects.requireNonNull(net.minecraft.network.chat.Component.Serializer.fromJson(json));
|
||||
}
|
||||
}
|
||||
+52
-26
@@ -2,25 +2,28 @@ package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.object
|
||||
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.ComponentProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.PacketAccessors;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectiveConstants;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ConstructorAccessor;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.objective.ObjectivePacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import net.minecraft.network.chat.numbers.NumberFormat;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundResetScorePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetScorePacket;
|
||||
import net.minecraft.server.ServerScoreboard;
|
||||
import net.minecraft.world.scores.Objective;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class AbstractObjectivePacketAdapter implements ObjectivePacketAdapter {
|
||||
protected final PacketSender<Packet<?>> sender;
|
||||
@@ -42,53 +45,76 @@ public abstract class AbstractObjectivePacketAdapter implements ObjectivePacketA
|
||||
@Override
|
||||
public void remove(@NotNull Collection<Player> players) {
|
||||
if (removePacket == null) {
|
||||
this.removePacket = ReflectUtil.findPacketConstructor(ClientboundSetObjectivePacket.class).invoke();
|
||||
PacketAccessors.SET_OBJECTIVE_NAME.set(removePacket, objectiveName);
|
||||
PacketAccessors.SET_OBJECTIVE_MODE.set(removePacket, ObjectiveConstants.MODE_REMOVE);
|
||||
this.removePacket = ReflectUtil.getEmptyConstructor(ClientboundSetObjectivePacket.class).invoke();
|
||||
PacketAccessors.OBJECTIVE_NAME_FIELD.set(removePacket, objectiveName);
|
||||
PacketAccessors.OBJECTIVE_MODE_FIELD.set(removePacket, ObjectiveConstants.MODE_REMOVE);
|
||||
}
|
||||
sender.sendPacket(players, removePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players, @NotNull String entry, int value) {
|
||||
ClientboundSetScorePacket packet = new ClientboundSetScorePacket(ServerScoreboard.Method.CHANGE, objectiveName, entry, value);
|
||||
sender.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScore(@NotNull Collection<Player> players, @NotNull String entry) {
|
||||
ClientboundSetScorePacket packet = new ClientboundSetScorePacket(ServerScoreboard.Method.REMOVE, objectiveName, entry, 0);
|
||||
Packet<?> packet;
|
||||
if (PacketAccessors.IS_1_20_3_OR_ABOVE) {
|
||||
packet = new ClientboundResetScorePacket(entry, objectiveName);
|
||||
} else {
|
||||
packet = Objects.requireNonNull(PacketAccessors.SCORE_1_20_2_CONSTRUCTOR)
|
||||
.invoke(ServerScoreboard.Method.REMOVE, objectiveName, entry, 0);
|
||||
}
|
||||
sender.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
protected @NotNull ClientboundSetDisplayObjectivePacket createDisplayPacket(@NotNull ObjectiveDisplaySlot displaySlot) {
|
||||
ClientboundSetDisplayObjectivePacket packet;
|
||||
try {
|
||||
Class.forName("net.minecraft.world.scores.DisplaySlot"); // Added in 1.20.2
|
||||
if (PacketAccessors.IS_1_20_2_OR_ABOVE) {
|
||||
packet = new ClientboundSetDisplayObjectivePacket(DisplaySlotProvider.toNms(displaySlot), null);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
ConstructorAccessor<ClientboundSetDisplayObjectivePacket> constructor = ReflectUtil.constructorAccessor(
|
||||
ClientboundSetDisplayObjectivePacket.class,
|
||||
int.class,
|
||||
Objective.class
|
||||
);
|
||||
packet = constructor.invoke(ObjectiveConstants.displaySlotIndex(displaySlot), null);
|
||||
} else {
|
||||
packet = Objects.requireNonNull(PacketAccessors.DISPLAY_1_20_1_CONSTRUCTOR)
|
||||
.invoke(ObjectiveConstants.displaySlotIndex(displaySlot), null);
|
||||
}
|
||||
|
||||
PacketAccessors.DISPLAY_OBJECTIVE_NAME.set(packet, objectiveName);
|
||||
return packet;
|
||||
}
|
||||
|
||||
protected @NotNull ClientboundSetObjectivePacket createPacket(
|
||||
protected @NotNull ClientboundSetScorePacket createScorePacket(
|
||||
@NotNull String entry,
|
||||
int value,
|
||||
@Nullable net.minecraft.network.chat.Component nmsDisplay,
|
||||
@Nullable Object numberFormat
|
||||
) {
|
||||
if (PacketAccessors.IS_1_20_5_OR_ABOVE) {
|
||||
return new ClientboundSetScorePacket(entry, objectiveName, value, Optional.ofNullable(nmsDisplay), Optional.ofNullable((NumberFormat) numberFormat));
|
||||
} else if (PacketAccessors.IS_1_20_3_OR_ABOVE) {
|
||||
return Objects.requireNonNull(PacketAccessors.SCORE_1_20_3_CONSTRUCTOR)
|
||||
.invoke(entry, objectiveName, value, nmsDisplay, numberFormat);
|
||||
} else {
|
||||
return Objects.requireNonNull(PacketAccessors.SCORE_1_20_2_CONSTRUCTOR)
|
||||
.invoke(ServerScoreboard.Method.CHANGE, objectiveName, entry, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected @NotNull ClientboundSetObjectivePacket createObjectivePacket(
|
||||
@NotNull PropertiesPacketType packetType,
|
||||
@NotNull net.minecraft.network.chat.Component nmsValue,
|
||||
@NotNull ObjectiveRenderType renderType
|
||||
@NotNull ObjectiveRenderType renderType,
|
||||
@Nullable Object numberFormat
|
||||
) {
|
||||
ClientboundSetObjectivePacket packet = PacketAccessors.OBJECTIVE_PACKET_CONSTRUCTOR.invoke();
|
||||
PacketAccessors.OBJECTIVE_MODE_FIELD.set(packet, ObjectiveConstants.mode(packetType));
|
||||
PacketAccessors.OBJECTIVE_NAME_FIELD.set(packet, objectiveName);
|
||||
PacketAccessors.OBJECTIVE_VALUE_FIELD.set(packet, nmsValue);
|
||||
|
||||
if (PacketAccessors.IS_1_20_3_OR_ABOVE) {
|
||||
assert PacketAccessors.OBJECTIVE_NUMBER_FORMAT_FIELD != null;
|
||||
Object value;
|
||||
if (PacketAccessors.IS_1_20_5_OR_ABOVE) {
|
||||
value = Optional.ofNullable(numberFormat);
|
||||
} else {
|
||||
value = numberFormat;
|
||||
}
|
||||
PacketAccessors.OBJECTIVE_NUMBER_FORMAT_FIELD.set(packet, value);
|
||||
}
|
||||
|
||||
ObjectiveCriteria.RenderType nmsRenderType;
|
||||
switch (renderType) {
|
||||
case INTEGER:
|
||||
|
||||
+16
-12
@@ -3,39 +3,43 @@ package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.object
|
||||
import io.papermc.paper.adventure.AdventureComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.ComponentProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.PacketAdapterProviderImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util.NativeAdventureUtil;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetScorePacket;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class PaperObjectivePacketAdapter extends AbstractObjectivePacketAdapter {
|
||||
private AdventureComponent lastValue;
|
||||
|
||||
public PaperObjectivePacketAdapter(@NotNull PacketAdapterProviderImpl packetAdapter, @NotNull ComponentProvider componentProvider, @NotNull String objectiveName) {
|
||||
super(packetAdapter, componentProvider, objectiveName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players, @NotNull String entry, int value, @Nullable Component display, @Nullable ScoreFormat scoreFormat) {
|
||||
net.minecraft.network.chat.Component nmsDisplay = display == null ? null : componentProvider.fromAdventure(display, null);
|
||||
Object numberFormat = ScoreFormatConverter.convert(componentProvider, null, scoreFormat);
|
||||
ClientboundSetScorePacket packet = createScorePacket(entry, value, nmsDisplay, numberFormat);
|
||||
sender.sendPacket(players, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendProperties(
|
||||
@NotNull Collection<Player> players,
|
||||
@NotNull PropertiesPacketType packetType,
|
||||
@NotNull Component value,
|
||||
@NotNull ObjectiveRenderType renderType
|
||||
@NotNull ObjectiveRenderType renderType,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
AdventureComponent nmsValue;
|
||||
if (this.lastValue != null && this.lastValue.adventure$component() == value) {
|
||||
nmsValue = this.lastValue;
|
||||
} else {
|
||||
nmsValue = NativeAdventureUtil.fromAdventureComponent(value);
|
||||
this.lastValue = nmsValue;
|
||||
}
|
||||
|
||||
ClientboundSetObjectivePacket packet = createPacket(packetType, nmsValue, renderType);
|
||||
AdventureComponent nmsValue = NativeAdventureUtil.fromAdventureComponent(value);
|
||||
Object numberFormat = ScoreFormatConverter.convert(componentProvider, null, scoreFormat);
|
||||
ClientboundSetObjectivePacket packet = createObjectivePacket(packetType, nmsValue, renderType, numberFormat);
|
||||
sender.sendPacket(players, packet);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.objective;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.ComponentProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.PacketAccessors;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.numbers.BlankFormat;
|
||||
import net.minecraft.network.chat.numbers.FixedFormat;
|
||||
import net.minecraft.network.chat.numbers.StyledFormat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson;
|
||||
|
||||
public final class ScoreFormatConverter {
|
||||
private static final MethodHandle RESULT_UNWRAP_METHOD;
|
||||
|
||||
static {
|
||||
try {
|
||||
RESULT_UNWRAP_METHOD = MethodHandles.lookup().findVirtual(DataResult.class, "result", MethodType.methodType(Optional.class));
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ScoreFormatConverter() {
|
||||
}
|
||||
|
||||
public static @Nullable Object convert(@NotNull ComponentProvider componentProvider, @Nullable Locale locale, @Nullable ScoreFormat format) {
|
||||
if (format == null || !PacketAccessors.IS_1_20_3_OR_ABOVE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (format == ScoreFormat.blank()) {
|
||||
return BlankFormat.INSTANCE;
|
||||
} else if (format instanceof ScoreFormat.Styled) {
|
||||
JsonElement json = gson().serializer().toJsonTree(((ScoreFormat.Styled) format).style());
|
||||
Object result = Style.Serializer.CODEC.parse(JsonOps.INSTANCE, json);
|
||||
Style style;
|
||||
try {
|
||||
//noinspection unchecked,rawtypes
|
||||
style = (Style) ((Optional) RESULT_UNWRAP_METHOD.invokeExact((DataResult) result)).orElseThrow(RuntimeException::new);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new StyledFormat(style);
|
||||
} else if (format instanceof ScoreFormat.Fixed) {
|
||||
return new FixedFormat(componentProvider.fromAdventure(((ScoreFormat.Fixed) format).content(), locale));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid score format: " + format);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-2
@@ -2,12 +2,14 @@ package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.object
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
|
||||
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.ComponentProvider;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.PacketAdapterProviderImpl;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.LocalePacketUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -16,17 +18,30 @@ public class SpigotObjectivePacketAdapter extends AbstractObjectivePacketAdapter
|
||||
super(packetAdapter, componentProvider, objectiveName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendScore(@NotNull Collection<Player> players, @NotNull String entry, int value, @Nullable Component display, @Nullable ScoreFormat scoreFormat) {
|
||||
LocalePacketUtil.sendLocalePackets(sender, players, locale -> {
|
||||
net.minecraft.network.chat.Component nmsDisplay = display == null ? null : componentProvider.fromAdventure(display, locale);
|
||||
Object numberFormat = ScoreFormatConverter.convert(componentProvider, locale, scoreFormat);
|
||||
return createScorePacket(entry, value, nmsDisplay, numberFormat);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendProperties(
|
||||
@NotNull Collection<Player> players,
|
||||
@NotNull PropertiesPacketType packetType,
|
||||
@NotNull Component value,
|
||||
@NotNull ObjectiveRenderType renderType
|
||||
@NotNull ObjectiveRenderType renderType,
|
||||
@Nullable ScoreFormat scoreFormat
|
||||
) {
|
||||
LocalePacketUtil.sendLocalePackets(
|
||||
sender,
|
||||
players,
|
||||
locale -> createPacket(packetType, componentProvider.fromAdventure(value, locale), renderType)
|
||||
locale -> {
|
||||
Object numberFormat = ScoreFormatConverter.convert(componentProvider, locale, scoreFormat);
|
||||
return createObjectivePacket(packetType, componentProvider.fromAdventure(value, locale), renderType, numberFormat);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
-10
@@ -10,8 +10,6 @@ import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPa
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamConstants;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamsPacketAdapter;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.PacketConstructor;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.util.reflect.ReflectUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
@@ -21,12 +19,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class AbstractTeamsPacketAdapterImpl implements TeamsPacketAdapter {
|
||||
static final PacketConstructor<Parameters> parametersConstructor =
|
||||
ReflectUtil.findPacketConstructor(Parameters.class);
|
||||
|
||||
protected final PacketSender<Packet<?>> sender;
|
||||
protected final ComponentProvider componentProvider;
|
||||
protected final String teamName;
|
||||
@@ -72,10 +70,6 @@ public abstract class AbstractTeamsPacketAdapterImpl implements TeamsPacketAdapt
|
||||
sender.sendPacket(players, createTeamsPacket(TeamConstants.mode(packetType), teamName, null, entries));
|
||||
}
|
||||
|
||||
protected void fillTeamPacket(ClientboundSetPlayerTeamPacket packet, Collection<String> entries) {
|
||||
PacketAccessors.ENTRIES_FIELD.set(packet, entries);
|
||||
}
|
||||
|
||||
protected void fillParameters(@NotNull Parameters parameters, @UnknownNullability Locale locale) {
|
||||
String nameTagVisibilityKey = properties.nameTagVisibility().key();
|
||||
PacketAccessors.NAME_TAG_VISIBILITY_FIELD.set(parameters, nameTagVisibilityKey);
|
||||
|
||||
+13
-6
@@ -1,5 +1,6 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.team;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
@@ -29,9 +30,9 @@ public class PaperTeamsPacketAdapterImpl extends AbstractTeamsPacketAdapterImpl
|
||||
}
|
||||
|
||||
private class TeamDisplayPacketAdapterImpl extends AbstractTeamsPacketAdapterImpl.TeamDisplayPacketAdapterImpl {
|
||||
private final ClientboundSetPlayerTeamPacket.Parameters parameters = parametersConstructor.invoke();
|
||||
private final ClientboundSetPlayerTeamPacket createPacket = createTeamsPacket(TeamConstants.MODE_CREATE, teamName, parameters, null);
|
||||
private final ClientboundSetPlayerTeamPacket updatePacket = createTeamsPacket(TeamConstants.MODE_UPDATE, teamName, parameters, null);
|
||||
private final ClientboundSetPlayerTeamPacket.Parameters parameters = PacketAccessors.PARAMETERS_CONSTRUCTOR.invoke();
|
||||
private ClientboundSetPlayerTeamPacket createPacket = null;
|
||||
private ClientboundSetPlayerTeamPacket updatePacket = null;
|
||||
private Component displayName, prefix, suffix;
|
||||
|
||||
public TeamDisplayPacketAdapterImpl(@NotNull ImmutableTeamProperties<Component> properties) {
|
||||
@@ -39,14 +40,20 @@ public class PaperTeamsPacketAdapterImpl extends AbstractTeamsPacketAdapterImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTeamPackets(@NotNull Collection<String> entries) {
|
||||
public void updateTeamPackets() {
|
||||
fillParameters(parameters, null);
|
||||
fillTeamPacket(createPacket, entries);
|
||||
fillTeamPacket(updatePacket, entries);
|
||||
createPacket = null;
|
||||
updatePacket = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendProperties(@NotNull PropertiesPacketType packetType, @NotNull Collection<Player> players) {
|
||||
if (createPacket == null || updatePacket == null) {
|
||||
Collection<String> entries = ImmutableList.copyOf(properties.syncedEntries());
|
||||
createPacket = createTeamsPacket(TeamConstants.MODE_CREATE, teamName, parameters, entries);
|
||||
updatePacket = createTeamsPacket(TeamConstants.MODE_UPDATE, teamName, parameters, entries);
|
||||
}
|
||||
|
||||
switch (packetType) {
|
||||
case CREATE:
|
||||
sender.sendPacket(players, createPacket);
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.team;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.ImmutableTeamProperties;
|
||||
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PacketSender;
|
||||
@@ -13,7 +14,6 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -36,13 +36,14 @@ public class SpigotTeamsPacketAdapter extends AbstractTeamsPacketAdapterImpl {
|
||||
|
||||
@Override
|
||||
public void sendProperties(@NotNull PropertiesPacketType packetType, @NotNull Collection<Player> players) {
|
||||
Collection<String> entries = ImmutableList.copyOf(properties.syncedEntries());
|
||||
LocalePacketUtil.sendLocalePackets(
|
||||
sender,
|
||||
players,
|
||||
locale -> {
|
||||
ClientboundSetPlayerTeamPacket.@NotNull Parameters parameters = parametersConstructor.invoke();
|
||||
ClientboundSetPlayerTeamPacket.@NotNull Parameters parameters = PacketAccessors.PARAMETERS_CONSTRUCTOR.invoke();
|
||||
fillParameters(parameters, locale);
|
||||
return createTeamsPacket(TeamConstants.mode(packetType), teamName, parameters, properties.entries());
|
||||
return createTeamsPacket(TeamConstants.mode(packetType), teamName, parameters, entries);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+13
-11
@@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class PacketUtil {
|
||||
private static final MethodHandle GET_HANDLE;
|
||||
@@ -36,19 +37,20 @@ public final class PacketUtil {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
|
||||
MethodHandle playerConnection;
|
||||
try {
|
||||
playerConnection = lookup.findGetter(ServerPlayer.class, "c", ServerGamePacketListenerImpl.class);
|
||||
} catch (NoSuchFieldException e) {
|
||||
try {
|
||||
playerConnection = lookup.findGetter(ServerPlayer.class, "b", ServerGamePacketListenerImpl.class);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
MethodHandle playerConnection = null;
|
||||
for (Field field : ServerPlayer.class.getFields()) {
|
||||
if (field.getType() == ServerGamePacketListenerImpl.class) {
|
||||
try {
|
||||
playerConnection = lookup.unreflectGetter(field);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
|
||||
|
||||
if (playerConnection == null) {
|
||||
throw new ExceptionInInitializerError("failed to find player connection field");
|
||||
}
|
||||
PLAYER_CONNECTION = playerConnection;
|
||||
|
||||
MethodType sendMethodType = MethodType.methodType(void.class, Packet.class);
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package net.megavex.scoreboardlibrary.implementation.packetAdapter.modern.util;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class RegistryUtil {
|
||||
public static final RegistryAccess MINECRAFT_REGISTRY;
|
||||
|
||||
static {
|
||||
String cbPackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
Class<?> craftRegistry;
|
||||
try {
|
||||
craftRegistry = Class.forName(cbPackage + ".CraftRegistry");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = craftRegistry.getDeclaredMethod("getMinecraftRegistry");
|
||||
MINECRAFT_REGISTRY = (RegistryAccess) method.invoke(null);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private RegistryUtil() {
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("net.megavex.scoreboardlibrary.publish-conventions")
|
||||
id("net.megavex.scoreboardlibrary.base-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
Loaded 100 of 116 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user