Skip to content

Commit 242bc7d

Browse files
committed
Add simple repair command
1 parent de1a752 commit 242bc7d

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
- Simple `/repair` command
11+
912
## [1.4.4] - 2025-05-23
1013
### Changed
1114
- Use stonecutter to support 1.21.1, 1.21.4 and 1.21.5

src/main/java/me/drex/essentials/command/CommandManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class CommandManager {
7070
new HealCommand(),
7171
new GlowCommand(),
7272
new PingCommand(),
73+
new RepairCommand(),
7374
new SignEditCommand(),
7475
new ModsCommand(),
7576
new FlyCommand(),
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package me.drex.essentials.command.impl.misc;
2+
3+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
4+
import eu.pb4.placeholders.api.PlaceholderContext;
5+
import me.drex.essentials.command.Command;
6+
import me.drex.essentials.command.CommandProperties;
7+
import net.minecraft.commands.CommandBuildContext;
8+
import net.minecraft.commands.CommandSourceStack;
9+
import net.minecraft.commands.Commands;
10+
import net.minecraft.server.level.ServerPlayer;
11+
import net.minecraft.world.item.ItemStack;
12+
13+
import static me.drex.message.api.LocalizedMessage.localized;
14+
import static net.minecraft.commands.Commands.argument;
15+
import static net.minecraft.commands.arguments.EntityArgument.getPlayer;
16+
import static net.minecraft.commands.arguments.EntityArgument.player;
17+
18+
public class RepairCommand extends Command {
19+
20+
public RepairCommand() {
21+
super(CommandProperties.create("repair", 2));
22+
}
23+
24+
@Override
25+
protected void registerArguments(LiteralArgumentBuilder<CommandSourceStack> literal, CommandBuildContext commandBuildContext) {
26+
literal.then(
27+
Commands.literal("all")
28+
.requires(require("all"))
29+
.executes(ctx -> {
30+
CommandSourceStack src = ctx.getSource();
31+
ServerPlayer player = src.getPlayerOrException();
32+
for (ItemStack itemStack : player.getInventory()) {
33+
if (itemStack.isDamaged()) {
34+
itemStack.setDamageValue(0);
35+
}
36+
}
37+
src.sendSuccess(() -> localized("fabric-essentials.commands.repair.all"), false);
38+
return SUCCESS;
39+
})
40+
)
41+
.executes(ctx -> {
42+
CommandSourceStack src = ctx.getSource();
43+
ServerPlayer player = src.getPlayerOrException();
44+
ItemStack itemStack = player.getMainHandItem();
45+
if (itemStack.isEmpty() || !itemStack.isDamaged()) {
46+
src.sendFailure(localized("fabric-essentials.commands.repair.missing"));
47+
return FAILURE;
48+
}
49+
itemStack.setDamageValue(0);
50+
src.sendSuccess(() -> localized("fabric-essentials.commands.repair"), false);
51+
return SUCCESS;
52+
});
53+
}
54+
}

src/main/resources/messages/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
"fabric-essentials.commands.ping.self": "<yellow>Pong! Your connection latency to the server is %player:ping_colored%<yellow>ms!",
8787
"fabric-essentials.commands.ping.other": "<yellow>Pong! %player:displayname%'s connection latency to the server is %player:ping_colored%<yellow>ms!",
8888

89+
"fabric-essentials.commands.repair": "<yellow>Successfully repaired the item in your hand.",
90+
"fabric-essentials.commands.repair.all": "<yellow>Successfully repaired all items in your inventory.",
91+
"fabric-essentials.commands.repair.missing": "<red>You need to hold a broken item to use this command!",
92+
8993
"fabric-essentials.commands.sethome.self": "<yellow>Set the home <gold>${home_name}<yellow>!",
9094
"fabric-essentials.commands.sethome.other": "<yellow>Set the home <gold>${home_name} <yellow>for <gold>%player:displayname%<yellow>!",
9195
"fabric-essentials.commands.sethome.limit": "<red>Home limited reached! You can't set any more homes!",

0 commit comments

Comments
 (0)