Skip to content

Commit

Permalink
Add more time internal placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
A5H73Y committed Aug 4, 2023
1 parent ac07ed6 commit 96c549c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build

env:
artifact_name: 'Parkour-7.2.0'
artifact_name: 'Parkour-7.2.1'
release_type: '-RELEASE'

on: push
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For the list of known supported plugins and tutorials on how to set them up, [cl
<dependency>
<groupId>com.github.A5H73Y</groupId>
<artifactId>Parkour</artifactId>
<version>7.2.0</version>
<version>7.2.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Expand All @@ -48,5 +48,5 @@ repositories {
```

```
compile 'com.github.A5H73Y:Parkour:7.2.0'
compile 'com.github.A5H73Y:Parkour:7.2.1'
```
8 changes: 8 additions & 0 deletions docs/changelogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Changelogs

Please note that each version of Parkour is backwards compatible with the previous version and will automatically upgrade your config upon server start up. There will be no manual intervention, unless stated in breaking changes.

## 7.2.1

* Added option to disable "OnCourse.ParkourKit.FloatingClosestBlock"
* Improvement to use centre of each block when calculating closest block
* Fixed various Challenge bugs
* Fix NPE with placeholders
* Update dependency versions

## 7.2.0

* Added ability to set a one-time fee for a course
Expand Down
6 changes: 5 additions & 1 deletion docs/tutorials/parkour-courses.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ _They **must** be uppercase._
* `%PLAYER_DISPLAY%` the Player's display name
* `%COURSE%` the Course's name
* `%DEATHS%` the amount of deaths accumulated
* `%TIME%` the amount of time accumulated
* `%CHECKPOINT%` the current checkpoint number
* `%TIME%` a formatted output of time accumulated
* `%TIME_MS%` the total amount of milliseconds accumulated
* `%TIME_S%` the total amount of seconds accumulated
* `%TIME_M%` the total amount of minutes accumulated
* `%TIME_H%` the total amount of hours accumulated

## Adding a Join Item

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.a5h73y</groupId>
<artifactId>Parkour</artifactId>
<version>7.2.0</version>
<version>7.2.1</version>
<packaging>jar</packaging>

<name>Parkour</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ public void onPlayerDisconnect(PlayerQuitEvent event) {

parkour.getPlayerManager().teardownParkourPlayer(player);

if (player.isBanned()
&& parkour.getParkourConfig().getBoolean("Other.OnPlayerBan.ResetParkourInfo")) {
if (parkour.getParkourConfig().getBoolean("Other.OnPlayerBan.ResetParkourInfo")
&& player.isBanned()) {
parkour.getPlayerManager().resetPlayer(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class ParkourConstants {

public static final String TIME_PLACEHOLDER = "%TIME%";

public static final String TIME_MS_PLACEHOLDER = "%TIME_MS%";

public static final String TIME_S_PLACEHOLDER = "%TIME_S%";

public static final String TIME_M_PLACEHOLDER = "%TIME_M%";

public static final String TIME_H_PLACEHOLDER = "%TIME_H%";

public static final String AMOUNT_PLACEHOLDER = "%AMOUNT%";

public static final String PARKOUR_RANK_PLACEHOLDER = "%RANK%";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ public long getCurrentTime() {
}

public String getDisplayTime() {
return DateTimeUtils.displayCurrentTime(hasFinished() ? getTimeFinished() : getCurrentTime());
return DateTimeUtils.displayCurrentTime(getAccumulatedTime());
}

public long getAccumulatedTime() {
return hasFinished() ? getTimeFinished() : getCurrentTime();
}

public void recalculateTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import static io.github.a5h73y.parkour.other.ParkourConstants.DEATHS_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.PLAYER_DISPLAY_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.PLAYER_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TIME_H_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TIME_MS_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TIME_M_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TIME_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TIME_S_PLACEHOLDER;
import static io.github.a5h73y.parkour.other.ParkourConstants.TOTAL_CHECKPOINT_PLACEHOLDER;
import static io.github.a5h73y.parkour.utility.StringUtils.colour;

Expand All @@ -16,6 +20,8 @@
import io.github.a5h73y.parkour.type.player.session.ParkourSession;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.github.a5h73y.parkour.utility.time.MillisecondConverter;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -392,11 +398,16 @@ public static void announceParkourMessage(Player player, String scope, String me
* @return updated input message
*/
public static String replaceAllParkourPlaceholders(String input, Player player, ParkourSession session) {
MillisecondConverter converter = new MillisecondConverter(session.getAccumulatedTime());
String result = input.replace(PLAYER_PLACEHOLDER, player.getName())
.replace(PLAYER_DISPLAY_PLACEHOLDER, player.getDisplayName())
.replace(COURSE_PLACEHOLDER, session.getCourse().getDisplayName())
.replace(DEATHS_PLACEHOLDER, String.valueOf(session.getDeaths()))
.replace(TIME_PLACEHOLDER, session.getDisplayTime())
.replace(TIME_MS_PLACEHOLDER, String.valueOf(session.getAccumulatedTime()))
.replace(TIME_S_PLACEHOLDER, String.valueOf(converter.getTotalSeconds()))
.replace(TIME_M_PLACEHOLDER, String.valueOf(converter.getTotalMinutes()))
.replace(TIME_H_PLACEHOLDER, String.valueOf(converter.getTotalHours()))
.replace(CHECKPOINT_PLACEHOLDER, String.valueOf(session.getCurrentCheckpoint()))
.replace(TOTAL_CHECKPOINT_PLACEHOLDER, String.valueOf(session.getCourse().getNumberOfCheckpoints()));
return Parkour.getInstance().getPlaceholderApi().parsePlaceholders(player, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected Set<K> getExpiredKeys() {
protected boolean isExpired(K key) {
boolean result = true;
if (this.cacheMap.containsKey(key)) {
LocalDateTime expirationDateTime = this.cacheMap.get(key).getCreatedAt().plus(this.cacheTimeout, ChronoUnit.SECONDS);
LocalDateTime expirationDateTime = this.cacheMap.get(key)
.getCreatedAt().plus(this.cacheTimeout, ChronoUnit.SECONDS);
result = LocalDateTime.now().isAfter(expirationDateTime);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public void setSeconds(long seconds) {
this.seconds = seconds;
}

public long getTotalSeconds() {
return seconds;
}

public long getMinutes() {
return minutes % 60;
}
Expand All @@ -49,6 +53,10 @@ public void setMinutes(long minutes) {
this.minutes = minutes;
}

public long getTotalMinutes() {
return minutes;
}

public long getHours() {
return hours % 24;
}
Expand All @@ -57,6 +65,10 @@ public void setHours(long hours) {
this.hours = hours;
}

public long getTotalHours() {
return hours;
}

public long getDays() {
return days;
}
Expand Down

0 comments on commit 96c549c

Please sign in to comment.