Skip to content

Commit

Permalink
chore: updated JDA library and ClashAPI versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lycoon committed Jan 17, 2024
1 parent 97c7c53 commit 4c82784
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 275 deletions.
25 changes: 6 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.lycoon</groupId>
<artifactId>clashbot</artifactId>
<version>1.4.3</version>
<version>2.0.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand All @@ -15,30 +15,17 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/Lycoon/clash-api</url>
</repository>

<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.3.0_277</version>
<version>5.0.0-beta.19</version>
</dependency>

<dependency>
<groupId>com.lycoon</groupId>
<artifactId>clashapi</artifactId>
<version>3.0.2</version>
<groupId>io.github.lycoon</groupId>
<artifactId>clash-api</artifactId>
<version>5.1.4</version>
</dependency>

<dependency>
Expand All @@ -62,7 +49,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.7</version>
<version>1.4.14</version>
</dependency>
</dependencies>

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/lycoon/clashbot/commands/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import static com.lycoon.clashbot.utils.CoreUtils.*;
import static com.lycoon.clashbot.utils.GameUtils.*;

import com.lycoon.clashapi.core.exceptions.ClashAPIException;
import com.lycoon.clashapi.models.player.Player;
import com.lycoon.clashapi.models.player.Troop;
import com.lycoon.clashapi.core.exception.ClashAPIException;
import com.lycoon.clashbot.core.CacheComponents;
import com.lycoon.clashbot.core.ClashBotMain;
import com.lycoon.clashbot.lang.LangUtils;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

import java.awt.*;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class PlayerCommand {
"Log Launcher", "Flame Flinger"};
private final static String[] PETS = {"L.A.S.S.I", "Electro Owl", "Mighty Yak", "Unicorn"};

