Skip to content

Commit

Permalink
Merge branch 'release/v0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Xharos committed Jul 7, 2024
2 parents 592cba8 + eae1dce commit 9a04be0
Show file tree
Hide file tree
Showing 24 changed files with 753 additions and 106 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "fr.islandswars"
version = "0.3.1"
version = "0.3.2"

repositories {
mavenCentral()
Expand All @@ -15,6 +15,8 @@ dependencies {
implementation("org.mongodb:mongodb-driver-reactivestreams:5.0.0")
implementation("io.lettuce:lettuce-core:6.3.2.RELEASE")
implementation("com.rabbitmq:amqp-client:5.21.0")
implementation("com.github.docker-java:docker-java-core:3.3.6")
implementation("com.github.docker-java:docker-java-transport-httpclient5:3.3.6")
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
Expand Down
3 changes: 3 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ services:
- mongodb_username
- mongodb_host
- mongodb_port
- docker_host
depends_on:
mongo:
condition: service_healthy
Expand Down Expand Up @@ -126,3 +127,5 @@ secrets:
file: secrets/mongodb_host
mongodb_port:
file: secrets/mongodb_port
docker_host:
file: secrets/docker_host
1 change: 1 addition & 0 deletions secrets/docker_host
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unix:///var/run/docker.sock
95 changes: 95 additions & 0 deletions src/main/java/fr/islandswars/commons/player/IslandsPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package fr.islandswars.commons.player;

import com.google.gson.annotations.SerializedName;
import fr.islandswars.commons.player.sanction.IslandsSanction;
import fr.islandswars.commons.utils.TimeUtils;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
* File <b>IslandsPlayer</b> located on fr.islandswars.commons.player
* IslandsPlayer is a part of commons.
* <p>
* Copyright (c) 2017 - 2024 Islands Wars.
* <p>
* commons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <a href="http://www.gnu.org/licenses/">GNU license</a>.
* <p>
*
* @author Jangliu, {@literal <[email protected]>}
* Created the 23/06/2024 at 16:32
* @since 0.3.1
*/
public abstract class IslandsPlayer {

protected UUID uuid;
protected List<Rank> ranks;
@SerializedName("first_connection")
protected String firstConnection;
@SerializedName("last_connection")
protected String lastConnection;
protected List<IslandsSanction> sanctions;

public IslandsPlayer() {
this.ranks = new ArrayList<>();
this.sanctions = new ArrayList<>();
}

public void firstConnection(UUID uuid, String PROXY) {
setUUID(uuid);
this.firstConnection = TimeUtils.NOW();
this.lastConnection = firstConnection;
addRank(new Rank(IslandsRank.PLAYER, PROXY, TimeUtils.NOW()));
}

public void welcomeBack() {
setLastConnection();
}

public IslandsRank getMainRank() {
return IslandsRank.getHighest(ranks);
}

public UUID getUUID() {
return uuid;
}

public void setUUID(UUID uuid) {
this.uuid = uuid;
}

public void setLastConnection() {
this.lastConnection = TimeUtils.NOW();
}

public void addRank(Rank rank) {
if (ranks.stream().noneMatch(r -> r.getRank().equals(rank.getRank())))
ranks.add(rank);
//TODO notify the player and update it !!
}

public Optional<IslandsSanction> isKick() {
for (IslandsSanction sanction : sanctions) {
var endDate = Instant.parse(sanction.getEnd());
var now = Instant.now();
if (endDate.isAfter(now))
return Optional.of(sanction);
}
return Optional.empty();
}
}

60 changes: 60 additions & 0 deletions src/main/java/fr/islandswars/commons/player/IslandsRank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package fr.islandswars.commons.player;

import java.util.List;

/**
* File <b>IslandsRank</b> located on fr.islandswars.commons.player
* IslandsRank is a part of commons.
* <p>
* Copyright (c) 2017 - 2024 Islands Wars.
* <p>
* commons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <a href="http://www.gnu.org/licenses/">GNU license</a>.
* <p>
*
* @author Jangliu, {@literal <[email protected]>}
* Created the 24/06/2024 at 16:07
* @since 0.3.1
*/
public enum IslandsRank {

ADMIN(1),
STAFF(2),
PLAYER(5);

private final int rankLevel;

IslandsRank(int rankLevel) {
this.rankLevel = rankLevel;
}

public static IslandsRank getHighest(List<Rank> ranks) {
var highestRank = PLAYER;

for (var rank : ranks) {
var currentRank = rank.getRank();
if (currentRank.getRankLevel() < highestRank.getRankLevel()) {
highestRank = currentRank;
}
}
return highestRank;
}

public boolean isStaff() {
return getRankLevel() <= IslandsRank.STAFF.getRankLevel();
}

public int getRankLevel() {
return rankLevel;
}
}
54 changes: 54 additions & 0 deletions src/main/java/fr/islandswars/commons/player/Rank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.islandswars.commons.player;

import fr.islandswars.commons.utils.TimeUtils;

import java.time.Instant;

/**
* File <b>Ranks</b> located on fr.islandswars.commons.player
* Ranks is a part of commons.
* <p>
* Copyright (c) 2017 - 2024 Islands Wars.
* <p>
* commons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <a href="http://www.gnu.org/licenses/">GNU license</a>.
* <p>
*
* @author Jangliu, {@literal <[email protected]>}
* Created the 25/06/2024 at 22:19
* @since 0.3.1
*/
public class Rank {

private String rank;
private String author;
private String date;

public Rank(IslandsRank rank, String givenBy, String date) {
this.rank = rank.name();
this.author = givenBy;
this.date = date;
}

public Instant getDate() {
return TimeUtils.FROM_ISO_STRING(date);
}

public String getAuthor() {
return author;
}

public IslandsRank getRank() {
return IslandsRank.valueOf(rank);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package fr.islandswars.commons.player.sanction;

import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.UUID;

/**
* File <b>IslandsSanction</b> located on fr.islandswars.commons.player.sanction
* IslandsSanction is a part of commons.
* <p>
* Copyright (c) 2017 - 2024 Islands Wars.
* <p>
* commons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <a href="http://www.gnu.org/licenses/">GNU license</a>.
* <p>
*
* @author Jangliu, {@literal <[email protected]>}
* Created the 24/06/2024 at 22:37
* @since 0.3.1
*/
public class IslandsSanction {

private SanctionReason reason;
private String start;
private String end;
private UUID author;
private String authorName;

public IslandsSanction(SanctionReason reason, UUID author, String authorName) {
this.reason = reason;
this.author = author;
this.authorName = authorName;
var now = Instant.now();
this.start = DateTimeFormatter.ISO_INSTANT.format(now);
this.end = DateTimeFormatter.ISO_INSTANT.format(now.plus(reason.getDays(), ChronoUnit.DAYS));
}

public String getEnd() {
return end;
}

public SanctionReason getReason() {
return reason;
}

public UUID getAuthor() {
return author;
}

public String getAuthorName() {
return authorName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fr.islandswars.commons.player.sanction;

/**
* File <b>SanctionReason</b> located on fr.islandswars.commons.player.sanction
* SanctionReason is a part of commons.
* <p>
* Copyright (c) 2017 - 2024 Islands Wars.
* <p>
* commons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <a href="http://www.gnu.org/licenses/">GNU license</a>.
* <p>
*
* @author Jangliu, {@literal <[email protected]>}
* Created the 24/06/2024 at 22:37
* @since 0.3.1
*/
public enum SanctionReason {

CHEAT("sanction.cheat", 7),
BEHAVIOR("sanction.behavior", 365);

private final String kickKey;
private final int days;

SanctionReason(String kickKey, int days) {
this.kickKey = kickKey;
this.days = days;
}

public int getDays() {
return days;
}

public String getKickKey() {
return kickKey;
}
}
Loading

0 comments on commit 9a04be0

Please sign in to comment.