Skip to content
Open
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
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Messages can be sent to any audience, such as players or the console.

## Supported Platforms

| Platform | Module | Java Version | Adventure API | Status |
|-------------------|------------------------|--------------|-----------------------|------------------------|
| **Paper** | `multification-paper` | Java 21 | Native (built-in) | ✅ Recommended |
| **Bukkit/Spigot** | `multification-bukkit` | Java 8+ | External adapter | ✅ Supported |
| **Velocity** | `multification-velocity` | Java 21+ | Native | ❌ Soon |
| **Core** | `multification-core` | Java 8+ | Custom implementation | For custom platforms |
| Platform | Module | Java Version | Adventure API | Status |
|-------------------|--------------------------|--------------|-----------------------|-------------------------|
| **Paper** | `multification-paper` | Java 21 | Native (built-in) | ✅ Supported |
| **Bukkit/Spigot** | `multification-bukkit` | Java 8+ | External adapter | ✅ Supported |
| **Velocity** | `multification-velocity` | Java 21+ | Native | ✅ Supported |
| **Core** | `multification-core` | Java 8+ | Custom implementation | 🔨 For custom platforms |

> **💡 Recommendation:** Use `multification-paper` for Paper servers (1.19.4+) to leverage native Adventure API without
> external dependencies.
Expand Down Expand Up @@ -175,9 +175,9 @@ public class MessagesConfig {

```java
Cdn cdn = CdnFactory.createYamlLike()
.getSettings()
.withComposer(Notice.class, new MultificationNoticeCdnComposer(multification.getNoticeRegistry()))
.build();
.getSettings()
.withComposer(Notice.class, new MultificationNoticeCdnComposer(multification.getNoticeRegistry()))
.build();
```

#### (CDN) 4. Load the configuration:
Expand Down Expand Up @@ -227,7 +227,10 @@ public class MessagesConfig extends OkaeriConfig {
```java
MessagesConfig config = (MessagesConfig) ConfigManager.create(MessagesConfig.class)
.withConfigurer(new MultificationSerdesPack(multification.getNoticeRegistry()))
.withConfigurer(new SerdesCommons(), new YamlBukkitConfigurer(), new SerdesBukkit()) // specify configurers for your platform
.withConfigurer(
new SerdesCommons(),
new YamlBukkitConfigurer(),
new SerdesBukkit()) // specify configurers for your platform
.withBindFile(new File(dataFolder, "messages.yml"))
.withRemoveOrphans(true) // automatic removal of undeclared keys
.saveDefaults() // save file if does not exists
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

object Versions {

const val ADVENTURE_PLATFORM_BUKKIT = "4.3.3"
Expand All @@ -11,7 +10,9 @@ object Versions {
const val AWAITILITY = "4.3.0"

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

const val JETBRAINS_ANNOTATIONS = "26.0.2-1"


}
47 changes: 47 additions & 0 deletions examples/velocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
id("java")
id("com.gradleup.shadow") version "9.0.0-beta4"
id("xyz.jpenilla.run-velocity") version "3.0.2"
}

version = "1.0.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.panda-lang.org/releases/")
}

dependencies {
compileOnly("com.velocitypowered:velocity-api:${Versions.VELOCITY_API}")
annotationProcessor("com.velocitypowered:velocity-api:${Versions.VELOCITY_API}")

implementation("dev.rollczi:litecommands-velocity:3.10.6")
// implementation("com.eternalcode:multification-velocity:1.2.3") // <-- uncomment in your project
// implementation("com.eternalcode:multification-cdn:1.2.3") // <-- uncomment in your project

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

val pluginName = "ExampleVelocityPlugin"
val packageName = "com.eternalcode.example.velocity"

tasks.shadowJar {
archiveFileName.set("$pluginName v${project.version}.jar")

listOf(
"dev.rollczi.litecommands",
"panda.std",
"panda.utilities",
).forEach { relocate(it, "$packageName.libs.$it") }
}

sourceSets.test {
java.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}

tasks.runVelocity {
velocityVersion("${Versions.VELOCITY_API}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.eternalcode.example;

import com.eternalcode.example.command.ReloadCommand;
import com.eternalcode.example.command.SwitchCommand;
import com.eternalcode.example.config.ConfigurationManager;
import com.eternalcode.example.config.MessagesConfig;
import com.eternalcode.example.notice.ExampleMultification;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.velocity.LiteVelocityFactory;

import java.nio.file.Path;

@Plugin(
id = "example-velocity-plugin",
name = "Example Velocity Plugin",
version = "1.0.0",
description = "An example Velocity plugin demonstrating Multification usage",
authors = { "EternalCode" }
)
public class ExampleVelocityPlugin {

private final ProxyServer server;
private final Path dataDirectory;

private LiteCommands<CommandSource> liteCommands;

@Inject
public ExampleVelocityPlugin(ProxyServer server, @DataDirectory Path dataDirectory) {
this.server = server;
this.dataDirectory = dataDirectory;
}

@Subscribe
void onProxyInitialize(ProxyInitializeEvent event) {
MessagesConfig messagesConfig = new MessagesConfig();
ExampleMultification multification = new ExampleMultification(this, this.server, messagesConfig);

ConfigurationManager configurationManager = new ConfigurationManager(this.dataDirectory.toFile(),
multification.getNoticeRegistry());
configurationManager.load(messagesConfig, "messages.yml");

this.liteCommands = LiteVelocityFactory.builder(this.server)
.commands(
new ReloadCommand(configurationManager, multification),
new SwitchCommand(multification))
.build();

this.server.getEventManager().register(this, new PlayerConnectListener(multification));
}

@Subscribe
void onProxyShutdown(ProxyShutdownEvent event) {
if (this.liteCommands != null) {
this.liteCommands.unregister();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.eternalcode.example;

import com.eternalcode.example.notice.ExampleMultification;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.player.ServerConnectedEvent;

public class PlayerConnectListener {

private final ExampleMultification multification;

public PlayerConnectListener(ExampleMultification multification) {
this.multification = multification;
}

@Subscribe
void onPlayerConnect(ServerConnectedEvent event) {
this.multification.create()
.all()
.notice(messagesConfig -> messagesConfig.joinedTheServer)
.placeholder("<server>", event.getServer().getServerInfo().getName())
.send();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.eternalcode.example.command;

import com.eternalcode.example.config.ConfigurationManager;
import com.eternalcode.example.notice.ExampleMultification;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;

@Command(name = "reload-config")
public class ReloadCommand {

private final ConfigurationManager configurationManager;
private final ExampleMultification multification;

public ReloadCommand(ConfigurationManager configurationManager, ExampleMultification multification) {
this.configurationManager = configurationManager;
this.multification = multification;
}

@Execute
public void execute(@Context CommandSource sender) {
this.configurationManager.reload();

if (sender instanceof Player player) {
this.multification.create()
.player(player.getUniqueId())
.notice(messagesConfig -> messagesConfig.reloadMessage)
.send();
return;
}

this.multification.create()
.console()
.notice(messagesConfig -> messagesConfig.reloadMessage)
.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.eternalcode.example.command;

import com.eternalcode.example.notice.ExampleMultification;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;

@Command(name = "switch")
public class SwitchCommand {

private final ExampleMultification multification;

public SwitchCommand(ExampleMultification multification) {
this.multification = multification;
}

@Execute
void execute(@Context Player player, @Arg RegisteredServer server) {
player.createConnectionRequest(server).fireAndForget();
this.multification.create()
.player(player.getUniqueId())
.notice(messagesConfig -> messagesConfig.switchedServer)
.placeholder("<server>", server.getServerInfo().getName())
.send();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.eternalcode.example.config;

import com.eternalcode.multification.cdn.MultificationNoticeCdnComposer;
import com.eternalcode.multification.notice.Notice;
import com.eternalcode.multification.notice.resolver.NoticeResolverRegistry;
import net.dzikoysk.cdn.Cdn;
import net.dzikoysk.cdn.CdnFactory;
import net.dzikoysk.cdn.source.Source;

import java.io.File;

public class ConfigurationManager {

private final File dataFolder;
private final Cdn cdn;
private MessagesConfig messagesConfig;

public ConfigurationManager(File dataFolder, NoticeResolverRegistry noticeRegistry) {
this.dataFolder = dataFolder;
this.cdn = CdnFactory.createYamlLike()
.getSettings()
.withComposer(Notice.class, new MultificationNoticeCdnComposer(noticeRegistry))
.build();
}

public void load(MessagesConfig config, String fileName) {
this.messagesConfig = config;
File file = new File(this.dataFolder, fileName);

this.cdn.load(Source.of(file), config)
.orThrow(cause -> cause);

this.cdn.render(config, Source.of(file))
.orThrow(cause -> cause);
}

public void reload() {
if (this.messagesConfig != null) {
load(this.messagesConfig, "messages.yml");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.eternalcode.example.config;

import com.eternalcode.multification.notice.Notice;
import net.dzikoysk.cdn.entity.Description;
import net.kyori.adventure.bossbar.BossBar;

import java.time.Duration;

public class MessagesConfig {

@Description("# Join message")
public Notice joinedTheServer = Notice.builder()
.chat("<green><player> has joined the server!")
.bossBar(
BossBar.Color.GREEN,
BossBar.Overlay.PROGRESS,
Duration.ofSeconds(5),
1.0F,
"<green><player> has joined the server!"
)
.sound("minecraft:entity.player.levelup", 1.0F, 1.0F)
.build();

@Description("# Server switch message")
public Notice switchedServer = Notice.builder()
.chat("Switched to <server>!")
.sound("minecraft:entity.enderman.teleport", 1.0F, 1.0F)
.build();

public Notice reloadMessage = Notice.builder()
.chat("<pride:pride>Configuration has been reloaded!")
.sound("minecraft:ambient.basalt_deltas.additions", 1.0F, 1.0F)
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.eternalcode.example.notice;


import com.eternalcode.example.config.MessagesConfig;
import com.eternalcode.multification.adventure.AudienceConverter;
import com.eternalcode.multification.translation.TranslationProvider;
import com.eternalcode.multification.velocity.VelocityMultification;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import org.jetbrains.annotations.NotNull;

public class ExampleMultification extends VelocityMultification<MessagesConfig> {

private final MessagesConfig messagesConfig;
private final MiniMessage miniMessage;

public ExampleMultification(Object plugin, ProxyServer server, MessagesConfig messagesConfig) {
super(server, plugin);
this.messagesConfig = messagesConfig;
this.miniMessage = MiniMessage.miniMessage();
}

@Override
protected @NotNull TranslationProvider<MessagesConfig> translationProvider() {
return locale -> this.messagesConfig;
}

@Override
protected @NotNull ComponentSerializer<Component, Component, String> serializer() {
return this.miniMessage;
}

@Override
protected @NotNull AudienceConverter<CommandSource> audienceConverter() {
return commandSender -> commandSender;
}
}
Loading