Ajout pourcentages de stats pour chaque rang

This commit is contained in:
Melaine Gérard 2024-11-24 17:38:33 +01:00
parent 4649f3d8f4
commit 4abbb8b0aa
9 changed files with 151 additions and 4 deletions

View File

@ -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")
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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<RankStat> rankStats = new ArrayList<>();
public List<RankStat> getRankStats() {
return rankStats;
}
public Rank(String discordId, String name, int percentage) {
this.discordId = discordId;

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<RankStat> rankStats = new ArrayList<>();
public List<RankStat> getRankStats() {
return rankStats;
}
public Long getId() {
return id;
}
@ -31,4 +41,5 @@ public class Stat implements IEntity {
public Stat(String name) {
this.name = name;
}
}