fix generator 30%

This commit is contained in:
loki 2026-03-07 15:59:12 +01:00
parent 261c4a5cab
commit 2d5c5eea48
24 changed files with 710 additions and 111 deletions

View file

@ -0,0 +1,134 @@
package dev.loki.loparkour.mode;
import dev.loki.loparkour.config.Config;
import dev.loki.loparkour.config.Locales;
import dev.loki.loparkour.generator.ParkourGenerator;
import dev.loki.loparkour.leaderboard.Leaderboard;
import dev.loki.loparkour.player.ParkourPlayer;
import dev.loki.loparkour.session.Session;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Coop Mode - Shared score between multiple players
*/
public class CoopMode implements Mode {
private final Leaderboard leaderboard = new Leaderboard(getName(), Leaderboard.Sort.SCORE);
@Override
@NotNull
public String getName() {
return "coop";
}
@Override
@Nullable
public dev.loki.loparkour.util.Item getItem(String locale) {
return Locales.getItem(locale, "modes.coop");
}
@Override
@NotNull
public Leaderboard getLeaderboard() {
return leaderboard;
}
@Override
public void create(Player player) {
if (!Config.CONFIG.getBoolean("joining")) {
player.sendMessage("§cJoining is currently disabled.");
return;
}
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp != null && pp.session.generator != null && pp.session.generator.getMode() instanceof CoopMode) {
return;
}
player.closeInventory();
Session.create(session -> new CoopGenerator(session), null, null, player);
}
private static class CoopGenerator extends ParkourGenerator {
private final Map<UUID, Integer> playerContributions = new HashMap<>();
private int sharedScore = 0;
public CoopGenerator(@NotNull Session session) {
super(session);
// Initialize contributions
for (ParkourPlayer pp : session.getPlayers()) {
playerContributions.put(pp.getUUID(), 0);
}
}
@Override
protected void score() {
super.score();
sharedScore++;
// Track individual contributions
if (!getPlayers().isEmpty()) {
UUID scorer = player.getUUID();
playerContributions.put(scorer, playerContributions.getOrDefault(scorer, 0) + 1);
}
// Milestone celebrations
if (sharedScore % 50 == 0) {
for (ParkourPlayer pp : getPlayers()) {
pp.player.sendTitle("§6" + sharedScore + " Points!", "§eTeam effort!", 5, 30, 10);
pp.player.playSound(pp.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.5f, 1.5f);
}
}
}
@Override
public void tick() {
super.tick();
// Display shared score and contributions in ActionBar
for (ParkourPlayer pp : getPlayers()) {
int myContribution = playerContributions.getOrDefault(pp.getUUID(), 0);
int percentage = sharedScore > 0 ? (myContribution * 100 / sharedScore) : 0;
String message = "§aTeam: §e" + sharedScore + " §7| §bYou: §e" + myContribution + " §7(" + percentage + "%)";
pp.player.spigot().sendMessage(
net.md_5.bungee.api.ChatMessageType.ACTION_BAR,
net.md_5.bungee.api.chat.TextComponent.fromLegacyText(message)
);
}
}
@Override
protected void fall() {
// Show final stats before reset
for (ParkourPlayer pp : getPlayers()) {
int contribution = playerContributions.getOrDefault(pp.getUUID(), 0);
pp.sendTranslated("modes.coop.stats",
Integer.toString(sharedScore),
Integer.toString(contribution));
}
super.fall();
// Reset coop state
sharedScore = 0;
playerContributions.clear();
for (ParkourPlayer pp : getPlayers()) {
playerContributions.put(pp.getUUID(), 0);
}
}
@Override
public Mode getMode() {
return Modes.COOP;
}
}
}

View file

