Moved project into bot package, added fx package, isolated Main class, added CommandHandler

This commit is contained in:
Savvy 2017-11-10 17:38:03 -05:00
parent 4e48aa3d6c
commit 835db67880
21 changed files with 113 additions and 46 deletions

View File

@ -101,6 +101,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.rixa.bot.Rixa</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -0,0 +1,10 @@
package io.rixa;
import io.rixa.bot.Rixa;
public class Main {
public static void main(String[] args) {
Rixa.getInstance();
}
}

View File

@ -1,9 +1,10 @@
package io.rixa;
package io.rixa.bot;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.rixa.data.config.Configuration;
import io.rixa.utils.FileUtils;
import io.rixa.bot.commands.CommandHandler;
import io.rixa.bot.data.config.Configuration;
import io.rixa.bot.utils.FileUtils;
import lombok.Getter;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
@ -23,6 +24,7 @@ import java.util.logging.Logger;
public class Rixa {
private static Rixa instance;
@Getter private CommandHandler commandHandler;
@Getter private Configuration configuration;
@Getter private ObjectMapper objectMapper;
@Getter private List<JDA> shardList;
@ -35,11 +37,12 @@ public class Rixa {
logger = Logger.getLogger(Rixa.class.getCanonicalName());
objectMapper = new ObjectMapper(new YAMLFactory());
defaultPath = new File("Rixa");
commandHandler = new CommandHandler();
shardList = new ArrayList<>();
defaultPath.mkdirs();
loadConfiguration();
loadJDA();
registerCommands();
loadJDA();
}
private void loadJDA() {
@ -70,10 +73,13 @@ public class Rixa {
private void loadConfiguration() {
try {
FileUtils.saveResource("config.yml", false);
File file = new File(defaultPath.getPath() + "/config.yml");
configuration = objectMapper.readValue(file, Configuration.class);
logger.info("Configuration successfully loaded.");
if (FileUtils.saveResource("config.yml", false)) {
File file = new File(defaultPath.getPath() + "/config.yml");
configuration = objectMapper.readValue(file, Configuration.class);
logger.info("Configuration successfully loaded.");
logger.info("Shutting down Rixa. Please edit configuration");
System.exit(0);
}
} catch (IOException e) {
logger.severe("Could not properly load configuration file!.");
e.printStackTrace();
@ -83,8 +89,4 @@ public class Rixa {
public static Rixa getInstance() {
return (instance == null) ? new Rixa() : instance;
}
public static void main(String[] args) {
Rixa.getInstance();
}
}
}

View File

@ -1,8 +1,7 @@
package io.rixa.commands;
package io.rixa.bot.commands;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import java.util.Collections;

View File

@ -0,0 +1,25 @@
package io.rixa.bot.commands;
import io.rixa.bot.commands.exceptions.CommandNotFoundException;
import java.util.HashMap;
import java.util.Map;
public class CommandHandler {
private Map<String, Command> commandMap = new HashMap<>();
public void registerCommand(Command command) {
if (commandMap.containsKey(command.getCommand())) return;
commandMap.put(command.getCommand(), command);
}
public Command getCommand(String commandName) throws CommandNotFoundException {
for(Command command: commandMap.values()) {
if (command.getAliases().contains(commandName)) {
return command;
}
}
throw new CommandNotFoundException("Could not find command");
}
}

View File

@ -1,4 +1,4 @@
package io.rixa.commands;
package io.rixa.bot.commands;
public enum RixaPermission {
NONE;

View File

@ -1,7 +1,7 @@
package io.rixa.commands.cmds;
package io.rixa.bot.commands.cmds;
import io.rixa.commands.Command;
import io.rixa.commands.RixaPermission;
import io.rixa.bot.commands.Command;
import io.rixa.bot.commands.RixaPermission;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
public class HelpCommand extends Command {

View File

@ -0,0 +1,8 @@
package io.rixa.bot.commands.exceptions;
public class CommandNotFoundException extends Exception {
public CommandNotFoundException(String message) {
super(message);
}
}

View File

@ -1,4 +1,4 @@
package io.rixa.data;
package io.rixa.bot.data;
public interface DataStorage {
}

View File

@ -1,4 +1,4 @@
package io.rixa.data.config;
package io.rixa.bot.data.config;
import lombok.Getter;
import lombok.Setter;

View File

@ -0,0 +1,6 @@
package io.rixa.bot.data.storage;
import io.rixa.bot.data.DataStorage;
public class MySQLStorage implements DataStorage {
}

View File

@ -1,7 +1,7 @@
package io.rixa.guild;
package io.rixa.bot.guild;
import io.rixa.guild.manager.IGuild;
import io.rixa.guild.modules.RixaModule;
import io.rixa.bot.guild.manager.IGuild;
import io.rixa.bot.guild.modules.RixaModule;
import lombok.Getter;
import net.dv8tion.jda.core.entities.Guild;

View File

@ -0,0 +1,4 @@
package io.rixa.bot.guild.manager;
public class GuildManager {
}

View File

@ -1,6 +1,6 @@
package io.rixa.guild.manager;
package io.rixa.bot.guild.manager;
import io.rixa.guild.RixaGuild;
import io.rixa.bot.guild.RixaGuild;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;

View File

@ -1,6 +1,6 @@
package io.rixa.guild.manager;
package io.rixa.bot.guild.manager;
import io.rixa.guild.modules.RixaModule;
import io.rixa.bot.guild.modules.RixaModule;
public interface IGuild {

View File

@ -1,4 +1,4 @@
package io.rixa.guild.modules;
package io.rixa.bot.guild.modules;
public interface RixaModule {

View File

@ -1,6 +1,6 @@
package io.rixa.guild.modules.module;
package io.rixa.bot.guild.modules.module;
import io.rixa.guild.modules.RixaModule;
import io.rixa.bot.guild.modules.RixaModule;
import lombok.Getter;
import lombok.Setter;

View File

@ -1,6 +1,6 @@
package io.rixa.utils;
package io.rixa.bot.utils;
import io.rixa.Rixa;
import io.rixa.bot.Rixa;
import java.io.*;
import java.net.URL;
@ -11,7 +11,7 @@ public class FileUtils {
/*
Method borrowed from https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
*/
public static void saveResource(String resourcePath, boolean replace) throws IOException{
public static boolean saveResource(String resourcePath, boolean replace) throws IOException{
if (resourcePath == null || resourcePath.equals("")) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
@ -39,9 +39,9 @@ public class FileUtils {
}
out.close();
in.close();
} else {
System.out.println("Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
return true;
}
return false;
}
/*

View File

@ -1,6 +0,0 @@
package io.rixa.data.storage;
import io.rixa.data.DataStorage;
public class MySQLStorage implements DataStorage {
}

View File

@ -0,0 +1,16 @@
package io.rixa.fx;
import javafx.application.Application;
import javafx.stage.Stage;
public class RixaFX extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
}
}

View File

@ -1,4 +0,0 @@
package io.rixa.guild.manager;
public class GuildManager {
}