Skip to content

Commit

Permalink
Merge branch 'master' into add-okaeri-serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Jun 29, 2024
2 parents 6d6db59 + d844e92 commit 215f6dd
Show file tree
Hide file tree
Showing 64 changed files with 1,832 additions and 372 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
build
.idea
.idea
run
17 changes: 17 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

object Versions {

const val ADVENTURE_PLATFORM_BUKKIT = "4.3.3-SNAPSHOT"
const val ADVENTURE_API = "4.18.0-SNAPSHOT"
const val CDN = "1.14.5"

const val MOCKITO_CORE = "5.12.0"
const val JUNIT_JUPITER = "5.10.2"
const val ASSERTJ_CORE = "3.26.0"
const val AWAITILITY = "4.2.1"

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

const val JETBRAINS_ANNOTATIONS = "24.1.0"

}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/multification-java-17.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("java-library")
`java-library`
}

java {
Expand Down
14 changes: 7 additions & 7 deletions buildSrc/src/main/kotlin/multification-java-unit-test.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
id("java-library")
`java-library`
}

dependencies {
testImplementation("org.mockito:mockito-core:5.12.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
testImplementation("org.assertj:assertj-core:3.26.0")
testImplementation("org.awaitility:awaitility:4.2.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.mockito:mockito-core:${Versions.MOCKITO_CORE}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT_JUPITER}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT_JUPITER}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT_JUPITER}")
testImplementation("org.assertj:assertj-core:${Versions.ASSERTJ_CORE}")
testImplementation("org.awaitility:awaitility:${Versions.AWAITILITY}")
}

tasks.getByName<Test>("test") {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/multification-java.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("java-library")
`java-library`
}

java {
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/multification-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id("java-library")
id("maven-publish")
`java-library`
`maven-publish`
}

group = "com.eternalcode"
version = "1.0.3-SNAPSHOT"
version = "1.1.0"

java {
withSourcesJar()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("java-library")
`java-library`
}

repositories {
Expand All @@ -8,5 +8,6 @@ repositories {
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
}
60 changes: 60 additions & 0 deletions examples/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
id("xyz.jpenilla.run-paper") version "2.3.0"
}

version = "1.0.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://repo.panda-lang.org/releases/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.stellardrift.ca/repository/snapshots/")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")

implementation("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM_BUKKIT}")
implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_API}")
implementation("dev.rollczi:litecommands-bukkit:3.4.1")
// 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
}

val pluginName = "ExamplePlugin"
val packageName = "com.eternalcode.example.bukkit"

bukkit {
main = "$packageName.$pluginName"
apiVersion = "1.13"
author = "Rollczi"
name = pluginName
version = "${project.version}"
}

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

listOf(
"com.eternalcode.multification",
"net.dzikoysk.cdn",
"panda.std",
"panda.utilities",
"net.kyori",
).forEach { relocate(it, "$packageName.libs.$it") }
}

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

