Fixed the gravity command

This commit is contained in:
Sollace 2020-05-03 22:42:28 +02:00
parent 9e6da2f64a
commit ece5f378dc
2 changed files with 24 additions and 24 deletions

View file

@ -4,6 +4,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.EntityArgumentType; import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -14,16 +15,16 @@ import net.minecraft.text.TranslatableText;
class GravityCommand { class GravityCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("gravity").requires(s -> s.hasPermissionLevel(4)); LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager
.literal("gravity")
.requires(s -> s.hasPermissionLevel(4));
builder.then(CommandManager builder.then(CommandManager.literal("get")
.literal("get")
.executes(context -> get(context.getSource(), context.getSource().getPlayer(), true)) .executes(context -> get(context.getSource(), context.getSource().getPlayer(), true))
).then(CommandManager.argument("target", EntityArgumentType.player()) .then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false)) .executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false))
); ));
builder.then(CommandManager builder.then(CommandManager.literal("set")
.literal("set")
.then(CommandManager.argument("gravity", FloatArgumentType.floatArg(-99, 99)) .then(CommandManager.argument("gravity", FloatArgumentType.floatArg(-99, 99))
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), FloatArgumentType.getFloat(context, "gravity"), true)) .executes(context -> set(context.getSource(), context.getSource().getPlayer(), FloatArgumentType.getFloat(context, "gravity"), true))
.then(CommandManager.argument("target", EntityArgumentType.player()) .then(CommandManager.argument("target", EntityArgumentType.player())
@ -33,18 +34,17 @@ class GravityCommand {
dispatcher.register(builder); dispatcher.register(builder);
} }
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) { static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) throws CommandSyntaxException {
String translationKey = "commands.gravity.get"; String translationKey = "commands.gravity.get";
Pony iplayer = Pony.of(player); Pony iplayer = Pony.of(player);
float gravity = iplayer.getGravity().getGravitationConstant(); float gravity = iplayer.getGravity().getGravitationConstant();
if (isSelf) { if (source.getPlayer() != player) {
player.sendMessage(new TranslatableText(translationKey, gravity)); translationKey += ".other";
} }
player.sendMessage(new TranslatableText(translationKey, player.getName(), gravity));
source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true);
return 0; return 0;
} }

View file

@ -227,7 +227,7 @@
"commands.racelist.illegal": "The default race %s cannot be used with this command.", "commands.racelist.illegal": "The default race %s cannot be used with this command.",
"commands.racelist.allowed": "Added %1$s to the whitelist.", "commands.racelist.allowed": "Added %1$s to the whitelist.",
"commands.racelist.allowed.failed": "%1$s is already whitelisted.", "commands.racelist.allowed.failed": "%1$s is already whitelisted.",
"commands.race.success.other": "%1$s was added to the whitelist by %2$s.", "commands.racelist.success.other": "%1$s was added to the whitelist by %2$s.",
"commands.racelist.allowed.failed.other": "%2$s tried to whitelist %1$s but it was already whitelisted.", "commands.racelist.allowed.failed.other": "%2$s tried to whitelist %1$s but it was already whitelisted.",
"commands.racelist.disallowed": "Removed %1$s from the whitelist.", "commands.racelist.disallowed": "Removed %1$s from the whitelist.",
"commands.racelist.disallowed.failed": "%1$s is not on the whitelist.", "commands.racelist.disallowed.failed": "%1$s is not on the whitelist.",
@ -241,10 +241,10 @@
"commands.disguise.success.otherself": "%1$s changed their disguise to %2$s", "commands.disguise.success.otherself": "%1$s changed their disguise to %2$s",
"commands.gravity.usage": "/gravity <get|set> <player> <gravity>", "commands.gravity.usage": "/gravity <get|set> <player> <gravity>",
"commands.gravity.get": "Your gravity is %f", "commands.gravity.get": "Your gravity is %2$f",
"commands.gravity.get.other": "%1$s has a gravity of %f", "commands.gravity.get.other": "%1$s has a gravity of %2$f",
"commands.gravity.set": "Your gravity was set to %f", "commands.gravity.set": "Your gravity was set to %2$f",
"commands.gravity.set.other": "Set %1$s's gravity to %f", "commands.gravity.set.other": "Set %1$s's gravity to %2$f",
"unicopia.race.human": "Human", "unicopia.race.human": "Human",
"unicopia.race.human.alt": "Humans", "unicopia.race.human.alt": "Humans",