From 1e151abae118ca465c865fd0e3de704051569c7d Mon Sep 17 00:00:00 2001 From: comportment Date: Sat, 7 Oct 2017 21:12:22 +0100 Subject: [PATCH] Making JDA-Command more lightweight, introducing comparing of commands --- README.md | 10 ++--- pom.xml | 11 ++---- .../diax/comportment/jdacommand/Command.java | 7 +++- .../jdacommand/CommandHandler.java | 18 ++------- .../jdacommand/ExecutionException.java | 37 ------------------- .../jdacommand/JDACommandInfo.java | 2 +- 6 files changed, 18 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/me/diax/comportment/jdacommand/ExecutionException.java diff --git a/README.md b/README.md index 471b4f2..2f1e465 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ For more detailed examples please see the example repository

Use JDA-Command in your projects today!

-The current promoted version is 1.1.0 +The current promoted version is 1.1.1
Maven
@@ -61,13 +61,13 @@ The current promoted version is 1.1.0 com.github.Comportment JDA-Command - 1.1.0 + 1.1.1 net.dv8tion JDA - 3.2.0_242 + 3.3.1_286 ``` @@ -83,8 +83,8 @@ repositories { dependencies { //JDA-Command dependency - compile 'com.github.Comportment:JDA-Command:1.1.0' + compile 'com.github.Comportment:JDA-Command:1.1.1' //JDA dependency - compile group: 'net.dv8tion', name: 'JDA', version: '3.2.0_242' + compile group: 'net.dv8tion', name: 'JDA', version: '3.3.1_286' } ``` diff --git a/pom.xml b/pom.xml index 4704d97..c3af47b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ me.diax.comportment JDA-Command - 1.1.0 + 1.1.1 Diax Software @@ -27,7 +27,7 @@ developer - comportment#9489 + comportment#4475 @ComportmentUK @@ -78,13 +78,8 @@ net.dv8tion JDA - 3.2.0_242 + 3.3.1_286 provided - - org.slf4j - slf4j-api - 1.8.0-alpha2 - diff --git a/src/main/java/me/diax/comportment/jdacommand/Command.java b/src/main/java/me/diax/comportment/jdacommand/Command.java index 0c9a075..c347545 100644 --- a/src/main/java/me/diax/comportment/jdacommand/Command.java +++ b/src/main/java/me/diax/comportment/jdacommand/Command.java @@ -26,7 +26,7 @@ * @author Comportment * @since 1.0.0 */ -public interface Command { +public interface Command extends Comparable { /** * This is the method called on to execute the command. @@ -69,4 +69,9 @@ default String getAttributeValueFromKey(String key) { default boolean hasAttribute(String key) { return Arrays.stream(getDescription().attributes()).anyMatch(ca -> ca.key().equals(key)); } + + @Override + default int compareTo(Command that) { + return this.getDescription().name().compareTo(that.getDescription().name()); + } } \ No newline at end of file diff --git a/src/main/java/me/diax/comportment/jdacommand/CommandHandler.java b/src/main/java/me/diax/comportment/jdacommand/CommandHandler.java index d458bb2..4c7bf92 100644 --- a/src/main/java/me/diax/comportment/jdacommand/CommandHandler.java +++ b/src/main/java/me/diax/comportment/jdacommand/CommandHandler.java @@ -16,10 +16,7 @@ package me.diax.comportment.jdacommand; -import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.Collections; @@ -33,7 +30,6 @@ * @since 1.0.0 */ public class CommandHandler { - private final Logger logger = LoggerFactory.getLogger("JDA-Command"); /** * A set of all of the commands that this {@link CommandHandler} has registered. @@ -140,19 +136,12 @@ public Command findCommand(String trigger) { * @param command The {@link Command} to execute. * @param message The {@link Message} which triggered the command. * @param args The arguments of the command. - * @throws ExecutionException If the command could not be executed. * @since 1.0.0 */ - public void execute(Command command, Message message, String args) throws ExecutionException { + public void execute(Command command, Message message, String args) { CommandDescription cd = command.getDescription(); if (cd == null) return; - //if (cd.args() > args.split("\\s+").length) return; - try { - logger.info("Executing " + cd.name()); - command.execute(message, args.trim()); - } catch (Exception e) { - throw new ExecutionException(e); - } + command.execute(message, args.trim()); } /** @@ -161,12 +150,11 @@ public void execute(Command command, Message message, String args) throws Execut * @param trigger The trigger of the command. * @param message The {@link Message} which triggered the command. * @param args The args of the command. - * @throws ExecutionException If the command could not be executed. * @see #findCommand(String) * @see #execute(Command, Message, String) * @since 1.0.1 */ - public void findAndExecute(String trigger, Message message, String args) throws ExecutionException { + public void findAndExecute(String trigger, Message message, String args) { Command command = this.findCommand(trigger); if (command == null || command.getDescription() == null) return; this.execute(command, message, args); diff --git a/src/main/java/me/diax/comportment/jdacommand/ExecutionException.java b/src/main/java/me/diax/comportment/jdacommand/ExecutionException.java deleted file mode 100644 index b131171..0000000 --- a/src/main/java/me/diax/comportment/jdacommand/ExecutionException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2017 Comportment | comportment@diax.me - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.diax.comportment.jdacommand; - -/** - * This represents an {@link Exception} that occurs when an error with JDA-Command occurs. - * - * @author Comportment - * @since 1.0.0 - */ -public class ExecutionException extends RuntimeException { - private static final long serialVersionUID = -3419515084851063729L; - - /** - * Constructor for an {@link ExecutionException}. - * - * @see RuntimeException(String, Throwable) - * @since 1.0.3 - */ - ExecutionException(Throwable cause) { - super(cause); - } -} \ No newline at end of file diff --git a/src/main/java/me/diax/comportment/jdacommand/JDACommandInfo.java b/src/main/java/me/diax/comportment/jdacommand/JDACommandInfo.java index 1cb088b..22af126 100644 --- a/src/main/java/me/diax/comportment/jdacommand/JDACommandInfo.java +++ b/src/main/java/me/diax/comportment/jdacommand/JDACommandInfo.java @@ -29,5 +29,5 @@ public class JDACommandInfo { * * @since 1.0.1 */ - public static final String VERSION = "1.1.0"; + public static final String VERSION = "1.1.1"; } \ No newline at end of file