From 4abbb8b0aaeca2e8ab8edc8f0098e49b47b9aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melaine=20G=C3=A9rard?= Date: Sun, 24 Nov 2024 17:38:33 +0100 Subject: [PATCH] :sparkles: Ajout pourcentages de stats pour chaque rang --- build.gradle.kts | 1 + .../listeners/GuildMemberJoinListener.java | 2 +- .../listeners/GuildMemberLeaveListener.java | 2 +- .../gachamelia/listeners/ReadyListener.java | 2 +- .../listeners/SlashCommandListener.java | 2 +- .../studio/gachamelia/models/Rank.java | 9 +++ .../studio/gachamelia/models/RankStat.java | 73 +++++++++++++++++++ .../studio/gachamelia/models/RankStatId.java | 53 ++++++++++++++ .../studio/gachamelia/models/Stat.java | 11 +++ 9 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/camelia/studio/gachamelia/models/RankStat.java create mode 100644 src/main/java/org/camelia/studio/gachamelia/models/RankStatId.java diff --git a/build.gradle.kts b/build.gradle.kts index cef5754..15de996 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,6 +31,7 @@ dependencies { implementation("io.github.cdimascio:dotenv-kotlin:6.4.2") implementation("net.dv8tion:JDA:5.2.1") implementation("ch.qos.logback:logback-classic:1.5.12") + implementation("jakarta.annotation:jakarta.annotation-api:3.0.0") } diff --git a/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberJoinListener.java b/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberJoinListener.java index 993d29c..403e8c3 100644 --- a/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberJoinListener.java +++ b/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberJoinListener.java @@ -12,7 +12,7 @@ import org.camelia.studio.gachamelia.services.RankService; import org.camelia.studio.gachamelia.services.UserService; import org.camelia.studio.gachamelia.utils.Configuration; import java.awt.*; -import javax.annotation.Nonnull; +import jakarta.annotation.Nonnull; public class GuildMemberJoinListener extends ListenerAdapter { diff --git a/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberLeaveListener.java b/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberLeaveListener.java index 47ec393..d93c39e 100644 --- a/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberLeaveListener.java +++ b/src/main/java/org/camelia/studio/gachamelia/listeners/GuildMemberLeaveListener.java @@ -1,5 +1,6 @@ package org.camelia.studio.gachamelia.listeners; +import jakarta.annotation.Nonnull; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; @@ -12,7 +13,6 @@ import org.camelia.studio.gachamelia.services.UserService; import org.camelia.studio.gachamelia.utils.Configuration; import java.awt.*; import java.time.Instant; -import javax.annotation.Nonnull; public class GuildMemberLeaveListener extends ListenerAdapter { diff --git a/src/main/java/org/camelia/studio/gachamelia/listeners/ReadyListener.java b/src/main/java/org/camelia/studio/gachamelia/listeners/ReadyListener.java index 77863bf..3aaec57 100644 --- a/src/main/java/org/camelia/studio/gachamelia/listeners/ReadyListener.java +++ b/src/main/java/org/camelia/studio/gachamelia/listeners/ReadyListener.java @@ -5,7 +5,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.session.ReadyEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import javax.annotation.Nonnull; +import jakarta.annotation.Nonnull; import org.camelia.studio.gachamelia.models.User; import org.camelia.studio.gachamelia.repossitories.RankRepository; import org.camelia.studio.gachamelia.services.RankService; diff --git a/src/main/java/org/camelia/studio/gachamelia/listeners/SlashCommandListener.java b/src/main/java/org/camelia/studio/gachamelia/listeners/SlashCommandListener.java index 620a22d..3076191 100644 --- a/src/main/java/org/camelia/studio/gachamelia/listeners/SlashCommandListener.java +++ b/src/main/java/org/camelia/studio/gachamelia/listeners/SlashCommandListener.java @@ -2,7 +2,7 @@ package org.camelia.studio.gachamelia.listeners; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import javax.annotation.Nonnull; +import jakarta.annotation.Nonnull; import org.camelia.studio.gachamelia.managers.CommandManager; public class SlashCommandListener extends ListenerAdapter { diff --git a/src/main/java/org/camelia/studio/gachamelia/models/Rank.java b/src/main/java/org/camelia/studio/gachamelia/models/Rank.java index c6284ed..8137602 100644 --- a/src/main/java/org/camelia/studio/gachamelia/models/Rank.java +++ b/src/main/java/org/camelia/studio/gachamelia/models/Rank.java @@ -6,6 +6,7 @@ import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; @Entity @@ -44,6 +45,14 @@ public class Rank implements IEntity { @Column(name = "byeTitle") private String byeTitle; + @OneToMany(mappedBy = "id.rank", fetch = FetchType.LAZY) + private final List rankStats = new ArrayList<>(); + + public List getRankStats() { + return rankStats; + } + + public Rank(String discordId, String name, int percentage) { this.discordId = discordId; diff --git a/src/main/java/org/camelia/studio/gachamelia/models/RankStat.java b/src/main/java/org/camelia/studio/gachamelia/models/RankStat.java new file mode 100644 index 0000000..c8805cf --- /dev/null +++ b/src/main/java/org/camelia/studio/gachamelia/models/RankStat.java @@ -0,0 +1,73 @@ +package org.camelia.studio.gachamelia.models; + +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import org.camelia.studio.gachamelia.interfaces.IEntity; + +import java.util.Objects; + +@Entity +@Table(name = "rank_stats") +public class RankStat implements IEntity { + @EmbeddedId + private RankStatId id; + + @Column(nullable = false) + private int percentage; + + public RankStat() { + } + + public RankStat(Rank rank, Stat stat, int percentage) { + this.id = new RankStatId(rank, stat); + this.percentage = percentage; + } + + public RankStatId getId() { + return id; + } + + public Rank getRank() { + return id.getRank(); + } + + public Stat getStat() { + return id.getStat(); + } + + public int getPercentage() { + return percentage; + } + + public void setPercentage(int percentage) { + this.percentage = percentage; + } + + public void setRank(Rank rank) { + if (this.id == null) { + this.id = new RankStatId(); + } + this.id.setRank(rank); + } + + public void setStat(Stat stat) { + if (this.id == null) { + this.id = new RankStatId(); + } + this.id.setStat(stat); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RankStat rankStat)) return false; + return Objects.equals(id, rankStat.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/src/main/java/org/camelia/studio/gachamelia/models/RankStatId.java b/src/main/java/org/camelia/studio/gachamelia/models/RankStatId.java new file mode 100644 index 0000000..d244d5d --- /dev/null +++ b/src/main/java/org/camelia/studio/gachamelia/models/RankStatId.java @@ -0,0 +1,53 @@ +package org.camelia.studio.gachamelia.models; + +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; + +import java.io.Serializable; +import java.util.Objects; + +public class RankStatId implements Serializable { + @ManyToOne + @JoinColumn(name = "rank_id", nullable = false) + private Rank rank; + + @ManyToOne + @JoinColumn(name = "stat_id", nullable = false) + private Stat stat; + + public RankStatId() { + } + + public RankStatId(Rank rank, Stat stat) { + this.rank = rank; + this.stat = stat; + } + + public Rank getRank() { + return rank; + } + + public Stat getStat() { + return stat; + } + + public void setRank(Rank rank) { + this.rank = rank; + } + + public void setStat(Stat stat) { + this.stat = stat; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RankStatId that)) return false; + return rank.equals(that.rank) && stat.equals(that.stat); + } + + @Override + public int hashCode() { + return Objects.hash(rank, stat); + } +} diff --git a/src/main/java/org/camelia/studio/gachamelia/models/Stat.java b/src/main/java/org/camelia/studio/gachamelia/models/Stat.java index 9bcbdd6..c6e06ba 100644 --- a/src/main/java/org/camelia/studio/gachamelia/models/Stat.java +++ b/src/main/java/org/camelia/studio/gachamelia/models/Stat.java @@ -3,6 +3,9 @@ package org.camelia.studio.gachamelia.models; import jakarta.persistence.*; import org.camelia.studio.gachamelia.interfaces.IEntity; +import java.util.ArrayList; +import java.util.List; + @Entity @Table(name = "stats") public class Stat implements IEntity { @@ -13,6 +16,13 @@ public class Stat implements IEntity { @Column(nullable = false) private String name; + @OneToMany(mappedBy = "id.stat", fetch = FetchType.LAZY) + private final List rankStats = new ArrayList<>(); + + public List getRankStats() { + return rankStats; + } + public Long getId() { return id; } @@ -31,4 +41,5 @@ public class Stat implements IEntity { public Stat(String name) { this.name = name; } + }