Move the admin and debug commands to a /unicopia command

This commit is contained in:
Sollace 2023-09-04 23:40:41 +01:00
parent 30f5c73609
commit c63bebdce1
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
11 changed files with 115 additions and 145 deletions

View file

@ -8,9 +8,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.PlaceableSpell;
import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -26,9 +26,8 @@ import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public class CastCommand { public class CastCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registries) { public static LiteralArgumentBuilder<ServerCommandSource> create(CommandRegistryAccess registries) {
dispatcher.register( return CommandManager.literal("cast").requires(s -> s.hasPermissionLevel(2))
CommandManager.literal("cast").requires(s -> s.hasPermissionLevel(2))
.then( .then(
buildBranches( buildBranches(
CommandManager.argument("spell", RegistryKeyArgumentType.registryKey(SpellType.REGISTRY_KEY)), CommandManager.argument("spell", RegistryKeyArgumentType.registryKey(SpellType.REGISTRY_KEY)),
@ -41,7 +40,6 @@ public class CastCommand {
CommandManager.argument("traits", TraitsArgumentType.traits()), CommandManager.argument("traits", TraitsArgumentType.traits()),
CastCommand::getTraits CastCommand::getTraits
)) ))
)
); );
} }

View file

@ -6,35 +6,21 @@ import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.command.ManaCommand.ManaType; import com.minelittlepony.unicopia.command.ManaCommand.ManaType;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry; import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.argument.serialize.ConstantArgumentSerializer; import net.minecraft.command.argument.serialize.ConstantArgumentSerializer;
import net.minecraft.server.MinecraftServer;
public class Commands { public class Commands {
@SuppressWarnings("deprecation")
public static void bootstrap() { public static void bootstrap() {
ArgumentTypeRegistry.registerArgumentType(Unicopia.id("animation"), Animation.ArgumentType.class, ConstantArgumentSerializer.of(Animation::argument)); ArgumentTypeRegistry.registerArgumentType(Unicopia.id("animation"), Animation.ArgumentType.class, ConstantArgumentSerializer.of(Animation::argument));
ArgumentTypeRegistry.registerArgumentType(Unicopia.id("animation_recipient"), Animation.Recipient.ArgumentType.class, ConstantArgumentSerializer.of(Animation.Recipient::argument)); ArgumentTypeRegistry.registerArgumentType(Unicopia.id("animation_recipient"), Animation.Recipient.ArgumentType.class, ConstantArgumentSerializer.of(Animation.Recipient::argument));
ArgumentTypeRegistry.registerArgumentType(Unicopia.id("mana_type"), ManaType.ArgumentType.class, ConstantArgumentSerializer.of(ManaType::argument)); ArgumentTypeRegistry.registerArgumentType(Unicopia.id("mana_type"), ManaType.ArgumentType.class, ConstantArgumentSerializer.of(ManaType::argument));
ArgumentTypeRegistry.registerArgumentType(Unicopia.id("trait_type"), Trait.ArgumentType.class, ConstantArgumentSerializer.of(Trait::argument)); ArgumentTypeRegistry.registerArgumentType(Unicopia.id("trait_type"), Trait.ArgumentType.class, ConstantArgumentSerializer.of(Trait::argument));
ArgumentTypeRegistry.registerArgumentType(Unicopia.id("spell_traits"), TraitsArgumentType.class, ConstantArgumentSerializer.of(TraitsArgumentType::traits)); ArgumentTypeRegistry.registerArgumentType(Unicopia.id("spell_traits"), TraitsArgumentType.class, ConstantArgumentSerializer.of(TraitsArgumentType::traits));
CommandRegistrationCallback.EVENT.register((dispatcher, registries, environment) -> { CommandRegistrationCallback.EVENT.register((dispatcher, registries, environment) -> {
RacelistCommand.register(dispatcher); dispatcher.register(EmoteCommand.create());
EmoteCommand.register(dispatcher); dispatcher.register(SpeciesCommand.create(environment));
SpeciesCommand.register(dispatcher, environment); dispatcher.register(UnicopiaCommand.create(registries, environment));
WorldTribeCommand.register(dispatcher);
GravityCommand.register(dispatcher);
DisguiseCommand.register(dispatcher, registries);
CastCommand.register(dispatcher, registries);
TraitCommand.register(dispatcher);
ManaCommand.register(dispatcher);
if (FabricLoader.getInstance().getGameInstance() instanceof MinecraftServer server) {
server.setFlightEnabled(true);
}
}); });
} }
} }

