Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ out/

# Vanilla-like server
server.properties
world/
survival/world/
/datapack-tests/mojang-data
/mojang-data/1.20.4
/mojang-data/1.21.1
/survival/world/
/world/

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.minestom.vanilla.commands;

import net.kyori.adventure.text.Component;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.ConsoleSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.condition.CommandCondition;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Abstract base class for Vanilla commands.
* Includes permission level handling and shared utility methods.
*/
public abstract class VanillaCommand extends Command {

public final int LEVEL_ALL = 0;
public final int LEVEL_MODERATOR = 1;
public final int LEVEL_GAMEMASTER = 2;
public final int LEVEL_ADMIN = 3;
public final int LEVEL_OWNER = 4;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a static constant


public VanillaCommand(@NotNull String name, @Nullable String... aliases) {
super(name, aliases);
}

public VanillaCommand(@NotNull String name) {
super(name);
}

/**
* Returns the usage message for this command, required and used for /help command.
*
* @param sender the command sender
* @param context the command context
* @return the usage message as a Component
*/
public abstract Component usage(CommandSender sender, CommandContext context);

protected abstract void defaultor(CommandSender sender, CommandContext context);

/**
* Creates a command condition that checks if the sender has the required permission level.
* Console senders are always allowed.
*
* @param level the required permission level
* @return the command condition
*/
public CommandCondition permission(int level) {
return (sender, commandName) -> {
if (sender instanceof ConsoleSender) return true;
if (sender instanceof Player player) return player.getPermissionLevel() >= level;
return false;
};
}

/**
* Checks whether the command was invoked without any arguments.
*
* @param context the command context
* @return true if no arguments were given, false otherwise
*/
public boolean hasNoArguments(CommandContext context) {
return context.getCommandName().equals(context.getInput());
}
}

This file was deleted.

Loading