diff --git a/build.gradle.kts b/build.gradle.kts index 51e8887..0d6f123 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { `java-library` id("io.papermc.paperweight.userdev") version "1.5.5" + id("net.minecrell.plugin-yml.bukkit") version "0.6.0" } group = "dev.plex" @@ -21,6 +22,9 @@ repositories { maven { url = uri("https://repo.rapture.pw/repository/maven-releases/") } + maven { + url = uri("https://oss.sonatype.org/content/repositories/snapshots") + } } dependencies { @@ -28,6 +32,8 @@ dependencies { compileOnly("com.infernalsuite.aswm:api:1.20-R0.1-SNAPSHOT") compileOnly("org.projectlombok:lombok:1.18.28") + library("cloud.commandframework", "cloud-paper", "1.8.3") + annotationProcessor("org.projectlombok:lombok:1.18.28") } @@ -49,16 +55,6 @@ tasks { } processResources { filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything - val props = mapOf( - "name" to project.name, - "version" to project.version, - "description" to project.description, - "apiVersion" to "1.20" - ) - inputs.properties(props) - filesMatching("plugin.yml") { - expand(props) - } } /* @@ -68,4 +64,11 @@ tasks { outputJar.set(layout.buildDirectory.file("libs/PaperweightTestPlugin-${project.version}.jar")) } */ +} + +bukkit { + main = "dev.plex.skyblock.Skyblock" + name = "Plex-Skyblock" + version = project.version.toString() + apiVersion = "1.20" } \ No newline at end of file diff --git a/src/main/java/dev/plex/skyblock/Skyblock.java b/src/main/java/dev/plex/skyblock/Skyblock.java index 1b99b04..3a2934b 100644 --- a/src/main/java/dev/plex/skyblock/Skyblock.java +++ b/src/main/java/dev/plex/skyblock/Skyblock.java @@ -1,5 +1,6 @@ package dev.plex.skyblock; +import dev.plex.skyblock.command.CommandHandler; import dev.plex.skyblock.hook.SlimeWorldHook; import dev.plex.skyblock.listener.PlayerListener; import lombok.Getter; @@ -15,6 +16,7 @@ public final class Skyblock extends JavaPlugin { @Getter private final SlimeWorldHook slimeWorldHook = new SlimeWorldHook(); + @Override public void onLoad() { plugin = this; @@ -22,6 +24,12 @@ public final class Skyblock extends JavaPlugin { @Override public void onEnable() { + try { + new CommandHandler().setup(); + } catch (Exception e) { + throw new RuntimeException(e); + } + getServer().getPluginManager().registerEvents(new PlayerListener(), this); slimeWorldHook.onEnable(this); } diff --git a/src/main/java/dev/plex/skyblock/command/CommandHandler.java b/src/main/java/dev/plex/skyblock/command/CommandHandler.java new file mode 100644 index 0000000..b1c411b --- /dev/null +++ b/src/main/java/dev/plex/skyblock/command/CommandHandler.java @@ -0,0 +1,41 @@ +package dev.plex.skyblock.command; + +import cloud.commandframework.CommandTree; +import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator; +import cloud.commandframework.execution.CommandExecutionCoordinator; +import cloud.commandframework.execution.FilteringCommandSuggestionProcessor; +import cloud.commandframework.paper.PaperCommandManager; +import dev.plex.skyblock.Skyblock; +import org.bukkit.command.CommandSender; + +import java.util.function.Function; + +/** + * @author Taah + * @project plex-skyblock + * @since 10:32 PM [02-07-2023] + */ +public class CommandHandler { + private PaperCommandManager commandManager; + + public void setup() throws Exception { + final Function, CommandExecutionCoordinator> executionCoordinatorFunction = + AsynchronousCommandExecutionCoordinator.builder().build(); + final Function mapperFunction = Function.identity(); + this.commandManager = new PaperCommandManager<>( + Skyblock.plugin(), + executionCoordinatorFunction, + mapperFunction, + mapperFunction + ); + + this.commandManager.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>( + FilteringCommandSuggestionProcessor.Filter.contains(true).andTrimBeforeLastSpace() + )); + this.commandManager.registerBrigadier(); + this.commandManager.registerAsynchronousCompletions(); + + + WorldCommand.register(this.commandManager); + } +} diff --git a/src/main/java/dev/plex/skyblock/command/WorldCommand.java b/src/main/java/dev/plex/skyblock/command/WorldCommand.java new file mode 100644 index 0000000..5f07a5a --- /dev/null +++ b/src/main/java/dev/plex/skyblock/command/WorldCommand.java @@ -0,0 +1,43 @@ +package dev.plex.skyblock.command; + +import cloud.commandframework.ArgumentDescription; +import cloud.commandframework.bukkit.parsers.PlayerArgument; +import cloud.commandframework.bukkit.parsers.WorldArgument; +import cloud.commandframework.paper.PaperCommandManager; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author Taah + * @project plex-skyblock + * @since 9:29 PM [02-07-2023] + */ + +public class WorldCommand { + + public static void register(PaperCommandManager commandManager) { + commandManager.command( + commandManager.commandBuilder("goto", ArgumentDescription.of("Teleports you to a world"), "gotoworld", "world", "tpworld") + .argument(WorldArgument.of("world")) + .senderType(Player.class) + .permission("skyblock.command.goto") + .handler(commandContext -> { + final World world = commandContext.get("world"); + ((Player) commandContext.getSender()).teleportAsync(world.getSpawnLocation()); + }) + ); + + commandManager.command( + commandManager.commandBuilder("goto", ArgumentDescription.of("Teleports a player to a world"), "gotoworld", "world", "tpworld") + .argument(WorldArgument.of("world")) + .argument(PlayerArgument.of("player")) + .permission("skyblock.command.goto.other") + .handler(commandContext -> { + final World world = commandContext.get("world"); + ((Player) commandContext.get("player")).teleportAsync(world.getSpawnLocation()); + }) + ); + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index f6560f6..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: "${name}" -version: "${version}" -main: dev.plex.skyblock.Skyblock -api-version: "1.20"