Skip to content

Commit fb0d193

Browse files
committed
merge adventure serializer legacy into project
1 parent b950109 commit fb0d193

11 files changed

Lines changed: 1295 additions & 5 deletions

File tree

modules/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ subprojects {
2424
setupLibraries(
2525
key="adventure",
2626
"net.kyori:adventure-api:4.25.0",
27-
"net.kyori:adventure-text-serializer-legacy:4.4.1",
2827
"net.kyori:adventure-text-serializer-gson:4.25.0",
2928
"net.kyori:adventure-text-minimessage:4.25.0",
3029
)

modules/library/src/main/java/top/mrxiaom/pluginbase/utils/adventure/audience/AudienceConsole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import net.kyori.adventure.audience.Audience;
44
import net.kyori.adventure.text.Component;
5-
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
65
import net.md_5.bungee.api.chat.BaseComponent;
76
import org.bukkit.Bukkit;
87
import org.bukkit.command.ConsoleCommandSender;
98
import org.jetbrains.annotations.NotNull;
109
import top.mrxiaom.pluginbase.utils.adventure.serializer.BungeeComponentSerializer;
10+
import top.mrxiaom.pluginbase.utils.adventure.serializer.legacy.LegacyComponentSerializer;
1111

1212
public class AudienceConsole implements Audience {
1313
private static boolean SUPPORT_BUNGEE = true;

modules/library/src/main/java/top/mrxiaom/pluginbase/utils/adventure/audience/AudiencePlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.kyori.adventure.sound.Sound;
66
import net.kyori.adventure.sound.SoundStop;
77
import net.kyori.adventure.text.Component;
8-
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
98
import net.kyori.adventure.title.Title;
109
import net.md_5.bungee.api.ChatMessageType;
1110
import net.md_5.bungee.api.chat.BaseComponent;
@@ -15,6 +14,7 @@
1514
import org.bukkit.entity.Player;
1615
import org.jetbrains.annotations.NotNull;
1716
import top.mrxiaom.pluginbase.utils.adventure.serializer.BungeeComponentSerializer;
17+
import top.mrxiaom.pluginbase.utils.adventure.serializer.legacy.LegacyComponentSerializer;
1818

1919
public class AudiencePlayer implements Audience {
2020
private static boolean SUPPORT_BUNGEE = true;
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2025 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package top.mrxiaom.pluginbase.utils.adventure.serializer.legacy;
25+
26+
import java.util.List;
27+
import java.util.stream.Stream;
28+
import net.kyori.adventure.text.format.NamedTextColor;
29+
import net.kyori.adventure.text.format.TextDecoration;
30+
import net.kyori.adventure.text.format.TextFormat;
31+
import net.kyori.examination.Examinable;
32+
import net.kyori.examination.ExaminableProperty;
33+
import org.jetbrains.annotations.ApiStatus;
34+
import org.jetbrains.annotations.NotNull;
35+
import org.jetbrains.annotations.Unmodifiable;
36+
37+
/**
38+
* A combination of a {@code character}, a {@link TextFormat}, and if the character is {@link #caseInsensitive()}.
39+
*
40+
* @since 4.14.0
41+
*/
42+
@ApiStatus.NonExtendable
43+
public interface CharacterAndFormat extends Examinable {
44+
/**
45+
* Character and format pair representing {@link NamedTextColor#BLACK}.
46+
*
47+
* @since 4.14.0
48+
*/
49+
CharacterAndFormat BLACK = characterAndFormat('0', NamedTextColor.BLACK, true);
50+
/**
51+
* Character and format pair representing {@link NamedTextColor#DARK_BLUE}.
52+
*
53+
* @since 4.14.0
54+
*/
55+
CharacterAndFormat DARK_BLUE = characterAndFormat('1', NamedTextColor.DARK_BLUE, true);
56+
/**
57+
* Character and format pair representing {@link NamedTextColor#DARK_GREEN}.
58+
*
59+
* @since 4.14.0
60+
*/
61+
CharacterAndFormat DARK_GREEN = characterAndFormat('2', NamedTextColor.DARK_GREEN, true);
62+
/**
63+
* Character and format pair representing {@link NamedTextColor#DARK_AQUA}.
64+
*
65+
* @since 4.14.0
66+
*/
67+
CharacterAndFormat DARK_AQUA = characterAndFormat('3', NamedTextColor.DARK_AQUA, true);
68+
/**
69+
* Character and format pair representing {@link NamedTextColor#DARK_RED}.
70+
*
71+
* @since 4.14.0
72+
*/
73+
CharacterAndFormat DARK_RED = characterAndFormat('4', NamedTextColor.DARK_RED, true);
74+
/**
75+
* Character and format pair representing {@link NamedTextColor#DARK_PURPLE}.
76+
*
77+
* @since 4.14.0
78+
*/
79+
CharacterAndFormat DARK_PURPLE = characterAndFormat('5', NamedTextColor.DARK_PURPLE, true);
80+
/**
81+
* Character and format pair representing {@link NamedTextColor#GOLD}.
82+
*
83+
* @since 4.14.0
84+
*/
85+
CharacterAndFormat GOLD = characterAndFormat('6', NamedTextColor.GOLD, true);
86+
/**
87+
* Character and format pair representing {@link NamedTextColor#GRAY}.
88+
*
89+
* @since 4.14.0
90+
*/
91+
CharacterAndFormat GRAY = characterAndFormat('7', NamedTextColor.GRAY, true);
92+
/**
93+
* Character and format pair representing {@link NamedTextColor#DARK_GRAY}.
94+
*
95+
* @since 4.14.0
96+
*/
97+
CharacterAndFormat DARK_GRAY = characterAndFormat('8', NamedTextColor.DARK_GRAY, true);
98+
/**
99+
* Character and format pair representing {@link NamedTextColor#BLUE}.
100+
*
101+
* @since 4.14.0
102+
*/
103+
CharacterAndFormat BLUE = characterAndFormat('9', NamedTextColor.BLUE, true);
104+
/**
105+
* Character and format pair representing {@link NamedTextColor#GREEN}.
106+
*
107+
* @since 4.14.0
108+
*/
109+
CharacterAndFormat GREEN = characterAndFormat('a', NamedTextColor.GREEN, true);
110+
/**
111+
* Character and format pair representing {@link NamedTextColor#AQUA}.
112+
*
113+
* @since 4.14.0
114+
*/
115+
CharacterAndFormat AQUA = characterAndFormat('b', NamedTextColor.AQUA, true);
116+
/**
117+
* Character and format pair representing {@link NamedTextColor#RED}.
118+
*
119+
* @since 4.14.0
120+
*/
121+
CharacterAndFormat RED = characterAndFormat('c', NamedTextColor.RED, true);
122+
/**
123+
* Character and format pair representing {@link NamedTextColor#LIGHT_PURPLE}.
124+
*
125+
* @since 4.14.0
126+
*/
127+
CharacterAndFormat LIGHT_PURPLE = characterAndFormat('d', NamedTextColor.LIGHT_PURPLE, true);
128+
/**
129+
* Character and format pair representing {@link NamedTextColor#YELLOW}.
130+
*
131+
* @since 4.14.0
132+
*/
133+
CharacterAndFormat YELLOW = characterAndFormat('e', NamedTextColor.YELLOW, true);
134+
/**
135+
* Character and format pair representing {@link NamedTextColor#WHITE}.
136+
*
137+
* @since 4.14.0
138+
*/
139+
CharacterAndFormat WHITE = characterAndFormat('f', NamedTextColor.WHITE, true);
140+
141+
/**
142+
* Character and format pair representing {@link TextDecoration#OBFUSCATED}.
143+
*
144+
* @since 4.14.0
145+
*/
146+
CharacterAndFormat OBFUSCATED = characterAndFormat('k', TextDecoration.OBFUSCATED, true);
147+
/**
148+
* Character and format pair representing {@link TextDecoration#BOLD}.
149+
*
150+
* @since 4.14.0
151+
*/
152+
CharacterAndFormat BOLD = characterAndFormat('l', TextDecoration.BOLD, true);
153+
/**
154+
* Character and format pair representing {@link TextDecoration#STRIKETHROUGH}.
155+
*
156+
* @since 4.14.0
157+
*/
158+
CharacterAndFormat STRIKETHROUGH = characterAndFormat('m', TextDecoration.STRIKETHROUGH, true);
159+
/**
160+
* Character and format pair representing {@link TextDecoration#UNDERLINED}.
161+
*
162+
* @since 4.14.0
163+
*/
164+
CharacterAndFormat UNDERLINED = characterAndFormat('n', TextDecoration.UNDERLINED, true);
165+
/**
166+
* Character and format pair representing {@link TextDecoration#ITALIC}.
167+
*
168+
* @since 4.14.0
169+
*/
170+
CharacterAndFormat ITALIC = characterAndFormat('o', TextDecoration.ITALIC, true);
171+
172+
/**
173+
* Character and format pair representing {@link Reset#INSTANCE}.
174+
*
175+
* @since 4.14.0
176+
*/
177+
CharacterAndFormat RESET = characterAndFormat('r', Reset.INSTANCE, true);
178+
179+
/**
180+
* Creates a new combination of a case-sensitive {@code character} and a {@link TextFormat}.
181+
*
182+
* @param character the character
183+
* @param format the format
184+
* @return a new character and format instance.
185+
* @since 4.14.0
186+
*/
187+
static @NotNull CharacterAndFormat characterAndFormat(final char character, final @NotNull TextFormat format) {
188+
return characterAndFormat(character, format, false);
189+
}
190+
191+
/**
192+
* Creates a new combination of a {@code character} and a {@link TextFormat}.
193+
*
194+
* @param character the character
195+
* @param format the format
196+
* @param caseInsensitive if the character is case-insensitive
197+
* @return a new character and format instance.
198+
* @since 4.17.0
199+
*/
200+
static @NotNull CharacterAndFormat characterAndFormat(final char character, final @NotNull TextFormat format, final boolean caseInsensitive) {
201+
return new CharacterAndFormatImpl(character, format, caseInsensitive);
202+
}
203+
204+
/**
205+
* Gets an unmodifiable list of character and format instances containing all default vanilla formats.
206+
*
207+
* @return an unmodifiable list of character and format instances containing all default vanilla formats
208+
* @since 4.14.0
209+
*/
210+
@Unmodifiable
211+
static @NotNull List<CharacterAndFormat> defaults() {
212+
return CharacterAndFormatImpl.Defaults.DEFAULTS;
213+
}
214+
215+
/**
216+
* Gets the character.
217+
*
218+
* @return the character
219+
* @since 4.14.0
220+
*/
221+
char character();
222+
223+
/**
224+
* Gets the format.
225+
*
226+
* @return the format
227+
* @since 4.14.0
228+
*/
229+
@NotNull TextFormat format();
230+
231+
/**
232+
* If the {@link #character()} is case-insensitive.
233+
*
234+
* @return if the character is case-insensitive
235+
* @since 4.17.0
236+
*/
237+
boolean caseInsensitive();
238+
239+
@Override
240+
default @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
241+
return Stream.of(
242+
ExaminableProperty.of("character", this.character()),
243+
ExaminableProperty.of("format", this.format()),
244+
ExaminableProperty.of("caseInsensitive", this.caseInsensitive())
245+
);
246+
}
247+
}

0 commit comments

Comments
 (0)