Skip to content

Commit 8bf28f5

Browse files
committed
* Added AdvancementCommand in examples:bukkit to demonstrate advancements via PacketEvents.
* Replaced `AdvancementType` with `AdvancementFrameType` for improved clarity across modules. * Updated `AdvancementResolver` to use `AdvancementFrameType` and streamlined icon/background parsing. * Adjusted `build.gradle.kts` with updated repository and dependency configurations for PacketEvents. * Incremented Minecraft version in server tasks to `1.21.8`.
1 parent 7e2adf9 commit 8bf28f5

6 files changed

Lines changed: 56 additions & 52 deletions

File tree

examples/bukkit/build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import gradle.kotlin.dsl.accessors._729aa7c1588b83738f7ec34c0a320432.api
2-
31
plugins {
42
id("java")
53
id("com.gradleup.shadow") version "9.0.0-beta4"
@@ -13,6 +11,7 @@ repositories {
1311
mavenCentral()
1412
maven("https://repo.panda-lang.org/releases/")
1513
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
14+
maven("https://repo.codemc.io/repository/maven-releases/") // packetevents
1615
maven("https://repo.stellardrift.ca/repository/snapshots/")
1716
}
1817

@@ -29,7 +28,7 @@ dependencies {
2928
implementation(project(":multification-cdn"))
3029
implementation(project(":multification-packetevents"))
3130

32-
api("com.github.retrooper:packetevents-spigot:${Versions.PACKETEVENTS}")
31+
compileOnly("com.github.retrooper:packetevents-spigot:${Versions.PACKETEVENTS}")
3332
}
3433

3534
val pluginName = "ExamplePlugin"
@@ -61,5 +60,9 @@ sourceSets.test {
6160
}
6261

6362
tasks.runServer {
64-
minecraftVersion("1.21.4")
63+
minecraftVersion("1.21.8")
64+
65+
downloadPlugins {
66+
downloadPlugins.url("https://cdn.modrinth.com/data/HYKaKraK/versions/Kee6pozk/packetevents-spigot-2.9.5.jar")
67+
}
6568
}

examples/bukkit/src/main/java/com/eternalcode/example/bukkit/ExamplePlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.eternalcode.example.bukkit;
22

3+
import com.eternalcode.example.bukkit.command.AdvancementCommand;
34
import com.eternalcode.example.bukkit.command.GiveCommand;
45
import com.eternalcode.example.bukkit.command.ReloadCommand;
56
import com.eternalcode.example.bukkit.command.TeleportCommand;
@@ -41,6 +42,7 @@ public void onEnable() {
4142
new FlyCommand(multification),
4243
new GiveCommand(multification),
4344
new ReloadCommand(configurationManager, multification),
45+
new AdvancementCommand(multification, this),
4446
new TimerCommand(new TimerManager(this.getServer().getScheduler(), this, multification))
4547
)
4648
.build();

examples/bukkit/src/main/java/com/eternalcode/example/bukkit/command/AdvancementCommand.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package com.eternalcode.example.bukkit.command;
22

33
import com.eternalcode.example.bukkit.multification.YourMultification;
4+
import com.eternalcode.multification.notice.Notice;
45
import com.eternalcode.multification.packetevents.notice.PacketEventsNotice;
6+
import com.eternalcode.multification.packetevents.notice.resolver.AdvancementFrameType;
57
import dev.rollczi.litecommands.annotations.command.Command;
68
import dev.rollczi.litecommands.annotations.context.Context;
79
import dev.rollczi.litecommands.annotations.execute.Execute;
810
import dev.rollczi.litecommands.annotations.permission.Permission;
11+
import org.bukkit.Bukkit;
912
import org.bukkit.entity.Player;
1013

1114
import java.time.Duration;
15+
import org.bukkit.plugin.Plugin;
1216

1317
@Command(name = "testadvancements")
1418
@Permission("example.testadvancements")
1519
public class AdvancementCommand {
1620

1721
private final YourMultification multification;
22+
private final Plugin plugin;
1823

19-
public AdvancementCommand(YourMultification multification) {
24+
public AdvancementCommand(YourMultification multification, Plugin plugin) {
2025
this.multification = multification;
26+
this.plugin = plugin;
2127
}
2228

2329
@Execute(name = "simple")
@@ -39,7 +45,7 @@ void executeChallenge(@Context Player player) {
3945
"<dark_purple>Epic Challenge",
4046
"Hold down Left Button",
4147
"DIAMOND_SWORD",
42-
AdvancementType.CHALLENGE,
48+
AdvancementFrameType.CHALLENGE,
4349
Duration.ofSeconds(5)
4450
))
4551
.send();
@@ -53,7 +59,7 @@ void executeGoal(@Context Player player) {
5359
"<gold>Reach the Goal",
5460
"Destroy the tree",
5561
"OAK_SAPLING",
56-
AdvancementType.GOAL,
62+
AdvancementFrameType.GOAL,
5763
"minecraft:textures/gui/advancements/backgrounds/stone.png"
5864
))
5965
.send();
@@ -68,7 +74,7 @@ void executeCustom(@Context Player player) {
6874
"<red>Custom Toast",
6975
"<gray>With all options configured",
7076
"GOLD_INGOT",
71-
AdvancementType.TASK,
77+
AdvancementFrameType.TASK,
7278
"minecraft:textures/gui/advancements/backgrounds/adventure.png",
7379
true, // showToast
7480
true, // hidden
@@ -84,7 +90,7 @@ void executeCustom(@Context Player player) {
8490
void executeTranslated(@Context Player player) {
8591
this.multification.create()
8692
.viewer(player)
87-
.notice(messages -> messages.welcomeAdvancement)
93+
.notice(Notice.chat("<green>Hello, {player}! This is a translated message."))
8894
.placeholder("{player}", player.getName())
8995
.send();
9096
}
@@ -99,28 +105,27 @@ void executeAll(@Context Player player) {
99105
"<yellow>Wait for it...",
100106
"More coming soon!",
101107
"CLOCK",
102-
AdvancementType.TASK,
108+
AdvancementFrameType.TASK,
103109
Duration.ofSeconds(2)
104110
))
105111
.send();
106112

107-
// Schedule next ones
108-
org.bukkit.Bukkit.getScheduler().runTaskLater(
109-
org.bukkit.Bukkit.getPluginManager().getPlugin("ExamplePlugin"),
113+
Bukkit.getScheduler().runTaskLater(
114+
this.plugin,
110115
() -> executeChallenge(player),
111-
40L // 2 seconds
116+
40L
112117
);
113118

114-
org.bukkit.Bukkit.getScheduler().runTaskLater(
115-
org.bukkit.Bukkit.getPluginManager().getPlugin("ExamplePlugin"),
119+
Bukkit.getScheduler().runTaskLater(
120+
this.plugin,
116121
() -> executeGoal(player),
117122
80L
118123
);
119124

120-
org.bukkit.Bukkit.getScheduler().runTaskLater(
121-
org.bukkit.Bukkit.getPluginManager().getPlugin("ExamplePlugin"),
125+
Bukkit.getScheduler().runTaskLater(
126+
this.plugin,
122127
() -> executeCustom(player),
123-
120L // 6 seconds
128+
120L
124129
);
125130
}
126131
}

multification-packetevents/src/com/eternalcode/multification/packetevents/notice/PacketEventsNotice.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.eternalcode.multification.notice.Notice;
44
import com.eternalcode.multification.packetevents.notice.resolver.AdvancementContent;
5+
import com.eternalcode.multification.packetevents.notice.resolver.AdvancementFrameType;
56
import com.eternalcode.multification.packetevents.notice.resolver.PacketEventsNoticeKey;
6-
import com.github.retrooper.packetevents.protocol.advancements.AdvancementType;
77

88
import java.time.Duration;
99

@@ -21,19 +21,19 @@ public static Notice advancement(String title, String description, String icon)
2121
.build();
2222
}
2323

24-
public static Notice advancement(String title, String description, String icon, AdvancementType frameType) {
24+
public static Notice advancement(String title, String description, String icon, AdvancementFrameType frameType) {
2525
return PacketEventsNotice.builder()
2626
.advancement(title, description, icon, frameType)
2727
.build();
2828
}
2929

30-
public static Notice advancement(String title, String description, String icon, AdvancementType frameType, String background) {
30+
public static Notice advancement(String title, String description, String icon, AdvancementFrameType frameType, String background) {
3131
return PacketEventsNotice.builder()
3232
.advancement(title, description, icon, frameType, background)
3333
.build();
3434
}
3535

36-
public static Notice advancement(String title, String description, String icon, AdvancementType frameType, Duration showTime) {
36+
public static Notice advancement(String title, String description, String icon, AdvancementFrameType frameType, Duration showTime) {
3737
return PacketEventsNotice.builder()
3838
.advancement(title, description, icon, frameType, showTime)
3939
.build();
@@ -53,23 +53,23 @@ public Builder advancement(String title, String description, String icon) {
5353
return this.advancement(title, description, icon, null, null, true, true, 0.0f, 0.0f, null);
5454
}
5555

56-
public Builder advancement(String title, String description, String icon, AdvancementType frameType) {
56+
public Builder advancement(String title, String description, String icon, AdvancementFrameType frameType) {
5757
return this.advancement(title, description, icon, frameType, null, true, true, 0.0f, 0.0f, null);
5858
}
5959

60-
public Builder advancement(String title, String description, String icon, AdvancementType frameType, String background) {
60+
public Builder advancement(String title, String description, String icon, AdvancementFrameType frameType, String background) {
6161
return this.advancement(title, description, icon, frameType, background, true, true, 0.0f, 0.0f, null);
6262
}
6363

64-
public Builder advancement(String title, String description, String icon, AdvancementType frameType, Duration showTime) {
64+
public Builder advancement(String title, String description, String icon, AdvancementFrameType frameType, Duration showTime) {
6565
return this.advancement(title, description, icon, frameType, null, true, true, 0.0f, 0.0f, showTime);
6666
}
6767

6868
public Builder advancement(
6969
String title,
7070
String description,
7171
String icon,
72-
AdvancementType frameType,
72+
AdvancementFrameType frameType,
7373
String background,
7474
boolean showToast,
7575
boolean hidden,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.eternalcode.multification.packetevents.notice.resolver;
22

3+
import com.github.retrooper.packetevents.protocol.advancements.AdvancementType;
4+
35
public enum AdvancementFrameType {
46

57
TASK,
68
CHALLENGE,
79
GOAL;
10+
11+
public AdvancementType toPacketEventsType() {
12+
return AdvancementType.valueOf(this.name());
13+
}
814
}
915

multification-packetevents/src/com/eternalcode/multification/packetevents/notice/resolver/AdvancementResolver.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
import com.github.retrooper.packetevents.protocol.advancements.AdvancementDisplay;
99
import com.github.retrooper.packetevents.protocol.advancements.AdvancementHolder;
1010
import com.github.retrooper.packetevents.protocol.advancements.AdvancementProgress;
11-
import com.github.retrooper.packetevents.protocol.advancements.AdvancementType;
1211
import com.github.retrooper.packetevents.protocol.item.ItemStack;
1312
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
1413
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
1514
import com.github.retrooper.packetevents.protocol.player.User;
1615
import com.github.retrooper.packetevents.resources.ResourceLocation;
1716
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAdvancements;
18-
import java.time.Duration;
1917
import net.kyori.adventure.audience.Audience;
2018
import net.kyori.adventure.key.Key;
2119
import net.kyori.adventure.text.Component;
@@ -26,7 +24,16 @@
2624
import org.jetbrains.annotations.NotNull;
2725
import org.jetbrains.annotations.Nullable;
2826

29-
import java.util.*;
27+
import java.time.Duration;
28+
import java.util.ArrayList;
29+
import java.util.Collections;
30+
import java.util.HashMap;
31+
import java.util.HashSet;
32+
import java.util.List;
33+
import java.util.Map;
34+
import java.util.Optional;
35+
import java.util.Set;
36+
import java.util.UUID;
3037
import java.util.function.UnaryOperator;
3138

3239
public class AdvancementResolver implements TextContentResolver<AdvancementContent> {
@@ -64,14 +71,13 @@ public void send(Audience audience, ComponentSerializer<Component, Component, St
6471
Component descComponent = serializer.deserialize(content.description());
6572

6673
ItemStack icon = this.createIcon(content.iconOrDefault());
67-
6874
ResourceLocation background = this.parseBackground(content.background());
6975

7076
AdvancementDisplay display = new AdvancementDisplay(
7177
titleComponent,
7278
descComponent,
7379
icon,
74-
content.frameTypeOrDefault(),
80+
content.frameTypeOrDefault().toPacketEventsType(),
7581
background,
7682
content.showToast(),
7783
content.hidden(),
@@ -160,8 +166,8 @@ public Optional<AdvancementContent> deserialize(NoticeSerdesResult result) {
160166
String title = parts[0];
161167
String description = parts[1];
162168
String icon = parts.length > 2 && !parts[2].isEmpty() ? parts[2] : null;
163-
AdvancementType frameType = parts.length > 3 && !parts[3].isEmpty()
164-
? AdvancementType.valueOf(parts[3])
169+
AdvancementFrameType frameType = parts.length > 3 && !parts[3].isEmpty()
170+
? AdvancementFrameType.valueOf(parts[3])
165171
: null;
166172
String background = parts.length > 4 && !parts[4].isEmpty() ? parts[4] : null;
167173
boolean showToast = parts.length > 5 ? Boolean.parseBoolean(parts[5]) : AdvancementContent.DEFAULT_SHOW_TOAST;
@@ -205,13 +211,6 @@ public AdvancementContent applyText(AdvancementContent content, UnaryOperator<St
205211
);
206212
}
207213

208-
/**
209-
* Creates an ItemStack icon from material name string.
210-
* Falls back to GRASS_BLOCK if material is invalid.
211-
*
212-
* @param materialName the material name (e.g., "OAK_SAPLING", "DIAMOND")
213-
* @return ItemStack with the specified material type
214-
*/
215214
private ItemStack createIcon(@NotNull String materialName) {
216215
try {
217216
ItemType materialType = ItemTypes.getByName(materialName);
@@ -232,25 +231,14 @@ private ItemStack createIcon(@NotNull String materialName) {
232231
}
233232
}
234233

235-
/**
236-
* Parses ResourceLocation from string format "namespace:path".
237-
* Examples:
238-
* - "minecraft:textures/gui/advancements/backgrounds/stone.png"
239-
* - "mypack:custom/background.png"
240-
*
241-
* @param backgroundString the background string in format "namespace:path"
242-
* @return ResourceLocation or null if string is null/invalid
243-
*/
244234
private ResourceLocation parseBackground(@Nullable String backgroundString) {
245235
if (backgroundString == null || backgroundString.isEmpty()) {
246236
return null;
247237
}
248238

249-
// Split by colon to get namespace and path
250239
String[] parts = backgroundString.split(":", 2);
251240

252241
if (parts.length != 2) {
253-
// Invalid format, default to minecraft namespace
254242
return new ResourceLocation("minecraft", backgroundString);
255243
}
256244

0 commit comments

Comments
 (0)