Fix command outputs. Fixes #435

This commit is contained in:
Sollace 2024-09-16 19:58:41 +01:00
parent 8a860178f6
commit 973d788a8c
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
5 changed files with 44 additions and 39 deletions

View file

@ -23,7 +23,6 @@ import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -63,10 +62,8 @@ public class ConfigCommand {
}))) })))
) )
.then(CommandManager.literal("list").executes(source -> ConfigCommand.<Set<String>>getProperty(configName, values -> { .then(CommandManager.literal("list").executes(source -> ConfigCommand.<Set<String>>getProperty(configName, values -> {
ServerPlayerEntity player = source.getSource().getPlayerOrThrow(); source.getSource().sendFeedback(() -> Text.translatable("command.unicopia.config.list", configName, values.size()), false);
values.forEach(line -> source.getSource().sendFeedback(() -> Text.literal(line), false));
player.sendMessage(Text.translatable("command.unicopia.config.list", configName, values.size()), false);
values.forEach(line -> player.sendMessage(Text.literal(line)));
})) }))
); );
} }

View file

@ -50,17 +50,19 @@ class GravityCommand {
l.getPhysics().setBaseGravityModifier(gravity); l.getPhysics().setBaseGravityModifier(gravity);
if (l.asEntity() instanceof PlayerEntity player) { if (l.asEntity() instanceof PlayerEntity player) {
if (source.getEntity() == player) { if (source.getEntity() == player) {
player.sendMessage(Text.translatable("commands.gravity.set.self", gravity)); source.sendFeedback(() -> Text.translatable("commands.gravity.set.self", gravity), true);
} else if (source.getWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { } else {
player.sendMessage(Text.translatable("commands.gravity.set.other", l.asEntity().getDisplayName(), gravity)); if (source.getWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(Text.translatable("commands.gravity.set", gravity));
}
source.sendFeedback(() -> Text.translatable("commands.gravity.set.other", l.asEntity().getDisplayName(), gravity), true);
} }
} }
return (Entity)l.asEntity(); return (Entity)l.asEntity();
}).toList(); }).toList();
if (affected.size() == 1) { if (affected.size() > 1) {
source.sendFeedback(() -> Text.translatable("commands.gravity.set.other", affected.get(0).getDisplayName()), true);
} else {
source.sendFeedback(() -> Text.translatable("commands.gravity.set.multiple", affected.size()), true); source.sendFeedback(() -> Text.translatable("commands.gravity.set.multiple", affected.size()), true);
} }
return 0; return 0;

View file

@ -24,7 +24,7 @@ public class ManaCommand {
var pony = Pony.of(source.getSource().getPlayer()); var pony = Pony.of(source.getSource().getPlayer());
var bar = type.getBar(pony.getMagicalReserves()); var bar = type.getBar(pony.getMagicalReserves());
source.getSource().getPlayer().sendMessage(Text.literal(type.name() + " is " + bar.get() + "/" + bar.getMax())); source.getSource().sendFeedback(() -> Text.literal(type.name() + " is " + bar.get() + "/" + bar.getMax()), true);
return 0; return 0;
}) })
.then(CommandManager.argument("value", FloatArgumentType.floatArg()).executes(source -> { .then(CommandManager.argument("value", FloatArgumentType.floatArg()).executes(source -> {
@ -48,7 +48,8 @@ public class ManaCommand {
pony.asWorld().playSound(null, pony.getOrigin(), USounds.Vanilla.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1, 2); pony.asWorld().playSound(null, pony.getOrigin(), USounds.Vanilla.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1, 2);
} }
bar.set(value); bar.set(value);
source.getSource().getPlayer().sendMessage(Text.literal("Set " + type.name() + " to " + bar.get() + "/" + bar.getMax())); var t = type;
source.getSource().sendFeedback(() -> Text.literal("Set " + t.name() + " to " + bar.get() + "/" + bar.getMax()), true);
return 0; return 0;
}))); })));
} }

View file

