-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandFeedbackHelper.java
69 lines (53 loc) · 2.44 KB
/
CommandFeedbackHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.auioc.mcmod.arnicalib.utils.game;
import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.EmptyText;
import static org.auioc.mcmod.arnicalib.utils.game.TextUtils.I18nText;
import java.util.function.Function;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.MutableComponent;
public class CommandFeedbackHelper {
private final MutableComponent prefix;
private final Function<String, String> i18n;
public CommandFeedbackHelper(MutableComponent prefix, Function<String, String> i18n) {
this.prefix = prefix;
this.i18n = i18n;
}
public CommandFeedbackHelper(Function<String, String> i18n) {
this(EmptyText(), i18n);
}
public MutableComponent createMessage(String key) {
return EmptyText().append(this.prefix).append(I18nText(this.i18n.apply(key)));
}
public MutableComponent createMessage(String key, Object... args) {
return EmptyText().append(this.prefix).append(I18nText(this.i18n.apply(key), args));
}
public MutableComponent successMessage(String key) {
return this.createMessage("command." + key + ".success");
}
public MutableComponent successMessage(String key, Object... args) {
return this.createMessage("command." + key + ".success", args);
}
public MutableComponent failureMessage(String key) {
return this.createMessage("command." + key + ".failure");
}
public MutableComponent failureMessage(String key, Object... args) {
return this.createMessage("command." + key + ".failure", args);
}
public int success(CommandContext<CommandSourceStack> ctx, String key) {
ctx.getSource().sendSuccess(this.successMessage(key), false);
return Command.SINGLE_SUCCESS;
}
public int success(CommandContext<CommandSourceStack> ctx, String key, Object... args) {
ctx.getSource().sendSuccess(this.successMessage(key, args), false);
return Command.SINGLE_SUCCESS;
}
public int failure(CommandContext<CommandSourceStack> ctx, String key) {
ctx.getSource().sendFailure(this.failureMessage(key));
return Command.SINGLE_SUCCESS;
}
public int failure(CommandContext<CommandSourceStack> ctx, String key, Object... args) {
ctx.getSource().sendFailure(this.failureMessage(key, args));
return Command.SINGLE_SUCCESS;
}
}