Skip to content

Commit

Permalink
Add the ability for max manual checkpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
A5H73Y committed Jan 6, 2024
1 parent 2780063 commit e90f2f5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void handleFreedomTool(Player player, Boolean rightClick) {
private void handleRocketTool(Player player) {
ParkourSession session = parkour.getParkourSessionManager().getParkourSession(player);
CourseConfig courseConfig = parkour.getConfigManager().getCourseConfig(session.getCourseName());
Integer maximumRockets = courseConfig.get("MaximumRockets", null);
Integer maximumRockets = courseConfig.getMaximumRockets();

if (maximumRockets != null) {
PlayerConfig config = parkour.getConfigManager().getPlayerConfig(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,14 @@ public boolean toggleManualCheckpoints() {
return getManualCheckpoints();
}

public Integer getMaximumRockets() {
return get("MaximumRockets", null);
}

public Integer getMaximumManualCheckpoints() {
return get("MaximumManualCheckpoints", null);
}

/**
* Get the Event Message for this Course.
* Possible events found within {@link ParkourEventType}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PlayerConfig extends Json {
public static final String PARKOINS = "Parkoins";
public static final String EXISTING_SESSION_COURSE_NAME = "ExistingSessionCourseName";
public static final String ROCKETS_USED = "RocketsUsed";
public static final String MANUAL_CHECKPOINTS_USED = "ManualCheckpointsUsed";
public static final String TOTAL_DEATHS = "TotalDeaths";
public static final String TOTAL_TIME = "TotalTime";

Expand Down Expand Up @@ -390,7 +391,15 @@ public int getRocketsUsedInSession() {
}

public void increaseRocketsUsedInSession() {
this.set(SESSION_PREFIX + ROCKETS_USED, this.getInt(SESSION_PREFIX + ROCKETS_USED) + 1);
this.set(SESSION_PREFIX + ROCKETS_USED, getRocketsUsedInSession() + 1);
}

public int getManualCheckpointsUsedInSession() {
return this.getInt(SESSION_PREFIX + MANUAL_CHECKPOINTS_USED);
}

public void increaseManualCheckpointsUsedInSession() {
this.set(SESSION_PREFIX + MANUAL_CHECKPOINTS_USED, getManualCheckpointsUsedInSession() + 1);
}

public void recordStatistics(ParkourSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ public void fastRestartCourse(Player player) {
if (session != null) {
session.resetProgress();
session.setFreedomLocation(null);
parkour.getConfigManager().getPlayerConfig(player).resetSessionData();
preparePlayerForCourse(player, session.getCourse().getName());
PlayerUtils.teleportToLocation(player, session.getCheckpoint().getLocation());
parkour.getScoreboardManager().addScoreboard(player, session);
Expand Down Expand Up @@ -1203,12 +1204,28 @@ public void setManualCheckpoint(Player player, @Nullable Location location) {
return;
}

Integer maxManualCheckpoints = parkour.getConfigManager()
.getCourseConfig(session.getCourseName()).getMaximumManualCheckpoints();

if (maxManualCheckpoints != null) {
PlayerConfig config = parkour.getConfigManager().getPlayerConfig(player);
int checkpointsUsed = config.getManualCheckpointsUsedInSession();

if (checkpointsUsed >= maxManualCheckpoints) {
TranslationUtils.sendMessage(player, "You have run out of Checkpoints!");
return;
}

config.increaseManualCheckpointsUsedInSession();
}

if (parkour.getParkourConfig().isTreatFirstCheckpointAsStart() && session.getFreedomLocation() == null) {
session.resetTime();
session.setStartTimer(true);
parkour.getBountifulApi().sendActionBar(player,
TranslationUtils.getTranslation("Parkour.TimerStarted", false));
}

session.setFreedomLocation(location != null ? location : player.getLocation());
parkour.getSoundsManager().playSound(player, SoundType.CHECKPOINT_ACHIEVED);

Expand Down

0 comments on commit e90f2f5

Please sign in to comment.