@ -44,10 +44,10 @@ class SpeciesCommand {
)) ))
.then(CommandManager.literal("describe") .then(CommandManager.literal("describe")
.then(CommandManager.argument("race", Race.argument()).suggests(UCommandSuggestion.ALL_RACE_SUGGESTIONS) .then(CommandManager.argument("race", Race.argument()).suggests(UCommandSuggestion.ALL_RACE_SUGGESTIONS)
.executes(context -> describe(context.getSource().getPlayer(), Race.fromArgument(context, "race"))) .executes(context -> describe(context.getSource(), Race.fromArgument(context, "race")))
)) ))
.then(CommandManager.literal("list") .then(CommandManager.literal("list")
.executes(context -> list(context.getSource().getPlayer()) .executes(context -> list(context.getSource())
)); ));
} }
@ -70,57 +70,59 @@ class SpeciesCommand {
} }
source.sendFeedback(() -> Text.translatable("commands.race.success.other", player.getName(), race.getDisplayName()), true); source.sendFeedback(() -> Text.translatable("commands.race.success.other", player.getName(), race.getDisplayName()), true);
} }
} else if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { } else {
player.sendMessage(Text.translatable("commands.race.permission"), false); source.sendFeedback(() -> Text.translatable("commands.race.permission"), false);
} }
return 0; return 0;
} }
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) { static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) {
source.sendFeedback(() -> {
Race spec = Pony.of(player).getSpecies(); Race spec = Pony.of(player).getSpecies();
String name = "commands.race.tell."; String name = "commands.race.tell.";
name += isSelf ? "self" : "other"; name += isSelf ? "self" : "other";
player.sendMessage(Text.translatable(name, player.getName()) return Text.translatable(name, player.getName())
.append(Text.translatable(spec.getTranslationKey()) .append(Text.translatable(spec.getTranslationKey())
.styled(s -> s.withColor(Formatting.GOLD))), false); .styled(s -> s.withColor(Formatting.GOLD)));
}, false);
return 0; return 0;
} }
static int list(PlayerEntity player) { static int list(ServerCommandSource source) {
player.sendMessage(Text.translatable("commands.race.list"), false); source.sendFeedback(() -> Text.translatable("commands.race.list"), false);
source.sendFeedback(() -> {
MutableText message = Text.literal(""); MutableText message = Text.literal("");
boolean first = true; boolean first = true;
for (Race i : Race.REGISTRY) { for (Race i : Race.REGISTRY) {
if (i.availability().isGrantable() && !i.isUnset() && i.isPermitted(player)) { if (i.availability().isGrantable() && !i.isUnset() && i.isPermitted(source.getPlayer())) {
message.append(Text.literal((!first ? "\n" : "") + " - ")); message.append(Text.literal((!first ? "\n" : "") + " - "));
message.append(i.getDisplayName()); message.append(i.getDisplayName());
first = false; first = false;
} }
} }
player.sendMessage(message.styled(s -> s.withColor(Formatting.GOLD)), false); return message.styled(s -> s.withColor(Formatting.GOLD));
}, false);
return 0; return 0;
} }
static int describe(PlayerEntity player, Race species) { static int describe(ServerCommandSource source, Race species) {
Identifier id = Race.REGISTRY.getId(species); Identifier id = Race.REGISTRY.getId(species);
for (String category : new String[] { "goods", "bads" }) { for (String category : new String[] { "goods", "bads" }) {
player.sendMessage(Text.translatable( source.sendFeedback(() -> Text.translatable(
String.format("gui.unicopia.tribe_selection.confirm.%s.%d.%s.%s", category), String.format("gui.unicopia.tribe_selection.confirm.%s.%d.%s.%s", category),
species.getAltDisplayName() species.getAltDisplayName()
), false); ), false);
for (int i = 1; i < 5; i++) { for (int i = 1; i < 5; i++) {
String line = String.format("gui.unicopia.tribe_selection.confirm.%s.%d.%s.%s", category, i, id.getNamespace(), id.getPath()); String line = String.format("gui.unicopia.tribe_selection.confirm.%s.%d.%s.%s", category, i, id.getNamespace(), id.getPath());
player.sendMessage(Text.translatable(line).styled(s -> s.withColor(category.equals("goods") ? Formatting.YELLOW : Formatting.RED)), false); source.sendFeedback(() -> Text.translatable(line).styled(s -> s.withColor(category.equals("goods") ? Formatting.YELLOW : Formatting.RED)), false);
} }
} }

View file

@ -13,6 +13,7 @@ import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.*; import net.minecraft.text.*;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.world.GameRules;
class TraitCommand { class TraitCommand {
static LiteralArgumentBuilder<ServerCommandSource> create() { static LiteralArgumentBuilder<ServerCommandSource> create() {
@ -78,7 +79,9 @@ class TraitCommand {
float gravity = iplayer.getPhysics().getGravityModifier(); float gravity = iplayer.getPhysics().getGravityModifier();
if (source.getPlayer() == player) { if (source.getPlayer() == player) {
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(Text.translatable(translationKey, gravity), false); player.sendMessage(Text.translatable(translationKey, gravity), false);
}
} else { } else {
source.sendFeedback(() -> Text.translatable(translationKey + ".other", player.getName(), gravity), true); source.sendFeedback(() -> Text.translatable(translationKey + ".other", player.getName(), gravity), true);
} }