mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-15 23:20:44 +00:00
add portal locations
This commit is contained in:
Submodule PrivateConfig updated: 107f708e24...c76697cec3
@@ -0,0 +1,48 @@
|
||||
package net.civmc.zorweth.mechanics;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EnderSignal;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
public final class EnderEyeListener implements Listener {
|
||||
|
||||
private final String worldName;
|
||||
private final List<PortalPosition> portals;
|
||||
|
||||
public EnderEyeListener(final String worldName, final List<PortalPosition> portals) {
|
||||
this.worldName = worldName;
|
||||
this.portals = portals;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onEnderEyeSpawn(final EntitySpawnEvent event) {
|
||||
if (!(event.getEntity() instanceof EnderSignal eye)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = event.getEntity().getWorld();
|
||||
if (!world.getName().equals(this.worldName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location closestPortal = null;
|
||||
double closestDistanceSquared = Double.MAX_VALUE;
|
||||
for (final PortalPosition portal : this.portals) {
|
||||
final Location location = new Location(world, portal.x(), world.getMinHeight(), portal.z());
|
||||
final double distanceSquared = location.distanceSquared(eye.getLocation());
|
||||
if (distanceSquared < closestDistanceSquared) {
|
||||
closestPortal = location;
|
||||
closestDistanceSquared = distanceSquared;
|
||||
}
|
||||
}
|
||||
|
||||
if (closestPortal != null) {
|
||||
eye.setTargetLocation(closestPortal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,12 @@ public class OilMechanics {
|
||||
oilPos.add(new OilVein((int) position.get("x"), (int) position.get("z"), (int) position.get("yield")));
|
||||
}
|
||||
|
||||
List<PortalPosition> portals = new ArrayList<>();
|
||||
List<Map<?, ?>> portalPositions = mechanics.getMapList("portals");
|
||||
for (Map<?, ?> position : portalPositions) {
|
||||
portals.add(new PortalPosition((int) position.get("x"), (int) position.get("z")));
|
||||
}
|
||||
|
||||
this.oilPos = oilPos;
|
||||
this.world = mechanicsWorld;
|
||||
this.radius = mechanics.getInt("radius");
|
||||
@@ -41,6 +47,9 @@ public class OilMechanics {
|
||||
Bukkit.addRecipe(recipe);
|
||||
}
|
||||
plugin.getServer().getPluginManager().registerEvents(new SeismicScannerListener(recipes, this), plugin);
|
||||
if (!portals.isEmpty()) {
|
||||
plugin.getServer().getPluginManager().registerEvents(new EnderEyeListener(mechanicsWorld, portals), plugin);
|
||||
}
|
||||
|
||||
Fuel.createCrudeOil();
|
||||
Fuel.createRocketFuel();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.civmc.zorweth.mechanics;
|
||||
|
||||
public record PortalPosition(int x, int z) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user