-
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.
Merge pull request #7 from timinc-cobble/tmetcalfe89/findsparkle-cmd
added findsparkle command
- Loading branch information
Showing
8 changed files
with
101 additions
and
5 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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/us/timinc/mc/cobblemon/shinysparkles/commands/CommandExecutor.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,8 @@ | ||
package us.timinc.mc.cobblemon.shinysparkles.commands | ||
|
||
import com.mojang.brigadier.CommandDispatcher | ||
import net.minecraft.server.command.ServerCommandSource | ||
|
||
abstract class CommandExecutor { | ||
abstract fun register(dispatcher: CommandDispatcher<ServerCommandSource>) | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/us/timinc/mc/cobblemon/shinysparkles/commands/Commands.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,16 @@ | ||
package us.timinc.mc.cobblemon.shinysparkles.commands | ||
|
||
import com.mojang.brigadier.CommandDispatcher | ||
import net.minecraft.command.CommandRegistryAccess | ||
import net.minecraft.server.command.CommandManager | ||
import net.minecraft.server.command.ServerCommandSource | ||
|
||
object Commands { | ||
fun register( | ||
dispatcher: CommandDispatcher<ServerCommandSource>, | ||
registry: CommandRegistryAccess, | ||
registrationEnvironment: CommandManager.RegistrationEnvironment | ||
) { | ||
FindSparkle.register(dispatcher) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/us/timinc/mc/cobblemon/shinysparkles/commands/FindSparkle.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,25 @@ | ||
package us.timinc.mc.cobblemon.shinysparkles.commands | ||
|
||
import com.mojang.brigadier.context.CommandContext | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.server.command.ServerCommandSource | ||
import net.minecraft.text.Text | ||
import us.timinc.mc.cobblemon.shinysparkles.ShinySparkles | ||
import us.timinc.mc.cobblemon.shinysparkles.store.player.SparklesData | ||
|
||
object FindSparkle : PlayerCommandExecutor(listOf("findsparkle")) { | ||
override fun check(ctx: CommandContext<ServerCommandSource>, player: PlayerEntity): Int { | ||
if (!ShinySparkles.config.enableFindCommand) { | ||
player.sendMessage(Text.translatable("shinysparkles.msg.commanddisabled"), true) | ||
return 0 | ||
} | ||
|
||
val prevSparklesData = SparklesData.getFromPlayer(player) | ||
val pos = prevSparklesData.pos ?: run { | ||
player.sendMessage(Text.translatable("shinysparkles.msg.nosparkleforyou"), true) | ||
return 0 | ||
} | ||
player.sendMessage(Text.literal("${pos.x}, ${pos.y}, ${pos.z}"), true) | ||
return 1 | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/us/timinc/mc/cobblemon/shinysparkles/commands/PlayerCommandExecutor.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,43 @@ | ||
package us.timinc.mc.cobblemon.shinysparkles.commands | ||
|
||
import com.mojang.brigadier.CommandDispatcher | ||
import com.mojang.brigadier.context.CommandContext | ||
import net.minecraft.command.argument.EntityArgumentType | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.server.command.CommandManager.argument | ||
import net.minecraft.server.command.CommandManager.literal | ||
import net.minecraft.server.command.ServerCommandSource | ||
import us.timinc.mc.cobblemon.shinysparkles.ShinySparkles.MOD_ID | ||
|
||
abstract class PlayerCommandExecutor(private val path: List<String>) : CommandExecutor() { | ||
override fun register(dispatcher: CommandDispatcher<ServerCommandSource>) { | ||
val reversedPath = path.reversed() | ||
var lastLink = literal(reversedPath.first()) | ||
.then(argument("player", EntityArgumentType.player()).executes(::withPlayer)) | ||
.executes(::withoutPlayer) | ||
|
||
for (name in reversedPath.drop(1)) { | ||
val nextLink = literal(name) | ||
nextLink.then(lastLink) | ||
lastLink = nextLink | ||
} | ||
|
||
dispatcher.register(literal(MOD_ID).then(lastLink)) | ||
} | ||
|
||
fun withPlayer(ctx: CommandContext<ServerCommandSource>): Int { | ||
return check( | ||
ctx, EntityArgumentType.getPlayer(ctx, "player") | ||
) | ||
} | ||
|
||
fun withoutPlayer(ctx: CommandContext<ServerCommandSource>): Int { | ||
return ctx.source.player?.let { player -> | ||
check( | ||
ctx, player | ||
) | ||
} ?: 0 | ||
} | ||
|
||
abstract fun check(ctx: CommandContext<ServerCommandSource>, player: PlayerEntity): Int | ||
} |
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,4 +1,6 @@ | ||
{ | ||
"shinysparkles.block.sparkle.msg.notyours": "The sparkle calls out for %d.", | ||
"shinysparkles.msg.emptyperson": "someone else" | ||
"shinysparkles.msg.emptyperson": "someone else", | ||
"shinysparkles.msg.commanddisabled": "This command is disabled.", | ||
"shinysparkles.msg.nosparkleforyou": "You do not currently have a shiny sparkle." | ||
} |