Skip to content

Commit

Permalink
Fix #8 and add a reset command
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed May 20, 2024
1 parent 5eaef66 commit e667eee
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.minecraft.command.argument.TextArgumentType
import xyz.bluspring.nicknamer.commands.nick.*
import xyz.bluspring.nicknamer.commands.pronouns.PronounsGetCommand
import xyz.bluspring.nicknamer.commands.pronouns.PronounsRefreshCommand
import xyz.bluspring.nicknamer.commands.pronouns.PronounsResetCommand
import xyz.bluspring.nicknamer.commands.pronouns.PronounsSetCommand
import xyz.bluspring.nicknamer.commands.pronouns.color.PronounsColorComplimentCommand
import xyz.bluspring.nicknamer.commands.pronouns.color.PronounsColorGetCommand
Expand Down Expand Up @@ -168,6 +169,11 @@ class NicknamerClient : ClientModInitializer {
.literal("get")
.executes(PronounsGetCommand())
)
.then(
ClientCommandManager
.literal("reset")
.executes(PronounsResetCommand())
)
.then(
ClientCommandManager
.literal("set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PronounsRefreshCommand<T : FabricClientCommandSource> : Command<T> {
profiles.profiles[profiles.currentProfile] = PronounManager.pronouns[playerUUID]!!
}

PronounManager.save()

context.source.sendFeedback(
Text.literal("Successfully set $playerName's pronouns from PronounDB to ")
.append(PronounManager.getPronounsText(playerUUID))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package xyz.bluspring.nicknamer.commands.pronouns

import com.mojang.brigadier.Command
import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.context.CommandContext
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.minecraft.text.Text
import xyz.bluspring.nicknamer.Nicknamer
import xyz.bluspring.nicknamer.config.pronouns.PronounManager

class PronounsResetCommand<T : FabricClientCommandSource> : Command<T> {
override fun run(context: CommandContext<T>): Int {
val playerName = StringArgumentType.getString(context, "player")
val playerUUID = Nicknamer.getPlayerUUID(playerName)

if (playerUUID == null) {
context.source.sendError(Text.literal("Could not find player $playerName!"))

return 0
}

PronounManager.pronouns.remove(playerUUID)

val profiles = PronounManager.pronounProfiles[playerUUID]
profiles?.profiles?.remove(profiles.currentProfile)

PronounManager.save()

context.source.sendFeedback(
Text.literal("Successfully set $playerName's pronouns to ")
.append(PronounManager.getPronounsText(playerUUID))
)

return 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class PronounsSetCommand<T : FabricClientCommandSource> : Command<T> {
profiles.profiles[profiles.currentProfile] = PronounManager.pronouns[playerUUID]!!
}

PronounManager.save()

context.source.sendFeedback(
Text.literal("Successfully set $playerName's pronouns to ")
.append(PronounManager.getPronounsText(playerUUID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PronounsColorSetCommand<T : FabricClientCommandSource> : Command<T> {
}

PronounManager.pronounColors[pronoun] = textColor
PronounManager.save()
context.source.sendFeedback(
Text.literal("Set pronoun color to ")
.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class PronounsProfileCreateCommand<T : FabricClientCommandSource> : Command<T> {
profiles.currentProfile = profileName

PronounManager.pronounProfiles[playerUUID] = profiles

PronounManager.save()

context.source.sendFeedback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PronounsProfileDeleteCommand<T : FabricClientCommandSource> : Command<T> {
PronounManager.pronounProfiles[playerUUID]!!.profiles.remove(profileName)
context.source.sendFeedback(Text.literal("Pronouns profile $profileName successfully deleted!"))

PronounManager.save()

return 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PronounsProfileSetCommand<T : FabricClientCommandSource> : Command<T> {
profiles.currentProfile = profileName

PronounManager.pronouns[playerUUID] = profile

PronounManager.save()

context.source.sendFeedback(
Expand Down

0 comments on commit e667eee

Please sign in to comment.