2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.command;
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-09-22 15:11:20 +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.builder.LiteralArgumentBuilder;
|
|
|
|
|
2020-09-22 15:11:20 +02:00
|
|
|
import net.minecraft.command.argument.EntityArgumentType;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
|
|
|
import net.minecraft.text.LiteralText;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.text.MutableText;
|
2020-01-27 11:05:22 +01:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
import net.minecraft.text.TranslatableText;
|
|
|
|
import net.minecraft.util.Formatting;
|
|
|
|
import net.minecraft.world.GameRules;
|
|
|
|
|
|
|
|
class SpeciesCommand {
|
|
|
|
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
|
|
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("race");
|
|
|
|
|
|
|
|
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("race", new RaceArgument())
|
|
|
|
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), true))
|
|
|
|
.then(CommandManager.argument("target", EntityArgumentType.player())
|
|
|
|
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), context.getArgument("race", Race.class), false))
|
|
|
|
)));
|
|
|
|
|
|
|
|
builder.then(CommandManager.literal("describe")
|
|
|
|
.then(CommandManager.argument("race", new RaceArgument())
|
|
|
|
.executes(context -> describe(context.getSource().getPlayer(), context.getArgument("race", Race.class))
|
|
|
|
)));
|
|
|
|
|
|
|
|
builder.then(CommandManager.literal("list")
|
|
|
|
.executes(context -> list(context.getSource().getPlayer())
|
|
|
|
));
|
|
|
|
|
|
|
|
dispatcher.register(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) {
|
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
if (race.isPermitted(player)) {
|
2020-04-26 12:07:25 +02:00
|
|
|
Pony pony = Pony.of(player);
|
|
|
|
pony.setSpecies(race);
|
2020-05-10 17:18:45 +02:00
|
|
|
pony.setDirty();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
Text formattedName = new TranslatableText(race.name().toLowerCase());
|
|
|
|
|
|
|
|
if (!isSelf) {
|
|
|
|
source.sendFeedback(new TranslatableText("commands.race.success.other", player.getName(), formattedName), true);
|
|
|
|
} else {
|
|
|
|
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(new TranslatableText("commands.race.success.self"), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
source.sendFeedback(new TranslatableText("commands.race.success.otherself", player.getName(), formattedName), true);
|
|
|
|
}
|
|
|
|
} else if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(new TranslatableText("commands.race.permission"), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) {
|
2020-04-15 18:12:00 +02:00
|
|
|
Race spec = Pony.of(player).getSpecies();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
String name = "commands.race.tell.";
|
|
|
|
name += isSelf ? "self" : "other";
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(new TranslatableText(name)
|
|
|
|
.append(new TranslatableText(spec.getTranslationKey())
|
|
|
|
.styled(s -> s.withColor(Formatting.GOLD))), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int list(PlayerEntity player) {
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(new TranslatableText("commands.race.list"), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
MutableText message = new LiteralText("");
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
boolean first = true;
|
|
|
|
for (Race i : Race.values()) {
|
2020-04-15 18:12:00 +02:00
|
|
|
if (!i.isDefault() && i.isPermitted(player)) {
|
2020-01-27 11:05:22 +01:00
|
|
|
message.append(new TranslatableText((!first ? "\n" : "") + " - " + i.name().toLowerCase()));
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(message.styled(s -> s.withColor(Formatting.GOLD)), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int describe(PlayerEntity player, Race species) {
|
|
|
|
String name = species.name().toLowerCase();
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
player.sendMessage(new TranslatableText(String.format("commands.race.describe.%s.1", name)).styled(s -> s.withColor(Formatting.YELLOW)), false);
|
|
|
|
player.sendMessage(new TranslatableText(String.format("commands.race.describe.%s.2", name)), false);
|
|
|
|
player.sendMessage(new TranslatableText(String.format("commands.race.describe.%s.3", name)).styled(s -> s.withColor(Formatting.RED)), false);
|
2020-01-27 11:05:22 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|