Skip to content

Commit

Permalink
some code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
FDPUser443 committed Jan 19, 2024
1 parent 530d09b commit 8724907
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,39 @@ package net.ccbluex.liquidbounce.features.command.commands.client
import net.ccbluex.liquidbounce.features.command.Command
import net.ccbluex.liquidbounce.features.command.CommandException
import net.ccbluex.liquidbounce.features.command.builder.CommandBuilder
import net.ccbluex.liquidbounce.features.command.builder.blockParameter
import net.ccbluex.liquidbounce.features.command.builder.ParameterBuilder
import net.ccbluex.liquidbounce.utils.client.chat
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.liquidbounce.utils.client.regular
import net.ccbluex.liquidbounce.utils.client.variable
import net.minecraft.client.MinecraftClient
import net.minecraft.client.resource.language.I18n.translate
import java.text.DecimalFormat

object CommandVClip {

private val decimalFormat = DecimalFormat("##0.000")

fun createCommand(): Command {
return CommandBuilder
.begin("vclip")
.parameter(
blockParameter("distance")
ParameterBuilder
.begin<Float>("distance")
.required()
.build()
)
.handler { command, args ->
val y = (args[0] as String).toDoubleOrNull()
val player = mc.player
val player = mc.player ?: throw CommandException(command.result("notInGame"))

if (y == null) {
chat(regular(translate("liquidbounce.command.vclip.error.invalidDistance")))
return@handler
throw CommandException(command.result("invalidDistance"))
}

if (player != null) {
player.updatePosition(player.x, player.y + y, player.z)
chat(
regular(
command.result(
translate("liquidbounce.command.vclip.result.positionUpdated"),
variable(player.x.toString()),
variable(player.y.toString()),
variable(player.z.toString())
)
)
)
} else {
throw CommandException(command.result(translate("liquidbounce.command.vclip.error.notInGame")))
}
player.updatePosition(player.x, player.y + y, player.z)
chat(regular(command.result("positionUpdated",
variable(decimalFormat.format(player.x)),
variable(decimalFormat.format(player.y)),
variable(decimalFormat.format(player.z)))))
}
.build()
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
"liquidbounce.command.value.result.valueError": "Unable to change value %s because of an error: '%s'!",
"liquidbounce.command.ping.description": "Checks your ping.",
"liquidbounce.command.ping.result.pingCheck": "Your ping is %sms.",
"liquidbounce.command.vclip.error.invalidDistance": "Invalid distance. Please enter a valid number.",
"liquidbounce.command.vclip.error.notInGame": "You are not in a game.",
"liquidbounce.command.vclip.result.invalidDistance": "Invalid distance. Please enter a valid number.",
"liquidbounce.command.vclip.result.notInGame": "You are not in a game.",
"liquidbounce.command.vclip.result.positionUpdated": "Your position has been updated to X: %s, Y: %s, Z: %s",
"liquidbounce.command.remoteview.description": "Allows you to view the perspective of another player.",
"liquidbounce.command.remoteview.subcommand.view.result.viewPlayer": "You are now viewing the perspective of %s.",
Expand Down

0 comments on commit 8724907

Please sign in to comment.