Moved project into bot package, added fx package, isolated Main class, added CommandHandler
This commit is contained in:
parent
4e48aa3d6c
commit
835db67880
7
pom.xml
7
pom.xml
@ -101,6 +101,13 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.0.2</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>io.rixa.bot.Rixa</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
10
src/main/java/io/rixa/Main.java
Normal file
10
src/main/java/io/rixa/Main.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package io.rixa;
|
||||||
|
|
||||||
|
import io.rixa.bot.Rixa;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Rixa.getInstance();
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
package io.rixa;
|
package io.rixa.bot;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
import io.rixa.data.config.Configuration;
|
import io.rixa.bot.commands.CommandHandler;
|
||||||
import io.rixa.utils.FileUtils;
|
import io.rixa.bot.data.config.Configuration;
|
||||||
|
import io.rixa.bot.utils.FileUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.dv8tion.jda.core.AccountType;
|
import net.dv8tion.jda.core.AccountType;
|
||||||
import net.dv8tion.jda.core.JDA;
|
import net.dv8tion.jda.core.JDA;
|
||||||
@ -23,6 +24,7 @@ import java.util.logging.Logger;
|
|||||||
public class Rixa {
|
public class Rixa {
|
||||||
|
|
||||||
private static Rixa instance;
|
private static Rixa instance;
|
||||||
|
@Getter private CommandHandler commandHandler;
|
||||||
@Getter private Configuration configuration;
|
@Getter private Configuration configuration;
|
||||||
@Getter private ObjectMapper objectMapper;
|
@Getter private ObjectMapper objectMapper;
|
||||||
@Getter private List<JDA> shardList;
|
@Getter private List<JDA> shardList;
|
||||||
@ -35,11 +37,12 @@ public class Rixa {
|
|||||||
logger = Logger.getLogger(Rixa.class.getCanonicalName());
|
logger = Logger.getLogger(Rixa.class.getCanonicalName());
|
||||||
objectMapper = new ObjectMapper(new YAMLFactory());
|
objectMapper = new ObjectMapper(new YAMLFactory());
|
||||||
defaultPath = new File("Rixa");
|
defaultPath = new File("Rixa");
|
||||||
|
commandHandler = new CommandHandler();
|
||||||
shardList = new ArrayList<>();
|
shardList = new ArrayList<>();
|
||||||
defaultPath.mkdirs();
|
defaultPath.mkdirs();
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
loadJDA();
|
|
||||||
registerCommands();
|
registerCommands();
|
||||||
|
loadJDA();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJDA() {
|
private void loadJDA() {
|
||||||
@ -70,10 +73,13 @@ public class Rixa {
|
|||||||
|
|
||||||
private void loadConfiguration() {
|
private void loadConfiguration() {
|
||||||
try {
|
try {
|
||||||
FileUtils.saveResource("config.yml", false);
|
if (FileUtils.saveResource("config.yml", false)) {
|
||||||
File file = new File(defaultPath.getPath() + "/config.yml");
|
File file = new File(defaultPath.getPath() + "/config.yml");
|
||||||
configuration = objectMapper.readValue(file, Configuration.class);
|
configuration = objectMapper.readValue(file, Configuration.class);
|
||||||
logger.info("Configuration successfully loaded.");
|
logger.info("Configuration successfully loaded.");
|
||||||
|
logger.info("Shutting down Rixa. Please edit configuration");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.severe("Could not properly load configuration file!.");
|
logger.severe("Could not properly load configuration file!.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -83,8 +89,4 @@ public class Rixa {
|
|||||||
public static Rixa getInstance() {
|
public static Rixa getInstance() {
|
||||||
return (instance == null) ? new Rixa() : instance;
|
return (instance == null) ? new Rixa() : instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Rixa.getInstance();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,8 +1,7 @@
|
|||||||
package io.rixa.commands;
|
package io.rixa.bot.commands;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
25
src/main/java/io/rixa/bot/commands/CommandHandler.java
Normal file
25
src/main/java/io/rixa/bot/commands/CommandHandler.java
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package io.rixa.commands;
|
package io.rixa.bot.commands;
|
||||||
|
|
||||||
public enum RixaPermission {
|
public enum RixaPermission {
|
||||||
NONE;
|
NONE;
|
@ -1,7 +1,7 @@
|
|||||||
package io.rixa.commands.cmds;
|
package io.rixa.bot.commands.cmds;
|
||||||
|
|
||||||
import io.rixa.commands.Command;
|
import io.rixa.bot.commands.Command;
|
||||||
import io.rixa.commands.RixaPermission;
|
import io.rixa.bot.commands.RixaPermission;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class HelpCommand extends Command {
|
public class HelpCommand extends Command {
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.rixa.bot.commands.exceptions;
|
||||||
|
|
||||||
|
public class CommandNotFoundException extends Exception {
|
||||||
|
|
||||||
|
public CommandNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package io.rixa.data;
|
package io.rixa.bot.data;
|
||||||
|
|
||||||
public interface DataStorage {
|
public interface DataStorage {
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package io.rixa.data.config;
|
package io.rixa.bot.data.config;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
6
src/main/java/io/rixa/bot/data/storage/MySQLStorage.java
Normal file
6
src/main/java/io/rixa/bot/data/storage/MySQLStorage.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package io.rixa.bot.data.storage;
|
||||||
|
|
||||||
|
import io.rixa.bot.data.DataStorage;
|
||||||
|
|
||||||
|
public class MySQLStorage implements DataStorage {
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package io.rixa.guild;
|
package io.rixa.bot.guild;
|
||||||
|
|
||||||
import io.rixa.guild.manager.IGuild;
|
import io.rixa.bot.guild.manager.IGuild;
|
||||||
import io.rixa.guild.modules.RixaModule;
|
import io.rixa.bot.guild.modules.RixaModule;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
package io.rixa.bot.guild.manager;
|
||||||
|
|
||||||
|
public class GuildManager {
|
||||||
|
}
|
@ -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 org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
@ -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 {
|
public interface IGuild {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package io.rixa.guild.modules;
|
package io.rixa.bot.guild.modules;
|
||||||
|
|
||||||
public interface RixaModule {
|
public interface RixaModule {
|
||||||
|
|
@ -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.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
@ -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.io.*;
|
||||||
import java.net.URL;
|
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
|
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("")) {
|
if (resourcePath == null || resourcePath.equals("")) {
|
||||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||||
}
|
}
|
||||||
@ -39,9 +39,9 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
} else {
|
return true;
|
||||||
System.out.println("Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
@ -1,6 +0,0 @@
|
|||||||
package io.rixa.data.storage;
|
|
||||||
|
|
||||||
import io.rixa.data.DataStorage;
|
|
||||||
|
|
||||||
public class MySQLStorage implements DataStorage {
|
|
||||||
}
|
|
16
src/main/java/io/rixa/fx/RixaFX.java
Normal file
16
src/main/java/io/rixa/fx/RixaFX.java
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
package io.rixa.guild.manager;
|
|
||||||
|
|
||||||
public class GuildManager {
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user