diff --git a/src/main/java/io/github/a5h73y/parkour/listener/PlayerInteractListener.java b/src/main/java/io/github/a5h73y/parkour/listener/PlayerInteractListener.java index 795487fe..949ae82b 100644 --- a/src/main/java/io/github/a5h73y/parkour/listener/PlayerInteractListener.java +++ b/src/main/java/io/github/a5h73y/parkour/listener/PlayerInteractListener.java @@ -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); diff --git a/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java b/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java index e2e356d1..5f74107f 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java +++ b/src/main/java/io/github/a5h73y/parkour/type/course/CourseConfig.java @@ -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}. diff --git a/src/main/java/io/github/a5h73y/parkour/type/player/PlayerConfig.java b/src/main/java/io/github/a5h73y/parkour/type/player/PlayerConfig.java index 5bcfefad..ef4bfe76 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/player/PlayerConfig.java +++ b/src/main/java/io/github/a5h73y/parkour/type/player/PlayerConfig.java @@ -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"; @@ -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) { diff --git a/src/main/java/io/github/a5h73y/parkour/type/player/PlayerManager.java b/src/main/java/io/github/a5h73y/parkour/type/player/PlayerManager.java index f716aaee..36829d54 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/player/PlayerManager.java +++ b/src/main/java/io/github/a5h73y/parkour/type/player/PlayerManager.java @@ -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); @@ -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);