Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ object Versions {

const val SPIGOT_API = "1.21.4-R0.1-SNAPSHOT"

const val PACKETEVENTS = "2.9.5"

const val JETBRAINS_ANNOTATIONS = "26.0.2-1"

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ plugins {
repositories {
mavenCentral()

maven("https://papermc.io/repo/repository/maven-public/") // paper, adventure, velocity
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") // spigot
maven("https://repo.panda-lang.org/releases/") // expressible
maven("https://repo.stellardrift.ca/repository/snapshots/")
maven("https://storehouse.okaeri.eu/repository/maven-public/") // okaeri configs
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // adventure snapshots
maven("https://storehouse.okaeri.eu/repository/maven-public/") // okaeri configs
maven("https://repo.stellardrift.ca/repository/snapshots/") // ? xd
maven("https://repo.codemc.io/repository/maven-releases/") // packetevents
maven("https://papermc.io/repo/repository/maven-public/") // paper, adventure, velocity
maven("https://repo.panda-lang.org/releases/") // expressible
}
13 changes: 10 additions & 3 deletions examples/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repositories {
mavenCentral()
maven("https://repo.panda-lang.org/releases/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.codemc.io/repository/maven-releases/") // packetevents
maven("https://repo.stellardrift.ca/repository/snapshots/")
}

Expand All @@ -23,8 +24,10 @@ dependencies {
// implementation("com.eternalcode:multification-bukkit:1.0.3") // <-- uncomment in your project
// implementation("com.eternalcode:multification-cdn:1.0.3") // <-- uncomment in your project

implementation(project(":multification-bukkit")) // don't use this line in your build.gradle
implementation(project(":multification-cdn")) // don't use this line in your build.gradle
implementation(project(":multification-bukkit"))
implementation(project(":multification-cdn"))

compileOnly("com.github.retrooper:packetevents-spigot:${Versions.PACKETEVENTS}")
}

val pluginName = "ExamplePlugin"
Expand Down Expand Up @@ -56,5 +59,9 @@ sourceSets.test {
}

tasks.runServer {
minecraftVersion("1.21.4")
minecraftVersion("1.21.8")

downloadPlugins {
downloadPlugins.url("https://cdn.modrinth.com/data/HYKaKraK/versions/Kee6pozk/packetevents-spigot-2.9.5.jar")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.example.bukkit;

import com.eternalcode.example.bukkit.command.AdvancementCommand;
import com.eternalcode.example.bukkit.command.GiveCommand;
import com.eternalcode.example.bukkit.command.ReloadCommand;
import com.eternalcode.example.bukkit.command.TeleportCommand;
Expand Down Expand Up @@ -41,6 +42,7 @@ public void onEnable() {
new FlyCommand(multification),
new GiveCommand(multification),
new ReloadCommand(configurationManager, multification),
new AdvancementCommand(multification, this),
new TimerCommand(new TimerManager(this.getServer().getScheduler(), this, multification))
)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.eternalcode.example.bukkit.command;

import com.eternalcode.example.bukkit.multification.YourMultification;
import com.eternalcode.multification.notice.Notice;
import com.eternalcode.multification.bukkit.notice.resolver.advancement.PacketEventsNotice;
import com.eternalcode.multification.bukkit.notice.resolver.advancement.AdvancementFrameType;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.time.Duration;

@Command(name = "testadvancements")
@Permission("example.testadvancements")
public class AdvancementCommand {

private final YourMultification multification;
private final Plugin plugin;

public AdvancementCommand(YourMultification multification, Plugin plugin) {
this.multification = multification;
this.plugin = plugin;
}

@Execute(name = "simple")
void executeSimple(@Context Player player) {
// Using simple helper method
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.advancement(
"<green>Simple Achievement",
"You triggered a test advancement!"
))
.send();
}

@Execute(name = "withicon")
void executeWithIcon(@Context Player player) {
// Using helper method with icon
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.advancement(
"<yellow>Achievement Unlocked",
"You found a diamond!",
"DIAMOND"
))
.send();
}

@Execute(name = "challenge")
void executeChallenge(@Context Player player) {
// Using helper method with frame type
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.advancement(
"<dark_purple>Epic Challenge",
"Defeat the Ender Dragon",
"DRAGON_HEAD",
AdvancementFrameType.CHALLENGE
))
.send();
}

@Execute(name = "goal")
void executeGoal(@Context Player player) {
// Using builder for more customization
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.builder()
.title("<gold>Reach the Goal")
.description("Plant 100 trees")
.icon("OAK_SAPLING")
.frameType(AdvancementFrameType.GOAL)
.background("minecraft:textures/gui/advancements/backgrounds/stone.png")
.buildAdvancement())
.send();
}

@Execute(name = "timed")
void executeTimed(@Context Player player) {
// Using builder with show time
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.builder()
.title("<aqua>Quick Message")
.description("This will disappear in 3 seconds")
.icon("CLOCK")
.frameType(AdvancementFrameType.TASK)
.showTime(Duration.ofSeconds(3))
.buildAdvancement())
.send();
}

@Execute(name = "custom")
void executeCustom(@Context Player player) {
// Using builder with full customization
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.builder()
.title("<red>Custom Toast")
.description("<gray>With all options configured")
.icon("GOLD_INGOT")
.frameType(AdvancementFrameType.TASK)
.background("minecraft:textures/gui/advancements/backgrounds/adventure.png")
.position(0.0f, 0.0f)
.showTime(Duration.ofSeconds(5))
.showToast(true)
.hidden(true)
.buildAdvancement())
.send();
}

