Skip to content
Merged
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: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ jobs:
with:
commit_message: Incremented patch version
commit_options: '--no-verify --signoff'
commit_user_name: Voinea Radu
commit_user_email: contact@voinearadu.com
commit_user_name: Radu Voinea
commit_user_email: contact@raduvoinea.com

# ==================== BUILD ====================

- name: Export Credentials
run: |
mkdir -p ~/.gradle
echo "
com.voinearadu.url=https://repository.voinearadu.com/repository/maven-releases/
com.voinearadu.auth.username=admin
com.voinearadu.auth.password=${{ secrets.NEXUS_PASSWORD }}
com.raduvoinea.url=https://repo.raduvoinea.com/repository/maven-releases/
com.raduvoinea.auth.username=admin
com.raduvoinea.auth.password=${{ secrets.NEXUS_PASSWORD }}
" > ~/.gradle/gradle.properties
if [ "${{ secrets.NEXUS_PASSWORD }}" == "" ]; then echo "com.voinearadu.publish=false" >> ~/.gradle/gradle.properties; fi
if [ "${{ secrets.NEXUS_PASSWORD }}" == "" ]; then echo "com.raduvoinea.publish=false" >> ~/.gradle/gradle.properties; fi

- name: Cache Gradle Dependencies
uses: actions/cache@v4
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

```kotlin
repositories {
maven("https://repository.voinearadu.com/repository/maven-releases/")
maven("https://repo.voinearadu.com/") // The short version of the above (might be slower on high latency connections)
maven("https://repo.raduvoinea.com/repository/maven-releases/")
maven("https://repo.raduvoinea.com/") // The short version of the above (might be slower on high latency connections)
}

dependencies {
implementation("com.voinearadu:command-manager-common:VERSION")
implementation("com.voinearadu:command-manager-velocity:VERSION")
implementation("com.voinearadu:command-manager-fabric-1-19:VERSION")
implementation("com.raduvoinea:command-manager-common:VERSION")
implementation("com.raduvoinea:command-manager-velocity:VERSION")
implementation("com.raduvoinea:command-manager-fabric-1-19:VERSION")
}
```
20 changes: 10 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ group = _group

