feat: added TranslateCommand, added MapManager, added MapData, removed unused Arguments from Command & Inheritance, Option was unused & removed

chore: removed unused library "json"
This commit is contained in:
limited_dev 2022-10-16 12:56:20 +02:00
parent cf5833f57b
commit a1f7951c03
18 changed files with 119 additions and 95 deletions

View file

@ -14,7 +14,6 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
implementation("net.dv8tion:JDA:5.0.0-alpha.20")
implementation("org.json:json:20220924")
}
tasks.getByName<Test>("test") {

View file

@ -1,25 +1,20 @@
package de.limited_dev.lil_judd;
import de.limited_dev.lil_judd.commands.components.CommandManager;
import de.limited_dev.lil_judd.features.MapManager;
import de.limited_dev.lil_judd.features.TimePlanner;
import de.limited_dev.lil_judd.features.WeaponManager;
import de.limited_dev.lil_judd.features.storage.GuildTimePlannerStorage;
import de.limited_dev.lil_judd.listeners.GuildStateListener;
import de.limited_dev.lil_judd.listeners.ReadyListener;
import de.limited_dev.lil_judd.listeners.SlashCommandInteractionListener;
import de.limited_dev.lil_judd.util.Logger;
import de.limited_dev.lil_judd.util.SlashCommandHelper;
import de.limited_dev.lil_judd.util.managers.TokenManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.requests.GatewayIntent;
import java.io.IOException;
public class Main {
private static JDA jda;
private static Logger lgr = new Logger();
@ -41,6 +36,7 @@ public class Main {
.build();
CommandManager.registerCommands();
MapManager.registerMaps();
jda.addEventListener(new ReadyListener());
jda.addEventListener(new SlashCommandInteractionListener());

View file

@ -1,7 +1,6 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.features.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
@ -10,7 +9,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class EndScrimCommand extends Command {
public EndScrimCommand() {
super("endscrim", "Quit a scrum / Leave the queue", null);
super("endscrim");
}
@Override
@ -18,11 +17,11 @@ public class EndScrimCommand extends Command {
Guild g = event.getGuild();
User u = event.getUser();
if(!ScrimMaker.IsInGameOrQueue(g)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "The Guild wasn't in a scrim.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "405: Method not allowed", "The Guild wasn't in a scrim.", null);
return;
}
if(!ScrimMaker.IsUserInGameOrQueue(g, u)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "There is a game running, but you are not part of it.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "There is a game running, but you are not part of it.", null);
return;
}
ScrimMaker.LeaveQueue(g);

View file

@ -1,14 +1,12 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class InfoCommand extends Command {
public InfoCommand() {
super("info", "Let me tell you about me", null);
super("info");
}
@Override

View file

@ -1,7 +1,6 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.features.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
@ -10,7 +9,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class MessageScrimCommand extends Command {
public MessageScrimCommand() {
super("msgscrim", "Msg the enemy team", null);
super("msgscrim");
}
@Override
@ -18,11 +17,11 @@ public class MessageScrimCommand extends Command {
Guild g = event.getGuild();
User u = event.getUser();
if(!ScrimMaker.IsInGameOrQueue(g)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "The Guild is not in a scrim.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "404: Not Found", "The Guild is not in a scrim.", null);
return;
}
if(!ScrimMaker.IsUserInGame(g, u)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Error", "You are not in the current game.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "You are not in the current game.", null);
return;
}
ScrimMaker.sendMessageToEnemy(g, u, event.getOption("message").getAsString());

View file

@ -3,13 +3,12 @@ package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class PingCommand extends Command {
public PingCommand() {
super("ping", "Pong! Get the Ping to my base", null);
super("ping");
}
@Override

View file

@ -1,7 +1,6 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.features.TimePlanner;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.Permission;
@ -9,13 +8,13 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class RemoveFeatureCommand extends Command {
public RemoveFeatureCommand() {
super("remove", "Remove a feature", new Option[]{ new Option(null, "Feature name", "Des", false)});
super("remove");
}
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
if(!event.getGuild().getMemberById(event.getUser().getId()).hasPermission(Permission.ADMINISTRATOR)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You do not have the Permission", "Sorry, but you don't have the Permission to run this command", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "Sorry, but you don't have the Permission to run this command", null);
return;
}
if(event.getOption("feature").getAsString().equals("timefinder")){

View file

@ -1,14 +1,13 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.features.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class ScrimInfoCommand extends Command {
public ScrimInfoCommand() {
super("scriminfo", "", null);
super("scriminfo");
}
@Override

View file

@ -1,11 +1,9 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.features.ScrimMaker;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@ -14,7 +12,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class SearchScrimCommand extends Command {
public SearchScrimCommand() {
super("searchscrim", "Search for a scrim", null);
super("searchscrim");
}
@Override
@ -32,15 +30,15 @@ public class SearchScrimCommand extends Command {
Guild g = event.getGuild();
int div = event.getOption("div").getAsInt();
if(ScrimMaker.IsInGameOrQueue(g)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "The Guild is already in a match", "You cannot join another.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "406: Not Acceptable", "The Guild is already in a match.", null);
return;
}
if(ContainsAUserTwice(users)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You added a user twice.", "Please only add every user once.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "406: Not Acceptable", "Please only add every user once.", null);
return;
}
if(ContainsABot(users)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You added a bot", "You cannot add a bot as user.", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "406: Not Acceptable", "You cannot add a bot as user.", null);
return;
}
ScrimMaker.EnterQueue(g, event.getChannel().asTextChannel(), div, users);
@ -53,6 +51,7 @@ public class SearchScrimCommand extends Command {
null);
}
private boolean ContainsAUserTwice(List<User> users){
int counter = 0;
for (User u : users)

View file

@ -1,7 +1,6 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.Option;
import de.limited_dev.lil_judd.features.TimePlanner;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.Permission;
@ -9,13 +8,13 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
public class SetupFeatureCommand extends Command {
public SetupFeatureCommand() {
super("setup", "Setup a Feature", new Option[]{ new Option(null, "Feature name", "Des", false)});
super("setup");
}
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
if(!event.getGuild().getMemberById(event.getUser().getIdLong()).hasPermission(Permission.ADMINISTRATOR)){
EmbeddedMessageHelper.sendSimpleOneLiner(event, "You do not have the Permission", "Sorry, but you don't have the Permission to run this command", null);
EmbeddedMessageHelper.sendSimpleOneLiner(event, "403: Forbidden", "You are not allowed to run this command.", null);
return;
}
if(event.getOption("feature").getAsString().equals("timefinder")){

View file

@ -0,0 +1,25 @@
package de.limited_dev.lil_judd.commands;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.features.MapManager;
import de.limited_dev.lil_judd.features.components.maps.MapData;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class TranslateCommand extends Command {
public TranslateCommand() {
super("translatemap");
}
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
String map = event.getOption("map").getAsString().toLowerCase();
MapData md = MapManager.getMapData(map);
if (md == null) {
EmbeddedMessageHelper.sendSimpleOneLiner(event, "404: Not found", "This Map does not exist.\nCheck for spelling mistakes", null);
return;
}
EmbeddedMessageHelper.sendSimpleOneLiner(event, "Map Translator", "ENG: " + md.getNameEN() + "" +
"\nDE: " + md.getNameDE(), md.getMapLink());
}
}

View file

@ -1,19 +1,13 @@
package de.limited_dev.lil_judd.commands.components;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Option;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
public class Command {
private final String name;
private final String description;
private final Option[] options;
public Command(String name, String description, Option[] options){
public Command(String name) {
this.name = name;
this.description = description;
this.options = options;
}
public void onSlashCommandInteraction(SlashCommandInteractionEvent event){
@ -27,20 +21,4 @@ public class Command {
public String getName() {
return name.toLowerCase();
}
public String getDescription() {
return description;
}
public Option[] getOptions() {
return options;
}
public boolean hasOptions(){
return options != null;
}
public int getAmountOfOptions(){
return options.length;
}
}

View file

@ -2,11 +2,12 @@ package de.limited_dev.lil_judd.commands.components;
import de.limited_dev.lil_judd.commands.*;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class CommandManager {
private static CopyOnWriteArrayList<Command> commands = new CopyOnWriteArrayList<>();
private static List<Command> commands = new CopyOnWriteArrayList<>();
public static void registerCommands(){
commands.add(new PingCommand());
@ -17,9 +18,10 @@ public class CommandManager {
commands.add(new EndScrimCommand());
commands.add(new MessageScrimCommand());
commands.add(new ScrimInfoCommand());
commands.add(new TranslateCommand());
}
public static CopyOnWriteArrayList<Command> getCommands() {
public static List<Command> getCommands() {
return commands;
}
}

View file

@ -1,34 +0,0 @@
package de.limited_dev.lil_judd.commands.components;
import net.dv8tion.jda.api.interactions.commands.OptionType;
public class Option {
private final OptionType type;
private final String name;
private final String description;
private final boolean optional;
public Option(OptionType type, String name, String description, boolean optional){
this.type = type;
this.name = name;
this.description = description;
this.optional = optional;
}
public OptionType getType() {
return type;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public boolean isOptional() {
return optional;
}
}

View file

@ -0,0 +1,35 @@
package de.limited_dev.lil_judd.features;
import de.limited_dev.lil_judd.features.components.maps.MapData;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class MapManager {
private static List<MapData> maps = new CopyOnWriteArrayList<>();
public static void registerMaps() {
maps.add(new MapData("Scorch Gorge", "Sengkluft", "https://cdn.wikimg.net/en/splatoonwiki/images/thumb/c/c2/S3_promo_screenshot_Scorch_Gorge_00.jpg/400px-S3_promo_screenshot_Scorch_Gorge_00.jpg"));
maps.add(new MapData("Eeltail Alley", "Streifenaal-Straße", "https://cdn.wikimg.net/en/splatoonwiki/images/thumb/8/84/S3_promo_screenshot_Eeltail_Alley_00.jpg/400px-S3_promo_screenshot_Eeltail_Alley_00.jpg"));
maps.add(new MapData("Hagglefish Market", "Schnapperchen-Basar", "https://cdn.wikimg.net/en/splatoonwiki/images/2/2e/S3HagglefishMarketIcon.webp"));
maps.add(new MapData("Undertow Spillway", "Schwertmuschel-Reservoir", "https://cdn.wikimg.net/en/splatoonwiki/images/f/f2/S3UndertowSpillwayIcon.webp"));
maps.add(new MapData("Mincemeat Metalworks", "Aalstahl-Metallwerk", "https://cdn.wikimg.net/en/splatoonwiki/images/a/a8/S3MincemeatMetalworksIcon.webp"));
maps.add(new MapData("Hammerhead Bridge", "Makrelenbrücke", "https://cdn.wikimg.net/en/splatoonwiki/images/2/24/S3HammerheadBridgeIcon.jpeg"));
maps.add(new MapData("Museum d'Alfonsino", "Pinakoithek", "https://cdn.wikimg.net/en/splatoonwiki/images/2/2c/S3_Stage_Museum_d%27Alfonsino_Promo_1.jpg"));
maps.add(new MapData("Mahi-Mahi Resort", "Mahi-Mahi Resort", "https://cdn.wikimg.net/en/splatoonwiki/images/b/b7/S3MahiMahiResortIcon.jpeg"));
maps.add(new MapData("Inkblot Art Academy", "Perlmutt-Akademie", "https://cdn.wikimg.net/en/splatoonwiki/images/9/9e/S3_Inkblot_Art_Academy.jpeg"));
maps.add(new MapData("Sturgeon Shipyard", "Störwerft", "https://cdn.wikimg.net/en/splatoonwiki/images/a/a5/S3_Sturgeon_Shipyard.jpg"));
maps.add(new MapData("MakoMart", "Cetacea-Markt", "https://cdn.wikimg.net/en/splatoonwiki/images/a/ac/S3_Mako_Mart.jpg"));
maps.add(new MapData("Wahoo World", "Flunder-Funpark", "https://cdn.wikimg.net/en/splatoonwiki/images/5/53/S3_Wahoo_World.jpg"));
}
public static MapData getMapData(String name) {
for (MapData md : maps) {
if (md.equalsDEName(name))
return md;
if (md.equalsENName(name))
return md;
}
return null;
}
}

View file

@ -0,0 +1,33 @@
package de.limited_dev.lil_judd.features.components.maps;
public class MapData {
private final String nameDE;
private final String nameEN;
private final String mapLink;
public MapData(String nameEN, String nameDE, String mapLink) {
this.nameEN = nameEN;
this.nameDE = nameDE;
this.mapLink = mapLink;
}
public boolean equalsDEName(String str) {
return this.nameDE.toLowerCase().equals(str);
}
public boolean equalsENName(String str) {
return this.nameEN.toLowerCase().equals(str);
}
public String getNameDE() {
return this.nameDE;
}
public String getNameEN() {
return this.nameEN;
}
public String getMapLink() {
return mapLink;
}
}

View file

@ -3,7 +3,6 @@ package de.limited_dev.lil_judd.listeners;
import de.limited_dev.lil_judd.Main;
import de.limited_dev.lil_judd.commands.components.Command;
import de.limited_dev.lil_judd.commands.components.CommandManager;
import de.limited_dev.lil_judd.util.EmbeddedMessageHelper;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

View file

@ -40,7 +40,7 @@ public class SlashCommandHelper {
Commands.slash("scriminfo", "Show info about the scrim system."),
Commands.slash("translatemap", "Translate a Map from German to English")
.addOptions(
new OptionData(OptionType.STRING, "map", "Message content", true)
new OptionData(OptionType.STRING, "map", "Map Name", true)
)