Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import fr.openmc.core.OMCPlugin;
import fr.openmc.core.features.dream.events.AltarBindEvent;
import fr.openmc.core.features.dream.events.AltarCraftingEvent;
import fr.openmc.core.features.dream.mecanism.altar.tasks.AltarCheckTask;
import fr.openmc.core.features.dream.mecanism.altar.tasks.AltarParticlesTask;
import fr.openmc.core.features.dream.models.registry.items.DreamItem;
import fr.openmc.core.features.dream.registries.DreamItemRegistry;
import fr.openmc.core.utils.bukkit.ItemUtils;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.openmc.core.features.dream.mecanism.altar;
package fr.openmc.core.features.dream.mecanism.altar.tasks;

import fr.openmc.core.features.dream.mecanism.altar.AltarManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package fr.openmc.core.features.dream.mecanism.altar.tasks;

import fr.openmc.core.features.dream.generation.DreamDimensionManager;
import fr.openmc.core.features.dream.models.registry.DreamBlock;
import fr.openmc.core.features.dream.registries.DreamBlocksRegistry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;

public class AltarParticlesTask extends BukkitRunnable {

private static final List<Vector> CIRCLE_PARTICLE = new ArrayList<>();

static {
for (int i = 0; i < 360; i += 20) {
double radians = Math.toRadians(i);
CIRCLE_PARTICLE.add(new Vector(
Math.cos(radians) * 0.7,
0,
Math.sin(radians) * 0.7
));
}
}

@Override
public void run() {
if (Bukkit.getOnlinePlayers().isEmpty()) return;

for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.getWorld().getName().equals(DreamDimensionManager.DIMENSION_NAME)) continue;
Location playerLoc = player.getLocation();
World world = playerLoc.getWorld();

List<DreamBlock> altars = DreamBlocksRegistry.getDreamBlocksByType("altar");

for (DreamBlock altar : altars) {
if (altar.location().getWorld() != world) continue;

Location center = altar.location();

if (center.distanceSquared(playerLoc) > 30 * 30) continue;

spawnCircleParticles(center);
}
}
}

private void spawnCircleParticles(Location base) {
World world = base.getWorld();
double x = base.getX() + 0.5;
double y = base.getY() + 1.5;
double z = base.getZ() + 0.5;

for (Vector vec : CIRCLE_PARTICLE) {
world.spawnParticle(
Particle.DUST,
x + vec.getX(),
y,
z + vec.getZ(),
1,
new Particle.DustOptions(org.bukkit.Color.ORANGE, 1.5f)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DreamBlocksRegistry {

Expand All @@ -27,6 +29,8 @@ public class DreamBlocksRegistry {

private static final List<DreamBlock> dreamBlocks = new ArrayList<>();

private static final Map<String, List<DreamBlock>> cacheByType = new HashMap<>();

public static void init() {
OMCPlugin.registerEvents(
new DreamBlocksListeners(),
Expand Down Expand Up @@ -84,15 +88,12 @@ public static void addDreamBlock(String type, Location loc) {
DreamBlock entry = new DreamBlock(type, loc);
if (!dreamBlocks.contains(entry)) {
dreamBlocks.add(entry);
cacheByType.computeIfAbsent(type.toLowerCase(), k -> new ArrayList<>())
.add(entry);
save();
}
}

public static void removeDreamBlock(Location loc) {
dreamBlocks.removeIf(e -> e.location().equals(loc));
save();
}

public static boolean isDreamBlock(Location loc) {
return dreamBlocks.stream().anyMatch(e -> e.location().equals(loc));
}
Expand All @@ -106,6 +107,6 @@ public static List<DreamBlock> getDreamBlocks() {
}

public static List<DreamBlock> getDreamBlocksByType(String type) {
return dreamBlocks.stream().filter(e -> e.type().equalsIgnoreCase(type)).toList();
return cacheByType.getOrDefault(type.toLowerCase(), new ArrayList<>());
}
}
Loading