2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.command;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-01-27 11:05:22 +01:00
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
|
|
import com.mojang.brigadier.arguments.FloatArgumentType;
|
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
2020-05-03 22:42:28 +02:00
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
import net.minecraft.command.arguments.EntityArgumentType;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
|
|
|
import net.minecraft.text.TranslatableText;
|
|
|
|
|
|
|
|
class GravityCommand {
|
|
|
|
|
|
|
|
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
2020-05-03 22:42:28 +02:00
|
|
|
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager
|
|
|
|
.literal("gravity")
|
|
|
|
.requires(s -> s.hasPermissionLevel(4));
|
|
|
|
|
|
|
|
builder.then(CommandManager.literal("get")
|
|
|
|
.executes(context -> get(context.getSource(), context.getSource().getPlayer(), true))
|
|
|
|
.then(CommandManager.argument("target", EntityArgumentType.player())
|
|
|
|
.executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false))
|
|
|
|
));
|
|
|
|
builder.then(CommandManager.literal("set")
|
|
|
|
.then(CommandManager.argument("gravity", FloatArgumentType.floatArg(-99, 99))
|
|
|
|
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), FloatArgumentType.getFloat(context, "gravity"), true))
|
|
|
|
.then(CommandManager.argument("target", EntityArgumentType.player())
|
|
|
|
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), FloatArgumentType.getFloat(context, "gravity"), false))
|
|
|
|
)));
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
dispatcher.register(builder);
|
|
|
|
}
|
|
|
|
|
2020-05-03 22:42:28 +02:00
|
|
|
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) throws CommandSyntaxException {
|
2020-01-27 11:05:22 +01:00
|
|
|
String translationKey = "commands.gravity.get";
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
Pony iplayer = Pony.of(player);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
float gravity = iplayer.getPhysics().getGravityModifier();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-05-03 22:42:28 +02:00
|
|
|
if (source.getPlayer() != player) {
|
|
|
|
translationKey += ".other";
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
2020-05-03 22:42:28 +02:00
|
|
|
player.sendMessage(new TranslatableText(translationKey, player.getName(), gravity));
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set(ServerCommandSource source, PlayerEntity player, float gravity, boolean isSelf) {
|
|
|
|
String translationKey = "commands.gravity.set";
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
Pony iplayer = Pony.of(player);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-05-10 19:52:43 +02:00
|
|
|
iplayer.getPhysics().setBaseGravityModifier(gravity);
|
2020-05-10 17:18:45 +02:00
|
|
|
iplayer.setDirty();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
if (isSelf) {
|
|
|
|
player.sendMessage(new TranslatableText(translationKey, gravity));
|
|
|
|
}
|
|
|
|
|
|
|
|
source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|