generated from UndefinedCreations/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(version-support): add 1.19.4, 1.19.3, 1.19.2 support
- Loading branch information
1 parent
d326e6a
commit 344a574
Showing
25 changed files
with
2,445 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = "stellar" | ||
include("server", "api", "common", "v1_20", "v1_20_1", "v1_20_2", "v1_20_4", "v1_20_6", "v1_21", "v1_21_1", "v1_21_3", "v1_21_4") | ||
include("server", "api", "common", "v1_19_2", "v1_19_3", "v1_19_4", "v1_20", "v1_20_1", "v1_20_2", "v1_20_4", "v1_20_6", "v1_21", "v1_21_1", "v1_21_3", "v1_21_4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.22" | ||
id("io.papermc.paperweight.userdev") version "1.7.1" | ||
} | ||
|
||
paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION | ||
|
||
dependencies { | ||
paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT") | ||
pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat") | ||
compileOnly(project(":common")) | ||
} | ||
|
||
tasks { | ||
compileKotlin { | ||
kotlinOptions.jvmTarget = "17" | ||
} | ||
} | ||
|
||
java { | ||
disableAutoTargetJvm() | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} |
486 changes: 486 additions & 0 deletions
486
v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/ArgumentHelper.kt
Large diffs are not rendered by default.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/BrigadierCommandHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.undefined.stellar.v1_19_2 | ||
|
||
import com.mojang.brigadier.builder.LiteralArgumentBuilder | ||
import com.mojang.brigadier.context.CommandContext | ||
import com.mojang.brigadier.tree.LiteralCommandNode | ||
import com.undefined.stellar.AbstractStellarCommand | ||
import com.undefined.stellar.argument.AbstractStellarArgument | ||
import com.undefined.stellar.data.help.CustomCommandHelpTopic | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer | ||
import net.minecraft.commands.CommandSourceStack | ||
import net.minecraft.server.MinecraftServer | ||
import org.bukkit.Bukkit | ||
|
||
object BrigadierCommandHelper { | ||
|
||
val COMMAND_SOURCE: CommandSourceStack by lazy { | ||
MinecraftServer.getServer().createCommandSourceStack() | ||
} | ||
val dispatcher by lazy { MinecraftServer.getServer().functions.dispatcher } | ||
val version: String = "1.19.2" | ||
|
||
fun register(command: LiteralArgumentBuilder<CommandSourceStack>): LiteralCommandNode<CommandSourceStack>? = | ||
dispatcher.register(command) | ||
|
||
fun handleHelpTopic(command: AbstractStellarCommand<*>) { | ||
Bukkit.getServer().helpMap.addTopic( | ||
CustomCommandHelpTopic(command.name, command.description, command.helpTopic) { | ||
val context = MinecraftServer.getServer().createCommandSourceStack() | ||
val requirements = command.requirements.all { it(this) } | ||
val permissionRequirements = command.permissionRequirements.all { | ||
if (it.permission.isEmpty()) context.hasPermission(it.level) | ||
else context.hasPermission(it.level, it.permission) | ||
} | ||
requirements.and(permissionRequirements) | ||
} | ||
) | ||
} | ||
|
||
fun handleExecutions(command: AbstractStellarCommand<*>, context: CommandContext<CommandSourceStack>) { | ||
val stellarContext = CommandContextAdapter.getStellarCommandContext(context) | ||
|
||
for (runnable in command.base.runnables) runnable(stellarContext) | ||
val arguments = getArguments(command.base, context) | ||
for (argument in arguments) for (runnable in argument.runnables) runnable(stellarContext) | ||
for (execution in command.executions) execution(stellarContext) | ||
} | ||
|
||
fun fulfillsRequirements(command: AbstractStellarCommand<*>, source: CommandSourceStack): Boolean { | ||
val fulfillsExecutionRequirements = command.requirements.all { it(source.bukkitSender) } | ||
val fulfillsPermissionRequirements = command.permissionRequirements.all { source.hasPermission(it.level, it.permission) } | ||
return fulfillsExecutionRequirements.and(fulfillsPermissionRequirements) | ||
} | ||
|
||
fun handleFailureMessageAndExecutions(command: AbstractStellarCommand<*>, context: CommandContext<CommandSourceStack>) { | ||
for (execution in command.failureExecutions) execution(CommandContextAdapter.getStellarCommandContext(context)) | ||
for (message in command.failureMessages) context.source.bukkitSender.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)) | ||
for (message in command.globalFailureMessages) context.source.bukkitSender.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)) | ||
} | ||
|
||
fun getArguments( | ||
baseCommand: AbstractStellarCommand<*>, | ||
context: CommandContext<CommandSourceStack>, | ||
currentIndex: Int = 1, | ||
listOfArguments: List<AbstractStellarArgument<*>> = emptyList() | ||
): List<AbstractStellarArgument<*>> { | ||
if (listOfArguments.size == context.nodes.size - 1) return listOfArguments | ||
for (argument in baseCommand.arguments) | ||
if (argument.name == context.nodes[currentIndex].node.name) | ||
return getArguments(argument, context, currentIndex + 1, listOfArguments + argument) | ||
return emptyList() | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.undefined.stellar.v1_19_2 | ||
|
||
import com.mojang.brigadier.Command | ||
import com.mojang.brigadier.builder.ArgumentBuilder | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder | ||
import com.undefined.stellar.AbstractStellarCommand | ||
import com.undefined.stellar.argument.AbstractStellarArgument | ||
import com.undefined.stellar.argument.LiteralStellarArgument | ||
import com.undefined.stellar.argument.types.primitive.PhraseArgument | ||
import net.minecraft.commands.CommandSourceStack | ||
|
||
object CommandAdapter { | ||
|
||
fun getBaseCommand(command: AbstractStellarCommand<*>, name: String = command.name): LiteralArgumentBuilder<CommandSourceStack> { | ||
val brigadierCommand = LiteralArgumentBuilder.literal<CommandSourceStack>(name) | ||
handleCommandFunctions(command, brigadierCommand) | ||
handleArguments(command, brigadierCommand) | ||
return brigadierCommand | ||
} | ||
|
||
fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder<CommandSourceStack, *>) { | ||
if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) | ||
brigadierCommand.executes { context -> | ||
BrigadierCommandHelper.handleExecutions(command, context) | ||
1 | ||
} | ||
brigadierCommand.requires { source -> | ||
BrigadierCommandHelper.fulfillsRequirements(command, source) | ||
} | ||
} | ||
|
||
fun handleArguments(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder<CommandSourceStack, *>) { | ||
for (argument in command.arguments) { | ||
when (argument) { | ||
is LiteralStellarArgument -> handleLiteralArgument(argument, brigadierCommand) | ||
is PhraseArgument-> handlePhraseArgument(argument, brigadierCommand) | ||
else -> handleRequiredArgument(argument, brigadierCommand) | ||
} | ||
} | ||
} | ||
|
||
private fun handleLiteralArgument(argument: LiteralStellarArgument, brigadierCommand: ArgumentBuilder<CommandSourceStack, *>) { | ||
for (argumentBuilder in ArgumentHelper.getLiteralArguments(argument)) { | ||
handleCommandFunctions(argument, argumentBuilder) | ||
handleArguments(argument, argumentBuilder) | ||
brigadierCommand.then(argumentBuilder) | ||
} | ||
} | ||
|
||
private fun handlePhraseArgument(argument: PhraseArgument, brigadierCommand: ArgumentBuilder<CommandSourceStack, *>) { | ||
val argumentBuilder = ArgumentHelper.getRequiredArgumentBuilder(argument) | ||
handleCommandFunctions(argument, argumentBuilder) | ||
handleGreedyStringWordFunctions(argument, argumentBuilder) | ||
brigadierCommand.then(argumentBuilder) | ||
} | ||
|
||
private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder<CommandSourceStack, *>) { | ||
argumentBuilder.executes { context -> | ||
val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) | ||
|
||
for (i in greedyContext.arguments.indices) { | ||
val word = argument.words[i] ?: continue | ||
for (runnable in word.runnables) runnable(greedyContext) | ||
if (i == greedyContext.arguments.lastIndex) | ||
for (execution in word.executions) execution(greedyContext) | ||
} | ||
Command.SINGLE_SUCCESS | ||
} | ||
|
||
argumentBuilder.suggests { context, builder -> | ||
val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) | ||
var prevChar = ' ' | ||
val input = ArgumentHelper.getArgumentInput(context, argument.name) ?: "" | ||
val amountOfSpaces: Int = if (input.isEmpty()) 0 else input.count { | ||
if (prevChar == ' ' && it == ' ') return@count false | ||
prevChar = it | ||
it == ' ' | ||
} | ||
val newBuilder = builder.createOffset(builder.input.lastIndexOf(' ') + 1) | ||
val word = argument.words[amountOfSpaces] ?: return@suggests newBuilder.buildFuture() | ||
for (stellarSuggestion in word.suggestions) | ||
for (suggestion in stellarSuggestion.get(greedyContext)) | ||
newBuilder.suggest(suggestion.text) { suggestion.tooltip } | ||
newBuilder.buildFuture() | ||
} | ||
} | ||
|
||
private fun handleRequiredArgument(argument: AbstractStellarArgument<*>, brigadierCommand: ArgumentBuilder<CommandSourceStack, *>) { | ||
val argumentBuilder = ArgumentHelper.getRequiredArgumentBuilder(argument) | ||
handleCommandFunctions(argument, argumentBuilder) | ||
handleArguments(argument, argumentBuilder) | ||
brigadierCommand.then(argumentBuilder) | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.undefined.stellar.v1_19_2 | ||
|
||
import com.mojang.brigadier.context.CommandContext | ||
import com.undefined.stellar.AbstractStellarCommand | ||
import com.undefined.stellar.StellarCommands | ||
import com.undefined.stellar.argument.AbstractStellarArgument | ||
import com.undefined.stellar.argument.LiteralStellarArgument | ||
import com.undefined.stellar.argument.types.custom.CustomArgument | ||
import com.undefined.stellar.data.argument.CommandNode | ||
import com.undefined.stellar.data.argument.PhraseCommandContext | ||
import com.undefined.stellar.exception.DuplicateArgumentNameException | ||
import com.undefined.stellar.exception.LiteralArgumentMismatchException | ||
import io.papermc.paper.adventure.PaperAdventure | ||
import net.kyori.adventure.identity.Identity | ||
import net.minecraft.commands.CommandSource | ||
import net.minecraft.commands.CommandSourceStack | ||
import net.minecraft.network.chat.Component | ||
import net.minecraft.server.MinecraftServer | ||
import net.minecraft.world.phys.Vec2 | ||
import net.minecraft.world.phys.Vec3 | ||
import org.bukkit.command.CommandSender | ||
|
||
object CommandContextAdapter { | ||
|
||
fun getStellarCommandContext(context: CommandContext<CommandSourceStack>): com.undefined.stellar.data.argument.CommandContext<CommandSender> { | ||
val input = context.input.removePrefix("/") | ||
val baseCommand: AbstractStellarCommand<*> = StellarCommands.getStellarCommand(context.nodes[0].node.name)!! | ||
val arguments = BrigadierCommandHelper.getArguments(baseCommand, context) | ||
if (arguments.filter { it !is LiteralStellarArgument }.groupingBy { it.name }.eachCount().any { it.value > 1 }) throw DuplicateArgumentNameException() | ||
val parsedArguments: CommandNode = | ||
BrigadierCommandHelper.getArguments(baseCommand, context) | ||
.associate<AbstractStellarArgument<*>, String, (com.undefined.stellar.data.argument.CommandContext<CommandSender>) -> Any?> { argument -> | ||
if (argument is CustomArgument) return@associate Pair(argument.name) { argument.parse(it) } | ||
if (argument is LiteralStellarArgument) return@associate Pair(argument.name) { throw LiteralArgumentMismatchException() } | ||
Pair(argument.name) { | ||
ArgumentHelper.getParsedArgument(context, argument) | ||
} | ||
} as CommandNode | ||
return com.undefined.stellar.data.argument.CommandContext( | ||
parsedArguments, | ||
context.source.bukkitSender, | ||
input | ||
) | ||
} | ||
|
||
fun getGreedyCommandContext(context: CommandContext<CommandSourceStack>): PhraseCommandContext<CommandSender> { | ||
val input = context.input.removePrefix("/") | ||
val words = input.split(' ').toMutableList() | ||
|
||
val totalOtherArguments = context.nodes.size - 1 | ||
for (i in (1..totalOtherArguments)) words.removeFirst() | ||
return PhraseCommandContext( | ||
words, | ||
context.source.bukkitSender, | ||
input | ||
) | ||
} | ||
|
||
fun getCommandSourceStack(sender: CommandSender): CommandSourceStack { | ||
val overworld = MinecraftServer.getServer().overworld() | ||
return CommandSourceStack( | ||
Source(sender), | ||
Vec3.atLowerCornerOf(overworld.getSharedSpawnPos()), | ||
Vec2.ZERO, | ||
overworld, | ||
4, | ||
sender.name, | ||
Component.literal(sender.name), | ||
MinecraftServer.getServer(), | ||
null | ||
) | ||
} | ||
|
||
@JvmRecord | ||
@Suppress("DEPRECATION") | ||
private data class Source(val sender: CommandSender) : CommandSource { | ||
override fun sendSystemMessage(message: Component) { | ||
sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) | ||
} | ||
|
||
override fun acceptsSuccess(): Boolean { | ||
return true | ||
} | ||
|
||
override fun acceptsFailure(): Boolean { | ||
return true | ||
} | ||
|
||
override fun shouldInformAdmins(): Boolean { | ||
return false | ||
} | ||
|
||
override fun getBukkitSender(stack: CommandSourceStack): CommandSender { | ||
return this.sender | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.