@ -9,13 +9,16 @@ import dev.loki.loparkour.leaderboard.Leaderboard;
import dev.loki.loparkour.player.ParkourPlayer;
import dev.loki.loparkour.session.Session;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* Elytra Parkour Mode - Flying parkour with rings and boost
*/
@ -56,8 +59,17 @@ public class ElytraMode implements Mode {
player.closeInventory();
// Create session with elytra setup
Session.create(session -> {
ParkourGenerator generator = new ParkourGenerator(session);
Session.create(session -> new ElytraGenerator(session), null, null, player);
}
private static class ElytraGenerator extends ParkourGenerator {
private final List<RingCheckpoint> rings = new ArrayList<>();
private final Map<UUID, Long> fireworkCooldowns = new HashMap<>();
private final Map<UUID, Integer> ringsCollected = new HashMap<>();
private int tickCounter = 0;
public ElytraGenerator(@NotNull Session session) {
super(session);
// Give elytra and fireworks to all players in session
for (ParkourPlayer parkourPlayer : session.getPlayers()) {
@ -67,9 +79,117 @@ public class ElytraMode implements Mode {
int fireworks = Config.CONFIG.getInt("modes.elytra.starting-fireworks");
p.getInventory().addItem(new ItemStack(Material.FIREWORK_ROCKET, fireworks));
ringsCollected.put(p.getUniqueId(), 0);
}
}
@Override
public void tick() {
super.tick();
tickCounter++;
// Spawn rings every 5 blocks
if (tickCounter % 100 == 0 && !state.history.isEmpty()) {
Location ringLoc = getLatest().getLocation().clone().add(0, 3, 0);
rings.add(new RingCheckpoint(ringLoc));
}
return generator;
}, null, null, player);
// Display rings and check for player passing through
Iterator<RingCheckpoint> it = rings.iterator();
while (it.hasNext()) {
RingCheckpoint ring = it.next();
// Display ring particles
displayRing(ring.location);
// Check if any player passed through
for (ParkourPlayer pp : getPlayers()) {
if (ring.collected) continue;
BoundingBox playerBox = pp.player.getBoundingBox();
if (ring.getBoundingBox().overlaps(playerBox)) {
ring.collected = true;
int count = ringsCollected.getOrDefault(pp.getUUID(), 0) + 1;
ringsCollected.put(pp.getUUID(), count);
// Bonus points for passing through ring
lifecycle.score();
lifecycle.score();
pp.player.playSound(pp.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1.5f);
pp.player.spawnParticle(Particle.TOTEM, ring.location, 20, 0.5, 0.5, 0.5, 0.1);
}
}
// Remove old rings
if (ring.location.distance(player.getLocation()) > 50) {
it.remove();
}
}
// Check firework cooldown
checkFireworkCooldown();
}
private void displayRing(Location center) {
World world = center.getWorld();
if (world == null) return;
double radius = 2.0;
int points = 30;
for (int i = 0; i < points; i++) {
double angle = 2 * Math.PI * i / points;
double x = center.getX() + radius * Math.cos(angle);
double z = center.getZ() + radius * Math.sin(angle);
Location particleLoc = new Location(world, x, center.getY(), z);
world.spawnParticle(Particle.END_ROD, particleLoc, 1, 0, 0, 0, 0);
}
}
private void checkFireworkCooldown() {
long now = System.currentTimeMillis();
int cooldownMs = Config.CONFIG.getInt("modes.elytra.firework-cooldown-ms");
for (ParkourPlayer pp : getPlayers()) {
UUID uuid = pp.getUUID();
ItemStack mainHand = pp.player.getInventory().getItemInMainHand();
ItemStack offHand = pp.player.getInventory().getItemInOffHand();
boolean usingFirework = (mainHand.getType() == Material.FIREWORK_ROCKET && pp.player.isGliding())
|| (offHand.getType() == Material.FIREWORK_ROCKET && pp.player.isGliding());
if (usingFirework) {
Long lastUse = fireworkCooldowns.get(uuid);
if (lastUse != null && now - lastUse < cooldownMs) {
long remaining = (cooldownMs - (now - lastUse)) / 1000;
pp.player.spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR,
net.md_5.bungee.api.chat.TextComponent.fromLegacyText("§cFirework cooldown: " + remaining + "s"));
continue;
}
fireworkCooldowns.put(uuid, now);
}
}
}
@Override
public Mode getMode() {
return Modes.ELYTRA;
}
private static class RingCheckpoint {
final Location location;
boolean collected = false;
RingCheckpoint(Location location) {
this.location = location;
}
BoundingBox getBoundingBox() {
return BoundingBox.of(location, 2.5, 2.5, 2.5);
}
}
}
}

View file

