Skip to content

Commit

Permalink
Basic Command loader and reloader.
Browse files Browse the repository at this point in the history
  • Loading branch information
thevalleyy committed Apr 28, 2024
1 parent fde4733 commit 456d749
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/main/java/tk/thevalleyy/customcommands/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -119,6 +120,31 @@ public static BrigadierCommand createBrigadierCommand(final ProxyServer proxy) {
.deserialize(
CustomCommands.Prefix + "<gray>Config reloaded."));
}

// create an instance of registerCustomCommands
registerCustomCommands registerCustomCommands = new registerCustomCommands();
Path commandsFolder = Path.of(CustomCommands.folder + "/Commands/");

try {
// create the default command
registerCustomCommands.createDefaultCommand(commandsFolder);

// load all custom commands
registerCustomCommands.loadCustomCommands(commandsFolder);
} catch (Exception e) {
player.sendMessage(
MiniMessage.miniMessage()
.deserialize(
CustomCommands.Prefix
+ "<red>Failed to reload the custom commands. <newline> <gray>Check the console for more information."));
return 0;
}

player.sendMessage(
MiniMessage.miniMessage()
.deserialize(
CustomCommands.Prefix + "<gray>Custom commands reloaded."));

break;

case "help": // display the dynamic generated help message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import com.moandjiezana.toml.Toml;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.VelocityBrigadierMessage;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.io.File;
Expand Down Expand Up @@ -111,6 +107,7 @@ public void loadCustomCommands(Path folder) {
String permission = toml.getString("Permission");
String response = toml.getString("Response");
long cooldown = toml.getLong("Cooldown");
// todo: report errors if the values are null to the user (console or in-game)

// register the command
try {
Expand Down

0 comments on commit 456d749

Please sign in to comment.