public static void call(SlashCommandEvent event) {
public static void call(SlashCommandInteractionEvent event) {
CompletableFuture.runAsync(() -> {
if (event.getOptions().isEmpty())
execute(event);
Expand All @@ -61,7 +61,7 @@ public static void call(SlashCommandEvent event) {
}

public static void drawSuperTroop(Graphics2D g2d, Troop troop, String troopName, int x, int y) {
if (troop == null || !troop.isSuperTroopActive())
if (troop == null || !troop.getSuperTroopIsActive())
g2d.drawImage(getImageFromFile("troops/locked/" + troopName + ".png"), x, y, 44, 44, null);
else
g2d.drawImage(getImageFromFile("troops/" + troop.getName() + ".png"), x, y, 44, 44, null);
Expand Down Expand Up @@ -120,7 +120,7 @@ public static void drawPets(Graphics2D g2d, Font font, List<Troop> pets, int y)
drawTroop(g2d, font, getTroopByName(pets, PETS[i]), PETS[i], (i % COLUMNS) * 50 + 710, y + j * 50);
}

public static void execute(SlashCommandEvent event, String... args) {
public static void execute(SlashCommandInteractionEvent event, String... args) {
Locale lang = LangUtils.getLanguage(event.getMember().getIdLong());
ResourceBundle i18n = LangUtils.getTranslations(lang);
NumberFormat nf = NumberFormat.getInstance(lang);
Expand All @@ -140,7 +140,7 @@ public static void execute(SlashCommandEvent event, String... args) {

try {
player = ClashBotMain.clashAPI.getPlayer(tag);
} catch (ClashAPIException | IOException e) {
} catch (ClashAPIException e) {
sendExceptionError(event, i18n, e, tag, "player");
return;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public static void execute(SlashCommandEvent event, String... args) {
Rectangle clanNameRect = new Rectangle(775, 130, 148, 30);
Rectangle clanRoleRect = new Rectangle(775, 151, 148, 30);
drawCenteredString(g2d, clanNameRect, font.deriveFont(FONT_SIZE + 2f), player.getClan().getName());
drawCenteredString(g2d, clanRoleRect, font.deriveFont(FONT_SIZE - 2f), i18n.getString(player.getRole()));
drawCenteredString(g2d, clanRoleRect, font.deriveFont(FONT_SIZE - 2f), i18n.getString(String.valueOf(player.getRole())));
} else {
Rectangle noClanRect = new Rectangle(775, 130, 148, 30);
drawCenteredString(g2d, noClanRect, font.deriveFont(FONT_SIZE + 2f), i18n.getString("no.clan"));
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/com/lycoon/clashbot/commands/clan/ClanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
import static com.lycoon.clashbot.utils.DatabaseUtils.*;
import static com.lycoon.clashbot.utils.CoreUtils.*;

import com.lycoon.clashapi.core.exceptions.ClashAPIException;
import com.lycoon.clashapi.models.clan.ClanMember;
import com.lycoon.clashapi.models.clan.Clan;
import com.lycoon.clashapi.models.common.Label;
import com.lycoon.clashapi.core.exception.ClashAPIException;
import com.lycoon.clashapi.models.player.enums.Role;
import com.lycoon.clashbot.commands.Command;
import com.lycoon.clashbot.core.ClashBotMain;
import com.lycoon.clashbot.lang.LangUtils;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.CompletableFuture;

public class ClanCommand {
public class ClanCommand
{
private final static int WIDTH = 932;
private final static int HEIGHT = 322;
private final static float FONT_SIZE = 12f;
Expand Down Expand Up @@ -66,7 +67,8 @@ public class ClanCommand {
put("Clan Capital", "label.capital");
}};

public static void call(SlashCommandEvent event) {
public static void call(SlashCommandInteractionEvent event)
{
CompletableFuture.runAsync(() -> {
if (event.getOptions().isEmpty())
execute(event);
Expand All @@ -75,15 +77,16 @@ public static void call(SlashCommandEvent event) {
});
}

public static String getClanChief(List<ClanMember> members) {
public static String getClanChief(List<ClanMember> members)
{
for (ClanMember member : members)
if (member.getRole().equals("leader"))
if (member.getRole() == Role.LEADER)
return member.getName();

return "";
}

public static Clan getClan(SlashCommandEvent event, Locale lang, String[] args) {
public static Clan getClan(SlashCommandInteractionEvent event, Locale lang, String[] args)
{
// Checking rate limitation
if (!checkThrottle(event, lang))
return null;
Expand All @@ -100,15 +103,15 @@ public static Clan getClan(SlashCommandEvent event, Locale lang, String[] args)

try {
clan = ClashBotMain.clashAPI.getClan(tag);
} catch (IOException ignored) {
} catch (ClashAPIException e) {
sendExceptionError(event, i18n, e, tag, "clan");
return null;
}
return clan;
}

public static void execute(SlashCommandEvent event, String... args) {
public static void execute(SlashCommandInteractionEvent event, String... args)
{
Locale lang = LangUtils.getLanguage(event.getMember().getIdLong());
ResourceBundle i18n = LangUtils.getTranslations(lang);
NumberFormat nf = NumberFormat.getInstance(lang);
Expand Down Expand Up @@ -157,9 +160,9 @@ public static void execute(SlashCommandEvent event, String... args) {
drawShadowedStringLeft(g2d, i18n.getString("undefined"), 905, 33, 14f, 2);

// Invitation type
switch (clan.getType()) {
case "inviteOnly" -> drawShadowedStringLeft(g2d, i18n.getString("clan.type.inviteonly"), 905, 67, 12f, 2, clanTypeInviteOnlyColor);
case "open" -> drawShadowedStringLeft(g2d, i18n.getString("clan.type.open"), 905, 67, 12f, 2, clanTypeOpenColor);
switch (clan.getInviteType()) {
case INVITE_ONLY -> drawShadowedStringLeft(g2d, i18n.getString("clan.type.inviteonly"), 905, 67, 12f, 2, clanTypeInviteOnlyColor);
case OPEN -> drawShadowedStringLeft(g2d, i18n.getString("clan.type.open"), 905, 67, 12f, 2, clanTypeOpenColor);
default -> drawShadowedStringLeft(g2d, i18n.getString("clan.type.closed"), 905, 67, 12f, 2, clanTypeClosedColor);
}

Expand Down
Loading

0 comments on commit 4c82784

Please sign in to comment.