@Execute(name = "positioned")
void executePositioned(@Context Player player) {
// Custom position example
this.multification.create()
.viewer(player)
.notice(PacketEventsNotice.builder()
.title("<blue>Centered Message")
.description("This appears in the center")
.icon("COMPASS")
.position(0.5f, 0.5f)
.buildAdvancement())
.send();
}

@Execute(name = "translated")
void executeTranslated(@Context Player player) {
// Chat message with placeholder
this.multification.create()
.viewer(player)
.notice(Notice.chat("<green>Hello, {player}! This is a translated message."))
.placeholder("{player}", player.getName())
.send();
}

@Execute(name = "all")
void executeAll(@Context Player player) {
// Show simple first
executeSimple(player);

// Schedule more advancements
Bukkit.getScheduler().runTaskLater(
this.plugin,
() -> executeWithIcon(player),
40L // 2 seconds
);

Bukkit.getScheduler().runTaskLater(
this.plugin,
() -> executeChallenge(player),
80L // 4 seconds
);

Bukkit.getScheduler().runTaskLater(
this.plugin,
() -> executeGoal(player),
120L // 6 seconds
);

Bukkit.getScheduler().runTaskLater(
this.plugin,
() -> executeCustom(player),
160L // 8 seconds
);
}
}
3 changes: 3 additions & 0 deletions multification-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ dependencies {

compileOnly("org.spigotmc:spigot-api:${Versions.SPIGOT_API}")
testImplementation("org.spigotmc:spigot-api:${Versions.SPIGOT_API}")

compileOnly("com.github.retrooper:packetevents-spigot:${Versions.PACKETEVENTS}")
testImplementation("com.github.retrooper:packetevents-spigot:${Versions.PACKETEVENTS}")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.eternalcode.multification.bukkit;

import com.eternalcode.multification.Multification;
import com.eternalcode.multification.bukkit.notice.resolver.advancement.AdvancementResolver;
import com.eternalcode.multification.bukkit.notice.resolver.sound.SoundBukkitResolver;
import com.eternalcode.multification.bukkit.util.PacketEventsUtil;
import com.eternalcode.multification.executor.AsyncExecutor;
import com.eternalcode.multification.locate.LocaleProvider;
import com.eternalcode.multification.viewer.ViewerProvider;
Expand All @@ -17,7 +19,13 @@ public abstract class BukkitMultification<TRANSLATION> extends Multification<Com

protected BukkitMultification() {
super();

// TODO: add special registration method for it?
this.noticeRegistry.registerResolver(new SoundBukkitResolver());

if (PacketEventsUtil.isPacketEventsLoaded()) {
this.noticeRegistry.registerResolver(new AdvancementResolver());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ public class BukkitNotice {

public static Notice sound(Sound sound, SoundCategory category, float volume, float pitch) {
return BukkitNotice.builder()
.sound(sound, category, pitch, volume)
.build();
.sound(sound, category, pitch, volume)
.build();
}

public static Notice sound(Sound sound, float volume, float pitch) {
return BukkitNotice.builder()
.sound(sound, pitch, volume)
.build();
.sound(sound, pitch, volume)
.build();
}

public static Notice sound(Sound sound) {
return BukkitNotice.builder()
.sound(sound)
.build();
.sound(sound)
.build();
}

public static BukkitNotice.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.eternalcode.multification.bukkit.notice.resolver.advancement;

import com.eternalcode.multification.notice.resolver.text.TextContent;
import java.time.Duration;
import java.util.List;
import org.jetbrains.annotations.Nullable;

public record AdvancementContent(
String title,
String description,
@Nullable String icon,
@Nullable AdvancementFrameType frameType,
@Nullable String background,
boolean showToast,
boolean hidden,
float x,
float y,
@Nullable Duration showTime
) implements TextContent {

public static final String DEFAULT_ICON = "GRASS_BLOCK";
public static final AdvancementFrameType DEFAULT_FRAME = AdvancementFrameType.TASK;
public static final boolean DEFAULT_SHOW_TOAST = true;
public static final boolean DEFAULT_HIDDEN = true;
public static final float DEFAULT_X = 0.0f;
public static final float DEFAULT_Y = 0.0f;
public static final Duration DEFAULT_SHOW_TIME = Duration.ofSeconds(1);

public AdvancementContent(String title, String description, @Nullable String icon, @Nullable AdvancementFrameType frameType) {
this(title, description, icon, frameType, null, DEFAULT_SHOW_TOAST, DEFAULT_HIDDEN, DEFAULT_X, DEFAULT_Y, null);
}

@Override
public List<String> contents() {
return List.of(this.title, this.description);
}

public String iconOrDefault() {
return this.icon != null ? this.icon : DEFAULT_ICON;
}

public AdvancementFrameType frameTypeOrDefault() {
return this.frameType != null ? this.frameType : DEFAULT_FRAME;
}

public Duration showTimeOrDefault() {
return this.showTime != null ? this.showTime : DEFAULT_SHOW_TIME;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.eternalcode.multification.bukkit.notice.resolver.advancement;

import com.github.retrooper.packetevents.protocol.advancements.AdvancementType;

public enum AdvancementFrameType {

TASK,
CHALLENGE,
GOAL;

public AdvancementType toPacketEventsType() {
return AdvancementType.valueOf(this.name());
}
}

Loading
Loading