Skip to content
Open

5.0.0 #166

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
12 changes: 7 additions & 5 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("java")
id("java-library")
id("maven-publish")
}

Expand All @@ -8,8 +9,8 @@ version = rootProject.version

repositories {
mavenCentral()
maven("https://repo.thenextlvl.net/releases")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.thenextlvl.net/releases")
}

java {
Expand All @@ -23,15 +24,16 @@ tasks.compileJava {
}

dependencies {
compileOnly("com.google.code.gson:gson:2.13.2")
compileOnly("net.kyori:adventure-api:4.26.0-SNAPSHOT")
api("net.thenextlvl:static-binder:0.1.2")

implementation("net.thenextlvl.core:files:3.0.1")
implementation("net.thenextlvl.core:i18n:3.2.2")
compileOnlyApi("org.jetbrains:annotations:26.0.2-1")
compileOnlyApi("org.jspecify:jspecify:1.0.0")
}

publishing {
publications.create<MavenPublication>("maven") {
artifactId = "commander"
groupId = "net.thenextlvl"
pom.url.set("https://thenextlvl.net/docs/commander")
pom.scm {
val repository = "TheNextLvl-net/commander"
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.jspecify.annotations.NullMarked;

@NullMarked
module net.thenextlvl.commander {
exports net.thenextlvl.commander;

requires static org.jetbrains.annotations;
requires static org.jspecify;
requires net.thenextlvl.binder;
}
51 changes: 20 additions & 31 deletions api/src/main/java/net/thenextlvl/commander/CommandFinder.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,58 @@
package net.thenextlvl.commander;

import net.thenextlvl.binder.StaticBinder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.NullMarked;

import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* The CommandFinder interface defines methods for finding commands based on a given input.
*/
@NullMarked
@ApiStatus.NonExtendable
public interface CommandFinder {
static CommandFinder instance() {
return StaticBinder.getInstance(CommandFinder.class.getClassLoader()).find(CommandFinder.class);
}

/**
* Finds and returns a set of commands that match the given pattern.
*
* @param pattern The pattern used to search for commands.
* @return An unmodifiable set of strings representing the commands that match the pattern.
* @return A stream of strings representing the commands that match the pattern.
*/
@Unmodifiable
Set<String> findCommands(Pattern pattern);
@Contract(pure = true)
Stream<String> findCommands(Pattern pattern);

/**
* Filters and finds commands from the provided stream that match the given pattern.
*
* @param commands The stream of commands to be searched.
* @param pattern The pattern used to filter matching commands.
* @return An unmodifiable set of strings representing the commands that match the given pattern.
* @return A stream of strings representing the commands that match the given pattern.
*/
default @Unmodifiable Set<String> findCommands(Stream<String> commands, Pattern pattern) {
return commands.filter(command ->
pattern.matcher(command).matches()
).collect(Collectors.toSet());
}
@Contract(pure = true)
Stream<String> findCommands(Stream<String> commands, Pattern pattern);

/**
* This method finds commands based on a given input.
*
* @param commands The stream of commands to search for.
* @param input The input used to search for commands.
* @return An unmodifiable set of strings representing the found commands.
* @return A stream of strings representing the found commands.
*/
default @Unmodifiable Set<String> findCommands(Stream<String> commands, String input) {
try {
return findCommands(commands, Pattern.compile(input.replace("*", ".*")));
} catch (PatternSyntaxException e) {
var escaped = Pattern.quote(input).replace("\\*", "*");
return findCommands(commands, Pattern.compile(escaped.replace("*", ".*")));
}
}
@Contract(pure = true)
Stream<String> findCommands(Stream<String> commands, String input);

/**
* Finds commands based on the given input.
*
* @param input The input used to search for commands.
* @return An unmodifiable set of strings representing the found commands.
* @return A stream of strings representing the found commands.
*/
default @Unmodifiable Set<String> findCommands(String input) {
try {
return findCommands(Pattern.compile(input.replace("*", ".*")));
} catch (PatternSyntaxException e) {
var escaped = Pattern.quote(input).replace("\\*", "*");
return findCommands(Pattern.compile(escaped.replace("*", ".*")));
}
}
@Contract(pure = true)
Stream<String> findCommands(String input);
}
14 changes: 12 additions & 2 deletions api/src/main/java/net/thenextlvl/commander/CommandRegistry.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package net.thenextlvl.commander;

import net.thenextlvl.binder.StaticBinder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.NullMarked;

import java.util.Set;

@NullMarked
@ApiStatus.NonExtendable
public interface CommandRegistry {
static CommandRegistry instance() {
return StaticBinder.getInstance(CommandRegistry.class.getClassLoader()).find(CommandRegistry.class);
}

/**
* Retrieves the set of commands that are currently hidden from visibility.
* <p>
Expand All @@ -16,6 +22,7 @@ public interface CommandRegistry {
* @return an unmodifiable set of strings representing the commands that are currently hidden
*/
@Unmodifiable
@Contract(pure = true)
Set<String> hiddenCommands();

/**
Expand All @@ -24,6 +31,7 @@ public interface CommandRegistry {
* @return an unmodifiable set of strings representing the commands that are unregistered
*/
@Unmodifiable
@Contract(pure = true)
Set<String> unregisteredCommands();

/**
Expand All @@ -43,6 +51,7 @@ public interface CommandRegistry {
* @param command the name of the command to check
* @return true if the command is hidden, false otherwise
*/
@Contract(pure = true)
boolean isHidden(String command);

/**
Expand All @@ -51,6 +60,7 @@ public interface CommandRegistry {
* @param command the name of the command to check
* @return true if the command is unregistered, false otherwise
*/
@Contract(pure = true)
boolean isUnregistered(String command);

/**
Expand Down
36 changes: 0 additions & 36 deletions api/src/main/java/net/thenextlvl/commander/Commander.java

This file was deleted.

15 changes: 13 additions & 2 deletions api/src/main/java/net/thenextlvl/commander/PermissionOverride.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package net.thenextlvl.commander;

import net.thenextlvl.binder.StaticBinder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.Map;

@NullMarked
@ApiStatus.NonExtendable
public interface PermissionOverride {
static PermissionOverride instance() {
return StaticBinder.getInstance(PermissionOverride.class.getClassLoader()).find(PermissionOverride.class);
}

/**
* Retrieves a mapping of commands and their associated original permissions.
* <p>
Expand All @@ -18,6 +24,7 @@ public interface PermissionOverride {
* The permission value may be null if no original permission was assigned.
*/
@Unmodifiable
@Contract(pure = true)
Map<String, @Nullable String> originalPermissions();

/**
Expand All @@ -30,6 +37,7 @@ public interface PermissionOverride {
* The permission value may be null if no override is applied to the command.
*/
@Unmodifiable
@Contract(pure = true)
Map<String, @Nullable String> overrides();

/**
Expand All @@ -39,6 +47,7 @@ public interface PermissionOverride {
* @return the originally assigned permission as a string, or null if no original permission exists for the command
*/
@Nullable
@Contract(pure = true)
String originalPermission(String command);

/**
Expand All @@ -49,6 +58,7 @@ public interface PermissionOverride {
* @return the effective permission as a string, or null if no permission is assigned to the command
*/
@Nullable
@Contract(pure = true)
String permission(String command);

/**
Expand All @@ -58,6 +68,7 @@ public interface PermissionOverride {
* @param command the name of the command to check
* @return true if the command's permission is overridden, false otherwise
*/
@Contract(pure = true)
boolean isOverridden(String command);

/**
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "net.thenextlvl.commander"
version = "4.4.0"
version = "5.0.0"

plugins {
id("com.gradleup.shadow") version "9.2.2" apply false
Expand Down
23 changes: 23 additions & 0 deletions commons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id("java")
id("java-library")
}

group = rootProject.group
version = rootProject.version

repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.thenextlvl.net/releases")
}

dependencies {
api("net.thenextlvl.core:files:3.0.1")
api("net.thenextlvl.core:i18n:3.2.2")
api(project(":api"))

compileOnly("com.google.code.gson:gson:2.13.2")
compileOnly("com.mojang:brigadier:1.3.10")
compileOnly("net.kyori:adventure-api:4.26.0-SNAPSHOT")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.thenextlvl.commander;

import core.i18n.file.ComponentBundle;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.thenextlvl.commander.access.BrigadierAccess;
import org.jspecify.annotations.NullMarked;
import org.slf4j.Logger;

import java.nio.file.Path;
import java.util.Locale;
import java.util.stream.Stream;

@NullMarked
public abstract class CommanderCommons {
private final Path dataPath;
private final ComponentBundle bundle;

protected CommanderCommons(Path dataPath) {
this.dataPath = dataPath;
var key = Key.key("commander", "translations");
var translations = dataPath.resolve("translations");
this.bundle = ComponentBundle.builder(key, translations)
.placeholder("prefix", "prefix")
.miniMessage(MiniMessage.builder().tags(TagResolver.resolver(
TagResolver.standard(),
Placeholder.parsed("root_command", getRootCommand())
)).build())
.resource("commander.properties", Locale.US)
.resource("commander_german.properties", Locale.GERMANY)
.build();
}

public ComponentBundle bundle() {
return bundle;
}

public Path getDataPath() {
return dataPath;
}

public abstract CommandFinder commandFinder();

public abstract CommonCommandRegistry commandRegistry();

public abstract CommonPermissionOverride permissionOverride();

public abstract Logger logger();

public abstract <S> BrigadierAccess<S> brigadierAccess();

public abstract String getRootCommand();

public abstract Stream<String> getKnownCommands();

public abstract Stream<String> getKnownPermissions();

public abstract void updateCommands();

public abstract void conflictSave(Audience audience);

public abstract void hiddenConflictSave(Audience audience);

public abstract void unregisteredConflictSave(Audience audience);

public abstract void permissionConflictSave(Audience audience);
}
Loading