Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-18 Refactor code base, add bukkit sub-module instead of static bukkit impl in core. #35

Merged
merged 4 commits into from
Jun 29, 2024
Merged
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
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
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

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"

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ 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/")
}
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"
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved
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")
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved

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;
}

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

import com.eternalcode.example.bukkit.notice.BukkitNotice;
import com.eternalcode.multification.notice.Notice;
import net.dzikoysk.cdn.entity.Description;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;

public class MessagesConfig {
@Description("# Fly command message")
public Notice selfFlyCommandMessage = Notice.chat("<green>You have toggled fly mode. It is now <yellow>{state}</yellow>.");
public Notice otherFlyCommandMessage = Notice.chat("<green>You have toggled fly mode for <yellow>{player}</yellow>. It is now <yellow>{state}</yellow>.");
public Notice otherFlyCommandMessageTarget = BukkitNotice.builder()
.chat("<green>Your fly mode has been toggled by <yellow>{player}</yellow>. It is now <yellow>{state}</yellow>.")
.sound(Sound.ENTITY_ITEM_PICKUP)
.build();

@Description("# Give command message")
public Notice senderGiveCommandMessage = Notice.title("<green>You have given <yellow>{amount}x {item}</yellow> to <yellow>{player}</yellow>.");
public Notice receiverGiveCommandMessage = BukkitNotice.builder()
.title("<green>You have received <yellow>{amount}x {item}</yellow> from <yellow>{player}</yellow>.")
.subtitle("<pride:progress>Remember to say thank you!</pride>")
.sound(Sound.ENTITY_ITEM_PICKUP)
.build();

@Description("# Teleport command message")
public Notice selfTeleportCommandMessage = BukkitNotice.builder()
.actionBar("<green>You have been teleported to <yellow>{player}</yellow>.")
.sound(Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 2.0F, 2.0F)
.build();

}
Loading