improve and fix cmd handler (first commit on arch)

yup this is my first commit on arch linux,.,.,..,.,.,
yes i use arch btw 😎
This commit is contained in:
Chayapak 2023-04-20 13:32:05 +07:00
parent 41680cf8cc
commit 678894b602
4 changed files with 20 additions and 8 deletions

View file

@ -89,7 +89,7 @@ public class Bot {
this.core = new CorePlugin(this); this.core = new CorePlugin(this);
this.players = new PlayersPlugin(this); this.players = new PlayersPlugin(this);
this.tabComplete = new TabCompletePlugin(this); this.tabComplete = new TabCompletePlugin(this);
this.commandHandler = new CommandHandlerPlugin(); this.commandHandler = new CommandHandlerPlugin(this);
this.chatCommandHandler = new ChatCommandHandlerPlugin(this); this.chatCommandHandler = new ChatCommandHandlerPlugin(this);
this.hashing = new HashingPlugin(this); this.hashing = new HashingPlugin(this);
this.bossbar = new BossbarManagerPlugin(this); this.bossbar = new BossbarManagerPlugin(this);

View file

@ -39,6 +39,8 @@ public class Configuration {
@Getter public String token; @Getter public String token;
@Getter public Map<String, String> servers = new HashMap<>(); @Getter public Map<String, String> servers = new HashMap<>();
@Getter public EmbedColors embedColors = new EmbedColors(); @Getter public EmbedColors embedColors = new EmbedColors();
@Getter public String trustedRoleName = "Trusted";
@Getter public String adminRoleName = "Admin";
} }
public static class EmbedColors { public static class EmbedColors {

View file

@ -1,5 +1,6 @@
package land.chipmunk.chayapak.chomens_bot.plugins; package land.chipmunk.chayapak.chomens_bot.plugins;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.commands.*; import land.chipmunk.chayapak.chomens_bot.commands.*;
@ -17,9 +18,13 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class CommandHandlerPlugin { public class CommandHandlerPlugin {
private final Bot bot;
@Getter private final List<Command> commands = new ArrayList<>(); @Getter private final List<Command> commands = new ArrayList<>();
public CommandHandlerPlugin () { public CommandHandlerPlugin (Bot bot) {
this.bot = bot;
registerCommand(new CommandBlockCommand()); registerCommand(new CommandBlockCommand());
registerCommand(new CowsayCommand()); registerCommand(new CowsayCommand());
registerCommand(new EchoCommand()); registerCommand(new EchoCommand());
@ -79,10 +84,10 @@ public class CommandHandlerPlugin {
if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED); if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED);
if (fullArgs.length > maximumArgs && !usage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED); if (fullArgs.length > maximumArgs && !usage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED);
if (trustLevel > 0 && splitInput.length < 2 && !console) return Component.text("Please provide a hash").color(NamedTextColor.RED); if (trustLevel > 0 && splitInput.length < 2 && inGame) return Component.text("Please provide a hash").color(NamedTextColor.RED);
String userHash = ""; String userHash = "";
if (trustLevel > 0 && !console) userHash = splitInput[1]; if (trustLevel > 0 && inGame) userHash = splitInput[1];
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length); final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length);
@ -90,16 +95,19 @@ public class CommandHandlerPlugin {
if (discord) { if (discord) {
final List<Role> roles = event.getMember().getRoles(); final List<Role> roles = event.getMember().getRoles();
final String trustedRoleName = bot.config().discord().trustedRoleName();
final String adminRoleName = bot.config().discord().adminRoleName();
if ( if (
command.trustLevel() == 1 && command.trustLevel() == 1 &&
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase("Trusted")) && roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(trustedRoleName)) &&
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase("Host")) roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName))
) return Component.text("You're not in the trusted role!").color(NamedTextColor.RED); ) return Component.text("You're not in the trusted role!").color(NamedTextColor.RED);
if ( if (
command.trustLevel() == 2 && command.trustLevel() == 2 &&
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase("Host")) roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName))
) return Component.text("You're not in the host role!").color(NamedTextColor.RED); ) return Component.text("You're not in the admin role!").color(NamedTextColor.RED);
} else { } else {
if ( if (
command.trustLevel() == 1 && command.trustLevel() == 1 &&

View file

@ -14,6 +14,8 @@ reconnectDelay: 7000
discord: discord:
prefix: 'default!' prefix: 'default!'
token: 'token here' token: 'token here'
trustedRoleName: 'Trusted'
adminRoleName: 'Admin' # NOTE: admin will be able to access servereval..
servers: servers:
localhost:25565: 'channel id' localhost:25565: 'channel id'