tasks.runServer {
minecraftVersion("1.20.4")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.eternalcode.example.bukkit;

import com.eternalcode.example.bukkit.command.GiveCommand;
import com.eternalcode.example.bukkit.command.TeleportCommand;
import com.eternalcode.example.bukkit.config.ConfigurationManager;
import com.eternalcode.example.bukkit.config.MessagesConfig;
import com.eternalcode.example.bukkit.multification.YourMultification;
import com.eternalcode.example.bukkit.command.FlyCommand;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import dev.rollczi.litecommands.LiteCommands;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class ExamplePlugin extends JavaPlugin {

private LiteCommands<CommandSender> liteCommands;
private AudienceProvider audienceProvider;

@Override
public void onEnable() {
// Kyori Adventure platform
audienceProvider = BukkitAudiences.create(this);
MiniMessage miniMessage = MiniMessage.miniMessage();

// Config & Multification
MessagesConfig messagesConfig = new MessagesConfig();
YourMultification multification = new YourMultification(messagesConfig, audienceProvider, miniMessage);

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

this.liteCommands = LiteBukkitFactory.builder()
.commands(
new TeleportCommand(multification),
new FlyCommand(multification),
new GiveCommand(multification)
)
.build();
}

@Override
public void onDisable() {
// unregister all commands from bukkit
if (this.liteCommands != null) {
this.liteCommands.unregister();
}

// close audience provider
if (this.audienceProvider != null) {
this.audienceProvider.close();
}
}

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

import com.eternalcode.example.bukkit.multification.YourMultification;
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;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@Command(name = "fly", aliases = {"f"})
@Permission("example.fly")
public class FlyCommand {

private final YourMultification multification;

public FlyCommand(YourMultification multification) {
this.multification = multification;
}

@Execute
void execute(@Context Player sender) {
sender.setAllowFlight(!sender.getAllowFlight());
multification.create()
.player(sender.getUniqueId())
.notice(messages -> messages.selfFlyCommandMessage)
.placeholder("{state}", sender.getAllowFlight() ? "enabled" : "disabled")
.send();
}

@Execute
void executeOther(@Context CommandSender sender, @Arg Player target) {
target.setAllowFlight(!target.getAllowFlight());

multification.create()
.player(target.getUniqueId())
.notice(messages -> messages.selfFlyCommandMessage)
.placeholder("{state}", target.getAllowFlight() ? "enabled" : "disabled")
.send();

multification.create()
.viewer(sender)
.notice(messages -> messages.otherFlyCommandMessage)
.placeholder("{state}", target.getAllowFlight() ? "enabled" : "disabled")
.placeholder("{player}", target.getName())
.send();

multification.create()
.player(target.getUniqueId())
.notice(messages -> messages.otherFlyCommandMessageTarget)
.placeholder("{state}", target.getAllowFlight() ? "enabled" : "disabled")
.placeholder("{player}", sender.getName())
.send();
}

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

import com.eternalcode.example.bukkit.multification.YourMultification;
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;
import dev.rollczi.litecommands.annotations.optional.OptionalArg;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

@Command(name = "give")
public class GiveCommand {

private final YourMultification multification;

public GiveCommand(YourMultification multification) {
this.multification = multification;
}

@Execute
public void execute(
@Context CommandSender commandSender,
@Arg("nick") Player target,
@Arg("item") Material item,
@OptionalArg("amount") Integer amount
) {
if (amount == null) {
amount = 1;
}

multification.create()
.player(target.getUniqueId())
.notice(messages -> messages.receiverGiveCommandMessage)
.placeholder("{player}", commandSender.getName())
.placeholder("{amount}", amount.toString())
.placeholder("{item}", item.name())
.send();


multification
.create()
.viewer(commandSender)
.notice(messages -> messages.senderGiveCommandMessage)
.placeholder("{player}", target.getName())
.placeholder("{amount}", amount.toString())
.placeholder("{item}", item.name())
.send();

target.getInventory().addItem(new ItemStack(item, amount));
}

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

import com.eternalcode.example.bukkit.multification.YourMultification;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import dev.rollczi.litecommands.annotations.command.Command;
import org.bukkit.entity.Player;

@Command(name = "teleport", aliases = "tp")
@Permission("dev.rollczi.teleport")
public class TeleportCommand {

private final YourMultification multification;

public TeleportCommand(YourMultification multification) {
this.multification = multification;
}

@Execute
public void teleportSelf(@Context Player sender, @Arg Player to) {
multification.create()
.player(sender.getUniqueId())
.notice(messages -> messages.selfTeleportCommandMessage)
.placeholder("{player}", to.getName())
.send();

sender.teleport(to.getLocation());
}

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

import com.eternalcode.multification.cdn.MultificationNoticeCdnComposer;
import com.eternalcode.multification.notice.Notice;
import com.eternalcode.multification.notice.resolver.NoticeResolverRegistry;
import java.io.File;
import net.dzikoysk.cdn.Cdn;
import net.dzikoysk.cdn.CdnFactory;
import net.dzikoysk.cdn.reflect.Visibility;
import net.dzikoysk.cdn.source.Source;
public class ConfigurationManager {

private final Cdn cdn;
private final File dataFolder;

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

public <T> T load(T config, String fileName) {
this.cdn.load(Source.of(this.dataFolder, fileName), config)
.orThrow(RuntimeException::new);

this.cdn.render(config, Source.of(this.dataFolder, fileName))
.orThrow(RuntimeException::new);

return config;
}

}
Loading

0 comments on commit 215f6dd

Please sign in to comment.