diff --git a/README.md b/README.md index 212b095..a31d3de 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,10 @@ Advanced infinitely generating parkour plugin with ghost system, leaderboards and multiple game modes. -> **BETA:** version 1.4.0 is a beta release. Generation, balance and game modes may still change. -> Parkour runs only in its own configured world (`world.name`, default `loparkour`); elytra is disabled there. - ![Java](https://img.shields.io/badge/Java-21+-orange?style=flat-square&logo=openjdk&logoColor=white) ![Paper](https://img.shields.io/badge/Paper-1.19.2+-blue?style=flat-square) ![License](https://img.shields.io/badge/license-GPLv3-blue?style=flat-square&logo=gnu&logoColor=white) ![version](https://img.shields.io/badge/version-1.4.0-green?style=flat-square) -![status](https://img.shields.io/badge/status-beta-orange?style=flat-square) [English](#english) | [Русский](#russian) @@ -32,7 +28,7 @@ LoParkour is an advanced parkour plugin with infinite world generation. The cour | Feature | Description | |---------|-------------| | Infinite generation | Parkour generates endlessly as you play | -| Multiple game modes | Default, Speedrun, Gravity Shift, Race, Coop, Duels | +| Multiple game modes | Default, Speedrun, Gravity Shift, Elytra | | Ghost system | Race against top player recordings | | Custom schematics | Create and use your own parkour structures (.lpschem) | | Visual themes | Customize block styles and particle effects | @@ -50,9 +46,7 @@ LoParkour is an advanced parkour plugin with infinite world generation. The cour | Default | Classic infinite parkour | | Speedrun | Blocks disappear after a few seconds | | Gravity Shift | Random gravity effects (levitation, slow falling, jump boost) | -| Race | First to the target score wins | -| Coop | Shared session and score with friends | -| Duels | One course per player, race to the goal | +| Elytra | Fly through particle rings | ### Commands @@ -88,15 +82,12 @@ LoParkour is an advanced parkour plugin with infinite world generation. The cour LoParkour - продвинутый паркур-плагин с бесконечной генерацией мира. Трасса генерируется по мере игры, с несколькими режимами, системой призраков, кастомными схематиками, визуальными темами и MySQL лидербордами. -> **BETA:** версия 1.4.0 — бета. Генерация, баланс и режимы ещё могут меняться. -> Паркур работает только в отдельном настроенном мире (`world.name`, по умолчанию `loparkour`); элитры в нём отключены. - ### Возможности | Возможность | Описание | |-------------|----------| | Бесконечная генерация | Паркур генерируется по мере игры | -| Несколько режимов | Default, Speedrun, Gravity Shift, Race, Coop, Duels | +| Несколько режимов | Default, Speedrun, Gravity Shift, Elytra | | Система призраков | Гонка против записей топ-игроков | | Кастомные схематики | Создавайте свои структуры (.lpschem) | | Визуальные темы | Настройка стилей блоков и частиц | diff --git a/build.gradle.kts b/build.gradle.kts index 30e4499..f7f0465 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -209,9 +209,7 @@ dependencies { compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("me.filoghost.holographicdisplays:holographicdisplays-api:3.0.0-SNAPSHOT") - // Only the API surface is needed; its transitive Geyser snapshot - // (org.geysermc:common:1.4.3-SNAPSHOT) was purged from every public repo. - compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT") { isTransitive = false } + compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT") // Error Prone + NullAway (compile-time bug/null-safety checks) errorprone("com.google.errorprone:error_prone_core:2.41.0") @@ -247,7 +245,7 @@ tasks.named("build") { } tasks.withType { - filesMatching(listOf("plugin.yml", "folia-plugin.yml", "config.yml")) { + filesMatching(listOf("plugin.yml", "config.yml")) { expand( "version" to project.version, "description" to (project.description ?: ""), diff --git a/src/main/java/dev/loki/loparkour/bootstrap/PluginBootstrap.java b/src/main/java/dev/loki/loparkour/bootstrap/PluginBootstrap.java index b36a7d2..90ecada 100644 --- a/src/main/java/dev/loki/loparkour/bootstrap/PluginBootstrap.java +++ b/src/main/java/dev/loki/loparkour/bootstrap/PluginBootstrap.java @@ -11,10 +11,15 @@ import dev.loki.loparkour.duels.DuelsMode; import dev.loki.loparkour.ghost.service.GhostService; import dev.loki.loparkour.hook.holo.HoloHook; import dev.loki.loparkour.hook.papi.PAPIHook; -import dev.loki.loparkour.listener.gameplay.ElytraRestrictionListener; import dev.loki.loparkour.listener.gameplay.ParkourRestrictionListener; import dev.loki.loparkour.listener.schematic.SchematicWandListener; import dev.loki.loparkour.listener.player.PlayerConnectionListener; +import dev.loki.loparkour.elytra.close.CloseMode; +import dev.loki.loparkour.elytra.core.ElytraMode; +import dev.loki.loparkour.elytra.minspeed.MinSpeedMode; +import dev.loki.loparkour.elytra.obstacle.ObstacleMode; +import dev.loki.loparkour.elytra.speeddemon.SpeedDemonMode; +import dev.loki.loparkour.elytra.timetrial.TimeTrialMode; import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.mode.impl.barrier.InvisibleBarrierMode; import dev.loki.loparkour.mode.impl.multi.CoopMode; @@ -82,6 +87,12 @@ public final class PluginBootstrap { Registry.register(new InvisibleBarrierMode()); Registry.register(new CoopMode()); Registry.register(new GravityShiftMode()); + Registry.register(new ElytraMode()); + Registry.register(new SpeedDemonMode()); + Registry.register(new MinSpeedMode()); + Registry.register(new TimeTrialMode()); + Registry.register(new CloseMode()); + Registry.register(new ObstacleMode()); Registry.register(new DuelsMode()); Modes.init(); } @@ -123,7 +134,6 @@ public final class PluginBootstrap { final var pm = plugin.getServer().getPluginManager(); pm.registerEvents(new PlayerConnectionListener(), plugin); pm.registerEvents(new ParkourRestrictionListener(), plugin); - pm.registerEvents(new ElytraRestrictionListener(), plugin); pm.registerEvents(new SchematicWandListener(), plugin); final LoParkourCommand cmd = new LoParkourCommand(); plugin.getCommand("LoParkour").setExecutor(cmd); diff --git a/src/main/java/dev/loki/loparkour/command/player/JoinCommandExecutor.java b/src/main/java/dev/loki/loparkour/command/player/JoinCommandExecutor.java index 13b271a..2745e69 100644 --- a/src/main/java/dev/loki/loparkour/command/player/JoinCommandExecutor.java +++ b/src/main/java/dev/loki/loparkour/command/player/JoinCommandExecutor.java @@ -6,7 +6,6 @@ import dev.loki.loparkour.command.util.CommandUtil; import dev.loki.loparkour.config.locale.Locales; import dev.loki.loparkour.menu.core.screen.ParkourOption; import dev.loki.loparkour.mode.base.Mode; -import dev.loki.loparkour.mode.base.ModeMessages; import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.mode.base.MultiMode; import dev.loki.loparkour.player.core.ParkourPlayer; @@ -25,16 +24,12 @@ public class JoinCommandExecutor { if (!player.cooldown(sender, "join", COOLDOWN_MS) || !ParkourOption.JOIN.mayPerform(p)) { return; } - final boolean alreadyPlaying = ParkourUser.getUser(p) != null; final Mode mode = Registry.getMode(arg); if (mode != null) { mode.create(p); } else { joinPlayingPlayer(arg, sender, p); } - if (!alreadyPlaying && ParkourUser.getUser(p) != null) { - ModeMessages.sendBetaWelcome(p); - } } private void joinPlayingPlayer(String arg, CommandSender sender, Player p) { diff --git a/src/main/java/dev/loki/loparkour/command/player/PlayerCommandHandler.java b/src/main/java/dev/loki/loparkour/command/player/PlayerCommandHandler.java index 993293f..367e708 100644 --- a/src/main/java/dev/loki/loparkour/command/player/PlayerCommandHandler.java +++ b/src/main/java/dev/loki/loparkour/command/player/PlayerCommandHandler.java @@ -6,7 +6,6 @@ import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.config.locale.Locales; import dev.loki.loparkour.menu.core.Menus; import dev.loki.loparkour.menu.core.screen.ParkourOption; -import dev.loki.loparkour.mode.base.ModeMessages; import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.player.core.ParkourUser; import dev.loki.loparkour.util.text.ColorUtil; @@ -98,9 +97,6 @@ public class PlayerCommandHandler { send(sender, Locales.getString(player, "other.no_do")); } else if (ParkourUser.getUser(player) == null) { Modes.defaultMode().create(player); - if (ParkourUser.getUser(player) != null) { - ModeMessages.sendBetaWelcome(player); - } } } diff --git a/src/main/java/dev/loki/loparkour/config/options/section/OptionGeneration.java b/src/main/java/dev/loki/loparkour/config/options/section/OptionGeneration.java index cf58b09..7747380 100644 --- a/src/main/java/dev/loki/loparkour/config/options/section/OptionGeneration.java +++ b/src/main/java/dev/loki/loparkour/config/options/section/OptionGeneration.java @@ -2,18 +2,15 @@ package dev.loki.loparkour.config.options.section; import dev.loki.loparkour.LoParkour; import dev.loki.loparkour.config.core.Config; -import org.jetbrains.annotations.NotNull; /** - * Generation-related configuration options (bounds, memory, jump validation, - * course spacing). + * Generation-related configuration options (bounds, memory, jump validation). * *

Block-type weights are not read here — they live in * {@code GeneratorProfileManager} / {@code GenerationProfileLoader}, which resolve * the {@code advanced.*} paths (see TODO: {@code generation.type|normal|special} * in generation.yml is currently ignored).

*/ -@SuppressWarnings("PMD.TooManyMethods") // flat, static config accessors grouped by section public final class OptionGeneration { private static final double DEFAULT_MAX_JUMP_DISTANCE = 5.0; @@ -25,12 +22,6 @@ public final class OptionGeneration { private static final int DEFAULT_TRAIL_KEEP_BEHIND = 10; private static final int DEFAULT_MIN_Y = 100; private static final int DEFAULT_MAX_Y = 200; - private static final int DEFAULT_COURSE_MIN_GAP = 2; - private static final int DEFAULT_COURSE_START_MAX_GAP = 3; - private static final int DEFAULT_COURSE_MAX_GAP = 4; - private static final int DEFAULT_COURSE_START_JUMPS = 5; - private static final int VANILLA_MAX_GAP = 4; - private static final int MAX_COURSE_START_JUMPS = 1000; private OptionGeneration() { } @@ -51,17 +42,10 @@ public final class OptionGeneration { private static double maxVerticalUp; private static double maxVerticalDown; - // ── Course spacing (gap bounds between consecutive blocks) ───────────────── - private static int courseMinGap; - private static int courseStartMaxGap; - private static int courseMaxGap; - private static int courseStartJumps; - public static void init() { initBounds(); initJumpValidation(); initMemory(); - initCourseSpacing(); } private static void initBounds() { @@ -98,35 +82,6 @@ public final class OptionGeneration { ? Config.CONFIG.getInt("memory.trail-keep-behind") : DEFAULT_TRAIL_KEEP_BEHIND; } - private static void initCourseSpacing() { - courseMinGap = readClampedGap("course-spacing.min-gap", DEFAULT_COURSE_MIN_GAP); - courseStartMaxGap = readClampedGap("course-spacing.start-max-gap", DEFAULT_COURSE_START_MAX_GAP); - courseMaxGap = readClampedGap("course-spacing.max-gap", DEFAULT_COURSE_MAX_GAP); - courseStartJumps = Config.CONFIG.isPath("course-spacing.start-jumps") - ? Math.max(0, Math.min(Config.CONFIG.getInt("course-spacing.start-jumps"), MAX_COURSE_START_JUMPS)) - : DEFAULT_COURSE_START_JUMPS; - - // Keep the bounds ordered: min <= startMax <= max. - courseStartMaxGap = Math.max(courseMinGap, courseStartMaxGap); - courseMaxGap = Math.max(courseStartMaxGap, courseMaxGap); - - if (courseMinGap > VANILLA_MAX_GAP) { - LoParkour.getPlugin().getLogger().severe( - "course-spacing.min-gap=" + courseMinGap + " exceeds the vanilla jump reach (" - + VANILLA_MAX_GAP + ") — clamped."); - courseMinGap = VANILLA_MAX_GAP; - courseStartMaxGap = Math.max(courseMinGap, courseStartMaxGap); - courseMaxGap = Math.max(courseStartMaxGap, courseMaxGap); - } - } - - private static int readClampedGap(@NotNull String path, int defaultValue) { - if (!Config.CONFIG.isPath(path)) { - return defaultValue; - } - return Math.max(1, Math.min(Config.CONFIG.getInt(path), VANILLA_MAX_GAP)); - } - public static int maxY() { return maxY; } @@ -166,24 +121,4 @@ public final class OptionGeneration { public static double maxVerticalDown() { return maxVerticalDown; } - - /** Minimum horizontal gap between consecutive blocks ({@code course-spacing.min-gap}). */ - public static int courseMinGap() { - return courseMinGap; - } - - /** Maximum gap during the conservative start segment ({@code course-spacing.start-max-gap}). */ - public static int courseStartMaxGap() { - return courseStartMaxGap; - } - - /** Maximum gap on a mature course ({@code course-spacing.max-gap}). */ - public static int courseMaxGap() { - return courseMaxGap; - } - - /** Number of conservative jumps after every (re)spawn ({@code course-spacing.start-jumps}). */ - public static int courseStartJumps() { - return courseStartJumps; - } } diff --git a/src/main/java/dev/loki/loparkour/duels/DuelsGenerator.java b/src/main/java/dev/loki/loparkour/duels/DuelsGenerator.java index 5307e18..7d3fa2c 100644 --- a/src/main/java/dev/loki/loparkour/duels/DuelsGenerator.java +++ b/src/main/java/dev/loki/loparkour/duels/DuelsGenerator.java @@ -10,7 +10,6 @@ import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.player.core.ParkourPlayer; import dev.loki.loparkour.scheduler.Scheduler; import dev.loki.loparkour.session.core.Session; -import dev.loki.loparkour.util.misc.Compat; import dev.loki.loparkour.util.text.ColorUtil; import org.bukkit.Location; import org.bukkit.Material; @@ -114,7 +113,7 @@ public class DuelsGenerator extends ParkourGenerator { final Location playerSpawn = platformCenter.clone().add(SPAWN_CENTER_OFFSET, 1, SPAWN_CENTER_OFFSET); playerSpawns.put(pp, playerSpawn); playerGenerators.put(pp, gen); - Compat.teleport(pp.player, playerSpawn); + pp.player.teleport(playerSpawn); } } diff --git a/src/main/java/dev/loki/loparkour/elytra/close/CloseGenerator.java b/src/main/java/dev/loki/loparkour/elytra/close/CloseGenerator.java index f0aaa87..dc1ac58 100644 --- a/src/main/java/dev/loki/loparkour/elytra/close/CloseGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/close/CloseGenerator.java @@ -2,6 +2,7 @@ package dev.loki.loparkour.elytra.close; import dev.loki.loparkour.elytra.core.ElytraGenerator; import dev.loki.loparkour.elytra.section.ElytraPointType; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; /** @@ -10,6 +11,6 @@ import dev.loki.loparkour.session.core.Session; public class CloseGenerator extends ElytraGenerator { public CloseGenerator(Session session) { - super(session, ElytraPointType.FLAT, new CloseMode()); + super(session, ElytraPointType.FLAT, Modes.close()); } } diff --git a/src/main/java/dev/loki/loparkour/elytra/core/ElytraGenerator.java b/src/main/java/dev/loki/loparkour/elytra/core/ElytraGenerator.java index e4f8fee..4dc6796 100644 --- a/src/main/java/dev/loki/loparkour/elytra/core/ElytraGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/core/ElytraGenerator.java @@ -7,9 +7,9 @@ import dev.loki.loparkour.elytra.section.ElytraPointType; import dev.loki.loparkour.elytra.section.ElytraSection; import dev.loki.loparkour.generator.core.coordinator.ParkourGenerator; import dev.loki.loparkour.mode.base.Mode; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; import dev.loki.loparkour.util.item.Materials; -import dev.loki.loparkour.util.misc.Compat; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -38,7 +38,7 @@ public class ElytraGenerator extends ParkourGenerator { private final ElytraBoost boost = new ElytraBoost(); public ElytraGenerator(Session session) { - this(session, ElytraPointType.CIRCLE, new ElytraMode()); + this(session, ElytraPointType.CIRCLE, Modes.elytra()); } protected ElytraGenerator(Session session, Mode mode) { @@ -133,7 +133,7 @@ public class ElytraGenerator extends ParkourGenerator { boost.reset(); if (regenerate) { if (player != null && playerSpawn != null) { - Compat.teleport(player, playerSpawn.toLocation(player.getWorld())); + player.teleport(playerSpawn.toLocation(player.getWorld())); player.setGliding(true); } generate(); diff --git a/src/main/java/dev/loki/loparkour/elytra/minspeed/MinSpeedGenerator.java b/src/main/java/dev/loki/loparkour/elytra/minspeed/MinSpeedGenerator.java index 68c74df..ea32e3c 100644 --- a/src/main/java/dev/loki/loparkour/elytra/minspeed/MinSpeedGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/minspeed/MinSpeedGenerator.java @@ -2,6 +2,7 @@ package dev.loki.loparkour.elytra.minspeed; import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.elytra.core.ElytraGenerator; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; import org.bukkit.entity.Player; @@ -19,7 +20,7 @@ public class MinSpeedGenerator extends ElytraGenerator { private int ticksTooSlow = 0; public MinSpeedGenerator(Session session) { - super(session, new MinSpeedMode()); + super(session, Modes.minSpeed()); } @Override diff --git a/src/main/java/dev/loki/loparkour/elytra/obstacle/ObstacleGenerator.java b/src/main/java/dev/loki/loparkour/elytra/obstacle/ObstacleGenerator.java index d25ee9c..ddc2bbe 100644 --- a/src/main/java/dev/loki/loparkour/elytra/obstacle/ObstacleGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/obstacle/ObstacleGenerator.java @@ -3,6 +3,7 @@ package dev.loki.loparkour.elytra.obstacle; import dev.loki.loparkour.elytra.core.ElytraGenerator; import dev.loki.loparkour.elytra.section.ElytraPointType; import dev.loki.loparkour.elytra.section.ElytraSection; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -27,7 +28,7 @@ public class ObstacleGenerator extends ElytraGenerator { private final Map> obstacles = new HashMap<>(); public ObstacleGenerator(Session session) { - super(session, new ObstacleMode()); + super(session, Modes.obstacle()); } @Override diff --git a/src/main/java/dev/loki/loparkour/elytra/speeddemon/SpeedDemonGenerator.java b/src/main/java/dev/loki/loparkour/elytra/speeddemon/SpeedDemonGenerator.java index 03ef2c1..a54949c 100644 --- a/src/main/java/dev/loki/loparkour/elytra/speeddemon/SpeedDemonGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/speeddemon/SpeedDemonGenerator.java @@ -1,6 +1,7 @@ package dev.loki.loparkour.elytra.speeddemon; import dev.loki.loparkour.elytra.core.ElytraGenerator; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; import org.bukkit.entity.Player; @@ -14,7 +15,7 @@ public class SpeedDemonGenerator extends ElytraGenerator { private double maxSpeed = 0; public SpeedDemonGenerator(Session session) { - super(session, new SpeedDemonMode()); + super(session, Modes.speedDemon()); } @Override diff --git a/src/main/java/dev/loki/loparkour/elytra/timetrial/TimeTrialGenerator.java b/src/main/java/dev/loki/loparkour/elytra/timetrial/TimeTrialGenerator.java index 97a0d79..87b0389 100644 --- a/src/main/java/dev/loki/loparkour/elytra/timetrial/TimeTrialGenerator.java +++ b/src/main/java/dev/loki/loparkour/elytra/timetrial/TimeTrialGenerator.java @@ -2,6 +2,7 @@ package dev.loki.loparkour.elytra.timetrial; import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.elytra.core.ElytraGenerator; +import dev.loki.loparkour.mode.base.Modes; import dev.loki.loparkour.session.core.Session; /** @@ -12,7 +13,7 @@ public class TimeTrialGenerator extends ElytraGenerator { private static final int SCORE = Config.GENERATION.getInt("mode-settings.time-trial.score", 500); public TimeTrialGenerator(Session session) { - super(session, new TimeTrialMode()); + super(session, Modes.timeTrial()); } @Override diff --git a/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculator.java b/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculator.java index aa2cf37..76ba57a 100644 --- a/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculator.java +++ b/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculator.java @@ -2,49 +2,54 @@ package dev.loki.loparkour.generator.jump.calculation; import dev.loki.loparkour.generator.core.coordinator.ParkourGenerator; import dev.loki.loparkour.generator.core.model.GeneratorOption; -import dev.loki.loparkour.generator.jump.constraints.JumpConstraintsResolver; -import dev.loki.loparkour.generator.jump.constraints.JumpConstraintsResolver.JumpConstraints; import dev.loki.loparkour.generator.jump.placement.BlockSelector; -import dev.loki.loparkour.generator.jump.spacing.CourseSpacing; +import dev.loki.loparkour.util.misc.MaterialUtil; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; -/** Calculates reachable jump positions within the {@link CourseSpacing} gap bounds. */ +/** + * Calculates jump positions and validates jump constraints. + */ public class JumpCalculator { private static final int MIN_HEIGHT = -2; private static final int MAX_VALID_DISTANCE = 4; - private static final int MAX_HEIGHT_UP = 1; + private static final int DEFAULT_MAX_DISTANCE = 4; + private static final int RESTRICTED_MAX_DISTANCE = 3; private static final double RANDOM_OFFSET_SD = 0.5; private static final double DEFAULT_RANDOM_OFFSET_SD = 1.0; private static final int MAX_RETRY_ATTEMPTS = 10; private static final int MAX_REROLL_ATTEMPTS = 3; + private static final int SAFETY_STEP_DISTANCE = 1; + private static final int SAFETY_STEP_HEIGHT = 0; private static final double NO_LATERAL_JITTER = 0.0; private static final double ZERO_HEADING_EPSILON = 1.0E-6; - private static final double GAP_EPSILON = 1.0E-6; + private static final int PACKED_ICE_MAX_DISTANCE = 4; + private static final int BLUE_ICE_MAX_DISTANCE = 4; + private static final int ICE_MAX_DISTANCE = 3; + private static final int DEFAULT_SPECIAL_MAX_DISTANCE = 3; private final ParkourGenerator generator; private final BlockSelector blockSelector; - private final JumpConstraintsResolver constraintsResolver; public JumpCalculator(@NotNull ParkourGenerator generator, @NotNull BlockSelector blockSelector) { this.generator = generator; this.blockSelector = blockSelector; - this.constraintsResolver = new JumpConstraintsResolver(blockSelector); } /** - * Calculates the next reachable block, or null when none exists (the attempt is skipped). + * Calculate the next block position based on current block and jump parameters. */ - @Nullable + @NotNull public Block calculateNextBlock(@NotNull Block current, int distance, int height) { if (generator.state.zone() == null || generator.state.zone().length < 2) { throw new IllegalStateException("Generator zone not initialized"); @@ -56,28 +61,56 @@ public class JumpCalculator { ); generator.state.setHeading(director.getRecommendedHeading(generator.state.heading())); - final JumpConstraints constraints = constraintsResolver.resolve(current); - - final CourseSpacing spacing = CourseSpacing.fromConfig(); - final int minGap = Math.max(1, Math.min(spacing.minGap(), Math.min(constraints.maxDistance, MAX_VALID_DISTANCE))); - final int gapCeiling = Math.min(Math.min( - spacing.maxGapFor(generator.state.generatedBlocks(), generator.getDifficultyScore()), - constraints.maxDistance), MAX_VALID_DISTANCE); - int resolvedHeight = director.getRecommendedHeight(height); - resolvedHeight = Math.min(resolvedHeight, constraints.maxHeight); - resolvedHeight = Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT_UP, resolvedHeight)); - int resolvedDistance = Math.max(minGap, Math.min(distance, gapCeiling)); + final JumpConstraints constraints = calculateJumpConstraints(current); + resolvedHeight = Math.min(resolvedHeight, constraints.maxHeight); + int resolvedDistance = Math.min(distance, constraints.maxDistance); + + resolvedHeight = Math.max(MIN_HEIGHT, Math.min(2, resolvedHeight)); + resolvedDistance = Math.max(1, Math.min(MAX_VALID_DISTANCE, resolvedDistance)); + if (resolvedHeight > 0) { - resolvedDistance = Math.max(resolvedDistance - resolvedHeight, minGap); + resolvedDistance = Math.max(resolvedDistance - resolvedHeight, 1); } final double randomOffsetSd = Arrays.asList(generator.generatorOptions) .contains(GeneratorOption.REDUCE_RANDOM_BLOCK_SELECTION_ANGLE) ? RANDOM_OFFSET_SD : DEFAULT_RANDOM_OFFSET_SD; final Location candidate = validateAndRetryJump(current.getLocation(), generator.state.heading(), - resolvedDistance, resolvedHeight, minGap, randomOffsetSd); - return candidate == null ? null : candidate.getBlock(); + resolvedDistance, resolvedHeight, ThreadLocalRandom.current(), randomOffsetSd); + return candidate.getBlock(); + } + + @NotNull + public JumpConstraints calculateJumpConstraints(@NotNull Block currentBlock) { + final Material material = currentBlock.getType(); + final BlockData blockData = currentBlock.getBlockData(); + + int maxHeight = 1; + int maxDistance = DEFAULT_MAX_DISTANCE; + + if (MaterialUtil.isSlabMaterial(material)) { + if (blockData instanceof org.bukkit.block.data.type.Slab slab) { + if (slab.getType() == org.bukkit.block.data.type.Slab.Type.BOTTOM) { + maxHeight = -1; + maxDistance = RESTRICTED_MAX_DISTANCE; + } else { + maxHeight = 0; + maxDistance = RESTRICTED_MAX_DISTANCE; + } + } else { + maxHeight = 0; + maxDistance = RESTRICTED_MAX_DISTANCE; + } + } else if (material == Material.GLASS_PANE) { + maxHeight = 0; + maxDistance = RESTRICTED_MAX_DISTANCE; + } else if (blockSelector.isSpecialMaterial(material)) { + maxHeight = getSpecialMaterialMaxHeight(material); + maxDistance = getSpecialMaterialMaxDistance(material); + } + + return new JumpConstraints(maxHeight, maxDistance); } @NotNull @@ -97,83 +130,71 @@ public class JumpCalculator { return Math.min(new JumpOffsetGenerator(height, distance).getRandomOffset(0, standardDeviation, random), maxJitter); } - /** - * Tries reachable integer block anchors; never returns an adjacent grid cell. - */ - @Nullable - static Location validateAndRetryJump(@NotNull Location current, @NotNull Vector heading, int distance, int height, - int minGap, double randomOffsetSd) { - return validateAndRetryJump(current, heading, distance, height, minGap, randomOffsetSd, new JumpValidator()); - } - - /** Package-visible variant with an injectable validator for tests. */ - @Nullable - static Location validateAndRetryJump(@NotNull Location current, @NotNull Vector heading, int distance, int height, - int minGap, double randomOffsetSd, @NotNull JumpValidator validator) { - final Random random = ThreadLocalRandom.current(); - final Vector normalized = heading.length() < ZERO_HEADING_EPSILON - ? new Vector(0, 0, 1) : heading.clone().normalize(); - final int baseDistance = Math.max(minGap, distance); - final int maxDistance = Math.min(MAX_VALID_DISTANCE, baseDistance + MAX_HEIGHT_UP); - int resolvedHeight = height; - for (int attempt = 0; attempt < MAX_RETRY_ATTEMPTS; attempt++) { - // Search a small distance window: diagonal offsets can land on a - // neighbouring grid cell, so a larger step may be the closest real jump. - for (int resolvedDistance = baseDistance; resolvedDistance <= maxDistance; resolvedDistance++) { - final Location candidate = blockAnchor(current, normalized, resolvedDistance, resolvedHeight, - randomOffset(resolvedHeight, resolvedDistance, randomOffsetSd, random)); - if (isReachableBlock(current, candidate, minGap, validator)) { - return candidate; - } - } - resolvedHeight = Math.max(MIN_HEIGHT, resolvedHeight - 1); - } - return safetyFallback(current, normalized, minGap, randomOffsetSd, validator); - } - - /** Last resort: a straight, flat step starting at {@code minGap} blocks. */ - @Nullable - static Location safetyFallback(@NotNull Location current, @NotNull Vector heading, int minGap, - double randomOffsetSd, @NotNull JumpValidator validator) { - final Random random = ThreadLocalRandom.current(); - for (int distance = minGap; distance <= MAX_VALID_DISTANCE; distance++) { - for (int i = 0; i < MAX_REROLL_ATTEMPTS; i++) { - final Location reRolled = blockAnchor(current, heading, distance, 0, - randomOffset(0, distance, randomOffsetSd, random)); - if (isReachableBlock(current, reRolled, minGap, validator)) { - return reRolled; - } - } - final Location straight = blockAnchor(current, heading, distance, 0, NO_LATERAL_JITTER); - if (isReachableBlock(current, straight, minGap, validator)) { - return straight; - } - } - return null; - } - - /** Snaps a fractional offset to the integer block that will actually be placed. */ @NotNull - private static Location blockAnchor(@NotNull Location current, @NotNull Vector heading, int distance, int height, - double randomOffset) { - final Vector offset = offsetFor(heading, distance, height, randomOffset); - // Floor to the integer block anchor without touching the world (unit tests - // use a mocked world); Location#getBlock() performs the same flooring. - return new Location(current.getWorld(), - Math.floor(current.getX() + offset.getX()), - Math.floor(current.getY() + offset.getY()), - Math.floor(current.getZ() + offset.getZ())); + static Location validateAndRetryJump(@NotNull Location current, @NotNull Vector heading, int distance, int height, + @NotNull Random random, double randomOffsetSd) { + final JumpValidator validator = new JumpValidator(); + int resolvedDistance = distance; + int resolvedHeight = height; + int attempts = 0; + Location candidate = current.clone().add(offsetFor(heading, resolvedDistance, resolvedHeight, + randomOffset(resolvedHeight, resolvedDistance, randomOffsetSd, random))); + while (!validator.canJump(current, candidate) && attempts < MAX_RETRY_ATTEMPTS) { + resolvedDistance = Math.max(1, resolvedDistance - 1); + resolvedHeight = Math.max(MIN_HEIGHT, resolvedHeight - 1); + candidate = current.clone().add(offsetFor(heading, resolvedDistance, resolvedHeight, + randomOffset(resolvedHeight, resolvedDistance, randomOffsetSd, random))); + attempts++; + } + + if (validator.canJump(current, candidate)) { + return candidate; + } + return safetyFallback(current, heading, randomOffsetSd, random, validator); } - /** @return true when the anchor clears the integer grid gap and the jump validator. */ - private static boolean isReachableBlock(@NotNull Location current, @NotNull Location candidate, int minGap, - @NotNull JumpValidator validator) { - final int dx = candidate.getBlockX() - current.getBlockX(); - final int dz = candidate.getBlockZ() - current.getBlockZ(); - if (dx == 0 && dz == 0) { - return false; + @NotNull + static Location safetyFallback(@NotNull Location current, @NotNull Vector heading, double randomOffsetSd, + @NotNull Random random, @NotNull JumpValidator validator) { + for (int i = 0; i < MAX_REROLL_ATTEMPTS; i++) { + final Location reRolled = current.clone().add(offsetFor(heading, SAFETY_STEP_DISTANCE, SAFETY_STEP_HEIGHT, + randomOffset(SAFETY_STEP_HEIGHT, SAFETY_STEP_DISTANCE, randomOffsetSd, random))); + if (validator.canJump(current, reRolled)) { + return reRolled; + } + } + final Location straight = current.clone().add( + offsetFor(heading, SAFETY_STEP_DISTANCE, SAFETY_STEP_HEIGHT, NO_LATERAL_JITTER)); + return validator.canJump(current, straight) ? straight : current; + } + + private int getSpecialMaterialMaxHeight(@NotNull Material material) { + return switch (material) { + case PACKED_ICE -> 1; + case BLUE_ICE -> 1; + case ICE -> 0; + case LADDER -> 1; + default -> 0; + }; + } + + private int getSpecialMaterialMaxDistance(@NotNull Material material) { + return switch (material) { + case PACKED_ICE -> PACKED_ICE_MAX_DISTANCE; + case BLUE_ICE -> BLUE_ICE_MAX_DISTANCE; + case ICE -> ICE_MAX_DISTANCE; + case LADDER -> 2; + default -> DEFAULT_SPECIAL_MAX_DISTANCE; + }; + } + + public static class JumpConstraints { + public final int maxHeight; + public final int maxDistance; + + public JumpConstraints(int maxHeight, int maxDistance) { + this.maxHeight = maxHeight; + this.maxDistance = maxDistance; } - final double blockGap = Math.sqrt(dx * dx + dz * dz); - return blockGap + GAP_EPSILON >= minGap && validator.canJump(current, candidate); } } diff --git a/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpOffsetGenerator.java b/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpOffsetGenerator.java index 876e55c..a34d834 100644 --- a/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpOffsetGenerator.java +++ b/src/main/java/dev/loki/loparkour/generator/jump/calculation/JumpOffsetGenerator.java @@ -78,10 +78,8 @@ public class JumpOffsetGenerator { } private static void warnUnexpectedHeight(int y) { - final dev.loki.loparkour.LoParkour plugin = dev.loki.loparkour.LoParkour.getPlugin(); - if (plugin != null) { // null outside a running server (unit tests) - plugin.getLogger().warning("Unexpected jump height " + y + ", using default maxOffset=2"); - } + dev.loki.loparkour.LoParkour.getPlugin().getLogger() + .warning("Unexpected jump height " + y + ", using default maxOffset=2"); } /** diff --git a/src/main/java/dev/loki/loparkour/generator/jump/constraints/JumpConstraintsResolver.java b/src/main/java/dev/loki/loparkour/generator/jump/constraints/JumpConstraintsResolver.java deleted file mode 100644 index 202a995..0000000 --- a/src/main/java/dev/loki/loparkour/generator/jump/constraints/JumpConstraintsResolver.java +++ /dev/null @@ -1,98 +0,0 @@ -package dev.loki.loparkour.generator.jump.constraints; - -import dev.loki.loparkour.generator.jump.placement.BlockSelector; -import dev.loki.loparkour.util.misc.MaterialUtil; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.jetbrains.annotations.NotNull; - -/** - * Resolves per-material jump limits (maximum upward step and maximum gap) - * for the block a jump starts from. Slabs, panes and slippery special blocks - * get tighter limits than full solid blocks. - */ -public final class JumpConstraintsResolver { - - private static final int DEFAULT_MAX_HEIGHT = 1; - private static final int DEFAULT_MAX_DISTANCE = 4; - private static final int RESTRICTED_MAX_DISTANCE = 3; - private static final int PACKED_ICE_MAX_DISTANCE = 4; - private static final int BLUE_ICE_MAX_DISTANCE = 4; - private static final int ICE_MAX_DISTANCE = 3; - private static final int LADDER_MAX_DISTANCE = 2; - private static final int DEFAULT_SPECIAL_MAX_DISTANCE = 3; - - private final BlockSelector blockSelector; - - public JumpConstraintsResolver(@NotNull BlockSelector blockSelector) { - this.blockSelector = blockSelector; - } - - /** - * @param currentBlock the block the jump starts from - * @return the limits for jumping off this block type; never null - */ - @NotNull - public JumpConstraints resolve(@NotNull Block currentBlock) { - final Material material = currentBlock.getType(); - final BlockData blockData = currentBlock.getBlockData(); - - int maxHeight = DEFAULT_MAX_HEIGHT; - int maxDistance = DEFAULT_MAX_DISTANCE; - - if (MaterialUtil.isSlabMaterial(material)) { - if (blockData instanceof org.bukkit.block.data.type.Slab slab) { - if (slab.getType() == org.bukkit.block.data.type.Slab.Type.BOTTOM) { - maxHeight = -1; - maxDistance = RESTRICTED_MAX_DISTANCE; - } else { - maxHeight = 0; - maxDistance = RESTRICTED_MAX_DISTANCE; - } - } else { - maxHeight = 0; - maxDistance = RESTRICTED_MAX_DISTANCE; - } - } else if (material == Material.GLASS_PANE) { - maxHeight = 0; - maxDistance = RESTRICTED_MAX_DISTANCE; - } else if (blockSelector.isSpecialMaterial(material)) { - maxHeight = specialMaxHeight(material); - maxDistance = specialMaxDistance(material); - } - - return new JumpConstraints(maxHeight, maxDistance); - } - - private int specialMaxHeight(@NotNull Material material) { - return switch (material) { - case PACKED_ICE -> 1; - case BLUE_ICE -> 1; - case ICE -> 0; - case LADDER -> 1; - default -> 0; - }; - } - - private int specialMaxDistance(@NotNull Material material) { - return switch (material) { - case PACKED_ICE -> PACKED_ICE_MAX_DISTANCE; - case BLUE_ICE -> BLUE_ICE_MAX_DISTANCE; - case ICE -> ICE_MAX_DISTANCE; - case LADDER -> LADDER_MAX_DISTANCE; - default -> DEFAULT_SPECIAL_MAX_DISTANCE; - }; - } - - /** Per-material limits for one jump. */ - public static final class JumpConstraints { - public final int maxHeight; - public final int maxDistance; - - public JumpConstraints(int maxHeight, int maxDistance) { - this.maxHeight = maxHeight; - this.maxDistance = maxDistance; - } - } -} diff --git a/src/main/java/dev/loki/loparkour/generator/jump/placement/BlockTargetSelector.java b/src/main/java/dev/loki/loparkour/generator/jump/placement/BlockTargetSelector.java index a60eebb..d6a832b 100644 --- a/src/main/java/dev/loki/loparkour/generator/jump/placement/BlockTargetSelector.java +++ b/src/main/java/dev/loki/loparkour/generator/jump/placement/BlockTargetSelector.java @@ -46,9 +46,7 @@ public class BlockTargetSelector { final int distance = Probs.random(generator.state.distanceChances); final int height = forcedHeight != NO_FORCED_HEIGHT ? forcedHeight : Probs.random(generator.state.heightChances); final Block nextBlock = jumpCalculator.calculateNextBlock(current, distance, height); - if (nextBlock != null) { - blocks.add(nextBlock); - } + blocks.add(nextBlock); return blocks; } } diff --git a/src/main/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacing.java b/src/main/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacing.java deleted file mode 100644 index 2b9d07f..0000000 --- a/src/main/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacing.java +++ /dev/null @@ -1,90 +0,0 @@ -package dev.loki.loparkour.generator.jump.spacing; - -import dev.loki.loparkour.config.options.section.OptionGeneration; -import org.jetbrains.annotations.NotNull; - -/** - * Resolves the horizontal gap bounds for a single generation step. - * - *

The first {@code startJumps} blocks of a course use a conservative - * {@code [minGap, startMaxGap]} range; afterwards the upper bound grows with the - * generator difficulty score toward {@code maxGap}. The lower bound never drops - * below {@code minGap}, so blocks are never placed directly next to each other - * ("in a row") and every gap is a real jump.

- * - *

All values are clamped to the vanilla jump reach (1..4 blocks), so a - * misconfigured {@code course-spacing.*} section can never produce unreachable - * gaps.

- */ -public final class CourseSpacing { - - /** Difficulty score at which the gap cap reaches {@code max-gap} (see GeneratorProfileManager). */ - private static final double FULL_DIFFICULTY_SCORE = 1.5; - - /** Largest gap a vanilla (non-sprint) jump can clear; mirrors JumpValidator.MAX_HORIZONTAL_DISTANCE. */ - private static final int VANILLA_MAX_GAP = 4; - - private static final int ABSOLUTE_MIN_GAP = 1; - - private final int minGap; - private final int startMaxGap; - private final int maxGap; - private final int startJumps; - - /** - * Creates spacing with sanitized bounds. - * - * @param minGap minimum horizontal gap between two blocks (1..4) - * @param startMaxGap maximum gap during the start segment ({@code >= minGap}) - * @param maxGap maximum gap on a mature course ({@code >= startMaxGap}) - * @param startJumps number of conservative jumps after every (re)spawn - */ - public CourseSpacing(int minGap, int startMaxGap, int maxGap, int startJumps) { - final int safeMin = clamp(minGap, ABSOLUTE_MIN_GAP, VANILLA_MAX_GAP); - this.minGap = safeMin; - this.startMaxGap = clamp(startMaxGap, safeMin, VANILLA_MAX_GAP); - this.maxGap = clamp(maxGap, this.startMaxGap, VANILLA_MAX_GAP); - this.startJumps = Math.max(0, startJumps); - } - - /** - * Spacing resolved from the {@code course-spacing.*} section of config.yml. - * - * @return sanitized spacing; never null - */ - @NotNull - public static CourseSpacing fromConfig() { - return new CourseSpacing( - OptionGeneration.courseMinGap(), - OptionGeneration.courseStartMaxGap(), - OptionGeneration.courseMaxGap(), - OptionGeneration.courseStartJumps()); - } - - /** - * Upper gap bound for one generation step. - * - * @param generatedBlocks blocks placed since the course (re)started - * @param difficultyScore generator difficulty score (roughly 0..1.5) - * @return the largest gap allowed for this step, never below {@link #minGap()} - */ - public int maxGapFor(int generatedBlocks, double difficultyScore) { - if (generatedBlocks < startJumps) { - return startMaxGap; - } - final double normalized = Math.max(0.0, Math.min(1.0, difficultyScore / FULL_DIFFICULTY_SCORE)); - final int scaled = minGap + (int) Math.ceil(normalized * (maxGap - minGap)); - return Math.max(startMaxGap, Math.min(maxGap, scaled)); - } - - /** - * @return the smallest gap ever placed; below this a step counts as "in a row" - */ - public int minGap() { - return minGap; - } - - private static int clamp(int value, int min, int max) { - return Math.max(min, Math.min(max, value)); - } -} diff --git a/src/main/java/dev/loki/loparkour/ghost/core/GhostPlayer.java b/src/main/java/dev/loki/loparkour/ghost/core/GhostPlayer.java index 0c71aaa..ff1239e 100644 --- a/src/main/java/dev/loki/loparkour/ghost/core/GhostPlayer.java +++ b/src/main/java/dev/loki/loparkour/ghost/core/GhostPlayer.java @@ -5,7 +5,6 @@ import dev.loki.loparkour.ghost.model.GhostData; import dev.loki.loparkour.scheduler.Scheduler; import dev.loki.loparkour.scheduler.ScheduledTask; -import dev.loki.loparkour.util.misc.Compat; import dev.loki.loparkour.LoParkour; import org.bukkit.Location; import org.bukkit.World; @@ -52,7 +51,7 @@ public class GhostPlayer { startTime = System.currentTimeMillis(); currentFrame = 0; - task = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(this::update, startLocation, 0, 1); + task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::update, 0, 1); } private void update() { @@ -68,7 +67,7 @@ public class GhostPlayer { if (frame.getTimestamp() > elapsed) { break; } - Compat.teleport(entity, frame.toLocation(world)); + entity.teleport(frame.toLocation(world)); currentFrame++; } diff --git a/src/main/java/dev/loki/loparkour/ghost/service/GhostReplay.java b/src/main/java/dev/loki/loparkour/ghost/service/GhostReplay.java index cec8dea..29faead 100644 --- a/src/main/java/dev/loki/loparkour/ghost/service/GhostReplay.java +++ b/src/main/java/dev/loki/loparkour/ghost/service/GhostReplay.java @@ -7,7 +7,6 @@ import dev.loki.loparkour.ghost.replay.PlayerGhost; import dev.loki.loparkour.player.core.ParkourUser; import dev.loki.loparkour.scheduler.ScheduledTask; import dev.loki.loparkour.scheduler.Scheduler; -import dev.loki.loparkour.util.misc.Compat; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -64,15 +63,14 @@ public class GhostReplay { ParkourUser.leave(viewer); } final Location start = run.getFrames().get(FIRST_FRAME).toLocation(world); - Compat.teleport(viewer, start); + viewer.teleport(start); moved = true; ghost = new PlayerGhost(viewer, run.getPlayerName()); if (ghost.spawn(start)) { startTime = System.currentTimeMillis(); frameIndex = FIRST_FRAME; current = start; - task = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(this::tick, start, - TICK_DELAY, TICK_PERIOD); + task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::tick, TICK_DELAY, TICK_PERIOD); } else { finish(); } @@ -108,7 +106,7 @@ public class GhostReplay { ghost = null; } if (moved && viewer.isOnline()) { - Compat.teleport(viewer, returnTo); + viewer.teleport(returnTo); } onFinish.run(); } diff --git a/src/main/java/dev/loki/loparkour/listener/gameplay/ElytraRestrictionListener.java b/src/main/java/dev/loki/loparkour/listener/gameplay/ElytraRestrictionListener.java deleted file mode 100644 index 8f5206a..0000000 --- a/src/main/java/dev/loki/loparkour/listener/gameplay/ElytraRestrictionListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package dev.loki.loparkour.listener.gameplay; - -import dev.loki.loparkour.config.locale.Locales; -import dev.loki.loparkour.world.core.World; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityToggleGlideEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -/** - * Blocks wearing, using and gliding with an elytra inside the parkour world. - * - *

The elytra game modes are no longer registered; this listener is the - * defence-in-depth guard for players who bring their own elytra.

- */ -public class ElytraRestrictionListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST) - public void onInteract(@NotNull PlayerInteractEvent event) { - final Player player = event.getPlayer(); - if (isInParkourWorld(player) && isElytra(event.getItem())) { - event.setCancelled(true); - Locales.send(player, "other.elytra_blocked"); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void onInventoryClick(@NotNull InventoryClickEvent event) { - if (!(event.getWhoClicked() instanceof Player player) || !isInParkourWorld(player)) { - return; - } - if (isElytra(event.getCurrentItem()) || isElytra(event.getCursor())) { - event.setCancelled(true); - Locales.send(player, "other.elytra_blocked"); - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onGlide(@NotNull EntityToggleGlideEvent event) { - if (event.isGliding() && event.getEntity() instanceof Player player && isInParkourWorld(player)) { - event.setCancelled(true); - Locales.send(player, "other.elytra_blocked"); - } - } - - private boolean isInParkourWorld(@NotNull Player player) { - final org.bukkit.World parkour = World.getWorld(); - return parkour != null && parkour.equals(player.getWorld()); - } - - private boolean isElytra(ItemStack item) { - return item != null && item.getType() == Material.ELYTRA; - } -} diff --git a/src/main/java/dev/loki/loparkour/mode/base/ModeMessages.java b/src/main/java/dev/loki/loparkour/mode/base/ModeMessages.java index 6beaffe..b517a82 100644 --- a/src/main/java/dev/loki/loparkour/mode/base/ModeMessages.java +++ b/src/main/java/dev/loki/loparkour/mode/base/ModeMessages.java @@ -1,9 +1,7 @@ package dev.loki.loparkour.mode.base; -import dev.loki.loparkour.LoParkour; import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.config.locale.Locales; -import dev.loki.loparkour.world.core.World; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -16,37 +14,13 @@ public final class ModeMessages { } /** - * Checks whether a new parkour session may be started. - * - *

Besides the {@code joining} switch this verifies that the configured - * parkour world is actually loaded. Without it a session would be built with - * null world locations and generation could leak into the player's world.

- * - * @return true if joining is allowed; otherwise sends the matching locale - * message, logs the missing world in English and returns false + * @return true if joining is allowed; otherwise sends {@code other.joining_disabled} and returns false */ public static boolean checkJoiningEnabled(@NotNull Player player) { - if (!Config.CONFIG.getBoolean("joining")) { - Locales.send(player, "other.joining_disabled"); - return false; + if (Config.CONFIG.getBoolean("joining")) { + return true; } - if (World.getWorld() == null) { - LoParkour.getPlugin().getLogger().severe( - "Parkour world '" + World.getName() + "' is not loaded. " - + "Set world.name to an existing world or let LoParkour create it; " - + "joining is disabled until the world is available."); - Locales.send(player, "other.world_unavailable", World.getName()); - return false; - } - return true; - } - - /** - * Sends the short beta notice shown after a successful join. - * - * @param player the player who just joined - */ - public static void sendBetaWelcome(@NotNull Player player) { - Locales.send(player, "other.beta_welcome"); + Locales.send(player, "other.joining_disabled"); + return false; } } diff --git a/src/main/java/dev/loki/loparkour/mode/base/Modes.java b/src/main/java/dev/loki/loparkour/mode/base/Modes.java index 3a13ab4..c0bccfe 100644 --- a/src/main/java/dev/loki/loparkour/mode/base/Modes.java +++ b/src/main/java/dev/loki/loparkour/mode/base/Modes.java @@ -2,6 +2,12 @@ package dev.loki.loparkour.mode.base; import dev.loki.loparkour.api.core.Registry; import dev.loki.loparkour.duels.DuelsMode; +import dev.loki.loparkour.elytra.close.CloseMode; +import dev.loki.loparkour.elytra.core.ElytraMode; +import dev.loki.loparkour.elytra.minspeed.MinSpeedMode; +import dev.loki.loparkour.elytra.obstacle.ObstacleMode; +import dev.loki.loparkour.elytra.speeddemon.SpeedDemonMode; +import dev.loki.loparkour.elytra.timetrial.TimeTrialMode; import dev.loki.loparkour.mode.impl.barrier.InvisibleBarrierMode; import dev.loki.loparkour.mode.impl.multi.CoopMode; import dev.loki.loparkour.mode.impl.multi.RaceMode; @@ -22,6 +28,12 @@ public final class Modes { private static RaceMode race; private static CoopMode coop; private static GravityShiftMode gravityShift; + private static ElytraMode elytra; + private static SpeedDemonMode speedDemon; + private static MinSpeedMode minSpeed; + private static TimeTrialMode timeTrial; + private static CloseMode close; + private static ObstacleMode obstacle; private static DuelsMode duels; public static void init() { @@ -32,6 +44,12 @@ public final class Modes { race = (RaceMode) Registry.getMode("race"); coop = (CoopMode) Registry.getMode("coop"); gravityShift = (GravityShiftMode) Registry.getMode("gravity-shift"); + elytra = (ElytraMode) Registry.getMode("elytra"); + speedDemon = (SpeedDemonMode) Registry.getMode("speeddemon"); + minSpeed = (MinSpeedMode) Registry.getMode("minspeed"); + timeTrial = (TimeTrialMode) Registry.getMode("timetrial"); + close = (CloseMode) Registry.getMode("close"); + obstacle = (ObstacleMode) Registry.getMode("obstacle"); duels = (DuelsMode) Registry.getMode("duels"); } @@ -63,6 +81,30 @@ public final class Modes { return gravityShift; } + public static ElytraMode elytra() { + return elytra; + } + + public static SpeedDemonMode speedDemon() { + return speedDemon; + } + + public static MinSpeedMode minSpeed() { + return minSpeed; + } + + public static TimeTrialMode timeTrial() { + return timeTrial; + } + + public static CloseMode close() { + return close; + } + + public static ObstacleMode obstacle() { + return obstacle; + } + public static DuelsMode duels() { return duels; } diff --git a/src/main/java/dev/loki/loparkour/player/core/ParkourUser.java b/src/main/java/dev/loki/loparkour/player/core/ParkourUser.java index fcbc1ba..8cf170b 100644 --- a/src/main/java/dev/loki/loparkour/player/core/ParkourUser.java +++ b/src/main/java/dev/loki/loparkour/player/core/ParkourUser.java @@ -10,7 +10,6 @@ import dev.loki.loparkour.hook.floodgate.FloodgateHook; import dev.loki.loparkour.menu.core.screen.ParkourOption; import dev.loki.loparkour.player.data.PreviousData; import dev.loki.loparkour.session.core.Session; -import dev.loki.loparkour.util.misc.Compat; import dev.loki.loparkour.util.text.ColorUtil; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -132,7 +131,7 @@ public abstract class ParkourUser { } public void teleport(@NotNull Location to) { - Compat.teleport(player, to); + player.teleport(to); } public void send(String message) { diff --git a/src/main/java/dev/loki/loparkour/player/data/PreviousData.java b/src/main/java/dev/loki/loparkour/player/data/PreviousData.java index 5a48458..60299f3 100644 --- a/src/main/java/dev/loki/loparkour/player/data/PreviousData.java +++ b/src/main/java/dev/loki/loparkour/player/data/PreviousData.java @@ -4,7 +4,6 @@ import dev.loki.loparkour.LoParkour; import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.config.options.OptionGeneral; import dev.loki.loparkour.reward.core.Reward; -import dev.loki.loparkour.util.misc.Compat; import io.papermc.lib.PaperLib; import org.bukkit.GameMode; import org.bukkit.Location; @@ -62,7 +61,7 @@ public class PreviousData { if (!urgent) { PaperLib.teleportAsync(player, to).thenRun(() -> apply(player)); } else { - Compat.teleport(player, to); + player.teleport(to); apply(player); } diff --git a/src/main/java/dev/loki/loparkour/scheduler/BukkitBackend.java b/src/main/java/dev/loki/loparkour/scheduler/BukkitBackend.java index b4bfac3..be8c3b2 100644 --- a/src/main/java/dev/loki/loparkour/scheduler/BukkitBackend.java +++ b/src/main/java/dev/loki/loparkour/scheduler/BukkitBackend.java @@ -38,20 +38,4 @@ final class BukkitBackend implements Scheduler.Backend { public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) { return Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, task, delayTicks, periodTicks)::cancel; } - - @Override - public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) { - return Bukkit.getScheduler().runTaskLater(plugin, task, delayTicks)::cancel; - } - - @Override - public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location, - long delayTicks, long periodTicks) { - return Bukkit.getScheduler().runTaskTimer(plugin, task, delayTicks, periodTicks)::cancel; - } - - @Override - public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) { - return Bukkit.getScheduler().runTask(plugin, task)::cancel; - } } diff --git a/src/main/java/dev/loki/loparkour/scheduler/FoliaBackend.java b/src/main/java/dev/loki/loparkour/scheduler/FoliaBackend.java index dd3b7e8..15516f2 100644 --- a/src/main/java/dev/loki/loparkour/scheduler/FoliaBackend.java +++ b/src/main/java/dev/loki/loparkour/scheduler/FoliaBackend.java @@ -20,27 +20,21 @@ final class FoliaBackend implements Scheduler.Backend { private static final String GLOBAL_SCHEDULER_CLASS = "GlobalRegionScheduler"; private static final String ASYNC_SCHEDULER_CLASS = "AsyncScheduler"; - private static final String REGION_SCHEDULER_CLASS = "RegionScheduler"; private final Plugin plugin; private final Object globalScheduler; private final Object asyncScheduler; - private final Object regionScheduler; private final Method globalRun; private final Method globalRunDelayed; private final Method globalRunAtFixedRate; private final Method asyncRunNow; private final Method asyncRunAtFixedRate; - private final Method regionRunDelayed; - private final Method regionRunAtFixedRate; - private final Method entityExecute; private final Method taskCancel; FoliaBackend(Plugin plugin) throws ReflectiveOperationException { this.plugin = plugin; this.globalScheduler = scheduler("getGlobalRegionScheduler"); this.asyncScheduler = scheduler("getAsyncScheduler"); - this.regionScheduler = scheduler("getRegionScheduler"); this.globalRun = method(GLOBAL_SCHEDULER_CLASS, "run", Plugin.class, Consumer.class); this.globalRunDelayed = method(GLOBAL_SCHEDULER_CLASS, "runDelayed", Plugin.class, Consumer.class, long.class); @@ -49,12 +43,6 @@ final class FoliaBackend implements Scheduler.Backend { this.asyncRunNow = method(ASYNC_SCHEDULER_CLASS, "runNow", Plugin.class, Consumer.class); this.asyncRunAtFixedRate = method(ASYNC_SCHEDULER_CLASS, "runAtFixedRate", Plugin.class, Consumer.class, long.class, long.class); - this.regionRunDelayed = method(REGION_SCHEDULER_CLASS, "runDelayed", - Plugin.class, org.bukkit.Location.class, Consumer.class, long.class); - this.regionRunAtFixedRate = method(REGION_SCHEDULER_CLASS, "runAtFixedRate", - Plugin.class, org.bukkit.Location.class, Consumer.class, long.class, long.class); - this.entityExecute = Class.forName(SCHEDULER_PACKAGE + "EntityScheduler") - .getMethod("execute", Plugin.class, Runnable.class); this.taskCancel = Class.forName(SCHEDULER_PACKAGE + "ScheduledTask").getMethod("cancel"); } @@ -79,29 +67,6 @@ final class FoliaBackend implements Scheduler.Backend { consumer(task), delayTicks, periodTicks)); } - @Override - public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location, - long delayTicks, long periodTicks) { - return wrap(invoke(regionRunAtFixedRate, regionScheduler, plugin, location, - consumer(task), delayTicks, periodTicks)); - } - - @Override - public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) { - return wrap(invoke(regionRunDelayed, regionScheduler, plugin, location, - consumer(task), delayTicks)); - } - - @Override - public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) { - try { - final Object entityScheduler = entity.getClass().getMethod("getScheduler").invoke(entity); - return wrap(invoke(entityExecute, entityScheduler, plugin, task)); - } catch (ReflectiveOperationException | IllegalArgumentException cause) { - throw new IllegalStateException("Folia entity scheduler call failed", cause); - } - } - @Override public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) { return wrap(invoke(asyncRunAtFixedRate, asyncScheduler, plugin, diff --git a/src/main/java/dev/loki/loparkour/scheduler/Scheduler.java b/src/main/java/dev/loki/loparkour/scheduler/Scheduler.java index 9cb2a42..0282ed6 100644 --- a/src/main/java/dev/loki/loparkour/scheduler/Scheduler.java +++ b/src/main/java/dev/loki/loparkour/scheduler/Scheduler.java @@ -99,49 +99,6 @@ public final class Scheduler { return backend.runTimerAsync(task, delayTicks, periodTicks); } - /** - * Runs the task once on the region thread owning the location. - * - *

On Bukkit this is a plain delayed task; on Folia it uses the region - * scheduler, so block access around the location is legal. - * - * @param task the task to run - * @param location the location whose region owns the task - * @param delayTicks delay in ticks - * @return a handle used to cancel the task - */ - public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) { - return backend.runAtLocation(task, location, delayTicks); - } - - /** - * Runs the task repeatedly on the region thread owning the location. - * - * @param task the task to run - * @param location the location whose region owns the task - * @param delayTicks first run delay in ticks - * @param periodTicks period between runs in ticks - * @return a handle used to cancel the task - */ - public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location, - long delayTicks, long periodTicks) { - return backend.runTimerAtLocation(task, location, delayTicks, periodTicks); - } - - /** - * Runs the task on the entity's thread on the next tick. - * - *

On Bukkit this is a plain sync task; on Folia it uses the entity - * scheduler, so entity access (teleport, inventory) is legal. - * - * @param task the task to run - * @param entity the entity whose thread owns the task - * @return a handle used to cancel the task - */ - public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) { - return backend.runAtEntity(task, entity); - } - private static Backend createBackend(Plugin plugin) { if (FOLIA) { try { @@ -175,12 +132,5 @@ public final class Scheduler { ScheduledTask runTimer(Runnable task, long delayTicks, long periodTicks); ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks); - - ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks); - - ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location, - long delayTicks, long periodTicks); - - ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity); } } diff --git a/src/main/java/dev/loki/loparkour/session/manager/SessionStateManager.java b/src/main/java/dev/loki/loparkour/session/manager/SessionStateManager.java index cbb3bd0..91d86a5 100644 --- a/src/main/java/dev/loki/loparkour/session/manager/SessionStateManager.java +++ b/src/main/java/dev/loki/loparkour/session/manager/SessionStateManager.java @@ -74,7 +74,7 @@ public class SessionStateManager { return; } - tickTask = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(() -> { + tickTask = Scheduler.get(LoParkour.getPlugin()).runTimer(() -> { if (session.generator() != null) { try { session.generator().tick(); @@ -86,7 +86,7 @@ public class SessionStateManager { p.player.sendMessage("§c[LoParkour] Tick error: " + t.getMessage())); } } - }, spawnLocation, 0, 1); // Run every tick (1 = 50ms) + }, 0, 1); // Run every tick (1 = 50ms) } /** diff --git a/src/main/java/dev/loki/loparkour/util/misc/Compat.java b/src/main/java/dev/loki/loparkour/util/misc/Compat.java index edd4327..eb55a3d 100644 --- a/src/main/java/dev/loki/loparkour/util/misc/Compat.java +++ b/src/main/java/dev/loki/loparkour/util/misc/Compat.java @@ -1,16 +1,11 @@ package dev.loki.loparkour.util.misc; -import dev.loki.loparkour.LoParkour; -import dev.loki.loparkour.scheduler.Scheduler; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import org.bukkit.structure.StructureManager; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; @@ -111,18 +106,6 @@ public final class Compat { return null; } - /** - * Teleports an entity. Direct on Bukkit; on Folia the call is routed to the - * entity scheduler because entity access from other threads is illegal. - */ - public static void teleport(@NotNull Entity entity, @NotNull Location location) { - if (Scheduler.isFolia()) { - Scheduler.get(LoParkour.getPlugin()).runAtEntity(() -> entity.teleport(location), entity); - } else { - entity.teleport(location); - } - } - /** * Resolves a {@link PotionEffectType} by name (JUMP → JUMP_BOOST, SLOW → * SLOWNESS were renamed in 1.21), or {@code null} when none exists. diff --git a/src/main/java/dev/loki/loparkour/world/core/World.java b/src/main/java/dev/loki/loparkour/world/core/World.java index c5550ad..19d0351 100644 --- a/src/main/java/dev/loki/loparkour/world/core/World.java +++ b/src/main/java/dev/loki/loparkour/world/core/World.java @@ -27,7 +27,9 @@ public final class World { private static String name; private static org.bukkit.World world; - /** Creates the parkour world and applies all world settings to it. */ + /** + * Creates a new world and sets all according settings in it. + */ public static void create() { name = Config.CONFIG.getString("world.name"); if (!isValidWorldFolderName(name)) { @@ -41,14 +43,6 @@ public final class World { if (Config.CONFIG.getBoolean("joining")) { createOrReuse(existingWorld); } - - if (world == null) { - LoParkour.getPlugin().getLogger().severe( - "Parkour world '" + name + "' is not available. LoParkour only generates parkour " - + "in its own world: set 'world.name' to a valid world or pre-create it " - + "(and set 'world.delete-on-reload: false'), then restart. Joining is disabled " - + "until the world exists."); - } } private static void createOrReuse(org.bukkit.World existingWorld) { @@ -116,7 +110,9 @@ public final class World { world.setAutoSave(false); } - /** Deletes the parkour world when configured to. */ + /** + * Deletes the world. + */ public static void delete() { if (!Config.CONFIG.getBoolean("world.delete-on-reload") || !Config.CONFIG.getBoolean("joining")) { return; @@ -168,7 +164,9 @@ public final class World { return new File(Bukkit.getWorldContainer(), name); } - /** Prevents path traversal and deletion outside the server world container. */ + /** + * Prevents path traversal and accidental deletion outside the server world container. + */ public static boolean isValidWorldFolderName(String n) { if (n == null || n.isBlank() || n.length() > MAX_WORLD_NAME_LENGTH) { return false; @@ -186,12 +184,16 @@ public final class World { return true; } - /** @return the configured name of the parkour world. */ + /** + * @return the name of the parkour world. + */ public static String getName() { return name; } - /** @return the loaded parkour world, or null when it is unavailable. */ + /** + * @return the Bukkit world wherein LoParkour is currently active. + */ public static org.bukkit.World getWorld() { return world; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7d8fa13..14acb7f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -150,24 +150,6 @@ jump-validation: max-vertical-up: 1.25 max-vertical-down: 3.0 -# -= Course spacing =- -# How far apart consecutive parkour blocks are placed (in blocks). -# Every gap is validated against vanilla jump physics before placement, -# so the next block is always reachable from the previous one. -# Values are clamped to the vanilla jump reach (1-4 blocks). -course-spacing: - # Minimum horizontal gap between two blocks. - # Blocks are never placed directly next to each other ("in a row"). - min-gap: 2 - # Maximum gap used during the conservative start segment (see start-jumps). - start-max-gap: 3 - # Maximum gap on a mature course; the exact cap grows with the - # adaptive difficulty of the players (start-max-gap .. max-gap). - max-gap: 4 - # Number of jumps kept conservative after every (re)spawn: - # gaps between min-gap and start-max-gap, upward steps of at most 1 block. - start-jumps: 5 - # -= Memory optimization =- memory: block-cleanup-distance: 20 diff --git a/src/main/resources/folia-plugin.yml b/src/main/resources/folia-plugin.yml deleted file mode 100644 index cb5c01f..0000000 --- a/src/main/resources/folia-plugin.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: 'LoParkour' -description: 'BETA - Advanced infinitely generating parkour plugin.' -author: loki -version: ${version} -api-version: ${apiVersion} -main: dev.loki.loparkour.LoParkour -softdepend: [floodgate, Vault, PlaceholderAPI, Multiverse-Core] -commands: - loparkour: - aliases: [parkour, lpk] - usage: / [arguments] - description: Main command for LoParkour diff --git a/src/main/resources/generation.yml b/src/main/resources/generation.yml index bd93c52..dc44ec5 100644 --- a/src/main/resources/generation.yml +++ b/src/main/resources/generation.yml @@ -12,13 +12,12 @@ generation: # -= Normal jump chances =- normal: # -= Distance chances =- - # Horizontal gap in blocks between two parkour blocks, in %. - # A gap of 1 is not a jump and is therefore not offered; the code also - # clamps every gap to course-spacing.min-gap in config.yml. + # The chances of the different distances in %. Can be above 100%. distance: + 1: 5 2: 35 3: 45 - 4: 20 + 4: 15 # -= Height chances =- # The chances of the different heights a jump can have in %. Can be above 100%. @@ -83,27 +82,24 @@ advanced: heading: east # -= Jump distance weights (advanced.distance.min .. max) =- - # Gap size in blocks between consecutive parkour blocks. 1 is intentionally - # not offered: a 1-block step is not a jump (course-spacing.min-gap clamps - # it anyway). 2 = easy, 4 = near the vanilla sprint-jump limit. distance: - min: 2 + min: 1 max: 4 chances: - 2: 40 - 3: 40 - 4: 20 + 1: 25 + 2: 25 + 3: 25 + 4: 25 # -= Vertical step weights (advanced.height.min .. max) =- - # A vanilla jump reaches at most ~1.25 blocks up, so positive steps are - # capped at 1; downward steps may be deeper (falling is always possible). height: min: -1 - max: 1 + max: 2 chances: - "-1": 25 - "0": 35 - 1: 40 + "-1": 20 + "0": 30 + 1: 30 + 2: 20 # -= Block type mix (default vs special vs schematic) =- type: diff --git a/src/main/resources/locales/en.yml b/src/main/resources/locales/en.yml index 5253af2..fa8bce1 100644 --- a/src/main/resources/locales/en.yml +++ b/src/main/resources/locales/en.yml @@ -45,6 +45,39 @@ play: name: "&#FF44FF&lInvisible Barrier" lore: "񢩈Invisible blocks with||񢩈colorful particle outlines" + elytra: + name: "&#FFFFFFElytra" + + elytra: + material: "elytra" + name: "�D4FF&lElytra" + lore: "񢩈Fly through rings||񢩈on your elytra." + + speeddemon: + material: "elytra" + name: "�D4FF&lSpeed Demon" + lore: "񢩈Reach the highest speed||񢩈possible on your elytra." + + minspeed: + material: "elytra" + name: "�D4FF&lMin Speed" + lore: "񢩈Keep above the minimum speed||񢩈to fly as far as possible." + + timetrial: + material: "elytra" + name: "�D4FF&lTime Trial" + lore: "񢩈Reach the target score||񢩈as fast as you can." + + close: + material: "elytra" + name: "�D4FF&lClose" + lore: "񢩈Fly through flat rings||񢩈placed close together." + + obstacle: + material: "barrier" + name: "�D4FF&lObstacle" + lore: "񢩈Fly around the obstacles||񢩈spawned on your course." + spectator: name: "&#FFFFFFSpectator" @@ -288,9 +321,6 @@ other: no_menu_items: "&#FF4444&lNo menu items are available for you right now." joining_disabled: "&#FF4444&lJoining is currently disabled." no_teleporting: "&#FFFFFFYou can't enter the parkour world by teleporting!" - world_unavailable: "&#FF4444&lParkour world \"%s\" is not available. Ask an admin to check world.name." - elytra_blocked: "&#FF4444&lElytra is disabled in the parkour world." - beta_welcome: "&#FFD700&lBETA &#A0A0A0LoParkour is in beta: courses and modes may still change. Have fun!" customize: "&#A0A0A0Customize your parkour experience by using \"/parkour\"" leave_error: "&#FF4444&lThere was an error while trying to leave." bungee_kick: "Couldn't move you to %s. Please rejoin." diff --git a/src/main/resources/locales/ru.yml b/src/main/resources/locales/ru.yml index bc36ab9..06ebb92 100644 --- a/src/main/resources/locales/ru.yml +++ b/src/main/resources/locales/ru.yml @@ -44,6 +44,39 @@ play: name: "&#FF44FF&lНевидимый барьер" lore: "񢩈Невидимые блоки с||񢩈цветными контурами из частиц" + elytra: + name: "&#FFFFFFЭлитры" + + elytra: + material: "elytra" + name: "�D4FF&lЭлитры" + lore: "񢩈Летай сквозь кольца||񢩈на элитрах." + + speeddemon: + material: "elytra" + name: "�D4FF&lСкорость-демон" + lore: "񢩈Разгонись до максимальной||񢩈скорости на элитрах." + + minspeed: + material: "elytra" + name: "�D4FF&lМин. скорость" + lore: "񢩈Держи минимальную скорость||񢩈и лети как можно дальше." + + timetrial: + material: "elytra" + name: "�D4FF&lГонка на время" + lore: "񢩈Достигни целевого счёта||񢩈как можно быстрее." + + close: + material: "elytra" + name: "�D4FF&lБлизко" + lore: "񢩈Летай сквозь плоские кольца||񢩈расположенные вплотную." + + obstacle: + material: "barrier" + name: "�D4FF&lПрепятствия" + lore: "񢩈Облетай препятствия,||񢩈появляющиеся на трассе." + spectator: name: "&#FFFFFFНаблюдатель" @@ -287,9 +320,6 @@ other: no_menu_items: "&#FF4444&lСейчас нет доступных пунктов меню." joining_disabled: "&#FF4444&lПрисоединение временно отключено." no_teleporting: "&#FFFFFFВы не можете войти в мир паркура телепортацией!" - world_unavailable: "&#FF4444&lМир паркура \"%s\" недоступен. Попросите админа проверить world.name." - elytra_blocked: "&#FF4444&lЭлитры отключены в мире паркура." - beta_welcome: "&#FFD700&lBETA &#A0A0A0LoParkour в бете: трассы и режимы ещё могут меняться. Приятной игры!" customize: "&#A0A0A0Настройте свой паркур, используя \"/parkour\"" leave_error: "&#FF4444&lОшибка при выходе из паркура." bungee_kick: "Не удалось перенести вас на %s. Перезайдите." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 132c64e..8c001ad 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: 'LoParkour' -description: 'BETA - Advanced infinitely generating parkour plugin.' +description: 'Advanced infinitely generating parkour plugin.' author: loki version: ${version} api-version: ${apiVersion} diff --git a/src/test/java/dev/loki/loparkour/arch/ArchitectureTest.java b/src/test/java/dev/loki/loparkour/arch/ArchitectureTest.java index 77568f4..ffc276e 100644 --- a/src/test/java/dev/loki/loparkour/arch/ArchitectureTest.java +++ b/src/test/java/dev/loki/loparkour/arch/ArchitectureTest.java @@ -46,14 +46,6 @@ class ArchitectureTest { .should().callMethod(org.bukkit.Bukkit.class, "getScheduler") .because("Bukkit.getScheduler() does not exist on Folia")); - @ArchTest - static final ArchRule NO_DIRECT_TELEPORT_OUTSIDE_COMPAT = freeze( - noClasses().that().resideOutsideOfPackage(ROOT + ".util.misc..") - .should().callMethod(org.bukkit.entity.Entity.class, "teleport", - org.bukkit.Location.class) - .because("teleports must go through Compat.teleport so they run " - + "on the entity thread on Folia")); - @ArchTest static final ArchRule NO_LEGACY_LOLIB = noClasses().should().dependOnClassesThat().resideInAPackage("dev.lolib.."); diff --git a/src/test/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculatorTest.java b/src/test/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculatorTest.java index 32167eb..20893c7 100644 --- a/src/test/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculatorTest.java +++ b/src/test/java/dev/loki/loparkour/generator/jump/calculation/JumpCalculatorTest.java @@ -8,9 +8,10 @@ import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.Random; + import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -21,7 +22,6 @@ class JumpCalculatorTest { private static final double DELTA = 1.0E-6; private static final double DIAGONAL_UNIT = 0.7071067811865476; private static final double DEFAULT_SD = 1; - private static final int MIN_GAP = 2; @Mock private World world; @@ -64,24 +64,20 @@ class JumpCalculatorTest { } @Test - void safetyFallbackReturnsValidMinimalStep() { + void safetyFallbackReturnsValidStepForUnitHeading() { final JumpValidator validator = new JumpValidator(); - final Location fallback = JumpCalculator.safetyFallback(current, new Vector(1, 0, 0), MIN_GAP, DEFAULT_SD, validator); + final Location fallback = JumpCalculator.safetyFallback(current, new Vector(1, 0, 0), DEFAULT_SD, new Random(42), validator); - assertNotNull(fallback); + assertNotEquals(current, fallback); assertTrue(validator.canJump(current, fallback)); - assertTrue(validator.calculateHorizontalDistance(current.toVector(), fallback.toVector()) >= MIN_GAP, - "fallback must keep at least the minimum gap"); - assertBlockGap(fallback); } @Test - void safetyFallbackReturnsNullWhenEvenMinimalStepUnreachable() { - // Validator with maxHorizontal < minGap: nothing can ever be placed. - final JumpValidator impossible = new JumpValidator(4.5, 1.0, 1.25, 3.0); - final Location fallback = JumpCalculator.safetyFallback(current, new Vector(1, 0, 0), MIN_GAP, DEFAULT_SD, impossible); + void safetyFallbackReturnsCurrentWhenStraightStepImpossible() { + final JumpValidator validator = new JumpValidator(); + final Location fallback = JumpCalculator.safetyFallback(current, new Vector(100, 0, 0), DEFAULT_SD, new Random(1), validator); - assertNull(fallback); + assertEquals(current, fallback); } @Test @@ -90,11 +86,10 @@ class JumpCalculatorTest { final Vector heading = new Vector(0, 0, 1); for (int distance = 1; distance <= 4; distance++) { - for (int height = -2; height <= 2; height++) { + for (int height = -2; height <= 1; height++) { final Location result = JumpCalculator.validateAndRetryJump( - current, heading, distance, height, MIN_GAP, DEFAULT_SD); + current, heading, distance, height, new Random(distance * 10 + height), DEFAULT_SD); - assertNotNull(result, "missing candidate for distance=" + distance + " height=" + height); assertTrue(validator.canJump(current, result), "unreachable block for distance=" + distance + " height=" + height); } @@ -102,40 +97,14 @@ class JumpCalculatorTest { } @Test - void validateAndRetryJumpNeverPlacesAdjacentBlock() { - final Vector heading = new Vector(DIAGONAL_UNIT, 0, DIAGONAL_UNIT); - - for (int attempt = 0; attempt < 50; attempt++) { - final Location result = JumpCalculator.validateAndRetryJump( - current, heading, 4, 1, MIN_GAP, DEFAULT_SD); - - assertNotNull(result); - final double horizontal = new JumpValidator().calculateHorizontalDistance(current.toVector(), result.toVector()); - assertTrue(horizontal >= MIN_GAP - DELTA, - "block placed in a row: horizontal gap " + horizontal + " < min gap " + MIN_GAP); - assertBlockGap(result); - } - } - - @Test - void validateAndRetryJumpReturnsNullWhenNothingReachable() { - final JumpValidator impossible = new JumpValidator(4.5, 1.0, 1.25, 3.0); + void validateAndRetryJumpReturnsCurrentAsLastResort() { final Location result = JumpCalculator.validateAndRetryJump( - current, new Vector(0, 0, 1), 4, 1, MIN_GAP, DEFAULT_SD, impossible); + current, new Vector(100, 0, 0), 4, 1, new Random(7), DEFAULT_SD); - assertNull(result); + assertEquals(current, result); } private static double dot(Vector a, Vector b) { return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); } - - /** Asserts the integer-grid distance between the current block and the placed block. */ - private void assertBlockGap(Location result) { - final int dx = result.getBlockX() - current.getBlockX(); - final int dz = result.getBlockZ() - current.getBlockZ(); - final double gridGap = Math.sqrt(dx * dx + dz * dz); - assertTrue(gridGap + DELTA >= MIN_GAP, - "blocks are adjacent on the grid: dx=" + dx + " dz=" + dz + " gap=" + gridGap); - } } diff --git a/src/test/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacingTest.java b/src/test/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacingTest.java deleted file mode 100644 index 41e1dde..0000000 --- a/src/test/java/dev/loki/loparkour/generator/jump/spacing/CourseSpacingTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package dev.loki.loparkour.generator.jump.spacing; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Unit tests for the gap-bounds policy between consecutive parkour blocks. - */ -class CourseSpacingTest { - - private static final CourseSpacing DEFAULTS = new CourseSpacing(2, 3, 4, 5); - - @Test - void startSegmentUsesConservativeCap() { - assertEquals(3, DEFAULTS.maxGapFor(0, 1.5)); - assertEquals(3, DEFAULTS.maxGapFor(4, 1.5)); - } - - @Test - void matureCourseGrowsWithDifficulty() { - assertEquals(3, DEFAULTS.maxGapFor(5, 0.0), "no difficulty — stay at the start cap"); - assertEquals(4, DEFAULTS.maxGapFor(5, 1.5), "full difficulty — reach max-gap"); - assertTrue(DEFAULTS.maxGapFor(5, 0.75) >= 3); - assertTrue(DEFAULTS.maxGapFor(5, 0.75) <= 4); - } - - @Test - void minGapNeverRisesAboveMaxGap() { - for (int blocks = 0; blocks < 20; blocks++) { - for (double score = 0.0; score <= 3.0; score += 0.25) { - assertTrue(DEFAULTS.maxGapFor(blocks, score) >= DEFAULTS.minGap(), - "gap cap below the minimum gap at blocks=" + blocks + " score=" + score); - } - } - } - - @Test - void outOfRangeValuesAreSanitized() { - // min-gap above the vanilla reach is clamped, bounds stay ordered. - final CourseSpacing weird = new CourseSpacing(9, 1, 12, -3); - assertEquals(4, weird.minGap()); - assertEquals(4, weird.maxGapFor(0, 1.5)); - assertEquals(4, weird.maxGapFor(100, 1.5)); - } - - @Test - void invertedBoundsAreOrdered() { - final CourseSpacing inverted = new CourseSpacing(3, 1, 2, 5); - assertEquals(3, inverted.minGap()); - assertEquals(3, inverted.maxGapFor(0, 1.5)); - assertEquals(3, inverted.maxGapFor(5, 1.5)); - } - - @Test - void zeroStartJumpsDisablesStartSegment() { - final CourseSpacing noStart = new CourseSpacing(2, 3, 4, 0); - assertEquals(3, noStart.maxGapFor(0, 0.0), "still bounded by the difficulty curve"); - } -} diff --git a/src/test/resources/archunit_store/cea999b4-4780-4ff1-ae71-5394d5efa19e b/src/test/resources/archunit_store/cea999b4-4780-4ff1-ae71-5394d5efa19e deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/resources/archunit_store/stored.rules b/src/test/resources/archunit_store/stored.rules index d43ad0b..62e7a72 100644 --- a/src/test/resources/archunit_store/stored.rules +++ b/src/test/resources/archunit_store/stored.rules @@ -1,7 +1,6 @@ # -#Sat Oct 10 15:00:30 CEST 2026 +#Tue Oct 06 13:42:44 CEST 2026 no\ classes\ that\ reside\ in\ a\ package\ 'dev.loki.loparkour.api..'\ should\ depend\ on\ classes\ that\ reside\ in\ any\ package\ ['dev.loki.loparkour.menu..',\ 'dev.loki.loparkour.command..',\ 'dev.loki.loparkour.storage..',\ 'dev.loki.loparkour.listener..',\ 'dev.loki.loparkour.hook..']=d1d8a9d7-476c-4f86-adda-8531054aea1f no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ call\ method\ Bukkit.getScheduler(),\ because\ Bukkit.getScheduler()\ does\ not\ exist\ on\ Folia=f1e3c34b-9b02-40e6-83a6-0269e173eb83 no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ depend\ on\ classes\ that\ are\ assignable\ to\ org.bukkit.scheduler.BukkitRunnable,\ because\ all\ tasks\ go\ through\ scheduler/\ so\ they\ work\ on\ Folia=339ab3ea-28aa-4f4b-a1e4-6c69e3ff0a0a -no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.util.misc..'\ should\ call\ method\ Entity.teleport(Location),\ because\ teleports\ must\ go\ through\ Compat.teleport\ so\ they\ run\ on\ the\ entity\ thread\ on\ Folia=cea999b4-4780-4ff1-ae71-5394d5efa19e slices\ matching\ 'dev.loki.loparkour.(*)..'\ should\ be\ free\ of\ cycles=58784f63-3f60-4edb-9733-fa0d7e11b877