-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
753 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unix:///var/run/docker.sock |
95 changes: 95 additions & 0 deletions
95
src/main/java/fr/islandswars/commons/player/IslandsPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
src/main/java/fr/islandswars/commons/player/IslandsRank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/fr/islandswars/commons/player/sanction/IslandsSanction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/fr/islandswars/commons/player/sanction/SanctionReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.