fun DependencyHandlerScope.applyDependencies() {
// Dependencies
if(project.properties["com.voinearadu.utils.local"] != null){
api(project(project.properties["com.voinearadu.utils.local"] as String))
}else{
api(libs.voinearadu.utils)
if (project.properties["com.raduvoinea.utils.local"] != null) {
api(project(project.properties["com.raduvoinea.utils.local"] as String))
} else {
api(libs.raduvoinea.utils)
}

// Annotations
Expand All @@ -34,7 +34,7 @@ fun RepositoryHandler.applyRepositories() {
mavenCentral()
maven("https://maven.parchmentmc.org/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repository.voinearadu.com/repository/maven-releases/")
maven("https://repo.raduvoinea.com/repository/maven-releases/")
}

repositories {
Expand Down Expand Up @@ -76,12 +76,12 @@ subprojects {
}

repositories {
if (project.properties["com.voinearadu.publish"] == "true") {
maven(url = (project.findProperty("com.voinearadu.url") ?: "") as String) {
name = "VoineaRaduRepository"
if (project.properties["com.raduvoinea.publish"] == "true") {
maven(url = (project.findProperty("com.raduvoinea.url") ?: "") as String) {
name = "raduvoineaRepository"
credentials(PasswordCredentials::class) {
username = (project.findProperty("com.voinearadu.auth.username") ?: "") as String
password = (project.findProperty("com.voinearadu.auth.password") ?: "") as String
username = (project.findProperty("com.raduvoinea.auth.username") ?: "") as String
password = (project.findProperty("com.raduvoinea.auth.password") ?: "") as String
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.voinearadu.publish=true
com.raduvoinea.publish=true
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]

version = "1.1.7"
group = "com.voinearadu"
group = "com.raduvoinea"

[plugins]

Expand Down Expand Up @@ -33,4 +33,4 @@ jetbrains_annotations = { module = "org.jetbrains:annotations", version = "26.0.
luckperms = { module = "net.luckperms:api", version = "5.4" }
kyori_minimessage = { module = "net.kyori:adventure-text-minimessage", version = "4.17.0" }
kyori_adventure_fabric = { module = "net.kyori:adventure-platform-fabric", version = "5.9.0" }
voinearadu_utils = { module = "com.voinearadu:utils", version = "1.1.28" }
raduvoinea_utils = { module = "com.raduvoinea:utils", version = "1.1.28" }
8 changes: 4 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}
6 changes: 3 additions & 3 deletions src/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies {
// Dependencies
if (project.properties["com.voinearadu.utils.local"] != null) {
api(project(project.properties["com.voinearadu.utils.local"] as String))
if (project.properties["com.raduvoinea.utils.local"] != null) {
api(project(project.properties["com.raduvoinea.utils.local"] as String))
} else {
api(libs.voinearadu.utils)
api(libs.raduvoinea.utils)
}
api(libs.luckperms)
api(libs.kyori.minimessage)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.voinearadu.commandmanager.common.annotation;
package com.raduvoinea.commandmanager.common.annotation;

import com.voinearadu.commandmanager.common.command.CommonCommand;
import com.raduvoinea.commandmanager.common.command.CommonCommand;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -13,6 +13,8 @@

String[] aliases();

String[] arguments() default {};

OnlyFor onlyFor() default OnlyFor.BOTH;

Class<? extends CommonCommand> parent() default CommonCommand.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.voinearadu.commandmanager.common.command;
package com.raduvoinea.commandmanager.common.command;

import com.voinearadu.commandmanager.common.annotation.Command;
import com.voinearadu.commandmanager.common.exception.CommandNotAnnotated;
import com.voinearadu.commandmanager.common.manager.CommonCommandManager;
import com.voinearadu.utils.logger.Logger;
import com.raduvoinea.commandmanager.common.annotation.Command;
import com.raduvoinea.commandmanager.common.exception.CommandNotAnnotated;
import com.raduvoinea.commandmanager.common.manager.CommonCommandManager;
import com.raduvoinea.utils.logger.Logger;
import com.raduvoinea.utils.message_builder.GenericMessageBuilder;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
Expand All @@ -19,8 +19,7 @@ public abstract class CommonCommand {
// Provided
private final CommonCommandManager commandManager;
private final @Getter Command annotation;
private final Set<CommonCommand> subCommands = new HashSet<>();
private boolean enabled = true;
private final List<CommonCommand> subCommands;

public CommonCommand(CommonCommandManager commandManager) throws CommandNotAnnotated {
this.commandManager = commandManager;
Expand All @@ -30,67 +29,83 @@ public CommonCommand(CommonCommandManager commandManager) throws CommandNotAnnot

this.annotation = this.getClass().getAnnotation(Command.class);

subCommands.addAll(commandManager.getReflectionsCrawler().getOfType(CommonCommand.class)
subCommands = commandManager.getReflectionsCrawler().getOfType(CommonCommand.class)
.stream()
.filter(commandClass -> commandClass.isAnnotationPresent(Command.class))
.filter(commandClass -> commandClass.getAnnotation(Command.class).parent().equals(this.getClass()))
.collect(Collectors.toSet())
.stream().map(commandClass -> {
.map(commandClass -> {
try {
return commandClass.getConstructor(CommonCommandManager.class).newInstance(commandManager);
CommonCommand command = commandClass.getConstructor(CommonCommandManager.class).newInstance(commandManager);
if (!commandManager.getInjectorHolder().isEmpty()) {
commandManager.getInjectorHolder().value().inject(command);
}
return command;
} catch (Exception error) {
Logger.error("There was an error while registering sub command " + commandClass.getName() + " for command(s) " + this.getAliases());
Logger.error(error);
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toSet()));
.collect(Collectors.toList());
}

public void enable() {
if (annotation.parent() == CommonCommand.class) {
Logger.log("Enabling command(s): " + this.getAliases());
} else {
CommonCommand parentCommand = commandManager.getCommand(annotation.parent());
private String getFullCommand() {
String parentFullCommand = "";

if (parentCommand == null) {
throw new RuntimeException("Parent command " + annotation.parent().getName() + " of subcommand " + this.getAliases() + " is not registered.");
if (!isRootCommand()) {
CommonCommand parent = commandManager.getCommand(getParent());

if (parent == null) {
Logger.error("Command " + getParent().getName() + " is not registered.");
return "Registration Error";
}

Logger.log("Enabling subcommand(s) of " + parentCommand.getAliases() + ": " + this.getAliases());
parentFullCommand = parent.getFullCommand() + " ";
}

this.enabled = true;
for (CommonCommand subCommand : this.getPrimitiveSubCommands()) {
subCommand.enable();
}
return parentFullCommand + this.getMainAlias();
}

public void disable() {
if (annotation.parent() == CommonCommand.class) {
Logger.log("Disabling command(s): " + this.getAliases());
} else {
CommonCommand parentCommand = commandManager.getCommand(annotation.parent());
private String getSimpleUsage() {
return commandManager.getConfig().simpleUsage
.parse("command", this.getFullCommand())
.parse("arguments", String.join(" ",
getArguments().stream()
.map(arg -> "<" + arg + ">")
.toList()
))
.parse();
}

if (parentCommand == null) {
throw new RuntimeException("Parent command " + annotation.parent().getName() + " of subcommand " + this.getAliases() + " is not registered.");
}
private List<String> getFullCommandAndSubCommands() {
List<String> lines = new ArrayList<>();
lines.add(this.getSimpleUsage());

Logger.log("Enabling subcommand(s) of " + parentCommand.getAliases() + ": " + this.getAliases());
for (CommonCommand subCommand : subCommands) {
lines.addAll(subCommand.getFullCommandAndSubCommands());
}

this.enabled = false;
for (CommonCommand subCommand : this.getPrimitiveSubCommands()) {
subCommand.disable();
}
lines.sort(String::compareTo);

return lines;
}

public void execute(@NotNull Object executor, @NotNull List<String> arguments) {
if (!enabled) {
return;
public String getUsage() {
List<String> subcommands = getFullCommandAndSubCommands();
subcommands = subcommands.subList(1, subcommands.size());

if(subcommands.isEmpty()){
return getSimpleUsage();
}

return commandManager.getConfig().complexUsage
.parse("simple_usage", getSimpleUsage())
.parse("sub_commands", String.join("\n", subcommands))
.parse();
}

public void execute(@NotNull Object executor, @NotNull List<String> arguments) {
if (!commandManager.checkPermission(executor, getPermission())) {
commandManager.sendMessage(executor, "You don't have permission to execute this command.");
return;
Expand All @@ -109,6 +124,11 @@ public void execute(@NotNull Object executor, @NotNull List<String> arguments) {
}
}

if (arguments.size() < this.getArguments().size()) {
sendMessage(executor, getUsage());
return;
}

if (annotation.onlyFor().equals(Command.OnlyFor.PLAYERS)) {
if (commandManager.getPlayerClass().isInstance(executor)) {
internalExecutePlayer(commandManager.getPlayerClass().cast(executor), arguments);
Expand Down Expand Up @@ -143,30 +163,33 @@ public void execute(@NotNull Object executor, @NotNull List<String> arguments) {
protected abstract void internalExecuteCommon(@NotNull Object sender, @NotNull List<String> arguments);

public @NotNull String getPermission() {
Class<? extends CommonCommand> parentClass = annotation.parent();

if (parentClass.equals(CommonCommand.class)) {
return commandManager.getBasePermission() + "." + annotation.aliases()[0];
if (isRootCommand()) {
return commandManager.getConfig().basePermission + "." + annotation.aliases()[0];
}

CommonCommand command = commandManager.getCommand(parentClass);
CommonCommand command = commandManager.getCommand(getParent());

if (command == null) {
throw new RuntimeException("Command " + parentClass.getName() + " is not registered.");
throw new RuntimeException("Command " + getParent().getName() + " is not registered.");
}

return command.getPermission() + "." + annotation.aliases()[0];
}

public final @NotNull Set<CommonCommand> getPrimitiveSubCommands() {
Set<CommonCommand> subCommands = new HashSet<>();
public final @NotNull List<CommonCommand> getPrimitiveSubCommands() {
return this.subCommands;
}

for (CommonCommand subCommand : this.subCommands) {
subCommands.add(subCommand);
subCommands.addAll(subCommand.getPrimitiveSubCommands());
}
public List<String> getArguments() {
return List.of(annotation.arguments());
}

public Class<? extends CommonCommand> getParent() {
return annotation.parent();
}

return subCommands;
public boolean isRootCommand() {
return getParent().equals(CommonCommand.class);
}

public final String getMainAlias() {
Expand All @@ -177,18 +200,16 @@ public final List<String> getAliases() {
return List.of(annotation.aliases());
}

protected final void sendMessage(Object target, String message) {
commandManager.sendMessage(target, message);
protected final void sendMessage(Object target, GenericMessageBuilder<?> message) {
sendMessage(target, message.toString());
}

protected final void broadcastMessage(String message) {
commandManager.broadcastMessage(message);
protected final void sendMessage(Object target, String message) {
commandManager.sendMessage(target, message);
}


protected final boolean checkPermission(Object target, String permission) {
return commandManager.checkPermission(target, permission);
}


}
Loading
Loading