Skip to content

Commit

Permalink
feat(cmd): Add command creator
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Dec 19, 2023
1 parent 6cc9ce1 commit fe0f75c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
10 changes: 10 additions & 0 deletions api/src/main/java/com/artformgames/core/ArtCore.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.artformgames.core;

import cc.carm.lib.easysql.api.SQLManager;
import com.artformgames.core.command.handlers.CommandUsageHandler;
import com.artformgames.core.command.handlers.PermMissedHandler;
import com.artformgames.core.user.manager.UserManager;
import dev.rollczi.litecommands.LiteCommandsBuilder;
import dev.rollczi.litecommands.bukkit.LiteBukkitSettings;
import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit;
import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

public class ArtCore {
Expand All @@ -25,6 +31,10 @@ private static ArtCorePlugin plugin() {
return core;
}

public LiteCommandsBuilder<CommandSender, LiteBukkitSettings, ?> createCommand() {
return LiteCommandsBukkit.builder().missingPermission(new PermMissedHandler()).invalidUsage(new CommandUsageHandler());
}

public static SQLManager getSQLManager() {
return plugin().getSQLManager();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.artformgames.core.command.handlers;

import com.artformgames.core.conf.GeneralMessages;
import dev.rollczi.litecommands.handler.result.ResultHandlerChain;
import dev.rollczi.litecommands.invalidusage.InvalidUsage;
import dev.rollczi.litecommands.invalidusage.InvalidUsageHandler;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.schematic.Schematic;
import org.bukkit.command.CommandSender;

public class CommandUsageHandler implements InvalidUsageHandler<CommandSender> {


@Override
public void handle(Invocation<CommandSender> invocation, InvalidUsage<CommandSender> result, ResultHandlerChain<CommandSender> chain) {
CommandSender sender = invocation.sender();
Schematic schematic = result.getSchematic();

if (schematic.isOnlyFirst()) {
GeneralMessages.UNKNOWN_COMMAND.send(sender, schematic.first());
return;
}

GeneralMessages.UNKNOWN_COMMANDS.send(sender);
schematic.all().forEach(scheme -> sender.sendMessage("§8 # §7" + scheme));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.artformgames.core.command.handlers;

import com.artformgames.core.conf.GeneralMessages;
import dev.rollczi.litecommands.handler.result.ResultHandlerChain;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.permission.MissingPermissions;
import dev.rollczi.litecommands.permission.MissingPermissionsHandler;
import org.bukkit.command.CommandSender;

public class PermMissedHandler implements MissingPermissionsHandler<CommandSender> {

@Override
public void handle(Invocation<CommandSender> invocation,
MissingPermissions missingPermissions, ResultHandlerChain<CommandSender> resultHandlerChain) {
CommandSender sender = invocation.sender();

GeneralMessages.NO_PERMISSIONS.send(sender);

if (sender.hasPermission("group.admin")) {
int i = 1;
for (String permission : missingPermissions.getPermissions()) {
if (!sender.hasPermission(permission)) {
GeneralMessages.MISSING_PERMISSION.send(sender);
sender.sendMessage("§8 # §7" + i + ". " + permission);
i++;
}
}
}

}


}
28 changes: 28 additions & 0 deletions api/src/main/java/com/artformgames/core/conf/GeneralMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.artformgames.core.conf;

import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
import net.md_5.bungee.api.chat.BaseComponent;

public class GeneralMessages extends MessagesRoot {

public static final ConfiguredMessageList<BaseComponent[]> UNKNOWN_COMMAND = list()
.defaults(
"&c&lUnknown command! &fPlease check your inputs.",
"&8# &fMaybe you want to use &e%(command) &f?"
).params("command").build();

public static final ConfiguredMessageList<BaseComponent[]> UNKNOWN_COMMANDS = list()
.defaults(
"&c&lUnknown command! &fPossible commands:"
).build();


public static final ConfiguredMessageList<BaseComponent[]> NO_PERMISSIONS = list()
.defaults("&c&lSorry! &fYou don't have permission to do this.")
.build();

public static final ConfiguredMessageList<BaseComponent[]> MISSING_PERMISSION = list()
.defaults("&7Missing permissions: ")
.build();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.artformgames.core.conf;

import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.annotation.ConfigPath;

public class PluginMessages extends MessagesRoot {

@ConfigPath(root = true)
public static final Class<?> GENERAL = GeneralMessages.class;

public class PluginMessages extends ConfigurationRoot {
}

0 comments on commit fe0f75c

Please sign in to comment.