50 lines
2.7 KiB
Java
50 lines
2.7 KiB
Java
package com.thebrokenrail.sorcerycraft.command;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
|
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
|
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;
|
|
import net.minecraft.util.Formatting;
|
|
import net.minecraft.util.Identifier;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class SpellCommand {
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
dispatcher.register(CommandManager.literal("spell")
|
|
.requires(source -> source.hasPermissionLevel(4))
|
|
.then(CommandManager.literal("list")
|
|
.then(CommandManager.argument("player", EntityArgumentType.player())
|
|
.executes(ctx -> {
|
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName()), false);
|
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
|
Map<Identifier, Integer> spells = spellPlayer.getSpells();
|
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
|
ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()).formatted(Formatting.YELLOW), false);
|
|
}
|
|
return 0;
|
|
})
|
|
)
|
|
)
|
|
.then(CommandManager.literal("clear")
|
|
.then(CommandManager.argument("player", EntityArgumentType.player())
|
|
.executes(ctx -> {
|
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
|
spellPlayer.setSpells(new HashMap<>());
|
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.cleared_spells", player.getDisplayName()), true);
|
|
return 1;
|
|
})
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|