@ -140,6 +140,12 @@ public class GravityShiftMode implements Mode {
);
player.player.addPotionEffect(currentEffect);
// Visual feedback
player.player.sendTitle("§6⚡", "§e" + selected.name, 5, 20, 10);
player.player.playSound(player.player.getLocation(), org.bukkit.Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.5f);
player.player.spawnParticle(org.bukkit.Particle.PORTAL, player.player.getLocation().add(0, 1, 0), 50, 0.5, 0.5, 0.5, 0.5);
player.sendTranslated("modes.gravity-shift.effect-applied", selected.name);
}

View file

@ -63,6 +63,7 @@ public class HardcoreMode implements Mode {
boolean resetRewards = Config.CONFIG.getBoolean("modes.hardcore.reset-rewards");
if (resetRewards) {
player.collectedRewards.clear();
player.sendTranslated("modes.hardcore.rewards-lost");
}

View file

@ -10,6 +10,8 @@ public class Modes {
public static GravityShiftMode GRAVITY_SHIFT;
public static HardcoreMode HARDCORE;
public static ElytraMode ELYTRA;
public static RaceMode RACE;
public static CoopMode COOP;
public static void init() {
DEFAULT = (DefaultMode) Registry.getMode("default");
@ -18,5 +20,7 @@ public class Modes {
GRAVITY_SHIFT = (GravityShiftMode) Registry.getMode("gravity-shift");
HARDCORE = (HardcoreMode) Registry.getMode("hardcore");
ELYTRA = (ElytraMode) Registry.getMode("elytra");
RACE = (RaceMode) Registry.getMode("race");
COOP = (CoopMode) Registry.getMode("coop");
}
}

View file

@ -0,0 +1,108 @@
package dev.loki.loparkour.mode;
import dev.loki.loparkour.config.Config;
import dev.loki.loparkour.config.Locales;
import dev.loki.loparkour.generator.ParkourGenerator;
import dev.loki.loparkour.leaderboard.Leaderboard;
import dev.loki.loparkour.player.ParkourPlayer;
import dev.loki.loparkour.session.Session;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Race Mode - First to reach target score wins
*/
public class RaceMode implements Mode {
private final Leaderboard leaderboard = new Leaderboard(getName(), Leaderboard.Sort.TIME);
@Override
@NotNull
public String getName() {
return "race";
}
@Override
@Nullable
public dev.loki.loparkour.util.Item getItem(String locale) {
return Locales.getItem(locale, "modes.race");
}
@Override
@NotNull
public Leaderboard getLeaderboard() {
return leaderboard;
}
@Override
public void create(Player player) {
if (!Config.CONFIG.getBoolean("joining")) {
player.sendMessage("§cJoining is currently disabled.");
return;
}
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp != null && pp.session.generator != null && pp.session.generator.getMode() instanceof RaceMode) {
return;
}
player.closeInventory();
Session.create(session -> new RaceGenerator(session), null, null, player);
}
private static class RaceGenerator extends ParkourGenerator {
private final int targetScore;
private boolean raceFinished = false;
public RaceGenerator(@NotNull Session session) {
super(session);
this.targetScore = Config.CONFIG.getInt("modes.race.target-score");
}
@Override
public void tick() {
super.tick();
if (raceFinished) return;
// Check if target reached
if (state.score >= targetScore) {
finishRace();
}
// Display progress in ActionBar
for (ParkourPlayer pp : getPlayers()) {
int remaining = targetScore - state.score;
String progress = "§e" + state.score + " §7/ §a" + targetScore + " §7(§c" + remaining + " §7left)";
pp.player.spigot().sendMessage(
net.md_5.bungee.api.ChatMessageType.ACTION_BAR,
net.md_5.bungee.api.chat.TextComponent.fromLegacyText(progress)
);
}
}
private void finishRace() {
raceFinished = true;
for (ParkourPlayer pp : getPlayers()) {
pp.player.sendTitle("§6§lRACE COMPLETE!", "§aFinished in " + getFormattedTime(), 10, 70, 20);
pp.player.playSound(pp.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1f, 1f);
pp.sendTranslated("modes.race.completed", Integer.toString(targetScore), getFormattedTime());
}
// Register time-based score
registerScore(getDetailedTime(), Double.toString(getDifficultyScore()).substring(0, 3), targetScore);
// Stop generator after 5 seconds
dev.lolib.scheduler.Scheduler.get(dev.loki.loparkour.LoParkour.getPlugin())
.runLater(() -> reset(false), 100);
}
@Override
public Mode getMode() {
return Modes.RACE;
}
}
}

View file

@ -3,6 +3,7 @@ package dev.loki.loparkour.mode;
import dev.loki.loparkour.util.Item;
import dev.lolib.scheduler.Scheduler;
import dev.lolib.scheduler.ScheduledTask;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.config.Config;
@ -12,7 +13,6 @@ import dev.loki.loparkour.leaderboard.Leaderboard;
import dev.loki.loparkour.player.ParkourPlayer;
import dev.loki.loparkour.session.Session;
import dev.lolib.scheduler.Scheduler;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
@ -27,7 +27,6 @@ import java.util.Map;
public class SpeedrunMode implements Mode {
private final Leaderboard leaderboard = new Leaderboard(getName(), Leaderboard.Sort.SCORE);
private final Map<Block, Long> blockTimestamps = new HashMap<>();
@Override
@NotNull
@ -64,44 +63,60 @@ public class SpeedrunMode implements Mode {
Session.create(session -> new SpeedrunGenerator(session), null, null, player);
}
public void onBlockTouch(@NotNull Block block, @NotNull ParkourPlayer player) {
if (!blockTimestamps.containsKey(block)) {
blockTimestamps.put(block, System.currentTimeMillis());
scheduleBlockRemoval(player, block);
}
}
private void scheduleBlockRemoval(@NotNull ParkourPlayer player, @NotNull Block block) {
double blockLifetime = Config.CONFIG.getDouble("modes.speedrun.block-lifetime");
double warningTime = Config.CONFIG.getDouble("modes.speedrun.warning-time");
long removalTime = (long) (blockLifetime * 1000);
long warningTimeMs = (long) (warningTime * 1000);
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
if (block.getType() != Material.AIR) {
player.player.playSound(block.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0f, 2.0f);
player.player.spawnParticle(Particle.FLAME, block.getLocation().add(0.5, 1, 0.5), 10, 0.3, 0.3, 0.3, 0.01);
}
}, warningTimeMs / 50);
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
if (block.getType() != Material.AIR) {
block.setType(Material.AIR);
blockTimestamps.remove(block);
}
}, removalTime / 50);
}
public void reset() {
blockTimestamps.clear();
}
private static class SpeedrunGenerator extends ParkourGenerator {
private final Map<Block, Long> blockTimestamps = new HashMap<>();
private final Map<Block, ScheduledTask> scheduledTasks = new HashMap<>();
public SpeedrunGenerator(@NotNull Session session) {
super(session);
}
public void onBlockTouch(@NotNull Block block) {
if (!blockTimestamps.containsKey(block)) {
blockTimestamps.put(block, System.currentTimeMillis());
scheduleBlockRemoval(block);
}
}
private void scheduleBlockRemoval(@NotNull Block block) {
double blockLifetime = Config.CONFIG.getDouble("modes.speedrun.block-lifetime");
double warningTime = Config.CONFIG.getDouble("modes.speedrun.warning-time");
long removalTime = (long) (blockLifetime * 1000);
long warningTimeMs = (long) (warningTime * 1000);
ScheduledTask warningTask = Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
if (block.getType() != Material.AIR) {
player.player.playSound(block.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0f, 2.0f);
player.player.spawnParticle(Particle.FLAME, block.getLocation().add(0.5, 1, 0.5), 10, 0.3, 0.3, 0.3, 0.01);
}
}, warningTimeMs / 50);
ScheduledTask removalTask = Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
if (block.getType() != Material.AIR) {
block.setType(Material.AIR);
blockTimestamps.remove(block);
scheduledTasks.remove(block);
}
}, removalTime / 50);
scheduledTasks.put(block, removalTask);
}
@Override
public void reset(boolean regenerate) {
// Cancel all scheduled tasks
for (ScheduledTask task : scheduledTasks.values()) {
if (task != null) {
task.cancel();
}
}
scheduledTasks.clear();
blockTimestamps.clear();
super.reset(regenerate);
}
@Override
public Mode getMode() {
return Modes.SPEEDRUN;