View file

@ -9,9 +9,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
@ -34,10 +34,8 @@ import net.minecraft.world.GameRules;
public class DisguiseCommand { public class DisguiseCommand {
private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.disguise.notfound")); private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.disguise.notfound"));
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registries) { public static LiteralArgumentBuilder<ServerCommandSource> create(CommandRegistryAccess registries) {
dispatcher.register(CommandManager return CommandManager.literal("disguise").requires(s -> s.hasPermissionLevel(2))
.literal("disguise")
.requires(s -> s.hasPermissionLevel(2))
.executes(context -> reveal(context.getSource(), context.getSource().getPlayer())) .executes(context -> reveal(context.getSource(), context.getSource().getPlayer()))
.then( .then(
CommandManager.argument("target", EntityArgumentType.players()) CommandManager.argument("target", EntityArgumentType.players())
@ -45,8 +43,7 @@ public class DisguiseCommand {
.then(buildPlayerDisguise(context -> EntityArgumentType.getPlayer(context, "target"))) .then(buildPlayerDisguise(context -> EntityArgumentType.getPlayer(context, "target")))
) )
.then(buildEntityDisguise(context -> context.getSource().getPlayer(), registries)) .then(buildEntityDisguise(context -> context.getSource().getPlayer(), registries))
.then(buildPlayerDisguise(context -> context.getSource().getPlayer())) .then(buildPlayerDisguise(context -> context.getSource().getPlayer()));
);
} }
private static ArgumentBuilder<ServerCommandSource, ?> buildEntityDisguise(Arg<ServerPlayerEntity> targetOp, CommandRegistryAccess registries) { private static ArgumentBuilder<ServerCommandSource, ?> buildEntityDisguise(Arg<ServerPlayerEntity> targetOp, CommandRegistryAccess registries) {

View file

@ -2,16 +2,16 @@ package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
public class EmoteCommand { public class EmoteCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
dispatcher.register(CommandManager return CommandManager
.literal("emote") .literal("emote")
.then(CommandManager.argument("animation", Animation.argument()).executes(source -> apply( .then(CommandManager.argument("animation", Animation.argument()).executes(source -> apply(
source.getSource(), source.getSource(),
@ -31,7 +31,7 @@ public class EmoteCommand {
IntegerArgumentType.getInteger(source, "duration") IntegerArgumentType.getInteger(source, "duration")
) )
)) ))
))); ));
} }
static int apply(ServerCommandSource source, Animation animation, Animation.Recipient recipient) throws CommandSyntaxException { static int apply(ServerCommandSource source, Animation animation, Animation.Recipient recipient) throws CommandSyntaxException {

View file

@ -5,7 +5,6 @@ import java.util.stream.Stream;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -19,24 +18,19 @@ import net.minecraft.world.GameRules;
class GravityCommand { class GravityCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager return CommandManager.literal("gravity").requires(s -> s.hasPermissionLevel(2))
.literal("gravity") .then(CommandManager.literal("get")
.requires(s -> s.hasPermissionLevel(2));
builder.then(CommandManager.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.literal("set") .then(CommandManager.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())
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), FloatArgumentType.getFloat(context, "gravity"), false)) .executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), FloatArgumentType.getFloat(context, "gravity"), false))
))); )));
dispatcher.register(builder);
} }
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) throws CommandSyntaxException { static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) throws CommandSyntaxException {

View file

@ -4,8 +4,8 @@ import java.util.function.Function;
import com.minelittlepony.unicopia.entity.player.MagicReserves; import com.minelittlepony.unicopia.entity.player.MagicReserves;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType; import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.argument.EnumArgumentType; import net.minecraft.command.argument.EnumArgumentType;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
@ -14,9 +14,8 @@ import net.minecraft.text.Text;
import net.minecraft.util.StringIdentifiable; import net.minecraft.util.StringIdentifiable;
public class ManaCommand { public class ManaCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
dispatcher.register(CommandManager return CommandManager.literal("mana").requires(s -> s.hasPermissionLevel(2))
.literal("mana").requires(s -> s.hasPermissionLevel(2))
.then(CommandManager.argument("type", ManaType.argument()).executes(source -> { .then(CommandManager.argument("type", ManaType.argument()).executes(source -> {
var type = source.getArgument("type", ManaType.class); var type = source.getArgument("type", ManaType.class);
var pony = Pony.of(source.getSource().getPlayer()); var pony = Pony.of(source.getSource().getPlayer());
@ -35,13 +34,10 @@ public class ManaCommand {
pony.getLevel().add(1); pony.getLevel().add(1);
value -= 1; value -= 1;
} }
bar.set(value); bar.set(value);
source.getSource().getPlayer().sendMessage(Text.literal("Set " + type.name() + " to " + bar.get() + "/" + bar.getMax())); source.getSource().getPlayer().sendMessage(Text.literal("Set " + type.name() + " to " + bar.get() + "/" + bar.getMax()));
return 0; return 0;
})) })));
)
);
} }
enum ManaType implements CommandArgumentEnum<ManaType> { enum ManaType implements CommandArgumentEnum<ManaType> {

View file

@ -3,10 +3,8 @@ package com.minelittlepony.unicopia.command;
import java.util.function.Function; import java.util.function.Function;
import com.minelittlepony.unicopia.*; import com.minelittlepony.unicopia.*;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.argument.RegistryKeyArgumentType;
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.server.network.ServerPlayerEntity;
@ -15,13 +13,10 @@ import net.minecraft.util.Formatting;
class RacelistCommand { class RacelistCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("racelist").requires(s -> s.hasPermissionLevel(4)); return CommandManager.literal("racelist").requires(s -> s.hasPermissionLevel(3))
.then(CommandManager.literal("allow")
RegistryKeyArgumentType<Race> raceArgument = Race.argument(); .then(CommandManager.argument("race", Race.argument())
builder.then(CommandManager.literal("allow")
.then(CommandManager.argument("race", raceArgument)
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), "allowed", race -> { .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), "allowed", race -> {
if (race.isUnset()) { if (race.isUnset()) {
@ -34,9 +29,9 @@ class RacelistCommand {
return result; return result;
})) }))
)); ))
builder.then(CommandManager.literal("disallow") .then(CommandManager.literal("disallow")
.then(CommandManager.argument("race", raceArgument) .then(CommandManager.argument("race", Race.argument())
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), "disallowed", race -> { .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), "disallowed", race -> {
boolean result = Unicopia.getConfig().speciesWhiteList.get().remove(race.getId().toString()); boolean result = Unicopia.getConfig().speciesWhiteList.get().remove(race.getId().toString());
@ -45,8 +40,6 @@ class RacelistCommand {
return result; return result;
})) }))
)); ));
dispatcher.register(builder);
} }
static int toggle(ServerCommandSource source, ServerPlayerEntity player, Race race, String action, Function<Race, Boolean> func) { static int toggle(ServerCommandSource source, ServerPlayerEntity player, Race race, String action, Function<Race, Boolean> func) {

View file

@ -5,7 +5,6 @@ import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.network.Channel; import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.MsgTribeSelect; import com.minelittlepony.unicopia.network.MsgTribeSelect;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
@ -22,8 +21,8 @@ import net.minecraft.util.Identifier;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
class SpeciesCommand { class SpeciesCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher, RegistrationEnvironment environment) { static LiteralArgumentBuilder<ServerCommandSource> create(RegistrationEnvironment environment) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("race"); LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("tribe");
if (environment.dedicated) { if (environment.dedicated) {
if (Unicopia.getConfig().enableCheats.get()) { if (Unicopia.getConfig().enableCheats.get()) {
@ -35,29 +34,25 @@ class SpeciesCommand {
RegistryKeyArgumentType<Race> raceArgument = Race.argument(); RegistryKeyArgumentType<Race> raceArgument = Race.argument();
builder.then(CommandManager.literal("get") return builder
.then(CommandManager.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))
)); ))
.then(CommandManager.literal("set")
builder.then(CommandManager.literal("set")
.then(CommandManager.argument("race", raceArgument) .then(CommandManager.argument("race", raceArgument)
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), true)) .executes(context -> set(context.getSource(), context.getSource().getPlayer(), Race.fromArgument(context, "race"), true))
.then(CommandManager.argument("target", EntityArgumentType.player()) .then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), Race.fromArgument(context, "race"), false))) .executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), Race.fromArgument(context, "race"), false)))
)); ))
.then(CommandManager.literal("describe")
builder.then(CommandManager.literal("describe")
.then(CommandManager.argument("race", raceArgument) .then(CommandManager.argument("race", raceArgument)
.executes(context -> describe(context.getSource().getPlayer(), Race.fromArgument(context, "race"))) .executes(context -> describe(context.getSource().getPlayer(), Race.fromArgument(context, "race")))
)); ))
.then(CommandManager.literal("list")
builder.then(CommandManager.literal("list")
.executes(context -> list(context.getSource().getPlayer()) .executes(context -> list(context.getSource().getPlayer())
)); ));
dispatcher.register(builder);
} }
static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) { static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) {

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -16,12 +15,9 @@ import net.minecraft.text.*;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
class TraitCommand { class TraitCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager return CommandManager.literal("trait").requires(s -> s.hasPermissionLevel(2))
.literal("trait") .then(CommandManager.literal("add")
.requires(s -> s.hasPermissionLevel(2));
builder.then(CommandManager.literal("add")
.then(CommandManager.argument("trait", Trait.argument()) .then(CommandManager.argument("trait", Trait.argument())
.then(CommandManager.argument("value", FloatArgumentType.floatArg()).executes(source -> add( .then(CommandManager.argument("value", FloatArgumentType.floatArg()).executes(source -> add(
source.getSource(), source.getSource(),
@ -29,16 +25,14 @@ class TraitCommand {
source.getArgument("trait", Trait.class), source.getArgument("trait", Trait.class),
FloatArgumentType.getFloat(source, "value") FloatArgumentType.getFloat(source, "value")
))) )))
)); ))
builder.then(CommandManager.literal("remove") .then(CommandManager.literal("remove")
.then(CommandManager.argument("trait", Trait.argument()).executes(source -> remove( .then(CommandManager.argument("trait", Trait.argument()).executes(source -> remove(
source.getSource(), source.getSource(),
source.getSource().getPlayer(), source.getSource().getPlayer(),
source.getArgument("trait", Trait.class) source.getArgument("trait", Trait.class)
)) ))
)); ));
dispatcher.register(builder);
} }
static int add(ServerCommandSource source, PlayerEntity player, Trait trait, float amount) throws CommandSyntaxException { static int add(ServerCommandSource source, PlayerEntity player, Trait trait, float amount) throws CommandSyntaxException {

View file

@ -0,0 +1,23 @@
package com.minelittlepony.unicopia.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.CommandManager.RegistrationEnvironment;
import net.minecraft.server.command.ServerCommandSource;
class UnicopiaCommand {
public static LiteralArgumentBuilder<ServerCommandSource> create(CommandRegistryAccess registries, RegistrationEnvironment environment) {
return CommandManager.literal("unicopia")
.then(EmoteCommand.create())
.then(SpeciesCommand.create(environment))
.then(RacelistCommand.create())
.then(WorldTribeCommand.create())
.then(GravityCommand.create())
.then(DisguiseCommand.create(registries))
.then(CastCommand.create(registries))
.then(TraitCommand.create())
.then(ManaCommand.create());
}
}

View file

@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties; import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -11,17 +10,12 @@ import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
class WorldTribeCommand { class WorldTribeCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) { static LiteralArgumentBuilder<ServerCommandSource> create() {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager return CommandManager.literal("worldtribe").requires(s -> s.hasPermissionLevel(3))
.literal("worldtribe") .then(CommandManager.literal("get").executes(context -> get(context.getSource())))
.requires(s -> s.hasPermissionLevel(4)); .then(CommandManager.literal("set")
builder.then(CommandManager.literal("get").executes(context -> get(context.getSource())));
builder.then(CommandManager.literal("set")
.then(CommandManager.argument("race", Race.argument()) .then(CommandManager.argument("race", Race.argument())
.executes(context -> set(context.getSource(), Race.fromArgument(context, "race"))))); .executes(context -> set(context.getSource(), Race.fromArgument(context, "race")))));
dispatcher.register(builder);
} }
static int get(ServerCommandSource source) throws CommandSyntaxException { static int get(ServerCommandSource source) throws CommandSyntaxException {