Skip to content

Commit a7fbb8e

Browse files
committed
command feedback
1 parent 2e19341 commit a7fbb8e

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/main/java/symbolics/division/meret/MeretCommands.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,58 @@
55
import com.mojang.brigadier.arguments.IntegerArgumentType;
66
import dev.doublekekse.area_lib.Area;
77
import dev.doublekekse.area_lib.command.argument.AreaArgument;
8+
import net.minecraft.ChatFormatting;
89
import net.minecraft.commands.CommandBuildContext;
910
import net.minecraft.commands.CommandSourceStack;
1011
import net.minecraft.commands.Commands;
1112
import net.minecraft.commands.arguments.ResourceLocationArgument;
1213
import net.minecraft.commands.synchronization.SuggestionProviders;
1314
import net.minecraft.core.Holder;
15+
import net.minecraft.network.chat.Component;
16+
import net.minecraft.network.chat.MutableComponent;
1417
import net.minecraft.resources.ResourceLocation;
1518
import net.minecraft.server.MinecraftServer;
1619
import net.minecraft.sounds.Music;
1720
import net.minecraft.sounds.SoundEvent;
1821

22+
import java.util.function.Consumer;
23+
1924
import static net.minecraft.commands.Commands.argument;
2025
import static net.minecraft.commands.Commands.literal;
2126

2227
public class MeretCommands {
23-
private static int setMusic(MinecraftServer server, Area area, ResourceLocation sound, int minDelay, int maxDelay, boolean replaceCurrentMusic) {
28+
private static MutableComponent feedback(ChatFormatting bodyFormatting, Component... siblings) {
29+
MutableComponent prefix = Component.literal("").append(Component.literal("[Meret] ").withStyle(ChatFormatting.DARK_RED));
30+
for (Component sibling : siblings) {
31+
prefix = prefix.append(sibling.getStyle().getColor() == null ? sibling.copy().withStyle(bodyFormatting) : sibling);
32+
}
33+
return prefix;
34+
}
35+
36+
private static int setMusic(Consumer<Component> feedback, MinecraftServer server, Area area, ResourceLocation sound, int minDelay, int maxDelay, boolean replaceCurrentMusic) {
2437
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent((sound));
2538
Music music = new Music(Holder.direct(soundEvent), minDelay, maxDelay, replaceCurrentMusic);
2639
area.put(server, Meret.AREA_MUSIC_DATA_COMPONENT, new AreaMusicComponent(music));
40+
feedback.accept(feedback(ChatFormatting.GREEN,
41+
Component.literal("music override for "),
42+
Component.literal(area.getId().toString()).withStyle(ChatFormatting.WHITE),
43+
Component.literal(" set to "),
44+
Component.literal(sound.toString()).withStyle(ChatFormatting.WHITE)
45+
));
2746
return 1;
2847
}
2948

30-
private static int clearMusic(MinecraftServer server, Area area) {
31-
area.remove(server, Meret.AREA_MUSIC_DATA_COMPONENT);
49+
private static int clearMusic(Consumer<Component> feedback, MinecraftServer server, Area area) {
50+
if (!area.has(Meret.AREA_MUSIC_DATA_COMPONENT)) {
51+
feedback.accept(feedback(ChatFormatting.YELLOW,
52+
Component.literal("no music was set in "),
53+
Component.literal(area.getId().toString()).withStyle(ChatFormatting.WHITE)
54+
));
55+
}
56+
feedback.accept(feedback(ChatFormatting.GREEN,
57+
Component.literal("music override cleared for "),
58+
Component.literal(area.getId().toString()).withStyle(ChatFormatting.WHITE)
59+
));
3260
return 1;
3361
}
3462

@@ -43,6 +71,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
4371
.then(argument("maxDelay", IntegerArgumentType.integer(0))
4472
.then(argument("replaceCurrent", BoolArgumentType.bool())
4573
.executes(c -> setMusic(
74+
c.getSource()::sendSystemMessage,
4675
c.getSource().getServer(),
4776
AreaArgument.getArea(c, "area"),
4877
ResourceLocationArgument.getId(c, "sound"),
@@ -59,6 +88,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
5988
.then(literal("clear")
6089
.then(argument("area", AreaArgument.area())
6190
.executes(c -> clearMusic(
91+
c.getSource()::sendSystemMessage,
6292
c.getSource().getServer(),
6393
AreaArgument.getArea(c, "area")
6494
))

0 commit comments

Comments
 (0)