Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 143
src/main/java/com/kodari/starunban/StarUnban.java
package com.kodari.starunban;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.Items;
public class StarUnban implements ModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, buildContext, selection) ->
dispatcher.register(Commands.literal("unban")
.then(Commands.argument("player", StringArgumentType.word())
.executes(context -> {
CommandSourceStack source = context.getSource();
ServerPlayer player = source.getPlayerOrException();
Inventory inventory = player.getInventory();
for (int slot = 0; slot < inventory.getContainerSize(); slot++) {
if (inventory.getItem(slot).getItem() == Items.NETHER_STAR) {
inventory.removeItem(slot, 1);
String target = StringArgumentType.getString(context, "player");
source.getServer().getCommands().performPrefixedCommand(
source.getServer().createCommandSourceStack(),
"deathban pardon " + target
);
source.sendSuccess(() -> Component.translatable("message.starunban.success", target), false);
return 1;
}
}
source.sendFailure(Component.translatable("message.starunban.missing_star"));
return 0;
}))));
}
}