Skip to content

Commit

Permalink
feat: support {team} as a substitution in command rewards
Browse files Browse the repository at this point in the history
Also added a tooltip listing supported substitutions

FTBTeam/FTB-Mods-Issues#1270
  • Loading branch information
desht committed Jul 16, 2024
1 parent cebbc48 commit e215e5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import dev.ftb.mods.ftbquests.quest.Quest;
import dev.ftb.mods.ftbteams.api.FTBTeamsAPI;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
Expand All @@ -17,13 +18,15 @@
import java.util.Map;

public class CommandReward extends Reward {
private static final String DEFAULT_COMMAND = "/say Hi, @p!";

private String command;
private boolean elevatePerms;
private boolean silent;

public CommandReward(long id, Quest quest) {
super(id, quest);
command = "/say Hi, @p!";
command = DEFAULT_COMMAND;
}

@Override
Expand Down Expand Up @@ -69,7 +72,7 @@ public void readNetData(FriendlyByteBuf buffer) {
@Environment(EnvType.CLIENT)
public void fillConfigGroup(ConfigGroup config) {
super.fillConfigGroup(config);
config.addString("command", command, v -> command = v, "/say Hi, @team!").setNameKey("ftbquests.reward.ftbquests.command");
config.addString("command", command, v -> command = v, DEFAULT_COMMAND).setNameKey("ftbquests.reward.ftbquests.command");
config.addBool("elevate", elevatePerms, v -> elevatePerms = v, false);
config.addBool("silent", silent, v -> silent = v, false);
}
Expand All @@ -89,6 +92,10 @@ public void claim(ServerPlayer player, boolean notify) {
}

overrides.put("quest", quest);
overrides.put("team", FTBTeamsAPI.api().getManager().getTeamForPlayer(player)
.map(team -> team.getName().getString())
.orElse(player.getGameProfile().getName())
);

String cmd = command;
for (Map.Entry<String, Object> entry : overrides.entrySet()) {
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@
"ftbquests.reward.ftbquests.xp": "XP",
"ftbquests.reward.ftbquests.xp_levels": "XP Levels",
"ftbquests.reward.ftbquests.command": "Command",
"ftbquests.reward.ftbquests.command.tooltip": "Vanilla substitutions, e.g. @p, are supported\nSpecial substitutions:\n{x} / {y} / {z} - player's current X/Y/Z pos\n{quest} - ID of this quest\n{chapter} - ID of this chapter\n{team} - short name of player's team",
"ftbquests.reward.ftbquests.command.elevate": "Run with Elevated Permission",
"ftbquests.reward.ftbquests.command.elevate.tooltip": "Run the command as if the player had permission level 2",
"ftbquests.reward.ftbquests.command.silent": "Silent",
Expand Down

0 comments on commit e215e5b

Please sign in to comment.